diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-21 19:47:09 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-21 19:47:09 +0200 |
| commit | c40d5f6e6ff81fb00507e384ef456d4390107e5e (patch) | |
| tree | 4b064b52d0057a2f6835e8d9a8d93c1165998385 | |
| parent | 26fdfdb00a1819f4a21c8d0fe1220c079983eecc (diff) | |
nrf/usb: prevent user code from constructing a PowerUsb directly.
PowerUsb must be constructed through `new()` so that it sets up the IRQ.
It must have at least one private field, otherwise user code can construct
it directly with `PowerUsb{}`.
| -rw-r--r-- | embassy-nrf/src/usb.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 9b6e6e83d..a039427f1 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -47,7 +47,9 @@ pub struct Driver<'d, T: Instance, P: UsbSupply> { | |||
| 47 | /// Uses the POWER peripheral to detect when power is available | 47 | /// Uses the POWER peripheral to detect when power is available |
| 48 | /// for USB. Unsuitable for usage with the nRF softdevice. | 48 | /// for USB. Unsuitable for usage with the nRF softdevice. |
| 49 | #[cfg(not(feature = "_nrf5340-app"))] | 49 | #[cfg(not(feature = "_nrf5340-app"))] |
| 50 | pub struct PowerUsb {} | 50 | pub struct PowerUsb { |
| 51 | _private: (), | ||
| 52 | } | ||
| 51 | 53 | ||
| 52 | /// Can be used to signal that power is available. Particularly suited for | 54 | /// Can be used to signal that power is available. Particularly suited for |
| 53 | /// use with the nRF softdevice. | 55 | /// use with the nRF softdevice. |
| @@ -70,7 +72,7 @@ impl PowerUsb { | |||
| 70 | regs.intenset | 72 | regs.intenset |
| 71 | .write(|w| w.usbdetected().set().usbremoved().set().usbpwrrdy().set()); | 73 | .write(|w| w.usbdetected().set().usbremoved().set().usbpwrrdy().set()); |
| 72 | 74 | ||
| 73 | Self {} | 75 | Self { _private: () } |
| 74 | } | 76 | } |
| 75 | 77 | ||
| 76 | #[cfg(not(feature = "_nrf5340-app"))] | 78 | #[cfg(not(feature = "_nrf5340-app"))] |
