embassy/examples
bors[bot] 3a90a8eb4a
Merge #711
711: Add DeviceStateHandler, DeviceCommand channel, and remote wakeup support r=Dirbaio a=alexmoon

Apologies for the size of this PR. Once I started getting into the Vbus power management side of my device I found a couple of areas of functionality missing from embassy-usb. Specifically, I need the application to be able to respond to changes in the USB device state in order to properly control the amount of power I'm drawing from Vbus. I also wanted to enable remote wakeup support for my device.

In order to enable device state monitoring, I've created a `DeviceStateHandler` trait and made it possible to pass in an optional reference a handler implementing that trait when creating the `UsbDeviceBuilder`.

Remote wakeup required a way to send commands to the bus which is exclusively owned by the `UsbDevice::run` method. This is the same problem we were discussing for enabling/disabling the device on Vbus power events. My solution is to allow an optional `Channel` to be provided to the `UsbDeviceBuilder` (via `UsbDeviceBuilder::new_with_channel`), allowing the application to send commands into the `run` method. Right now it supports enable, disable and remote wakeup commands.

Since there's now a way to dynamically enable and disable the device, I also added `Config::start_enabled` to control whether or not the `UsbDevice` should start in the enabled state. That also allowed me to make `UsbDeviceBuilder::build` sync again and move enabling the bus into `UsbDevice::run`.

This led to a few driver changes:
1. `Driver::enable` became `Driver::into_bus`
2. `Bus::enable`, `Bus::disable`, and `Bus::remote_wakeup` were added
3. I removed `Bus::reset`, `Bus::suspend`, and `Bus::resume` because they were only ever called based on the result of `Bus::poll`. It made more sense to me to have `Bus::poll` handle the driver-specific state management itself.

I've updated the `usb_hid_keyboard` example to take advantage of all these additional features.

Let me know what you think.

Thanks!


Co-authored-by: alexmoon <alex.r.moon@gmail.com>
2022-04-14 15:16:55 +00:00
..
boot Add embassy-boot 2022-02-09 10:50:29 +01:00
nrf Split UsbDevice::run into run and run_until_suspend 2022-04-13 16:04:31 -04:00
rp Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
std net: auto-enable defmt in smoltcp using namespaced features. 2022-04-13 17:46:27 +02:00
stm32f0 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32f1 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32f2 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32f3 Simpler Channel. 2022-04-06 01:34:08 +02:00
stm32f4 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32f7 net: auto-enable defmt in smoltcp using namespaced features. 2022-04-13 17:46:27 +02:00
stm32g0 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32g4 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32h7 net: auto-enable defmt in smoltcp using namespaced features. 2022-04-13 17:46:27 +02:00
stm32l0 Update to latest rust-lorawan version 2022-04-08 12:58:57 +02:00
stm32l1 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32l4 fix clock in l4 rng example 2022-04-11 21:06:22 -06:00
stm32u5 Use embassy/defmt-timestamp-uptime in all examples. 2022-04-02 04:35:06 +02:00
stm32wb Add missing stm32wl/stm32wb chips except stm32wle 2022-04-08 03:15:27 +02:00
stm32wl Update to latest rust-lorawan version 2022-04-08 12:58:57 +02:00
wasm embassy, embassy-nrf: add nightly Cargo feature to gate nightly-only features. 2022-02-12 01:16:31 +01:00