aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb/src/control.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-02-07 22:49:14 +0100
committerDario Nieuwenhuis <[email protected]>2023-02-08 00:17:08 +0100
commit3af991ab63d14cfad6f50d28bfb944d1895d1c70 (patch)
tree575fecf6f47fbfd7116070aff2ffd5f4e84c7cf1 /embassy-usb/src/control.rs
parent1d841cc8ac74feacc4d231958ce2c46419ae3bda (diff)
usb: unify ControlHandler+DeviceStateHandler, route all control requests to all handlers.
- Allows classes to handle vendor requests. - Allows classes to use a single handler for multiple interfaces. - Allows classes to access the other events (previously only `reset` was available).
Diffstat (limited to 'embassy-usb/src/control.rs')
-rw-r--r--embassy-usb/src/control.rs58
1 files changed, 0 insertions, 58 deletions
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs
index 39b499f03..ceccfd85b 100644
--- a/embassy-usb/src/control.rs
+++ b/embassy-usb/src/control.rs
@@ -2,7 +2,6 @@
2use core::mem; 2use core::mem;
3 3
4use crate::driver::Direction; 4use crate::driver::Direction;
5use crate::types::StringIndex;
6 5
7/// Control request type. 6/// Control request type.
8#[repr(u8)] 7#[repr(u8)]
@@ -145,60 +144,3 @@ pub enum InResponse<'a> {
145 /// The request was rejected. 144 /// The request was rejected.
146 Rejected, 145 Rejected,
147} 146}
148
149/// Handler for control requests.
150///
151/// All methods are optional callbacks that will be called by
152/// [`UsbDevice::run()`](crate::UsbDevice::run)
153pub trait ControlHandler {
154 /// Called after a USB reset after the bus reset sequence is complete.
155 fn reset(&mut self) {}
156
157 /// Called when a "set alternate setting" control request is done on the interface.
158 fn set_alternate_setting(&mut self, alternate_setting: u8) {
159 let _ = alternate_setting;
160 }
161
162 /// Called when a control request is received with direction HostToDevice.
163 ///
164 /// # Arguments
165 ///
166 /// * `req` - The request from the SETUP packet.
167 /// * `data` - The data from the request.
168 fn control_out(&mut self, req: Request, data: &[u8]) -> OutResponse {
169 let _ = (req, data);
170 OutResponse::Rejected
171 }
172
173 /// Called when a control request is received with direction DeviceToHost.
174 ///
175 /// You should write the response somewhere (usually to `buf`, but you may use another buffer
176 /// owned by yourself, or a static buffer), then return `InResponse::Accepted(data)`.
177 ///
178 /// # Arguments
179 ///
180 /// * `req` - The request from the SETUP packet.
181 fn control_in<'a>(&'a mut self, req: Request, buf: &'a mut [u8]) -> InResponse<'a> {
182 let _ = (req, buf);
183 InResponse::Rejected
184 }
185
186 /// Called when a GET DESCRIPTOR control request is received on the interface.
187 ///
188 /// You should write the response somewhere (usually to `buf`, but you may use another buffer
189 /// owned by yourself, or a static buffer), then return `InResponse::Accepted(data)`.
190 ///
191 /// # Arguments
192 ///
193 /// * `req` - The request from the SETUP packet.
194 fn get_descriptor<'a>(&'a mut self, req: Request, buf: &'a mut [u8]) -> InResponse<'a> {
195 let _ = (req, buf);
196 InResponse::Rejected
197 }
198
199 /// Called when a GET_DESCRIPTOR STRING control request is received.
200 fn get_string(&mut self, index: StringIndex, lang_id: u16) -> Option<&str> {
201 let _ = (index, lang_id);
202 None
203 }
204}