aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-12-05 21:22:34 -0500
committerKevin O'Connor <kevin@koconnor.net>2018-12-24 11:42:19 -0500
commitb84ecebf8f005175549297f1a818cf65822c3106 (patch)
treece23fd9d131a07656775ea543dfe5b9af395b652
parentc6065e29a6f652e6673d790f1200cd8bf0817673 (diff)
downloadkutter-b84ecebf8f005175549297f1a818cf65822c3106.tar.gz
kutter-b84ecebf8f005175549297f1a818cf65822c3106.tar.xz
kutter-b84ecebf8f005175549297f1a818cf65822c3106.zip
usb_cdc: Add support for detecting a USB level Arduino bootloader request
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/avr/usbserial.c5
-rw-r--r--src/generic/usb_cdc.c12
-rw-r--r--src/generic/usb_cdc.h1
-rw-r--r--src/lpc176x/usbserial.c5
-rw-r--r--src/samd21/usbserial.c5
-rw-r--r--src/stm32f1/usbserial.c5
6 files changed, 33 insertions, 0 deletions
diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c
index e95ab040..442ef934 100644
--- a/src/avr/usbserial.c
+++ b/src/avr/usbserial.c
@@ -178,6 +178,11 @@ usb_set_configure(void)
UEIENX = 1<<TXINE;
}
+void
+usb_request_bootloader(void)
+{
+}
+
#if CONFIG_MACH_at90usb1286
#define UHWCON_Init ((1<<UIMOD) | (1<<UVREGE))
#define PLLCSR_Init ((1<<PLLP2) | (1<<PLLP0) | (1<<PLLE))
diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c
index 7f6b2f34..d395a3c0 100644
--- a/src/generic/usb_cdc.c
+++ b/src/generic/usb_cdc.c
@@ -402,6 +402,15 @@ usb_req_set_configuration(struct usb_ctrlrequest *req)
}
static struct usb_cdc_line_coding line_coding;
+static uint8_t line_control_state;
+
+static void
+check_reboot(void)
+{
+ if (line_coding.dwDTERate == 1200 && !(line_control_state & 0x01))
+ // A baud of 1200 is an Arduino style request to enter the bootloader
+ usb_request_bootloader();
+}
static void
usb_req_set_line_coding(struct usb_ctrlrequest *req)
@@ -412,6 +421,7 @@ usb_req_set_line_coding(struct usb_ctrlrequest *req)
return;
}
usb_do_xfer(&line_coding, sizeof(line_coding), UX_READ);
+ check_reboot();
}
static void
@@ -432,7 +442,9 @@ usb_req_set_line(struct usb_ctrlrequest *req)
usb_do_stall();
return;
}
+ line_control_state = req->wValue;
usb_do_xfer(NULL, 0, UX_SEND);
+ check_reboot();
}
static void
diff --git a/src/generic/usb_cdc.h b/src/generic/usb_cdc.h
index 4771d08c..1763a843 100644
--- a/src/generic/usb_cdc.h
+++ b/src/generic/usb_cdc.h
@@ -21,6 +21,7 @@ int_fast8_t usb_send_ep0_progmem(const void *data, uint_fast8_t len);
void usb_stall_ep0(void);
void usb_set_address(uint_fast8_t addr);
void usb_set_configure(void);
+void usb_request_bootloader(void);
// usb_cdc.c
void usb_notify_bulk_in(void);
diff --git a/src/lpc176x/usbserial.c b/src/lpc176x/usbserial.c
index fba2fd0b..a9a0e7eb 100644
--- a/src/lpc176x/usbserial.c
+++ b/src/lpc176x/usbserial.c
@@ -242,6 +242,11 @@ usb_set_configure(void)
}
void
+usb_request_bootloader(void)
+{
+}
+
+void
usbserial_init(void)
{
usb_irq_disable();
diff --git a/src/samd21/usbserial.c b/src/samd21/usbserial.c
index 2db22ae6..a574b31c 100644
--- a/src/samd21/usbserial.c
+++ b/src/samd21/usbserial.c
@@ -169,6 +169,11 @@ usb_set_configure(void)
}
void
+usb_request_bootloader(void)
+{
+}
+
+void
usbserial_init(void)
{
// configure usb clock
diff --git a/src/stm32f1/usbserial.c b/src/stm32f1/usbserial.c
index f9e46d8c..20e1da0d 100644
--- a/src/stm32f1/usbserial.c
+++ b/src/stm32f1/usbserial.c
@@ -211,6 +211,11 @@ usb_set_configure(void)
{
}
+void
+usb_request_bootloader(void)
+{
+}
+
/****************************************************************
* Setup and interrupts