From 64c152f50b65fd72650f7c8f72e24e049e73af80 Mon Sep 17 00:00:00 2001 From: Jan Paw Date: Fri, 6 Nov 2020 21:28:02 +0100 Subject: [PATCH] Baudrate type implementation #88 --- CHANGELOG.md | 106 ++++++++++ README.md | 8 + avr-hal-generic/src/adc.rs | 2 +- avr-hal-generic/src/serial.rs | 111 ++++++++++- avr-hal-generic/src/spi.rs | 37 ++-- avr-hal-generic/src/wdt.rs | 4 +- .../examples/diecimila-panic.rs | 2 +- boards/arduino-diecimila/src/lib.rs | 27 +-- boards/arduino-diecimila/src/pins.rs | 10 +- .../arduino-leonardo/examples/leonardo-adc.rs | 2 +- .../examples/leonardo-i2cdetect.rs | 2 +- .../examples/leonardo-panic.rs | 2 +- .../examples/leonardo-serial.rs | 2 +- .../examples/leonardo-spi-feedback.rs | 2 +- boards/arduino-leonardo/src/lib.rs | 20 +- boards/arduino-leonardo/src/pins.rs | 14 +- .../arduino-mega2560/examples/mega2560-adc.rs | 2 +- .../examples/mega2560-i2cdetect.rs | 2 +- .../examples/mega2560-panic.rs | 2 +- .../examples/mega2560-serial.rs | 2 +- .../examples/mega2560-spi-feedback.rs | 2 +- boards/arduino-mega2560/src/lib.rs | 33 ++-- boards/arduino-mega2560/src/pins.rs | 26 +-- boards/arduino-uno/Cargo.toml | 2 +- boards/arduino-uno/examples/uno-adc.rs | 2 +- boards/arduino-uno/examples/uno-hc-sr04.rs | 2 +- boards/arduino-uno/examples/uno-i2cdetect.rs | 2 +- boards/arduino-uno/examples/uno-panic.rs | 2 +- boards/arduino-uno/examples/uno-serial.rs | 2 +- .../arduino-uno/examples/uno-spi-feedback.rs | 2 +- boards/arduino-uno/src/lib.rs | 18 +- boards/arduino-uno/src/pins.rs | 10 +- boards/bigavr6/examples/bigavr6-i2cdetect.rs | 2 +- boards/bigavr6/examples/bigavr6-panic.rs | 2 +- boards/bigavr6/examples/bigavr6-serial.rs | 2 +- boards/bigavr6/src/lib.rs | 21 +- .../examples/pro-micro-adc.rs | 2 +- .../examples/pro-micro-i2cdetect.rs | 2 +- .../examples/pro-micro-panic.rs | 2 +- .../examples/pro-micro-serial.rs | 2 +- .../examples/pro-micro-spi-feedback.rs | 2 +- boards/sparkfun-pro-micro/src/lib.rs | 16 +- boards/sparkfun-pro-micro/src/pins.rs | 14 +- boards/trinket/src/lib.rs | 20 +- chips/atmega1280-hal/src/lib.rs | 16 +- chips/atmega1280-hal/src/port.rs | 70 +++---- chips/atmega1280-hal/src/usart.rs | 17 +- chips/atmega168-hal/src/adc.rs | 10 +- chips/atmega168-hal/src/lib.rs | 27 ++- chips/atmega168-hal/src/port.rs | 22 +-- chips/atmega168-hal/src/pwm.rs | 14 +- chips/atmega2560-hal/src/adc.rs | 10 +- chips/atmega2560-hal/src/lib.rs | 16 +- chips/atmega2560-hal/src/port.rs | 70 +++---- chips/atmega2560-hal/src/pwm.rs | 26 +-- chips/atmega2560-hal/src/spi.rs | 6 +- chips/atmega2560-hal/src/usart.rs | 17 +- chips/atmega328p-hal/Cargo.toml | 4 +- chips/atmega328p-hal/src/adc.rs | 10 +- chips/atmega328p-hal/src/lib.rs | 182 ++++++++++++++++-- chips/atmega328p-hal/src/port.rs | 52 +++-- chips/atmega328p-hal/src/pwm.rs | 118 +++++++++++- chips/atmega328p-hal/src/wdt.rs | 7 +- chips/atmega32u4-hal/src/adc.rs | 8 +- chips/atmega32u4-hal/src/lib.rs | 28 +-- chips/atmega32u4-hal/src/port.rs | 34 ++-- chips/atmega32u4-hal/src/pwm.rs | 18 +- chips/atmega32u4-hal/src/wdt.rs | 6 +- chips/atmega48p-hal/src/adc.rs | 10 +- chips/atmega48p-hal/src/lib.rs | 22 +-- chips/atmega48p-hal/src/port.rs | 22 +-- chips/atmega48p-hal/src/pwm.rs | 14 +- chips/atmega48p-hal/src/spi.rs | 6 +- chips/attiny85-hal/src/lib.rs | 10 +- chips/attiny85-hal/src/port.rs | 6 +- chips/attiny88-hal/src/lib.rs | 16 +- chips/attiny88-hal/src/port.rs | 28 +-- chips/attiny88-hal/src/spi.rs | 6 +- 78 files changed, 1011 insertions(+), 466 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000..c86d56b0d4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,106 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +**Note**: As this project is still very early in its lifecycle, we don't have +proper releases yet. Instead, the CHANGELOG will document changes over time so +people already using the crates have a reference what is changing upstream. + +## [2020-10-26 - 2020-11-01][2020-44] +### Changed +- In HAL crates, the `avr-hal-generic` crate is no longer renamed to `avr-hal` + as this will just lead to confusion and problems down the line ([#89]). +- In HAL crates, the peripheral access crate (submodule of `avr-device`) is + imported as `pac` everywhere instead of using the actual device name. This + will make it easier to support multiple devices in a single HAL in the future + ([#89]). +- The reexported modules in board crates were cleaned up: The HAL crate is now + reexported as `hal` and the PAC crates as `pac` ([#89]). + +[#89]: https://github.com/Rahix/avr-hal/pull/89 + + +## [2020-10-12 - 2020-10-18][2020-42] +### Added +- The runner scripts now have better suport for MacOS out of the box ([#87]). + +[#87]: https://github.com/Rahix/avr-hal/pull/87 + + +## [2020-10-05 - 2020-10-11][2020-41] +### Added +- Added a script for automatically synchronizing target specs with upstream + ([#84]). + +### Changed +- Moved all target specs (like `avr-atmega32u4.json`) to a single directory + named `avr-specs/` ([#82]). +- Updated various settings in all target specs for better compatibility and + general cleanup ([#85]). + +### Fixed +- Fixed a number of issues in the `sparkfun-pro-micro` board crate ([#74]). + +[#74]: https://github.com/Rahix/avr-hal/pull/74 +[#82]: https://github.com/Rahix/avr-hal/pull/82 +[#84]: https://github.com/Rahix/avr-hal/pull/84 +[#85]: https://github.com/Rahix/avr-hal/pull/85 + + +## [2020-09-14 - 2020-09-20][2020-38] +### Changed +- The `Pins::new()` for `arduino-leonardo` now also consumes the `PORTF` + peripheral and exposes its pins as `a0` - `a5` ([#73]). + +### Fixed +- Fixed a nightly regression which broke our target specs ([#72]). + +[#73]: https://github.com/Rahix/avr-hal/pull/73 +[#72]: https://github.com/Rahix/avr-hal/pull/72 + + +## [2020-09-07 - 2020-09-13][2020-37] +### Added +- Added support for Arduino Nano (in `arduino-uno` board crate) ([#69]). +- Added support for `ADC6` and `ADC7` pins in `atmega328p-hal` ([#69]). + +### Fixed +- Reduced the overhead from `delay_us(u32)` ([#68]). + +[#68]: https://github.com/Rahix/avr-hal/pull/68 +[#69]: https://github.com/Rahix/avr-hal/pull/69 + + +## [2020-08-31 - 2020-09-06][2020-36] +### Added +- Support for Sparkfun's Pro Micro board ([#62]). +- SPI driver now implements the `blocking::spi::{Transfer, Write}` traits + ([#66]). + +### Fixed +- Fixed not resetting `U2X` bit in `USART` driver which leads to wrong baudrates + in some situations (reported in [#67], fixed in [`7caed3a995e2`]). +- Fixed I2C/TWI driver not resetting all bits during initialization + ([`3116e9ad5441`]). + +[#62]: https://github.com/Rahix/avr-hal/pull/62 +[#66]: https://github.com/Rahix/avr-hal/pull/66 +[#67]: https://github.com/Rahix/avr-hal/pull/67 +[`7caed3a995e2`]: https://github.com/Rahix/avr-hal/commit/7caed3a995e22f107b87e69f53679b0b4a3eb758 +[`3116e9ad5441`]: https://github.com/Rahix/avr-hal/commit/3116e9ad544120fffd55c60fcca58b51e61f934b + + +## 2019-05-11 - 2020-08-31 +Please look at the git log for changes before this point :) + + + + +[2020-44]: https://github.com/Rahix/avr-hal/compare/master@%7B2020-10-25%7D...master@%7B2020-11-01%7D +[2020-42]: https://github.com/Rahix/avr-hal/compare/master@%7B2020-10-11%7D...master@%7B2020-10-18%7D +[2020-41]: https://github.com/Rahix/avr-hal/compare/master@%7B2020-10-04%7D...master@%7B2020-10-11%7D +[2020-38]: https://github.com/Rahix/avr-hal/compare/master@%7B2020-09-13%7D...master@%7B2020-09-20%7D +[2020-37]: https://github.com/Rahix/avr-hal/compare/master@%7B2020-09-06%7D...master@%7B2020-09-13%7D +[2020-36]: https://github.com/Rahix/avr-hal/compare/master@%7B2020-08-30%7D...master@%7B2020-09-06%7D diff --git a/README.md b/README.md index b200f8eced..18fdf86a86 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ avr-hal [![Build Status](https://travis-ci.com/Rahix/avr-hal.svg?branch=master)] ## Quickstart You need nightly rust for compiling rust code for AVR. Go into `./boards/arduino-leonardo` (or the directory for whatever board you want), and run the following commands: ```bash +cd boards/arduino-leonardo + # Now you are ready to build your first avr blink example! cargo +nightly build --example leonardo-blink @@ -54,6 +56,11 @@ This is a step-by-step guide for creating a new project targeting Arduino Leonar [dependencies.arduino-leonardo] git = "https://github.com/Rahix/avr-hal" + rev = "" + # ^- Pin the dependency to a specific version. You should use the latest + # commit hash from the avr-hal master branch. You can find it here: + # + # https://github.com/Rahix/avr-hal/commits/master # Configure the build for minimal size [profile.dev] @@ -68,6 +75,7 @@ This is a step-by-step guide for creating a new project targeting Arduino Leonar lto = true opt-level = "s" ``` + **Note**: If you at some point want to update to a newer version of `avr-hal`, you just need to put a later commit hash into the `rev =` field. For any breaking changes which might require you to fix something in your code, read the [CHANGELOG](https://github.com/Rahix/avr-hal/blob/master/CHANGELOG.md). 6. Start your project with this basic template: ```rust #![no_std] diff --git a/avr-hal-generic/src/adc.rs b/avr-hal-generic/src/adc.rs index ddf1abf382..ae26597465 100644 --- a/avr-hal-generic/src/adc.rs +++ b/avr-hal-generic/src/adc.rs @@ -60,7 +60,7 @@ macro_rules! impl_adc { use $crate::hal::adc::{Channel, OneShot}; use $crate::nb; use $crate::port::mode::Analog; - pub use avr_hal::adc::*; + pub use $crate::adc::*; pub struct $Adc { peripheral: $ADC, diff --git a/avr-hal-generic/src/serial.rs b/avr-hal-generic/src/serial.rs index 677ba3841d..453db15283 100644 --- a/avr-hal-generic/src/serial.rs +++ b/avr-hal-generic/src/serial.rs @@ -1,5 +1,105 @@ //! Serial Implementations +use core::cmp::Ordering; + +// Clock is needed because the calculations needs to take core clock into account +#[derive(Debug, Clone, Copy)] +pub struct Baudrate { + pub ubrr: u16, + pub u2x: bool, + pub _clock: ::core::marker::PhantomData, +} + +impl PartialEq for Baudrate { + fn eq(&self, other: &Self) -> bool { + self.compare_value() == other.compare_value() + } +} + +impl Eq for Baudrate {} + +impl PartialOrd for Baudrate { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.compare_value().cmp(&other.compare_value())) + } +} + +impl Ord for Baudrate { + fn cmp(&self, other: &Self) -> Ordering { + other.compare_value().cmp(&self.compare_value()) + } +} + +impl From for Baudrate { + fn from(baud: u32) -> Self { + Baudrate::new(baud) + } +} + +impl Baudrate { + pub fn new(baud: u32) -> Baudrate { + let mut ubrr = (CLOCK::FREQ / 4 / baud - 1) / 2; + let mut u2x = true; + debug_assert!(ubrr <= u16::MAX as u32); + if ubrr > 4095 { + u2x = false; + ubrr = (CLOCK::FREQ / 8 / baud - 1) / 2; + } + + Baudrate { + ubrr: ubrr as u16, + u2x: u2x, + _clock: ::core::marker::PhantomData, + } + } + + pub fn with_exact(u2x: bool, ubrr: u16) -> Baudrate { + Baudrate { + ubrr, u2x, _clock: ::core::marker::PhantomData, + } + } + + fn compare_value(&self) -> u32 { + if self.u2x { + return 8 * (self.ubrr as u32 + 1); + } else { + return 16 * (self.ubrr as u32 + 1); + }; + } +} + +pub trait BaudrateExt { + fn into_baudrate(self) -> Baudrate; +} + +impl BaudrateExt for u32 { + fn into_baudrate(self) -> Baudrate { + Baudrate::new(self) + } +} + +pub trait BaudrateArduinoExt { + fn into_baudrate(self) -> Baudrate; +} + +impl BaudrateArduinoExt for u32 { + fn into_baudrate(self) -> Baudrate { + let br = Baudrate::new(self); + + // hardcoded exception for 57600 for compatibility with the bootloader + // shipped with the Duemilanove and previous boards and the firmware + // on the 8U2 on the Uno and Mega 2560. + // + // https://github.com/arduino/ArduinoCore-avr/blob/3055c1efa3c6980c864f661e6c8cc5d5ac773af4/cores/arduino/HardwareSerial.cpp#L123-L132 + if CLOCK::FREQ == 16_000_000 && br.ubrr == 34 && br.u2x { + // (CLOCK::FREQ / 8 / 57600 - 1) / 2 == 16 + Baudrate::with_exact(false, 16) + } else { + br + } + } +} + /// Implement serial traits for a USART peripheral #[macro_export] macro_rules! impl_usart { @@ -40,7 +140,7 @@ macro_rules! impl_usart { p: $USART, rx: $rxmod::$RX<$crate::port::mode::Input>, tx: $txmod::$TX<$crate::port::mode::Output>, - baud: u32, + baud: Baudrate, ) -> $Usart { let mut usart = $Usart { p, @@ -52,12 +152,9 @@ macro_rules! impl_usart { usart } - fn initialize(&mut self, baud: u32) { - // Value for baudrate register must be calculated based on clock frequency. - let brr = CLOCK::FREQ / (16 * baud) - 1; - self.p.[].write(|w| unsafe { w.bits(brr as u16) }); - - self.p.[].reset(); + fn initialize(&mut self, baud: Baudrate) { + self.p.[].write(|w| unsafe { w.bits(baud.ubrr) }); + self.p.[].write(|w| w.[]().bit(baud.u2x)); // Enable receiver and transmitter but leave interrupts disabled. self.p.[].write(|w| w diff --git a/avr-hal-generic/src/spi.rs b/avr-hal-generic/src/spi.rs index a5f14c2270..7999cbf7c9 100644 --- a/avr-hal-generic/src/spi.rs +++ b/avr-hal-generic/src/spi.rs @@ -78,10 +78,6 @@ macro_rules! impl_spi { } } ) => { - type SCLK = $sclkmod::$SCLK<$crate::port::mode::Output>; - type MOSI = $mosimod::$MOSI<$crate::port::mode::Output>; - type MISO = $misomod::$MISO<$crate::port::mode::Input>; - /// Behavior for a SPI interface. /// /// Stores the SPI peripheral for register access. In addition, it takes @@ -90,9 +86,9 @@ macro_rules! impl_spi { $(#[$spi_attr])* pub struct $Spi { peripheral: $SPI, - sclk: SCLK, - mosi: MOSI, - miso: MISO, + sclk: $sclkmod::$SCLK<$crate::port::mode::Output>, + mosi: $mosimod::$MOSI<$crate::port::mode::Output>, + miso: $misomod::$MISO<$crate::port::mode::Input>, settings: Settings, is_write_in_progress: bool, } @@ -104,8 +100,14 @@ macro_rules! impl_spi { /// The pins are not actually used directly, but they are moved into the struct in /// order to enforce that they are in the correct mode, and cannot be used by anyone /// else while SPI is active. - pub fn new(peripheral: $SPI, sclk: SCLK, mosi: MOSI, miso: MISO<$crate::port::mode::PullUp>, settings: Settings) -> Self { - let spi = Spi { + pub fn new( + peripheral: $SPI, + sclk: $sclkmod::$SCLK<$crate::port::mode::Output>, + mosi: $mosimod::$MOSI<$crate::port::mode::Output>, + miso: $misomod::$MISO<$crate::port::mode::Input<$crate::port::mode::PullUp>>, + settings: Settings + ) -> Self { + let spi = $Spi { peripheral, sclk, mosi, @@ -125,8 +127,14 @@ macro_rules! impl_spi { /// The pins are not actually used directly, but they are moved into the struct in /// order to enforce that they are in the correct mode, and cannot be used by anyone /// else while SPI is active. - pub fn with_external_pullup(peripheral: $SPI, sclk: SCLK, mosi: MOSI, miso: MISO<$crate::port::mode::Floating>, settings: Settings) -> Self { - let spi = Spi { + pub fn with_external_pullup( + peripheral: $SPI, + sclk: $sclkmod::$SCLK<$crate::port::mode::Output>, + mosi: $mosimod::$MOSI<$crate::port::mode::Output>, + miso: $misomod::$MISO<$crate::port::mode::Input<$crate::port::mode::Floating>>, + settings: Settings + ) -> Self { + let spi = $Spi { peripheral, sclk, mosi, @@ -143,7 +151,12 @@ macro_rules! impl_spi { /// Disable the SPI device and release ownership of the peripheral /// and pins. Instance can no-longer be used after this is /// invoked. - pub fn release(self) -> ($SPI, SCLK, MOSI, MISO) { + pub fn release(self) -> ( + $SPI, + $sclkmod::$SCLK<$crate::port::mode::Output>, + $mosimod::$MOSI<$crate::port::mode::Output>, + $misomod::$MISO<$crate::port::mode::Input>, + ) { self.peripheral.spcr.write(|w| { w.spe().clear_bit() }); diff --git a/avr-hal-generic/src/wdt.rs b/avr-hal-generic/src/wdt.rs index 2726aeb0b5..3cfb0d7dfb 100644 --- a/avr-hal-generic/src/wdt.rs +++ b/avr-hal-generic/src/wdt.rs @@ -85,7 +85,7 @@ macro_rules! impl_wdt { // 2. Within the next four clock cycles, write the WDE and Watchdog prescaler // bits (WDP) as desired, but with the WDCE bit cleared. This must be done in // one operation. - avr_hal::avr_device::interrupt::free(|_| { + $crate::avr_device::interrupt::free(|_| { // Reset the watchdog timer self.feed(); // Enable watchdog configuration mode @@ -116,7 +116,7 @@ macro_rules! impl_wdt { // previous value of the WDE bit. // 2. Within the next four clock cycles, clear the WDE and WDCE bits. // This must be done in one operation. - avr_hal::avr_device::interrupt::free(|_| { + $crate::avr_device::interrupt::free(|_| { // Reset the watchdog timer self.feed(); // Enable watchdog configuration mode diff --git a/boards/arduino-diecimila/examples/diecimila-panic.rs b/boards/arduino-diecimila/examples/diecimila-panic.rs index 6ffca0665f..d4a997ab78 100644 --- a/boards/arduino-diecimila/examples/diecimila-panic.rs +++ b/boards/arduino-diecimila/examples/diecimila-panic.rs @@ -34,7 +34,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-diecimila/src/lib.rs b/boards/arduino-diecimila/src/lib.rs index ede3c75e5c..85d9a9f91f 100644 --- a/boards/arduino-diecimila/src/lib.rs +++ b/boards/arduino-diecimila/src/lib.rs @@ -1,20 +1,25 @@ #![no_std] -pub extern crate atmega168_hal as hal; +// Expose hal & pac crates +pub use atmega168_hal as hal; +pub use crate::hal::pac; + /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] -pub use hal::entry; +pub use crate::hal::entry; mod pins; -pub use crate::atmega168::Peripherals; +pub use crate::pac::Peripherals; pub use crate::pins::*; -pub use atmega168_hal::adc; -pub use atmega168_hal::atmega168; -pub use atmega168_hal::prelude; -pub use atmega168_hal::pwm; -pub use atmega168_hal::spi; +pub use crate::hal::adc; +pub mod prelude { + pub use crate::hal::prelude::*; + pub use crate::hal::usart::BaudrateArduinoExt as _; +} +pub use crate::hal::pwm; +pub use crate::hal::spi; -pub type Delay = hal::delay::Delay; -pub type Serial = hal::usart::Usart0; -pub type I2c = hal::i2c::I2c; +pub type Delay = crate::hal::delay::Delay; +pub type Serial = crate::hal::usart::Usart0; +pub type I2c = crate::hal::i2c::I2c; diff --git a/boards/arduino-diecimila/src/pins.rs b/boards/arduino-diecimila/src/pins.rs index ca5cadf008..d55ce0a39d 100644 --- a/boards/arduino-diecimila/src/pins.rs +++ b/boards/arduino-diecimila/src/pins.rs @@ -1,14 +1,14 @@ -use atmega168_hal::port::PortExt; +use crate::hal::port::PortExt; avr_hal_generic::impl_board_pins! { #[port_defs] - use atmega168_hal::port; + use crate::hal::port; /// Generic DDR that works for all ports pub struct DDR { - portb: crate::atmega168::PORTB, - portc: crate::atmega168::PORTC, - portd: crate::atmega168::PORTD, + portb: crate::pac::PORTB, + portc: crate::pac::PORTC, + portd: crate::pac::PORTD, } /// Reexport of the Diecimila's pins, with the names they have on the board diff --git a/boards/arduino-leonardo/examples/leonardo-adc.rs b/boards/arduino-leonardo/examples/leonardo-adc.rs index 575ccafd88..d159da8ac9 100644 --- a/boards/arduino-leonardo/examples/leonardo-adc.rs +++ b/boards/arduino-leonardo/examples/leonardo-adc.rs @@ -15,7 +15,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Reading analog inputs ...\r").void_unwrap(); diff --git a/boards/arduino-leonardo/examples/leonardo-i2cdetect.rs b/boards/arduino-leonardo/examples/leonardo-i2cdetect.rs index 689050678a..49c0ac3b34 100644 --- a/boards/arduino-leonardo/examples/leonardo-i2cdetect.rs +++ b/boards/arduino-leonardo/examples/leonardo-i2cdetect.rs @@ -13,7 +13,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); let mut i2c = arduino_leonardo::I2c::new( dp.TWI, diff --git a/boards/arduino-leonardo/examples/leonardo-panic.rs b/boards/arduino-leonardo/examples/leonardo-panic.rs index fb0195b37a..7d3792b610 100644 --- a/boards/arduino-leonardo/examples/leonardo-panic.rs +++ b/boards/arduino-leonardo/examples/leonardo-panic.rs @@ -35,7 +35,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-leonardo/examples/leonardo-serial.rs b/boards/arduino-leonardo/examples/leonardo-serial.rs index 88c1f452f2..aef1004391 100644 --- a/boards/arduino-leonardo/examples/leonardo-serial.rs +++ b/boards/arduino-leonardo/examples/leonardo-serial.rs @@ -14,7 +14,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-leonardo/examples/leonardo-spi-feedback.rs b/boards/arduino-leonardo/examples/leonardo-spi-feedback.rs index b1371bd3d3..158a611c04 100644 --- a/boards/arduino-leonardo/examples/leonardo-spi-feedback.rs +++ b/boards/arduino-leonardo/examples/leonardo-spi-feedback.rs @@ -25,7 +25,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); pins.led_rx.into_output(&mut pins.ddr); // SS must be set to output mode. diff --git a/boards/arduino-leonardo/src/lib.rs b/boards/arduino-leonardo/src/lib.rs index 98317cd279..35c2f270fa 100644 --- a/boards/arduino-leonardo/src/lib.rs +++ b/boards/arduino-leonardo/src/lib.rs @@ -41,18 +41,24 @@ #![no_std] -pub extern crate atmega32u4_hal as hal; +// Expose hal & pac crates +pub use atmega32u4_hal as hal; +pub use crate::hal::pac; + /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] -pub use hal::entry; +pub use crate::hal::entry; + +pub use crate::pac::Peripherals; mod pins; pub use crate::pins::*; -pub use atmega32u4_hal::atmega32u4; -pub use crate::atmega32u4::Peripherals; -pub use atmega32u4_hal::prelude; - +pub mod prelude { + pub use crate::hal::prelude::*; + pub use crate::hal::usart::BaudrateExt as _; +} +pub use crate::hal::usart; /// Busy-Delay /// @@ -185,7 +191,7 @@ pub mod pwm { /// dp.USART1, /// pins.d0, /// pins.d1.into_output(&mut pins.ddr), -/// 57600, +/// 57600.into_baudrate(), /// ); /// /// ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-leonardo/src/pins.rs b/boards/arduino-leonardo/src/pins.rs index 015f7f5f4a..06c9ebc7c1 100644 --- a/boards/arduino-leonardo/src/pins.rs +++ b/boards/arduino-leonardo/src/pins.rs @@ -1,16 +1,16 @@ -use atmega32u4_hal::port::PortExt; +use crate::hal::port::PortExt; avr_hal_generic::impl_board_pins! { #[port_defs] - use atmega32u4_hal::port; + use crate::hal::port; /// Generic DDR that works for all ports pub struct DDR { - portb: crate::atmega32u4::PORTB, - portc: crate::atmega32u4::PORTC, - portd: crate::atmega32u4::PORTD, - porte: crate::atmega32u4::PORTE, - portf: crate::atmega32u4::PORTF, + portb: crate::pac::PORTB, + portc: crate::pac::PORTC, + portd: crate::pac::PORTD, + porte: crate::pac::PORTE, + portf: crate::pac::PORTF, } /// Reexport of the Leonardo's pins, with the names they have on the board diff --git a/boards/arduino-mega2560/examples/mega2560-adc.rs b/boards/arduino-mega2560/examples/mega2560-adc.rs index 20bb887f93..9b7df8d1cc 100644 --- a/boards/arduino-mega2560/examples/mega2560-adc.rs +++ b/boards/arduino-mega2560/examples/mega2560-adc.rs @@ -27,7 +27,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Reading analog inputs ...\r").void_unwrap(); diff --git a/boards/arduino-mega2560/examples/mega2560-i2cdetect.rs b/boards/arduino-mega2560/examples/mega2560-i2cdetect.rs index 15e84fdb31..8da76a215c 100644 --- a/boards/arduino-mega2560/examples/mega2560-i2cdetect.rs +++ b/boards/arduino-mega2560/examples/mega2560-i2cdetect.rs @@ -17,7 +17,7 @@ fn main() -> ! { dp.USART0, porte.pe0, porte.pe1.into_output(&mut porte.ddr), - 57600, + 57600.into_baudrate(), ); let mut i2c = arduino_mega2560::I2c::new( dp.TWI, diff --git a/boards/arduino-mega2560/examples/mega2560-panic.rs b/boards/arduino-mega2560/examples/mega2560-panic.rs index 5c0d8f2f21..b1e8fc01fa 100644 --- a/boards/arduino-mega2560/examples/mega2560-panic.rs +++ b/boards/arduino-mega2560/examples/mega2560-panic.rs @@ -34,7 +34,7 @@ fn main() -> ! { dp.USART0, porte.pe0, porte.pe1.into_output(&mut porte.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from MEGA2560!\r").void_unwrap(); diff --git a/boards/arduino-mega2560/examples/mega2560-serial.rs b/boards/arduino-mega2560/examples/mega2560-serial.rs index 230988f579..538f1ffe86 100644 --- a/boards/arduino-mega2560/examples/mega2560-serial.rs +++ b/boards/arduino-mega2560/examples/mega2560-serial.rs @@ -13,7 +13,7 @@ fn main() -> ! { dp.USART0, porte.pe0, porte.pe1.into_output(&mut porte.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-mega2560/examples/mega2560-spi-feedback.rs b/boards/arduino-mega2560/examples/mega2560-spi-feedback.rs index 9b33492bbb..c5752e0ece 100644 --- a/boards/arduino-mega2560/examples/mega2560-spi-feedback.rs +++ b/boards/arduino-mega2560/examples/mega2560-spi-feedback.rs @@ -42,7 +42,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); pins.d53.into_output(&mut pins.ddr); // SS must be set to output mode. diff --git a/boards/arduino-mega2560/src/lib.rs b/boards/arduino-mega2560/src/lib.rs index 94dad64dc2..9c9097324a 100644 --- a/boards/arduino-mega2560/src/lib.rs +++ b/boards/arduino-mega2560/src/lib.rs @@ -1,22 +1,29 @@ #![no_std] -pub extern crate atmega2560_hal as hal; +// Expose hal & pac crates +pub use atmega2560_hal as hal; +pub use crate::hal::pac; + /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] -pub use hal::entry; +pub use crate::hal::entry; -mod pins; +pub use crate::pac::Peripherals; -pub use atmega2560_hal::atmega2560; -pub use crate::atmega2560::Peripherals; -pub use atmega2560_hal::prelude; -pub use atmega2560_hal::spi; -pub use atmega2560_hal::adc; +mod pins; pub use crate::pins::*; -pub type Delay = hal::delay::Delay; -pub type Serial = atmega2560_hal::usart::Usart0; -pub type I2c = hal::i2c::I2c; +pub mod prelude { + pub use crate::hal::prelude::*; + pub use crate::hal::usart::BaudrateExt as _; +} + +pub use crate::hal::spi; +pub use crate::hal::adc; + +pub type Delay = crate::hal::delay::Delay; +pub type Serial = crate::hal::usart::Usart0; +pub type I2c = crate::hal::i2c::I2c; /// Support for PWM pins /// @@ -62,5 +69,5 @@ pub type I2c = hal::i2c::I2c; /// /// [ex-pwm]: https://github.com/sepotvin/avr-hal/blob/master/boards/arduino-mega2560/examples/mega2560-pwm.rs pub mod pwm { - pub use atmega2560_hal::pwm::*; -} \ No newline at end of file + pub use crate::hal::pwm::*; +} diff --git a/boards/arduino-mega2560/src/pins.rs b/boards/arduino-mega2560/src/pins.rs index 1faff479f8..ad856411a7 100644 --- a/boards/arduino-mega2560/src/pins.rs +++ b/boards/arduino-mega2560/src/pins.rs @@ -1,22 +1,22 @@ -use atmega2560_hal::port::PortExt; +use crate::hal::port::PortExt; avr_hal_generic::impl_board_pins! { #[port_defs] - use atmega2560_hal::port; + use crate::hal::port; /// Generic DDR that works for all ports pub struct DDR { - porta: crate::atmega2560::PORTA, - portb: crate::atmega2560::PORTB, - portc: crate::atmega2560::PORTC, - portd: crate::atmega2560::PORTD, - porte: crate::atmega2560::PORTE, - portf: crate::atmega2560::PORTF, - portg: crate::atmega2560::PORTG, - porth: crate::atmega2560::PORTH, - portj: crate::atmega2560::PORTJ, - portk: crate::atmega2560::PORTK, - portl: crate::atmega2560::PORTL, + porta: crate::pac::PORTA, + portb: crate::pac::PORTB, + portc: crate::pac::PORTC, + portd: crate::pac::PORTD, + porte: crate::pac::PORTE, + portf: crate::pac::PORTF, + portg: crate::pac::PORTG, + porth: crate::pac::PORTH, + portj: crate::pac::PORTJ, + portk: crate::pac::PORTK, + portl: crate::pac::PORTL, } /// Reexport of the Mega 2560's pins, with the names they have on the board diff --git a/boards/arduino-uno/Cargo.toml b/boards/arduino-uno/Cargo.toml index 2fbe72637d..0fbdd562c1 100644 --- a/boards/arduino-uno/Cargo.toml +++ b/boards/arduino-uno/Cargo.toml @@ -10,7 +10,7 @@ rt = ["atmega328p-hal/rt"] arduino-nano = ["atmega328p-hal/adc-pins"] [dependencies] -atmega328p-hal = { path = "../../chips/atmega328p-hal/" } +atmega328p-hal = { path = "../../chips/atmega328p-hal/", features = ["atmega328p"] } avr-hal-generic = { path = "../../avr-hal-generic/" } [dev-dependencies] diff --git a/boards/arduino-uno/examples/uno-adc.rs b/boards/arduino-uno/examples/uno-adc.rs index 85af87aea9..257626f1cf 100644 --- a/boards/arduino-uno/examples/uno-adc.rs +++ b/boards/arduino-uno/examples/uno-adc.rs @@ -18,7 +18,7 @@ fn main() -> ! { let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD); let mut serial = - arduino_uno::Serial::new(dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), 9600); + arduino_uno::Serial::new(dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), 9600.into_baudrate()); let mut adc = adc::Adc::new(dp.ADC, Default::default()); diff --git a/boards/arduino-uno/examples/uno-hc-sr04.rs b/boards/arduino-uno/examples/uno-hc-sr04.rs index 0479dacc2e..1f4360a3fa 100644 --- a/boards/arduino-uno/examples/uno-hc-sr04.rs +++ b/boards/arduino-uno/examples/uno-hc-sr04.rs @@ -16,7 +16,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); let timer1 = dp.TC1; diff --git a/boards/arduino-uno/examples/uno-i2cdetect.rs b/boards/arduino-uno/examples/uno-i2cdetect.rs index f73d2ee17c..24c2ef1ef5 100644 --- a/boards/arduino-uno/examples/uno-i2cdetect.rs +++ b/boards/arduino-uno/examples/uno-i2cdetect.rs @@ -13,7 +13,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); let mut i2c = arduino_uno::I2c::new( dp.TWI, diff --git a/boards/arduino-uno/examples/uno-panic.rs b/boards/arduino-uno/examples/uno-panic.rs index dbba954efb..7d77097d9c 100644 --- a/boards/arduino-uno/examples/uno-panic.rs +++ b/boards/arduino-uno/examples/uno-panic.rs @@ -34,7 +34,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-uno/examples/uno-serial.rs b/boards/arduino-uno/examples/uno-serial.rs index 086d422bcc..39e59cca19 100644 --- a/boards/arduino-uno/examples/uno-serial.rs +++ b/boards/arduino-uno/examples/uno-serial.rs @@ -19,7 +19,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-uno/examples/uno-spi-feedback.rs b/boards/arduino-uno/examples/uno-spi-feedback.rs index 780a7d5070..ba71258cdc 100644 --- a/boards/arduino-uno/examples/uno-spi-feedback.rs +++ b/boards/arduino-uno/examples/uno-spi-feedback.rs @@ -29,7 +29,7 @@ fn main() -> ! { dp.USART0, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); pins.d10.into_output(&mut pins.ddr); // SS must be set to output mode. diff --git a/boards/arduino-uno/src/lib.rs b/boards/arduino-uno/src/lib.rs index 94603c78be..f1d5b2ab2a 100644 --- a/boards/arduino-uno/src/lib.rs +++ b/boards/arduino-uno/src/lib.rs @@ -55,17 +55,23 @@ #![no_std] -pub extern crate atmega328p_hal as hal; +// Expose hal & pac crates +pub use atmega328p_hal as hal; +pub use crate::hal::pac; + /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] -pub use hal::entry; +pub use crate::hal::entry; + +pub use crate::pac::Peripherals; mod pins; pub use crate::pins::*; -pub use atmega328p_hal::atmega328p; -pub use crate::atmega328p::Peripherals; -pub use atmega328p_hal::prelude; +pub mod prelude { + pub use crate::hal::prelude::*; + pub use crate::hal::usart::BaudrateArduinoExt as _; +} /// Busy-Delay /// @@ -189,7 +195,7 @@ pub mod pwm { /// dp.USART0, /// pins.d0, /// pins.d1.into_output(&mut pins.ddr), -/// 57600, +/// 57600.into_baudrate(), /// ); /// /// ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/arduino-uno/src/pins.rs b/boards/arduino-uno/src/pins.rs index 9670b41401..53c41cc233 100644 --- a/boards/arduino-uno/src/pins.rs +++ b/boards/arduino-uno/src/pins.rs @@ -1,14 +1,14 @@ -use atmega328p_hal::port::PortExt; +use crate::hal::port::PortExt; avr_hal_generic::impl_board_pins! { #[port_defs] - use atmega328p_hal::port; + use crate::hal::port; /// Generic DDR that works for all ports pub struct DDR { - portb: crate::atmega328p::PORTB, - portc: crate::atmega328p::PORTC, - portd: crate::atmega328p::PORTD, + portb: crate::pac::PORTB, + portc: crate::pac::PORTC, + portd: crate::pac::PORTD, } /// Reexport of the Leonardo's pins, with the names they have on the board diff --git a/boards/bigavr6/examples/bigavr6-i2cdetect.rs b/boards/bigavr6/examples/bigavr6-i2cdetect.rs index f0b194cf64..e02edc6c7b 100644 --- a/boards/bigavr6/examples/bigavr6-i2cdetect.rs +++ b/boards/bigavr6/examples/bigavr6-i2cdetect.rs @@ -17,7 +17,7 @@ fn main() -> ! { dp.USART0, porte.pe0, porte.pe1.into_output(&mut porte.ddr), - 57600, + 57600.into_baudrate(), ); let mut i2c = bigavr6::I2c::new( dp.TWI, diff --git a/boards/bigavr6/examples/bigavr6-panic.rs b/boards/bigavr6/examples/bigavr6-panic.rs index 3c2420983a..d67f276fcf 100644 --- a/boards/bigavr6/examples/bigavr6-panic.rs +++ b/boards/bigavr6/examples/bigavr6-panic.rs @@ -34,7 +34,7 @@ fn main() -> ! { dp.USART0, porte.pe0, porte.pe1.into_output(&mut porte.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from BIGAVR6!\r").void_unwrap(); diff --git a/boards/bigavr6/examples/bigavr6-serial.rs b/boards/bigavr6/examples/bigavr6-serial.rs index 4e37e9ff47..3ad6631de9 100644 --- a/boards/bigavr6/examples/bigavr6-serial.rs +++ b/boards/bigavr6/examples/bigavr6-serial.rs @@ -13,7 +13,7 @@ fn main() -> ! { dp.USART0, porte.pe0, porte.pe1.into_output(&mut porte.ddr), - 57600, + 57600.into_baudrate(), ); // The following would also work, but needs +600% more bytes diff --git a/boards/bigavr6/src/lib.rs b/boards/bigavr6/src/lib.rs index db28430ab2..67444d8365 100644 --- a/boards/bigavr6/src/lib.rs +++ b/boards/bigavr6/src/lib.rs @@ -1,14 +1,19 @@ #![no_std] -pub extern crate atmega1280_hal as hal; +// Expose hal & pac crates +pub use atmega1280_hal as hal; +pub use crate::hal::pac; + /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] -pub use hal::entry; +pub use crate::hal::entry; -pub use atmega1280_hal::atmega1280; -pub use crate::atmega1280::Peripherals; -pub use atmega1280_hal::prelude; +pub use crate::pac::Peripherals; +pub mod prelude { + pub use crate::hal::prelude::*; + pub use crate::hal::usart::BaudrateExt as _; +} -pub type Delay = hal::delay::Delay; -pub type Serial = atmega1280_hal::usart::Usart0; -pub type I2c = hal::i2c::I2c; +pub type Delay = crate::hal::delay::Delay; +pub type Serial = crate::hal::usart::Usart0; +pub type I2c = crate::hal::i2c::I2c; diff --git a/boards/sparkfun-pro-micro/examples/pro-micro-adc.rs b/boards/sparkfun-pro-micro/examples/pro-micro-adc.rs index c7306474cb..f278aaca92 100644 --- a/boards/sparkfun-pro-micro/examples/pro-micro-adc.rs +++ b/boards/sparkfun-pro-micro/examples/pro-micro-adc.rs @@ -15,7 +15,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Reading analog inputs ...\r").void_unwrap(); diff --git a/boards/sparkfun-pro-micro/examples/pro-micro-i2cdetect.rs b/boards/sparkfun-pro-micro/examples/pro-micro-i2cdetect.rs index acb99f921f..0145c89c45 100644 --- a/boards/sparkfun-pro-micro/examples/pro-micro-i2cdetect.rs +++ b/boards/sparkfun-pro-micro/examples/pro-micro-i2cdetect.rs @@ -13,7 +13,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); let mut i2c = sparkfun_pro_micro::I2c::new( dp.TWI, diff --git a/boards/sparkfun-pro-micro/examples/pro-micro-panic.rs b/boards/sparkfun-pro-micro/examples/pro-micro-panic.rs index fe36f584bc..1a2937bd61 100644 --- a/boards/sparkfun-pro-micro/examples/pro-micro-panic.rs +++ b/boards/sparkfun-pro-micro/examples/pro-micro-panic.rs @@ -35,7 +35,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/sparkfun-pro-micro/examples/pro-micro-serial.rs b/boards/sparkfun-pro-micro/examples/pro-micro-serial.rs index 86ca7fdab9..c050c7d5ec 100644 --- a/boards/sparkfun-pro-micro/examples/pro-micro-serial.rs +++ b/boards/sparkfun-pro-micro/examples/pro-micro-serial.rs @@ -14,7 +14,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/sparkfun-pro-micro/examples/pro-micro-spi-feedback.rs b/boards/sparkfun-pro-micro/examples/pro-micro-spi-feedback.rs index 948f376f99..0de0883f17 100644 --- a/boards/sparkfun-pro-micro/examples/pro-micro-spi-feedback.rs +++ b/boards/sparkfun-pro-micro/examples/pro-micro-spi-feedback.rs @@ -25,7 +25,7 @@ fn main() -> ! { dp.USART1, pins.d0, pins.d1.into_output(&mut pins.ddr), - 57600, + 57600.into_baudrate(), ); pins.led_rx.into_output(&mut pins.ddr); // SS must be set to output mode. diff --git a/boards/sparkfun-pro-micro/src/lib.rs b/boards/sparkfun-pro-micro/src/lib.rs index 3107d348c3..bdae34e886 100644 --- a/boards/sparkfun-pro-micro/src/lib.rs +++ b/boards/sparkfun-pro-micro/src/lib.rs @@ -41,17 +41,21 @@ #![no_std] -pub extern crate atmega32u4_hal as hal; +pub use atmega32u4_hal as hal; +pub use crate::hal::pac; + /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] -pub use hal::entry; +pub use crate::hal::entry; mod pins; pub use crate::pins::*; -pub use atmega32u4_hal::atmega32u4; -pub use crate::atmega32u4::Peripherals; -pub use atmega32u4_hal::prelude; +pub use crate::pac::Peripherals; +pub mod prelude { + pub use crate::hal::prelude::*; + pub use crate::hal::usart::BaudrateExt as _; +} /// Busy-Delay @@ -182,7 +186,7 @@ pub mod pwm { /// dp.USART1, /// pins.d0, /// pins.d1.into_output(&mut pins.ddr), -/// 57600, +/// 57600.into_baudrate(), /// ); /// /// ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); diff --git a/boards/sparkfun-pro-micro/src/pins.rs b/boards/sparkfun-pro-micro/src/pins.rs index 99fc8f0844..632bb7f09e 100644 --- a/boards/sparkfun-pro-micro/src/pins.rs +++ b/boards/sparkfun-pro-micro/src/pins.rs @@ -1,16 +1,16 @@ -use atmega32u4_hal::port::PortExt; +use crate::hal::port::PortExt; avr_hal_generic::impl_board_pins! { #[port_defs] - use atmega32u4_hal::port; + use crate::hal::port; /// Generic DDR that works for all ports pub struct DDR { - portb: crate::atmega32u4::PORTB, - portc: crate::atmega32u4::PORTC, - portd: crate::atmega32u4::PORTD, - porte: crate::atmega32u4::PORTE, - portf: crate::atmega32u4::PORTF, + portb: crate::pac::PORTB, + portc: crate::pac::PORTC, + portd: crate::pac::PORTD, + porte: crate::pac::PORTE, + portf: crate::pac::PORTF, } /// Reexport of the Pro Micro's pins, with the names they have on the board diff --git a/boards/trinket/src/lib.rs b/boards/trinket/src/lib.rs index 54d1c1dd3a..a16ced1edf 100644 --- a/boards/trinket/src/lib.rs +++ b/boards/trinket/src/lib.rs @@ -1,27 +1,29 @@ #![no_std] -pub extern crate attiny85_hal as hal; +// Expose hal & pac crates +pub use attiny85_hal as hal; +pub use crate::hal::pac; + /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] -pub use hal::entry; +pub use crate::hal::entry; -pub use attiny85_hal::attiny85; -pub use crate::attiny85::Peripherals; -pub use attiny85_hal::prelude; +pub use crate::pac::Peripherals; +pub use crate::hal::prelude; -pub type Delay = hal::delay::Delay; +pub type Delay = crate::hal::delay::Delay; pub use crate::pins::*; mod pins { - use attiny85_hal::port::PortExt; + use crate::hal::port::PortExt; avr_hal_generic::impl_board_pins! { #[port_defs] - use attiny85_hal::port; + use crate::hal::port; /// Generic DDR (not strictly necessary for ATtiny85) pub struct DDR { - portb: crate::attiny85::PORTB, + portb: crate::pac::PORTB, } /// Reexport of the pins with names as on the Trinket board diff --git a/chips/atmega1280-hal/src/lib.rs b/chips/atmega1280-hal/src/lib.rs index ca16a4b23c..b555d81560 100644 --- a/chips/atmega1280-hal/src/lib.rs +++ b/chips/atmega1280-hal/src/lib.rs @@ -1,30 +1,30 @@ #![no_std] -extern crate avr_hal_generic as avr_hal; +/// Reexport of `atemga1280` from `avr-device` +pub use avr_device::atmega1280 as pac; -pub use avr_device::atmega1280; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; pub mod port; pub mod usart; pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } pub mod i2c { use crate::port::portd; - pub use avr_hal::i2c::*; + pub use avr_hal_generic::i2c::*; - avr_hal::impl_twi_i2c! { + avr_hal_generic::impl_twi_i2c! { pub struct I2c { - peripheral: crate::atmega1280::TWI, + peripheral: crate::pac::TWI, pins: { sda: portd::PD1, scl: portd::PD0, diff --git a/chips/atmega1280-hal/src/port.rs b/chips/atmega1280-hal/src/port.rs index 33fe36f148..2160046ebe 100644 --- a/chips/atmega1280-hal/src/port.rs +++ b/chips/atmega1280-hal/src/port.rs @@ -4,7 +4,7 @@ //! //! [1]: ../../avr_hal_generic/port/index.html -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -12,23 +12,23 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_generic_pin! { +avr_hal_generic::impl_generic_pin! { pub enum Pin { - A(crate::atmega1280::PORTA, porta, pina, ddra), - B(crate::atmega1280::PORTB, portb, pinb, ddrb), - C(crate::atmega1280::PORTC, portc, pinc, ddrc), - D(crate::atmega1280::PORTD, portd, pind, ddrd), - E(crate::atmega1280::PORTE, porte, pine, ddre), - F(crate::atmega1280::PORTF, portf, pinf, ddrf), - G(crate::atmega1280::PORTG, portg, ping, ddrg), - H(crate::atmega1280::PORTH, porth, pinh, ddrh), - J(crate::atmega1280::PORTJ, portj, pinj, ddrj), - K(crate::atmega1280::PORTK, portk, pink, ddrk), - L(crate::atmega1280::PORTL, portl, pinl, ddrl), + A(crate::pac::PORTA, porta, pina, ddra), + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), + E(crate::pac::PORTE, porte, pine, ddre), + F(crate::pac::PORTF, portf, pinf, ddrf), + G(crate::pac::PORTG, portg, ping, ddrg), + H(crate::pac::PORTH, porth, pinh, ddrh), + J(crate::pac::PORTJ, portj, pinj, ddrj), + K(crate::pac::PORTK, portk, pink, ddrk), + L(crate::pac::PORTL, portl, pinl, ddrl), } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porta { #[port_ext] use super::PortExt; @@ -36,7 +36,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::A; - impl PortExt for crate::atmega1280::PORTA { + impl PortExt for crate::pac::PORTA { regs: (pina, ddra, porta), pa0: (PA0, 0), pa1: (PA1, 1), @@ -50,7 +50,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; @@ -58,7 +58,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::B; - impl PortExt for crate::atmega1280::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), @@ -72,7 +72,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portc { #[port_ext] use super::PortExt; @@ -80,7 +80,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::C; - impl PortExt for crate::atmega1280::PORTC { + impl PortExt for crate::pac::PORTC { regs: (pinc, ddrc, portc), pc0: (PC0, 0), pc1: (PC1, 1), @@ -94,7 +94,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portd { #[port_ext] use super::PortExt; @@ -102,7 +102,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::D; - impl PortExt for crate::atmega1280::PORTD { + impl PortExt for crate::pac::PORTD { regs: (pind, ddrd, portd), pd0: (PD0, 0), pd1: (PD1, 1), @@ -116,7 +116,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porte { #[port_ext] use super::PortExt; @@ -124,7 +124,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::E; - impl PortExt for crate::atmega1280::PORTE { + impl PortExt for crate::pac::PORTE { regs: (pine, ddre, porte), pe0: (PE0, 0), pe1: (PE1, 1), @@ -138,7 +138,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portf { #[port_ext] use super::PortExt; @@ -146,7 +146,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::F; - impl PortExt for crate::atmega1280::PORTF { + impl PortExt for crate::pac::PORTF { regs: (pinf, ddrf, portf), pf0: (PF0, 0), pf1: (PF1, 1), @@ -160,7 +160,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portg { #[port_ext] use super::PortExt; @@ -168,7 +168,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::G; - impl PortExt for crate::atmega1280::PORTG { + impl PortExt for crate::pac::PORTG { regs: (ping, ddrg, portg), pg0: (PG0, 0), pg1: (PG1, 1), @@ -180,7 +180,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porth { #[port_ext] use super::PortExt; @@ -188,7 +188,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::H; - impl PortExt for crate::atmega1280::PORTH { + impl PortExt for crate::pac::PORTH { regs: (pinh, ddrh, porth), ph0: (PH0, 0), ph1: (PH1, 1), @@ -202,7 +202,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portj { #[port_ext] use super::PortExt; @@ -210,7 +210,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::J; - impl PortExt for crate::atmega1280::PORTJ { + impl PortExt for crate::pac::PORTJ { regs: (pinj, ddrj, portj), pj0: (PJ0, 0), pj1: (PJ1, 1), @@ -224,7 +224,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portk { #[port_ext] use super::PortExt; @@ -232,7 +232,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::K; - impl PortExt for crate::atmega1280::PORTK { + impl PortExt for crate::pac::PORTK { regs: (pink, ddrk, portk), pk0: (PK0, 0), pk1: (PK1, 1), @@ -246,7 +246,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portl { #[port_ext] use super::PortExt; @@ -254,7 +254,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::L; - impl PortExt for crate::atmega1280::PORTL { + impl PortExt for crate::pac::PORTL { regs: (pinl, ddrl, portl), pl0: (PL0, 0), pl1: (PL1, 1), diff --git a/chips/atmega1280-hal/src/usart.rs b/chips/atmega1280-hal/src/usart.rs index 4baa52da0c..56b83a897b 100644 --- a/chips/atmega1280-hal/src/usart.rs +++ b/chips/atmega1280-hal/src/usart.rs @@ -2,10 +2,11 @@ use crate::port::porte; use crate::port::portd; use crate::port::porth; use crate::port::portj; +pub use avr_hal_generic::serial::*; -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart0 { - peripheral: crate::atmega1280::USART0, + peripheral: crate::pac::USART0, pins: { rx: porte::PE0, tx: porte::PE1, @@ -14,9 +15,9 @@ crate::avr_hal::impl_usart! { } } -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart1 { - peripheral: crate::atmega1280::USART1, + peripheral: crate::pac::USART1, pins: { rx: portd::PD2, tx: portd::PD3, @@ -25,9 +26,9 @@ crate::avr_hal::impl_usart! { } } -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart2 { - peripheral: crate::atmega1280::USART2, + peripheral: crate::pac::USART2, pins: { rx: porth::PH0, tx: porth::PH1, @@ -36,9 +37,9 @@ crate::avr_hal::impl_usart! { } } -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart3 { - peripheral: crate::atmega1280::USART3, + peripheral: crate::pac::USART3, pins: { rx: portj::PJ0, tx: portj::PJ1, diff --git a/chips/atmega168-hal/src/adc.rs b/chips/atmega168-hal/src/adc.rs index ff8f62a541..0bcbcd7df5 100644 --- a/chips/atmega168-hal/src/adc.rs +++ b/chips/atmega168-hal/src/adc.rs @@ -2,12 +2,12 @@ extern crate avr_hal_generic as avr_hal; use crate::port::portc::{PC0, PC1, PC2, PC3, PC4, PC5}; -use crate::atmega168::adc::admux::MUX_A; +use crate::pac::adc::admux::MUX_A; -avr_hal::impl_adc! { +avr_hal_generic::impl_adc! { pub struct Adc { type ChannelID = MUX_A; - peripheral: crate::atmega168::ADC, + peripheral: crate::pac::ADC, set_mux: |peripheral, id| { peripheral.admux.modify(|_, w| w.mux().variant(id)); }, @@ -26,8 +26,8 @@ avr_hal::impl_adc! { /// /// This module contains ADC channels, additional to the direct pin channels. pub mod channel { - use avr_hal::hal::adc::Channel; - use crate::atmega168::adc::admux::MUX_A; + use avr_hal_generic::hal::adc::Channel; + use crate::pac::adc::admux::MUX_A; /// Channel for the _Bandgap Reference Voltage_ pub struct Vbg; diff --git a/chips/atmega168-hal/src/lib.rs b/chips/atmega168-hal/src/lib.rs index 16c3be5803..d60f787ac1 100644 --- a/chips/atmega168-hal/src/lib.rs +++ b/chips/atmega168-hal/src/lib.rs @@ -5,34 +5,33 @@ //! #![no_std] -extern crate avr_hal_generic as avr_hal; +pub use avr_device::atmega168 as pac; -pub use avr_device::atmega168; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; pub mod adc; pub mod port; pub mod pwm; pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } /// I2C Bus pub mod i2c { use crate::port::portc; - pub use avr_hal::i2c::*; + pub use avr_hal_generic::i2c::*; - avr_hal::impl_twi_i2c! { + avr_hal_generic::impl_twi_i2c! { /// I2C based on ATmega168's TWI peripheral pub struct I2c { - peripheral: crate::atmega168::TWI, + peripheral: crate::pac::TWI, pins: { sda: portc::PC4, scl: portc::PC5, @@ -82,11 +81,11 @@ pub mod spi { //! also instantiate a Settings object with the other options available. use crate::port::portb; - pub use avr_hal::spi::*; + pub use avr_hal_generic::spi::*; - avr_hal::impl_spi! { + avr_hal_generic::impl_spi! { pub struct Spi { - peripheral: crate::atmega168::SPI, + peripheral: crate::pac::SPI, pins: { sclk: portb::PB5, mosi: portb::PB3, @@ -99,14 +98,14 @@ pub mod spi { /// Serial interface using USART pub mod usart { use crate::port::portd; - pub use avr_hal::serial::*; + pub use avr_hal_generic::serial::*; - crate::avr_hal::impl_usart! { + avr_hal_generic::impl_usart! { /// Serial interface based on ATmega168's USART0 peripheral /// /// Maximum baudrate seems to be 57600 pub struct Usart0 { - peripheral: crate::atmega168::USART0, + peripheral: crate::pac::USART0, pins: { rx: portd::PD0, tx: portd::PD1, diff --git a/chips/atmega168-hal/src/port.rs b/chips/atmega168-hal/src/port.rs index e99b1ac600..9fa65ca35c 100644 --- a/chips/atmega168-hal/src/port.rs +++ b/chips/atmega168-hal/src/port.rs @@ -1,5 +1,5 @@ //! `PORTB` - `PORTD` digital IO -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -7,15 +7,15 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_generic_pin! { +avr_hal_generic::impl_generic_pin! { pub enum Pin { - B(crate::atmega168::PORTB, portb, pinb, ddrb), - C(crate::atmega168::PORTC, portc, pinc, ddrc), - D(crate::atmega168::PORTD, portd, pind, ddrd), + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; @@ -23,7 +23,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::B; - impl PortExt for crate::atmega168::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), @@ -37,7 +37,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portc { #[port_ext] use super::PortExt; @@ -45,7 +45,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::C; - impl PortExt for crate::atmega168::PORTC { + impl PortExt for crate::pac::PORTC { regs: (pinc, ddrc, portc), pc0: (PC0, 0), pc1: (PC1, 1), @@ -58,7 +58,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portd { #[port_ext] use super::PortExt; @@ -66,7 +66,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::D; - impl PortExt for crate::atmega168::PORTD { + impl PortExt for crate::pac::PORTD { regs: (pind, ddrd, portd), pd0: (PD0, 0), pd1: (PD1, 1), diff --git a/chips/atmega168-hal/src/pwm.rs b/chips/atmega168-hal/src/pwm.rs index eb39a105fe..e8fe106f8e 100644 --- a/chips/atmega168-hal/src/pwm.rs +++ b/chips/atmega168-hal/src/pwm.rs @@ -26,9 +26,9 @@ //! | `PD6` | `.into_pwm(&mut timer0)` | use crate::port::{portb, portd}; -pub use avr_hal::pwm::*; +pub use avr_hal_generic::pwm::*; -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC0` for PWM (pins `PD5`, `PD6`) /// /// # Example @@ -43,7 +43,7 @@ avr_hal::impl_pwm! { /// pd5.enable(); /// ``` pub struct Timer0Pwm { - timer: crate::atmega168::TC0, + timer: crate::pac::TC0, init: |tim, prescaler| { tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast()); tim.tccr0b.modify(|_, w| match prescaler { @@ -75,7 +75,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC1` for PWM (pins `PB1`, `PB2`) /// /// # Example @@ -90,7 +90,7 @@ avr_hal::impl_pwm! { /// pb1.enable(); /// ``` pub struct Timer1Pwm { - timer: crate::atmega168::TC1, + timer: crate::pac::TC1, init: |tim, prescaler| { tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01)); tim.tccr1b.modify(|_, w| { @@ -125,7 +125,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC2` for PWM (pins `PB3`, `PD3`) /// /// # Example @@ -141,7 +141,7 @@ avr_hal::impl_pwm! { /// pb3.enable(); /// ``` pub struct Timer2Pwm { - timer: crate::atmega168::TC2, + timer: crate::pac::TC2, init: |tim, prescaler| { tim.tccr2a.modify(|_, w| w.wgm2().pwm_fast()); tim.tccr2b.modify(|_, w| match prescaler { diff --git a/chips/atmega2560-hal/src/adc.rs b/chips/atmega2560-hal/src/adc.rs index f24262531b..505d615648 100644 --- a/chips/atmega2560-hal/src/adc.rs +++ b/chips/atmega2560-hal/src/adc.rs @@ -3,12 +3,12 @@ extern crate avr_hal_generic as avr_hal; use crate::port::portf::{PF0, PF1, PF2, PF3, PF4, PF5, PF6, PF7}; use crate::port::portk::{PK0, PK1, PK2, PK3, PK4, PK5, PK6, PK7}; -use crate::atmega2560::adc::admux::MUX_A; +use crate::pac::adc::admux::MUX_A; -avr_hal::impl_adc! { +avr_hal_generic::impl_adc! { pub struct Adc { type ChannelID = MUX_A; - peripheral: crate::atmega2560::ADC, + peripheral: crate::pac::ADC, set_mux: |peripheral, id| { peripheral.admux.modify(|_, w| w.mux().variant(id)); // n.b. the high bit of ADMUX[MUX] is in the ADCSRB register @@ -39,8 +39,8 @@ avr_hal::impl_adc! { /// /// This module contains ADC channels, additional to the direct pin channels. pub mod channel { - use avr_hal::hal::adc::Channel; - use crate::atmega2560::adc::admux::MUX_A; + use avr_hal_generic::hal::adc::Channel; + use crate::pac::adc::admux::MUX_A; /// Channel for the _Bandgap Reference Voltage_ pub struct Vbg; diff --git a/chips/atmega2560-hal/src/lib.rs b/chips/atmega2560-hal/src/lib.rs index b0cd8c0500..574b1b66e9 100644 --- a/chips/atmega2560-hal/src/lib.rs +++ b/chips/atmega2560-hal/src/lib.rs @@ -1,14 +1,14 @@ #![no_std] -extern crate avr_hal_generic as avr_hal; +/// Reexport of `atmega2560` from `avr-device` +pub use avr_device::atmega2560 as pac; -pub use avr_device::atmega2560; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; pub mod adc; pub mod port; @@ -17,17 +17,17 @@ pub mod spi; pub mod usart; pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } pub mod i2c { use crate::port::portd; - pub use avr_hal::i2c::*; + pub use avr_hal_generic::i2c::*; - avr_hal::impl_twi_i2c! { + avr_hal_generic::impl_twi_i2c! { pub struct I2c { - peripheral: crate::atmega2560::TWI, + peripheral: crate::pac::TWI, pins: { sda: portd::PD1, scl: portd::PD0, diff --git a/chips/atmega2560-hal/src/port.rs b/chips/atmega2560-hal/src/port.rs index a369aa96e4..2160046ebe 100644 --- a/chips/atmega2560-hal/src/port.rs +++ b/chips/atmega2560-hal/src/port.rs @@ -4,7 +4,7 @@ //! //! [1]: ../../avr_hal_generic/port/index.html -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -12,23 +12,23 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_generic_pin! { +avr_hal_generic::impl_generic_pin! { pub enum Pin { - A(crate::atmega2560::PORTA, porta, pina, ddra), - B(crate::atmega2560::PORTB, portb, pinb, ddrb), - C(crate::atmega2560::PORTC, portc, pinc, ddrc), - D(crate::atmega2560::PORTD, portd, pind, ddrd), - E(crate::atmega2560::PORTE, porte, pine, ddre), - F(crate::atmega2560::PORTF, portf, pinf, ddrf), - G(crate::atmega2560::PORTG, portg, ping, ddrg), - H(crate::atmega2560::PORTH, porth, pinh, ddrh), - J(crate::atmega2560::PORTJ, portj, pinj, ddrj), - K(crate::atmega2560::PORTK, portk, pink, ddrk), - L(crate::atmega2560::PORTL, portl, pinl, ddrl), + A(crate::pac::PORTA, porta, pina, ddra), + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), + E(crate::pac::PORTE, porte, pine, ddre), + F(crate::pac::PORTF, portf, pinf, ddrf), + G(crate::pac::PORTG, portg, ping, ddrg), + H(crate::pac::PORTH, porth, pinh, ddrh), + J(crate::pac::PORTJ, portj, pinj, ddrj), + K(crate::pac::PORTK, portk, pink, ddrk), + L(crate::pac::PORTL, portl, pinl, ddrl), } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porta { #[port_ext] use super::PortExt; @@ -36,7 +36,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::A; - impl PortExt for crate::atmega2560::PORTA { + impl PortExt for crate::pac::PORTA { regs: (pina, ddra, porta), pa0: (PA0, 0), pa1: (PA1, 1), @@ -50,7 +50,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; @@ -58,7 +58,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::B; - impl PortExt for crate::atmega2560::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), @@ -72,7 +72,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portc { #[port_ext] use super::PortExt; @@ -80,7 +80,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::C; - impl PortExt for crate::atmega2560::PORTC { + impl PortExt for crate::pac::PORTC { regs: (pinc, ddrc, portc), pc0: (PC0, 0), pc1: (PC1, 1), @@ -94,7 +94,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portd { #[port_ext] use super::PortExt; @@ -102,7 +102,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::D; - impl PortExt for crate::atmega2560::PORTD { + impl PortExt for crate::pac::PORTD { regs: (pind, ddrd, portd), pd0: (PD0, 0), pd1: (PD1, 1), @@ -116,7 +116,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porte { #[port_ext] use super::PortExt; @@ -124,7 +124,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::E; - impl PortExt for crate::atmega2560::PORTE { + impl PortExt for crate::pac::PORTE { regs: (pine, ddre, porte), pe0: (PE0, 0), pe1: (PE1, 1), @@ -138,7 +138,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portf { #[port_ext] use super::PortExt; @@ -146,7 +146,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::F; - impl PortExt for crate::atmega2560::PORTF { + impl PortExt for crate::pac::PORTF { regs: (pinf, ddrf, portf), pf0: (PF0, 0), pf1: (PF1, 1), @@ -160,7 +160,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portg { #[port_ext] use super::PortExt; @@ -168,7 +168,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::G; - impl PortExt for crate::atmega2560::PORTG { + impl PortExt for crate::pac::PORTG { regs: (ping, ddrg, portg), pg0: (PG0, 0), pg1: (PG1, 1), @@ -180,7 +180,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porth { #[port_ext] use super::PortExt; @@ -188,7 +188,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::H; - impl PortExt for crate::atmega2560::PORTH { + impl PortExt for crate::pac::PORTH { regs: (pinh, ddrh, porth), ph0: (PH0, 0), ph1: (PH1, 1), @@ -202,7 +202,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portj { #[port_ext] use super::PortExt; @@ -210,7 +210,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::J; - impl PortExt for crate::atmega2560::PORTJ { + impl PortExt for crate::pac::PORTJ { regs: (pinj, ddrj, portj), pj0: (PJ0, 0), pj1: (PJ1, 1), @@ -224,7 +224,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portk { #[port_ext] use super::PortExt; @@ -232,7 +232,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::K; - impl PortExt for crate::atmega2560::PORTK { + impl PortExt for crate::pac::PORTK { regs: (pink, ddrk, portk), pk0: (PK0, 0), pk1: (PK1, 1), @@ -246,7 +246,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portl { #[port_ext] use super::PortExt; @@ -254,7 +254,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::L; - impl PortExt for crate::atmega2560::PORTL { + impl PortExt for crate::pac::PORTL { regs: (pinl, ddrl, portl), pl0: (PL0, 0), pl1: (PL1, 1), diff --git a/chips/atmega2560-hal/src/pwm.rs b/chips/atmega2560-hal/src/pwm.rs index a5487bf42f..bd2ba27e4e 100644 --- a/chips/atmega2560-hal/src/pwm.rs +++ b/chips/atmega2560-hal/src/pwm.rs @@ -35,9 +35,9 @@ //! | `PL5` | `.into_pwm(&mut timer5)` | | use crate::port::{portb, porte, portg, porth, portl}; -pub use avr_hal::pwm::*; +pub use avr_hal_generic::pwm::*; -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC0` for PWM (pins `PB7`, `PG5`) /// /// # Example @@ -53,7 +53,7 @@ avr_hal::impl_pwm! { /// pb7.enable(); /// ``` pub struct Timer0Pwm { - timer: crate::atmega2560::TC0, + timer: crate::pac::TC0, init: |tim, prescaler| { tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast()); tim.tccr0b.modify(|_, w| match prescaler { @@ -85,7 +85,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC1` for PWM (pins `PB5`, `PB6`, `PB7`) /// /// # Example @@ -103,7 +103,7 @@ avr_hal::impl_pwm! { /// /// **Note**: For `PB7` the method is called `into_pwm1()`! pub struct Timer1Pwm { - timer: crate::atmega2560::TC1, + timer: crate::pac::TC1, init: |tim, prescaler| { tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01)); tim.tccr1b.modify(|_, w| { @@ -146,7 +146,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC2` for PWM (pins `PB4`, `PH6`) /// /// # Example @@ -162,7 +162,7 @@ avr_hal::impl_pwm! { /// pb4.enable(); /// ``` pub struct Timer2Pwm { - timer: crate::atmega2560::TC2, + timer: crate::pac::TC2, init: |tim, prescaler| { tim.tccr2a.modify(|_, w| w.wgm2().bits(0b01)); tim.tccr2b.modify(|_, w| { @@ -197,7 +197,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC3` for PWM (pins `PE3`, `PE4`, `PE5`) /// /// # Example @@ -213,7 +213,7 @@ avr_hal::impl_pwm! { /// pe3.enable(); /// ``` pub struct Timer3Pwm { - timer: crate::atmega2560::TC3, + timer: crate::pac::TC3, init: |tim, prescaler| { tim.tccr3a.modify(|_, w| w.wgm3().bits(0b01)); tim.tccr3b.modify(|_, w| { @@ -256,7 +256,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC4` for PWM (pins `PH3`, `PH4`, `PH5`) /// /// # Example @@ -272,7 +272,7 @@ avr_hal::impl_pwm! { /// ph3.enable(); /// ``` pub struct Timer4Pwm { - timer: crate::atmega2560::TC4, + timer: crate::pac::TC4, init: |tim, prescaler| { tim.tccr4a.modify(|_, w| w.wgm4().bits(0b01)); tim.tccr4b.modify(|_, w| { @@ -315,7 +315,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC5` for PWM (pins `PL3`, `PL4`, `PL5`) /// /// # Example @@ -331,7 +331,7 @@ avr_hal::impl_pwm! { /// pl3.enable(); /// ``` pub struct Timer5Pwm { - timer: crate::atmega2560::TC5, + timer: crate::pac::TC5, init: |tim, prescaler| { tim.tccr5a.modify(|_, w| w.wgm5().bits(0b01)); tim.tccr5b.modify(|_, w| { diff --git a/chips/atmega2560-hal/src/spi.rs b/chips/atmega2560-hal/src/spi.rs index 0adaf38a6e..62cd39398a 100644 --- a/chips/atmega2560-hal/src/spi.rs +++ b/chips/atmega2560-hal/src/spi.rs @@ -24,13 +24,13 @@ extern crate avr_hal_generic as avr_hal; -pub use avr_hal::spi::*; +pub use avr_hal_generic::spi::*; use crate::port::portb; -avr_hal::impl_spi! { +avr_hal_generic::impl_spi! { pub struct Spi { - peripheral: crate::atmega2560::SPI, + peripheral: crate::pac::SPI, pins: { sclk: portb::PB1, mosi: portb::PB2, diff --git a/chips/atmega2560-hal/src/usart.rs b/chips/atmega2560-hal/src/usart.rs index 2b2de438b7..56b83a897b 100644 --- a/chips/atmega2560-hal/src/usart.rs +++ b/chips/atmega2560-hal/src/usart.rs @@ -2,10 +2,11 @@ use crate::port::porte; use crate::port::portd; use crate::port::porth; use crate::port::portj; +pub use avr_hal_generic::serial::*; -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart0 { - peripheral: crate::atmega2560::USART0, + peripheral: crate::pac::USART0, pins: { rx: porte::PE0, tx: porte::PE1, @@ -14,9 +15,9 @@ crate::avr_hal::impl_usart! { } } -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart1 { - peripheral: crate::atmega2560::USART1, + peripheral: crate::pac::USART1, pins: { rx: portd::PD2, tx: portd::PD3, @@ -25,9 +26,9 @@ crate::avr_hal::impl_usart! { } } -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart2 { - peripheral: crate::atmega2560::USART2, + peripheral: crate::pac::USART2, pins: { rx: porth::PH0, tx: porth::PH1, @@ -36,9 +37,9 @@ crate::avr_hal::impl_usart! { } } -crate::avr_hal::impl_usart! { +avr_hal_generic::impl_usart! { pub struct Usart3 { - peripheral: crate::atmega2560::USART3, + peripheral: crate::pac::USART3, pins: { rx: portj::PJ0, tx: portj::PJ1, diff --git a/chips/atmega328p-hal/Cargo.toml b/chips/atmega328p-hal/Cargo.toml index b9d3170745..415334b1b1 100644 --- a/chips/atmega328p-hal/Cargo.toml +++ b/chips/atmega328p-hal/Cargo.toml @@ -8,10 +8,12 @@ edition = "2018" rt = ["avr-device/rt"] # Package exposes the ADC6 and ADC7 pins (only 32TQFP, 32MLF, 32UFBGA) adc-pins = [] +device-selected = [] +atmega328p = ["avr-device/atmega328p", "device-selected"] +atmega328pb = ["avr-device/atmega328pb", "device-selected"] [dependencies] avr-hal-generic = { path = "../../avr-hal-generic/" } [dependencies.avr-device] version = "0.2.2" -features = ["atmega328p"] diff --git a/chips/atmega328p-hal/src/adc.rs b/chips/atmega328p-hal/src/adc.rs index ee5724dd64..080ae6e0c2 100644 --- a/chips/atmega328p-hal/src/adc.rs +++ b/chips/atmega328p-hal/src/adc.rs @@ -2,12 +2,12 @@ extern crate avr_hal_generic as avr_hal; use crate::port::portc::{PC0, PC1, PC2, PC3, PC4, PC5}; -use crate::atmega328p::adc::admux::MUX_A; +use crate::pac::adc::admux::MUX_A; -avr_hal::impl_adc! { +avr_hal_generic::impl_adc! { pub struct Adc { type ChannelID = MUX_A; - peripheral: crate::atmega328p::ADC, + peripheral: crate::pac::ADC, set_mux: |peripheral, id| { peripheral.admux.modify(|_, w| w.mux().variant(id)); }, @@ -26,8 +26,8 @@ avr_hal::impl_adc! { /// /// This module contains ADC channels, additional to the direct pin channels. pub mod channel { - use avr_hal::hal::adc::Channel; - use crate::atmega328p::adc::admux::MUX_A; + use avr_hal_generic::hal::adc::Channel; + use crate::pac::adc::admux::MUX_A; /// Channel for `ADC6` pin. /// diff --git a/chips/atmega328p-hal/src/lib.rs b/chips/atmega328p-hal/src/lib.rs index f3c7ddf8ba..f76b1c6484 100644 --- a/chips/atmega328p-hal/src/lib.rs +++ b/chips/atmega328p-hal/src/lib.rs @@ -1,35 +1,56 @@ #![no_std] -extern crate avr_hal_generic as avr_hal; +#[cfg(not(feature = "device-selected"))] +compile_error!( + "This crate requires you to specify your target chip as a feature. + + Please select one of the following + + * atmega328p + * atmega328pb + " +); + + +/// Reexport of `atmega328p` from `avr-device` +#[cfg(feature = "atmega328p")] +pub use avr_device::atmega328p as pac; +/// Reexport of `atmega328pb` from `avr-device` +#[cfg(feature = "atmega328pb")] +pub use avr_device::atmega328pb as pac; -pub use avr_device::atmega328p; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; +#[cfg(feature = "device-selected")] pub mod port; - +#[cfg(feature = "device-selected")] pub mod adc; +#[cfg(feature = "device-selected")] pub mod pwm; +#[cfg(feature = "device-selected")] pub mod wdt; +#[cfg(feature = "device-selected")] pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } +#[cfg(feature = "atmega328p")] /// I2C Bus pub mod i2c { use crate::port::portc; - pub use avr_hal::i2c::*; + pub use avr_hal_generic::i2c::*; - avr_hal::impl_twi_i2c! { + avr_hal_generic::impl_twi_i2c! { /// I2C based on ATmega328P's TWI peripheral pub struct I2c { - peripheral: crate::atmega328p::TWI, + peripheral: crate::pac::TWI, pins: { sda: portc::PC4, scl: portc::PC5, @@ -53,6 +74,66 @@ pub mod i2c { } } +#[cfg(feature = "atmega328pb")] +/// I2C Bus +pub mod i2c { + use crate::port::{portc, porte}; + pub use avr_hal_generic::i2c::*; + + avr_hal_generic::impl_twi_i2c! { + /// I2C based on ATmega328P's TWI peripheral + pub struct I2c0 { + peripheral: crate::pac::TWI0, + pins: { + sda: portc::PC4, + scl: portc::PC5, + }, + registers: { + control: twcr { + enable: twen, + ack: twea, + int: twint, + start: twsta, + stop: twsto, + }, + status: twsr { + prescaler: twps, + status: tws, + }, + bitrate: twbr, + data: twdr, + }, + } + } + + avr_hal_generic::impl_twi_i2c! { + /// I2C based on ATmega328P's TWI peripheral + pub struct I2c1 { + peripheral: crate::pac::TWI1, + pins: { + sda: porte::PE0, + scl: porte::PE1, + }, + registers: { + control: twcr { + enable: twen, + ack: twea, + int: twint, + start: twsta, + stop: twsto, + }, + status: twsr { + prescaler: twps, + status: tws, + }, + bitrate: twbr, + data: twdr, + }, + } + } +} + +#[cfg(feature = "atmega328p")] pub mod spi { //! Implementation of the Rust Embedded-HAL SPI FullDuplex trait for AVR. //! @@ -79,11 +160,11 @@ pub mod spi { //! also instantiate a Settings object with the other options available. use crate::port::portb; - pub use avr_hal::spi::*; + pub use avr_hal_generic::spi::*; - avr_hal::impl_spi! { + avr_hal_generic::impl_spi! { pub struct Spi { - peripheral: crate::atmega328p::SPI, + peripheral: crate::pac::SPI, pins: { sclk: portb::PB5, mosi: portb::PB3, @@ -93,17 +174,71 @@ pub mod spi { } } +#[cfg(feature = "atmega328pb")] +pub mod spi { + //! Implementation of the Rust Embedded-HAL SPI FullDuplex trait for AVR. + //! + //! The interface can be instantiated with the `new` method, and used directly + //! or passed into a driver. Example usage: + //! + //! ``` + //! pins.d10.into_output(&mut pins.ddr);// SS must be set to output mode + //! // create SPI interface + //! let mut spi = Spi0::new( + //! dp.SPI,// SPI peripheral + //! pins.d13.into_output(&mut pins.ddr),// SCLK + //! pins.d11.into_output(&mut pins.ddr),// MOSI output pin + //! pins.d12.into_pull_up_input(&mut pins.ddr),// MISO input pin + //! Settings::default(), + //! ); + //! + //! // Send a byte + //! let sent = 0b10101010; + //! spi.send(sent).unwrap(); + //! let response = spi.read().unwrap(); + //! ``` + //! In the example above, all of the settings are left at the default. You can + //! also instantiate a Settings object with the other options available. + + use crate::port::{portb, portc, porte}; + pub use avr_hal_generic::spi::*; + + avr_hal_generic::impl_spi! { + pub struct Spi0 { + peripheral: crate::pac::SPI0, + pins: { + sclk: portb::PB5, + mosi: portb::PB3, + miso: portb::PB4, + } + } + } + + avr_hal_generic::impl_spi! { + pub struct Spi1 { + peripheral: crate::pac::SPI1, + pins: { + sclk: portc::PC1, + mosi: porte::PE3, + miso: portc::PC0, + } + } + } +} + /// Serial interface using USART +#[cfg(feature = "device-selected")] pub mod usart { - use crate::port::portd; - pub use avr_hal::serial::*; + #[allow(unused_imports)] + use crate::port::{portb, portd}; + pub use avr_hal_generic::serial::*; - crate::avr_hal::impl_usart! { + avr_hal_generic::impl_usart! { /// Serial interface based on ATmega328P's USART0 peripheral /// /// Maximum baudrate seems to be 57600 pub struct Usart0 { - peripheral: crate::atmega328p::USART0, + peripheral: crate::pac::USART0, pins: { rx: portd::PD0, tx: portd::PD1, @@ -111,4 +246,19 @@ pub mod usart { register_suffix: 0, } } + + #[cfg(feature = "atmega328pb")] + avr_hal_generic::impl_usart! { + /// Serial interface based on ATmega328PB's USART0 peripheral + /// + /// Maximum baudrate seems to be 57600 + pub struct Usart1 { + peripheral: crate::pac::USART1, + pins: { + rx: portb::PB4, + tx: portb::PB3, + }, + register_suffix: 1, + } + } } diff --git a/chips/atmega328p-hal/src/port.rs b/chips/atmega328p-hal/src/port.rs index 71623ef796..8b3117ffed 100644 --- a/chips/atmega328p-hal/src/port.rs +++ b/chips/atmega328p-hal/src/port.rs @@ -4,7 +4,7 @@ //! //! [1]: ../../avr_hal_generic/port/index.html -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -12,15 +12,27 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_generic_pin! { +#[cfg(feature = "atmega328p")] +avr_hal_generic::impl_generic_pin! { pub enum Pin { - B(crate::atmega328p::PORTB, portb, pinb, ddrb), - C(crate::atmega328p::PORTC, portc, pinc, ddrc), - D(crate::atmega328p::PORTD, portd, pind, ddrd), + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), } } -avr_hal::impl_port! { +#[cfg(feature = "atmega328pb")] +avr_hal_generic::impl_generic_pin! { + pub enum Pin { + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), + E(crate::pac::PORTE, porte, pine, ddre), + } +} + + +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; @@ -28,7 +40,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::B; - impl PortExt for crate::atmega328p::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), @@ -42,7 +54,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portc { #[port_ext] use super::PortExt; @@ -50,7 +62,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::C; - impl PortExt for crate::atmega328p::PORTC { + impl PortExt for crate::pac::PORTC { regs: (pinc, ddrc, portc), pc0: (PC0, 0), pc1: (PC1, 1), @@ -63,7 +75,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portd { #[port_ext] use super::PortExt; @@ -71,7 +83,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::D; - impl PortExt for crate::atmega328p::PORTD { + impl PortExt for crate::pac::PORTD { regs: (pind, ddrd, portd), pd0: (PD0, 0), pd1: (PD1, 1), @@ -85,3 +97,21 @@ avr_hal::impl_port! { } } +#[cfg(feature = "atmega328pb")] +avr_hal_generic::impl_port! { + pub mod porte { + #[port_ext] + use super::PortExt; + + #[generic_pin] + use Pin::E; + + impl PortExt for crate::pac::PORTE { + regs: (pine, ddre, porte), + pe0: (PE0, 0), + pe1: (PE1, 1), + pe2: (PE2, 2), + pe3: (PE3, 3), + } + } +} diff --git a/chips/atmega328p-hal/src/pwm.rs b/chips/atmega328p-hal/src/pwm.rs index 2270d3ffeb..938b76f3cc 100644 --- a/chips/atmega328p-hal/src/pwm.rs +++ b/chips/atmega328p-hal/src/pwm.rs @@ -26,9 +26,9 @@ //! | `PD6` | `.into_pwm(&mut timer0)` | use crate::port::{portb, portd}; -pub use avr_hal::pwm::*; +pub use avr_hal_generic::pwm::*; -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC0` for PWM (pins `PD5`, `PD6`) /// /// # Example @@ -43,7 +43,7 @@ avr_hal::impl_pwm! { /// pd5.enable(); /// ``` pub struct Timer0Pwm { - timer: crate::atmega328p::TC0, + timer: crate::pac::TC0, init: |tim, prescaler| { tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast()); tim.tccr0b.modify(|_, w| match prescaler { @@ -75,7 +75,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC1` for PWM (pins `PB1`, `PB2`) /// /// # Example @@ -90,7 +90,7 @@ avr_hal::impl_pwm! { /// pb1.enable(); /// ``` pub struct Timer1Pwm { - timer: crate::atmega328p::TC1, + timer: crate::pac::TC1, init: |tim, prescaler| { tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01)); tim.tccr1b.modify(|_, w| { @@ -125,7 +125,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC2` for PWM (pins `PB3`, `PD3`) /// /// # Example @@ -141,7 +141,7 @@ avr_hal::impl_pwm! { /// pb3.enable(); /// ``` pub struct Timer2Pwm { - timer: crate::atmega328p::TC2, + timer: crate::pac::TC2, init: |tim, prescaler| { tim.tccr2a.modify(|_, w| w.wgm2().pwm_fast()); tim.tccr2b.modify(|_, w| match prescaler { @@ -172,3 +172,107 @@ avr_hal::impl_pwm! { }, } } + +#[cfg(feature = "atmega328pb")] +avr_hal_generic::impl_pwm! { + /// Use `TC3` for PWM (pins `PD0`, `PD2`) + /// + /// # Example + /// ``` + /// let mut portd = dp.PORTD.split(); + /// let mut timer3 = Timer3Pwm::new(dp.TC3, pwm::Prescaler::Prescale64); + /// + /// let mut pb1 = portd.pd1.into_output(&mut portd.ddr).into_pwm(&mut timer3); + /// let mut pb2 = portd.pd2.into_output(&mut portd.ddr).into_pwm(&mut timer3); + /// + /// pd1.set_duty(128); + /// pd1.enable(); + /// ``` + pub struct Timer3Pwm { + timer: crate::pac::TC3, + init: |tim, prescaler| { + tim.tccr3a.modify(|_, w| w.wgm3().bits(0b01)); + tim.tccr3b.modify(|_, w| { + //TODO: Figure out if svdtool can mark this as safe (as for Tc1) + unsafe { w.wgm3().bits(0b01) }; + match prescaler { + Prescaler::Direct => w.cs3().direct(), + Prescaler::Prescale8 => w.cs3().prescale_8(), + Prescaler::Prescale64 => w.cs3().prescale_64(), + Prescaler::Prescale256 => w.cs3().prescale_256(), + Prescaler::Prescale1024 => w.cs3().prescale_1024(), + } + }); + }, + pins: { + portd::PD0: { + ocr: ocr3a, + into_pwm: |tim| if enable { + tim.tccr3a.modify(|_, w| w.com3a().match_clear()); + } else { + tim.tccr3a.modify(|_, w| w.com3a().disconnected()); + }, + }, + portd::PD2: { + ocr: ocr3b, + into_pwm3: |tim| if enable { + tim.tccr3a.modify(|_, w| w.com3b().match_clear()); + } else { + tim.tccr3a.modify(|_, w| w.com3b().disconnected()); + }, + }, + }, + } +} + +#[cfg(feature = "atmega328pb")] +avr_hal_generic::impl_pwm! { + /// Use `TC4` for PWM (pins `PD1`, `PD2`) + /// + /// # Example + /// ``` + /// let mut portd = dp.PORTD.split(); + /// let mut timer4 = Timer4Pwm::new(dp.TC4, pwm::Prescaler::Prescale64); + /// + /// let mut pd1 = portd.pd1.into_output(&mut portd.ddr).into_pwm(&mut timer4); + /// let mut pd2 = portd.pd2.into_output(&mut portd.ddr).into_pwm(&mut timer4); + /// + /// pd1.set_duty(128); + /// pd1.enable(); + /// ``` + pub struct Timer4Pwm { + timer: crate::pac::TC4, + init: |tim, prescaler| { + tim.tccr4a.modify(|_, w| w.wgm4().bits(0b01)); + tim.tccr4b.modify(|_, w| { + //TODO: Figure out if svdtool can mark this as safe (as for Tc1) + unsafe { w.wgm4().bits(0b01) }; + match prescaler { + Prescaler::Direct => w.cs4().direct(), + Prescaler::Prescale8 => w.cs4().prescale_8(), + Prescaler::Prescale64 => w.cs4().prescale_64(), + Prescaler::Prescale256 => w.cs4().prescale_256(), + Prescaler::Prescale1024 => w.cs4().prescale_1024(), + } + }); + }, + pins: { + portd::PD1: { + ocr: ocr4a, + into_pwm: |tim| if enable { + tim.tccr4a.modify(|_, w| w.com4a().match_clear()); + } else { + tim.tccr4a.modify(|_, w| w.com4a().disconnected()); + }, + }, + portd::PD2: { + ocr: ocr4b, + into_pwm4: |tim| if enable { + tim.tccr4a.modify(|_, w| w.com4b().match_clear()); + } else { + tim.tccr4a.modify(|_, w| w.com4b().disconnected()); + }, + }, + }, + } +} diff --git a/chips/atmega328p-hal/src/wdt.rs b/chips/atmega328p-hal/src/wdt.rs index 434106c606..4cc928c105 100644 --- a/chips/atmega328p-hal/src/wdt.rs +++ b/chips/atmega328p-hal/src/wdt.rs @@ -2,8 +2,7 @@ pub use avr_hal_generic::wdt::*; -avr_hal::impl_wdt! { - +avr_hal_generic::impl_wdt! { pub enum Timeout { /// 16 milliseconds Ms16 { wdpl().cycles_2k_512k() }, @@ -28,7 +27,7 @@ avr_hal::impl_wdt! { } pub struct Wdt { - mcu_status_register: crate::atmega328p::cpu::MCUSR, - peripheral: crate::atmega328p::WDT, + mcu_status_register: crate::pac::cpu::MCUSR, + peripheral: crate::pac::WDT, } } diff --git a/chips/atmega32u4-hal/src/adc.rs b/chips/atmega32u4-hal/src/adc.rs index cb45acf541..b5f1823434 100644 --- a/chips/atmega32u4-hal/src/adc.rs +++ b/chips/atmega32u4-hal/src/adc.rs @@ -2,7 +2,7 @@ use crate::port::portb::{PB4, PB5, PB6}; use crate::port::portd::{PD4, PD6, PD7}; use crate::port::portf::{PF0, PF1, PF4, PF5, PF6, PF7}; -pub use crate::avr_hal::adc::*; +pub use avr_hal_generic::adc::*; #[doc(hidden)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] @@ -28,10 +28,10 @@ pub enum AdcMux { AdcTemp = 0b100111, } -avr_hal::impl_adc! { +avr_hal_generic::impl_adc! { pub struct Adc { type ChannelID = AdcMux; - peripheral: crate::atmega32u4::ADC, + peripheral: crate::pac::ADC, set_mux: |peripheral, id| { let id = id as u8; peripheral.admux.modify(|_, w| w.mux().bits(id & 0x1f)); @@ -58,7 +58,7 @@ avr_hal::impl_adc! { /// /// This module contains ADC channels, additional to the direct pin channels. pub mod channel { - use avr_hal::hal::adc::Channel; + use avr_hal_generic::hal::adc::Channel; use super::AdcMux; /// Channel for the _Bandgap Reference Voltage_ diff --git a/chips/atmega32u4-hal/src/lib.rs b/chips/atmega32u4-hal/src/lib.rs index c913b15813..4a87d62bd9 100644 --- a/chips/atmega32u4-hal/src/lib.rs +++ b/chips/atmega32u4-hal/src/lib.rs @@ -1,14 +1,14 @@ #![no_std] -extern crate avr_hal_generic as avr_hal; +/// Reexport of `atmega32u4` from `avr-device` +pub use avr_device::atmega32u4 as pac; -pub use avr_device::atmega32u4; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; pub mod adc; pub mod port; @@ -16,19 +16,19 @@ pub mod pwm; pub mod wdt; pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } /// I2C Bus pub mod i2c { use crate::port::portd; - pub use avr_hal::i2c::*; + pub use avr_hal_generic::i2c::*; - avr_hal::impl_twi_i2c! { + avr_hal_generic::impl_twi_i2c! { /// I2C based on ATmega32U4's TWI peripheral pub struct I2c { - peripheral: crate::atmega32u4::TWI, + peripheral: crate::pac::TWI, pins: { sda: portd::PD1, scl: portd::PD0, @@ -76,12 +76,12 @@ pub mod spi { //! In the example above, all of the settings are left at the default. You can //! also instantiate a Settings object with the other options available. - pub use avr_hal::spi::*; + pub use avr_hal_generic::spi::*; use crate::port::portb; - avr_hal::impl_spi! { + avr_hal_generic::impl_spi! { pub struct Spi { - peripheral: crate::atmega32u4::SPI, + peripheral: crate::pac::SPI, pins: { sclk: portb::PB1, mosi: portb::PB2, @@ -94,14 +94,14 @@ pub mod spi { /// Serial interface using USART pub mod usart { use crate::port::portd; - pub use avr_hal::serial::*; + pub use avr_hal_generic::serial::*; - crate::avr_hal::impl_usart! { + avr_hal_generic::impl_usart! { /// Serial interface based on ATmega32U4's USART1 peripheral /// /// Maximum baudrate seems to be 57600 pub struct Usart1 { - peripheral: crate::atmega32u4::USART1, + peripheral: crate::pac::USART1, pins: { rx: portd::PD2, tx: portd::PD3, diff --git a/chips/atmega32u4-hal/src/port.rs b/chips/atmega32u4-hal/src/port.rs index 6291fbacc3..acc6d1557c 100644 --- a/chips/atmega32u4-hal/src/port.rs +++ b/chips/atmega32u4-hal/src/port.rs @@ -4,7 +4,7 @@ //! //! [1]: ../../avr_hal_generic/port/index.html -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -12,17 +12,17 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_generic_pin! { +avr_hal_generic::impl_generic_pin! { pub enum Pin { - B(crate::atmega32u4::PORTB, portb, pinb, ddrb), - C(crate::atmega32u4::PORTC, portc, pinc, ddrc), - D(crate::atmega32u4::PORTD, portd, pind, ddrd), - E(crate::atmega32u4::PORTE, porte, pine, ddre), - F(crate::atmega32u4::PORTF, portf, pinf, ddrf), + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), + E(crate::pac::PORTE, porte, pine, ddre), + F(crate::pac::PORTF, portf, pinf, ddrf), } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; @@ -30,7 +30,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::B; - impl PortExt for crate::atmega32u4::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), @@ -44,7 +44,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portc { #[port_ext] use super::PortExt; @@ -52,7 +52,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::C; - impl PortExt for crate::atmega32u4::PORTC { + impl PortExt for crate::pac::PORTC { regs: (pinc, ddrc, portc), pc6: (PC6, 6), pc7: (PC7, 7), @@ -60,7 +60,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portd { #[port_ext] use super::PortExt; @@ -68,7 +68,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::D; - impl PortExt for crate::atmega32u4::PORTD { + impl PortExt for crate::pac::PORTD { regs: (pind, ddrd, portd), pd0: (PD0, 0), pd1: (PD1, 1), @@ -82,7 +82,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porte { #[port_ext] use super::PortExt; @@ -90,7 +90,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::E; - impl PortExt for crate::atmega32u4::PORTE { + impl PortExt for crate::pac::PORTE { regs: (pine, ddre, porte), pe2: (PE2, 2), pe6: (PE6, 6), @@ -98,7 +98,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portf { #[port_ext] use super::PortExt; @@ -106,7 +106,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::F; - impl PortExt for crate::atmega32u4::PORTF { + impl PortExt for crate::pac::PORTF { regs: (pinf, ddrf, portf), pf0: (PF0, 0), pf1: (PF1, 1), diff --git a/chips/atmega32u4-hal/src/pwm.rs b/chips/atmega32u4-hal/src/pwm.rs index c0535463aa..76f4cc2e6c 100644 --- a/chips/atmega32u4-hal/src/pwm.rs +++ b/chips/atmega32u4-hal/src/pwm.rs @@ -27,9 +27,9 @@ //! | `PD7` | `.into_pwm(&mut timer4)` | | use crate::port::{portb, portc, portd}; -pub use avr_hal::pwm::*; +pub use avr_hal_generic::pwm::*; -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC0` for PWM (pins `PB7`, `PD0`) /// /// # Example @@ -45,7 +45,7 @@ avr_hal::impl_pwm! { /// pb7.enable(); /// ``` pub struct Timer0Pwm { - timer: crate::atmega32u4::TC0, + timer: crate::pac::TC0, init: |tim, prescaler| { tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast()); tim.tccr0b.modify(|_, w| match prescaler { @@ -77,7 +77,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC1` for PWM (pins `PB5`, `PB6`, `PB7`) /// /// # Example @@ -95,7 +95,7 @@ avr_hal::impl_pwm! { /// /// **Note**: For `PB7` the method is called `into_pwm1()`! pub struct Timer1Pwm { - timer: crate::atmega32u4::TC1, + timer: crate::pac::TC1, init: |tim, prescaler| { tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01)); tim.tccr1b.modify(|_, w| { @@ -138,7 +138,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC3` for PWM (pin `PC6`) /// /// # Example @@ -152,7 +152,7 @@ avr_hal::impl_pwm! { /// pc6.enable(); /// ``` pub struct Timer3Pwm { - timer: crate::atmega32u4::TC3, + timer: crate::pac::TC3, init: |tim, prescaler| { tim.tccr3a.modify(|_, w| w.wgm3().bits(0b01)); tim.tccr3b.modify(|_, w| { @@ -179,7 +179,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC4` for PWM (pins `PB6`, `PC7`, `PD7`) /// /// # Example @@ -199,7 +199,7 @@ avr_hal::impl_pwm! { /// /// **Note**: For `PB6` the method is called `into_pwm6()`! pub struct Timer4Pwm { - timer: crate::atmega32u4::TC4, + timer: crate::pac::TC4, init: |tim, prescaler| { tim.tccr4b.modify(|_, w| match prescaler { Prescaler::Direct => w.cs4().direct(), diff --git a/chips/atmega32u4-hal/src/wdt.rs b/chips/atmega32u4-hal/src/wdt.rs index 44d7daec49..9893ad56da 100644 --- a/chips/atmega32u4-hal/src/wdt.rs +++ b/chips/atmega32u4-hal/src/wdt.rs @@ -2,7 +2,7 @@ pub use avr_hal_generic::wdt::*; -avr_hal::impl_wdt! { +avr_hal_generic::impl_wdt! { pub enum Timeout { /// 16 milliseconds Ms16 { wdpl().cycles_2k_512k() }, @@ -27,7 +27,7 @@ avr_hal::impl_wdt! { } pub struct Wdt { - mcu_status_register: crate::atmega32u4::cpu::MCUSR, - peripheral: crate::atmega32u4::WDT, + mcu_status_register: crate::pac::cpu::MCUSR, + peripheral: crate::pac::WDT, } } diff --git a/chips/atmega48p-hal/src/adc.rs b/chips/atmega48p-hal/src/adc.rs index 66ba9e74cb..fb4b10585c 100644 --- a/chips/atmega48p-hal/src/adc.rs +++ b/chips/atmega48p-hal/src/adc.rs @@ -2,12 +2,12 @@ extern crate avr_hal_generic as avr_hal; use crate::port::portc::{PC0, PC1, PC2, PC3, PC4, PC5}; -use crate::atmega48p::adc::admux::MUX_A; +use crate::pac::adc::admux::MUX_A; -avr_hal::impl_adc! { +avr_hal_generic::impl_adc! { pub struct Adc { type ChannelID = MUX_A; - peripheral: crate::atmega48p::ADC, + peripheral: crate::pac::ADC, set_mux: |peripheral, id| { peripheral.admux.modify(|_, w| w.mux().variant(id)); }, @@ -26,8 +26,8 @@ avr_hal::impl_adc! { /// /// This module contains ADC channels, additional to the direct pin channels. pub mod channel { - use crate::atmega48p::adc::admux::MUX_A; - use avr_hal::hal::adc::Channel; + use crate::pac::adc::admux::MUX_A; + use avr_hal_generic::hal::adc::Channel; /// Channel for the _Bandgap Reference Voltage_ pub struct Vbg; diff --git a/chips/atmega48p-hal/src/lib.rs b/chips/atmega48p-hal/src/lib.rs index b24183defa..9c86775521 100644 --- a/chips/atmega48p-hal/src/lib.rs +++ b/chips/atmega48p-hal/src/lib.rs @@ -1,14 +1,14 @@ #![no_std] -extern crate avr_hal_generic as avr_hal; +/// Reexport of `atmega48p` from `avr-device` +pub use avr_device::atmega48p as pac; -pub use avr_device::atmega48p; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; pub mod port; @@ -18,19 +18,19 @@ pub mod pwm; pub mod spi; pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } /// I2C Bus pub mod i2c { use crate::port::portc; - pub use avr_hal::i2c::*; + pub use avr_hal_generic::i2c::*; - avr_hal::impl_twi_i2c! { + avr_hal_generic::impl_twi_i2c! { /// I2C based on ATmega328P's TWI peripheral pub struct I2c { - peripheral: crate::atmega48p::TWI, + peripheral: crate::pac::TWI, pins: { sda: portc::PC4, scl: portc::PC5, @@ -57,14 +57,14 @@ pub mod i2c { /// Serial interface using USART pub mod usart { use crate::port::portd; - pub use avr_hal::serial::*; + pub use avr_hal_generic::serial::*; - crate::avr_hal::impl_usart! { + avr_hal_generic::impl_usart! { /// Serial interface based on ATmega48P's USART0 peripheral /// /// Maximum baudrate seems to be 57600 pub struct Usart0 { - peripheral: crate::atmega48p::USART0, + peripheral: crate::pac::USART0, pins: { rx: portd::PD0, tx: portd::PD1, diff --git a/chips/atmega48p-hal/src/port.rs b/chips/atmega48p-hal/src/port.rs index 140996e3af..18a7b3b06f 100644 --- a/chips/atmega48p-hal/src/port.rs +++ b/chips/atmega48p-hal/src/port.rs @@ -4,7 +4,7 @@ //! //! [1]: ../../avr_hal_generic/port/index.html -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -12,15 +12,15 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_generic_pin! { +avr_hal_generic::impl_generic_pin! { pub enum Pin { - B(crate::atmega48p::PORTB, portb, pinb, ddrb), - C(crate::atmega48p::PORTC, portc, pinc, ddrc), - D(crate::atmega48p::PORTD, portd, pind, ddrd), + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; @@ -28,7 +28,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::B; - impl PortExt for crate::atmega48p::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), @@ -42,7 +42,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portc { #[port_ext] use super::PortExt; @@ -50,7 +50,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::C; - impl PortExt for crate::atmega48p::PORTC { + impl PortExt for crate::pac::PORTC { regs: (pinc, ddrc, portc), pc0: (PC0, 0), pc1: (PC1, 1), @@ -63,7 +63,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portd { #[port_ext] use super::PortExt; @@ -71,7 +71,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::D; - impl PortExt for crate::atmega48p::PORTD { + impl PortExt for crate::pac::PORTD { regs: (pind, ddrd, portd), pd0: (PD0, 0), pd1: (PD1, 1), diff --git a/chips/atmega48p-hal/src/pwm.rs b/chips/atmega48p-hal/src/pwm.rs index 666398bcf1..389acdba80 100644 --- a/chips/atmega48p-hal/src/pwm.rs +++ b/chips/atmega48p-hal/src/pwm.rs @@ -26,9 +26,9 @@ //! | `PD6` | `.into_pwm(&mut timer0)` | use crate::port::{portb, portd}; -pub use avr_hal::pwm::*; +pub use avr_hal_generic::pwm::*; -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC0` for PWM (pins `PD5`, `PD6`) /// /// # Example @@ -43,7 +43,7 @@ avr_hal::impl_pwm! { /// pd5.enable(); /// ``` pub struct Timer0Pwm { - timer: crate::atmega48p::TC0, + timer: crate::pac::TC0, init: |tim, prescaler| { tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast()); tim.tccr0b.modify(|_, w| match prescaler { @@ -75,7 +75,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC1` for PWM (pins `PB1`, `PB2`) /// /// # Example @@ -90,7 +90,7 @@ avr_hal::impl_pwm! { /// pb1.enable(); /// ``` pub struct Timer1Pwm { - timer: crate::atmega48p::TC1, + timer: crate::pac::TC1, init: |tim, prescaler| { tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01)); tim.tccr1b.modify(|_, w| { @@ -125,7 +125,7 @@ avr_hal::impl_pwm! { } } -avr_hal::impl_pwm! { +avr_hal_generic::impl_pwm! { /// Use `TC2` for PWM (pins `PB3`, `PD3`) /// /// # Example @@ -141,7 +141,7 @@ avr_hal::impl_pwm! { /// pb3.enable(); /// ``` pub struct Timer2Pwm { - timer: crate::atmega48p::TC2, + timer: crate::pac::TC2, init: |tim, prescaler| { tim.tccr2a.modify(|_, w| w.wgm2().pwm_fast()); tim.tccr2b.modify(|_, w| match prescaler { diff --git a/chips/atmega48p-hal/src/spi.rs b/chips/atmega48p-hal/src/spi.rs index 9895418ab6..618ab8078c 100644 --- a/chips/atmega48p-hal/src/spi.rs +++ b/chips/atmega48p-hal/src/spi.rs @@ -23,11 +23,11 @@ //! also instantiate a Settings object with the other options available. use crate::port::portb; -pub use avr_hal::spi::*; +pub use avr_hal_generic::spi::*; -avr_hal::impl_spi! { +avr_hal_generic::impl_spi! { pub struct Spi { - peripheral: crate::atmega48p::SPI, + peripheral: crate::pac::SPI, pins: { sclk: portb::PB5, mosi: portb::PB3, diff --git a/chips/attiny85-hal/src/lib.rs b/chips/attiny85-hal/src/lib.rs index 12341523b8..962479c33c 100644 --- a/chips/attiny85-hal/src/lib.rs +++ b/chips/attiny85-hal/src/lib.rs @@ -1,18 +1,18 @@ #![no_std] -extern crate avr_hal_generic as avr_hal; +/// Reexport of `attiny85` from `avr-device` +pub use avr_device::attiny85 as pac; -pub use avr_device::attiny85; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; pub mod port; pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } diff --git a/chips/attiny85-hal/src/port.rs b/chips/attiny85-hal/src/port.rs index 1e32c7c8d0..f33fb995f0 100644 --- a/chips/attiny85-hal/src/port.rs +++ b/chips/attiny85-hal/src/port.rs @@ -4,7 +4,7 @@ //! //! [1]: ../../avr_hal_generic/port/index.html -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -12,12 +12,12 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; - impl PortExt for crate::attiny85::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), diff --git a/chips/attiny88-hal/src/lib.rs b/chips/attiny88-hal/src/lib.rs index e04e3eaeb4..daadf181d8 100644 --- a/chips/attiny88-hal/src/lib.rs +++ b/chips/attiny88-hal/src/lib.rs @@ -1,33 +1,33 @@ #![no_std] -extern crate avr_hal_generic as avr_hal; +/// Reexport of `attiny88` from `avr-device` +pub use avr_device::attiny88 as pac; -pub use avr_device::attiny88; /// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html). #[cfg(feature = "rt")] pub use avr_device::entry; -pub use avr_hal::clock; -pub use avr_hal::delay; +pub use avr_hal_generic::clock; +pub use avr_hal_generic::delay; pub mod port; pub mod spi; pub mod prelude { - pub use crate::avr_hal::prelude::*; + pub use avr_hal_generic::prelude::*; pub use crate::port::PortExt as _; } /// I2C Bus pub mod i2c { use crate::port::portc; - pub use avr_hal::i2c::*; + pub use avr_hal_generic::i2c::*; - avr_hal::impl_twi_i2c! { + avr_hal_generic::impl_twi_i2c! { /// I2C based on ATtiny88's TWI peripheral pub struct I2c { - peripheral: crate::attiny88::TWI, + peripheral: crate::pac::TWI, pins: { sda: portc::PC4, scl: portc::PC5, diff --git a/chips/attiny88-hal/src/port.rs b/chips/attiny88-hal/src/port.rs index 3ff2d708c3..66133c81e0 100644 --- a/chips/attiny88-hal/src/port.rs +++ b/chips/attiny88-hal/src/port.rs @@ -4,7 +4,7 @@ //! //! [1]: ../../avr_hal_generic/port/index.html -pub use avr_hal::port::mode; +pub use avr_hal_generic::port::mode; pub trait PortExt { type Parts; @@ -12,16 +12,16 @@ pub trait PortExt { fn split(self) -> Self::Parts; } -avr_hal::impl_generic_pin! { +avr_hal_generic::impl_generic_pin! { pub enum Pin { - A(crate::attiny88::PORTA, porta, pina, ddra), - B(crate::attiny88::PORTB, portb, pinb, ddrb), - C(crate::attiny88::PORTC, portc, pinc, ddrc), - D(crate::attiny88::PORTD, portd, pind, ddrd), + A(crate::pac::PORTA, porta, pina, ddra), + B(crate::pac::PORTB, portb, pinb, ddrb), + C(crate::pac::PORTC, portc, pinc, ddrc), + D(crate::pac::PORTD, portd, pind, ddrd), } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod porta { #[port_ext] use super::PortExt; @@ -29,7 +29,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::A; - impl PortExt for crate::attiny88::PORTA { + impl PortExt for crate::pac::PORTA { regs: (pina, ddra, porta), pa0: (PA0, 0), pa1: (PA1, 1), @@ -39,7 +39,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portb { #[port_ext] use super::PortExt; @@ -47,7 +47,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::B; - impl PortExt for crate::attiny88::PORTB { + impl PortExt for crate::pac::PORTB { regs: (pinb, ddrb, portb), pb0: (PB0, 0), pb1: (PB1, 1), @@ -61,7 +61,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portc { #[port_ext] use super::PortExt; @@ -69,7 +69,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::C; - impl PortExt for crate::attiny88::PORTC { + impl PortExt for crate::pac::PORTC { regs: (pinc, ddrc, portc), pc0: (PC0, 0), pc1: (PC1, 1), @@ -83,7 +83,7 @@ avr_hal::impl_port! { } } -avr_hal::impl_port! { +avr_hal_generic::impl_port! { pub mod portd { #[port_ext] use super::PortExt; @@ -91,7 +91,7 @@ avr_hal::impl_port! { #[generic_pin] use Pin::D; - impl PortExt for crate::attiny88::PORTD { + impl PortExt for crate::pac::PORTD { regs: (pind, ddrd, portd), pd0: (PD0, 0), pd1: (PD1, 1), diff --git a/chips/attiny88-hal/src/spi.rs b/chips/attiny88-hal/src/spi.rs index 920356bb32..df204f5806 100644 --- a/chips/attiny88-hal/src/spi.rs +++ b/chips/attiny88-hal/src/spi.rs @@ -23,11 +23,11 @@ //! also instantiate a Settings object with the other options available. use crate::port::portb; -pub use avr_hal::spi::*; +pub use avr_hal_generic::spi::*; -avr_hal::impl_spi! { +avr_hal_generic::impl_spi! { pub struct Spi { - peripheral: crate::attiny88::SPI, + peripheral: crate::pac::SPI, pins: { sclk: portb::PB5, mosi: portb::PB3,