ChibiOS/HAL  6.1.0
hal_i2s_lld.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_lld.h
19  * @brief PLATFORM I2S subsystem low level driver header.
20  *
21  * @addtogroup I2S
22  * @{
23  */
24 
25 #ifndef HAL_I2S_LLD_H
26 #define HAL_I2S_LLD_H
27 
28 #if (HAL_USE_I2S == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /*===========================================================================*/
35 /* Driver pre-compile time settings. */
36 /*===========================================================================*/
37 
38 /**
39  * @name PLATFORM configuration options
40  * @{
41  */
42 /**
43  * @brief I2SD1 driver enable switch.
44  * @details If set to @p TRUE the support for I2S1 is included.
45  * @note The default is @p FALSE.
46  */
47 #if !defined(PLATFORM_I2S_USE_I2S1) || defined(__DOXYGEN__)
48 #define PLATFORM_I2S_USE_I2S1 FALSE
49 #endif
50 /** @} */
51 
52 /*===========================================================================*/
53 /* Derived constants and error checks. */
54 /*===========================================================================*/
55 
56 /*===========================================================================*/
57 /* Driver data structures and types. */
58 /*===========================================================================*/
59 
60 /**
61  * @brief Type of a structure representing an I2S driver.
62  */
63 typedef struct I2SDriver I2SDriver;
64 
65 /**
66  * @brief I2S notification callback type.
67  *
68  * @param[in] i2sp pointer to the @p I2SDriver object
69  * @param[in] offset offset in buffers of the data to read/write
70  * @param[in] n number of samples to read/write
71  */
72 typedef void (*i2scallback_t)(I2SDriver *i2sp, size_t offset, size_t n);
73 
74 /**
75  * @brief Driver configuration structure.
76  * @note It could be empty on some architectures.
77  */
78 typedef struct {
79  /**
80  * @brief Transmission buffer pointer.
81  * @note Can be @p NULL if TX is not required.
82  */
83  const void *tx_buffer;
84  /**
85  * @brief Receive buffer pointer.
86  * @note Can be @p NULL if RX is not required.
87  */
88  void *rx_buffer;
89  /**
90  * @brief TX and RX buffers size as number of samples.
91  */
92  size_t size;
93  /**
94  * @brief Callback function called during streaming.
95  */
97  /* End of the mandatory fields.*/
98 } I2SConfig;
99 
100 /**
101  * @brief Structure representing an I2S driver.
102  */
103 struct I2SDriver {
104  /**
105  * @brief Driver state.
106  */
108  /**
109  * @brief Current configuration data.
110  */
112  /* End of the mandatory fields.*/
113 };
114 
115 /*===========================================================================*/
116 /* Driver macros. */
117 /*===========================================================================*/
118 
119 /*===========================================================================*/
120 /* External declarations. */
121 /*===========================================================================*/
122 
123 #if (PLATFORM_I2S_USE_I2S1 == TRUE) && !defined(__DOXYGEN__)
124 extern I2SDriver I2SD1;
125 #endif
126 
127 #ifdef __cplusplus
128 extern "C" {
129 #endif
130  void i2s_lld_init(void);
131  void i2s_lld_start(I2SDriver *i2sp);
132  void i2s_lld_stop(I2SDriver *i2sp);
133  void i2s_lld_start_exchange(I2SDriver *i2sp);
134  void i2s_lld_stop_exchange(I2SDriver *i2sp);
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /* HAL_USE_I2S == TRUE */
140 
141 #endif /* HAL_I2S_LLD_H */
142 
143 /** @} */
I2SDriver I2SD1
I2S2 driver identifier.
Definition: hal_i2s_lld.c:39
i2sstate_t
Driver state machine possible states.
Definition: hal_i2s.h:57
void i2s_lld_init(void)
Low level I2S driver initialization.
Definition: hal_i2s_lld.c:63
void i2s_lld_stop(I2SDriver *i2sp)
Deactivates the I2S peripheral.
Definition: hal_i2s_lld.c:97
Driver configuration structure.
Definition: hal_i2s_lld.h:78
void(* i2scallback_t)(I2SDriver *i2sp, size_t offset, size_t n)
I2S notification callback type.
Definition: hal_i2s_lld.h:72
const void * tx_buffer
Transmission buffer pointer.
Definition: hal_i2s_lld.h:83
Structure representing an I2S driver.
Definition: hal_i2s_lld.h:103
i2sstate_t state
Driver state.
Definition: hal_i2s_lld.h:107
void i2s_lld_start_exchange(I2SDriver *i2sp)
Starts a I2S data exchange.
Definition: hal_i2s_lld.c:116
void * rx_buffer
Receive buffer pointer.
Definition: hal_i2s_lld.h:88
i2scallback_t end_cb
Callback function called during streaming.
Definition: hal_i2s_lld.h:96
const I2SConfig * config
Current configuration data.
Definition: hal_i2s_lld.h:111
void i2s_lld_stop_exchange(I2SDriver *i2sp)
Stops the ongoing data exchange.
Definition: hal_i2s_lld.c:130
void i2s_lld_start(I2SDriver *i2sp)
Configures and activates the I2S peripheral.
Definition: hal_i2s_lld.c:77
size_t size
TX and RX buffers size as number of samples.
Definition: hal_i2s_lld.h:92