aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-07-28 17:50:03 -0400
committerBrian Cully <bjc@kublai.com>2019-07-28 17:50:03 -0400
commit1b055ef6621812b6be30b4230b1cc8304d105150 (patch)
treec1633af70d82dedcbae7266e9708180efbe09a0f
parenta175b1477ad6cfad765eb058dd5e2f2de8833a29 (diff)
downloadsamd21-demo-1b055ef6621812b6be30b4230b1cc8304d105150.tar.gz
samd21-demo-1b055ef6621812b6be30b4230b1cc8304d105150.zip
Rename USBToken/USBPipeType.
These are implementation details of the samd platform as used.
-rwxr-xr-xusbh/src/lib.rs4
-rw-r--r--usbh/src/pipe.rs50
2 files changed, 28 insertions, 26 deletions
diff --git a/usbh/src/lib.rs b/usbh/src/lib.rs
index 1cd8a1a..63b28ba 100755
--- a/usbh/src/lib.rs
+++ b/usbh/src/lib.rs
@@ -6,7 +6,7 @@ mod pipe;
mod usbproto;
use device::DeviceTable;
-use pipe::{PipeErr, PipeTable, USBPipeType, NO_DATA_STAGE};
+use pipe::{PType, PipeErr, PipeTable, NO_DATA_STAGE};
use rb::{Reader, RingBuffer, Writer};
use usbproto::*;
@@ -399,7 +399,7 @@ where
let speed = self.usb.host().status.read().speed().bits();
let pipe = self.pipe_table.pipe_for(self.usb.host_mut(), 0, 0);
pipe.regs.cfg.write(|w| {
- unsafe { w.ptype().bits(USBPipeType::Control as u8) };
+ unsafe { w.ptype().bits(PType::Control as u8) };
w.bk().clear_bit()
});
pipe.desc.bank0.pcksize.write(|w| match speed {
diff --git a/usbh/src/pipe.rs b/usbh/src/pipe.rs
index 660a21e..d431e06 100644
--- a/usbh/src/pipe.rs
+++ b/usbh/src/pipe.rs
@@ -130,7 +130,7 @@ impl Pipe<'_, '_> {
};
self.dtgl_clear();
self.send(
- USBToken::Setup,
+ PToken::Setup,
&DataBuf::from(&mut setup_packet),
NAK_LIMIT,
millis,
@@ -166,8 +166,8 @@ impl Pipe<'_, '_> {
});
let token = match bm_request_type.direction()? {
- RequestDirection::DeviceToHost => USBToken::Out,
- RequestDirection::HostToDevice => USBToken::In,
+ RequestDirection::DeviceToHost => PToken::Out,
+ RequestDirection::HostToDevice => PToken::In,
};
trace!("dispatching status stage");
@@ -177,7 +177,7 @@ impl Pipe<'_, '_> {
fn send(
&mut self,
- token: USBToken,
+ token: PToken,
buf: &DataBuf,
nak_limit: usize,
millis: &dyn Fn() -> usize,
@@ -230,7 +230,7 @@ impl Pipe<'_, '_> {
.write(|w| unsafe { w.addr().bits(db.ptr as u32 + bytes_received as u32) });
self.regs.statusclr.write(|w| w.bk0rdy().set_bit());
- self.dispatch_retries(USBToken::In, nak_limit, millis)?;
+ self.dispatch_retries(PToken::In, nak_limit, millis)?;
let recvd = self.desc.bank0.pcksize.read().byte_count().bits() as usize;
bytes_received += recvd;
trace!("!! read {} of {}", bytes_received, db.len);
@@ -291,7 +291,7 @@ impl Pipe<'_, '_> {
// non-blocking.
fn dispatch_retries(
&mut self,
- token: USBToken,
+ token: PToken,
retries: usize,
millis: &dyn Fn() -> usize,
) -> Result<(), PipeErr> {
@@ -333,17 +333,17 @@ impl Pipe<'_, '_> {
Err(last_err)
}
- fn dispatch_packet(&mut self, token: USBToken) {
+ fn dispatch_packet(&mut self, token: PToken) {
self.regs
.cfg
.modify(|_, w| unsafe { w.ptoken().bits(token as u8) });
match token {
- USBToken::Setup => {
+ PToken::Setup => {
self.regs.intflag.write(|w| w.txstp().set_bit());
self.regs.statusset.write(|w| w.bk0rdy().set_bit());
}
- USBToken::In => self.regs.statusclr.write(|w| w.bk0rdy().set_bit()),
- USBToken::Out => {
+ PToken::In => self.regs.statusclr.write(|w| w.bk0rdy().set_bit()),
+ PToken::Out => {
self.regs.intflag.write(|w| w.trcpt0().set_bit());
self.regs.statusset.write(|w| w.bk0rdy().set_bit());
}
@@ -352,7 +352,7 @@ impl Pipe<'_, '_> {
self.regs.statusclr.write(|w| w.pfreeze().set_bit());
}
- fn dispatch_result(&mut self, token: USBToken) -> Result<bool, PipeErr> {
+ fn dispatch_result(&mut self, token: PToken) -> Result<bool, PipeErr> {
if self.is_transfer_complete(token)? {
Ok(true)
} else if self.regs.intflag.read().stall().bit_is_set() {
@@ -388,9 +388,9 @@ impl Pipe<'_, '_> {
}
}
- fn is_transfer_complete(&mut self, token: USBToken) -> Result<bool, PipeErr> {
+ fn is_transfer_complete(&mut self, token: PToken) -> Result<bool, PipeErr> {
match token {
- USBToken::Setup => {
+ PToken::Setup => {
if self.regs.intflag.read().txstp().bit_is_set() {
self.regs.intflag.write(|w| w.txstp().set_bit());
self.regs.statusset.write(|w| w.pfreeze().set_bit());
@@ -399,7 +399,7 @@ impl Pipe<'_, '_> {
Ok(false)
}
}
- USBToken::In => {
+ PToken::In => {
if self.regs.intflag.read().trcpt0().bit_is_set() {
self.regs.intflag.write(|w| w.trcpt0().set_bit());
self.regs.statusset.write(|w| w.pfreeze().set_bit());
@@ -408,7 +408,7 @@ impl Pipe<'_, '_> {
Ok(false)
}
}
- USBToken::Out => {
+ PToken::Out => {
if self.regs.intflag.read().trcpt0().bit_is_set() {
self.regs.intflag.write(|w| w.trcpt0().set_bit());
self.regs.statusset.write(|w| w.pfreeze().set_bit());
@@ -456,16 +456,18 @@ impl Pipe<'_, '_> {
}
}
+// TODO: merge into SVD for pipe cfg register.
#[derive(Copy, Clone, Debug, PartialEq)]
-pub(crate) enum USBToken {
- Setup = 0,
- In = 1,
- Out = 2,
- Reserved = 3,
+pub(crate) enum PToken {
+ Setup = 0x0,
+ In = 0x1,
+ Out = 0x2,
+ _Reserved = 0x3,
}
+// TODO: merge into SVD for pipe cfg register.
#[derive(Copy, Clone, Debug, PartialEq)]
-pub(crate) enum USBPipeType {
+pub(crate) enum PType {
Disabled = 0x0,
Control = 0x1,
ISO = 0x2,
@@ -476,9 +478,9 @@ pub(crate) enum USBPipeType {
_Reserved1 = 0x07,
}
-pub(crate) struct DataBuf<'a> {
- pub(crate) ptr: *mut u8,
- pub(crate) len: usize,
+struct DataBuf<'a> {
+ ptr: *mut u8,
+ len: usize,
_marker: core::marker::PhantomData<&'a ()>,
}
impl DataBuf<'_> {}