38
38
#include "nrfx_uarte.h"
39
39
#include <string.h>
40
40
41
+ #ifdef NRF52840_XXAA
42
+
41
43
// expression to examine, and return value in case of failing
42
44
#define _VERIFY_ERR (_exp ) \
43
45
do {\
@@ -53,14 +55,14 @@ static void uart_callback_irq (const nrfx_uarte_event_t * event, void * context)
53
55
busio_uart_obj_t * self = (busio_uart_obj_t * ) context ;
54
56
55
57
switch ( event -> type ) {
56
- case NRFX_UART_EVT_RX_DONE :
58
+ case NRFX_UARTE_EVT_RX_DONE :
57
59
self -> rx_count = event -> data .rxtx .bytes ;
58
60
break ;
59
61
60
- case NRFX_UART_EVT_TX_DONE :
62
+ case NRFX_UARTE_EVT_TX_DONE :
61
63
break ;
62
64
63
- case NRFX_UART_EVT_ERROR :
65
+ case NRFX_UARTE_EVT_ERROR :
64
66
if ( self -> rx_count == -1 ) {
65
67
self -> rx_count = 0 ;
66
68
}
@@ -76,9 +78,6 @@ void common_hal_busio_uart_construct (busio_uart_obj_t *self,
76
78
const mcu_pin_obj_t * tx , const mcu_pin_obj_t * rx , uint32_t baudrate ,
77
79
uint8_t bits , uart_parity_t parity , uint8_t stop , uint32_t timeout ,
78
80
uint8_t receiver_buffer_size ) {
79
- #ifndef NRF52840_XXAA
80
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
81
- #else
82
81
if ( (tx == mp_const_none ) && (rx == mp_const_none ) ) {
83
82
mp_raise_ValueError (translate ("tx and rx cannot both be None" ));
84
83
}
@@ -130,36 +129,22 @@ void common_hal_busio_uart_construct (busio_uart_obj_t *self,
130
129
// queue 1-byte transfer for rx_characters_available()
131
130
self -> rx_count = -1 ;
132
131
_VERIFY_ERR (nrfx_uarte_rx (& self -> uarte , self -> buffer , 1 ));
133
- #endif
134
132
}
135
133
136
134
bool common_hal_busio_uart_deinited (busio_uart_obj_t * self ) {
137
- #ifndef NRF52840_XXAA
138
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
139
- #else
140
135
return (nrf_uarte_rx_pin_get (self -> uarte .p_reg ) == NRF_UART_PSEL_DISCONNECTED ) &&
141
136
(nrf_uarte_tx_pin_get (self -> uarte .p_reg ) == NRF_UART_PSEL_DISCONNECTED );
142
- #endif
143
137
}
144
138
145
139
void common_hal_busio_uart_deinit (busio_uart_obj_t * self ) {
146
- #ifndef NRF52840_XXAA
147
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
148
- #else
149
140
if ( !common_hal_busio_uart_deinited (self ) ) {
150
141
nrfx_uarte_uninit (& self -> uarte );
151
142
gc_free (self -> buffer );
152
143
}
153
- #endif
154
144
}
155
145
156
146
// Read characters.
157
147
size_t common_hal_busio_uart_read (busio_uart_obj_t * self , uint8_t * data , size_t len , int * errcode ) {
158
- #ifndef NRF52840_XXAA
159
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
160
- return 0 ;
161
- #else
162
-
163
148
if ( nrf_uarte_rx_pin_get (self -> uarte .p_reg ) == NRF_UART_PSEL_DISCONNECTED ) {
164
149
mp_raise_ValueError (translate ("No RX pin" ));
165
150
}
@@ -202,15 +187,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
202
187
}
203
188
204
189
return len - remain ;
205
- #endif
206
190
}
207
191
208
192
// Write characters.
209
193
size_t common_hal_busio_uart_write (busio_uart_obj_t * self , const uint8_t * data , size_t len , int * errcode ) {
210
- #ifndef NRF52840_XXAA
211
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
212
- return 0 ;
213
- #else
214
194
if ( nrf_uarte_tx_pin_get (self -> uarte .p_reg ) == NRF_UART_PSEL_DISCONNECTED ) {
215
195
mp_raise_ValueError (translate ("No TX pin" ));
216
196
}
@@ -254,13 +234,9 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
254
234
}
255
235
256
236
return len ;
257
- #endif
258
237
}
259
238
260
239
uint32_t common_hal_busio_uart_get_baudrate (busio_uart_obj_t * self ) {
261
- #ifndef NRF52840_XXAA
262
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
263
- #endif
264
240
return self -> baudrate ;
265
241
}
266
242
@@ -274,24 +250,15 @@ void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrat
274
250
}
275
251
276
252
uint32_t common_hal_busio_uart_rx_characters_available (busio_uart_obj_t * self ) {
277
- #ifndef NRF52840_XXAA
278
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
279
- #else
280
253
return (self -> rx_count > 0 ) ? self -> rx_count : 0 ;
281
- #endif
282
254
}
283
255
284
256
void common_hal_busio_uart_clear_rx_buffer (busio_uart_obj_t * self ) {
285
257
286
258
}
287
259
288
260
bool common_hal_busio_uart_ready_to_tx (busio_uart_obj_t * self ) {
289
- #ifndef NRF52840_XXAA
290
- mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
291
- return false;
292
- #else
293
261
return !nrfx_uarte_tx_in_progress (& self -> uarte );
294
- #endif
295
262
}
296
263
297
264
static uint32_t get_nrf_baud (uint32_t baudrate )
@@ -345,3 +312,56 @@ static uint32_t get_nrf_baud (uint32_t baudrate)
345
312
return NRF_UART_BAUDRATE_1000000 ;
346
313
}
347
314
}
315
+
316
+ #else
317
+
318
+ void common_hal_busio_uart_construct (busio_uart_obj_t * self ,
319
+ const mcu_pin_obj_t * tx , const mcu_pin_obj_t * rx , uint32_t baudrate ,
320
+ uint8_t bits , uart_parity_t parity , uint8_t stop , uint32_t timeout ,
321
+ uint8_t receiver_buffer_size ) {
322
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
323
+ }
324
+
325
+ bool common_hal_busio_uart_deinited (busio_uart_obj_t * self ) {
326
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
327
+ return true;
328
+ }
329
+
330
+ void common_hal_busio_uart_deinit (busio_uart_obj_t * self ) {
331
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
332
+ }
333
+
334
+ // Read characters.
335
+ size_t common_hal_busio_uart_read (busio_uart_obj_t * self , uint8_t * data , size_t len , int * errcode ) {
336
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
337
+ return 0 ;
338
+ }
339
+
340
+ // Write characters.
341
+ size_t common_hal_busio_uart_write (busio_uart_obj_t * self , const uint8_t * data , size_t len , int * errcode ) {
342
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
343
+ return 0 ;
344
+ }
345
+
346
+ uint32_t common_hal_busio_uart_get_baudrate (busio_uart_obj_t * self ) {
347
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
348
+ return self -> baudrate ;
349
+ }
350
+
351
+ void common_hal_busio_uart_set_baudrate (busio_uart_obj_t * self , uint32_t baudrate ) {
352
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
353
+ }
354
+
355
+ uint32_t common_hal_busio_uart_rx_characters_available (busio_uart_obj_t * self ) {
356
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
357
+ }
358
+
359
+ void common_hal_busio_uart_clear_rx_buffer (busio_uart_obj_t * self ) {
360
+
361
+ }
362
+
363
+ bool common_hal_busio_uart_ready_to_tx (busio_uart_obj_t * self ) {
364
+ mp_raise_NotImplementedError (translate ("busio.UART not yet implemented" ));
365
+ return false;
366
+ }
367
+ #endif
0 commit comments