ChibiOS/HAL  6.1.0
hal_i2s.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_i2s.h
19  * @brief I2S Driver macros and structures.
20  *
21  * @addtogroup I2S
22  * @{
23  */
24 
25 #ifndef HAL_I2S_H
26 #define HAL_I2S_H
27 
28 #if (HAL_USE_I2S == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /**
35  * @name I2S modes
36  * @{
37  */
38 #define I2S_MODE_SLAVE 0
39 #define I2S_MODE_MASTER 1
40 /** @} */
41 
42 /*===========================================================================*/
43 /* Driver pre-compile time settings. */
44 /*===========================================================================*/
45 
46 /*===========================================================================*/
47 /* Derived constants and error checks. */
48 /*===========================================================================*/
49 
50 /*===========================================================================*/
51 /* Driver data structures and types. */
52 /*===========================================================================*/
53 
54 /**
55  * @brief Driver state machine possible states.
56  */
57 typedef enum {
58  I2S_UNINIT = 0, /**< Not initialized. */
59  I2S_STOP = 1, /**< Stopped. */
60  I2S_READY = 2, /**< Ready. */
61  I2S_ACTIVE = 3, /**< Active. */
62  I2S_COMPLETE = 4 /**< Transmission complete. */
63 } i2sstate_t;
64 
65 #include "hal_i2s_lld.h"
66 
67 /*===========================================================================*/
68 /* Driver macros. */
69 /*===========================================================================*/
70 
71 /**
72  * @name Macro Functions
73  * @{
74  */
75 /**
76  * @brief Starts a I2S data exchange.
77  *
78  * @param[in] i2sp pointer to the @p I2SDriver object
79  *
80  * @iclass
81  */
82 #define i2sStartExchangeI(i2sp) { \
83  i2s_lld_start_exchange(i2sp); \
84  (i2sp)->state = I2S_ACTIVE; \
85 }
86 
87 /**
88  * @brief Stops the ongoing data exchange.
89  * @details The ongoing data exchange, if any, is stopped, if the driver
90  * was not active the function does nothing.
91  *
92  * @param[in] i2sp pointer to the @p I2SDriver object
93  *
94  * @iclass
95  */
96 #define i2sStopExchangeI(i2sp) { \
97  i2s_lld_stop_exchange(i2sp); \
98  (i2sp)->state = I2S_READY; \
99 }
100 
101 /**
102  * @brief Common ISR code, half buffer event.
103  * @details This code handles the portable part of the ISR code:
104  * - Callback invocation.
105  * .
106  * @note This macro is meant to be used in the low level drivers
107  * implementation only.
108  *
109  * @param[in] i2sp pointer to the @p I2CDriver object
110  *
111  * @notapi
112  */
113 #define _i2s_isr_half_code(i2sp) { \
114  if ((i2sp)->config->end_cb != NULL) { \
115  (i2sp)->config->end_cb(i2sp, 0, (i2sp)->config->size / 2); \
116  } \
117 }
118 
119 /**
120  * @brief Common ISR code.
121  * @details This code handles the portable part of the ISR code:
122  * - Callback invocation.
123  * - Driver state transitions.
124  * .
125  * @note This macro is meant to be used in the low level drivers
126  * implementation only.
127  *
128  * @param[in] i2sp pointer to the @p I2CDriver object
129  *
130  * @notapi
131  */
132 #define _i2s_isr_full_code(i2sp) { \
133  if ((i2sp)->config->end_cb) { \
134  (i2sp)->state = I2S_COMPLETE; \
135  (i2sp)->config->end_cb(i2sp, \
136  (i2sp)->config->size / 2, \
137  (i2sp)->config->size / 2); \
138  if ((i2sp)->state == I2S_COMPLETE) { \
139  (i2sp)->state = I2S_ACTIVE; \
140  } \
141  } \
142 }
143 /** @} */
144 
145 /*===========================================================================*/
146 /* External declarations. */
147 /*===========================================================================*/
148 
149 #ifdef __cplusplus
150 extern "C" {
151 #endif
152  void i2sInit(void);
153  void i2sObjectInit(I2SDriver *i2sp);
154  void i2sStart(I2SDriver *i2sp, const I2SConfig *config);
155  void i2sStop(I2SDriver *i2sp);
156  void i2sStartExchange(I2SDriver *i2sp);
157  void i2sStopExchange(I2SDriver *i2sp);
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif /* HAL_USE_I2S == TRUE */
163 
164 #endif /* HAL_I2S_H */
165 
166 /** @} */
i2sstate_t
Driver state machine possible states.
Definition: hal_i2s.h:57
void i2sInit(void)
I2S Driver initialization.
Definition: hal_i2s.c:56
Driver configuration structure.
Definition: hal_i2s_lld.h:78
void i2sStop(I2SDriver *i2sp)
Deactivates the I2S peripheral.
Definition: hal_i2s.c:102
PLATFORM I2S subsystem low level driver header.
void i2sObjectInit(I2SDriver *i2sp)
Initializes the standard part of a I2SDriver structure.
Definition: hal_i2s.c:68
void i2sStartExchange(I2SDriver *i2sp)
Starts a I2S data exchange.
Definition: hal_i2s.c:125
Structure representing an I2S driver.
Definition: hal_i2s_lld.h:103
void i2sStart(I2SDriver *i2sp, const I2SConfig *config)
Configures and activates the I2S peripheral.
Definition: hal_i2s.c:82
void i2sStopExchange(I2SDriver *i2sp)
Stops the ongoing data exchange.
Definition: hal_i2s.c:144