drv_aic_i2s.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * drv_aic_i2s.h
  3. *
  4. * Created on: 2016年4月1日
  5. * Author: Urey
  6. */
  7. #ifndef DRIVER_DRV_AIC_I2S_H_
  8. #define DRIVER_DRV_AIC_I2S_H_
  9. #include "board.h"
  10. #ifdef RT_USING_ICODEC
  11. # define CODEC_AS_MASTER
  12. #define CODEC_DEF_RATE (24000000)
  13. #else
  14. //# undef CODEC_AS_MASTER
  15. //# define CODEC_AS_MASTER
  16. #define CODEC_DEF_RATE (44100)
  17. #endif
  18. #ifdef RT_USING_ECODEC_WM8978
  19. # define CFG_AIC_I2S_EXT_CODEC
  20. #endif
  21. #define CFG_AIC_SOC_CLKOUT
  22. //#define CFG_AIC_SOC_CLKIN
  23. #define CFG_I2S_DMA_PAGE_SIZE (32 * 1024)
  24. #define CFG_I2S_DMA_PAGE_NUM 8
  25. enum
  26. {
  27. I2S_TRIGGER_STOP = 0,
  28. I2S_TRIGGER_START ,
  29. I2S_TRIGGER_PAUSE_PUSH ,
  30. I2S_TRIGGER_PAUSE_RELEASE ,
  31. I2S_TRIGGER_SUSPEND ,
  32. I2S_TRIGGER_RESUME,
  33. };
  34. /*********************************************************************************************************
  35. ** 数据结构
  36. *********************************************************************************************************/
  37. struct jz_i2s
  38. {
  39. struct jz_aic *aic;
  40. int i2s_init;
  41. #define I2S_WRITE 0x1
  42. #define I2S_READ 0x2
  43. #define I2S_INCODEC (0x1 <<4)
  44. #define I2S_EXCODEC (0x2 <<4)
  45. #define I2S_SLAVE (0x1 << 8)
  46. #define I2S_MASTER (0x2 << 8)
  47. int i2s_mode;
  48. uint32_t tx_dr_base;
  49. int channels;
  50. int fmt_width;
  51. int rates;
  52. /* used for DMA transform */
  53. struct rt_dma_channel *tx_dmac;
  54. struct rt_dma_channel *rx_dmac;
  55. };
  56. /*********************************************************************************************************
  57. ** 函数申明
  58. *********************************************************************************************************/
  59. int aic_set_rate(struct jz_aic *aic, uint32_t freq);
  60. struct jz_i2s *rt_hw_aic_i2s_init(void);
  61. //void aic_i2s_start_substream(struct jz_i2s *i2s,int stream);
  62. //void aic_i2s_stop_substream(struct jz_i2s *i2s,int stream);
  63. int aic_i2s_set_sysclk(struct jz_i2s *i2s,uint32_t freq);
  64. int aic_i2s_set_clkdiv(struct jz_i2s *i2s,int div_id, int div);
  65. int aic_i2s_startup(struct jz_i2s *i2s,int stream);
  66. int aic_i2s_trigger(struct jz_i2s* i2s,int cmd,int stream);
  67. int aic_i2s_hw_params(struct jz_i2s* i2s,int stream);
  68. void aic_i2s_shutdown(struct jz_i2s *i2s,int stream);
  69. rt_size_t aic_i2s_send(struct jz_i2s *i2s, const void* buffer, rt_size_t size,void (*tx_callback)(void *,void *), void *tx_arg);
  70. rt_size_t aic_i2s_recv(struct jz_i2s *i2s, void* buffer, rt_size_t size,void (*rx_callback)(void *,void *), void *rx_arg);
  71. void aic_i2s_set_rate(struct jz_i2s *i2s,int rate);
  72. #endif /* DRIVER_DRV_AIC_I2S_H_ */