Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB support for Leonardo #572

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0a06561
First attempt of making some generic code
supersimple33 Jul 20, 2024
8cb5745
Just muting some non-issues
supersimple33 Jul 24, 2024
13f0b06
Switching to using Macro 2.0
supersimple33 Jul 24, 2024
e7c3820
Moving into atmega-hal
supersimple33 Jul 24, 2024
8d0f94e
Switch to using pac for writing less code
supersimple33 Jul 25, 2024
dfc1521
First impl for UsbBus
supersimple33 Jul 25, 2024
16ca589
Moving SuspendNotifier outside due to orphan rule
supersimple33 Jul 25, 2024
e4608f3
Removing no longer used parts of macro
supersimple33 Jul 25, 2024
e81e875
Some macro and code changes for 8u2 device
supersimple33 Jul 29, 2024
52fb66b
Switching to tabs
supersimple33 Jul 29, 2024
a87be91
Passing AvrGenericUsbBus name for viz purposes
supersimple33 Jul 29, 2024
fc15a3f
Exposing in arduino hal
supersimple33 Jul 29, 2024
652ee6a
Escaping hygiene manually
supersimple33 Jul 30, 2024
3d3ad86
Adding a new macro for making a UsbBus
supersimple33 Jul 30, 2024
ba329eb
Adding a decl-macro for new usb devices
supersimple33 Jul 30, 2024
71cc082
Adding the original hello world example
supersimple33 Jul 30, 2024
8f9d219
Making necessary functions public
supersimple33 Aug 2, 2024
2f1509c
A better error handler
supersimple33 Aug 3, 2024
b504d11
Even better panic handling
supersimple33 Aug 3, 2024
4ca1972
Merge branch 'Rahix:main' into main
supersimple33 Aug 3, 2024
08bfd24
Small nit changes
supersimple33 Aug 3, 2024
8a47b1f
cleaner error handles
supersimple33 Aug 3, 2024
0be252f
Merge branch 'main' into main
supersimple33 Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ board-selected = []
mcu-atmega = []
mcu-attiny = []
arduino-diecimila = ["mcu-atmega", "atmega-hal/atmega168", "board-selected"]
arduino-leonardo = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
arduino-leonardo = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected", "usb-device"]
arduino-mega2560 = ["mcu-atmega", "atmega-hal/atmega2560", "board-selected"]
arduino-mega1280 = ["mcu-atmega", "atmega-hal/atmega1280", "board-selected"]
arduino-nano = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc", "board-selected"]
Expand All @@ -39,6 +39,7 @@ docsrs = ["arduino-uno"]
cfg-if = "1"
embedded-hal = "1.0"
ufmt = "0.2.0"
usb-device = { version = "0.3.2", optional = true }

[dependencies.embedded-hal-v0]
version = "0.2.3"
Expand Down
46 changes: 45 additions & 1 deletion arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_std]
#![feature(doc_cfg)]
#![feature(decl_macro)]

//! `arduino-hal`
//! =============
Expand Down Expand Up @@ -175,11 +176,23 @@ pub mod usart {
pub type UsartReader<USART, RX, TX> =
crate::hal::usart::UsartReader<USART, RX, TX, crate::DefaultClock>;
}

#[doc(no_inline)]
#[cfg(feature = "mcu-atmega")]
pub use usart::Usart;

#[cfg(feature = "arduino-leonardo")]
use usb_device::{bus::UsbBusAllocator, device::{UsbDeviceBuilder, UsbVidPid}};
#[cfg(feature = "arduino-leonardo")]
pub mod usb {
pub use crate::hal::usb::*;

pub type AvrUsbBus = crate::hal::usb::AvrUsbBus;
}
#[doc(no_inline)]
#[cfg(feature = "arduino-leonardo")]
pub use usb::AvrUsbBus;


#[cfg(feature = "board-selected")]
pub mod eeprom {
pub use crate::hal::eeprom::{Eeprom, EepromOps, OutOfBoundsError};
Expand Down Expand Up @@ -340,3 +353,34 @@ macro_rules! default_serial {
)
};
}

/// Convenience macro to instantiate the [`UsbBus`] driver for this board.
///
/// # Example
/// ```no_run
/// TODO
/// ```
#[cfg(feature = "arduino-leonardo")]
pub macro default_usb_bus ($usb:expr, $pll:expr) {
unsafe {
static mut USB_BUS: Option<UsbBusAllocator<AvrUsbBus>> = None;
&*USB_BUS.insert($crate::AvrUsbBus::with_suspend_notifier($usb, $pll))
};
}

/// Convenience macro to instantiate the [`UsbDevice`] driver for this board.
///
/// # Example
/// ```no_run
/// TODO
/// ```
#[cfg(feature = "arduino-leonardo")]
pub macro default_usb_device ($usb_bus:expr, $vid:expr, $pid:expr, $strings:expr) {
UsbDeviceBuilder::new(
$usb_bus,
UsbVidPid($vid, $pid)
)
.strings(&[$strings])
.unwrap()
.build()
}
1 change: 1 addition & 0 deletions arduino-hal/src/port/leonardo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

#[allow(non_camel_case_types)] // Mute LedRx and LedTx complaints
avr_hal_generic::renamed_pins! {
/// Pins of the **Arduino Leonardo**.
///
Expand Down
1 change: 1 addition & 0 deletions avr-hal-generic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ embedded-storage = "0.2"
embedded-hal = "1.0"
embedded-hal-bus = "0.1"
unwrap-infallible = "0.1.5"
usb-device = "0.3.2"

[dependencies.embedded-hal-v0]
version = "0.2.3"
Expand Down
6 changes: 5 additions & 1 deletion avr-hal-generic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![no_std]
#![feature(asm_experimental_arch)]
#![cfg_attr(avr_hal_asm_macro, feature(asm_experimental_arch))]
#![cfg_attr(not(avr_hal_asm_macro), feature(llvm_asm))]
#![feature(decl_macro)]


pub use embedded_hal as hal;
pub use embedded_hal_v0 as hal_v0;
Expand All @@ -21,6 +24,7 @@ pub mod simple_pwm;
pub mod spi;
pub mod usart;
pub mod wdt;
pub mod usb;

/// Prelude containing all HAL traits
pub mod prelude {
Expand Down
Loading
Loading