From 1bb3cd4e183639e8768c55091e91db04d20d0112 Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Fri, 27 Nov 2020 16:29:27 -0700 Subject: [PATCH 1/6] pygamer: change imports to fix docs BREAKING --- boards/pygamer/examples/blinky_basic.rs | 2 +- boards/pygamer/examples/button_rtic.rs | 4 +-- boards/pygamer/examples/clock_out.rs | 2 +- boards/pygamer/examples/ferris_img.rs | 2 +- .../pygamer/examples/neopixel_adc_battery.rs | 4 +-- boards/pygamer/examples/neopixel_adc_light.rs | 2 +- boards/pygamer/examples/neopixel_button.rs | 4 +-- boards/pygamer/examples/neopixel_easing.rs | 2 +- .../pygamer/examples/neopixel_rainbow_spi.rs | 2 +- .../examples/neopixel_rainbow_timer.rs | 4 +-- boards/pygamer/examples/neopixel_tilt.rs | 2 +- boards/pygamer/examples/pwm_tc4.rs | 2 +- boards/pygamer/examples/pwm_tcc0.rs | 2 +- boards/pygamer/examples/qspi.rs | 2 +- boards/pygamer/examples/sd_card.rs | 2 +- boards/pygamer/examples/timer.rs | 2 +- boards/pygamer/examples/usb_poll.rs | 2 +- boards/pygamer/examples/usb_serial.rs | 2 +- boards/pygamer/src/lib.rs | 18 ++++++------- boards/pygamer/src/pins.rs | 25 ++++++++++--------- 20 files changed, 44 insertions(+), 43 deletions(-) diff --git a/boards/pygamer/examples/blinky_basic.rs b/boards/pygamer/examples/blinky_basic.rs index a353629af817..c5028ecc1ca0 100644 --- a/boards/pygamer/examples/blinky_basic.rs +++ b/boards/pygamer/examples/blinky_basic.rs @@ -5,7 +5,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::clock::GenericClockController; use hal::delay::Delay; diff --git a/boards/pygamer/examples/button_rtic.rs b/boards/pygamer/examples/button_rtic.rs index b75bef51385d..f9af69c7e257 100644 --- a/boards/pygamer/examples/button_rtic.rs +++ b/boards/pygamer/examples/button_rtic.rs @@ -3,14 +3,14 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, pins::ButtonReader, pins::Keys, Pins}; +use pygamer::{hal, ButtonReader, Keys, Pins}; use hal::clock::GenericClockController; use hal::gpio::{OpenDrain, Output, Pa23}; use hal::prelude::*; use rtic::app; -#[app(device = crate::hal::pac, peripherals = true)] +#[app(device = pygamer::pac, peripherals = true)] const APP: () = { struct Resources { red_led: Pa23>, diff --git a/boards/pygamer/examples/clock_out.rs b/boards/pygamer/examples/clock_out.rs index 10dc0e313e48..18a7273e81f8 100644 --- a/boards/pygamer/examples/clock_out.rs +++ b/boards/pygamer/examples/clock_out.rs @@ -5,7 +5,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::clock::GenericClockController; use pac::gclk::genctrl::SRC_A::DPLL0; diff --git a/boards/pygamer/examples/ferris_img.rs b/boards/pygamer/examples/ferris_img.rs index 450f4a1a35ad..6eab439f6703 100644 --- a/boards/pygamer/examples/ferris_img.rs +++ b/boards/pygamer/examples/ferris_img.rs @@ -12,7 +12,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use embedded_graphics::pixelcolor::{Rgb565, RgbColor}; use embedded_graphics::prelude::*; diff --git a/boards/pygamer/examples/neopixel_adc_battery.rs b/boards/pygamer/examples/neopixel_adc_battery.rs index a46d5653be33..81538d5ee086 100644 --- a/boards/pygamer/examples/neopixel_adc_battery.rs +++ b/boards/pygamer/examples/neopixel_adc_battery.rs @@ -8,13 +8,13 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::adc::Adc; -use hal::pac::gclk::pchctrl::GEN_A::GCLK11; use hal::prelude::*; use hal::timer::SpinTimer; use hal::{clock::GenericClockController, delay::Delay}; +use pac::gclk::pchctrl::GEN_A::GCLK11; use pac::{CorePeripherals, Peripherals}; use smart_leds::{brightness, hsv::RGB8, SmartLedsWrite}; diff --git a/boards/pygamer/examples/neopixel_adc_light.rs b/boards/pygamer/examples/neopixel_adc_light.rs index ef3aaa9b66cf..68704e67c440 100644 --- a/boards/pygamer/examples/neopixel_adc_light.rs +++ b/boards/pygamer/examples/neopixel_adc_light.rs @@ -8,7 +8,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use embedded_hal::digital::v1_compat::OldOutputPin; use hal::adc::Adc; diff --git a/boards/pygamer/examples/neopixel_button.rs b/boards/pygamer/examples/neopixel_button.rs index 52b08cc8b89f..05a6969cd4b3 100644 --- a/boards/pygamer/examples/neopixel_button.rs +++ b/boards/pygamer/examples/neopixel_button.rs @@ -12,17 +12,17 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, pins::Keys, Pins}; +use pygamer::{entry, hal, pac, util, Keys, Pins}; use hal::adc::Adc; use hal::prelude::*; use hal::timer::SpinTimer; -use hal::util::map_from; use hal::{clock::GenericClockController, delay::Delay}; use pac::gclk::pchctrl::GEN_A::GCLK11; use pac::{CorePeripherals, Peripherals}; use smart_leds::hsv::{hsv2rgb, Hsv, RGB8}; use smart_leds::SmartLedsWrite; +use util::map_from; #[entry] fn main() -> ! { diff --git a/boards/pygamer/examples/neopixel_easing.rs b/boards/pygamer/examples/neopixel_easing.rs index 3a100f068000..f6f82a47548c 100644 --- a/boards/pygamer/examples/neopixel_easing.rs +++ b/boards/pygamer/examples/neopixel_easing.rs @@ -8,7 +8,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use core::f32::consts::FRAC_PI_2; use hal::clock::GenericClockController; diff --git a/boards/pygamer/examples/neopixel_rainbow_spi.rs b/boards/pygamer/examples/neopixel_rainbow_spi.rs index 4390ec1fad4e..0299e08fc23f 100644 --- a/boards/pygamer/examples/neopixel_rainbow_spi.rs +++ b/boards/pygamer/examples/neopixel_rainbow_spi.rs @@ -9,7 +9,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::prelude::*; use hal::sercom::PadPin; diff --git a/boards/pygamer/examples/neopixel_rainbow_timer.rs b/boards/pygamer/examples/neopixel_rainbow_timer.rs index d1ae56fa291a..ab8f3cd5a88a 100644 --- a/boards/pygamer/examples/neopixel_rainbow_timer.rs +++ b/boards/pygamer/examples/neopixel_rainbow_timer.rs @@ -11,11 +11,11 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, Pins}; +use pygamer::{entry, hal, pac, Pins}; -use hal::pac::{CorePeripherals, Peripherals}; use hal::prelude::*; use hal::{clock::GenericClockController, delay::Delay, timer::TimerCounter}; +use pac::{CorePeripherals, Peripherals}; use smart_leds::hsv::{hsv2rgb, Hsv}; use smart_leds::SmartLedsWrite; diff --git a/boards/pygamer/examples/neopixel_tilt.rs b/boards/pygamer/examples/neopixel_tilt.rs index 229b334023aa..d11fdbca8266 100644 --- a/boards/pygamer/examples/neopixel_tilt.rs +++ b/boards/pygamer/examples/neopixel_tilt.rs @@ -9,7 +9,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::prelude::*; use hal::time::KiloHertz; diff --git a/boards/pygamer/examples/pwm_tc4.rs b/boards/pygamer/examples/pwm_tc4.rs index dc704761eaf7..812ebf75ac29 100644 --- a/boards/pygamer/examples/pwm_tc4.rs +++ b/boards/pygamer/examples/pwm_tc4.rs @@ -5,7 +5,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use core::f32::consts::FRAC_PI_2; use hal::clock::GenericClockController; diff --git a/boards/pygamer/examples/pwm_tcc0.rs b/boards/pygamer/examples/pwm_tcc0.rs index 74eda7b86673..b2c1d279bf5b 100644 --- a/boards/pygamer/examples/pwm_tcc0.rs +++ b/boards/pygamer/examples/pwm_tcc0.rs @@ -5,7 +5,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use core::f32::consts::FRAC_PI_2; use hal::clock::GenericClockController; diff --git a/boards/pygamer/examples/qspi.rs b/boards/pygamer/examples/qspi.rs index 20e6eb929234..f62ccae378cd 100644 --- a/boards/pygamer/examples/qspi.rs +++ b/boards/pygamer/examples/qspi.rs @@ -24,7 +24,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::clock::GenericClockController; use hal::delay::Delay; diff --git a/boards/pygamer/examples/sd_card.rs b/boards/pygamer/examples/sd_card.rs index 1b9af7bbe206..a130adf8548e 100644 --- a/boards/pygamer/examples/sd_card.rs +++ b/boards/pygamer/examples/sd_card.rs @@ -16,7 +16,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use embedded_graphics::pixelcolor::{Rgb565, RgbColor}; use embedded_graphics::prelude::*; diff --git a/boards/pygamer/examples/timer.rs b/boards/pygamer/examples/timer.rs index 4ba12d28f0b9..b1a6ee08dac0 100644 --- a/boards/pygamer/examples/timer.rs +++ b/boards/pygamer/examples/timer.rs @@ -6,7 +6,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::clock::GenericClockController; use hal::prelude::*; diff --git a/boards/pygamer/examples/usb_poll.rs b/boards/pygamer/examples/usb_poll.rs index e35ce6ee98f1..868468551726 100644 --- a/boards/pygamer/examples/usb_poll.rs +++ b/boards/pygamer/examples/usb_poll.rs @@ -6,7 +6,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use hal::clock::GenericClockController; use hal::prelude::*; diff --git a/boards/pygamer/examples/usb_serial.rs b/boards/pygamer/examples/usb_serial.rs index ac3cc63961c3..ad698f2b15af 100644 --- a/boards/pygamer/examples/usb_serial.rs +++ b/boards/pygamer/examples/usb_serial.rs @@ -16,7 +16,7 @@ #[cfg(not(feature = "panic_led"))] use panic_halt as _; -use pygamer::{self as hal, entry, pac, Pins}; +use pygamer::{entry, hal, pac, Pins}; use cortex_m::interrupt::free as disable_interrupts; use cortex_m::peripheral::NVIC; diff --git a/boards/pygamer/src/lib.rs b/boards/pygamer/src/lib.rs index 2b52ebf66132..f122e5dbbd91 100644 --- a/boards/pygamer/src/lib.rs +++ b/boards/pygamer/src/lib.rs @@ -2,21 +2,21 @@ #![recursion_limit = "1024"] #[cfg(feature = "unproven")] -pub mod buttons; +mod buttons; -pub mod pins; -use atsamd_hal as hal; +// Re-export the HAL and the PAC to give the user lower-level access to the +// device should they need it. +pub use atsamd_hal::{self as hal, target_device as pac}; #[cfg(feature = "rt")] pub use cortex_m_rt::entry; -pub use pins::Pins; +mod pins; +pub use pins::*; -use hal::*; - -pub use hal::common::*; -pub use hal::samd51::*; -pub use hal::target_device as pac; +pub mod prelude { + pub use atsamd_hal::prelude::*; +} pub mod util { /// Analogous to Arduinos map function diff --git a/boards/pygamer/src/pins.rs b/boards/pygamer/src/pins.rs index 40c405c7bf5d..d4ce5e723e0e 100644 --- a/boards/pygamer/src/pins.rs +++ b/boards/pygamer/src/pins.rs @@ -1,7 +1,8 @@ //! PyGamer pins -use super::{hal, pac, target_device}; +use super::hal; +use atsamd_hal::target_device::{self, MCLK, QSPI}; use embedded_hal::{digital::v1_compat::OldOutputPin, timer::CountDown, timer::Periodic}; use gpio::{Floating, Input, Output, Port, PushPull}; use hal::clock::GenericClockController; @@ -11,8 +12,6 @@ use hal::hal::spi; use hal::prelude::*; use hal::sercom::{I2CMaster2, PadPin, SPIMaster1, SPIMaster4, UART5}; use hal::{qspi, time::Hertz}; -use pac::{MCLK, QSPI}; -use st7735_lcd::{Orientation, ST7735}; use ws2812_timer_delay as ws2812; #[cfg(feature = "usb")] @@ -20,7 +19,7 @@ use hal::usb::usb_device::bus::UsbBusAllocator; #[cfg(feature = "usb")] pub use hal::usb::UsbBus; #[cfg(feature = "usb")] -use pac::gclk::{genctrl::SRC_A, pchctrl::GEN_A}; +use target_device::gclk::{genctrl::SRC_A, pchctrl::GEN_A}; #[cfg(feature = "unproven")] pub use crate::buttons::ButtonReader; @@ -29,7 +28,9 @@ pub use crate::buttons::Keys; #[cfg(feature = "unproven")] use hal::pwm::Pwm2; #[cfg(feature = "unproven")] -use pac::{ADC0, ADC1}; +use st7735_lcd::{Orientation, ST7735}; +#[cfg(feature = "unproven")] +use target_device::{ADC0, ADC1}; define_pins!( /// Maps the pins to their arduino names and @@ -321,9 +322,9 @@ impl Display { pub fn init( self, clocks: &mut GenericClockController, - sercom4: pac::SERCOM4, - mclk: &mut pac::MCLK, - timer2: pac::TC2, + sercom4: target_device::SERCOM4, + mclk: &mut target_device::MCLK, + timer2: target_device::TC2, delay: &mut hal::delay::Delay, port: &mut Port, ) -> Result< @@ -417,7 +418,7 @@ impl SPI { self, clocks: &mut GenericClockController, bus_speed: F, - sercom1: pac::SERCOM1, + sercom1: target_device::SERCOM1, mclk: &mut MCLK, port: &mut Port, ) -> SPIMaster1< @@ -457,7 +458,7 @@ impl I2C { self, clocks: &mut GenericClockController, bus_speed: F, - sercom2: pac::SERCOM2, + sercom2: target_device::SERCOM2, mclk: &mut MCLK, port: &mut Port, ) -> I2CMaster2>, hal::sercom::Sercom2Pad1>> { @@ -491,7 +492,7 @@ impl USB { /// as a USB device. pub fn init( self, - usb: pac::USB, + usb: target_device::USB, clocks: &mut GenericClockController, mclk: &mut MCLK, port: &mut Port, @@ -523,7 +524,7 @@ impl UART { self, clocks: &mut GenericClockController, baud: F, - sercom5: pac::SERCOM5, + sercom5: target_device::SERCOM5, mclk: &mut MCLK, port: &mut Port, ) -> UART5>, hal::sercom::Sercom5Pad0>, (), ()> From 0da09cfa48084c832d524b2294f6d42329a9bd3a Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Fri, 27 Nov 2020 19:54:48 -0700 Subject: [PATCH 2/6] edgebadge: change imports to fix docs BREAKING --- boards/edgebadge/examples/blinky_basic.rs | 2 +- boards/edgebadge/examples/button_rtic.rs | 4 +-- boards/edgebadge/examples/ferris_img.rs | 2 +- .../examples/neopixel_adc_battery.rs | 2 +- .../edgebadge/examples/neopixel_adc_light.rs | 2 +- boards/edgebadge/examples/neopixel_button.rs | 2 +- boards/edgebadge/examples/neopixel_easing.rs | 2 +- .../examples/neopixel_rainbow_timer.rs | 2 +- boards/edgebadge/examples/neopixel_tilt.rs | 2 +- boards/edgebadge/examples/usb_poll.rs | 2 +- boards/edgebadge/examples/usb_serial.rs | 2 +- boards/edgebadge/src/lib.rs | 18 ++++++------- boards/edgebadge/src/pins.rs | 25 ++++++++++--------- 13 files changed, 34 insertions(+), 33 deletions(-) diff --git a/boards/edgebadge/examples/blinky_basic.rs b/boards/edgebadge/examples/blinky_basic.rs index 445dc4cea334..385f16ad5b16 100644 --- a/boards/edgebadge/examples/blinky_basic.rs +++ b/boards/edgebadge/examples/blinky_basic.rs @@ -3,7 +3,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use hal::clock::GenericClockController; diff --git a/boards/edgebadge/examples/button_rtic.rs b/boards/edgebadge/examples/button_rtic.rs index f20eea6f8c7d..ad13e0bd9bb5 100644 --- a/boards/edgebadge/examples/button_rtic.rs +++ b/boards/edgebadge/examples/button_rtic.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, pins::ButtonReader, pins::Keys, Pins}; +use edgebadge::{hal, ButtonReader, Keys, Pins}; use panic_halt as _; use hal::clock::GenericClockController; @@ -9,7 +9,7 @@ use hal::gpio::{OpenDrain, Output, Pa23}; use hal::prelude::*; use rtic::app; -#[app(device = crate::hal::pac, peripherals = true)] +#[app(device = edgebadge::pac, peripherals = true)] const APP: () = { struct Resources { red_led: Pa23>, diff --git a/boards/edgebadge/examples/ferris_img.rs b/boards/edgebadge/examples/ferris_img.rs index 187b76c5a868..40147e257fcf 100644 --- a/boards/edgebadge/examples/ferris_img.rs +++ b/boards/edgebadge/examples/ferris_img.rs @@ -10,7 +10,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use embedded_graphics::pixelcolor::{Rgb565, RgbColor}; diff --git a/boards/edgebadge/examples/neopixel_adc_battery.rs b/boards/edgebadge/examples/neopixel_adc_battery.rs index c6761e8fb8b6..34ff69e6126d 100644 --- a/boards/edgebadge/examples/neopixel_adc_battery.rs +++ b/boards/edgebadge/examples/neopixel_adc_battery.rs @@ -6,7 +6,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use hal::adc::Adc; diff --git a/boards/edgebadge/examples/neopixel_adc_light.rs b/boards/edgebadge/examples/neopixel_adc_light.rs index bd8276b76c9f..ca8aed4081e7 100644 --- a/boards/edgebadge/examples/neopixel_adc_light.rs +++ b/boards/edgebadge/examples/neopixel_adc_light.rs @@ -6,7 +6,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use embedded_hal::digital::v1_compat::OldOutputPin; diff --git a/boards/edgebadge/examples/neopixel_button.rs b/boards/edgebadge/examples/neopixel_button.rs index 006aa299931d..281425fab540 100644 --- a/boards/edgebadge/examples/neopixel_button.rs +++ b/boards/edgebadge/examples/neopixel_button.rs @@ -9,7 +9,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, pins::Keys, Pins}; +use edgebadge::{entry, hal, pac, Keys, Pins}; use panic_halt as _; use hal::prelude::*; diff --git a/boards/edgebadge/examples/neopixel_easing.rs b/boards/edgebadge/examples/neopixel_easing.rs index 2542f83b0043..c155c7e28764 100644 --- a/boards/edgebadge/examples/neopixel_easing.rs +++ b/boards/edgebadge/examples/neopixel_easing.rs @@ -6,7 +6,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use core::f32::consts::FRAC_PI_2; diff --git a/boards/edgebadge/examples/neopixel_rainbow_timer.rs b/boards/edgebadge/examples/neopixel_rainbow_timer.rs index 6bb88a6c3ee5..fffcdc6fa2b4 100644 --- a/boards/edgebadge/examples/neopixel_rainbow_timer.rs +++ b/boards/edgebadge/examples/neopixel_rainbow_timer.rs @@ -9,7 +9,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use hal::prelude::*; diff --git a/boards/edgebadge/examples/neopixel_tilt.rs b/boards/edgebadge/examples/neopixel_tilt.rs index b7c36335f61f..21b762afc8fe 100644 --- a/boards/edgebadge/examples/neopixel_tilt.rs +++ b/boards/edgebadge/examples/neopixel_tilt.rs @@ -7,7 +7,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use hal::prelude::*; diff --git a/boards/edgebadge/examples/usb_poll.rs b/boards/edgebadge/examples/usb_poll.rs index a6d13aa266fa..62f76b0d2f2e 100644 --- a/boards/edgebadge/examples/usb_poll.rs +++ b/boards/edgebadge/examples/usb_poll.rs @@ -4,7 +4,7 @@ #![no_std] #![no_main] -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use hal::clock::GenericClockController; diff --git a/boards/edgebadge/examples/usb_serial.rs b/boards/edgebadge/examples/usb_serial.rs index 90d9ee84c7c3..b5391d6829fa 100644 --- a/boards/edgebadge/examples/usb_serial.rs +++ b/boards/edgebadge/examples/usb_serial.rs @@ -14,7 +14,7 @@ //! Note leds may appear white during debug. Either build for release or add //! opt-level = 2 to profile.dev in Cargo.toml -use edgebadge::{self as hal, entry, pac, Pins}; +use edgebadge::{entry, hal, pac, Pins}; use panic_halt as _; use cortex_m::interrupt::free as disable_interrupts; diff --git a/boards/edgebadge/src/lib.rs b/boards/edgebadge/src/lib.rs index 5ef9120d86b7..eb92ce2adedf 100644 --- a/boards/edgebadge/src/lib.rs +++ b/boards/edgebadge/src/lib.rs @@ -2,18 +2,18 @@ #![recursion_limit = "1024"] #[cfg(feature = "unproven")] -pub mod buttons; +mod buttons; -pub mod pins; -use atsamd_hal as hal; +// Re-export the HAL and the PAC to give the user lower-level access to the +// device should they need it. +pub use atsamd_hal::{self as hal, target_device as pac}; #[cfg(feature = "rt")] pub use cortex_m_rt::entry; -pub use pins::Pins; +mod pins; +pub use pins::*; -use hal::*; - -pub use hal::common::*; -pub use hal::samd51::*; -pub use hal::target_device as pac; +pub mod prelude { + pub use atsamd_hal::prelude::*; +} diff --git a/boards/edgebadge/src/pins.rs b/boards/edgebadge/src/pins.rs index 0d815c161e8f..04f66b100e10 100644 --- a/boards/edgebadge/src/pins.rs +++ b/boards/edgebadge/src/pins.rs @@ -1,7 +1,8 @@ //! EdgeBadge pins -use super::{hal, pac, target_device}; +use super::hal; +use atsamd_hal::target_device::{self, MCLK}; use embedded_hal::{digital::v1_compat::OldOutputPin, timer::CountDown, timer::Periodic}; use gpio::{Floating, Input, Output, Port, PushPull}; use hal::clock::GenericClockController; @@ -11,8 +12,6 @@ use hal::hal::spi; use hal::prelude::*; use hal::sercom::{I2CMaster2, PadPin, SPIMaster1, SPIMaster4, UART5}; use hal::time::Hertz; -use pac::MCLK; -use st7735_lcd::{Orientation, ST7735}; use ws2812_timer_delay as ws2812; #[cfg(feature = "usb")] @@ -20,7 +19,7 @@ use hal::usb::usb_device::bus::UsbBusAllocator; #[cfg(feature = "usb")] pub use hal::usb::UsbBus; #[cfg(feature = "usb")] -use pac::gclk::{genctrl::SRC_A, pchctrl::GEN_A}; +use target_device::gclk::{genctrl::SRC_A, pchctrl::GEN_A}; #[cfg(feature = "unproven")] pub use crate::buttons::ButtonReader; @@ -29,7 +28,9 @@ pub use crate::buttons::Keys; #[cfg(feature = "unproven")] use hal::pwm::Pwm2; #[cfg(feature = "unproven")] -use pac::ADC0; +use st7735_lcd::{Orientation, ST7735}; +#[cfg(feature = "unproven")] +use target_device::ADC0; define_pins!( /// Maps the pins to their arduino names and @@ -310,9 +311,9 @@ impl Display { pub fn init( self, clocks: &mut GenericClockController, - sercom4: pac::SERCOM4, - mclk: &mut pac::MCLK, - timer2: pac::TC2, + sercom4: target_device::SERCOM4, + mclk: &mut target_device::MCLK, + timer2: target_device::TC2, delay: &mut hal::delay::Delay, port: &mut Port, ) -> Result< @@ -406,7 +407,7 @@ impl SPI { self, clocks: &mut GenericClockController, bus_speed: F, - sercom1: pac::SERCOM1, + sercom1: target_device::SERCOM1, mclk: &mut MCLK, port: &mut Port, ) -> SPIMaster1< @@ -446,7 +447,7 @@ impl I2C { self, clocks: &mut GenericClockController, bus_speed: F, - sercom2: pac::SERCOM2, + sercom2: target_device::SERCOM2, mclk: &mut MCLK, port: &mut Port, ) -> I2CMaster2>, hal::sercom::Sercom2Pad1>> { @@ -480,7 +481,7 @@ impl USB { /// as a USB device. pub fn init( self, - usb: pac::USB, + usb: target_device::USB, clocks: &mut GenericClockController, mclk: &mut MCLK, port: &mut Port, @@ -512,7 +513,7 @@ impl UART { self, clocks: &mut GenericClockController, baud: F, - sercom5: pac::SERCOM5, + sercom5: target_device::SERCOM5, mclk: &mut MCLK, port: &mut Port, ) -> UART5>, hal::sercom::Sercom5Pad0>, (), ()> From 10493bfc38e89851a0c50c192a5546375fb77f6f Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Tue, 8 Dec 2020 10:19:04 -0700 Subject: [PATCH 3/6] disambiguate pins and sets --- boards/pygamer/examples/button_rtic.rs | 6 +++--- boards/pygamer/examples/ferris_img.rs | 6 +++--- boards/pygamer/examples/neopixel_adc_battery.rs | 6 +++--- boards/pygamer/examples/neopixel_button.rs | 8 ++++---- boards/pygamer/examples/neopixel_easing.rs | 4 ++-- boards/pygamer/examples/neopixel_rainbow_timer.rs | 4 ++-- boards/pygamer/examples/neopixel_tilt.rs | 8 ++++---- boards/pygamer/examples/sd_card.rs | 12 ++++++------ boards/pygamer/examples/usb_poll.rs | 8 ++++---- boards/pygamer/examples/usb_serial.rs | 8 ++++---- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/boards/pygamer/examples/button_rtic.rs b/boards/pygamer/examples/button_rtic.rs index f9af69c7e257..fe95cc0f4207 100644 --- a/boards/pygamer/examples/button_rtic.rs +++ b/boards/pygamer/examples/button_rtic.rs @@ -50,7 +50,7 @@ const APP: () = { &mut device.NVMCTRL, ); - let mut pins = Pins::new(device.PORT).split(); + let mut sets = Pins::new(device.PORT).split(); let gclk0 = clocks.gclk0(); let timer_clock = clocks.tc2_tc3(&gclk0).unwrap(); @@ -61,8 +61,8 @@ const APP: () = { tc3.enable_interrupt(); init::LateResources { - buttons: pins.buttons.init(&mut pins.port), - red_led: pins.led_pin.into_open_drain_output(&mut pins.port), + buttons: sets.buttons.init(&mut sets.port), + red_led: sets.led_pin.into_open_drain_output(&mut sets.port), timer: tc3, } } diff --git a/boards/pygamer/examples/ferris_img.rs b/boards/pygamer/examples/ferris_img.rs index 6eab439f6703..60795bdf1bd8 100644 --- a/boards/pygamer/examples/ferris_img.rs +++ b/boards/pygamer/examples/ferris_img.rs @@ -32,10 +32,10 @@ fn main() -> ! { &mut peripherals.OSCCTRL, &mut peripherals.NVMCTRL, ); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); let mut delay = hal::delay::Delay::new(core.SYST, &mut clocks); - let (mut display, _backlight) = pins + let (mut display, _backlight) = sets .display .init( &mut clocks, @@ -43,7 +43,7 @@ fn main() -> ! { &mut peripherals.MCLK, peripherals.TC2, &mut delay, - &mut pins.port, + &mut sets.port, ) .unwrap(); diff --git a/boards/pygamer/examples/neopixel_adc_battery.rs b/boards/pygamer/examples/neopixel_adc_battery.rs index 81538d5ee086..0d3caf0a9488 100644 --- a/boards/pygamer/examples/neopixel_adc_battery.rs +++ b/boards/pygamer/examples/neopixel_adc_battery.rs @@ -29,14 +29,14 @@ fn main() -> ! { &mut peripherals.OSCCTRL, &mut peripherals.NVMCTRL, ); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); let mut adc0 = Adc::adc0(peripherals.ADC0, &mut peripherals.MCLK, &mut clocks, GCLK11); - let mut battery = pins.battery.init(&mut pins.port); + let mut battery = sets.battery.init(&mut sets.port); // neopixels let timer = SpinTimer::new(4); - let mut neopixel = pins.neopixel.init(timer, &mut pins.port); + let mut neopixel = sets.neopixel.init(timer, &mut sets.port); let mut delay = Delay::new(core.SYST, &mut clocks); diff --git a/boards/pygamer/examples/neopixel_button.rs b/boards/pygamer/examples/neopixel_button.rs index 05a6969cd4b3..e329e20ad378 100644 --- a/boards/pygamer/examples/neopixel_button.rs +++ b/boards/pygamer/examples/neopixel_button.rs @@ -38,17 +38,17 @@ fn main() -> ! { ); let mut delay = Delay::new(core_peripherals.SYST, &mut clocks); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); - let mut buttons = pins.buttons.init(&mut pins.port); + let mut buttons = sets.buttons.init(&mut sets.port); let mut adc1 = Adc::adc1(peripherals.ADC1, &mut peripherals.MCLK, &mut clocks, GCLK11); - let mut joystick = pins.joystick.init(&mut pins.port); + let mut joystick = sets.joystick.init(&mut sets.port); // neopixels let timer = SpinTimer::new(4); - let mut neopixel = pins.neopixel.init(timer, &mut pins.port); + let mut neopixel = sets.neopixel.init(timer, &mut sets.port); const NUM_LEDS: usize = 5; let mut pos_button: usize = 2; diff --git a/boards/pygamer/examples/neopixel_easing.rs b/boards/pygamer/examples/neopixel_easing.rs index f6f82a47548c..f80e3d210613 100644 --- a/boards/pygamer/examples/neopixel_easing.rs +++ b/boards/pygamer/examples/neopixel_easing.rs @@ -33,10 +33,10 @@ fn main() -> ! { &mut peripherals.NVMCTRL, ); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); let timer = SpinTimer::new(4); - let mut neopixel = pins.neopixel.init(timer, &mut pins.port); + let mut neopixel = sets.neopixel.init(timer, &mut sets.port); let mut delay = Delay::new(core.SYST, &mut clocks); let trng = Trng::new(&mut peripherals.MCLK, peripherals.TRNG); diff --git a/boards/pygamer/examples/neopixel_rainbow_timer.rs b/boards/pygamer/examples/neopixel_rainbow_timer.rs index ab8f3cd5a88a..5220cb9084c1 100644 --- a/boards/pygamer/examples/neopixel_rainbow_timer.rs +++ b/boards/pygamer/examples/neopixel_rainbow_timer.rs @@ -30,14 +30,14 @@ fn main() -> ! { &mut peripherals.OSCCTRL, &mut peripherals.NVMCTRL, ); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); let gclk0 = clocks.gclk0(); let timer_clock = clocks.tc2_tc3(&gclk0).unwrap(); let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.TC3, &mut peripherals.MCLK); timer.start(3.mhz()); - let mut neopixel = pins.neopixel.init(timer, &mut pins.port); + let mut neopixel = sets.neopixel.init(timer, &mut sets.port); let mut delay = Delay::new(core.SYST, &mut clocks); loop { diff --git a/boards/pygamer/examples/neopixel_tilt.rs b/boards/pygamer/examples/neopixel_tilt.rs index d11fdbca8266..6c2b111e6aa6 100644 --- a/boards/pygamer/examples/neopixel_tilt.rs +++ b/boards/pygamer/examples/neopixel_tilt.rs @@ -34,19 +34,19 @@ fn main() -> ! { ); let mut delay = Delay::new(core_peripherals.SYST, &mut clocks); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); // neopixels let timer = SpinTimer::new(4); - let mut neopixel = pins.neopixel.init(timer, &mut pins.port); + let mut neopixel = sets.neopixel.init(timer, &mut sets.port); // i2c - let i2c = pins.i2c.init( + let i2c = sets.i2c.init( &mut clocks, KiloHertz(400), peripherals.SERCOM2, &mut peripherals.MCLK, - &mut pins.port, + &mut sets.port, ); let mut lis3dh = Lis3dh::new(i2c, 0x19).unwrap(); diff --git a/boards/pygamer/examples/sd_card.rs b/boards/pygamer/examples/sd_card.rs index a130adf8548e..2e5e76208429 100644 --- a/boards/pygamer/examples/sd_card.rs +++ b/boards/pygamer/examples/sd_card.rs @@ -43,22 +43,22 @@ fn main() -> ! { ); let mut delay = Delay::new(core.SYST, &mut clocks); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); - let mut red_led = pins.led_pin.into_open_drain_output(&mut pins.port); + let mut red_led = sets.led_pin.into_open_drain_output(&mut sets.port); - let sdmmc_cs: OldOutputPin<_> = pins.sd_cs_pin.into_push_pull_output(&mut pins.port).into(); - let sdmmc_spi = pins.spi.init( + let sdmmc_cs: OldOutputPin<_> = sets.sd_cs_pin.into_push_pull_output(&mut sets.port).into(); + let sdmmc_spi = sets.spi.init( &mut clocks, MegaHertz(3), peripherals.SERCOM1, &mut peripherals.MCLK, - &mut pins.port, + &mut sets.port, ); let mut cont = embedded_sdmmc::Controller::new(embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs), Clock); - let (mut display, _backlight) = pins + let (mut display, _backlight) = sets .display .init( &mut clocks, diff --git a/boards/pygamer/examples/usb_poll.rs b/boards/pygamer/examples/usb_poll.rs index 868468551726..5dd5e16f8ccc 100644 --- a/boards/pygamer/examples/usb_poll.rs +++ b/boards/pygamer/examples/usb_poll.rs @@ -26,17 +26,17 @@ fn main() -> ! { &mut peripherals.NVMCTRL, ); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); - let usb_bus = pins.usb.init( + let usb_bus = sets.usb.init( peripherals.USB, &mut clocks, &mut peripherals.MCLK, - &mut pins.port, + &mut sets.port, ); let mut serial = SerialPort::new(&usb_bus); - let mut led = pins.led_pin.into_open_drain_output(&mut pins.port); + let mut led = sets.led_pin.into_open_drain_output(&mut sets.port); let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) .manufacturer("Fake company") diff --git a/boards/pygamer/examples/usb_serial.rs b/boards/pygamer/examples/usb_serial.rs index ad698f2b15af..0c1a57730939 100644 --- a/boards/pygamer/examples/usb_serial.rs +++ b/boards/pygamer/examples/usb_serial.rs @@ -40,19 +40,19 @@ fn main() -> ! { &mut peripherals.OSCCTRL, &mut peripherals.NVMCTRL, ); - let mut pins = Pins::new(peripherals.PORT).split(); + let mut sets = Pins::new(peripherals.PORT).split(); let timer = SpinTimer::new(4); - let mut neopixel = pins.neopixel.init(timer, &mut pins.port); + let mut neopixel = sets.neopixel.init(timer, &mut sets.port); let _ = neopixel.write((0..5).map(|_| RGB8::default())); let bus_allocator = unsafe { - USB_ALLOCATOR = Some(pins.usb.init( + USB_ALLOCATOR = Some(sets.usb.init( peripherals.USB, &mut clocks, &mut peripherals.MCLK, - &mut pins.port, + &mut sets.port, )); USB_ALLOCATOR.as_ref().unwrap() }; From 772f5e2c348d6630aaf6e8bc0b1d342e03c6f57f Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Tue, 8 Dec 2020 22:03:32 -0700 Subject: [PATCH 4/6] Description --- boards/pygamer/src/lib.rs | 27 +++++++++++++++++++++++++++ boards/pygamer/src/pins.rs | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/boards/pygamer/src/lib.rs b/boards/pygamer/src/lib.rs index f122e5dbbd91..23da33da97d6 100644 --- a/boards/pygamer/src/lib.rs +++ b/boards/pygamer/src/lib.rs @@ -1,3 +1,30 @@ +//! `pygamer` is a Board Support Package (BSP) which provides a type-safe API +//! for the Adafruit [Pygamer]. +//! +//! This crate is essentially a thin wrapper for [atsamd-hal], and re-exports it +//! along with some of its members. +//! +//! Instead of interacting with the hal pin numbers [Pins] lets you use +//! descriptive labels printed on the board like d13 or neopixel. +//! ```ignore +//! let mut pins = Pins::new(peripherals.PORT); +//! let mut red_led = pins.d13.into_open_drain_output(&mut pins.port); +//! ``` +//! +//! The `split()` fn goes further and returns a [Sets] struct which you interact +//! with groups of pins like a bus or peripheral and offers an `init()` fn. +//! ```ignore +//! let mut sets = Pins::new(peripherals.PORT).split(); +//! let timer = SpinTimer::new(4); +//! let mut neopixel = sets.neopixel.init(timer, &mut sets.port); +//! ``` +//! +//! Visit Adafruit for an overview of [pinout] and available connectors. +//! +//! [Pygamer]: https://www.adafruit.com/product/4242 +//! [atsamd-hal]: https://github.com/atsamd-rs/atsamd +//! [pinout]: https://learn.adafruit.com/adafruit-pygamer + #![no_std] #![recursion_limit = "1024"] diff --git a/boards/pygamer/src/pins.rs b/boards/pygamer/src/pins.rs index d4ce5e723e0e..4bb663957d03 100644 --- a/boards/pygamer/src/pins.rs +++ b/boards/pygamer/src/pins.rs @@ -552,9 +552,9 @@ pub struct Analog { /// Digital pins pub struct Digital { - /// also usabe as A8 + /// also usable as A8 pub d2: Pb3>, - /// also usabe as A9 + /// also usable as A9 pub d3: Pb2>, pub d5: Pa16>, pub d6: Pa18>, From 05c0342ce0986d4b6828845b25b912076359848d Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Wed, 9 Dec 2020 00:58:39 -0700 Subject: [PATCH 5/6] docs --- boards/pygamer/src/buttons.rs | 161 ++++++++++++++++++++-------------- boards/pygamer/src/lib.rs | 13 ++- boards/pygamer/src/pins.rs | 141 +++++------------------------ 3 files changed, 122 insertions(+), 193 deletions(-) diff --git a/boards/pygamer/src/buttons.rs b/boards/pygamer/src/buttons.rs index 39672f809c94..5c4c242de634 100644 --- a/boards/pygamer/src/buttons.rs +++ b/boards/pygamer/src/buttons.rs @@ -18,54 +18,70 @@ pub enum Keys { } pub struct ButtonIter { - pub pressed: u8, - pub released: u8, - pub bit_index: u8, + pressed: u8, + released: u8, + bit_index: u8, } -//should be impossible for released and pressed, but gives released preference -fn mask_to_event(mask: u8, released: u8, pressed: u8) -> Option { - let pressed_bool = mask & pressed == mask; - let released_bool = mask & released == mask; - - match mask { - 0x8 => { - if released_bool { - Some(Keys::BUp) - } else if pressed_bool { - Some(Keys::BDown) - } else { - None - } +/// Iterates through each button reporting its CHANGED status, if it has +/// recently changed from released to pressed, or opposite. Returns None after +/// the last button has been checked. Use [ButtonReader::events] to read +/// buttons fresh and receive a new Iterator. +impl ButtonIter { + /// Create a ButtonIter + pub fn new(pressed: u8, released: u8) -> ButtonIter { + ButtonIter { + pressed, + released, + bit_index: 0, } - 0x4 => { - if released_bool { - Some(Keys::AUp) - } else if pressed_bool { - Some(Keys::ADown) - } else { - None + } + + /// Should be impossible for released and pressed, but gives released + /// preference + fn mask_to_event(&self, mask: u8) -> Option { + let pressed_bool = mask & self.pressed == mask; + let released_bool = mask & self.released == mask; + + match mask { + 0x8 => { + if released_bool { + Some(Keys::BUp) + } else if pressed_bool { + Some(Keys::BDown) + } else { + None + } } - } - 0x2 => { - if released_bool { - Some(Keys::StartUp) - } else if pressed_bool { - Some(Keys::StartDown) - } else { - None + 0x4 => { + if released_bool { + Some(Keys::AUp) + } else if pressed_bool { + Some(Keys::ADown) + } else { + None + } } - } - 0x1 => { - if released_bool { - Some(Keys::SelectUp) - } else if pressed_bool { - Some(Keys::SelectDown) - } else { - None + 0x2 => { + if released_bool { + Some(Keys::StartUp) + } else if pressed_bool { + Some(Keys::StartDown) + } else { + None + } + } + 0x1 => { + if released_bool { + Some(Keys::SelectUp) + } else if pressed_bool { + Some(Keys::SelectDown) + } else { + None + } } + _ => None, } - _ => None, } } @@ -73,8 +89,8 @@ impl Iterator for ButtonIter { type Item = Keys; fn next(&mut self) -> Option { - //really want a while post increment but doesnt exist - //only 4 buttons represented in the shift + // really want a while post increment but doesnt exist + // only 4 buttons represented in the shift if self.bit_index >= 4 { return None; } @@ -84,7 +100,7 @@ impl Iterator for ButtonIter { let mask = 0x01 << self.bit_index; self.bit_index += 1; - let event = mask_to_event(mask, self.released, self.pressed); + let event = self.mask_to_event(mask); if event.is_some() { return event; } @@ -97,29 +113,39 @@ impl Iterator for ButtonIter { } /// Button pins - pub struct ButtonReader { - /// Button Latch - pub latch: Pb0>, - /// Button Out - pub data_in: Pb30>, - /// Button Clock - pub clock: Pb31>, - pub last: u8, + latch: Pb0>, + data_in: Pb30>, + clock: Pb31>, + last: u8, } -//120mhz, 1 cycle = 0.000000008333333 = 8.333333ns -//https://www.onsemi.com/pub/Collateral/MC74HC165A-D.PDF -//3v <=125c -//tsu min setup time 55ns = 7 cycles -//th min hold time 5ns = 1 cycles -//tw min pulse width 36ns = 5 cycles -//trec min recovery time 55ns, how long before you should attempt to read -// again? - impl ButtonReader { - // 28*8.333ns total blocking read - /// Returns a ButtonIter of button changes as Keys enums + /// Create a ButtonReader + pub fn new( + latch: Pb0>, + data_in: Pb30>, + clock: Pb31>, + ) -> ButtonReader { + ButtonReader { + latch, + data_in, + clock, + last: 0, + } + } + + // 120mhz, 1 cycle = 0.000000008333333 = 8.333333ns + // https://www.onsemi.com/pub/Collateral/MC74HC165A-D.PDF + // 3v <=125c + // tsu min setup time 55ns = 7 cycles + // th min hold time 5ns = 1 cycles + // tw min pulse width 36ns = 5 cycles + // trec min recovery time 55ns, how long before you should attempt to read + // again? + + /// Reads all buttons (Blocks for 28*8.333ns). Returns a ButtonIter of + /// button changes as Keys enums. pub fn events(&mut self) -> ButtonIter { self.latch.set_low().ok(); cycle_delay(7); //tsu? @@ -141,11 +167,10 @@ impl ButtonReader { self.clock.set_high().ok(); } - let iter = ButtonIter { - pressed: (self.last ^ current) & current, - released: (self.last ^ current) & self.last, - bit_index: 0, - }; + let pressed = (self.last ^ current) & current; + let released = (self.last ^ current) & self.last; + + let iter = ButtonIter::new(pressed, released); self.last = current; diff --git a/boards/pygamer/src/lib.rs b/boards/pygamer/src/lib.rs index 23da33da97d6..401821094f31 100644 --- a/boards/pygamer/src/lib.rs +++ b/boards/pygamer/src/lib.rs @@ -4,7 +4,7 @@ //! This crate is essentially a thin wrapper for [atsamd-hal], and re-exports it //! along with some of its members. //! -//! Instead of interacting with the hal pin numbers [Pins] lets you use +//! Instead of interacting with the hal pin numbers, [Pins] lets you use //! descriptive labels printed on the board like d13 or neopixel. //! ```ignore //! let mut pins = Pins::new(peripherals.PORT); @@ -19,11 +19,16 @@ //! let mut neopixel = sets.neopixel.init(timer, &mut sets.port); //! ``` //! -//! Visit Adafruit for an overview of [pinout] and available connectors. +//! Visit Adafruit for an [overview] of pins and connectors and check out the +//! [examples] to get an idea of how applications are structured and how the API +//! works. Finally, install [hf2] to enable `cargo run` support for single +//! command build and upload. //! //! [Pygamer]: https://www.adafruit.com/product/4242 -//! [atsamd-hal]: https://github.com/atsamd-rs/atsamd -//! [pinout]: https://learn.adafruit.com/adafruit-pygamer +//! [atsamd-hal]: https://docs.rs/atsamd-hal/latest/atsamd_hal/ +//! [overview]: https://learn.adafruit.com/adafruit-pygamer +//! [examples]: https://github.com/atsamd-rs/atsamd/tree/master/boards/pygamer/examples +//! [hf2]: https://github.com/jacobrosenthal/hf2-rs/tree/master/hf2-cli #![no_std] #![recursion_limit = "1024"] diff --git a/boards/pygamer/src/pins.rs b/boards/pygamer/src/pins.rs index 4bb663957d03..f20c2e6e9ca6 100644 --- a/boards/pygamer/src/pins.rs +++ b/boards/pygamer/src/pins.rs @@ -33,110 +33,52 @@ use st7735_lcd::{Orientation, ST7735}; use target_device::{ADC0, ADC1}; define_pins!( - /// Maps the pins to their arduino names and - /// the numbers printed on the board. + /// Array of pins mapped to their arduino names and the numbers printed on + /// the board. struct Pins, target_device: target_device, - /// Analog pin 0. Can act as a true analog output - /// as it has a DAC (which is not currently supported - /// by this hal) as well as input. pin speaker = a2, - /// enable speaker amplifier pin speaker_enable = a27, - - /// Analog pin 1 pin a1 = a5, - /// Analog pin 2 pin a2 = b8, - /// Analog pin 3 pin a3 = b9, - /// Analog pin 4 pin a4 = a4, - /// Analog pin 5 pin a5 = a6, - /// Battery Measure (also Analog pin 6) pin battery = b1, - /// Light sensor (also Analog pin 7) pin light = b4, - /// Digital pin 2 (also Analog pin 8) pin d2 = b3, - /// Digital pin 3 (also Analog pin 9) pin d3 = b2, - /// Digital pin 5 pin d5 = a16, - /// Digital pin 6 pin d6 = a18, - /// Accelerometer interrupt pin (also d7) pin accel_irq = b14, - /// Neopixel data line (controls all 5 neopixels, also d8) pin neopixel = a15, - /// Digital pin 9 pin d9 = a19, - /// Digital pin 10 pin d10 = a20, - /// Digital pin 11 pin d11 = a21, - /// Digital pin 12 pin d12 = a22, - /// D13 LED/JACDAC pin d13 = a23, - - // TFT(Thin-film-transistor liquid-crystal display) control pins - /// TFT MOSI pin tft_mosi = b15, - /// TFT SCK pin tft_sck = b13, - /// TFT Reset pin tft_reset = a0, - /// TFT DC pin tft_dc = b5, - /// TFT CS pin tft_cs = b12, - /// TFT Backlight (also Analog pin 7) pin tft_backlight = a1, - - // UART - Universal Asynchronous Receiver/Transmitter - /// Pin TX (d1) pin tx = b16, - /// Pin RX (d0) pin rx = b17, - - // SPI - Serial Peripheral Interface (connected to sd card slot) - /// Pin MISO pin miso = b22, - /// Pin MOSI pin mosi = b23, - /// Pin SCK pin sck = a17, - - // I2C (connected to LIS3DH accelerometer) - /// STEMMA SDA pin sda = a12, - /// STEMMA SCL pin scl = a13, - - /// USB D- pin pin usb_dm = a24, - /// USB D+ pin pin usb_dp = a25, - - /// SD card chip select (also d4) pin sd_cs = a14, - - /// Joystick X pin joy_x = b7, - /// Joystick Y pin joy_y = b6, - - /// Button Latch pin button_latch = b0, - /// Button Out pin button_out = b30, - /// Button Clock pin button_clock = b31, - - /// qspi flash pin flash_sck = b10, pin flash_cs = b11, pin flash_d0 = a8, @@ -255,53 +197,22 @@ impl Pins { /// Sets of pins split apart by category pub struct Sets { - /// Port pub port: Port, - - /// LCD Display pub display: Display, - - /// Red Led pub led_pin: Pa23>, - - /// Neopixel (RGB LED) pins pub neopixel: Neopixel, - - /// Analog Light Sensor pub light_pin: Pb4>, - - /// I2C (connected to LIS3DH accelerometer and "Stemma" port) pub i2c: I2C, - - /// SD Card CS pin pub sd_cs_pin: Pa14>, - - /// Battery Voltage pub battery: Battery, - - /// Speaker (DAC not implemented in hal yet) pub speaker: Speaker, - - /// SPI (connected to SD Card) pub spi: SPI, - - /// USB pins pub usb: USB, - - /// UART (external pinout) pins pub uart: UART, - - /// Analog pins. pub analog: Analog, - - /// Digital pins. pub digital: Digital, - - /// Flash storage pub flash: QSPIFlash, - pub buttons: Buttons, - pub joystick: Joystick, } @@ -412,8 +323,8 @@ pub struct SPI { } impl SPI { - /// Convenience for setting up the labelled pins to operate - /// as an SPI master, running at the specified frequency. + /// Convenience for setting up the labelled pins to operate as an SPI + /// master, running at the specified frequency. pub fn init>( self, clocks: &mut GenericClockController, @@ -452,8 +363,8 @@ pub struct I2C { } impl I2C { - /// Convenience for setting up the labelled SDA, SCL pins to - /// operate as an I2C master running at the specified frequency. + /// Convenience for setting up the labelled SDA, SCL pins to operate as an + /// I2C master running at the specified frequency. pub fn init>( self, clocks: &mut GenericClockController, @@ -488,8 +399,8 @@ pub struct USB { impl USB { #[cfg(feature = "usb")] - /// Convenience for setting up the onboard usb port to operate - /// as a USB device. + /// Convenience for setting up the onboard usb port to operate as a USB + /// device. pub fn init( self, usb: target_device::USB, @@ -518,8 +429,8 @@ pub struct UART { } impl UART { - /// Convenience for setting up the labelled TX, RX pins - /// to operate as a UART device at the specified baud rate. + /// Convenience for setting up the labelled TX, RX pins to operate as a UART + /// device at the specified baud rate. pub fn init>( self, clocks: &mut GenericClockController, @@ -575,6 +486,7 @@ pub struct QSPIFlash { } impl QSPIFlash { + /// Convenience for setting up the onboard qspi flash chip. pub fn init(self, mclk: &mut MCLK, port: &mut Port, qspi: QSPI) -> qspi::Qspi { qspi::Qspi::new( mclk, port, qspi, self.sck, self.cs, self.data0, self.data1, self.data2, self.data3, @@ -584,18 +496,15 @@ impl QSPIFlash { /// Button pins pub struct Buttons { - /// Button Latch pub latch: Pb0>, - /// Button Out pub data_in: Pb30>, - /// Button Clock pub clock: Pb31>, } #[cfg(feature = "unproven")] impl Buttons { - /// Convenience for setting up the button latch pins - /// Returns ButtonReader iterator which can be polled for Key events + /// Convenience for setting up the button latch pins. Returns a ButtonReader + /// iterator which can be polled for Key events. pub fn init(self, port: &mut Port) -> ButtonReader { let mut latch = self.latch.into_push_pull_output(port); latch.set_high().ok(); @@ -605,29 +514,22 @@ impl Buttons { let mut clock = self.clock.into_push_pull_output(port); clock.set_high().ok(); - ButtonReader { - latch, - data_in, - clock, - last: 0, - } + ButtonReader::new(latch, data_in, clock) } } /// Joystick pins pub struct JoystickReader { - /// Joystick X pub joy_x: Pb7, - /// Joystick Y pub joy_y: Pb6, } #[cfg(feature = "unproven")] impl JoystickReader { - /// returns a tuple (x,y) where values are 12 bit, between 0-4095 - /// values are NOT centered, but could be by subtracting 2048 + /// Returns a tuple (x,y) where values are 12 bit, between 0-4095. Values + /// are NOT centered, but could be by subtracting 2048. pub fn read(&mut self, adc: &mut hal::adc::Adc) -> (u16, u16) { - //note adafruit averages 3 readings on x and y (not inside the adc) seems + // note adafruit averages 3 readings on x and y (not inside the adc) seems // unnecessary? note adafruit recenters around zero.. Im not doing that // either atm. @@ -640,16 +542,14 @@ impl JoystickReader { /// Joystick pins pub struct Joystick { - /// Joystick X pub joy_x: Pb7>, - /// Joystick Y pub joy_y: Pb6>, } #[cfg(feature = "unproven")] impl Joystick { /// Convenience for setting up the joystick. Returns JoystickReader instance - /// which can be polled for joystick (x,y) tuple + /// which can be polled for joystick (x,y) tuple. pub fn init(self, port: &mut Port) -> JoystickReader { JoystickReader { joy_x: self.joy_x.into_function_b(port), @@ -661,13 +561,12 @@ impl Joystick { /// Battery Reader #[cfg(feature = "unproven")] pub struct BatteryReader { - /// Battery pin pub battery: Pb1, } #[cfg(feature = "unproven")] impl BatteryReader { - /// Returns a float for voltage of battery + /// Returns a float for voltage of battery. pub fn read(&mut self, adc: &mut hal::adc::Adc) -> f32 { let data: u16 = adc.read(&mut self.battery).unwrap(); let result: f32 = (data as f32 / 4095.0) * 2.0 * 3.3; @@ -682,7 +581,7 @@ pub struct Battery { #[cfg(feature = "unproven")] impl Battery { - /// Convenience for reading Battery Volage. Returns BatteryReader instance + /// Convenience for reading Battery Volage. Returns a BatteryReader instance /// which can be polled for battery voltage pub fn init(self, port: &mut Port) -> BatteryReader { BatteryReader { From 3e8f060d7b1290c352edb2ea36a9ff3319b3e888 Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Wed, 9 Dec 2020 01:54:41 -0700 Subject: [PATCH 6/6] hal docs --- hal/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hal/src/lib.rs b/hal/src/lib.rs index f5bd2884ac65..83a68bc98923 100644 --- a/hal/src/lib.rs +++ b/hal/src/lib.rs @@ -1,7 +1,26 @@ +//! `atsamd-hal` is Hardware Abstraction Layer (HAL) provideing a type-safe API +//! for working with with the SAM family of processors including: +//! * samd11 +//! * samd21 +//! * samd51 +//! * same51 +//! * same53 +//! * same54 +//! +//! It utilizes the raw registers provided by the Peripheral Access Crate (PAC) +//! and, where possible, traits specified by the `embedded-hal` project making +//! it possible to share code and patterns with various other hals in the +//! embedded rust ecosystem. +//! +//! When in doubt, reference the datasheets available at [Microchip]. +//! +//! [Microchip]: https://www.microchip.com/design-centers/32-bit + #![no_std] pub extern crate embedded_hal as hal; +#[doc(hidden)] pub use paste; pub mod typelevel; @@ -74,6 +93,7 @@ macro_rules! dbgprint { #[macro_use] pub mod common; +#[doc(inline)] pub use self::common::*; #[cfg(feature = "samd11")]