diff --git a/cores/nRF5/usb/tinyusb/src/device/usbd.h b/cores/nRF5/usb/tinyusb/src/device/usbd.h index 1e59c0a7..f454c25b 100644 --- a/cores/nRF5/usb/tinyusb/src/device/usbd.h +++ b/cores/nRF5/usb/tinyusb/src/device/usbd.h @@ -85,15 +85,12 @@ bool tud_mounted(void); //--------------------------------------------------------------------+ // APPLICATION CALLBACK //--------------------------------------------------------------------+ -/** \brief Callback function that will be invoked device is mounted (configured) by USB host - * \note This callback should be used by Application to \b set-up application data - */ -void tud_mount_cb(void); -/** \brief Callback function that will be invoked when device is unmounted (bus reset/unplugged) - * \note This callback should be used by Application to \b tear-down application data - */ -void tud_umount_cb(void); +/** Callback invoked when device is mounted (configured) */ +ATTR_WEAK void tud_mount_cb(void); + +/** Callback invoked when device is unmounted (bus reset/unplugged) */ +ATTR_WEAK void tud_umount_cb(void); //void tud_device_suspended_cb(void); diff --git a/cores/nRF5/usb/usb.c b/cores/nRF5/usb/usb.c index 8ad8277d..735e2842 100644 --- a/cores/nRF5/usb/usb.c +++ b/cores/nRF5/usb/usb.c @@ -110,4 +110,24 @@ void usb_init(void) tusb_init(); } + + +// Invoked when cdc when line state changed e.g connected/disconnected +// Use to reset to DFU when disconnect with 1200 bps +void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) +{ + (void) itf; // interface ID, not used + + // disconnected event + if ( !dtr && !rts ) + { + cdc_line_coding_t coding; + tud_cdc_get_line_coding(&coding); + + if ( coding.bit_rate == 1200 ) enterSerialDfu(); + } +} + + + #endif diff --git a/variants/feather_nrf52840_express/variant.cpp b/variants/feather_nrf52840_express/variant.cpp index b235c27b..d20faa9a 100644 --- a/variants/feather_nrf52840_express/variant.cpp +++ b/variants/feather_nrf52840_express/variant.cpp @@ -23,6 +23,8 @@ #include "wiring_digital.h" #include "nrf.h" +extern "C" void usb_init(void); + const uint32_t g_ADigitalPinMap[] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , @@ -39,5 +41,8 @@ void initVariant() pinMode(PIN_LED2, OUTPUT); ledOff(PIN_LED2); + + // USB init TODO may have trouble with ISR when SD is enabled + usb_init(); } diff --git a/variants/pca10056/variant.cpp b/variants/pca10056/variant.cpp index 718de07d..7e7c3eaa 100644 --- a/variants/pca10056/variant.cpp +++ b/variants/pca10056/variant.cpp @@ -23,6 +23,8 @@ #include "wiring_digital.h" #include "nrf.h" +extern "C" void usb_init(void); + const uint32_t g_ADigitalPinMap[] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , @@ -31,6 +33,7 @@ const uint32_t g_ADigitalPinMap[] = 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 }; + void initVariant() { // LED1 & LED2 @@ -41,5 +44,6 @@ void initVariant() ledOff(PIN_LED2); // USB init TODO may have trouble with ISR when SD is enabled + usb_init(); }