feat(types): make all types and his fields public for crate

This commit is contained in:
doryan 2024-11-14 01:55:34 +04:00
parent 652ba78cdf
commit 7436a78885

View File

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