From 9e49090ac6fb41645e5d09145cc4163e65565788 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Tue, 31 Jul 2012 13:03:12 -0400 Subject: usb_cdcacm: Add hook system. Provide hooks so users can reach into the CDC ACM callbacks with their own code. We'll use this to move the bootloader reset signals to Wirish. Signed-off-by: Marti Bolivar --- libmaple/usb/stm32f1/usb_cdcacm.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libmaple/usb/stm32f1') diff --git a/libmaple/usb/stm32f1/usb_cdcacm.c b/libmaple/usb/stm32f1/usb_cdcacm.c index 75bbc4f..ee3c8e3 100644 --- a/libmaple/usb/stm32f1/usb_cdcacm.c +++ b/libmaple/usb/stm32f1/usb_cdcacm.c @@ -353,6 +353,22 @@ USER_STANDARD_REQUESTS User_Standard_Requests = { .User_SetDeviceAddress = usbSetDeviceAddress }; +/* + * User hooks + */ + +static void (*rx_hook)(unsigned, void*) = 0; +static void (*iface_setup_hook)(unsigned, void*) = 0; + +void usb_cdcacm_set_hooks(unsigned hook_flags, void (*hook)(unsigned, void*)) { + if (hook_flags & USB_CDCACM_HOOK_RX) { + rx_hook = hook; + } + if (hook_flags & USB_CDCACM_HOOK_IFACE_SETUP) { + iface_setup_hook = hook; + } +} + /* * CDC ACM interface */ @@ -522,6 +538,10 @@ static void vcomDataRxCb(void) { } usb_copy_from_pma(vcomBufferRx, newBytes, USB_CDCACM_RX_ADDR); + + if (rx_hook) { + rx_hook(USB_CDCACM_HOOK_RX, 0); + } } static uint8* vcomGetSetLineCoding(uint16 length) { @@ -607,6 +627,12 @@ static RESULT usbDataSetup(uint8 request) { CopyRoutine = NULL; if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) { + /* Call the user hook first. */ + if (iface_setup_hook) { + uint8 req_copy = request; + iface_setup_hook(USB_CDCACM_HOOK_IFACE_SETUP, &req_copy); + } + switch (request) { case (USB_CDCACM_GET_LINE_CODING): CopyRoutine = vcomGetSetLineCoding; @@ -636,6 +662,11 @@ static RESULT usbNoDataSetup(uint8 request) { /* we support set com feature but dont handle it */ if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) { + /* Call the user hook first. */ + if (iface_setup_hook) { + uint8 req_copy = request; + iface_setup_hook(USB_CDCACM_HOOK_IFACE_SETUP, &req_copy); + } switch (request) { case (USB_CDCACM_SET_COMM_FEATURE): -- cgit v1.2.3