aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/usb/otg.rs8
-rw-r--r--embassy-usb-synopsys-otg/src/lib.rs38
2 files changed, 23 insertions, 23 deletions
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs
index 9551af99b..5d0e1116e 100644
--- a/embassy-stm32/src/usb/otg.rs
+++ b/embassy-stm32/src/usb/otg.rs
@@ -7,7 +7,7 @@ use embassy_usb_synopsys_otg::otg_v1::Otg;
7pub use embassy_usb_synopsys_otg::Config; 7pub use embassy_usb_synopsys_otg::Config;
8use embassy_usb_synopsys_otg::{ 8use embassy_usb_synopsys_otg::{
9 on_interrupt as on_interrupt_impl, Bus as OtgBus, ControlPipe, Driver as OtgDriver, Endpoint, In, OtgInstance, Out, 9 on_interrupt as on_interrupt_impl, Bus as OtgBus, ControlPipe, Driver as OtgDriver, Endpoint, In, OtgInstance, Out,
10 PhyType, State, MAX_EP_COUNT, 10 PhyType, State,
11}; 11};
12 12
13use crate::gpio::AFType; 13use crate::gpio::AFType;
@@ -15,6 +15,8 @@ use crate::interrupt;
15use crate::interrupt::typelevel::Interrupt; 15use crate::interrupt::typelevel::Interrupt;
16use crate::rcc::{RccPeripheral, SealedRccPeripheral}; 16use crate::rcc::{RccPeripheral, SealedRccPeripheral};
17 17
18const MAX_EP_COUNT: usize = 9;
19
18/// Interrupt handler. 20/// Interrupt handler.
19pub struct InterruptHandler<T: Instance> { 21pub struct InterruptHandler<T: Instance> {
20 _phantom: PhantomData<T>, 22 _phantom: PhantomData<T>,
@@ -54,7 +56,7 @@ const RX_FIFO_EXTRA_SIZE_WORDS: u16 = 30;
54/// USB driver. 56/// USB driver.
55pub struct Driver<'d, T: Instance> { 57pub struct Driver<'d, T: Instance> {
56 phantom: PhantomData<&'d mut T>, 58 phantom: PhantomData<&'d mut T>,
57 inner: OtgDriver<'d>, 59 inner: OtgDriver<'d, MAX_EP_COUNT>,
58} 60}
59 61
60impl<'d, T: Instance> Driver<'d, T> { 62impl<'d, T: Instance> Driver<'d, T> {
@@ -190,7 +192,7 @@ impl<'d, T: Instance> embassy_usb_driver::Driver<'d> for Driver<'d, T> {
190/// USB bus. 192/// USB bus.
191pub struct Bus<'d, T: Instance> { 193pub struct Bus<'d, T: Instance> {
192 phantom: PhantomData<&'d mut T>, 194 phantom: PhantomData<&'d mut T>,
193 inner: OtgBus<'d>, 195 inner: OtgBus<'d, MAX_EP_COUNT>,
194 inited: bool, 196 inited: bool,
195} 197}
196 198
diff --git a/embassy-usb-synopsys-otg/src/lib.rs b/embassy-usb-synopsys-otg/src/lib.rs
index 59be2c0be..a84f50e5a 100644
--- a/embassy-usb-synopsys-otg/src/lib.rs
+++ b/embassy-usb-synopsys-otg/src/lib.rs
@@ -23,7 +23,12 @@ pub mod otg_v1;
23use otg_v1::{regs, vals, Otg}; 23use otg_v1::{regs, vals, Otg};
24 24
25/// Handle interrupts. 25/// Handle interrupts.
26pub unsafe fn on_interrupt(r: Otg, state: &State<{ MAX_EP_COUNT }>, ep_count: usize, quirk_setup_late_cnak: bool) { 26pub unsafe fn on_interrupt<const MAX_EP_COUNT: usize>(
27 r: Otg,
28 state: &State<MAX_EP_COUNT>,
29 ep_count: usize,
30 quirk_setup_late_cnak: bool,
31) {
27 let ints = r.gintsts().read(); 32 let ints = r.gintsts().read();
28 if ints.wkupint() || ints.usbsusp() || ints.usbrst() || ints.enumdne() || ints.otgint() || ints.srqint() { 33 if ints.wkupint() || ints.usbsusp() || ints.usbrst() || ints.enumdne() || ints.otgint() || ints.srqint() {
29 // Mask interrupts and notify `Bus` to process them 34 // Mask interrupts and notify `Bus` to process them
@@ -291,16 +296,16 @@ impl Default for Config {
291} 296}
292 297
293/// USB OTG driver. 298/// USB OTG driver.
294pub struct Driver<'d> { 299pub struct Driver<'d, const MAX_EP_COUNT: usize> {
295 config: Config, 300 config: Config,
296 ep_in: [Option<EndpointData>; MAX_EP_COUNT], 301 ep_in: [Option<EndpointData>; MAX_EP_COUNT],
297 ep_out: [Option<EndpointData>; MAX_EP_COUNT], 302 ep_out: [Option<EndpointData>; MAX_EP_COUNT],
298 ep_out_buffer: &'d mut [u8], 303 ep_out_buffer: &'d mut [u8],
299 ep_out_buffer_offset: usize, 304 ep_out_buffer_offset: usize,
300 instance: OtgInstance<'d>, 305 instance: OtgInstance<'d, MAX_EP_COUNT>,
301} 306}
302 307
303impl<'d> Driver<'d> { 308impl<'d, const MAX_EP_COUNT: usize> Driver<'d, MAX_EP_COUNT> {
304 /// Initializes the USB OTG peripheral. 309 /// Initializes the USB OTG peripheral.
305 /// 310 ///
306 /// # Arguments 311 /// # Arguments
@@ -310,7 +315,7 @@ impl<'d> Driver<'d> {
310 /// Endpoint allocation will fail if it is too small. 315 /// Endpoint allocation will fail if it is too small.
311 /// * `instance` - The USB OTG peripheral instance and its configuration. 316 /// * `instance` - The USB OTG peripheral instance and its configuration.
312 /// * `config` - The USB driver configuration. 317 /// * `config` - The USB driver configuration.
313 pub fn new(ep_out_buffer: &'d mut [u8], instance: OtgInstance<'d>, config: Config) -> Self { 318 pub fn new(ep_out_buffer: &'d mut [u8], instance: OtgInstance<'d, MAX_EP_COUNT>, config: Config) -> Self {
314 Self { 319 Self {
315 config, 320 config,
316 ep_in: [None; MAX_EP_COUNT], 321 ep_in: [None; MAX_EP_COUNT],
@@ -414,11 +419,11 @@ impl<'d> Driver<'d> {
414 } 419 }
415} 420}
416 421
417impl<'d> embassy_usb_driver::Driver<'d> for Driver<'d> { 422impl<'d, const MAX_EP_COUNT: usize> embassy_usb_driver::Driver<'d> for Driver<'d, MAX_EP_COUNT> {
418 type EndpointOut = Endpoint<'d, Out>; 423 type EndpointOut = Endpoint<'d, Out>;
419 type EndpointIn = Endpoint<'d, In>; 424 type EndpointIn = Endpoint<'d, In>;
420 type ControlPipe = ControlPipe<'d>; 425 type ControlPipe = ControlPipe<'d>;
421 type Bus = Bus<'d>; 426 type Bus = Bus<'d, MAX_EP_COUNT>;
422 427
423 fn alloc_endpoint_in( 428 fn alloc_endpoint_in(
424 &mut self, 429 &mut self,
@@ -474,15 +479,15 @@ impl<'d> embassy_usb_driver::Driver<'d> for Driver<'d> {
474} 479}
475 480
476/// USB bus. 481/// USB bus.
477pub struct Bus<'d> { 482pub struct Bus<'d, const MAX_EP_COUNT: usize> {
478 config: Config, 483 config: Config,
479 ep_in: [Option<EndpointData>; MAX_EP_COUNT], 484 ep_in: [Option<EndpointData>; MAX_EP_COUNT],
480 ep_out: [Option<EndpointData>; MAX_EP_COUNT], 485 ep_out: [Option<EndpointData>; MAX_EP_COUNT],
481 instance: OtgInstance<'d>, 486 instance: OtgInstance<'d, MAX_EP_COUNT>,
482 inited: bool, 487 inited: bool,
483} 488}
484 489
485impl<'d> Bus<'d> { 490impl<'d, const MAX_EP_COUNT: usize> Bus<'d, MAX_EP_COUNT> {
486 fn restore_irqs(&mut self) { 491 fn restore_irqs(&mut self) {
487 self.instance.regs.gintmsk().write(|w| { 492 self.instance.regs.gintmsk().write(|w| {
488 w.set_usbrst(true); 493 w.set_usbrst(true);
@@ -496,9 +501,7 @@ impl<'d> Bus<'d> {
496 w.set_otgint(true); 501 w.set_otgint(true);
497 }); 502 });
498 } 503 }
499}
500 504
501impl<'d> Bus<'d> {
502 /// Returns the PHY type. 505 /// Returns the PHY type.
503 pub fn phy_type(&self) -> PhyType { 506 pub fn phy_type(&self) -> PhyType {
504 self.instance.phy_type 507 self.instance.phy_type
@@ -715,7 +718,7 @@ impl<'d> Bus<'d> {
715 } 718 }
716} 719}
717 720
718impl<'d> embassy_usb_driver::Bus for Bus<'d> { 721impl<'d, const MAX_EP_COUNT: usize> embassy_usb_driver::Bus for Bus<'d, MAX_EP_COUNT> {
719 async fn poll(&mut self) -> Event { 722 async fn poll(&mut self) -> Event {
720 poll_fn(move |cx| { 723 poll_fn(move |cx| {
721 if !self.inited { 724 if !self.inited {
@@ -1292,17 +1295,12 @@ fn ep0_mpsiz(max_packet_size: u16) -> u16 {
1292 } 1295 }
1293} 1296}
1294 1297
1295/// The number of maximum configurable EPs.
1296// TODO: this should at least be configurable, but ideally not a constant.
1297// Using OtgInstance::ENDPOINT_COUNT requires feature(const_generic_expr) so just define maximum eps
1298pub const MAX_EP_COUNT: usize = 9;
1299
1300/// Hardware-dependent USB IP configuration. 1298/// Hardware-dependent USB IP configuration.
1301pub struct OtgInstance<'d> { 1299pub struct OtgInstance<'d, const MAX_EP_COUNT: usize> {
1302 /// The USB peripheral. 1300 /// The USB peripheral.
1303 pub regs: Otg, 1301 pub regs: Otg,
1304 /// The USB state. 1302 /// The USB state.
1305 pub state: &'d State<{ MAX_EP_COUNT }>, 1303 pub state: &'d State<MAX_EP_COUNT>,
1306 /// FIFO depth in words. 1304 /// FIFO depth in words.
1307 pub fifo_depth_words: u16, 1305 pub fifo_depth_words: u16,
1308 /// Number of used endpoints. 1306 /// Number of used endpoints.