diff --git a/src/types/usb_device.rs b/src/types/usb_device.rs index 6de6d7b..5e0c5c0 100644 --- a/src/types/usb_device.rs +++ b/src/types/usb_device.rs @@ -1,30 +1,26 @@ -use core::cmp::max; - use avr_device::{ atmega32u4::{PLL, USB_DEVICE}, - interrupt::{free, CriticalSection, Mutex}, + interrupt::{CriticalSection, Mutex}, }; use usb_device::{ - bus::{PollResult, UsbBus}, - endpoint::{EndpointAddress, EndpointType}, - Result as UsbResult, UsbDirection, UsbError, + bus::UsbBusAllocator, + endpoint::EndpointType, + UsbDirection, UsbError, }; #[allow(unused)] #[derive(Default, Copy, Clone)] pub(crate) struct USBEndpoint { - is_allocated: bool, - size: u8, - ep_type: u8, - ep_dir: bool, - banks: u8, + pub(crate) is_allocated: bool, + pub(crate) size: u8, + pub(crate) ep_type: u8, + pub(crate) ep_dir: bool, + pub(crate) banks: u8, } -const ENDPOINTS_ALLOC_LAYOUT: [u16; 7] = [64, 256, 64, 64, 64, 64, 64]; - impl USBEndpoint { #[inline] - fn set_type(&mut self, ep_type: EndpointType) { + pub(crate) fn set_type(&mut self, ep_type: EndpointType) { self.ep_type = match ep_type { EndpointType::Control => 0, // 0 = 0b00 EndpointType::Isochronous { @@ -37,7 +33,7 @@ impl USBEndpoint { } #[inline] - fn set_dir(&mut self, dir: UsbDirection) { + pub(crate) fn set_dir(&mut self, dir: UsbDirection) { self.ep_dir = match dir { UsbDirection::In => true, UsbDirection::Out => false, @@ -45,7 +41,7 @@ impl USBEndpoint { } #[inline] - fn set_size(&mut self, size: u16) { + pub(crate) fn set_size(&mut self, size: u16) { self.size = match size { 8 => 0b000, 16 => 0b001, @@ -59,30 +55,31 @@ impl USBEndpoint { } } -pub struct UsbDevice { - pll: Mutex, - usb: Mutex, - ep_table: [USBEndpoint; L], - dpram_already_used: u16, +pub(crate) struct UsbDevice { + pub(crate) pll: Mutex, + pub(crate) usb: Mutex, + pub(crate) ep_table: [USBEndpoint; L], + pub(crate) dpram_already_used: u16, } -const DPRAM_SIZE: u16 = 832; +pub(crate) const DPRAM_SIZE: u16 = 832; +pub(crate) const ENDPOINTS_ALLOC_LAYOUT: [u16; 7] = [64, 256, 64, 64, 64, 64, 64]; impl UsbDevice { #[inline] - pub fn new(pll: PLL, usb: USB_DEVICE) -> Self { + pub(crate) fn new(pll: PLL, usb: USB_DEVICE) -> UsbBusAllocator { let (pll, usb) = (Mutex::new(pll), Mutex::new(usb)); let ep_table: [USBEndpoint; L] = [Default::default(); L]; - Self { + UsbBusAllocator::new(Self { pll, usb, ep_table, dpram_already_used: 0, - } + }) } - pub fn select_endpoint( - &mut self, + pub(crate) fn select_endpoint( + &self, cs: CriticalSection<'_>, endpoint_index: usize, ) -> Result<(), UsbError> { @@ -102,7 +99,7 @@ impl UsbDevice { Ok(()) } - pub fn configure_endpoint( + pub(crate) fn configure_endpoint( &mut self, cs: CriticalSection<'_>, endpoint_index: usize, @@ -113,7 +110,7 @@ impl UsbDevice { let current_endpoint = self.ep_table[endpoint_index]; // Clear interrupt. // - + usb.udint.modify(|_, w| w.eorsti().clear_bit()); // Enable endpoint. // @@ -148,4 +145,3 @@ impl UsbDevice { } } } -