diff options
Diffstat (limited to 'examples/nrf/src/bin')
| -rw-r--r-- | examples/nrf/src/bin/usb/cdc_acm.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/nrf/src/bin/usb/cdc_acm.rs b/examples/nrf/src/bin/usb/cdc_acm.rs index 4b4925937..2a78324fe 100644 --- a/examples/nrf/src/bin/usb/cdc_acm.rs +++ b/examples/nrf/src/bin/usb/cdc_acm.rs | |||
| @@ -66,6 +66,7 @@ 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], | ||
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | /// Shared data between Control and CdcAcmClass | 72 | /// Shared data between Control and CdcAcmClass |
| @@ -138,17 +139,17 @@ impl<'a> ControlHandler for Control<'a> { | |||
| 138 | } | 139 | } |
| 139 | } | 140 | } |
| 140 | 141 | ||
| 141 | fn control_in(&mut self, req: Request, resp: &mut [u8]) -> InResponse { | 142 | fn control_in(&mut self, req: Request) -> InResponse<'_> { |
| 142 | match req.request { | 143 | match req.request { |
| 143 | // REQ_GET_ENCAPSULATED_COMMAND is not really supported - it will be rejected below. | 144 | // REQ_GET_ENCAPSULATED_COMMAND is not really supported - it will be rejected below. |
| 144 | REQ_GET_LINE_CODING if req.length == 7 => { | 145 | REQ_GET_LINE_CODING if req.length == 7 => { |
| 145 | info!("Sending line coding"); | 146 | info!("Sending line coding"); |
| 146 | let coding = self.shared().line_coding.lock(|x| x.get()); | 147 | let coding = self.shared().line_coding.lock(|x| x.get()); |
| 147 | resp[0..4].copy_from_slice(&coding.data_rate.to_le_bytes()); | 148 | self.buf[0..4].copy_from_slice(&coding.data_rate.to_le_bytes()); |
| 148 | resp[4] = coding.stop_bits as u8; | 149 | self.buf[4] = coding.stop_bits as u8; |
| 149 | resp[5] = coding.parity_type as u8; | 150 | self.buf[5] = coding.parity_type as u8; |
| 150 | resp[6] = coding.data_bits; | 151 | self.buf[6] = coding.data_bits; |
| 151 | InResponse::Accepted(7) | 152 | InResponse::Accepted(&self.buf) |
| 152 | } | 153 | } |
| 153 | _ => InResponse::Rejected, | 154 | _ => InResponse::Rejected, |
| 154 | } | 155 | } |
| @@ -165,6 +166,7 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { | |||
| 165 | ) -> Self { | 166 | ) -> Self { |
| 166 | let control = state.control.write(Control { | 167 | let control = state.control.write(Control { |
| 167 | shared: &state.shared, | 168 | shared: &state.shared, |
| 169 | buf: [0; 7], | ||
| 168 | }); | 170 | }); |
| 169 | 171 | ||
| 170 | let control_shared = &state.shared; | 172 | let control_shared = &state.shared; |
