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::{
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<const L: usize> {
pll: Mutex<PLL>,
usb: Mutex<USB_DEVICE>,
ep_table: [USBEndpoint; L],
dpram_already_used: u16,
pub(crate) struct UsbDevice<const L: usize> {
pub(crate) pll: Mutex<PLL>,
pub(crate) usb: Mutex<USB_DEVICE>,
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<const L: usize> UsbDevice<L> {
#[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 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<const L: usize> UsbDevice<L> {
Ok(())
}
pub fn configure_endpoint(
pub(crate) fn configure_endpoint(
&mut self,
cs: CriticalSection<'_>,
endpoint_index: usize,
@ -148,4 +145,3 @@ impl<const L: usize> UsbDevice<L> {
}
}
}