44
44
#include "mpconfigboard.h"
45
45
#include "nrf.h"
46
46
#include "mphalport.h"
47
+
48
+ #if NRFX_UART_ENABLED
47
49
#include "nrfx_uart.h"
50
+ #else
51
+ #include "nrfx_uarte.h"
52
+ #endif
48
53
49
54
50
55
#if MICROPY_PY_MACHINE_UART
@@ -56,6 +61,40 @@ typedef struct _machine_hard_uart_buf_t {
56
61
volatile ringbuf_t rx_ringbuf ;
57
62
} machine_hard_uart_buf_t ;
58
63
64
+ #if NRFX_UARTE_ENABLED
65
+
66
+ #define nrfx_uart_t nrfx_uarte_t
67
+ #define nrfx_uart_config_t nrfx_uarte_config_t
68
+
69
+ #define nrfx_uart_rx nrfx_uarte_rx
70
+ #define nrfx_uart_tx nrfx_uarte_tx
71
+ #define nrfx_uart_tx_in_progress nrfx_uarte_tx_in_progress
72
+ #define nrfx_uart_init nrfx_uarte_init
73
+ #define nrfx_uart_event_t nrfx_uarte_event_t
74
+ #define NRFX_UART_INSTANCE NRFX_UARTE_INSTANCE
75
+
76
+ #define NRF_UART_HWFC_ENABLED NRF_UARTE_HWFC_ENABLED
77
+ #define NRF_UART_HWFC_DISABLED NRF_UARTE_HWFC_DISABLED
78
+ #define NRF_UART_PARITY_EXCLUDED NRF_UARTE_PARITY_EXCLUDED
79
+ #define NRFX_UART_EVT_RX_DONE NRFX_UARTE_EVT_RX_DONE
80
+
81
+ #define NRF_UART_BAUDRATE_1200 NRF_UARTE_BAUDRATE_1200
82
+ #define NRF_UART_BAUDRATE_2400 NRF_UARTE_BAUDRATE_2400
83
+ #define NRF_UART_BAUDRATE_4800 NRF_UARTE_BAUDRATE_4800
84
+ #define NRF_UART_BAUDRATE_9600 NRF_UARTE_BAUDRATE_9600
85
+ #define NRF_UART_BAUDRATE_14400 NRF_UARTE_BAUDRATE_14400
86
+ #define NRF_UART_BAUDRATE_19200 NRF_UARTE_BAUDRATE_19200
87
+ #define NRF_UART_BAUDRATE_28800 NRF_UARTE_BAUDRATE_28800
88
+ #define NRF_UART_BAUDRATE_38400 NRF_UARTE_BAUDRATE_38400
89
+ #define NRF_UART_BAUDRATE_57600 NRF_UARTE_BAUDRATE_57600
90
+ #define NRF_UART_BAUDRATE_76800 NRF_UARTE_BAUDRATE_76800
91
+ #define NRF_UART_BAUDRATE_115200 NRF_UARTE_BAUDRATE_115200
92
+ #define NRF_UART_BAUDRATE_230400 NRF_UARTE_BAUDRATE_230400
93
+ #define NRF_UART_BAUDRATE_250000 NRF_UARTE_BAUDRATE_250000
94
+ #define NRF_UART_BAUDRATE_1000000 NRF_UARTE_BAUDRATE_1000000
95
+
96
+ #endif
97
+
59
98
typedef struct _machine_hard_uart_obj_t {
60
99
mp_obj_base_t base ;
61
100
const nrfx_uart_t * p_uart ; // Driver instance
@@ -210,7 +249,10 @@ STATIC mp_obj_t machine_hard_uart_make_new(const mp_obj_type_t *type, size_t n_a
210
249
// Enable event callback and start asynchronous receive
211
250
nrfx_uart_init (self -> p_uart , & config , uart_event_handler );
212
251
nrfx_uart_rx (self -> p_uart , & self -> buf -> rx_buf [0 ], 1 );
252
+
253
+ #if NRFX_UART_ENABLED
213
254
nrfx_uart_rx_enable (self -> p_uart );
255
+ #endif
214
256
215
257
return MP_OBJ_FROM_PTR (self );
216
258
}
0 commit comments