summaryrefslogtreecommitdiff
path: root/bsp/acm32/acm32f4xx-nucleo/libraries/HAL_Driver/Inc/HAL_I2S.h
blob: aa7ad5091c30533f1f06fdf5603225461a577527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
  ******************************************************************************
  * @file    HAL_I2S.h
  * @version V1.0.0
  * @date    2020
  * @brief   Header file of I2S HAL module.
  ******************************************************************************
*/

#ifndef __HAL_I2S_H__
#define __HAL_I2S_H__

#include "ACM32Fxx_HAL.h"

/************************************************************************************/
/*                             Registers Bits Definition                            */
/************************************************************************************/

/****************  Bit definition for I2S CTL Register  ***********************/
#define I2S_CTL_I2SEN               (BIT10)
#define I2S_CTL_I2SOPMOD            (BIT9|BIT8)
#define I2S_CTL_PCMSMOD             (BIT7)
#define I2S_CTL_I2SSTD              (BIT5|BIT4)
#define I2S_CTL_CKPL                (BIT3)
#define I2S_CTL_DTLEN               (BIT2|BIT1)
#define I2S_CTL_CHLEN               (BIT0)

/****************  Bit definition for I2S PSC Register  ***********************/
#define I2S_PSC_MCKOEN              (BIT10)
#define I2S_PSC_OF                  (BIT9)
#define I2S_PSC_DIV                 (0x1FF)

/****************  Bit definition for I2S DIE Register  ***********************/
#define I2S_DIE_TBEIE               (BIT7)
#define I2S_DIE_RBNEIE              (BIT6)
#define I2S_DIE_ERRIE               (BIT5)
#define I2S_DIE_DMATEN              (BIT1)
#define I2S_DIE_DMAREN              (BIT0)

/****************  Bit definition for I2S STATUS Register  ***********************/
#define I2S_STATUS_FERR             (BIT8)
#define I2S_STATUS_TRANS            (BIT7)
#define I2S_STATUS_RXORERR          (BIT6)
#define I2S_STATUS_TXURERR          (BIT3)
#define I2S_STATUS_I2SCH            (BIT2)
#define I2S_STATUS_TXBE             (BIT1)
#define I2S_STATUS_RXBNE            (BIT0)



/** @defgroup I2S_Mode I2S Mode
  * @{
  */
#define I2S_MODE_SLAVE_TX                (0x00000000)
#define I2S_MODE_SLAVE_RX                (0x00000100)
#define I2S_MODE_MASTER_TX               (0x00000200)
#define I2S_MODE_MASTER_RX               (I2S_CTL_I2SOPMOD)
/**
  * @}
  */


/** @defgroup I2S_Standard I2S Standard
  * @{
  */
#define I2S_STANDARD_PHILIPS             (0x00000000U)
#define I2S_STANDARD_MSB                 (0x00000010U)
#define I2S_STANDARD_LSB                 (0x00000020U)
#define I2S_STANDARD_PCM_SHORT           (I2S_CTL_I2SSTD)
#define I2S_STANDARD_PCM_LONG            (I2S_CTL_I2SSTD | I2S_CTL_PCMSMOD)
/**
  * @}
  */


/** @defgroup I2S_Data_Format I2S Data Format
  * @{
  */
#define I2S_DATAFORMAT_16B               (0x00000000U)
#define I2S_DATAFORMAT_16B_EXTENDED      (I2S_CTL_CHLEN)
#define I2S_DATAFORMAT_24B               (I2S_CTL_CHLEN | 0x02)
#define I2S_DATAFORMAT_32B               (I2S_CTL_CHLEN | 0x04)
/**
  * @}
  */


/** @defgroup I2S_MCLK_Output I2S MCLK Output
  * @{
  */
#define I2S_MCLKOUTPUT_ENABLE            (I2S_PSC_MCKOEN)
#define I2S_MCLKOUTPUT_DISABLE           (0x00000000U)
/**
  * @}
  */


/** @defgroup I2S_Clock_Polarity I2S Clock Polarity
  * @{
  */
#define I2S_CPOL_LOW                     (0x00000000U)
#define I2S_CPOL_HIGH                    (I2S_CTL_CKPL)
/**
  * @}
  */


/** @defgroup I2S_Audio_FrequencyOF I2S Clock Frequency OF
  * @{
  */
#define I2S_FREQ_OF_DISABLE              (0x00000000U)
#define I2S_FREQ_OF_ENABLE               (I2S_PSC_OF)
/**
  * @}
  */

/**
  * @brief  HAL State structures definition
  */
typedef enum
{
    HAL_I2S_STATE_RESET      = 0x00U,    /*!< I2S not yet initialized or disabled                */
    HAL_I2S_STATE_READY      = 0x01U,    /*!< I2S initialized and ready for use                  */
    HAL_I2S_STATE_BUSY       = 0x02U,    /*!< I2S internal process is ongoing                    */
    HAL_I2S_STATE_BUSY_TX    = 0x03U,    /*!< Data Transmission process is ongoing               */
    HAL_I2S_STATE_BUSY_RX    = 0x04U,    /*!< Data Reception process is ongoing                  */
    HAL_I2S_STATE_TIMEOUT    = 0x06U,    /*!< I2S timeout state                                  */
    HAL_I2S_STATE_ERROR      = 0x07U     /*!< I2S error state                                    */
}enum_I2S_State;


