Skip to content

Commit 6197738

Browse files
committed
Use EndpointAddress for UsbClass too
1 parent e50c90f commit 6197738

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/class.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use bus::StringIndex;
33
use device::{ControlOutResult, ControlInResult};
44
use descriptor::DescriptorWriter;
55
use control;
6+
use endpoint::EndpointAddress;
67

78
/// A trait implemented by USB class implementations.
89
pub trait UsbClass {
@@ -77,23 +78,23 @@ pub trait UsbClass {
7778
///
7879
/// Note: This method may be called for an endpoint address you didn't allocate, and in that
7980
/// case you should ignore the event.
80-
fn endpoint_setup(&self, addr: u8) {
81+
fn endpoint_setup(&self, addr: EndpointAddress) {
8182
let _ = addr;
8283
}
8384

8485
/// Called when endpoint with address `addr` has received data (OUT packet).
8586
///
8687
/// Note: This method may be called for an endpoint address you didn't allocate, and in that
8788
/// case you should ignore the event.
88-
fn endpoint_out(&self, addr: u8) {
89+
fn endpoint_out(&self, addr: EndpointAddress) {
8990
let _ = addr;
9091
}
9192

9293
/// Called when endpoint with address `addr` has completed transmitting data (IN packet).
9394
///
9495
/// Note: This method may be called for an endpoint address you didn't allocate, and in that
9596
/// case you should ignore the event.
96-
fn endpoint_in_complete(&self, addr: u8) {
97+
fn endpoint_in_complete(&self, addr: EndpointAddress) {
9798
let _ = addr;
9899
}
99100

src/device.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
44
use ::{Result, UsbError};
55
use utils::AtomicMutex;
66
use bus::{UsbBusWrapper, UsbBus, PollResult};
7-
use endpoint::{EndpointType, EndpointIn, EndpointOut};
7+
use endpoint::{EndpointType, EndpointIn, EndpointOut, EndpointAddress, EndpointDirection};
88
use control;
99
use class::UsbClass;
1010
pub use device_builder::{UsbDeviceBuilder, UsbVidPid};
@@ -201,20 +201,23 @@ impl<'a, B: UsbBus + 'a> UsbDevice<'a, B> {
201201
// Pending events for other endpoints?
202202
if (all & !1) != 0 {
203203
let mut bit = 2u16;
204-
for i in 1..(MAX_ENDPOINTS as u8) {
204+
for i in 1..MAX_ENDPOINTS {
205205
if (ep_setup & bit) != 0 {
206206
for cls in self.classes() {
207-
cls.endpoint_setup(i);
207+
cls.endpoint_setup(
208+
EndpointAddress::from_parts(i, EndpointDirection::Out));
208209
}
209210
} else if (ep_out & bit) != 0 {
210211
for cls in self.classes() {
211-
cls.endpoint_out(i);
212+
cls.endpoint_out(
213+
EndpointAddress::from_parts(i, EndpointDirection::Out));
212214
}
213215
}
214216

215217
if (ep_in_complete & bit) != 0 {
216218
for cls in self.classes() {
217-
cls.endpoint_in_complete(i | 0x80);
219+
cls.endpoint_in_complete(
220+
EndpointAddress::from_parts(i, EndpointDirection::In));
218221
}
219222
}
220223

src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'a, B: UsbBus> Endpoint<'a, B, Out> {
152152
}
153153

154154
/// Type-safe endpoint address.
155-
#[derive(Debug, Clone, Copy)]
155+
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
156156
pub struct EndpointAddress(u8);
157157

158158
impl From<u8> for EndpointAddress {

0 commit comments

Comments
 (0)