samples: usb: hid: remote wakeup in HID mouse example
Added support for remote wakeup in hid_mouse example. If rempote wakeup support is enabled, wakeup request is performed on every button click when the bus in suspended state. Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
This commit is contained in:
parent
804b9e1ada
commit
aa4c30c3e9
|
@ -11,6 +11,8 @@ by the Zephyr project. This very simple driver enumerates a board with a button
|
|||
into a mouse that has a left mouse button and optionally (depending on
|
||||
the number of buttons on the board) a right mouse button, X-axis movement,
|
||||
and Y-axis movement.
|
||||
If the USB peripheral driver supports remote wakeup feature, wakeup request
|
||||
will be performed on every button click if the bus is in suspended state.
|
||||
This sample can be found under :file:`samples/subsys/usb/hid-mouse` in the
|
||||
Zephyr project tree.
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ static u32_t def_val[4];
|
|||
static volatile u8_t status[4];
|
||||
static K_SEM_DEFINE(sem, 0, 1); /* starts off "not available" */
|
||||
static struct gpio_callback callback[4];
|
||||
static enum usb_dc_status_code usb_status;
|
||||
|
||||
#define MOUSE_BTN_REPORT_POS 0
|
||||
#define MOUSE_X_REPORT_POS 1
|
||||
|
@ -93,12 +94,25 @@ static struct gpio_callback callback[4];
|
|||
#define MOUSE_BTN_MIDDLE BIT(2)
|
||||
|
||||
|
||||
|
||||
static void status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
{
|
||||
usb_status = status;
|
||||
}
|
||||
|
||||
static void left_button(struct device *gpio, struct gpio_callback *cb,
|
||||
u32_t pins)
|
||||
{
|
||||
u32_t cur_val;
|
||||
u8_t state = status[MOUSE_BTN_REPORT_POS];
|
||||
|
||||
if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) {
|
||||
if (usb_status == USB_DC_SUSPEND) {
|
||||
usb_wakeup_request();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gpio_pin_read(gpio, PIN0, &cur_val);
|
||||
if (def_val[0] != cur_val) {
|
||||
state |= MOUSE_BTN_LEFT;
|
||||
|
@ -119,6 +133,13 @@ static void right_button(struct device *gpio, struct gpio_callback *cb,
|
|||
u32_t cur_val;
|
||||
u8_t state = status[MOUSE_BTN_REPORT_POS];
|
||||
|
||||
if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) {
|
||||
if (usb_status == USB_DC_SUSPEND) {
|
||||
usb_wakeup_request();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gpio_pin_read(gpio, PIN1, &cur_val);
|
||||
if (def_val[0] != cur_val) {
|
||||
state |= MOUSE_BTN_RIGHT;
|
||||
|
@ -240,8 +261,12 @@ void main(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
usb_hid_register_device(hid_dev, hid_report_desc,
|
||||
sizeof(hid_report_desc), NULL);
|
||||
static const struct hid_ops ops = {
|
||||
.status_cb = status_cb
|
||||
};
|
||||
usb_hid_register_device(hid_dev,
|
||||
hid_report_desc, sizeof(hid_report_desc),
|
||||
&ops);
|
||||
usb_hid_init(hid_dev);
|
||||
|
||||
while (true) {
|
||||
|
|
Loading…
Reference in a new issue