/**
  * @brief I2S Init structure definition
  */
typedef struct
{
    uint32_t u32_Mode;            /*!< Specifies the I2S operating mode.
                                       This parameter can be a value of @ref I2S_Mode */
    
    uint32_t u32_Standard;        /*!< Specifies the standard used for the I2S communication.
                                       This parameter can be a value of @ref I2S_Standard */
    
    uint32_t u32_DataFormat;      /*!< Specifies the data format for the I2S communication.
                                       This parameter can be a value of @ref I2S_Data_Format */
    
    uint32_t u32_MCLKOutput;      /*!< Specifies whether the I2S MCLK output is enabled or not.
                                       This parameter can be a value of @ref I2S_MCLK_Output */

    uint32_t u32_CPOL;            /*!< Specifies the idle state of the I2S clock.
                                       This parameter can be a value of @ref I2S_Clock_Polarity */

    uint32_t u32_FreqOF;          /*!< Specifies the frequency selected for the I2S communication.
                                       This parameter can be a value of @ref I2S_Audio_FrequencyFO */

    uint32_t u32_FreqDIV;         /*!< Specifies the frequency selected for the I2S communication.
                                       This parameter must be a number between Min_Data = 0x001 and Max_Data = 0x1FF */
}I2S_InitTypeDef;



/**
  * @brief I2S handle Structure definition
  */
typedef struct
{
    I2S_TypeDef           *Instance;     /*!< I2S registers base address */

    I2S_InitTypeDef        Init;         /*!< I2S communication parameters */

    enum_I2S_State         I2S_Status;

    uint32_t              *u32_Rx_Buffer;        /* I2S Rx Buffer */
    uint32_t              *u32_Tx_Buffer;        /* I2S Tx Buffer */
    
    uint32_t               u32_Rx_Size;          /* I2S Rx Size */
    uint32_t               u32_Tx_Size;          /* I2S Tx Size */
    
    uint32_t               u32_Rx_Count;         /* I2S RX Count */
    uint32_t               u32_Tx_Count;         /* I2S TX Count */

    DMA_HandleTypeDef   *HDMA_Rx;          /* SPI Rx DMA handle parameters */
    DMA_HandleTypeDef   *HDMA_Tx;          /* SPI Tx DMA handle parameters */

}I2S_HandleTypeDef;


/** @defgroup  RTC Private Macros
  * @{
  */
#define IS_I2S_MODE(__MODE__)             (((__MODE__) == I2S_MODE_SLAVE_TX)  || \
                                           ((__MODE__) == I2S_MODE_SLAVE_RX)  || \
                                           ((__MODE__) == I2S_MODE_MASTER_TX) || \
                                           ((__MODE__) == I2S_MODE_MASTER_RX))

#define IS_I2S_STANDARD(__STANDARD__)     (((__STANDARD__) == I2S_STANDARD_PHILIPS)   || \
                                           ((__STANDARD__) == I2S_STANDARD_MSB)       || \
                                           ((__STANDARD__) == I2S_STANDARD_LSB)       || \
                                           ((__STANDARD__) == I2S_STANDARD_PCM_SHORT) || \
                                           ((__STANDARD__) == I2S_STANDARD_PCM_LONG))
                                           
#define IS_I2S_DATAFORMAT(__DATAFORMAT__)       (((__DATAFORMAT__) == I2S_DATAFORMAT_16B)           || \
                                                 ((__DATAFORMAT__) == I2S_DATAFORMAT_16B_EXTENDED)  || \
                                                 ((__DATAFORMAT__) == I2S_DATAFORMAT_24B)           || \
                                                 ((__DATAFORMAT__) == I2S_DATAFORMAT_32B))

#define IS_I2S_MCLK_OUTPUT(__MCLK_OUTPUT__)     (((__MCLK_OUTPUT__) == I2S_MCLKOUTPUT_ENABLE)  || \
                                                 ((__MCLK_OUTPUT__) == I2S_MCLKOUTPUT_DISABLE))

#define IS_I2S_MCLK_CPOL(__CPOL__)              (((__CPOL__) == I2S_CPOL_LOW)  || \
                                                 ((__CPOL__) == I2S_CPOL_HIGH))

#define IS_I2S_OF(__OF__)                       (((__OF__) == I2S_FREQ_OF_DISABLE)  || \
                                                 ((__OF__) == I2S_FREQ_OF_ENABLE))

#define IS_I2S_DIV(__DIV__)                      ((__DIV__) >= 0x001 && (__DIV__) <= 0x1FF)
/**
  * @}
  */

/* HAL_I2S_IRQHandler */
void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s);

/* HAL_I2S_MspInit */
void HAL_I2S_MspInit(I2S_HandleTypeDef *hspi);

/* HAL_I2S_Init */
HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s);

/* HAL_I2S_Transmit */
HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size, uint32_t fu32_Timeout);

/* HAL_I2S_Receive */
HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size, uint32_t fu32_Timeout);

/* HAL_I2S_Transmit_IT */
HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);

/* HAL_I2S_Receive_IT */
HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);

/* HAL_I2S_Transmit_DMA */
HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);

/* HAL_I2S_Receive_DMA */
HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);

#endif