drv_sai.h 1.7 KB

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