diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/CMSIS/Driver/Include/Driver_I2C.h')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/CMSIS/Driver/Include/Driver_I2C.h | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/CMSIS/Driver/Include/Driver_I2C.h b/lib/chibios-contrib/ext/mcux-sdk/CMSIS/Driver/Include/Driver_I2C.h new file mode 100644 index 000000000..b9ba9d025 --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/CMSIS/Driver/Include/Driver_I2C.h | |||
@@ -0,0 +1,217 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2013-2017 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: 2. Feb 2017 | ||
19 | * $Revision: V2.3 | ||
20 | * | ||
21 | * Project: I2C (Inter-Integrated Circuit) Driver definitions | ||
22 | */ | ||
23 | |||
24 | /* History: | ||
25 | * Version 2.3 | ||
26 | * ARM_I2C_STATUS made volatile | ||
27 | * Version 2.2 | ||
28 | * Removed function ARM_I2C_MasterTransfer in order to simplify drivers | ||
29 | * and added back parameter "xfer_pending" to functions | ||
30 | * ARM_I2C_MasterTransmit and ARM_I2C_MasterReceive | ||
31 | * Version 2.1 | ||
32 | * Added function ARM_I2C_MasterTransfer and removed parameter "xfer_pending" | ||
33 | * from functions ARM_I2C_MasterTransmit and ARM_I2C_MasterReceive | ||
34 | * Added function ARM_I2C_GetDataCount | ||
35 | * Removed flag "address_nack" from ARM_I2C_STATUS | ||
36 | * Replaced events ARM_I2C_EVENT_MASTER_DONE and ARM_I2C_EVENT_SLAVE_DONE | ||
37 | * with event ARM_I2C_EVENT_TRANSFER_DONE | ||
38 | * Added event ARM_I2C_EVENT_TRANSFER_INCOMPLETE | ||
39 | * Removed parameter "arg" from function ARM_I2C_SignalEvent | ||
40 | * Version 2.0 | ||
41 | * New simplified driver: | ||
42 | * complexity moved to upper layer (especially data handling) | ||
43 | * more unified API for different communication interfaces | ||
44 | * Added: | ||
45 | * Slave Mode | ||
46 | * Changed prefix ARM_DRV -> ARM_DRIVER | ||
47 | * Version 1.10 | ||
48 | * Namespace prefix ARM_ added | ||
49 | * Version 1.00 | ||
50 | * Initial release | ||
51 | */ | ||
52 | |||
53 | #ifndef DRIVER_I2C_H_ | ||
54 | #define DRIVER_I2C_H_ | ||
55 | |||
56 | #ifdef __cplusplus | ||
57 | extern "C" | ||
58 | { | ||
59 | #endif | ||
60 | |||
61 | #include "Driver_Common.h" | ||
62 | |||
63 | #define ARM_I2C_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,3) /* API version */ | ||
64 | |||
65 | |||
66 | /****** I2C Control Codes *****/ | ||
67 | |||
68 | #define ARM_I2C_OWN_ADDRESS (0x01) ///< Set Own Slave Address; arg = address | ||
69 | #define ARM_I2C_BUS_SPEED (0x02) ///< Set Bus Speed; arg = speed | ||
70 | #define ARM_I2C_BUS_CLEAR (0x03) ///< Execute Bus clear: send nine clock pulses | ||
71 | #define ARM_I2C_ABORT_TRANSFER (0x04) ///< Abort Master/Slave Transmit/Receive | ||
72 | |||
73 | /*----- I2C Bus Speed -----*/ | ||
74 | #define ARM_I2C_BUS_SPEED_STANDARD (0x01) ///< Standard Speed (100kHz) | ||
75 | #define ARM_I2C_BUS_SPEED_FAST (0x02) ///< Fast Speed (400kHz) | ||
76 | #define ARM_I2C_BUS_SPEED_FAST_PLUS (0x03) ///< Fast+ Speed ( 1MHz) | ||
77 | #define ARM_I2C_BUS_SPEED_HIGH (0x04) ///< High Speed (3.4MHz) | ||
78 | |||
79 | |||
80 | /****** I2C Address Flags *****/ | ||
81 | |||
82 | #define ARM_I2C_ADDRESS_10BIT (0x0400) ///< 10-bit address flag | ||
83 | #define ARM_I2C_ADDRESS_GC (0x8000) ///< General Call flag | ||
84 | |||
85 | |||
86 | /** | ||
87 | \brief I2C Status | ||
88 | */ | ||
89 | typedef volatile struct _ARM_I2C_STATUS { | ||
90 | uint32_t busy : 1; ///< Busy flag | ||
91 | uint32_t mode : 1; ///< Mode: 0=Slave, 1=Master | ||
92 | uint32_t direction : 1; ///< Direction: 0=Transmitter, 1=Receiver | ||
93 | uint32_t general_call : 1; ///< General Call indication (cleared on start of next Slave operation) | ||
94 | uint32_t arbitration_lost : 1; ///< Master lost arbitration (cleared on start of next Master operation) | ||
95 | uint32_t bus_error : 1; ///< Bus error detected (cleared on start of next Master/Slave operation) | ||
96 | uint32_t reserved : 26; | ||
97 | } ARM_I2C_STATUS; | ||
98 | |||
99 | |||
100 | /****** I2C Event *****/ | ||
101 | #define ARM_I2C_EVENT_TRANSFER_DONE (1UL << 0) ///< Master/Slave Transmit/Receive finished | ||
102 | #define ARM_I2C_EVENT_TRANSFER_INCOMPLETE (1UL << 1) ///< Master/Slave Transmit/Receive incomplete transfer | ||
103 | #define ARM_I2C_EVENT_SLAVE_TRANSMIT (1UL << 2) ///< Addressed as Slave Transmitter but transmit operation is not set. | ||
104 | #define ARM_I2C_EVENT_SLAVE_RECEIVE (1UL << 3) ///< Addressed as Slave Receiver but receive operation is not set. | ||
105 | #define ARM_I2C_EVENT_ADDRESS_NACK (1UL << 4) ///< Address not acknowledged from Slave | ||
106 | #define ARM_I2C_EVENT_GENERAL_CALL (1UL << 5) ///< Slave addressed with general call address | ||
107 | #define ARM_I2C_EVENT_ARBITRATION_LOST (1UL << 6) ///< Master lost arbitration | ||
108 | #define ARM_I2C_EVENT_BUS_ERROR (1UL << 7) ///< Bus error detected (START/STOP at illegal position) | ||
109 | #define ARM_I2C_EVENT_BUS_CLEAR (1UL << 8) ///< Bus clear finished | ||
110 | |||
111 | |||
112 | // Function documentation | ||
113 | /** | ||
114 | \fn ARM_DRIVER_VERSION ARM_I2C_GetVersion (void) | ||
115 | \brief Get driver version. | ||
116 | \return \ref ARM_DRIVER_VERSION | ||
117 | |||
118 | \fn ARM_I2C_CAPABILITIES ARM_I2C_GetCapabilities (void) | ||
119 | \brief Get driver capabilities. | ||
120 | \return \ref ARM_I2C_CAPABILITIES | ||
121 | |||
122 | \fn int32_t ARM_I2C_Initialize (ARM_I2C_SignalEvent_t cb_event) | ||
123 | \brief Initialize I2C Interface. | ||
124 | \param[in] cb_event Pointer to \ref ARM_I2C_SignalEvent | ||
125 | \return \ref execution_status | ||
126 | |||
127 | \fn int32_t ARM_I2C_Uninitialize (void) | ||
128 | \brief De-initialize I2C Interface. | ||
129 | \return \ref execution_status | ||
130 | |||
131 | \fn int32_t ARM_I2C_PowerControl (ARM_POWER_STATE state) | ||
132 | \brief Control I2C Interface Power. | ||
133 | \param[in] state Power state | ||
134 | \return \ref execution_status | ||
135 | |||
136 | \fn int32_t ARM_I2C_MasterTransmit (uint32_t addr, const uint8_t *data, uint32_t num, bool xfer_pending) | ||
137 | \brief Start transmitting data as I2C Master. | ||
138 | \param[in] addr Slave address (7-bit or 10-bit) | ||
139 | \param[in] data Pointer to buffer with data to transmit to I2C Slave | ||
140 | \param[in] num Number of data bytes to transmit | ||
141 | \param[in] xfer_pending Transfer operation is pending - Stop condition will not be generated | ||
142 | \return \ref execution_status | ||
143 | |||
144 | \fn int32_t ARM_I2C_MasterReceive (uint32_t addr, uint8_t *data, uint32_t num, bool xfer_pending) | ||
145 | \brief Start receiving data as I2C Master. | ||
146 | \param[in] addr Slave address (7-bit or 10-bit) | ||
147 | \param[out] data Pointer to buffer for data to receive from I2C Slave | ||
148 | \param[in] num Number of data bytes to receive | ||
149 | \param[in] xfer_pending Transfer operation is pending - Stop condition will not be generated | ||
150 | \return \ref execution_status | ||
151 | |||
152 | \fn int32_t ARM_I2C_SlaveTransmit (const uint8_t *data, uint32_t num) | ||
153 | \brief Start transmitting data as I2C Slave. | ||
154 | \param[in] data Pointer to buffer with data to transmit to I2C Master | ||
155 | \param[in] num Number of data bytes to transmit | ||
156 | \return \ref execution_status | ||
157 | |||
158 | \fn int32_t ARM_I2C_SlaveReceive (uint8_t *data, uint32_t num) | ||
159 | \brief Start receiving data as I2C Slave. | ||
160 | \param[out] data Pointer to buffer for data to receive from I2C Master | ||
161 | \param[in] num Number of data bytes to receive | ||
162 | \return \ref execution_status | ||
163 | |||
164 | \fn int32_t ARM_I2C_GetDataCount (void) | ||
165 | \brief Get transferred data count. | ||
166 | \return number of data bytes transferred; -1 when Slave is not addressed by Master | ||
167 | |||
168 | \fn int32_t ARM_I2C_Control (uint32_t control, uint32_t arg) | ||
169 | \brief Control I2C Interface. | ||
170 | \param[in] control Operation | ||
171 | \param[in] arg Argument of operation (optional) | ||
172 | \return \ref execution_status | ||
173 | |||
174 | \fn ARM_I2C_STATUS ARM_I2C_GetStatus (void) | ||
175 | \brief Get I2C status. | ||
176 | \return I2C status \ref ARM_I2C_STATUS | ||
177 | |||
178 | \fn void ARM_I2C_SignalEvent (uint32_t event) | ||
179 | \brief Signal I2C Events. | ||
180 | \param[in] event \ref I2C_events notification mask | ||
181 | */ | ||
182 | |||
183 | typedef void (*ARM_I2C_SignalEvent_t) (uint32_t event); ///< Pointer to \ref ARM_I2C_SignalEvent : Signal I2C Event. | ||
184 | |||
185 | |||
186 | /** | ||
187 | \brief I2C Driver Capabilities. | ||
188 | */ | ||
189 | typedef struct _ARM_I2C_CAPABILITIES { | ||
190 | uint32_t address_10_bit : 1; ///< supports 10-bit addressing | ||
191 | uint32_t reserved : 31; ///< Reserved (must be zero) | ||
192 | } ARM_I2C_CAPABILITIES; | ||
193 | |||
194 | |||
195 | /** | ||
196 | \brief Access structure of the I2C Driver. | ||
197 | */ | ||
198 | typedef struct _ARM_DRIVER_I2C { | ||
199 | ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_I2C_GetVersion : Get driver version. | ||
200 | ARM_I2C_CAPABILITIES (*GetCapabilities)(void); ///< Pointer to \ref ARM_I2C_GetCapabilities : Get driver capabilities. | ||
201 | int32_t (*Initialize) (ARM_I2C_SignalEvent_t cb_event); ///< Pointer to \ref ARM_I2C_Initialize : Initialize I2C Interface. | ||
202 | int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_I2C_Uninitialize : De-initialize I2C Interface. | ||
203 | int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_I2C_PowerControl : Control I2C Interface Power. | ||
204 | int32_t (*MasterTransmit) (uint32_t addr, const uint8_t *data, uint32_t num, bool xfer_pending); ///< Pointer to \ref ARM_I2C_MasterTransmit : Start transmitting data as I2C Master. | ||
205 | int32_t (*MasterReceive) (uint32_t addr, uint8_t *data, uint32_t num, bool xfer_pending); ///< Pointer to \ref ARM_I2C_MasterReceive : Start receiving data as I2C Master. | ||
206 | int32_t (*SlaveTransmit) ( const uint8_t *data, uint32_t num); ///< Pointer to \ref ARM_I2C_SlaveTransmit : Start transmitting data as I2C Slave. | ||
207 | int32_t (*SlaveReceive) ( uint8_t *data, uint32_t num); ///< Pointer to \ref ARM_I2C_SlaveReceive : Start receiving data as I2C Slave. | ||
208 | int32_t (*GetDataCount) (void); ///< Pointer to \ref ARM_I2C_GetDataCount : Get transferred data count. | ||
209 | int32_t (*Control) (uint32_t control, uint32_t arg); ///< Pointer to \ref ARM_I2C_Control : Control I2C Interface. | ||
210 | ARM_I2C_STATUS (*GetStatus) (void); ///< Pointer to \ref ARM_I2C_GetStatus : Get I2C status. | ||
211 | } const ARM_DRIVER_I2C; | ||
212 | |||
213 | #ifdef __cplusplus | ||
214 | } | ||
215 | #endif | ||
216 | |||
217 | #endif /* DRIVER_I2C_H_ */ | ||