|
1 |
commit a23878ddb85bb8fd069f02042f15ad4be2a0d709
|
|
2 |
Author: Marc Rothmann <mrothmann@techfak.uni-bielefeld.de>
|
|
3 |
Date: Mon Sep 17 11:40:39 2018 +0200
|
|
4 |
|
|
5 |
Added QEI driver to HAL.
|
|
6 |
|
|
7 |
diff --git a/os/hal/hal.mk b/os/hal/hal.mk
|
|
8 |
index f177a3f..64d96d9 100644
|
|
9 |
--- a/os/hal/hal.mk
|
|
10 |
+++ b/os/hal/hal.mk
|
|
11 |
@@ -41,6 +41,9 @@ endif
|
|
12 |
ifneq ($(findstring HAL_USE_ICU TRUE,$(HALCONF)),)
|
|
13 |
HALSRC += $(CHIBIOS)/os/hal/src/hal_icu.c
|
|
14 |
endif
|
|
15 |
+ifneq ($(findstring HAL_USE_QEI TRUE,$(HALCONF)),)
|
|
16 |
+HALSRC += $(CHIBIOS)/os/hal/src/hal_qei.c
|
|
17 |
+endif
|
|
18 |
ifneq ($(findstring HAL_USE_MAC TRUE,$(HALCONF)),)
|
|
19 |
HALSRC += $(CHIBIOS)/os/hal/src/hal_mac.c
|
|
20 |
endif
|
|
21 |
@@ -94,6 +97,7 @@ HALSRC = $(CHIBIOS)/os/hal/src/hal.c \
|
|
22 |
$(CHIBIOS)/os/hal/src/hal_i2c.c \
|
|
23 |
$(CHIBIOS)/os/hal/src/hal_i2s.c \
|
|
24 |
$(CHIBIOS)/os/hal/src/hal_icu.c \
|
|
25 |
+ $(CHIBIOS)/os/hal/src/hal_qei.c \
|
|
26 |
$(CHIBIOS)/os/hal/src/hal_mac.c \
|
|
27 |
$(CHIBIOS)/os/hal/src/hal_mmc_spi.c \
|
|
28 |
$(CHIBIOS)/os/hal/src/hal_pal.c \
|
|
29 |
diff --git a/os/hal/include/hal_qei.h b/os/hal/include/hal_qei.h
|
|
30 |
new file mode 100644
|
|
31 |
index 0000000..aef5e62
|
|
32 |
--- /dev/null
|
|
33 |
+++ b/os/hal/include/hal_qei.h
|
|
34 |
@@ -0,0 +1,148 @@
|
|
35 |
+/*
|
|
36 |
+AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
|
37 |
+Copyright (C) 2016..2018 Thomas Schöpping et al.
|
|
38 |
+
|
|
39 |
+This program is free software: you can redistribute it and/or modify
|
|
40 |
+it under the terms of the GNU General Public License as published by
|
|
41 |
+the Free Software Foundation, either version 3 of the License, or
|
|
42 |
+(at your option) any later version.
|
|
43 |
+
|
|
44 |
+This program is distributed in the hope that it will be useful,
|
|
45 |
+but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
46 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
47 |
+GNU General Public License for more details.
|
|
48 |
+
|
|
49 |
+You should have received a copy of the GNU General Public License
|
|
50 |
+along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
51 |
+*/
|
|
52 |
+
|
|
53 |
+/**
|
|
54 |
+ * @file hal_qei.h
|
|
55 |
+ * @brief QEI Driver macros and structures.
|
|
56 |
+ *
|
|
57 |
+ * @addtogroup QEI
|
|
58 |
+ * @{
|
|
59 |
+ */
|
|
60 |
+
|
|
61 |
+#ifndef _HAL_QEI_H_
|
|
62 |
+#define _HAL_QEI_H_
|
|
63 |
+
|
|
64 |
+#if HAL_USE_QEI || defined(__DOXYGEN__)
|
|
65 |
+
|
|
66 |
+/*===========================================================================*/
|
|
67 |
+/* Driver constants. */
|
|
68 |
+/*===========================================================================*/
|
|
69 |
+
|
|
70 |
+/*===========================================================================*/
|
|
71 |
+/* Driver pre-compile time settings. */
|
|
72 |
+/*===========================================================================*/
|
|
73 |
+
|
|
74 |
+/*===========================================================================*/
|
|
75 |
+/* Derived constants and error checks. */
|
|
76 |
+/*===========================================================================*/
|
|
77 |
+
|
|
78 |
+/*===========================================================================*/
|
|
79 |
+/* Driver data structures and types. */
|
|
80 |
+/*===========================================================================*/
|
|
81 |
+
|
|
82 |
+/**
|
|
83 |
+ * @brief Driver state machine possible states.
|
|
84 |
+ */
|
|
85 |
+typedef enum {
|
|
86 |
+ QEI_UNINIT = 0, /**< Not initialized. */
|
|
87 |
+ QEI_STOP = 1, /**< Stopped. */
|
|
88 |
+ QEI_READY = 2, /**< Ready. */
|
|
89 |
+ QEI_ACTIVE = 4, /**< Active. */
|
|
90 |
+} qeistate_t;
|
|
91 |
+
|
|
92 |
+/**
|
|
93 |
+ * @brief Type of a structure representing an QEI driver.
|
|
94 |
+ */
|
|
95 |
+typedef struct QEIDriver QEIDriver;
|
|
96 |
+
|
|
97 |
+#include "hal_qei_lld.h"
|
|
98 |
+
|
|
99 |
+/*===========================================================================*/
|
|
100 |
+/* Driver macros. */
|
|
101 |
+/*===========================================================================*/
|
|
102 |
+
|
|
103 |
+/**
|
|
104 |
+ * @name Macro Functions
|
|
105 |
+ * @{
|
|
106 |
+ */
|
|
107 |
+/**
|
|
108 |
+ * @brief Enables the quadrature encoder.
|
|
109 |
+ *
|
|
110 |
+ * @param[in] qeip pointer to the @p QEIDriver object
|
|
111 |
+ *
|
|
112 |
+ * @iclass
|
|
113 |
+ */
|
|
114 |
+#define qeiEnableI(qeip) qei_lld_enable(qeip)
|
|
115 |
+
|
|
116 |
+/**
|
|
117 |
+ * @brief Disables the quadrature encoder.
|
|
118 |
+ *
|
|
119 |
+ * @param[in] qeip pointer to the @p QEIDriver object
|
|
120 |
+ *
|
|
121 |
+ * @iclass
|
|
122 |
+ */
|
|
123 |
+#define qeiDisableI(qeip) qei_lld_disable(qeip)
|
|
124 |
+
|
|
125 |
+/**
|
|
126 |
+ * @brief Returns the direction of the last transition.
|
|
127 |
+ * @details The direction is defined as boolean and is
|
|
128 |
+ * calculated at each transition on any input.
|
|
129 |
+ *
|
|
130 |
+ * @param[in] qeip pointer to the @p QEIDriver object
|
|
131 |
+ * @return The request direction.
|
|
132 |
+ * @retval FALSE Position counted up.
|
|
133 |
+ * @retval TRUE Position counted down.
|
|
134 |
+ * @iclass
|
|
135 |
+ */
|
|
136 |
+#define qeiGetDirectionI(qeip) qei_lld_get_direction(qeip)
|
|
137 |
+
|
|
138 |
+/**
|
|
139 |
+ * @brief Returns the position of the encoder.
|
|
140 |
+ * @details The position is defined as number of pulses since last reset.
|
|
141 |
+ *
|
|
142 |
+ * @param[in] qeip pointer to the @p QEIDriver object
|
|
143 |
+ * @return The number of pulses.
|
|
144 |
+ *
|
|
145 |
+ * @iclass
|
|
146 |
+ */
|
|
147 |
+#define qeiGetPositionI(qeip) qei_lld_get_position(qeip)
|
|
148 |
+
|
|
149 |
+/**
|
|
150 |
+ * @brief Returns the range of the encoder.
|
|
151 |
+ * @details The range is defined as number of maximum pulse count.
|
|
152 |
+ *
|
|
153 |
+ * @param[in] qeip pointer to the @p QEIDriver object
|
|
154 |
+ * @return The number of pulses.
|
|
155 |
+ *
|
|
156 |
+ * @iclass
|
|
157 |
+ */
|
|
158 |
+#define qeiGetRangeI(qeip) qei_lld_get_range(qeip)
|
|
159 |
+/** @} */
|
|
160 |
+
|
|
161 |
+/*===========================================================================*/
|
|
162 |
+/* External declarations. */
|
|
163 |
+/*===========================================================================*/
|
|
164 |
+
|
|
165 |
+#ifdef __cplusplus
|
|
166 |
+extern "C" {
|
|
167 |
+#endif
|
|
168 |
+ void qeiInit(void);
|
|
169 |
+ void qeiObjectInit(QEIDriver *qeip);
|
|
170 |
+ void qeiStart(QEIDriver *qeip, const QEIConfig *config);
|
|
171 |
+ void qeiStop(QEIDriver *qeip);
|
|
172 |
+ void qeiEnable(QEIDriver *qeip);
|
|
173 |
+ void qeiDisable(QEIDriver *qeip);
|
|
174 |
+#ifdef __cplusplus
|
|
175 |
+}
|
|
176 |
+#endif
|
|
177 |
+
|
|
178 |
+#endif /* HAL_USE_QEI */
|
|
179 |
+
|
|
180 |
+#endif /* _HAL_QEI_H_ */
|
|
181 |
+
|
|
182 |
+/** @} */
|
|
183 |
diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
|
|
184 |
index 6ade226..96c9da0 100644
|
|
185 |
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
|
|
186 |
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
|
|
187 |
@@ -34,6 +34,7 @@
|
|
188 |
/* Driver local definitions. */
|
|
189 |
/*===========================================================================*/
|
|
190 |
|
|
191 |
+#if STM32_I2C_I2C1_USE_DMA
|
|
192 |
#define I2C1_RX_DMA_CHANNEL \
|
|
193 |
STM32_DMA_GETCHANNEL(STM32_I2C_I2C1_RX_DMA_STREAM, \
|
|
194 |
STM32_I2C1_RX_DMA_CHN)
|
|
195 |
@@ -41,7 +42,9 @@
|
|
196 |
#define I2C1_TX_DMA_CHANNEL \
|
|
197 |
STM32_DMA_GETCHANNEL(STM32_I2C_I2C1_TX_DMA_STREAM, \
|
|
198 |
STM32_I2C1_TX_DMA_CHN)
|
|
199 |
+#endif
|
|
200 |
|
|
201 |
+#if STM32_I2C_I2C2_USE_DMA
|
|
202 |
#define I2C2_RX_DMA_CHANNEL \
|
|
203 |
STM32_DMA_GETCHANNEL(STM32_I2C_I2C2_RX_DMA_STREAM, \
|
|
204 |
STM32_I2C2_RX_DMA_CHN)
|
|
205 |
@@ -49,7 +52,9 @@
|
|
206 |
#define I2C2_TX_DMA_CHANNEL \
|
|
207 |
STM32_DMA_GETCHANNEL(STM32_I2C_I2C2_TX_DMA_STREAM, \
|
|
208 |
STM32_I2C2_TX_DMA_CHN)
|
|
209 |
+#endif
|
|
210 |
|
|
211 |
+#if STM32_I2C_I2C3_USE_DMA
|
|
212 |
#define I2C3_RX_DMA_CHANNEL \
|
|
213 |
STM32_DMA_GETCHANNEL(STM32_I2C_I2C3_RX_DMA_STREAM, \
|
|
214 |
STM32_I2C3_RX_DMA_CHN)
|
|
215 |
@@ -57,6 +62,7 @@
|
|
216 |
#define I2C3_TX_DMA_CHANNEL \
|
|
217 |
STM32_DMA_GETCHANNEL(STM32_I2C_I2C3_TX_DMA_STREAM, \
|
|
218 |
STM32_I2C3_TX_DMA_CHN)
|
|
219 |
+#endif
|
|
220 |
|
|
221 |
/*===========================================================================*/
|
|
222 |
/* Driver constants. */
|
|
223 |
@@ -72,6 +78,20 @@
|
|
224 |
#define I2C_EV6_MASTER_REC_MODE_SELECTED \
|
|
225 |
((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) | I2C_SR1_ADDR))
|
|
226 |
|
|
227 |
+#define I2C_EV7_MASTER_REC_BYTE_RECEIVED \
|
|
228 |
+ ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) | I2C_SR1_RXNE))
|
|
229 |
+
|
|
230 |
+#define I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP \
|
|
231 |
+ ((uint32_t)(I2C_SR1_RXNE))
|
|
232 |
+
|
|
233 |
+#define I2C_EV7_2_EV7_3_MASTER_REC_BYTE_QUEUED \
|
|
234 |
+ ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) | \
|
|
235 |
+ I2C_SR1_BTF | I2C_SR1_RXNE))
|
|
236 |
+
|
|
237 |
+#define I2C_EV8_MASTER_BYTE_TRANSMITTING \
|
|
238 |
+ ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY | I2C_SR2_TRA)<< 16) | \
|
|
239 |
+ I2C_SR1_TXE))
|
|
240 |
+
|
|
241 |
#define I2C_EV8_2_MASTER_BYTE_TRANSMITTED \
|
|
242 |
((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY | I2C_SR2_TRA) << 16) | \
|
|
243 |
I2C_SR1_BTF | I2C_SR1_TXE))
|
|
244 |
@@ -129,8 +149,24 @@ static void i2c_lld_abort_operation(I2CDriver *i2cp) {
|
|
245 |
dp->SR1 = 0;
|
|
246 |
|
|
247 |
/* Stops the associated DMA streams.*/
|
|
248 |
- dmaStreamDisable(i2cp->dmatx);
|
|
249 |
- dmaStreamDisable(i2cp->dmarx);
|
|
250 |
+#if STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA
|
|
251 |
+ if (&I2CD1 == i2cp) {
|
|
252 |
+ dmaStreamDisable(i2cp->dmatx);
|
|
253 |
+ dmaStreamDisable(i2cp->dmarx);
|
|
254 |
+ }
|
|
255 |
+#endif
|
|
256 |
+#if STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA
|
|
257 |
+ if (&I2CD2 == i2cp) {
|
|
258 |
+ dmaStreamDisable(i2cp->dmatx);
|
|
259 |
+ dmaStreamDisable(i2cp->dmarx);
|
|
260 |
+ }
|
|
261 |
+#endif
|
|
262 |
+#if STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA
|
|
263 |
+ if (&I2CD3 == i2cp) {
|
|
264 |
+ dmaStreamDisable(i2cp->dmatx);
|
|
265 |
+ dmaStreamDisable(i2cp->dmarx);
|
|
266 |
+ }
|
|
267 |
+#endif
|
|
268 |
}
|
|
269 |
|
|
270 |
/**
|
|
271 |
@@ -236,13 +272,17 @@ static void i2c_lld_set_opmode(I2CDriver *i2cp) {
|
|
272 |
}
|
|
273 |
|
|
274 |
/**
|
|
275 |
- * @brief I2C shared ISR code.
|
|
276 |
+ * @brief I2C shared ISR code for DMA access.
|
|
277 |
*
|
|
278 |
* @param[in] i2cp pointer to the @p I2CDriver object
|
|
279 |
*
|
|
280 |
* @notapi
|
|
281 |
*/
|
|
282 |
-static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
|
|
283 |
+#if (STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA) || \
|
|
284 |
+ (STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA) || \
|
|
285 |
+ (STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA) || \
|
|
286 |
+ defined(__DOXYGEN__)
|
|
287 |
+static void i2c_lld_serve_event_interrupt_dma(I2CDriver *i2cp) {
|
|
288 |
I2C_TypeDef *dp = i2cp->i2c;
|
|
289 |
uint32_t regSR2 = dp->SR2;
|
|
290 |
uint32_t event = dp->SR1;
|
|
291 |
@@ -252,7 +292,7 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
|
|
292 |
done by the DMA.*/
|
|
293 |
switch (I2C_EV_MASK & (event | (regSR2 << 16))) {
|
|
294 |
case I2C_EV5_MASTER_MODE_SELECT:
|
|
295 |
- if ((i2cp->addr >> 8) > 0) {
|
|
296 |
+ if ((i2cp->addr >> 8) > 0) {
|
|
297 |
/* 10-bit address: 1 1 1 1 0 X X R/W */
|
|
298 |
dp->DR = 0xF0 | (0x6 & (i2cp->addr >> 8)) | (0x1 & i2cp->addr);
|
|
299 |
} else {
|
|
300 |
@@ -293,6 +333,140 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
|
|
301 |
if (event & (I2C_SR1_ADDR | I2C_SR1_ADD10))
|
|
302 |
(void)dp->SR2;
|
|
303 |
}
|
|
304 |
+#endif /* any I2CDx uses DMA mode */
|
|
305 |
+
|
|
306 |
+/**
|
|
307 |
+ * @brief I2C shared ISR code for non-DMA access.
|
|
308 |
+ *
|
|
309 |
+ * @param[in] i2cp pointer to the @p I2CDriver object
|
|
310 |
+ *
|
|
311 |
+ * @notapi
|
|
312 |
+ */
|
|
313 |
+#if (STM32_I2C_USE_I2C1 && !STM32_I2C_I2C1_USE_DMA) || \
|
|
314 |
+ (STM32_I2C_USE_I2C2 && !STM32_I2C_I2C2_USE_DMA) || \
|
|
315 |
+ (STM32_I2C_USE_I2C3 && !STM32_I2C_I2C3_USE_DMA) || \
|
|
316 |
+ defined(__DOXYGEN__)
|
|
317 |
+static void i2c_lld_serve_event_interrupt_isr(I2CDriver *i2cp) {
|
|
318 |
+ I2C_TypeDef *dp = i2cp->i2c;
|
|
319 |
+ uint32_t regSR2 = dp->SR2;
|
|
320 |
+ uint32_t event = dp->SR1;
|
|
321 |
+
|
|
322 |
+ switch (I2C_EV_MASK & (event | (regSR2 << 16))) {
|
|
323 |
+ case I2C_EV5_MASTER_MODE_SELECT:
|
|
324 |
+ dp->CR2 |= I2C_CR2_ITBUFEN;
|
|
325 |
+ dp->DR = i2cp->addr;
|
|
326 |
+ break;
|
|
327 |
+ case I2C_EV6_MASTER_TRA_MODE_SELECTED:
|
|
328 |
+ (void)dp->SR2; // clear ADDR flag
|
|
329 |
+ /* EV8_1 */
|
|
330 |
+ dp->DR = *(i2cp->txbuf);
|
|
331 |
+
|
|
332 |
+ ++i2cp->txbuf;
|
|
333 |
+ --i2cp->txbytes;
|
|
334 |
+
|
|
335 |
+ /* if N == 1, skip the I2C_EV8_MASTER_BYTE_TRANSMITTING event
|
|
336 |
+ * but enter I2C_EV8_2_MASTER_BYTE_TRANSMITTED next */
|
|
337 |
+ if (i2cp->txbytes == 0) {
|
|
338 |
+ dp->CR2 &= ~I2C_CR2_ITBUFEN;
|
|
339 |
+ }
|
|
340 |
+ break;
|
|
341 |
+ case I2C_EV6_MASTER_REC_MODE_SELECTED:
|
|
342 |
+ switch (i2cp->rxbytes) {
|
|
343 |
+ case 1:
|
|
344 |
+ dp->CR1 &= ~I2C_CR1_ACK;
|
|
345 |
+ (void)dp->SR2; // clear ADDR flag
|
|
346 |
+ dp->CR1 |= I2C_CR1_STOP;
|
|
347 |
+ break;
|
|
348 |
+ case 2:
|
|
349 |
+ (void)dp->SR2; // clear ADDR flag
|
|
350 |
+ /* EV6_1 */
|
|
351 |
+ dp->CR1 |= I2C_CR1_POS;
|
|
352 |
+ dp->CR1 &= ~I2C_CR1_ACK;
|
|
353 |
+ dp->CR2 &= ~I2C_CR2_ITBUFEN;
|
|
354 |
+ break;
|
|
355 |
+ case 3: /* N == 3 is a very special case, since EV7 is completely skipped */
|
|
356 |
+ (void)dp->SR2; // clear ADDR flag
|
|
357 |
+ /* Disable the I2C_EV7_MASTER_REC_BYTE_RECEIVED event
|
|
358 |
+ * but enter I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP next */
|
|
359 |
+ dp->CR2 &= ~I2C_CR2_ITBUFEN;
|
|
360 |
+ break;
|
|
361 |
+ default: /* N > 2 */
|
|
362 |
+ (void)dp->SR2; // clear ADDR flag
|
|
363 |
+ break;
|
|
364 |
+ }
|
|
365 |
+ break;
|
|
366 |
+ case I2C_EV7_MASTER_REC_BYTE_RECEIVED:
|
|
367 |
+ if (i2cp->rxbytes > 3) {
|
|
368 |
+ *(i2cp->rxbuf) = dp->DR;
|
|
369 |
+ ++i2cp->rxbuf;
|
|
370 |
+ --i2cp->rxbytes;
|
|
371 |
+ }
|
|
372 |
+ if (i2cp->rxbytes == 3) {
|
|
373 |
+ /* Disable this event for DataN-2, but force into event
|
|
374 |
+ * I2C_EV7_2_EV7_3_MASTER_REC_BYTE_RECEIVED_QUEUED by not reading dp->DR. */
|
|
375 |
+ dp->CR2 &= ~I2C_CR2_ITBUFEN;
|
|
376 |
+ }
|
|
377 |
+ break;
|
|
378 |
+ case I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP:
|
|
379 |
+ osalDbgAssert(i2cp->rxbytes == 1, "more than 1 byte to be received");
|
|
380 |
+ *(i2cp->rxbuf) = dp->DR;
|
|
381 |
+ --i2cp->rxbytes;
|
|
382 |
+ dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
|
|
383 |
+ _i2c_wakeup_isr(i2cp);
|
|
384 |
+ break;
|
|
385 |
+ case I2C_EV7_2_EV7_3_MASTER_REC_BYTE_QUEUED:
|
|
386 |
+ if (i2cp->rxbytes == 3) {
|
|
387 |
+ /* EV7_2 (N > 2) */
|
|
388 |
+ dp->CR1 &= ~I2C_CR1_ACK;
|
|
389 |
+ *(i2cp->rxbuf) = dp->DR;
|
|
390 |
+ ++i2cp->rxbuf;
|
|
391 |
+ dp->CR1 |= I2C_CR1_STOP;
|
|
392 |
+ *(i2cp->rxbuf) = dp->DR;
|
|
393 |
+ ++i2cp->rxbuf;
|
|
394 |
+ i2cp->rxbytes -= 2;
|
|
395 |
+ /* enable I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP event */
|
|
396 |
+ dp->CR2 |= I2C_CR2_ITBUFEN;
|
|
397 |
+ } else {
|
|
398 |
+ /* EV7_3 (N == 2) */
|
|
399 |
+ dp->CR1 |= I2C_CR1_STOP;
|
|
400 |
+ *(i2cp->rxbuf) = dp->DR;
|
|
401 |
+ ++i2cp->rxbuf;
|
|
402 |
+ *(i2cp->rxbuf) = dp->DR;
|
|
403 |
+ i2cp->rxbytes -= 2;
|
|
404 |
+
|
|
405 |
+ dp->CR1 &= ~I2C_CR1_POS;
|
|
406 |
+ dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
|
|
407 |
+
|
|
408 |
+ _i2c_wakeup_isr(i2cp);
|
|
409 |
+ }
|
|
410 |
+ break;
|
|
411 |
+ case I2C_EV8_MASTER_BYTE_TRANSMITTING:
|
|
412 |
+ dp->DR = *(i2cp->txbuf);
|
|
413 |
+ ++i2cp->txbuf;
|
|
414 |
+ --i2cp->txbytes;
|
|
415 |
+
|
|
416 |
+ /* if this was the last byte, ensure that this event is not entered again */
|
|
417 |
+ if (i2cp->txbytes == 0) {
|
|
418 |
+ dp->CR2 &= ~I2C_CR2_ITBUFEN;
|
|
419 |
+ }
|
|
420 |
+ break;
|
|
421 |
+ case I2C_EV8_2_MASTER_BYTE_TRANSMITTED:
|
|
422 |
+ if (i2cp->rxbytes > 0) {
|
|
423 |
+ /* start "read after write" operation (LSB of address = 1 => read) */
|
|
424 |
+ i2cp->addr |= 0x01;
|
|
425 |
+ dp->CR1 |= I2C_CR1_START | I2C_CR1_ACK;
|
|
426 |
+ } else {
|
|
427 |
+ dp->CR1 |= I2C_CR1_STOP;
|
|
428 |
+ dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
|
|
429 |
+ _i2c_wakeup_isr(i2cp);
|
|
430 |
+ }
|
|
431 |
+ break;
|
|
432 |
+ default:
|
|
433 |
+ osalDbgAssert(i2cp->rxbytes != 1, "more than 1 byte to be received");
|
|
434 |
+ break;
|
|
435 |
+ }
|
|
436 |
+}
|
|
437 |
+#endif /* any I2CDx uses non-DMA mode */
|
|
438 |
|
|
439 |
/**
|
|
440 |
* @brief DMA RX end IRQ handler.
|
|
441 |
@@ -302,6 +476,10 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
|
|
442 |
*
|
|
443 |
* @notapi
|
|
444 |
*/
|
|
445 |
+#if (STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA) || \
|
|
446 |
+ (STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA) || \
|
|
447 |
+ (STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA) || \
|
|
448 |
+ defined(__DOXYGEN__)
|
|
449 |
static void i2c_lld_serve_rx_end_irq(I2CDriver *i2cp, uint32_t flags) {
|
|
450 |
I2C_TypeDef *dp = i2cp->i2c;
|
|
451 |
|
|
452 |
@@ -347,6 +525,7 @@ static void i2c_lld_serve_tx_end_irq(I2CDriver *i2cp, uint32_t flags) {
|
|
453 |
of R/W transaction itself.*/
|
|
454 |
dp->CR2 |= I2C_CR2_ITEVTEN;
|
|
455 |
}
|
|
456 |
+#endif /* any I2CDx uses DMA mode */
|
|
457 |
|
|
458 |
/**
|
|
459 |
* @brief I2C error handler.
|
|
460 |
@@ -359,8 +538,24 @@ static void i2c_lld_serve_tx_end_irq(I2CDriver *i2cp, uint32_t flags) {
|
|
461 |
static void i2c_lld_serve_error_interrupt(I2CDriver *i2cp, uint16_t sr) {
|
|
462 |
|