diff options
| author | alexmoon <[email protected]> | 2022-03-29 15:09:24 -0400 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-06 05:38:11 +0200 |
| commit | 13370c28db244edd24029d6066ac9e448bd419c9 (patch) | |
| tree | 4728f35654af719466c52446ae3bd9fb58524793 /examples/nrf/src/bin | |
| parent | c53bb7394a20e180e2ac7e81cc468025018bd1da (diff) | |
Add a control_buf to UsbDevice
Diffstat (limited to 'examples/nrf/src/bin')
| -rw-r--r-- | examples/nrf/src/bin/usb/cdc_acm.rs | 19 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb/main.rs | 2 |
2 files changed, 12 insertions, 9 deletions
diff --git a/examples/nrf/src/bin/usb/cdc_acm.rs b/examples/nrf/src/bin/usb/cdc_acm.rs index 2a78324fe..c28681dc4 100644 --- a/examples/nrf/src/bin/usb/cdc_acm.rs +++ b/examples/nrf/src/bin/usb/cdc_acm.rs | |||
| @@ -66,7 +66,6 @@ pub struct CdcAcmClass<'d, D: Driver<'d>> { | |||
| 66 | 66 | ||
| 67 | struct Control<'a> { | 67 | struct Control<'a> { |
| 68 | shared: &'a ControlShared, | 68 | shared: &'a ControlShared, |
| 69 | buf: [u8; 7], | ||
| 70 | } | 69 | } |
| 71 | 70 | ||
| 72 | /// Shared data between Control and CdcAcmClass | 71 | /// Shared data between Control and CdcAcmClass |
| @@ -97,7 +96,7 @@ impl<'a> Control<'a> { | |||
| 97 | } | 96 | } |
| 98 | } | 97 | } |
| 99 | 98 | ||
| 100 | impl<'a> ControlHandler for Control<'a> { | 99 | impl<'d> ControlHandler for Control<'d> { |
| 101 | fn reset(&mut self) { | 100 | fn reset(&mut self) { |
| 102 | let shared = self.shared(); | 101 | let shared = self.shared(); |
| 103 | shared.line_coding.lock(|x| x.set(LineCoding::default())); | 102 | shared.line_coding.lock(|x| x.set(LineCoding::default())); |
| @@ -139,17 +138,18 @@ impl<'a> ControlHandler for Control<'a> { | |||
| 139 | } | 138 | } |
| 140 | } | 139 | } |
| 141 | 140 | ||
| 142 | fn control_in(&mut self, req: Request) -> InResponse<'_> { | 141 | fn control_in<'a>(&'a mut self, req: Request, buf: &'a mut [u8]) -> InResponse<'a> { |
| 143 | match req.request { | 142 | match req.request { |
| 144 | // REQ_GET_ENCAPSULATED_COMMAND is not really supported - it will be rejected below. | 143 | // REQ_GET_ENCAPSULATED_COMMAND is not really supported - it will be rejected below. |
| 145 | REQ_GET_LINE_CODING if req.length == 7 => { | 144 | REQ_GET_LINE_CODING if req.length == 7 => { |
| 146 | info!("Sending line coding"); | 145 | info!("Sending line coding"); |
| 147 | let coding = self.shared().line_coding.lock(|x| x.get()); | 146 | let coding = self.shared().line_coding.lock(|x| x.get()); |
| 148 | self.buf[0..4].copy_from_slice(&coding.data_rate.to_le_bytes()); | 147 | assert!(buf.len() >= 7); |
| 149 | self.buf[4] = coding.stop_bits as u8; | 148 | buf[0..4].copy_from_slice(&coding.data_rate.to_le_bytes()); |
| 150 | self.buf[5] = coding.parity_type as u8; | 149 | buf[4] = coding.stop_bits as u8; |
| 151 | self.buf[6] = coding.data_bits; | 150 | buf[5] = coding.parity_type as u8; |
| 152 | InResponse::Accepted(&self.buf) | 151 | buf[6] = coding.data_bits; |
| 152 | InResponse::Accepted(&buf[0..7]) | ||
| 153 | } | 153 | } |
| 154 | _ => InResponse::Rejected, | 154 | _ => InResponse::Rejected, |
| 155 | } | 155 | } |
| @@ -166,11 +166,12 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { | |||
| 166 | ) -> Self { | 166 | ) -> Self { |
| 167 | let control = state.control.write(Control { | 167 | let control = state.control.write(Control { |
| 168 | shared: &state.shared, | 168 | shared: &state.shared, |
| 169 | buf: [0; 7], | ||
| 170 | }); | 169 | }); |
| 171 | 170 | ||
| 172 | let control_shared = &state.shared; | 171 | let control_shared = &state.shared; |
| 173 | 172 | ||
| 173 | assert!(builder.control_buf_len() >= 7); | ||
| 174 | |||
| 174 | let comm_if = builder.alloc_interface_with_handler(control); | 175 | let comm_if = builder.alloc_interface_with_handler(control); |
| 175 | let comm_ep = builder.alloc_interrupt_endpoint_in(8, 255); | 176 | let comm_ep = builder.alloc_interrupt_endpoint_in(8, 255); |
| 176 | let data_if = builder.alloc_interface(); | 177 | let data_if = builder.alloc_interface(); |
diff --git a/examples/nrf/src/bin/usb/main.rs b/examples/nrf/src/bin/usb/main.rs index 398dd07b6..c4b9c0176 100644 --- a/examples/nrf/src/bin/usb/main.rs +++ b/examples/nrf/src/bin/usb/main.rs | |||
| @@ -47,6 +47,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 47 | let mut device_descriptor = [0; 256]; | 47 | let mut device_descriptor = [0; 256]; |
| 48 | let mut config_descriptor = [0; 256]; | 48 | let mut config_descriptor = [0; 256]; |
| 49 | let mut bos_descriptor = [0; 256]; | 49 | let mut bos_descriptor = [0; 256]; |
| 50 | let mut control_buf = [0; 7]; | ||
| 50 | 51 | ||
| 51 | let mut state = State::new(); | 52 | let mut state = State::new(); |
| 52 | 53 | ||
| @@ -56,6 +57,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 56 | &mut device_descriptor, | 57 | &mut device_descriptor, |
| 57 | &mut config_descriptor, | 58 | &mut config_descriptor, |
| 58 | &mut bos_descriptor, | 59 | &mut bos_descriptor, |
| 60 | &mut control_buf, | ||
| 59 | ); | 61 | ); |
| 60 | 62 | ||
| 61 | // Create classes on the builder. | 63 | // Create classes on the builder. |
