aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb/src/control.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-03-28 03:30:08 +0200
committerDario Nieuwenhuis <[email protected]>2022-04-06 05:38:11 +0200
commitbfce731982af1f053b1b727e49e920fc496a9546 (patch)
treec634162e1b851d1c28a2148323a66d053cc8afcd /embassy-usb/src/control.rs
parent2b547f311efc7feaa3afbb9f1bf4100c5502839e (diff)
usb: nicer names for control structs.
Diffstat (limited to 'embassy-usb/src/control.rs')
-rw-r--r--embassy-usb/src/control.rs34
1 files changed, 15 insertions, 19 deletions
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs
index ae4ad04a9..05536dab2 100644
--- a/embassy-usb/src/control.rs
+++ b/embassy-usb/src/control.rs
@@ -126,7 +126,7 @@ impl Request {
126 126
127#[derive(Copy, Clone, Eq, PartialEq, Debug)] 127#[derive(Copy, Clone, Eq, PartialEq, Debug)]
128#[cfg_attr(feature = "defmt", derive(defmt::Format))] 128#[cfg_attr(feature = "defmt", derive(defmt::Format))]
129pub enum RequestStatus { 129pub enum OutResponse {
130 Accepted, 130 Accepted,
131 Rejected, 131 Rejected,
132} 132}
@@ -152,8 +152,8 @@ pub trait ControlHandler {
152 /// 152 ///
153 /// * `req` - The request from the SETUP packet. 153 /// * `req` - The request from the SETUP packet.
154 /// * `data` - The data from the request. 154 /// * `data` - The data from the request.
155 fn control_out(&mut self, req: Request, data: &[u8]) -> RequestStatus { 155 fn control_out(&mut self, req: Request, data: &[u8]) -> OutResponse {
156 RequestStatus::Rejected 156 OutResponse::Rejected
157 } 157 }
158 158
159 /// Called when a control request is received with direction DeviceToHost. 159 /// Called when a control request is received with direction DeviceToHost.
@@ -171,11 +171,7 @@ pub trait ControlHandler {
171 /// 171 ///
172 /// * `req` - The request from the SETUP packet. 172 /// * `req` - The request from the SETUP packet.
173 /// * `control` - The control pipe. 173 /// * `control` - The control pipe.
174 fn control_in<'a>( 174 fn control_in<'a>(&mut self, req: Request, control: ControlIn<'a>) -> InResponse<'a> {
175 &mut self,
176 req: Request,
177 control: ControlIn<'a>,
178 ) -> ControlInRequestStatus<'a> {
179 control.reject() 175 control.reject()
180 } 176 }
181} 177}
@@ -189,14 +185,14 @@ pub struct ControlIn<'a> {
189 185
190#[derive(Eq, PartialEq, Debug)] 186#[derive(Eq, PartialEq, Debug)]
191#[cfg_attr(feature = "defmt", derive(defmt::Format))] 187#[cfg_attr(feature = "defmt", derive(defmt::Format))]
192pub struct ControlInRequestStatus<'a> { 188pub struct InResponse<'a> {
193 pub(crate) status: RequestStatus, 189 pub(crate) response: OutResponse,
194 pub(crate) data: &'a [u8], 190 pub(crate) data: &'a [u8],
195} 191}
196 192
197impl<'a> ControlInRequestStatus<'a> { 193impl<'a> InResponse<'a> {
198 pub fn status(&self) -> RequestStatus { 194 pub fn status(&self) -> OutResponse {
199 self.status 195 self.response
200 } 196 }
201} 197}
202 198
@@ -206,22 +202,22 @@ impl<'a> ControlIn<'a> {
206 } 202 }
207 203
208 /// Accepts the transfer with the supplied buffer. 204 /// Accepts the transfer with the supplied buffer.
209 pub fn accept(self, data: &[u8]) -> ControlInRequestStatus<'a> { 205 pub fn accept(self, data: &[u8]) -> InResponse<'a> {
210 assert!(data.len() < self.buf.len()); 206 assert!(data.len() < self.buf.len());
211 207
212 let buf = &mut self.buf[0..data.len()]; 208 let buf = &mut self.buf[0..data.len()];
213 buf.copy_from_slice(data); 209 buf.copy_from_slice(data);
214 210
215 ControlInRequestStatus { 211 InResponse {
216 status: RequestStatus::Accepted, 212 response: OutResponse::Accepted,
217 data: buf, 213 data: buf,
218 } 214 }
219 } 215 }
220 216
221 /// Rejects the transfer by stalling the pipe. 217 /// Rejects the transfer by stalling the pipe.
222 pub fn reject(self) -> ControlInRequestStatus<'a> { 218 pub fn reject(self) -> InResponse<'a> {
223 ControlInRequestStatus { 219 InResponse {
224 status: RequestStatus::Rejected, 220 response: OutResponse::Rejected,
225 data: &[], 221 data: &[],
226 } 222 }
227 } 223 }