aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb/src/class/hid.rs
diff options
context:
space:
mode:
authorRafael Bachmann <[email protected]>2023-10-15 23:45:44 +0200
committerRafael Bachmann <[email protected]>2023-10-15 23:52:44 +0200
commit31d4516516940720101300a40d0d6d2bb8d1728e (patch)
treece44bfebf56fea7726bccae7d2617efd360af319 /embassy-usb/src/class/hid.rs
parent66e62e999409fd6967ab959a061f7eae660102d0 (diff)
Apply Pedantic Clippy Lints
Diffstat (limited to 'embassy-usb/src/class/hid.rs')
-rw-r--r--embassy-usb/src/class/hid.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/embassy-usb/src/class/hid.rs b/embassy-usb/src/class/hid.rs
index 0da29b1a6..0000b5b2b 100644
--- a/embassy-usb/src/class/hid.rs
+++ b/embassy-usb/src/class/hid.rs
@@ -63,7 +63,7 @@ pub enum ReportId {
63} 63}
64 64
65impl ReportId { 65impl ReportId {
66 fn try_from(value: u16) -> Result<Self, ()> { 66 const fn try_from(value: u16) -> Result<Self, ()> {
67 match value >> 8 { 67 match value >> 8 {
68 1 => Ok(ReportId::In(value as u8)), 68 1 => Ok(ReportId::In(value as u8)),
69 2 => Ok(ReportId::Out(value as u8)), 69 2 => Ok(ReportId::Out(value as u8)),
@@ -87,7 +87,7 @@ impl<'d> Default for State<'d> {
87 87
88impl<'d> State<'d> { 88impl<'d> State<'d> {
89 /// Create a new `State`. 89 /// Create a new `State`.
90 pub fn new() -> Self { 90 pub const fn new() -> Self {
91 State { 91 State {
92 control: MaybeUninit::uninit(), 92 control: MaybeUninit::uninit(),
93 out_report_offset: AtomicUsize::new(0), 93 out_report_offset: AtomicUsize::new(0),
@@ -154,7 +154,7 @@ fn build<'d, D: Driver<'d>>(
154} 154}
155 155
156impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> HidReaderWriter<'d, D, READ_N, WRITE_N> { 156impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> HidReaderWriter<'d, D, READ_N, WRITE_N> {
157 /// Creates a new HidReaderWriter. 157 /// Creates a new `HidReaderWriter`.
158 /// 158 ///
159 /// This will allocate one IN and one OUT endpoints. If you only need writing (sending) 159 /// This will allocate one IN and one OUT endpoints. If you only need writing (sending)
160 /// HID reports, consider using [`HidWriter::new`] instead, which allocates an IN endpoint only. 160 /// HID reports, consider using [`HidWriter::new`] instead, which allocates an IN endpoint only.
@@ -230,7 +230,7 @@ pub enum ReadError {
230 230
231impl From<EndpointError> for ReadError { 231impl From<EndpointError> for ReadError {
232 fn from(val: EndpointError) -> Self { 232 fn from(val: EndpointError) -> Self {
233 use EndpointError::*; 233 use EndpointError::{BufferOverflow, Disabled};
234 match val { 234 match val {
235 BufferOverflow => ReadError::BufferOverflow, 235 BufferOverflow => ReadError::BufferOverflow,
236 Disabled => ReadError::Disabled, 236 Disabled => ReadError::Disabled,
@@ -258,16 +258,15 @@ impl<'d, D: Driver<'d>, const N: usize> HidWriter<'d, D, N> {
258 258
259 /// Waits for the interrupt in endpoint to be enabled. 259 /// Waits for the interrupt in endpoint to be enabled.
260 pub async fn ready(&mut self) { 260 pub async fn ready(&mut self) {
261 self.ep_in.wait_enabled().await 261 self.ep_in.wait_enabled().await;
262 } 262 }
263 263
264 /// Writes an input report by serializing the given report structure. 264 /// Writes an input report by serializing the given report structure.
265 #[cfg(feature = "usbd-hid")] 265 #[cfg(feature = "usbd-hid")]
266 pub async fn write_serialize<IR: AsInputReport>(&mut self, r: &IR) -> Result<(), EndpointError> { 266 pub async fn write_serialize<IR: AsInputReport>(&mut self, r: &IR) -> Result<(), EndpointError> {
267 let mut buf: [u8; N] = [0; N]; 267 let mut buf: [u8; N] = [0; N];
268 let size = match serialize(&mut buf, r) { 268 let Ok(size) = serialize(&mut buf, r) else {
269 Ok(size) => size, 269 return Err(EndpointError::BufferOverflow);
270 Err(_) => return Err(EndpointError::BufferOverflow),
271 }; 270 };
272 self.write(&buf[0..size]).await 271 self.write(&buf[0..size]).await
273 } 272 }
@@ -293,7 +292,7 @@ impl<'d, D: Driver<'d>, const N: usize> HidWriter<'d, D, N> {
293impl<'d, D: Driver<'d>, const N: usize> HidReader<'d, D, N> { 292impl<'d, D: Driver<'d>, const N: usize> HidReader<'d, D, N> {
294 /// Waits for the interrupt out endpoint to be enabled. 293 /// Waits for the interrupt out endpoint to be enabled.
295 pub async fn ready(&mut self) { 294 pub async fn ready(&mut self) {
296 self.ep_out.wait_enabled().await 295 self.ep_out.wait_enabled().await;
297 } 296 }
298 297
299 /// Delivers output reports from the Interrupt Out pipe to `handler`. 298 /// Delivers output reports from the Interrupt Out pipe to `handler`.
@@ -350,9 +349,8 @@ impl<'d, D: Driver<'d>, const N: usize> HidReader<'d, D, N> {
350 if size < max_packet_size || total == N { 349 if size < max_packet_size || total == N {
351 self.offset.store(0, Ordering::Release); 350 self.offset.store(0, Ordering::Release);
352 break; 351 break;
353 } else {
354 self.offset.store(total, Ordering::Release);
355 } 352 }
353 self.offset.store(total, Ordering::Release);
356 } 354 }
357 Err(err) => { 355 Err(err) => {
358 self.offset.store(0, Ordering::Release); 356 self.offset.store(0, Ordering::Release);