From 385efdf53fa3fe38591f22d01edf75d3087c2326 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Thu, 8 Aug 2019 09:53:06 -0400 Subject: Simplify data toggle handling. Only use the data toggle from hardware if we get a data toggle error. Otherwise, use computed toggle values based on endpoint. --- src/lib.rs | 2 ++ src/pipe.rs | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) mode change 100755 => 100644 src/lib.rs diff --git a/src/lib.rs b/src/lib.rs old mode 100755 new mode 100644 index 85b3b8f..ce551d4 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +//! USB Host driver implementation for SAMD* series chips. + #![no_std] mod pipe; diff --git a/src/pipe.rs b/src/pipe.rs index 0da0e7f..607e1c9 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -27,7 +27,7 @@ use atsamd_hal::target_device::usb::{ host::{BINTERVAL, PCFG, PINTFLAG, PSTATUS, PSTATUSCLR, PSTATUSSET}, }; use core::convert::TryInto; -use log::trace; +use log::{trace, warn}; // Maximum time to wait for a control request with data to finish. cf // ยง9.2.6.1 of USB 2.0. @@ -309,8 +309,8 @@ impl Pipe<'_, '_> { // the status bit is set, set it again? if it's clear then // clear it? This is what I get for having to work from // Arduino sources. - trace!( - "~~~ tok: {:?}, dtgl: {}, i: {}, o: {}", + warn!( + "tok: {:?}, dtgl: {}, i: {}, o: {}", token, self.regs.status.read().dtgl().bit(), ep.in_toggle(), @@ -330,6 +330,8 @@ impl Pipe<'_, '_> { t } + PToken::Setup => false, + _ => !self.regs.status.read().dtgl().bit_is_set(), }; @@ -372,10 +374,11 @@ impl Pipe<'_, '_> { let res = self.dispatch_result(token); match res { Ok(true) => { + // Swap sequence bits on successful transfer. if token == PToken::In { - ep.set_in_toggle(self.regs.status.read().dtgl().bit_is_set()); + ep.set_in_toggle(!ep.in_toggle()); } else if token == PToken::Out { - ep.set_out_toggle(self.regs.status.read().dtgl().bit_is_set()); + ep.set_out_toggle(!ep.out_toggle()); } return Ok(()); } -- cgit v1.2.3