mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 00:51:29 +00:00
chip/stm32/usb: Replace reset handler by generic event handler
Some USB interface handlers need to know when USB has been
successfully resumed after a wake event. For example, this is
useful so that HID keyboard can send the events at the right time.
BRANCH=none
BUG=b:35775048
TEST=Using USB HID keyboard patches to queue keys in a FIFO:
After USB autosuspends, press a single key and hold it. Without
this patch the endpoint data only gets reloaded on the _next_
event.
TEST=On hammer, I2C passthrough still works.
Change-Id: I9b52b9de16767c8a66c702a5ae70369334a3d590
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/569547
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
a1abf686c3
commit
9e33d6ce3c
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -221,8 +221,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;
|
||||
@@ -231,7 +234,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 --- */
|
||||
|
||||
@@ -127,9 +127,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;
|
||||
|
||||
@@ -199,14 +199,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); }
|
||||
|
||||
@@ -287,7 +287,8 @@ int usb_usart_interface(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 */
|
||||
|
||||
@@ -292,8 +292,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 */;
|
||||
@@ -303,14 +306,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
|
||||
@@ -455,6 +458,8 @@ static void usb_interrupt_handle_wake(uint16_t status)
|
||||
|
||||
/* Either: state is ready, or we timed out. */
|
||||
if (good || state == 3 || esof_count <= -USB_RESUME_TIMEOUT_MS) {
|
||||
int ep;
|
||||
|
||||
STM32_USB_CNTR &= ~(STM32_USB_CNTR_ESOFM | STM32_USB_CNTR_SOFM);
|
||||
usb_wake_done = 1;
|
||||
if (!good) {
|
||||
@@ -465,6 +470,9 @@ static void usb_interrupt_handle_wake(uint16_t status)
|
||||
}
|
||||
|
||||
CPRINTF("RSMOK%d %d\n", -esof_count, state);
|
||||
|
||||
for (ep = 1; ep < USB_EP_COUNT; ep++)
|
||||
usb_ep_event[ep](USB_EVENT_DEVICE_RESUME);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_USB_SUSPEND && CONFIG_USB_REMOTE_WAKEUP */
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -228,14 +228,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)
|
||||
|
||||
@@ -188,13 +188,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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user