I2S_LPC18xx.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 02. March 2016
  19. * $Revision: V1.1
  20. *
  21. * Project: I2S Driver Definitions for NXP LPC18xx
  22. * -------------------------------------------------------------------------- */
  23. #ifndef __I2S_LPC18XX_H
  24. #define __I2S_LPC18XX_H
  25. #include "LPC18xx.h"
  26. #include "Driver_SAI.h"
  27. #include "SCU_LPC18xx.h"
  28. #include "GPDMA_LPC18xx.h"
  29. // Clock Control Unit register
  30. #define CCU_CLK_CFG_RUN (1 << 0)
  31. #define CCU_CLK_CFG_AUTO (1 << 1)
  32. #define CCU_CLK_STAT_RUN (1 << 0)
  33. // I2S Register interface definitions
  34. // I2S Digital audio output/input register
  35. #define I2S_DAO_DAI_WORDWIDTH_POS ( 0U)
  36. #define I2S_DAO_DAI_WORDWIDTH_MSK (3U << I2S_DAO_DAI_WORDWIDTH_POS)
  37. #define I2S_DAO_DAI_MONO (1U << 2)
  38. #define I2S_DAO_DAI_STOP (1U << 3)
  39. #define I2S_DAO_DAI_RESET (1U << 4)
  40. #define I2S_DAO_DAI_WS_SEL (1U << 5)
  41. #define I2S_DAO_DAI_WS_HALFPERIOD_POS ( 6U)
  42. #define I2S_DAO_DAI_WS_HALFPERIOD_MSK (0x1FF << I2S_DAO_DAI_WS_HALFPERIOD_POS)
  43. #define I2S_DAO_MUTE (1U << 15)
  44. // I2S Transmit fifo register
  45. #define I2S_TXFIFO_I2STXFIFO_MSK (0xFFFFFFFFU)
  46. // I2S Receive fifo register
  47. #define I2S_RXFIFO_I2SrXFIFO_MSK (0xFFFFFFFFU)
  48. // I2S Status feedback register
  49. #define I2S_STATE_IRQ ( 1U)
  50. #define I2S_STATE_DMAREQ1 (1U << 1)
  51. #define I2S_STATE_DMAREQ2 (1U << 2)
  52. #define I2S_STATE_RX_LEVEL_POS ( 8U)
  53. #define I2S_STATE_RX_LEVEL_MSK (0xFU << I2S_STATE_RX_LEVEL_POS)
  54. #define I2S_STATE_TX_LEVEL_POS ( 16U)
  55. #define I2S_STATE_TX_LEVEL_MSK (0xFU << I2S_STATE_TX_LEVEL_POS)
  56. // I2S DMA configuration register
  57. #define I2S_DMA_RX_DMA_ENABLE ( 1U)
  58. #define I2S_DMA_TX_DMA_ENABLE (1U << 1)
  59. #define I2S_DMA_RX_DEPTH_DMA_POS ( 8U)
  60. #define I2S_DMA_RX_DEPTH_DMA_MSK (0xFU << I2S_DMA_RX_DEPTH_DMA_POS)
  61. #define I2S_DMA_TX_DEPTH_DMA_POS ( 16U)
  62. #define I2S_DMA_TX_DEPTH_DMA_MSK (0xFU << I2S_DMA_TX_DEPTH_DMA_POS)
  63. // I2S Interrupt request control register
  64. #define I2S_IRQ_RX_IRQ_ENABLE ( 1U)
  65. #define I2S_IRQ_TX_IRQ_ENABLE (1U << 1)
  66. #define I2S_IRQ_RX_DEPTH_IRQ_POS ( 8U)
  67. #define I2S_IRQ_RX_DEPTH_IRQ_MSK (0xFU << I2S_IRQ_RX_DEPTH_IRQ_POS)
  68. #define I2S_IRQ_TX_DEPTH_IRQ_POS ( 16U)
  69. #define I2S_IRQ_TX_DEPTH_IRQ_MSK (0xFU << I2S_IRQ_TX_DEPTH_IRQ_POS)
  70. // I2S Transmit/Recevice clock rate register
  71. #define I2S_TX_RX_RATE_Y_DIVIDER_POS ( 0U)
  72. #define I2S_TX_RX_RATE_Y_DIVIDER_MSK (0xFFU << I2S_TX_RX_RATE_Y_DIVIDER_POS)
  73. #define I2S_TX_RX_RATE_X_DIVIDER_POS ( 8U)
  74. #define I2S_TX_RX_RATE_X_DIVIDER_MSK (0xFFU << I2S_TX_RX_RATE_X_DIVIDER_POS)
  75. // I2S Transmit/Receive clock bit rate register
  76. #define I2S_TX_RX_BITRATE_BITRATE_POS ( 0U)
  77. #define I2S_TX_RX_BITRATE_BITRATE_MSK (0x3FU << I2S_TX_RX_BITRATE_BITRATE_POS)
  78. // I2S Transmit/Receive mode control register
  79. #define I2S_TX_RX_MODE_CLKSEL_POS ( 0U)
  80. #define I2S_TX_RX_MODE_CLKSEL_MSK (3U << I2S_TX_RX_MODE_CLKSEL_POS)
  81. #define I2S_TX_RX_MODE_4PIN (1U << 2U)
  82. #define I2S_TX_RX_MODE_MCENA (1U << 3U)
  83. // I2S flags
  84. #define I2S_FLAG_INITIALIZED ( 1U)
  85. #define I2S_FLAG_POWERED (1U << 1)
  86. #define I2S_FLAG_CONFIGURED (1U << 2)
  87. // I2S Stream Information (Run-Time)
  88. typedef struct _I2S_STREAM_INFO {
  89. uint32_t num; // Total number of data to be transmited/received
  90. uint8_t *buf; // Pointer to data buffer
  91. uint32_t cnt; // Number of data transmited/receive
  92. uint8_t data_bits; // Number of data bits
  93. uint8_t master; // Master flag
  94. uint8_t residue_num;
  95. uint8_t residue_buf[4];
  96. uint8_t residue_cnt;
  97. } I2S_STREAM_INFO;
  98. typedef struct _I2S_STATUS {
  99. uint8_t tx_busy; // Transmitter busy flag
  100. uint8_t rx_busy; // Receiver busy flag
  101. uint8_t tx_underflow; // Transmit data underflow detected (cleared on start of next send operation)
  102. uint8_t rx_overflow; // Receive data overflow detected (cleared on start of next receive operation)
  103. uint8_t frame_error; // Sync Frame error detected (cleared on start of next send/receive operation)
  104. } I2S_STATUS;
  105. // I2S Information (Run-Time)
  106. typedef struct _I2S_INFO {
  107. ARM_SAI_SignalEvent_t cb_event; // Event callback
  108. I2S_STATUS status; // Status flags
  109. I2S_STREAM_INFO tx; // Transmit information
  110. I2S_STREAM_INFO rx; // Receive information
  111. uint8_t flags; // I2S driver flags
  112. } I2S_INFO;
  113. // I2S DMA
  114. typedef const struct _I2S_DMA {
  115. uint8_t channel; // DMA Channel
  116. uint8_t peripheral; // DMA mux
  117. uint8_t peripheral_sel;// DMA mux selection
  118. GPDMA_SignalEvent_t cb_event; // DMA Event callback
  119. } I2S_DMA;
  120. // I2S Pin Configuration
  121. typedef const struct _I2S_PINS {
  122. PIN_ID *sck; // Clock pin identifier
  123. PIN_ID *ws; // Word select pin identifier
  124. PIN_ID *sda; // Data pin identifier
  125. PIN_ID *mclk; // Master clock pin identifier
  126. } I2S_PINS;
  127. // I2S Reseurces definitions
  128. typedef struct {
  129. ARM_SAI_CAPABILITIES capabilities; // Capabilities
  130. LPC_I2Sn_Type *reg; // Pointer to I2S peripheral
  131. I2S_PINS rx_pins; // I2S receive pins configuration
  132. I2S_PINS tx_pins; // I2S transmit pins configuration
  133. IRQn_Type irq_num; // I2S IRQ Number
  134. I2S_DMA *dma_tx; // I2S TX DMA configuration
  135. I2S_DMA *dma_rx; // I2S RX DMA configuration
  136. uint8_t tx_fifo_level; // I2S transmit fifo level
  137. uint8_t rx_fifo_level; // I2S receive fifo level
  138. I2S_INFO *info; // Run-Time information
  139. } const I2S_RESOURCES;
  140. #endif // __I2S_LPC18XX_H