8000 nrf/usb_cdc.c: Add support for Arduino 1200bps touch. · micropython/micropython@aa6ac60 · GitHub
[go: up one dir, main page]

Skip to content

Commit aa6ac60

Browse files
committed
nrf/usb_cdc.c: Add support for Arduino 1200bps touch.
1 parent e825107 commit aa6ac60

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ports/nrf/drivers/usb/usb_cdc.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "nrfx_uart.h"
3636
#include "py/ringbuf.h"
3737
#include "py/stream.h"
38+
#include "py/runtime.h"
3839

3940
#ifdef BLUETOOTH_SD
4041
#include "nrf_sdm.h"
@@ -193,6 +194,25 @@ void usb_cdc_sd_event_handler(uint32_t soc_evt) {
193194
}
194195
#endif
195196

197+
#if MICROPY_HW_USB_CDC_1200BPS_TOUCH
198+
static mp_sched_node_t mp_bootloader_sched_node;
199+
STATIC void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) {
200+
mp_hal_delay_ms(250);
201+
MICROPY_BOARD_ENTER_BOOTLOADER();
202+
}
203+
204+
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
205+
if (dtr == false && rts == false) {
206+
cdc_line_coding_t line_coding;
207+
tud_cdc_n_get_line_coding(itf, &line_coding);
208+
if (line_coding.bit_rate == 1200) {
209+
// Delay bootloader jump to allow the USB stack to service endpoints.
210+
mp_sched_schedule_node(&mp_bootloader_sched_node, usbd_cdc_run_bootloader_task);
211+
}
212+
}
213+
}
214+
#endif
215+
196216
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
197217
uintptr_t ret = 0;
198218
if (poll_flags & MP_STREAM_POLL_RD) {

ports/nrf/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
#define MICROPY_MODULE_WEAK_LINKS (1)
158158
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
159159
#define MICROPY_USE_INTERNAL_ERRNO (1)
160+
#define MICROPY_ENABLE_SCHEDULER (1)
161+
#define MICROPY_SCHEDULER_STATIC_NODES (1)
160162
#define MICROPY_PY_FUNCTION_ATTRS (1)
161163
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
162164
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)

0 commit comments

Comments
 (0)
0