summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-07-05 15:40:02 +0700
committerhathach <[email protected]>2024-07-05 15:40:02 +0700
commit8d5dbb957766921eba78b8762a458e6518521b66 (patch)
tree8549597da1eda90cb6f9ee0d18cb260f7410bd52 /examples
parent13dedddd1963e67251f75b3e3ebd654d74d8aa56 (diff)
add board_reset_to_bootloader(), try to implement that for ch32v203 but not working yet
Diffstat (limited to 'examples')
-rw-r--r--examples/device/cdc_dual_ports/src/main.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c
index 1167a5d50..ef12186f2 100644
--- a/examples/device/cdc_dual_ports/src/main.c
+++ b/examples/device/cdc_dual_ports/src/main.c
@@ -119,6 +119,26 @@ static void cdc_task(void) {
}
}
+// 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 instance, bool dtr, bool rts) {
+ (void)rts;
+
+ // DTR = false is counted as disconnected
+ if (!dtr) {
+ // touch1200 only with first CDC instance (Serial)
+ if (instance == 0) {
+ cdc_line_coding_t coding;
+ tud_cdc_get_line_coding(&coding);
+ if (coding.bit_rate == 1200) {
+ if (board_reset_to_bootloader) {
+ board_reset_to_bootloader();
+ }
+ }
+ }
+ }
+}
+
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+