drv_sai.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * File: drv_sound.h
  3. *
  4. * COPYRIGHT (C) 2012-2018, Shanghai Real-Thread Technology Co., Ltd
  5. */
  6. #ifndef __DRV_SOUND_H_
  7. #define __DRV_SOUND_H_
  8. #include <rtthread.h>
  9. #include <rtdevice.h>
  10. #include <board.h>
  11. #include <rtdef.h>
  12. #include <rthw.h>
  13. #include "fsl_sai.h"
  14. #include "fsl_dmamux.h"
  15. #include "fsl_sai_edma.h"
  16. #define AUD_DMA_FIFO_SIZE (2048)
  17. #define CODEC_I2C_NAME ("i2c1")
  18. /* Select Audio/Video PLL (786.48 MHz) as sai1 clock source */
  19. #define DEMO_SAI1_CLOCK_SOURCE_SELECT (2U)
  20. /* Clock pre divider for sai1 clock source */
  21. #define DEMO_SAI1_CLOCK_SOURCE_PRE_DIVIDER (0U)
  22. /* Clock divider for sai1 clock source */
  23. #define DEMO_SAI1_CLOCK_SOURCE_DIVIDER (63U)
  24. /* Get frequency of sai1 clock */
  25. #define AUD_BLOCK_CNT 2
  26. #define AUD_BLOCK_SIZE 1024
  27. #define AUD_FIFO_SIZE (AUD_BLOCK_SIZE * AUD_BLOCK_CNT)
  28. #define DEMO_SAI_CLK_FREQ \
  29. (CLOCK_GetFreq(kCLOCK_AudioPllClk) / (DEMO_SAI1_CLOCK_SOURCE_DIVIDER + 1U) / \
  30. (DEMO_SAI1_CLOCK_SOURCE_PRE_DIVIDER + 1U))
  31. #define AUD_DMA_FIFO_SIZE (2048)
  32. struct saidma_tx_config
  33. {
  34. edma_handle_t edma;
  35. rt_uint8_t channel;
  36. dma_request_source_t request;
  37. sai_edma_handle_t txHandle;
  38. };
  39. struct saidma_rx_config
  40. {
  41. edma_handle_t edma;
  42. rt_uint8_t channel;
  43. dma_request_source_t request;
  44. sai_edma_handle_t rxHandle;
  45. };
  46. struct drv_sai {
  47. I2S_Type *base;
  48. IRQn_Type irqn;
  49. struct saidma_tx_config *dma_tx;
  50. struct saidma_rx_config *dma_rx;
  51. rt_uint8_t dma_flag;
  52. int txBlockIndex;
  53. int rxBlockIndex;
  54. };
  55. void sai_init(void);
  56. int rt_hw_sound_init(void);
  57. #endif