diff options
-rw-r--r-- | board/polyberry/board.c | 2 | ||||
-rw-r--r-- | board/stm32f446e-eval/board.c | 3 | ||||
-rw-r--r-- | board/sweetberry/board.c | 2 | ||||
-rw-r--r-- | board/twinkie/sniffer.c | 7 | ||||
-rw-r--r-- | board/twinkie/usb_commands.c | 7 | ||||
-rw-r--r-- | chip/stm32/usb-stream.c | 10 | ||||
-rw-r--r-- | chip/stm32/usb-stream.h | 9 | ||||
-rw-r--r-- | chip/stm32/usb.c | 9 | ||||
-rw-r--r-- | chip/stm32/usb_console.c | 7 | ||||
-rw-r--r-- | chip/stm32/usb_dwc.c | 4 | ||||
-rw-r--r-- | chip/stm32/usb_dwc_console.c | 9 | ||||
-rw-r--r-- | chip/stm32/usb_dwc_console.h | 2 | ||||
-rw-r--r-- | chip/stm32/usb_dwc_hw.h | 21 | ||||
-rw-r--r-- | chip/stm32/usb_dwc_stream.c | 6 | ||||
-rw-r--r-- | chip/stm32/usb_dwc_stream.h | 11 | ||||
-rw-r--r-- | chip/stm32/usb_endpoints.S | 36 | ||||
-rw-r--r-- | chip/stm32/usb_gpio.c | 9 | ||||
-rw-r--r-- | chip/stm32/usb_gpio.h | 9 | ||||
-rw-r--r-- | chip/stm32/usb_hid_keyboard.c | 9 | ||||
-rw-r--r-- | chip/stm32/usb_hid_touchpad.c | 8 | ||||
-rw-r--r-- | chip/stm32/usb_hw.h | 27 | ||||
-rw-r--r-- | chip/stm32/usb_power.c | 6 | ||||
-rw-r--r-- | chip/stm32/usb_power.h | 11 | ||||
-rw-r--r-- | chip/stm32/usb_spi.c | 9 | ||||
-rw-r--r-- | chip/stm32/usb_spi.h | 9 |
25 files changed, 159 insertions, 83 deletions
diff --git a/board/polyberry/board.c b/board/polyberry/board.c index 65039abd86..5bb811f82c 100644 --- a/board/polyberry/board.c +++ b/board/polyberry/board.c @@ -16,9 +16,9 @@ #include "update_fw.h" #include "usb_descriptor.h" #include "util.h" -#include "usb_dwc_hw.h" #include "usb_dwc_console.h" #include "usb_dwc_update.h" +#include "usb_hw.h" /****************************************************************************** * Define the strings used in our USB descriptors. diff --git a/board/stm32f446e-eval/board.c b/board/stm32f446e-eval/board.c index 749f55c0d4..fc796464e2 100644 --- a/board/stm32f446e-eval/board.c +++ b/board/stm32f446e-eval/board.c @@ -13,9 +13,8 @@ #include "registers.h" #include "stm32-dma.h" #include "usb_descriptor.h" -#include "usb_dwc_hw.h" #include "usb_dwc_console.h" - +#include "usb_hw.h" /****************************************************************************** * Define the strings used in our USB descriptors. diff --git a/board/sweetberry/board.c b/board/sweetberry/board.c index d05bb70bf4..8131eb9b18 100644 --- a/board/sweetberry/board.c +++ b/board/sweetberry/board.c @@ -17,8 +17,8 @@ #include "update_fw.h" #include "usb_descriptor.h" #include "util.h" -#include "usb_dwc_hw.h" #include "usb_dwc_console.h" +#include "usb_hw.h" #include "usb_power.h" #include "usb_dwc_update.h" diff --git a/board/twinkie/sniffer.c b/board/twinkie/sniffer.c index 80887bac88..873aeef8fa 100644 --- a/board/twinkie/sniffer.c +++ b/board/twinkie/sniffer.c @@ -113,8 +113,11 @@ static void ep_tx(void) task_set_event(TASK_ID_SNIFFER, 1 << b, 0); } -static void ep_reset(void) +static void ep_event(enum usb_ep_event evt) { + if (evt != USB_EVENT_RESET) + return; + /* Bulk IN endpoint */ btable_ep[USB_EP_SNIFFER].tx_addr = usb_sram_addr(ep_buf[0]); btable_ep[USB_EP_SNIFFER].tx_count = EP_BUF_SIZE; @@ -123,7 +126,7 @@ static void ep_reset(void) (0 << 9) /* Bulk EP */ | (0 << 12) /* RX Disabled */; } -USB_DECLARE_EP(USB_EP_SNIFFER, ep_tx, ep_tx, ep_reset); +USB_DECLARE_EP(USB_EP_SNIFFER, ep_tx, ep_tx, ep_event); /* --- RX operation using comparator linked to timer --- */ diff --git a/board/twinkie/usb_commands.c b/board/twinkie/usb_commands.c index 508b3511b1..a858702db0 100644 --- a/board/twinkie/usb_commands.c +++ b/board/twinkie/usb_commands.c @@ -93,8 +93,11 @@ static void cmd_ep_rx(void) console_has_input(); } -static void cmd_ep_reset(void) +static void cmd_ep_event(enum usb_ep_event evt) { + if (evt != USB_EVENT_RESET) + return; + btable_ep[USB_EP_COMMAND].tx_addr = usb_sram_addr(ep_buf_tx); btable_ep[USB_EP_COMMAND].tx_count = 0; @@ -108,7 +111,7 @@ static void cmd_ep_reset(void) EP_RX_VALID); } -USB_DECLARE_EP(USB_EP_COMMAND, cmd_ep_tx, cmd_ep_rx, cmd_ep_reset); +USB_DECLARE_EP(USB_EP_COMMAND, cmd_ep_tx, cmd_ep_rx, cmd_ep_event); /* we have space to insert the null terminator */ BUILD_ASSERT(CONFIG_CONSOLE_INPUT_LINE_SIZE > USB_MAX_PACKET_SIZE); diff --git a/chip/stm32/usb-stream.c b/chip/stm32/usb-stream.c index 313e29e8df..29bebaa6fc 100644 --- a/chip/stm32/usb-stream.c +++ b/chip/stm32/usb-stream.c @@ -126,9 +126,15 @@ static usb_uint usb_ep_rx_size(size_t bytes) return 0x8000 | ((bytes - 32) << 5); } -void usb_stream_reset(struct usb_stream_config const *config) +void usb_stream_event(struct usb_stream_config const *config, + enum usb_ep_event evt) { - int i = config->endpoint; + int i; + + if (evt != USB_EVENT_RESET) + return; + + i = config->endpoint; btable_ep[i].tx_addr = usb_sram_addr(config->tx_ram); btable_ep[i].tx_count = 0; diff --git a/chip/stm32/usb-stream.h b/chip/stm32/usb-stream.h index f829009c51..7788be47c9 100644 --- a/chip/stm32/usb-stream.h +++ b/chip/stm32/usb-stream.h @@ -198,14 +198,14 @@ extern struct producer_ops const usb_stream_producer_ops; { \ usb_stream_rx(&NAME); \ } \ - static void CONCAT2(NAME, _ep_reset)(void) \ + static void CONCAT2(NAME, _ep_event)(enum usb_ep_event evt) \ { \ - usb_stream_reset(&NAME); \ + usb_stream_event(&NAME, evt); \ } \ USB_DECLARE_EP(ENDPOINT, \ CONCAT2(NAME, _ep_tx), \ CONCAT2(NAME, _ep_rx), \ - CONCAT2(NAME, _ep_reset)); \ + CONCAT2(NAME, _ep_event)); \ static void CONCAT2(NAME, _deferred_)(void) \ { usb_stream_deferred(&NAME); } @@ -241,7 +241,8 @@ void usb_stream_deferred(struct usb_stream_config const *config); */ void usb_stream_tx(struct usb_stream_config const *config); void usb_stream_rx(struct usb_stream_config const *config); -void usb_stream_reset(struct usb_stream_config const *config); +void usb_stream_event(struct usb_stream_config const *config, + enum usb_ep_event evt); #endif /* defined(CHIP_FAMILY_STM32F4) */ #endif /* __CROS_EC_USB_STREAM_H */ diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index b99d4be5b0..dcf31e1dae 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -313,8 +313,11 @@ error: STM32_TOGGLE_EP(0, EP_TX_MASK, EP_TX_VALID, 0); } -static void ep0_reset(void) +static void ep0_event(enum usb_ep_event evt) { + if (evt != USB_EVENT_RESET) + return; + STM32_USB_EP(0) = (1 << 9) /* control EP */ | (2 << 4) /* TX NAK */ | (3 << 12) /* RX VALID */; @@ -324,14 +327,14 @@ static void ep0_reset(void) btable_ep[0].rx_count = 0x8000 | ((USB_MAX_PACKET_SIZE/32-1) << 10); btable_ep[0].tx_count = 0; } -USB_DECLARE_EP(0, ep0_tx, ep0_rx, ep0_reset); +USB_DECLARE_EP(0, ep0_tx, ep0_rx, ep0_event); static void usb_reset(void) { int ep; for (ep = 0; ep < USB_EP_COUNT; ep++) - usb_ep_reset[ep](); + usb_ep_event[ep](USB_EVENT_RESET); /* * set the default address : 0 diff --git a/chip/stm32/usb_console.c b/chip/stm32/usb_console.c index c2a40918f2..83fc837aab 100644 --- a/chip/stm32/usb_console.c +++ b/chip/stm32/usb_console.c @@ -91,8 +91,11 @@ static void con_ep_rx(void) console_has_input(); } -static void ep_reset(void) +static void ep_event(enum usb_ep_event evt) { + if (evt != USB_EVENT_RESET) + return; + btable_ep[USB_EP_CONSOLE].tx_addr = usb_sram_addr(ep_buf_tx); btable_ep[USB_EP_CONSOLE].tx_count = 0; @@ -109,7 +112,7 @@ static void ep_reset(void) is_reset = 1; } -USB_DECLARE_EP(USB_EP_CONSOLE, con_ep_tx, con_ep_rx, ep_reset); +USB_DECLARE_EP(USB_EP_CONSOLE, con_ep_tx, con_ep_rx, ep_event); static int __tx_char(void *context, int c) { diff --git a/chip/stm32/usb_dwc.c b/chip/stm32/usb_dwc.c index 78de99873a..ec8aace692 100644 --- a/chip/stm32/usb_dwc.c +++ b/chip/stm32/usb_dwc.c @@ -12,7 +12,7 @@ #include "hooks.h" #include "link_defs.h" #include "registers.h" -#include "usb_dwc_hw.h" +#include "usb_hw.h" #include "system.h" #include "task.h" #include "timer.h" @@ -967,7 +967,7 @@ static void usb_init_endpoints(void) /* Reset the other endpoints */ for (ep = 1; ep < USB_EP_COUNT; ep++) - usb_ep_reset[ep](); + usb_ep_event[ep](USB_EVENT_RESET); } static void usb_reset(void) diff --git a/chip/stm32/usb_dwc_console.c b/chip/stm32/usb_dwc_console.c index b462df6a56..0d1340fb83 100644 --- a/chip/stm32/usb_dwc_console.c +++ b/chip/stm32/usb_dwc_console.c @@ -13,8 +13,8 @@ #include "task.h" #include "timer.h" #include "util.h" -#include "usb_dwc_hw.h" #include "usb_descriptor.h" +#include "usb_hw.h" /* Console output macro */ #define CPRINTF(format, args...) cprintf(CC_USB, format, ## args) @@ -216,8 +216,11 @@ static void con_ep_tx(void) GR_USB_DIEPINT(USB_EP_CONSOLE) = 0xffffffff; } -static void ep_reset(void) +static void ep_event(enum usb_ep_event evt) { + if (evt != USB_EVENT_RESET) + return; + epN_reset(USB_EP_CONSOLE); is_reset = 1; @@ -230,7 +233,7 @@ static void ep_reset(void) } -USB_DECLARE_EP(USB_EP_CONSOLE, con_ep_tx, con_ep_rx, ep_reset); +USB_DECLARE_EP(USB_EP_CONSOLE, con_ep_tx, con_ep_rx, ep_event); static int usb_wait_console(void) { diff --git a/chip/stm32/usb_dwc_console.h b/chip/stm32/usb_dwc_console.h index 387a8f0543..ab2206d359 100644 --- a/chip/stm32/usb_dwc_console.h +++ b/chip/stm32/usb_dwc_console.h @@ -6,7 +6,7 @@ #ifndef __CHIP_STM32_USB_DWC_CONSOLE_H #define __CHIP_STM32_USB_DWC_CONSOLE_H -#include "usb_dwc_hw.h" +#include "usb_hw.h" extern struct dwc_usb_ep ep_console_ctl; diff --git a/chip/stm32/usb_dwc_hw.h b/chip/stm32/usb_dwc_hw.h index 81637c3f17..d1fe07cb87 100644 --- a/chip/stm32/usb_dwc_hw.h +++ b/chip/stm32/usb_dwc_hw.h @@ -12,20 +12,31 @@ #define _EP_HANDLER2(num, suffix) CONCAT3(ep_, num, suffix) #define _EP_TX_HANDLER(num) _EP_HANDLER2(num, _tx) #define _EP_RX_HANDLER(num) _EP_HANDLER2(num, _rx) -#define _EP_RESET_HANDLER(num) _EP_HANDLER2(num, _rst) +#define _EP_EVENT_HANDLER(num) _EP_HANDLER2(num, _evt) +/* Used to check function types are correct (attribute alias does not do it) */ +#define _EP_TX_HANDLER_TYPECHECK(num) _EP_HANDLER2(num, _tx_typecheck) +#define _EP_RX_HANDLER_TYPECHECK(num) _EP_HANDLER2(num, _rx_typecheck) +#define _EP_EVENT_HANDLER_TYPECHECK(num) _EP_HANDLER2(num, _evt_typecheck) -#define USB_DECLARE_EP(num, tx_handler, rx_handler, rst_handler) \ +#define USB_DECLARE_EP(num, tx_handler, rx_handler, evt_handler) \ void _EP_TX_HANDLER(num)(void) \ __attribute__ ((alias(STRINGIFY(tx_handler)))); \ void _EP_RX_HANDLER(num)(void) \ __attribute__ ((alias(STRINGIFY(rx_handler)))); \ - void _EP_RESET_HANDLER(num)(void) \ - __attribute__ ((alias(STRINGIFY(rst_handler)))) + void _EP_EVENT_HANDLER(num)(enum usb_ep_event evt) \ + __attribute__ ((alias(STRINGIFY(evt_handler)))); \ + static __unused void \ + (*_EP_TX_HANDLER_TYPECHECK(num))(void) = tx_handler; \ + static __unused void \ + (*_EP_RX_HANDLER_TYPECHECK(num))(void) = rx_handler; \ + static __unused void \ + (*_EP_EVENT_HANDLER_TYPECHECK(num))(enum usb_ep_event evt)\ + = evt_handler /* Endpoint callbacks */ extern void (*usb_ep_tx[]) (void); extern void (*usb_ep_rx[]) (void); -extern void (*usb_ep_reset[]) (void); +extern void (*usb_ep_event[]) (enum usb_ep_event evt); struct usb_setup_packet; /* EP0 Interface handler callbacks */ extern int (*usb_iface_request[]) (struct usb_setup_packet *req); diff --git a/chip/stm32/usb_dwc_stream.c b/chip/stm32/usb_dwc_stream.c index d7ec6fb5b8..bf3f37c37b 100644 --- a/chip/stm32/usb_dwc_stream.c +++ b/chip/stm32/usb_dwc_stream.c @@ -59,8 +59,12 @@ int tx_stream_handler(struct usb_stream_config const *config) } /* Reset stream */ -void usb_stream_reset(struct usb_stream_config const *config) +void usb_stream_event(struct usb_stream_config const *config, + enum usb_ep_event evt) { + if (evt != USB_EVENT_RESET) + return; + epN_reset(config->endpoint); *(config->is_reset) = 1; diff --git a/chip/stm32/usb_dwc_stream.h b/chip/stm32/usb_dwc_stream.h index df1311f03f..e46e7a929c 100644 --- a/chip/stm32/usb_dwc_stream.h +++ b/chip/stm32/usb_dwc_stream.h @@ -14,7 +14,7 @@ #include "producer.h" #include "queue.h" #include "usb_descriptor.h" -#include "usb_dwc_hw.h" +#include "usb_hw.h" /* * Compile time Per-USB stream configuration stored in flash. Instances of this @@ -173,9 +173,9 @@ extern struct producer_ops const usb_stream_producer_ops; { \ usb_epN_rx(ENDPOINT); \ } \ - static void CONCAT2(NAME, _ep_reset)(void) \ + static void CONCAT2(NAME, _ep_event)(enum usb_ep_event evt) \ { \ - usb_stream_reset(&NAME); \ + usb_stream_event(&NAME, evt); \ } \ struct dwc_usb_ep CONCAT2(NAME, _ep_ctl) = { \ .max_packet = USB_MAX_PACKET_SIZE, \ @@ -196,7 +196,7 @@ extern struct producer_ops const usb_stream_producer_ops; USB_DECLARE_EP(ENDPOINT, \ CONCAT2(NAME, _ep_tx), \ CONCAT2(NAME, _ep_rx), \ - CONCAT2(NAME, _ep_reset)); + CONCAT2(NAME, _ep_event)); /* This is a short version for declaring Google serial endpoints */ #define USB_STREAM_CONFIG(NAME, \ @@ -231,6 +231,7 @@ int tx_stream_handler(struct usb_stream_config const *config); */ void usb_stream_tx(struct usb_stream_config const *config); void usb_stream_rx(struct usb_stream_config const *config); -void usb_stream_reset(struct usb_stream_config const *config); +void usb_stream_event(struct usb_stream_config const *config, + enum usb_ep_event evt); #endif /* __CROS_EC_USB_STREAM_H */ diff --git a/chip/stm32/usb_endpoints.S b/chip/stm32/usb_endpoints.S index 25ee68f3b7..9b3c41d175 100644 --- a/chip/stm32/usb_endpoints.S +++ b/chip/stm32/usb_endpoints.S @@ -66,24 +66,24 @@ endpoint 13 rx endpoint 14 rx endpoint 15 rx -.global usb_ep_reset -usb_ep_reset: -endpoint 0 rst -endpoint 1 rst -endpoint 2 rst -endpoint 3 rst -endpoint 4 rst -endpoint 5 rst -endpoint 6 rst -endpoint 7 rst -endpoint 8 rst -endpoint 9 rst -endpoint 10 rst -endpoint 11 rst -endpoint 12 rst -endpoint 13 rst -endpoint 14 rst -endpoint 15 rst +.global usb_ep_event +usb_ep_event: +endpoint 0 evt +endpoint 1 evt +endpoint 2 evt +endpoint 3 evt +endpoint 4 evt +endpoint 5 evt +endpoint 6 evt +endpoint 7 evt +endpoint 8 evt +endpoint 9 evt +endpoint 10 evt +endpoint 11 evt +endpoint 12 evt +endpoint 13 evt +endpoint 14 evt +endpoint 15 evt .global usb_iface_request usb_iface_request: diff --git a/chip/stm32/usb_gpio.c b/chip/stm32/usb_gpio.c index 43cda832a8..2407d3cd8a 100644 --- a/chip/stm32/usb_gpio.c +++ b/chip/stm32/usb_gpio.c @@ -60,9 +60,14 @@ void usb_gpio_rx(struct usb_gpio_config const *config) STM32_TOGGLE_EP(config->endpoint, EP_RX_MASK, EP_RX_VALID, 0); } -void usb_gpio_reset(struct usb_gpio_config const *config) +void usb_gpio_event(struct usb_gpio_config const *config, enum usb_ep_event evt) { - int i = config->endpoint; + int i; + + if (evt != USB_EVENT_RESET) + return; + + i = config->endpoint; btable_ep[i].tx_addr = usb_sram_addr(config->tx_ram); btable_ep[i].tx_count = USB_GPIO_TX_PACKET_SIZE; diff --git a/chip/stm32/usb_gpio.h b/chip/stm32/usb_gpio.h index cfbded61bf..2809b64401 100644 --- a/chip/stm32/usb_gpio.h +++ b/chip/stm32/usb_gpio.h @@ -108,14 +108,14 @@ struct usb_gpio_config { { \ usb_gpio_rx(&NAME); \ } \ - static void CONCAT2(NAME, _ep_reset)(void) \ + static void CONCAT2(NAME, _ep_event)(enum usb_ep_event evt) \ { \ - usb_gpio_reset(&NAME); \ + usb_gpio_event(&NAME, evt); \ } \ USB_DECLARE_EP(ENDPOINT, \ CONCAT2(NAME, _ep_tx), \ CONCAT2(NAME, _ep_rx), \ - CONCAT2(NAME, _ep_reset)) + CONCAT2(NAME, _ep_event)) /* @@ -124,6 +124,7 @@ struct usb_gpio_config { */ void usb_gpio_tx(struct usb_gpio_config const *config); void usb_gpio_rx(struct usb_gpio_config const *config); -void usb_gpio_reset(struct usb_gpio_config const *config); +void usb_gpio_event(struct usb_gpio_config const *config, + enum usb_ep_event evt); #endif /* __CROS_EC_USB_GPIO_H */ diff --git a/chip/stm32/usb_hid_keyboard.c b/chip/stm32/usb_hid_keyboard.c index 3b1204e47b..a3e0d5ffd3 100644 --- a/chip/stm32/usb_hid_keyboard.c +++ b/chip/stm32/usb_hid_keyboard.c @@ -230,14 +230,15 @@ static void hid_keyboard_tx(void) hid_ep_data_ready = 0; } -static void hid_keyboard_reset(void) +static void hid_keyboard_event(enum usb_ep_event evt) { - hid_reset(USB_EP_HID_KEYBOARD, hid_ep_buf[hid_current_buf], - HID_KEYBOARD_REPORT_SIZE); + if (evt == USB_EVENT_RESET) + hid_reset(USB_EP_HID_KEYBOARD, hid_ep_buf[hid_current_buf], + HID_KEYBOARD_REPORT_SIZE); } USB_DECLARE_EP(USB_EP_HID_KEYBOARD, hid_keyboard_tx, hid_keyboard_tx, - hid_keyboard_reset); + hid_keyboard_event); static int hid_keyboard_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx) diff --git a/chip/stm32/usb_hid_touchpad.c b/chip/stm32/usb_hid_touchpad.c index 686abdcda3..fdb6b2fafb 100644 --- a/chip/stm32/usb_hid_touchpad.c +++ b/chip/stm32/usb_hid_touchpad.c @@ -298,13 +298,15 @@ static void hid_touchpad_tx(void) hid_tx(USB_EP_HID_TOUCHPAD); } -static void hid_touchpad_reset(void) +static void hid_touchpad_event(enum usb_ep_event evt) { - hid_reset(USB_EP_HID_TOUCHPAD, hid_ep_buf, HID_TOUCHPAD_REPORT_SIZE); + if (evt == USB_EVENT_RESET) + hid_reset(USB_EP_HID_TOUCHPAD, hid_ep_buf, + HID_TOUCHPAD_REPORT_SIZE); } USB_DECLARE_EP(USB_EP_HID_TOUCHPAD, hid_touchpad_tx, hid_touchpad_tx, - hid_touchpad_reset); + hid_touchpad_event); static int hid_touchpad_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx) diff --git a/chip/stm32/usb_hw.h b/chip/stm32/usb_hw.h index ef231c4567..89c8e9d6f0 100644 --- a/chip/stm32/usb_hw.h +++ b/chip/stm32/usb_hw.h @@ -6,6 +6,12 @@ #ifndef __CROS_EC_USB_HW_H #define __CROS_EC_USB_HW_H +/* Event types for the endpoint event handler. */ +enum usb_ep_event { + USB_EVENT_RESET, + USB_EVENT_DEVICE_RESUME, /* Device-initiated wake completed. */ +}; + #if defined(CHIP_FAMILY_STM32F4) #include "usb_dwc_hw.h" #else @@ -64,20 +70,31 @@ void *memcpy_from_usbram(void *dest, const void *src, size_t n); #define _EP_HANDLER2(num, suffix) CONCAT3(ep_, num, suffix) #define _EP_TX_HANDLER(num) _EP_HANDLER2(num, _tx) #define _EP_RX_HANDLER(num) _EP_HANDLER2(num, _rx) -#define _EP_RESET_HANDLER(num) _EP_HANDLER2(num, _rst) +#define _EP_EVENT_HANDLER(num) _EP_HANDLER2(num, _evt) +/* Used to check function types are correct (attribute alias does not do it) */ +#define _EP_TX_HANDLER_TYPECHECK(num) _EP_HANDLER2(num, _tx_typecheck) +#define _EP_RX_HANDLER_TYPECHECK(num) _EP_HANDLER2(num, _rx_typecheck) +#define _EP_EVENT_HANDLER_TYPECHECK(num) _EP_HANDLER2(num, _evt_typecheck) -#define USB_DECLARE_EP(num, tx_handler, rx_handler, rst_handler) \ +#define USB_DECLARE_EP(num, tx_handler, rx_handler, evt_handler) \ void _EP_TX_HANDLER(num)(void) \ __attribute__ ((alias(STRINGIFY(tx_handler)))); \ void _EP_RX_HANDLER(num)(void) \ __attribute__ ((alias(STRINGIFY(rx_handler)))); \ - void _EP_RESET_HANDLER(num)(void) \ - __attribute__ ((alias(STRINGIFY(rst_handler)))); + void _EP_EVENT_HANDLER(num)(enum usb_ep_event evt) \ + __attribute__ ((alias(STRINGIFY(evt_handler)))); \ + static __unused void \ + (*_EP_TX_HANDLER_TYPECHECK(num))(void) = tx_handler; \ + static __unused void \ + (*_EP_RX_HANDLER_TYPECHECK(num))(void) = rx_handler; \ + static __unused void \ + (*_EP_EVENT_HANDLER_TYPECHECK(num))(enum usb_ep_event evt)\ + = evt_handler /* arrays with all endpoint callbacks */ extern void (*usb_ep_tx[]) (void); extern void (*usb_ep_rx[]) (void); -extern void (*usb_ep_reset[]) (void); +extern void (*usb_ep_event[]) (enum usb_ep_event evt); /* array with interface-specific control request callbacks */ extern int (*usb_iface_request[]) (usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx); diff --git a/chip/stm32/usb_power.c b/chip/stm32/usb_power.c index 60e104a953..ade0085af2 100644 --- a/chip/stm32/usb_power.c +++ b/chip/stm32/usb_power.c @@ -52,8 +52,12 @@ void usb_power_deferred_tx(struct usb_power_config const *config) } /* Reset stream */ -void usb_power_reset(struct usb_power_config const *config) +void usb_power_event(struct usb_power_config const *config, + enum usb_ep_event evt) { + if (evt != USB_EVENT_RESET) + return; + config->ep->out_databuffer = config->state->rx_buf; config->ep->out_databuffer_max = sizeof(config->state->rx_buf); config->ep->in_databuffer = config->state->tx_buf; diff --git a/chip/stm32/usb_power.h b/chip/stm32/usb_power.h index d6306c1a05..976f849404 100644 --- a/chip/stm32/usb_power.h +++ b/chip/stm32/usb_power.h @@ -11,7 +11,7 @@ #include "compile_time_macros.h" #include "hooks.h" #include "usb_descriptor.h" -#include "usb_dwc_hw.h" +#include "usb_hw.h" /* * Command: @@ -324,14 +324,14 @@ union usb_power_command_data { }; \ static void CONCAT2(NAME, _ep_tx_) (void) { usb_epN_tx(ENDPOINT); } \ static void CONCAT2(NAME, _ep_rx_) (void) { usb_epN_rx(ENDPOINT); } \ - static void CONCAT2(NAME, _ep_reset_)(void) \ + static void CONCAT2(NAME, _ep_event_)(enum usb_ep_event evt) \ { \ - usb_power_reset(&NAME); \ + usb_power_event(&NAME, evt); \ } \ USB_DECLARE_EP(ENDPOINT, \ CONCAT2(NAME, _ep_tx_), \ CONCAT2(NAME, _ep_rx_), \ - CONCAT2(NAME, _ep_reset_)); \ + CONCAT2(NAME, _ep_event_)); \ static void CONCAT2(NAME, _deferred_tx_)(void) \ { usb_power_deferred_tx(&NAME); } \ static void CONCAT2(NAME, _deferred_rx_)(void) \ @@ -353,7 +353,8 @@ void usb_power_deferred_cap(struct usb_power_config const *config); */ void usb_power_tx(struct usb_power_config const *config); void usb_power_rx(struct usb_power_config const *config); -void usb_power_reset(struct usb_power_config const *config); +void usb_power_event(struct usb_power_config const *config, + enum usb_ep_event evt); diff --git a/chip/stm32/usb_spi.c b/chip/stm32/usb_spi.c index ca540c3c7c..69138171a2 100644 --- a/chip/stm32/usb_spi.c +++ b/chip/stm32/usb_spi.c @@ -124,9 +124,14 @@ void usb_spi_rx(struct usb_spi_config const *config) hook_call_deferred(config->deferred, 0); } -void usb_spi_reset(struct usb_spi_config const *config) +void usb_spi_event(struct usb_spi_config const *config, enum usb_ep_event evt) { - int endpoint = config->endpoint; + int endpoint; + + if (evt != USB_EVENT_RESET) + return; + + endpoint = config->endpoint; btable_ep[endpoint].tx_addr = usb_sram_addr(config->tx_ram); btable_ep[endpoint].tx_count = 0; diff --git a/chip/stm32/usb_spi.h b/chip/stm32/usb_spi.h index 3c71fd4bc6..5aaa92e2df 100644 --- a/chip/stm32/usb_spi.h +++ b/chip/stm32/usb_spi.h @@ -188,11 +188,14 @@ struct usb_spi_config { }; \ static void CONCAT2(NAME, _ep_tx_) (void) { usb_spi_tx (&NAME); } \ static void CONCAT2(NAME, _ep_rx_) (void) { usb_spi_rx (&NAME); } \ - static void CONCAT2(NAME, _ep_reset_)(void) { usb_spi_reset(&NAME); } \ + static void CONCAT2(NAME, _ep_event_)(enum usb_ep_event evt) \ + { \ + usb_spi_event(&NAME, evt); \ + } \ USB_DECLARE_EP(ENDPOINT, \ CONCAT2(NAME, _ep_tx_), \ CONCAT2(NAME, _ep_rx_), \ - CONCAT2(NAME, _ep_reset_)); \ + CONCAT2(NAME, _ep_event_)); \ static int CONCAT2(NAME, _interface_)(usb_uint *rx_buf, \ usb_uint *tx_buf) \ { return usb_spi_interface(&NAME, rx_buf, tx_buf); } \ @@ -222,7 +225,7 @@ void usb_spi_enable(struct usb_spi_config const *config, int enabled); */ void usb_spi_tx(struct usb_spi_config const *config); void usb_spi_rx(struct usb_spi_config const *config); -void usb_spi_reset(struct usb_spi_config const *config); +void usb_spi_event(struct usb_spi_config const *config, enum usb_ep_event evt); int usb_spi_interface(struct usb_spi_config const *config, usb_uint *rx_buf, usb_uint *tx_buf); |