From da2372b19cff52b362ced933691f3b91a0678b04 Mon Sep 17 00:00:00 2001 From: Eivind Alexander Bergem Date: Fri, 4 Mar 2022 10:34:37 +0100 Subject: [PATCH 01/17] Fixed broken link in rp-pico Cargo.toml --- boards/rp-pico/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/rp-pico/Cargo.toml b/boards/rp-pico/Cargo.toml index f7b048c..979da31 100644 --- a/boards/rp-pico/Cargo.toml +++ b/boards/rp-pico/Cargo.toml @@ -3,7 +3,7 @@ name = "rp-pico" version = "0.3.0" authors = ["evan "] edition = "2018" -homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/pico" +homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/rp-pico" description = "Board Support Package for the Raspberry Pi Pico" license = "MIT OR Apache-2.0" repository = "https://github.com/rp-rs/rp-hal.git" From b81955c2a828f540fd51d2273c7bd9b38c3e9584 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Fri, 11 Mar 2022 22:37:34 +1100 Subject: [PATCH 02/17] Prep for 0.4.0 release (#312) * Update changelog for 0.4.0 release * Enable rt feature for irq example in Cargo.toml * Bump pio/pio-proc deps to 0.2.0, update pio examples * Update BSPs to latest ws2812-pio, remove unused pio dep * Fix usage of pio_proc in doc comment * Clean up pio doc-example * Update rp-pico to latest i2c-pio Co-authored-by: Jan Niehusmann --- boards/adafruit-feather-rp2040/Cargo.toml | 3 +-- boards/adafruit-itsy-bitsy-rp2040/Cargo.toml | 3 +-- boards/adafruit-kb2040/Cargo.toml | 3 +-- boards/adafruit-qt-py-rp2040/Cargo.toml | 3 +-- boards/adafruit-trinkey-qt2040/Cargo.toml | 2 +- boards/rp-pico/Cargo.toml | 4 ++-- boards/solderparty-rp2040-stamp/Cargo.toml | 2 +- boards/sparkfun-pro-micro-rp2040/Cargo.toml | 2 +- rp2040-hal/CHANGELOG.md | 7 ++++++- rp2040-hal/Cargo.toml | 9 +++++++-- rp2040-hal/examples/pio_proc_blink.rs | 13 +++++-------- rp2040-hal/examples/pio_side_set.rs | 15 ++++++--------- rp2040-hal/src/pio.rs | 12 +++++------- 13 files changed, 38 insertions(+), 40 deletions(-) diff --git a/boards/adafruit-feather-rp2040/Cargo.toml b/boards/adafruit-feather-rp2040/Cargo.toml index 9f4c6b8..b7ea901 100644 --- a/boards/adafruit-feather-rp2040/Cargo.toml +++ b/boards/adafruit-feather-rp2040/Cargo.toml @@ -22,8 +22,7 @@ panic-halt= "0.2.0" embedded-hal ="0.2.5" nb = "1.0.0" smart-leds = "0.3.0" -pio = "0.1.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } [features] default = ["boot2", "rt"] diff --git a/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml b/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml index eee6ade..0b102ea 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml +++ b/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml @@ -22,8 +22,7 @@ panic-halt= "0.2.0" embedded-hal ="0.2.5" smart-leds = "0.3" nb = "1.0.0" -pio = "0.1.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } [features] default = ["rt", "boot2"] diff --git a/boards/adafruit-kb2040/Cargo.toml b/boards/adafruit-kb2040/Cargo.toml index 2cd53a3..106b869 100644 --- a/boards/adafruit-kb2040/Cargo.toml +++ b/boards/adafruit-kb2040/Cargo.toml @@ -28,5 +28,4 @@ rp2040-boot2 = "0.2" smart-leds = "0.3.0" embedded-time = "0.12.0" nb = "1.0.0" -pio = "0.1.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } diff --git a/boards/adafruit-qt-py-rp2040/Cargo.toml b/boards/adafruit-qt-py-rp2040/Cargo.toml index 35c1400..15d2090 100644 --- a/boards/adafruit-qt-py-rp2040/Cargo.toml +++ b/boards/adafruit-qt-py-rp2040/Cargo.toml @@ -22,8 +22,7 @@ panic-halt= "0.2.0" embedded-hal ="0.2.5" smart-leds = "0.3" nb = "1.0.0" -pio = "0.1.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } [features] default = ["boot2", "rt"] diff --git a/boards/adafruit-trinkey-qt2040/Cargo.toml b/boards/adafruit-trinkey-qt2040/Cargo.toml index 874ab5c..3cc30f1 100644 --- a/boards/adafruit-trinkey-qt2040/Cargo.toml +++ b/boards/adafruit-trinkey-qt2040/Cargo.toml @@ -21,7 +21,7 @@ embedded-hal ="0.2.5" embedded-time = "0.12.0" smart-leds = "0.3" nb = "1.0.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } [features] default = ["boot2", "rt"] diff --git a/boards/rp-pico/Cargo.toml b/boards/rp-pico/Cargo.toml index 979da31..faf0305 100644 --- a/boards/rp-pico/Cargo.toml +++ b/boards/rp-pico/Cargo.toml @@ -26,11 +26,11 @@ panic-halt= "0.2.0" embedded-hal ="0.2.5" cortex-m-rtic = "0.6.0-rc.4" nb = "1.0" -i2c-pio = { git = "https://github.com/ithinuel/i2c-pio-rs", rev = "df06e4ac94a5b2c985d6a9426dc4cc9be0d535c0" } +i2c-pio = { git = "https://github.com/ithinuel/i2c-pio-rs", rev = "fa155bbae4e8553b448a66cc47236db38b7524dd" } heapless = "0.7.9" embedded-sdmmc = { git = "https://github.com/rust-embedded-community/embedded-sdmmc-rs.git" } smart-leds = "0.3.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } ssd1306 = "0.7.0" embedded-graphics = "0.7.1" diff --git a/boards/solderparty-rp2040-stamp/Cargo.toml b/boards/solderparty-rp2040-stamp/Cargo.toml index 91fa647..9ebe18c 100644 --- a/boards/solderparty-rp2040-stamp/Cargo.toml +++ b/boards/solderparty-rp2040-stamp/Cargo.toml @@ -27,5 +27,5 @@ embedded-hal ="0.2.5" nb = "1.0.0" smart-leds = "0.3.0" pio = "0.1.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } embedded-time = "0.12.0" diff --git a/boards/sparkfun-pro-micro-rp2040/Cargo.toml b/boards/sparkfun-pro-micro-rp2040/Cargo.toml index 1cfcaf4..3295488 100644 --- a/boards/sparkfun-pro-micro-rp2040/Cargo.toml +++ b/boards/sparkfun-pro-micro-rp2040/Cargo.toml @@ -23,7 +23,7 @@ smart-leds = "0.3.0" embedded-time = "0.12.0" nb = "1.0.0" pio = "0.1.0" -ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "4f0d81e594ea9934f9c4c38ed9824ad0cce4ebb5" } +ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "fd6b6604d65a66242b52ccf7f24a95ca325991dd" } [features] default = ["boot2", "rt"] diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index 5455812..2759d75 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.4.0] - 2022-03-09 + ### Added - ROM function caching @@ -17,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - UART IRQ examples - PIO side-set example - Stopped PIO state machines can change their clock divider +- Added HAL IRQ example ### Changed @@ -32,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update critical_section to use new spinlock implementation - Update embedded-hal alpha support to version 1.0.0-alpha.7 - Avoid 64-bit division in clock calculations +- Update pio and pio-proc to 0.2.0 ## [0.3.0] - 2021-12-19 @@ -90,7 +94,8 @@ The Minimum-Supported Rust Version (MSRV) for this release is 1.54. - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/v0.3.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/v0.4.0...HEAD +[0.4.0]: https://github.com/rp-rs/rp-hal/compare/v0.3.0...v0.4.0 [0.3.0]: https://github.com/rp-rs/rp-hal/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/rp-rs/rp-hal/compare/v0.1.0...v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/v0.1.0 diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 8822de4..d9003be 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -18,7 +18,7 @@ itertools = { version = "0.10.1", default-features = false } nb = "1.0" rp2040-pac = "0.3.0" paste = "1.0" -pio = "0.1.0" +pio = "0.2.0" usb-device = "0.2.8" vcell = "0.1" void = { version = "1.0.2", default-features = false } @@ -44,7 +44,7 @@ cortex-m-rt = "0.7" panic-halt = "0.2.0" rp2040-boot2 = "0.2.0" hd44780-driver = "0.4.0" -pio-proc = "0.1.0" +pio-proc = "0.2.0" dht-sensor = "0.2.1" [features] @@ -56,3 +56,8 @@ alloc = [] rom-func-cache = [] disable-intrinsics = [] rom-v2-intrinsics = [] + +[[example]] +# irq example uses cortex-m-rt::interrupt, need rt feature for that +name = "gpio_irq_example" +required-features = ["rt"] diff --git a/rp2040-hal/examples/pio_proc_blink.rs b/rp2040-hal/examples/pio_proc_blink.rs index 4dff296..1528cb3 100644 --- a/rp2040-hal/examples/pio_proc_blink.rs +++ b/rp2040-hal/examples/pio_proc_blink.rs @@ -34,14 +34,11 @@ fn main() -> ! { let led_pin_id = 25; // Define some simple PIO program. - let program = pio_proc::pio!( - 32, - " -.wrap_target - set pins, 1 [31] - set pins, 0 [31] -.wrap - " + let program = pio_proc::pio_asm!( + ".wrap_target", + "set pins, 1 [31]", + "set pins, 0 [31]", + ".wrap" ); // Initialize and start PIO diff --git a/rp2040-hal/examples/pio_side_set.rs b/rp2040-hal/examples/pio_side_set.rs index c6fd7bd..46f45b8 100644 --- a/rp2040-hal/examples/pio_side_set.rs +++ b/rp2040-hal/examples/pio_side_set.rs @@ -36,15 +36,12 @@ fn main() -> ! { let led_pin_id = 25; // Define some simple PIO program. - let program = pio_proc::pio!( - 32, - " - .side_set 1 ; each instruction may set 1 bit - .wrap_target - nop side 1 - nop side 0 - .wrap - " + let program = pio_proc::pio_asm!( + ".side_set 1", // each instruction may set 1 bit + ".wrap_target", + " nop side 1", + " nop side 0", + ".wrap", ); // Initialize and start PIO diff --git a/rp2040-hal/src/pio.rs b/rp2040-hal/src/pio.rs index 7847764..9bb4a8e 100644 --- a/rp2040-hal/src/pio.rs +++ b/rp2040-hal/src/pio.rs @@ -244,13 +244,11 @@ impl PIO

{ /// let mut peripherals = pac::Peripherals::take().unwrap(); /// let (mut pio, sm0, _, _, _) = peripherals.PIO0.split(&mut peripherals.RESETS); /// // Install a program in instruction memory. -/// let program = pio_proc::pio!( -/// 32, -/// ".wrap_target -/// set pins, 1 [31] -/// set pins, 0 [31] -/// .wrap -/// " +/// let program = pio_proc::pio_asm!( +/// ".wrap_target", +/// "set pins, 1 [31]", +/// "set pins, 0 [31]", +/// ".wrap" /// ).program; /// let installed = pio.install(&program).unwrap(); /// // Configure a state machine to use the program. From 7aefb8680df07f157b26bab1157e0261c70b60c3 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 12 Mar 2022 22:43:16 +1100 Subject: [PATCH 03/17] Update BSPs prior to release (#313) * Update BSP authors to include 'rp-rs developers' * Update BSP readme's to reflect current release version * Update BSP changelogs * Fix version number in HAL README --- boards/adafruit-feather-rp2040/CHANGELOG.md | 9 ++++++++- boards/adafruit-feather-rp2040/Cargo.toml | 2 +- boards/adafruit-feather-rp2040/README.md | 2 +- boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md | 9 ++++++++- boards/adafruit-itsy-bitsy-rp2040/Cargo.toml | 2 +- boards/adafruit-itsy-bitsy-rp2040/README.md | 2 +- boards/adafruit-kb2040/CHANGELOG.md | 9 ++++++++- boards/adafruit-kb2040/Cargo.toml | 2 +- boards/adafruit-kb2040/README.md | 2 +- boards/adafruit-macropad/CHANGELOG.md | 9 ++++++++- boards/adafruit-macropad/Cargo.toml | 2 +- boards/adafruit-macropad/README.md | 2 +- boards/adafruit-qt-py-rp2040/CHANGELOG.md | 9 ++++++++- boards/adafruit-qt-py-rp2040/Cargo.toml | 2 +- boards/adafruit-qt-py-rp2040/README.md | 2 +- boards/pimoroni-pico-explorer/CHANGELOG.md | 9 ++++++++- boards/pimoroni-pico-explorer/Cargo.toml | 2 +- boards/pimoroni-pico-explorer/README.md | 2 +- boards/pimoroni-pico-lipo-16mb/CHANGELOG.md | 9 ++++++++- boards/pimoroni-pico-lipo-16mb/Cargo.toml | 2 +- boards/pimoroni-pico-lipo-16mb/README.md | 2 +- boards/pimoroni-tiny2040/Cargo.toml | 2 +- boards/rp-pico/CHANGELOG.md | 9 ++++++++- boards/rp-pico/Cargo.toml | 2 +- boards/rp-pico/README.md | 2 +- boards/solderparty-rp2040-stamp/README.md | 2 +- boards/sparkfun-pro-micro-rp2040/CHANGELOG.md | 9 ++++++++- boards/sparkfun-pro-micro-rp2040/Cargo.toml | 2 +- boards/sparkfun-pro-micro-rp2040/README.md | 2 +- rp2040-hal/README.md | 2 +- 30 files changed, 93 insertions(+), 30 deletions(-) diff --git a/boards/adafruit-feather-rp2040/CHANGELOG.md b/boards/adafruit-feather-rp2040/CHANGELOG.md index 25f2848..6208953 100644 --- a/boards/adafruit-feather-rp2040/CHANGELOG.md +++ b/boards/adafruit-feather-rp2040/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp2040-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-feather-rp2040-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-feather-rp2040-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-feather-rp2040-v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-feather-rp2040-v0.1.0 diff --git a/boards/adafruit-feather-rp2040/Cargo.toml b/boards/adafruit-feather-rp2040/Cargo.toml index b7ea901..b28a83b 100644 --- a/boards/adafruit-feather-rp2040/Cargo.toml +++ b/boards/adafruit-feather-rp2040/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "adafruit-feather-rp2040" version = "0.2.0" -authors = ["Andrea Nall "] +authors = ["Andrea Nall ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/adafruit-feather-rp2040" description = "Board Support Package for the Adafruit Feather RP2040" diff --git a/boards/adafruit-feather-rp2040/README.md b/boards/adafruit-feather-rp2040/README.md index 9aabfce..08328b2 100644 --- a/boards/adafruit-feather-rp2040/README.md +++ b/boards/adafruit-feather-rp2040/README.md @@ -16,7 +16,7 @@ RP2040 chip according to how it is connected up on the Feather. To use this crate, your `Cargo.toml` file should contain: ```toml -adafruit-feather-rp2040 = "0.1.0" +adafruit-feather-rp2040 = "0.2.0" ``` In your program, you will need to call `adafruit_feather_rp2040::Pins::new` to create diff --git a/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md b/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md index b54a3e8..fbd87a1 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md +++ b/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp2040-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-itsy-bitsy-rp2040-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-itsy-bitsy-rp2040-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-itsy-bitsy-rp2040-v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-itsy-bitsy-rp2040-v0.1.0 diff --git a/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml b/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml index 0b102ea..41359d7 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml +++ b/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "adafruit-itsy-bitsy-rp2040" version = "0.2.0" -authors = ["Andrew Christiansen "] +authors = ["Andrew Christiansen ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/adafruit_itsy_bitsy_rp2040" description = "Board Support Package for the Adafruit ItsyBitsy RP2040" diff --git a/boards/adafruit-itsy-bitsy-rp2040/README.md b/boards/adafruit-itsy-bitsy-rp2040/README.md index 5d16b42..f8a2ae9 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/README.md +++ b/boards/adafruit-itsy-bitsy-rp2040/README.md @@ -16,7 +16,7 @@ RP2040 chip according to how it is connected up on the ItsyBitsy RP2040. To use this crate, your `Cargo.toml` file should contain: ```toml -adafruit-itsy-bitsy-rp2040 = "0.1.0" +adafruit-itsy-bitsy-rp2040 = "0.2.0" ``` In your program, you will need to call `adafruit_itsy_bitsy_rp2040::Pins::new` to create diff --git a/boards/adafruit-kb2040/CHANGELOG.md b/boards/adafruit-kb2040/CHANGELOG.md index 24cd4ec..41a6a52 100644 --- a/boards/adafruit-kb2040/CHANGELOG.md +++ b/boards/adafruit-kb2040/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp2040-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-kb2040-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-kb2040-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-kb2040-v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-kb2040-v0.1.0 diff --git a/boards/adafruit-kb2040/Cargo.toml b/boards/adafruit-kb2040/Cargo.toml index 106b869..b3223ff 100644 --- a/boards/adafruit-kb2040/Cargo.toml +++ b/boards/adafruit-kb2040/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "adafruit-kb2040" version = "0.2.0" -authors = ["Andrew Christiansen "] +authors = ["Andrew Christiansen ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/adafruit-kb2040" description = "Board Support Package for the Adafruit adafruit-kb2040" diff --git a/boards/adafruit-kb2040/README.md b/boards/adafruit-kb2040/README.md index 808cb42..3ebeb7b 100644 --- a/boards/adafruit-kb2040/README.md +++ b/boards/adafruit-kb2040/README.md @@ -16,7 +16,7 @@ RP2040 chip according to how it is connected up on the KB2040. To use this crate, your `Cargo.toml` file should contain: ```toml -adafruit-kb2040 = "0.1.0" +adafruit-kb2040 = "0.2.0" ``` In your program, you will need to call `adafruit-kb2040::Pins::new` to create diff --git a/boards/adafruit-macropad/CHANGELOG.md b/boards/adafruit-macropad/CHANGELOG.md index 7e7d0a9..4fc049e 100644 --- a/boards/adafruit-macropad/CHANGELOG.md +++ b/boards/adafruit-macropad/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp2040-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-macropad-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-macropad-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-macropad-v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-macropad-v0.1.0 diff --git a/boards/adafruit-macropad/Cargo.toml b/boards/adafruit-macropad/Cargo.toml index a961790..9f418bc 100644 --- a/boards/adafruit-macropad/Cargo.toml +++ b/boards/adafruit-macropad/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "adafruit-macropad" version = "0.2.0" -authors = ["Andrea Nall "] +authors = ["Andrea Nall ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/adafruit_macropad" description = "Board Support Package for the Adafruit Macropad" diff --git a/boards/adafruit-macropad/README.md b/boards/adafruit-macropad/README.md index f4912da..df7fbf8 100644 --- a/boards/adafruit-macropad/README.md +++ b/boards/adafruit-macropad/README.md @@ -16,7 +16,7 @@ RP2040 chip according to how it is connected up on the Feather. To use this crate, your `Cargo.toml` file should contain: ```toml -adafruit-macropad = "0.1.0" +adafruit-macropad = "0.2.0" ``` In your program, you will need to call `adafruit_macropad::Pins::new` to create diff --git a/boards/adafruit-qt-py-rp2040/CHANGELOG.md b/boards/adafruit-qt-py-rp2040/CHANGELOG.md index 799f4a7..6adbea4 100644 --- a/boards/adafruit-qt-py-rp2040/CHANGELOG.md +++ b/boards/adafruit-qt-py-rp2040/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp2040-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-qt-py-rp2040-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/adafruit-qt-py-rp2040-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-qt-py-rp2040-v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/adafruit-qt-py-rp2040-v0.1.0 diff --git a/boards/adafruit-qt-py-rp2040/Cargo.toml b/boards/adafruit-qt-py-rp2040/Cargo.toml index 15d2090..ac44e43 100644 --- a/boards/adafruit-qt-py-rp2040/Cargo.toml +++ b/boards/adafruit-qt-py-rp2040/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "adafruit-qt-py-rp2040" version = "0.2.0" -authors = ["Stephen Onnen "] +authors = ["Stephen Onnen ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/adafruit-qt-py-rp2040" description = "Board Support Package for the Adafruit QT Py RP2040" diff --git a/boards/adafruit-qt-py-rp2040/README.md b/boards/adafruit-qt-py-rp2040/README.md index c3250d4..5db1ae6 100644 --- a/boards/adafruit-qt-py-rp2040/README.md +++ b/boards/adafruit-qt-py-rp2040/README.md @@ -16,7 +16,7 @@ RP2040 chip according to how it is connected up on the QT Py. To use this crate, your `Cargo.toml` file should contain: ```toml -adafruit-qt-py-rp2040 = { git = "https://github.com/rp-rs/rp-hal.git" } +adafruit-qt-py-rp2040 = "0.2.0" ``` In your program, you will need to call `adafruit_qt_py_rp2040::Pins::new` to create diff --git a/boards/pimoroni-pico-explorer/CHANGELOG.md b/boards/pimoroni-pico-explorer/CHANGELOG.md index e2e2069..0f4da47 100644 --- a/boards/pimoroni-pico-explorer/CHANGELOG.md +++ b/boards/pimoroni-pico-explorer/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp2040-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/pimoroni-pico-explorer-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/pimoroni-pico-explorer-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/pimoroni-pico-explorer-v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/pimoroni-pico-explorer-v0.1.0 diff --git a/boards/pimoroni-pico-explorer/Cargo.toml b/boards/pimoroni-pico-explorer/Cargo.toml index 2061193..a1f9916 100644 --- a/boards/pimoroni-pico-explorer/Cargo.toml +++ b/boards/pimoroni-pico-explorer/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pimoroni-pico-explorer" version = "0.2.0" -authors = ["Hmvp "] +authors = ["Hmvp ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/pimoroni-pico-explorer" description = "Board Support Package for the Pico Explorer" diff --git a/boards/pimoroni-pico-explorer/README.md b/boards/pimoroni-pico-explorer/README.md index 7e96a36..4d4541c 100644 --- a/boards/pimoroni-pico-explorer/README.md +++ b/boards/pimoroni-pico-explorer/README.md @@ -17,7 +17,7 @@ RP2040 chip according to how it is connected up on the Pico Explorer. To use this crate, your `Cargo.toml` file should contain: ```toml -pimoroni-pico-explorer = "0.1.0" +pimoroni-pico-explorer = "0.2.0" ``` In your program, you will need to call `pimoroni_pico_explorer::Pins::new` to create diff --git a/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md b/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md index 8ccb686..fce231d 100644 --- a/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md +++ b/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp2040-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/pimoroni-pico-lipo-16mb-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/pimoroni-pico-lipo-16mb-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/pimoroni-pico-lipo-16mb-v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/pimoroni-pico-lipo-16mb-v0.1.0 diff --git a/boards/pimoroni-pico-lipo-16mb/Cargo.toml b/boards/pimoroni-pico-lipo-16mb/Cargo.toml index 79a247b..c503985 100644 --- a/boards/pimoroni-pico-lipo-16mb/Cargo.toml +++ b/boards/pimoroni-pico-lipo-16mb/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pimoroni-pico-lipo-16mb" version = "0.2.0" -authors = ["Hmvp "] +authors = ["Hmvp ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/pimoroni-pico-lipo-16mb" description = "Board Support Package for the Pico LiPo 16MB" diff --git a/boards/pimoroni-pico-lipo-16mb/README.md b/boards/pimoroni-pico-lipo-16mb/README.md index 0c8055d..c463495 100644 --- a/boards/pimoroni-pico-lipo-16mb/README.md +++ b/boards/pimoroni-pico-lipo-16mb/README.md @@ -18,7 +18,7 @@ space, and so it may not work if you only have the 4MB variant. To use this crate, your `Cargo.toml` file should contain: ```toml -pimoroni-pico-lipo-16mb = { git = "https://github.com/rp-rs/rp-hal.git" } +pimoroni-pico-lipo-16mb = "0.2.0" ``` In your program, you will need to call `pimoroni_pico_lipo_16mb::Pins::new` to create diff --git a/boards/pimoroni-tiny2040/Cargo.toml b/boards/pimoroni-tiny2040/Cargo.toml index f21900f..1f7b52c 100644 --- a/boards/pimoroni-tiny2040/Cargo.toml +++ b/boards/pimoroni-tiny2040/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pimoroni-tiny2040" version = "0.1.0" -authors = ["Mike Bell "] +authors = ["Mike Bell ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/pimoroni-tiny2040" description = "Board Support Package for the Pimoroni Tiny2040" diff --git a/boards/rp-pico/CHANGELOG.md b/boards/rp-pico/CHANGELOG.md index a7f1cf8..d22724a 100644 --- a/boards/rp-pico/CHANGELOG.md +++ b/boards/rp-pico/CHANGELOG.md @@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.3.0] - 2022-03-11 + +### Changed + +- Update to rp-hal 0.4.0 + ## [0.2.0] - 2021-12-23 ### Added @@ -31,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [@jannic]: https://github.com/jannic [rp-rs]: https://github.com/rp-rs -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/rp-pico-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/rp-pico-v0.3.0...HEAD +[0.3.0]: https://github.com/rp-rs/rp-hal/releases/tag/rp-pico-v0.3.0 [0.2.0]: https://github.com/rp-rs/rp-hal/releases/tag/rp-pico-v0.2.0 [0.1.3]: https://github.com/jannic/rp-microcontroller-rs/tree/rp-pico-0.1.3 diff --git a/boards/rp-pico/Cargo.toml b/boards/rp-pico/Cargo.toml index faf0305..7ea36a8 100644 --- a/boards/rp-pico/Cargo.toml +++ b/boards/rp-pico/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rp-pico" version = "0.3.0" -authors = ["evan "] +authors = ["evan ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/rp-pico" description = "Board Support Package for the Raspberry Pi Pico" diff --git a/boards/rp-pico/README.md b/boards/rp-pico/README.md index de24f3d..4a24b82 100644 --- a/boards/rp-pico/README.md +++ b/boards/rp-pico/README.md @@ -16,7 +16,7 @@ RP2040 chip according to how it is connected up on the Pico. To use this crate, your `Cargo.toml` file should contain: ```toml -rp-pico = "0.2.0" +rp-pico = "0.3.0" ``` In your program, you will need to call `rp_pico::Pins::new` to create diff --git a/boards/solderparty-rp2040-stamp/README.md b/boards/solderparty-rp2040-stamp/README.md index 8b17bed..feb1318 100644 --- a/boards/solderparty-rp2040-stamp/README.md +++ b/boards/solderparty-rp2040-stamp/README.md @@ -16,7 +16,7 @@ RP2040 chip according to how it is connected up on the Stamp To use this crate, your `Cargo.toml` file should contain: ```toml -solderparty-rp2040-stamp = { git = "https://github.com/rp-rs/rp-hal.git" } +solderparty-rp2040-stamp = "0.1.0" ``` In your program, you will need to call `solderparty_rp2040_stamp::Pins::new` to create diff --git a/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md b/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md index 04fbbeb..9f7e350 100644 --- a/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md +++ b/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md @@ -15,9 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - None +## [0.2.0] - 2022-03-11 + +### Changed + +- Update to rp-hal 0.4.0 + ## [0.1.0] - 2021-12-20 - Initial release -[Unreleased]: https://github.com/rp-rs/rp-hal/compare/sparkfun-pro-micro-rp2040-v0.1.0...HEAD +[Unreleased]: https://github.com/rp-rs/rp-hal/compare/sparkfun-pro-micro-rp2040-v0.2.0...HEAD +[0.2.0]: https://github.com/rp-rs/rp-hal/compare/sparkfun-pro-micro-rp2040-v0.1.0...v0.2.0 [0.1.0]: https://github.com/rp-rs/rp-hal/releases/tag/sparkfun-pro-micro-rp2040-v0.1.0 diff --git a/boards/sparkfun-pro-micro-rp2040/Cargo.toml b/boards/sparkfun-pro-micro-rp2040/Cargo.toml index 3295488..3fe87bb 100644 --- a/boards/sparkfun-pro-micro-rp2040/Cargo.toml +++ b/boards/sparkfun-pro-micro-rp2040/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sparkfun-pro-micro-rp2040" version = "0.2.0" -authors = ["Wilfried Chauveau "] +authors = ["Wilfried Chauveau ", "The rp-rs Developers"] edition = "2018" homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/sparkfun-pro-micro-rp2040" description = "Board Support Package for the Sparkfun Pro Micro RP2040" diff --git a/boards/sparkfun-pro-micro-rp2040/README.md b/boards/sparkfun-pro-micro-rp2040/README.md index a1d57d6..e0ce5ad 100644 --- a/boards/sparkfun-pro-micro-rp2040/README.md +++ b/boards/sparkfun-pro-micro-rp2040/README.md @@ -17,7 +17,7 @@ RP2040 chip according to how it is connected up on the Pro Micro RP2040. To use this crate, your `Cargo.toml` file should contain: ```toml -sparkfun-pro-micro-rp2040 = "0.1.0" +sparkfun-pro-micro-rp2040 = "0.2.0" ``` In your program, you will need to call `sparkfun_pro_micro_rp2040::Pins::new` to create diff --git a/rp2040-hal/README.md b/rp2040-hal/README.md index dce1529..2bb87f6 100644 --- a/rp2040-hal/README.md +++ b/rp2040-hal/README.md @@ -68,7 +68,7 @@ https://github.com/rp-rs/rp-hal/ for more details. To include this crate in your project, amend your `Cargo.toml` file to include ```toml -rp2040-hal = "0.3.0" +rp2040-hal = "0.4.0" ``` To obtain a copy of the source code (e.g. if you want to propose a bug-fix or From f8de8755ccf82a782c9430c343afa8daea671b24 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 13 Mar 2022 02:35:59 +0100 Subject: [PATCH 04/17] Add an rp2040 specific #[entry] macro. (#300) * Add an rp2040 specific #[entry] macro. This macro extends the one from cortex-m-rt by code to unlock all spinlocks on boot. * Idiomatic pointer arithmetic Apply suggestion by @9names, improving address calculations. (This doesn't change the generated code at opt levels 2 or "z".) Co-authored-by: 9names <60134748+9names@users.noreply.github.com> --- Cargo.toml | 1 + rp2040-hal-macros/Cargo.toml | 20 ++++++++++++ rp2040-hal-macros/README.md | 27 +++++++++++++++++ rp2040-hal-macros/src/lib.rs | 59 ++++++++++++++++++++++++++++++++++++ rp2040-hal/Cargo.toml | 2 ++ rp2040-hal/src/lib.rs | 9 ++++++ 6 files changed, 118 insertions(+) create mode 100644 rp2040-hal-macros/Cargo.toml create mode 100644 rp2040-hal-macros/README.md create mode 100644 rp2040-hal-macros/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 55a1dfc..ef4c89c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ resolver = "2" members = [ "rp2040-hal", + "rp2040-hal-macros", "boards/adafruit-feather-rp2040", "boards/adafruit-itsy-bitsy-rp2040", "boards/adafruit-kb2040", diff --git a/rp2040-hal-macros/Cargo.toml b/rp2040-hal-macros/Cargo.toml new file mode 100644 index 0000000..64e6cfc --- /dev/null +++ b/rp2040-hal-macros/Cargo.toml @@ -0,0 +1,20 @@ +[package] +description = "Macros used by rp2040-hal" +license = "MIT OR Apache-2.0" +name = "rp2040-hal-macros" +readme = "README.md" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] +quote = "1.0" +proc-macro2 = "1.0" +cortex-m-rt = "0.7.0" + +[dependencies.syn] +features = ["extra-traits", "full"] +version = "1.0" + diff --git a/rp2040-hal-macros/README.md b/rp2040-hal-macros/README.md new file mode 100644 index 0000000..00c62c9 --- /dev/null +++ b/rp2040-hal-macros/README.md @@ -0,0 +1,27 @@ +# `rp2040-hal-macros` + +Macros used by rp2040-hal. + +## Entry macro + +Extension of the `cortex-m-rt` `#[entry]` with rp2040 specific initialization code. + +Currently, it just unlocks all spinlocks before calling the entry function. + +# License + +Licensed under either of + +- Apache License, Version 2.0 (`APACHE2.0` or + http://www.apache.org/licenses/LICENSE-2.0) + +- MIT license (`MIT` or http://opensource.org/licenses/MIT) + +at your option. + +## Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall be +dual licensed as above, without any additional terms or conditions. + diff --git a/rp2040-hal-macros/src/lib.rs b/rp2040-hal-macros/src/lib.rs new file mode 100644 index 0000000..f8e9c71 --- /dev/null +++ b/rp2040-hal-macros/src/lib.rs @@ -0,0 +1,59 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; +use proc_macro2::Span; +use quote::quote; +use syn::{parse, parse_macro_input, Item, ItemFn, Stmt}; + +#[proc_macro_attribute] +pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { + let mut f = parse_macro_input!(input as ItemFn); + + if !args.is_empty() { + return parse::Error::new(Span::call_site(), "This attribute accepts no arguments") + .to_compile_error() + .into(); + } + + let clear_locks: TokenStream = quote!(unsafe { + const SIO_BASE: u32 = 0xd0000000; + const SPINLOCK0_PTR: *mut u32 = (SIO_BASE + 0x100) as *mut u32; + const SPINLOCK_COUNT: usize = 32; + for i in 0..SPINLOCK_COUNT { + SPINLOCK0_PTR.wrapping_add(i).write_volatile(1); + } + }) + .into(); + let clear_locks = parse_macro_input!(clear_locks as Stmt); + + // statics must stay first so cortex_m_rt::entry still finds them + let stmts = insert_after_static(f.block.stmts, clear_locks); + f.block.stmts = stmts; + + quote!( + #[::cortex_m_rt::entry] + #f + ) + .into() +} + +/// Insert new statements after initial block of statics +fn insert_after_static(stmts: impl IntoIterator, insert: Stmt) -> Vec { + let mut istmts = stmts.into_iter(); + let mut stmts = vec![]; + for stmt in istmts.by_ref() { + match stmt { + Stmt::Item(Item::Static(var)) => { + stmts.push(Stmt::Item(Item::Static(var))); + } + _ => { + stmts.push(insert); + stmts.push(stmt); + break; + } + } + } + stmts.extend(istmts); + + stmts +} diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index d9003be..ea0e1c3 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0" [dependencies] cortex-m = "0.7.2" +cortex-m-rt = ">=0.6.15,<0.8" embedded-hal = { version = "0.2.5", features = ["unproven"] } eh1_0_alpha = { version = "=1.0.0-alpha.7", package="embedded-hal", optional=true } embedded-time = "0.12.0" @@ -19,6 +20,7 @@ nb = "1.0" rp2040-pac = "0.3.0" paste = "1.0" pio = "0.2.0" +rp2040-hal-macros = { version = "0.1.0", path = "../rp2040-hal-macros" } usb-device = "0.2.8" vcell = "0.1" void = { version = "1.0.2", default-features = false } diff --git a/rp2040-hal/src/lib.rs b/rp2040-hal/src/lib.rs index 8d2db4e..3153868 100644 --- a/rp2040-hal/src/lib.rs +++ b/rp2040-hal/src/lib.rs @@ -49,6 +49,15 @@ pub mod xosc; pub use adc::Adc; pub use clocks::Clock; pub use i2c::I2C; +/// Attribute to declare the entry point of the program +/// +/// This is based on and can be used like the [entry attribute from +/// cortex-m-rt](https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.entry.html). +/// +/// It extends that macro with code to unlock all spinlocks at the beginning +/// of `main`. As spinlocks are not automatically unlocked on software resets, +/// this can prevent unexpected deadlocks when running from a debugger. +pub use rp2040_hal_macros::entry; pub use sio::Sio; pub use spi::Spi; pub use timer::Timer; From 6026ea4ae37d8e1f5bad3c0361ada34beca7de58 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 18 Mar 2022 10:55:31 +0100 Subject: [PATCH 05/17] Allow to start multiple state machines in sync (#301) * add example of synchronized PIOs * Synchronize state machines using WAIT IRQ instruction * Use "irq wait 0" instead of "wait 1 irq 0" This way, the initial value of the interrupt flag doesn't matter * Start state machines synchronized without IRQ WAIT instruction * Improve API Co-authored-by: Andrew Straw --- rp2040-hal/examples/pio_synchronized.rs | 96 +++++++ rp2040-hal/src/pio.rs | 346 ++++++++++++++++++++++++ 2 files changed, 442 insertions(+) create mode 100644 rp2040-hal/examples/pio_synchronized.rs diff --git a/rp2040-hal/examples/pio_synchronized.rs b/rp2040-hal/examples/pio_synchronized.rs new file mode 100644 index 0000000..39cf23d --- /dev/null +++ b/rp2040-hal/examples/pio_synchronized.rs @@ -0,0 +1,96 @@ +//! This example toggles the GPIO0 and GPIO1 pins, with each controlled from a +//! separate PIO state machine. +//! +//! Despite running in separate state machines, the clocks are sychronized at +//! the rise and fall times will be simultaneous. +#![no_std] +#![no_main] + +use cortex_m_rt::entry; +use hal::gpio::{FunctionPio0, Pin}; +use hal::pac; +use hal::pio::PIOExt; +use hal::Sio; +use panic_halt as _; +use rp2040_hal as hal; + +#[link_section = ".boot2"] +#[used] +pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; + +#[entry] +fn main() -> ! { + let mut pac = pac::Peripherals::take().unwrap(); + + let sio = Sio::new(pac.SIO); + let pins = hal::gpio::Pins::new( + pac.IO_BANK0, + pac.PADS_BANK0, + sio.gpio_bank0, + &mut pac.RESETS, + ); + + // configure pins for Pio0. + let _: Pin<_, FunctionPio0> = pins.gpio0.into_mode(); + let _: Pin<_, FunctionPio0> = pins.gpio1.into_mode(); + + // PIN id for use inside of PIO + let pin0 = 0; + let pin1 = 1; + + // Define some simple PIO program. + let program = pio_proc::pio_asm!( + " +.wrap_target + set pins, 1 [31] + set pins, 0 [31] +.wrap + " + ); + + // Initialize and start PIO + let (mut pio, sm0, sm1, _, _) = pac.PIO0.split(&mut pac.RESETS); + // I'm "measuring" the phase offset between the two pins by connecting + // then through a LED. If there is a clock offset, there will be a + // short time with a voltage between the pins, so the LED will flash up. + // With a slow clock this is not visible, so use a reasonably fast clock. + let div = 256f32; + + let installed = pio.install(&program.program).unwrap(); + let (mut sm0, _, _) = rp2040_hal::pio::PIOBuilder::from_program(installed) + .set_pins(pin0, 1) + .clock_divisor(div) + .build(sm0); + // The GPIO pin needs to be configured as an output. + sm0.set_pindirs([(pin0, hal::pio::PinDir::Output)]); + + // NOTE: with the current rp-hal, I need to call pio.install() twice. This + // should be investigated further as it seems wrong. + let installed = pio.install(&program.program).unwrap(); + let (mut sm1, _, _) = rp2040_hal::pio::PIOBuilder::from_program(installed) + .set_pins(pin1, 1) + .clock_divisor(div) + .build(sm1); + // The GPIO pin needs to be configured as an output. + sm1.set_pindirs([(pin1, hal::pio::PinDir::Output)]); + + // Start both SMs at the same time + let group = sm0.with(sm1).sync().start(); + cortex_m::asm::delay(10_000_000); + + // Stop both SMs at the same time + let group = group.stop(); + cortex_m::asm::delay(10_000_000); + + // Start them again and extract the individual state machines + let (sm1, sm2) = group.start().free(); + cortex_m::asm::delay(10_000_000); + + // Stop the two state machines separately + let _sm1 = sm1.stop(); + cortex_m::asm::delay(10_000_000); + let _sm2 = sm2.stop(); + + #[allow(clippy::empty_loop)] + loop {} +} diff --git a/rp2040-hal/src/pio.rs b/rp2040-hal/src/pio.rs index 9bb4a8e..d7a3d01 100644 --- a/rp2040-hal/src/pio.rs +++ b/rp2040-hal/src/pio.rs @@ -655,6 +655,352 @@ impl StateMachine<(P, SM), Stopped> { } } +impl StateMachine<(P, SM), State> { + /// Create a group of state machines, which can be started/stopped synchonously + pub fn with( + self, + other_sm: StateMachine<(P, SM2), State>, + ) -> StateMachineGroup2 { + StateMachineGroup2 { + sm1: self, + sm2: other_sm, + } + } +} + +/// Group of 2 state machines, which can be started/stopped synchronously. +pub struct StateMachineGroup2< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + State, +> { + sm1: StateMachine<(P, SM1Idx), State>, + sm2: StateMachine<(P, SM2Idx), State>, +} + +/// Group of 3 state machines, which can be started/stopped synchronously. +pub struct StateMachineGroup3< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + State, +> { + sm1: StateMachine<(P, SM1Idx), State>, + sm2: StateMachine<(P, SM2Idx), State>, + sm3: StateMachine<(P, SM3Idx), State>, +} + +/// Group of 4 state machines, which can be started/stopped synchronously. +pub struct StateMachineGroup4< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + SM4Idx: StateMachineIndex, + State, +> { + sm1: StateMachine<(P, SM1Idx), State>, + sm2: StateMachine<(P, SM2Idx), State>, + sm3: StateMachine<(P, SM3Idx), State>, + sm4: StateMachine<(P, SM4Idx), State>, +} + +impl + StateMachineGroup2 +{ + /// Split the group, releasing the contained state machines + #[allow(clippy::type_complexity)] + pub fn free( + self, + ) -> ( + StateMachine<(P, SM1Idx), State>, + StateMachine<(P, SM2Idx), State>, + ) { + (self.sm1, self.sm2) + } + + /// Add another state machine to the group + pub fn with( + self, + other_sm: StateMachine<(P, SM3Idx), State>, + ) -> StateMachineGroup3 { + StateMachineGroup3 { + sm1: self.sm1, + sm2: self.sm2, + sm3: other_sm, + } + } + + fn mask(&self) -> u32 { + (1 << SM1Idx::id()) | (1 << SM2Idx::id()) + } +} + +impl< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + State, + > StateMachineGroup3 +{ + /// Split the group, releasing the contained state machines + #[allow(clippy::type_complexity)] + pub fn free( + self, + ) -> ( + StateMachine<(P, SM1Idx), State>, + StateMachine<(P, SM2Idx), State>, + StateMachine<(P, SM3Idx), State>, + ) { + (self.sm1, self.sm2, self.sm3) + } + + /// Add another state machine to the group + pub fn with( + self, + other_sm: StateMachine<(P, SM4Idx), State>, + ) -> StateMachineGroup4 { + StateMachineGroup4 { + sm1: self.sm1, + sm2: self.sm2, + sm3: self.sm3, + sm4: other_sm, + } + } + + fn mask(&self) -> u32 { + (1 << SM1Idx::id()) | (1 << SM2Idx::id()) | (1 << SM3Idx::id()) + } +} + +impl< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + SM4Idx: StateMachineIndex, + State, + > StateMachineGroup4 +{ + /// Split the group, releasing the contained state machines + #[allow(clippy::type_complexity)] + pub fn free( + self, + ) -> ( + StateMachine<(P, SM1Idx), State>, + StateMachine<(P, SM2Idx), State>, + StateMachine<(P, SM3Idx), State>, + StateMachine<(P, SM4Idx), State>, + ) { + (self.sm1, self.sm2, self.sm3, self.sm4) + } + + fn mask(&self) -> u32 { + (1 << SM1Idx::id()) | (1 << SM2Idx::id()) | (1 << SM3Idx::id()) | (1 << SM4Idx::id()) + } +} + +impl + StateMachineGroup2 +{ + /// Start grouped state machines + pub fn start(mut self) -> StateMachineGroup2 { + self.sm1.sm.set_ctrl_bits(self.mask()); + StateMachineGroup2 { + sm1: StateMachine { + sm: self.sm1.sm, + program: self.sm1.program, + _phantom: core::marker::PhantomData, + }, + sm2: StateMachine { + sm: self.sm2.sm, + program: self.sm2.program, + _phantom: core::marker::PhantomData, + }, + } + } + + /// Sync grouped state machines + pub fn sync(mut self) -> Self { + self.sm1.sm.set_ctrl_bits(self.mask() << 8); + self + } +} + +impl< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + > StateMachineGroup3 +{ + /// Start grouped state machines + pub fn start(mut self) -> StateMachineGroup3 { + self.sm1.sm.set_ctrl_bits(self.mask()); + StateMachineGroup3 { + sm1: StateMachine { + sm: self.sm1.sm, + program: self.sm1.program, + _phantom: core::marker::PhantomData, + }, + sm2: StateMachine { + sm: self.sm2.sm, + program: self.sm2.program, + _phantom: core::marker::PhantomData, + }, + sm3: StateMachine { + sm: self.sm3.sm, + program: self.sm3.program, + _phantom: core::marker::PhantomData, + }, + } + } + + /// Sync grouped state machines + pub fn sync(mut self) -> Self { + self.sm1.sm.set_ctrl_bits(self.mask() << 8); + self + } +} + +impl< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + SM4Idx: StateMachineIndex, + > StateMachineGroup4 +{ + /// Start grouped state machines + pub fn start(mut self) -> StateMachineGroup4 { + self.sm1.sm.set_ctrl_bits(self.mask()); + StateMachineGroup4 { + sm1: StateMachine { + sm: self.sm1.sm, + program: self.sm1.program, + _phantom: core::marker::PhantomData, + }, + sm2: StateMachine { + sm: self.sm2.sm, + program: self.sm2.program, + _phantom: core::marker::PhantomData, + }, + sm3: StateMachine { + sm: self.sm3.sm, + program: self.sm3.program, + _phantom: core::marker::PhantomData, + }, + sm4: StateMachine { + sm: self.sm4.sm, + program: self.sm4.program, + _phantom: core::marker::PhantomData, + }, + } + } + + /// Sync grouped state machines + pub fn sync(mut self) -> Self { + self.sm1.sm.set_ctrl_bits(self.mask() << 8); + self + } +} + +impl + StateMachineGroup2 +{ + /// Stop grouped state machines + pub fn stop(mut self) -> StateMachineGroup2 { + self.sm1.sm.clear_ctrl_bits(self.mask()); + StateMachineGroup2 { + sm1: StateMachine { + sm: self.sm1.sm, + program: self.sm1.program, + _phantom: core::marker::PhantomData, + }, + sm2: StateMachine { + sm: self.sm2.sm, + program: self.sm2.program, + _phantom: core::marker::PhantomData, + }, + } + } +} + +impl< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + > StateMachineGroup3 +{ + /// Stop grouped state machines + pub fn stop(mut self) -> StateMachineGroup3 { + self.sm1.sm.clear_ctrl_bits(self.mask()); + StateMachineGroup3 { + sm1: StateMachine { + sm: self.sm1.sm, + program: self.sm1.program, + _phantom: core::marker::PhantomData, + }, + sm2: StateMachine { + sm: self.sm2.sm, + program: self.sm2.program, + _phantom: core::marker::PhantomData, + }, + sm3: StateMachine { + sm: self.sm3.sm, + program: self.sm3.program, + _phantom: core::marker::PhantomData, + }, + } + } +} + +impl< + P: PIOExt, + SM1Idx: StateMachineIndex, + SM2Idx: StateMachineIndex, + SM3Idx: StateMachineIndex, + SM4Idx: StateMachineIndex, + > StateMachineGroup4 +{ + /// Stop grouped state machines + pub fn stop(mut self) -> StateMachineGroup4 { + self.sm1.sm.clear_ctrl_bits(self.mask()); + StateMachineGroup4 { + sm1: StateMachine { + sm: self.sm1.sm, + program: self.sm1.program, + _phantom: core::marker::PhantomData, + }, + sm2: StateMachine { + sm: self.sm2.sm, + program: self.sm2.program, + _phantom: core::marker::PhantomData, + }, + sm3: StateMachine { + sm: self.sm3.sm, + program: self.sm3.program, + _phantom: core::marker::PhantomData, + }, + sm4: StateMachine { + sm: self.sm4.sm, + program: self.sm4.program, + _phantom: core::marker::PhantomData, + }, + } + } + + /// Sync grouped state machines + pub fn sync(mut self) -> Self { + self.sm1.sm.set_ctrl_bits(self.mask() << 8); + self + } +} + /// Type which, once destructed, restarts the clock dividers for all selected state machines, /// effectively synchronizing them. pub struct Synchronize<'sm, SM: ValidStateMachine> { From 990085948ace93cf52ff17f571dcbfc4128b880b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20Mei=C3=9Fner?= Date: Fri, 18 Mar 2022 10:56:27 +0100 Subject: [PATCH 06/17] Using thread send safe UART* marker, as suggested by @danielzfranklin in #Issue-284 (#314) --- rp2040-hal/src/uart/peripheral.rs | 5 +++-- rp2040-hal/src/uart/writer.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index 796731f..9740bef 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -16,6 +16,7 @@ use rp2040_pac::{UART0, UART1}; #[cfg(feature = "eh1_0_alpha")] use eh1_0_alpha::serial as eh1; +use pac::Peripherals; /// An UART Peripheral based on an underlying UART device. pub struct UartPeripheral> { @@ -208,7 +209,7 @@ impl> UartPeripheral { effective_baudrate: self.effective_baudrate, }; // Safety: reader and writer will never write to the same address - let device_copy = unsafe { &*UART0::ptr() }; + let device_copy = unsafe { Peripherals::steal().UART0 }; let writer = Writer { device: device_copy, device_marker: core::marker::PhantomData, @@ -228,7 +229,7 @@ impl> UartPeripheral { effective_baudrate: self.effective_baudrate, }; // Safety: reader and writer will never write to the same address - let device_copy = unsafe { &*UART1::ptr() }; + let device_copy = unsafe { Peripherals::steal().UART1 }; let writer = Writer { device: device_copy, device_marker: core::marker::PhantomData, diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index bf5a550..c67a5b6 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -114,7 +114,7 @@ pub(crate) fn disable_tx_interrupt(rb: &RegisterBlock) { /// [`UartPeripheral`]: struct.UartPeripheral.html /// [`UartPeripheral::split()`]: struct.UartPeripheral.html#method.split pub struct Writer> { - pub(super) device: &'static RegisterBlock, + pub(super) device: D, pub(super) device_marker: PhantomData, pub(super) pins: PhantomData

, } @@ -129,26 +129,26 @@ impl> Writer { /// /// Upon success, the remaining (unwritten) slice is returned. pub fn write_raw<'d>(&self, data: &'d [u8]) -> nb::Result<&'d [u8], Infallible> { - write_raw(self.device, data) + write_raw(&self.device, data) } /// Writes bytes to the UART. /// /// This function blocks until the full buffer has been sent. pub fn write_full_blocking(&self, data: &[u8]) { - write_full_blocking(self.device, data); + write_full_blocking(&self.device, data); } /// Enables the Transmit Interrupt. /// /// The relevant UARTx IRQ will fire when there is space in the transmit FIFO. pub fn enable_tx_interrupt(&mut self) { - enable_tx_interrupt(self.device) + enable_tx_interrupt(&self.device) } /// Disables the Transmit Interrupt. pub fn disable_tx_interrupt(&mut self) { - disable_tx_interrupt(self.device) + disable_tx_interrupt(&self.device) } } @@ -164,7 +164,7 @@ impl> Write for Writer { } fn flush(&mut self) -> nb::Result<(), Self::Error> { - transmit_flushed(self.device) + transmit_flushed(&self.device) } } @@ -184,7 +184,7 @@ impl> eh1::nb::Write for Writer { } fn flush(&mut self) -> nb::Result<(), Self::Error> { - transmit_flushed(self.device).map_err(|e| match e { + transmit_flushed(&self.device).map_err(|e| match e { WouldBlock => WouldBlock, Other(v) => match v {}, }) From f67b650bb38044ff009c7bbabc510de90eab4910 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 18 Mar 2022 10:57:45 +0100 Subject: [PATCH 07/17] Remove some unused fields from UartPeripheral and Reader (#315) * Remove unused field `effective_baudrate` from uart code * Remove unused field `config` from uart code --- rp2040-hal/src/uart/peripheral.rs | 16 +--------------- rp2040-hal/src/uart/reader.rs | 5 +---- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index 9740bef..878fb0c 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -23,8 +23,6 @@ pub struct UartPeripheral> { device: D, _state: S, pins: P, - config: UartConfig, - effective_baudrate: Baud, } impl> UartPeripheral { @@ -32,8 +30,6 @@ impl> UartPeripheral { UartPeripheral { device: self.device, pins: self.pins, - config: self.config, - effective_baudrate: self.effective_baudrate, _state: state, } } @@ -54,8 +50,6 @@ impl> UartPeripheral { device, _state: Disabled, pins, - config: common_configs::_9600_8_N_1, // placeholder - effective_baudrate: Baud(0), } } @@ -66,7 +60,7 @@ impl> UartPeripheral { frequency: Hertz, ) -> Result, Error> { let (mut device, pins) = self.free(); - let effective_baudrate = configure_baudrate(&mut device, &config.baudrate, &frequency)?; + configure_baudrate(&mut device, &config.baudrate, &frequency)?; device.uartlcr_h.write(|w| { // FIFOs are enabled @@ -94,9 +88,7 @@ impl> UartPeripheral { Ok(UartPeripheral { device, - config, pins, - effective_baudrate, _state: Enabled, }) } @@ -193,8 +185,6 @@ impl> UartPeripheral { device: reader.device, _state: Enabled, pins: reader.pins, - config: reader.config, - effective_baudrate: reader.effective_baudrate, } } } @@ -205,8 +195,6 @@ impl> UartPeripheral { let reader = Reader { device: self.device, pins: self.pins, - config: self.config, - effective_baudrate: self.effective_baudrate, }; // Safety: reader and writer will never write to the same address let device_copy = unsafe { Peripherals::steal().UART0 }; @@ -225,8 +213,6 @@ impl> UartPeripheral { let reader = Reader { device: self.device, pins: self.pins, - config: self.config, - effective_baudrate: self.effective_baudrate, }; // Safety: reader and writer will never write to the same address let device_copy = unsafe { Peripherals::steal().UART1 }; diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index 78b8702..e8ab935 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -2,11 +2,10 @@ //! //! This module is for receiving data with a UART. -use super::{UartConfig, UartDevice, ValidUartPinout}; +use super::{UartDevice, ValidUartPinout}; use rp2040_pac::uart0::RegisterBlock; use embedded_hal::serial::Read; -use embedded_time::rate::Baud; use nb::Error::*; #[cfg(feature = "eh1_0_alpha")] @@ -167,8 +166,6 @@ pub(crate) fn read_full_blocking( pub struct Reader> { pub(super) device: D, pub(super) pins: P, - pub(super) config: UartConfig, - pub(super) effective_baudrate: Baud, } impl> Reader { From b8ef969d927e9f85746d1ec3092c3c0b69482c1a Mon Sep 17 00:00:00 2001 From: Derek Hageman Date: Sun, 20 Feb 2022 10:26:58 -0700 Subject: [PATCH 08/17] Generate intrinsic aliases directly Using the full module structure generated by the intrinsics macro interacts oddly with inlining on some optimization levels, causing a duplicate identical function body to be generated. This doesn't affect performance, but it wastes space, so just declare the alias directly which seems to cause the symbol to be aliased as it should be. --- rp2040-hal/src/intrinsics.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rp2040-hal/src/intrinsics.rs b/rp2040-hal/src/intrinsics.rs index dbb67a9..5b13247 100644 --- a/rp2040-hal/src/intrinsics.rs +++ b/rp2040-hal/src/intrinsics.rs @@ -13,9 +13,10 @@ macro_rules! intrinsics_aliases { $($rest:ident)* ) => { #[cfg(all(target_arch = "arm", not(feature = "disable-intrinsics")))] - intrinsics! { - extern $abi fn $alias( $($argname: $ty),* ) -> $ret { - $name($($argname),*) + mod $alias { + #[no_mangle] + pub extern $abi fn $alias( $($argname: $ty),* ) -> $ret { + super::$name($($argname),*) } } @@ -31,9 +32,10 @@ macro_rules! intrinsics_aliases { $($rest:ident)* ) => { #[cfg(all(target_arch = "arm", not(feature = "disable-intrinsics")))] - intrinsics! { + mod $alias { + #[no_mangle] unsafe extern $abi fn $alias( $($argname: $ty),* ) -> $ret { - $name($($argname),*) + super::$name($($argname),*) } } From a15c109e8da2ae69dc138aafe0f10d16d341c38e Mon Sep 17 00:00:00 2001 From: Derek Hageman Date: Sat, 19 Feb 2022 16:22:08 -0700 Subject: [PATCH 09/17] Change hardware divider results structure order Putting the quotient first makes the compiler emit slightly better code by putting the quotient in r0 which is generally what the intrinsics want. --- rp2040-hal/src/sio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rp2040-hal/src/sio.rs b/rp2040-hal/src/sio.rs index a2f769f..367c55d 100644 --- a/rp2040-hal/src/sio.rs +++ b/rp2040-hal/src/sio.rs @@ -43,10 +43,10 @@ pub struct HwDivider { /// Result of divide/modulo operation pub struct DivResult { - /// The remainder of divide/modulo operation - pub remainder: T, /// The quotient of divide/modulo operation pub quotient: T, + /// The remainder of divide/modulo operation + pub remainder: T, } /// Struct containing ownership markers for managing ownership of the SIO registers. From f9d2610fff381b44f3358a709188d657f2f11457 Mon Sep 17 00:00:00 2001 From: Derek Hageman Date: Sat, 19 Feb 2022 19:17:38 -0700 Subject: [PATCH 10/17] Use direct assembler calls for the divider Convert the hardware divider to optimized assembler. --- rp2040-hal/src/float/div.rs | 71 ++++++++++- rp2040-hal/src/sio.rs | 234 ++++++++++++++++++++++-------------- 2 files changed, 210 insertions(+), 95 deletions(-) diff --git a/rp2040-hal/src/float/div.rs b/rp2040-hal/src/float/div.rs index d0d1e2f..30f3532 100644 --- a/rp2040-hal/src/float/div.rs +++ b/rp2040-hal/src/float/div.rs @@ -1,6 +1,71 @@ use super::Float; use crate::rom_data; -use crate::sio::save_divider; + +// Make sure this stays as a separate call, because when it's inlined the +// compiler will move the save of the registers used to contain the divider +// state into the function prologue. That save and restore (push/pop) takes +// longer than the actual division, so doing it in the common case where +// they are not required wastes a lot of time. +#[inline(never)] +#[cold] +fn save_divider_and_call(f: F) -> R +where + F: FnOnce() -> R, +{ + let sio = unsafe { &(*pac::SIO::ptr()) }; + + // Since we can't save the signed-ness of the calculation, we have to make + // sure that there's at least an 8 cycle delay before we read the result. + // The Pico SDK ensures this by using a 6 cycle push and two 1 cycle reads. + // Since we can't be sure the Rust implementation will optimize to the same, + // just use an explicit wait. + while !sio.div_csr.read().ready().bit() {} + + // Read the quotient last, since that's what clears the dirty flag + let dividend = sio.div_udividend.read().bits(); + let divisor = sio.div_udivisor.read().bits(); + let remainder = sio.div_remainder.read().bits(); + let quotient = sio.div_quotient.read().bits(); + + // If we get interrupted here (before a write sets the DIRTY flag) its fine, since + // we have the full state, so the interruptor doesn't have to restore it. Once the + // write happens and the DIRTY flag is set, the interruptor becomes responsible for + // restoring our state. + let result = f(); + + // If we are interrupted here, then the interruptor will start an incorrect calculation + // using a wrong divisor, but we'll restore the divisor and result ourselves correctly. + // This sets DIRTY, so any interruptor will save the state. + sio.div_udividend.write(|w| unsafe { w.bits(dividend) }); + // If we are interrupted here, the the interruptor may start the calculation using + // incorrectly signed inputs, but we'll restore the result ourselves. + // This sets DIRTY, so any interruptor will save the state. + sio.div_udivisor.write(|w| unsafe { w.bits(divisor) }); + // If we are interrupted here, the interruptor will have restored everything but the + // quotient may be wrongly signed. If the calculation started by the above writes is + // still ongoing it is stopped, so it won't replace the result we're restoring. + // DIRTY and READY set, but only DIRTY matters to make the interruptor save the state. + sio.div_remainder.write(|w| unsafe { w.bits(remainder) }); + // State fully restored after the quotient write. This sets both DIRTY and READY, so + // whatever we may have interrupted can read the result. + sio.div_quotient.write(|w| unsafe { w.bits(quotient) }); + + result +} + +fn save_divider(f: F) -> R +where + F: FnOnce() -> R, +{ + let sio = unsafe { &(*pac::SIO::ptr()) }; + if !sio.div_csr.read().dirty().bit() { + // Not dirty, so nothing is waiting for the calculation. So we can just + // issue it directly without a save/restore. + f() + } else { + save_divider_and_call(f) + } +} trait ROMDiv { fn rom_div(self, b: Self) -> Self; @@ -9,14 +74,14 @@ trait ROMDiv { impl ROMDiv for f32 { fn rom_div(self, b: Self) -> Self { // ROM implementation uses the hardware divider, so we have to save it - save_divider(|_sio| rom_data::float_funcs::fdiv(self, b)) + save_divider(|| rom_data::float_funcs::fdiv(self, b)) } } impl ROMDiv for f64 { fn rom_div(self, b: Self) -> Self { // ROM implementation uses the hardware divider, so we have to save it - save_divider(|_sio| rom_data::double_funcs::ddiv(self, b)) + save_divider(|| rom_data::double_funcs::ddiv(self, b)) } } diff --git a/rp2040-hal/src/sio.rs b/rp2040-hal/src/sio.rs index 367c55d..f3bef82 100644 --- a/rp2040-hal/src/sio.rs +++ b/rp2040-hal/src/sio.rs @@ -171,107 +171,159 @@ impl SioFifo { } } -pub(crate) fn save_divider(f: F) -> R -where - F: FnOnce(&pac::sio::RegisterBlock) -> R, -{ - let sio = unsafe { &(*pac::SIO::ptr()) }; - if !sio.div_csr.read().dirty().bit() { - // Not dirty, so nothing is waiting for the calculation. So we can just - // issue it directly without a save/restore. - f(sio) - } else { - // Since we can't save the signed-ness of the calculation, we have to make - // sure that there's at least an 8 cycle delay before we read the result. - // The Pico SDK ensures this by using a 6 cycle push and two 1 cycle reads. - // Since we can't be sure the Rust implementation will optimize to the same, - // just use an explicit wait. - while !sio.div_csr.read().ready().bit() {} +// This takes advantage of how AAPCS defines a 64-bit return on 32-bit registers +// by packing it into r0[0:31] and r1[32:63]. So all we need to do is put +// the remainder in the high order 32 bits of a 64 bit result. We can also +// alias the division operators to these for a similar reason r0 is the +// result either way and r1 a scratch register, so the caller can't assume it +// retains the argument value. +#[cfg(target_arch = "arm")] +core::arch::global_asm!( + ".macro hwdivider_head", + "ldr r2, =(0xd0000000)", // SIO_BASE + // Check the DIRTY state of the divider by shifting it into the C + // status bit. + "ldr r3, [r2, #0x078]", // DIV_CSR + "lsrs r3, #2", // DIRTY = 1, so shift 2 down + // We only need to save the state when DIRTY, otherwise we can just do the + // division directly. + "bcs 2f", + "1:", + // Do the actual division now, we're either not DIRTY, or we've saved the + // state and branched back here so it's safe now. + ".endm", + ".macro hwdivider_tail", + // 8 cycle delay to wait for the result. Each branch takes two cycles + // and fits into a 2-byte Thumb instruction, so this is smaller than + // 8 NOPs. + "b 3f", + "3: b 3f", + "3: b 3f", + "3: b 3f", + "3:", + // Read the quotient last, since that's what clears the dirty flag. + "ldr r1, [r2, #0x074]", // DIV_REMAINDER + "ldr r0, [r2, #0x070]", // DIV_QUOTIENT + // Either return to the caller or back to the state restore. + "bx lr", + "2:", + // Since we can't save the signed-ness of the calculation, we have to make + // sure that there's at least an 8 cycle delay before we read the result. + // The push takes 5 cycles, and we've already spent at least 7 checking + // the DIRTY state to get here. + "push {{r4-r6, lr}}", + // Read the quotient last, since that's what clears the dirty flag. + "ldr r3, [r2, #0x060]", // DIV_UDIVIDEND + "ldr r4, [r2, #0x064]", // DIV_UDIVISOR + "ldr r5, [r2, #0x074]", // DIV_REMAINDER + "ldr r6, [r2, #0x070]", // DIV_QUOTIENT + // If we get interrupted here (before a write sets the DIRTY flag) it's + // fine, since we have the full state, so the interruptor doesn't have to + // restore it. Once the write happens and the DIRTY flag is set, the + // interruptor becomes responsible for restoring our state. + "bl 1b", + // If we are interrupted here, then the interruptor will start an incorrect + // calculation using a wrong divisor, but we'll restore the divisor and + // result ourselves correctly. This sets DIRTY, so any interruptor will + // save the state. + "str r3, [r2, #0x060]", // DIV_UDIVIDEND + // If we are interrupted here, the the interruptor may start the + // calculation using incorrectly signed inputs, but we'll restore the + // result ourselves. This sets DIRTY, so any interruptor will save the + // state. + "str r4, [r2, #0x064]", // DIV_UDIVISOR + // If we are interrupted here, the interruptor will have restored + // everything but the quotient may be wrongly signed. If the calculation + // started by the above writes is still ongoing it is stopped, so it won't + // replace the result we're restoring. DIRTY and READY set, but only + // DIRTY matters to make the interruptor save the state. + "str r5, [r2, #0x074]", // DIV_REMAINDER + // State fully restored after the quotient write. This sets both DIRTY + // and READY, so whatever we may have interrupted can read the result. + "str r6, [r2, #0x070]", // DIV_QUOTIENT + "pop {{r4-r6, pc}}", + ".endm", +); - // Read the quotient last, since that's what clears the dirty flag - let dividend = sio.div_udividend.read().bits(); - let divisor = sio.div_udivisor.read().bits(); - let remainder = sio.div_remainder.read().bits(); - let quotient = sio.div_quotient.read().bits(); +macro_rules! division_function { + ( + $name:ident $($intrinsic:ident)* ( $argty:ty ) { + $($begin:literal),+ + } + ) => { + #[cfg(all(target_arch = "arm", not(feature = "disable-intrinsics")))] + core::arch::global_asm!( + // Mangle the name slightly, since this is a global symbol. + concat!(".global _rphal_", stringify!($name)), + concat!(".type _rphal_", stringify!($name), ", %function"), + ".align 2", + concat!("_rphal_", stringify!($name), ":"), + $( + concat!(".global ", stringify!($intrinsic)), + concat!(".type ", stringify!($intrinsic), ", %function"), + concat!(stringify!($intrinsic), ":"), + )* - // If we get interrupted here (before a write sets the DIRTY flag) its fine, since - // we have the full state, so the interruptor doesn't have to restore it. Once the - // write happens and the DIRTY flag is set, the interruptor becomes responsible for - // restoring our state. - let result = f(sio); + "hwdivider_head", + $($begin),+ , + "hwdivider_tail", + ); - // If we are interrupted here, then the interruptor will start an incorrect calculation - // using a wrong divisor, but we'll restore the divisor and result ourselves correctly. - // This sets DIRTY, so any interruptor will save the state. - sio.div_udividend.write(|w| unsafe { w.bits(dividend) }); - // If we are interrupted here, the the interruptor may start the calculation using - // incorrectly signed inputs, but we'll restore the result ourselves. - // This sets DIRTY, so any interruptor will save the state. - sio.div_udivisor.write(|w| unsafe { w.bits(divisor) }); - // If we are interrupted here, the interruptor will have restored everything but the - // quotient may be wrongly signed. If the calculation started by the above writes is - // still ongoing it is stopped, so it won't replace the result we're restoring. - // DIRTY and READY set, but only DIRTY matters to make the interruptor save the state. - sio.div_remainder.write(|w| unsafe { w.bits(remainder) }); - // State fully restored after the quotient write. This sets both DIRTY and READY, so - // whatever we may have interrupted can read the result. - sio.div_quotient.write(|w| unsafe { w.bits(quotient) }); + #[cfg(all(target_arch = "arm", feature = "disable-intrinsics"))] + core::arch::global_asm!( + // Mangle the name slightly, since this is a global symbol. + concat!(".global _rphal_", stringify!($name)), + concat!(".type _rphal_", stringify!($name), ", %function"), + ".align 2", + concat!("_rphal_", stringify!($name), ":"), - result + "hwdivider_head", + $($begin),+ , + "hwdivider_tail", + ); + + #[cfg(target_arch = "arm")] + extern "aapcs" { + // Connect a local name to global symbol above through FFI. + #[link_name = concat!("_rphal_", stringify!($name)) ] + fn $name(n: $argty, d: $argty) -> u64; + } + + #[cfg(not(target_arch = "arm"))] + #[allow(unused_variables)] + unsafe fn $name(n: $argty, d: $argty) -> u64 { 0 } + }; +} + +division_function! { + unsigned_divmod __aeabi_uidivmod __aeabi_uidiv ( u32 ) { + "str r0, [r2, #0x060]", // DIV_UDIVIDEND + "str r1, [r2, #0x064]" // DIV_UDIVISOR } } -// Don't use cortex_m::asm::delay(8) because that ends up delaying 15 cycles -// on Cortex-M0. Each iteration of the inner loop is 3 cycles and it adds -// one extra iteration. -#[inline(always)] -fn divider_delay() { - cortex_m::asm::nop(); - cortex_m::asm::nop(); - cortex_m::asm::nop(); - cortex_m::asm::nop(); - cortex_m::asm::nop(); - cortex_m::asm::nop(); - cortex_m::asm::nop(); - cortex_m::asm::nop(); +division_function! { + signed_divmod __aeabi_idivmod __aeabi_idiv ( i32 ) { + "str r0, [r2, #0x068]", // DIV_SDIVIDEND + "str r1, [r2, #0x06c]" // DIV_SDIVISOR + } } -fn divider_unsigned(dividend: u32, divisor: u32) -> DivResult { - save_divider(|sio| { - sio.div_udividend.write(|w| unsafe { w.bits(dividend) }); - sio.div_udivisor.write(|w| unsafe { w.bits(divisor) }); - - divider_delay(); - - // Note: quotient must be read last - let remainder = sio.div_remainder.read().bits(); - let quotient = sio.div_quotient.read().bits(); - - DivResult { - remainder, - quotient, - } - }) +fn divider_unsigned(n: u32, d: u32) -> DivResult { + let packed = unsafe { unsigned_divmod(n, d) }; + DivResult { + quotient: packed as u32, + remainder: (packed >> 32) as u32, + } } -fn divider_signed(dividend: i32, divisor: i32) -> DivResult { - save_divider(|sio| { - sio.div_sdividend - .write(|w| unsafe { w.bits(dividend as u32) }); - sio.div_sdivisor - .write(|w| unsafe { w.bits(divisor as u32) }); - - divider_delay(); - - // Note: quotient must be read last - let remainder = sio.div_remainder.read().bits() as i32; - let quotient = sio.div_quotient.read().bits() as i32; - - DivResult { - remainder, - quotient, - } - }) +fn divider_signed(n: i32, d: i32) -> DivResult { + let packed = unsafe { signed_divmod(n, d) }; + // Double casts to avoid sign extension + DivResult { + quotient: packed as u32 as i32, + remainder: (packed >> 32) as u32 as i32, + } } impl HwDivider { @@ -287,7 +339,6 @@ impl HwDivider { } intrinsics! { - #[aeabi = __aeabi_uidiv] extern "C" fn __udivsi3(n: u32, d: u32) -> u32 { divider_unsigned(n, d).quotient } @@ -304,7 +355,6 @@ intrinsics! { quo_rem.quotient } - #[aeabi = __aeabi_idiv] extern "C" fn __divsi3(n: i32, d: i32) -> i32 { divider_signed(n, d).quotient } From 3d8f66df788b0dad5740936cdc0f7bc5edef96b3 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sun, 10 Apr 2022 22:21:40 +1000 Subject: [PATCH 11/17] Provide an unsafe function for resetting all spinlocks --- rp2040-hal/src/sio.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rp2040-hal/src/sio.rs b/rp2040-hal/src/sio.rs index f3bef82..b841e6d 100644 --- a/rp2040-hal/src/sio.rs +++ b/rp2040-hal/src/sio.rs @@ -648,3 +648,22 @@ pub fn spinlock_state() -> [bool; 32] { } result } + +/// Free all spinlocks, regardless of their current status +/// +/// RP2040 does not release all spinlocks on reset. +/// The C SDK clears these all during entry, and so do we if you call hal::entry! +/// But if someone is using the default cortex-m entry they risk hitting deadlocks so provide *something* to help out +/// +/// # Safety +/// Where possible, you should use the hal::entry macro attribute on main instead of this. +/// You should call this as soon as possible after reset - preferably as the first entry in fn main(), before *ANY* use of spinlocks, atomics, or critical_section +pub unsafe fn spinlock_reset() { + // Using raw pointers to avoid taking peripherals accidently at startup + const SIO_BASE: u32 = 0xd0000000; + const SPINLOCK0_PTR: *mut u32 = (SIO_BASE + 0x100) as *mut u32; + const SPINLOCK_COUNT: usize = 32; + for i in 0..SPINLOCK_COUNT { + SPINLOCK0_PTR.wrapping_add(i).write_volatile(1); + } +} From e9a4f7e40b46f28f4dab29406a3d9bd342eb59a9 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Mon, 11 Apr 2022 19:52:14 +1000 Subject: [PATCH 12/17] Update rtic example to reset spinlocks in init --- boards/rp-pico/examples/pico_rtic.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boards/rp-pico/examples/pico_rtic.rs b/boards/rp-pico/examples/pico_rtic.rs index 721340c..7db9aee 100644 --- a/boards/rp-pico/examples/pico_rtic.rs +++ b/boards/rp-pico/examples/pico_rtic.rs @@ -27,6 +27,11 @@ mod app { #[init] fn init(c: init::Context) -> (Shared, Local, init::Monotonics) { + // Soft-reset does not release the hardware spinlocks + // Release them now to avoid a deadlock after debug or watchdog reset + unsafe { + hal::sio::spinlock_reset(); + } let mut resets = c.device.RESETS; let mut watchdog = Watchdog::new(c.device.WATCHDOG); let _clocks = init_clocks_and_plls( From 977bc2732a5871cb5c09bf6842de6a016cf1c9b6 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Sun, 17 Apr 2022 22:39:31 +0100 Subject: [PATCH 13/17] Remove unmaintained implementation async i2c. --- rp2040-hal/CHANGELOG.md | 4 + rp2040-hal/Cargo.toml | 14 -- rp2040-hal/src/i2c/controller.rs | 3 - .../src/i2c/controller/embassy_support.rs | 219 ------------------ rp2040-hal/src/lib.rs | 2 - 5 files changed, 4 insertions(+), 238 deletions(-) delete mode 100644 rp2040-hal/src/i2c/controller/embassy_support.rs diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index 2759d75..9bd6e45 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed + +- removed i2c embassy driver prototype + ## [0.4.0] - 2022-03-09 ### Added diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index ea0e1c3..6ea6523 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -30,17 +30,6 @@ critical-section = { version = "0.2.4", features = ["custom-impl"] } futures = { version = "0.3", default-features = false, optional = true } chrono = { version = "0.4", default-features = false, optional = true } -# namespaced features will let us use "dep:embassy-traits" in the features rather than using this -# trick of renaming the crate. -# -# This is commented out so that we can publish to crates.io -# -# [dependencies.embassy_traits] -# git = "https://github.com/embassy-rs/embassy" -# rev = "6d6e6f55b8a9ecd38b5a6d3bb11f74b2654afdeb" -# package = "embassy-traits" -# optional = true - [dev-dependencies] cortex-m-rt = "0.7" panic-halt = "0.2.0" @@ -51,9 +40,6 @@ dht-sensor = "0.2.1" [features] rt = ["rp2040-pac/rt"] -# This is commented out so that we can publish to crates.io -# -# embassy-traits = ["embassy_traits", "futures"] alloc = [] rom-func-cache = [] disable-intrinsics = [] diff --git a/rp2040-hal/src/i2c/controller.rs b/rp2040-hal/src/i2c/controller.rs index bd4ac7c..0098c9b 100644 --- a/rp2040-hal/src/i2c/controller.rs +++ b/rp2040-hal/src/i2c/controller.rs @@ -14,9 +14,6 @@ use eh1_0_alpha::i2c as eh1; use super::{i2c_reserved_addr, Controller, Error, SclPin, SdaPin, I2C}; -#[cfg(feature = "embassy-traits")] -mod embassy_support; - impl, Sda: PinId + BankPinId, Scl: PinId + BankPinId> I2C, Pin), Controller> { diff --git a/rp2040-hal/src/i2c/controller/embassy_support.rs b/rp2040-hal/src/i2c/controller/embassy_support.rs deleted file mode 100644 index 4bfb2f1..0000000 --- a/rp2040-hal/src/i2c/controller/embassy_support.rs +++ /dev/null @@ -1,219 +0,0 @@ -use core::{future::Future, iter::Peekable, ops::Deref, task::Poll}; - -use super::{Block, Controller, Error, I2C}; - -impl, PINS> I2C { - async fn non_blocking_read_internal<'a, U: Iterator + 'a>( - &mut self, - mut buffer: Peekable, - ) -> Result<(), Error> { - let mut first = true; - while let Some(byte) = buffer.next() { - let last = buffer.peek().is_none(); - - // wait until there is space in the FIFO to write the next byte - block_on(|| { - if self.tx_fifo_full() { - Poll::Pending - } else { - Poll::Ready(()) - } - }) - .await; - - self.i2c.ic_data_cmd.write(|w| { - if first { - w.restart().enable(); - first = false; - } else { - w.restart().disable(); - } - - if last { - w.stop().enable(); - } else { - w.stop().disable(); - } - - w.cmd().read() - }); - - block_on(|| { - if let Some(abort_reason) = self.read_and_clear_abort_reason() { - Poll::Ready(Err(Error::Abort(abort_reason))) - } else if self.i2c.ic_rxflr.read().bits() != 0 { - Poll::Ready(Ok(())) - } else { - Poll::Pending - } - }) - .await?; - - *byte = self.i2c.ic_data_cmd.read().dat().bits(); - } - - Ok(()) - } - - async fn non_blocking_write_internal( - &mut self, - bytes: impl IntoIterator, - do_stop: bool, - ) -> Result<(), Error> { - let mut bytes = bytes.into_iter().peekable(); - while let Some(byte) = bytes.next() { - let last = bytes.peek().is_none(); - - self.i2c.ic_data_cmd.write(|w| { - if do_stop && last { - w.stop().enable(); - } else { - w.stop().disable(); - } - unsafe { w.dat().bits(byte) } - }); - - // Wait until the transmission of the address/data from the internal - // shift register has completed. For this to function correctly, the - // TX_EMPTY_CTRL flag in IC_CON must be set. The TX_EMPTY_CTRL flag - // was set in i2c_init. - block_on(|| { - if self.i2c.ic_raw_intr_stat.read().tx_empty().is_inactive() { - Poll::Pending - } else { - Poll::Ready(()) - } - }) - .await; - - let abort_reason = self.read_and_clear_abort_reason(); - - if abort_reason.is_some() || (do_stop && last) { - // If the transaction was aborted or if it completed - // successfully wait until the STOP condition has occured. - - block_on(|| { - if self.i2c.ic_raw_intr_stat.read().stop_det().is_inactive() { - Poll::Pending - } else { - Poll::Ready(()) - } - }) - .await; - - self.i2c.ic_clr_stop_det.read().clr_stop_det(); - } - - // Note the hardware issues a STOP automatically on an abort condition. - // Note also the hardware clears RX FIFO as well as TX on abort, - // ecause we set hwparam IC_AVOID_RX_FIFO_FLUSH_ON_TX_ABRT to 0. - if let Some(abort_reason) = abort_reason { - return Err(Error::Abort(abort_reason)); - } - } - - Ok(()) - } -} -async fn block_on Poll, T>(mut f: F) -> T { - futures::future::poll_fn(|cx| { - // always ready to scan - cx.waker().wake_by_ref(); - - f() - }) - .await -} - -impl embassy_traits::i2c::I2c for I2C -where - T: Deref, - A: embassy_traits::i2c::AddressMode + 'static + Into, -{ - type Error = Error; - - #[rustfmt::skip] - type WriteFuture<'a> - where - Self: 'a = impl Future> + 'a; - - #[rustfmt::skip] - type ReadFuture<'a> - where - Self: 'a = impl Future> + 'a; - - #[rustfmt::skip] - type WriteReadFuture<'a> - where - Self: 'a = impl Future> + 'a; - - fn read<'a>(&'a mut self, address: A, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { - let mut buffer = buffer.iter_mut().peekable(); - let addr: u16 = address.into(); - - async move { - self.setup(addr); - - Self::validate(addr, None, Some(buffer.peek().is_none()))?; - - self.non_blocking_read_internal(buffer).await - } - } - - fn write<'a>(&'a mut self, address: A, bytes: &'a [u8]) -> Self::WriteFuture<'a> { - async move { - let addr: u16 = address.into(); - Self::validate(addr, Some(bytes.is_empty()), None)?; - self.setup(addr); - - self.non_blocking_write_internal(bytes.iter().cloned(), true) - .await - } - } - - fn write_read<'a>( - &'a mut self, - address: A, - bytes: &'a [u8], - buffer: &'a mut [u8], - ) -> Self::WriteReadFuture<'a> { - async move { - let addr: u16 = address.into(); - Self::validate(addr, Some(bytes.is_empty()), Some(buffer.is_empty()))?; - self.setup(addr); - - self.non_blocking_write_internal(bytes.iter().cloned(), false) - .await?; - self.non_blocking_read_internal(buffer.iter_mut().peekable()) - .await - } - } -} -impl embassy_traits::i2c::WriteIter for I2C -where - T: Deref, - A: embassy_traits::i2c::AddressMode + 'static + Into, -{ - type Error = Error; - - #[rustfmt::skip] - type WriteIterFuture<'a, U> - where - U: 'a + IntoIterator, - Self: 'a = impl Future> + 'a; - - fn write_iter<'a, U>(&'a mut self, address: A, bytes: U) -> Self::WriteIterFuture<'a, U> - where - U: IntoIterator + 'a, - { - let addr: u16 = address.into(); - async move { - let mut bytes = bytes.into_iter().peekable(); - Self::validate(addr, Some(bytes.peek().is_none()), None)?; - - self.setup(addr); - - self.non_blocking_write_internal(bytes, true).await - } - } -} diff --git a/rp2040-hal/src/lib.rs b/rp2040-hal/src/lib.rs index 3153868..6e2aa8f 100644 --- a/rp2040-hal/src/lib.rs +++ b/rp2040-hal/src/lib.rs @@ -5,8 +5,6 @@ #![warn(missing_docs)] #![no_std] -#![cfg_attr(feature = "embassy-traits", feature(generic_associated_types))] -#![cfg_attr(feature = "embassy-traits", feature(type_alias_impl_trait))] extern crate cortex_m; extern crate embedded_hal as hal; From bb07402fc91e24a88b3aef38e9ab8e22a5ecdfa7 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Sun, 17 Apr 2022 23:03:11 +0100 Subject: [PATCH 14/17] Abstract alarms --- boards/rp-pico/examples/pico_rtic.rs | 2 +- rp2040-hal/src/timer.rs | 45 ++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/boards/rp-pico/examples/pico_rtic.rs b/boards/rp-pico/examples/pico_rtic.rs index 7db9aee..05f29ed 100644 --- a/boards/rp-pico/examples/pico_rtic.rs +++ b/boards/rp-pico/examples/pico_rtic.rs @@ -9,7 +9,7 @@ mod app { use embedded_hal::digital::v2::OutputPin; use embedded_time::duration::Extensions; use rp_pico::{ - hal::{self, clocks::init_clocks_and_plls, watchdog::Watchdog, Sio}, + hal::{self, clocks::init_clocks_and_plls, timer::Alarm, watchdog::Watchdog, Sio}, XOSC_CRYSTAL_FREQ, }; diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index ed912f7..57b3033 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -148,18 +148,51 @@ impl embedded_hal::timer::Cancel for CountDown<'_> { } } +/// Alarm abstraction. +pub trait Alarm { + /// Clear the interrupt flag. + /// + /// The interrupt is unable to trigger a 2nd time until this interrupt is cleared. + fn clear_interrupt(&mut self); + + /// Enable this alarm to trigger an interrupt. + /// + /// After this interrupt is triggered, make sure to clear the interrupt with [clear_interrupt]. + /// + /// [clear_interrupt]: #method.clear_interrupt + fn enable_interrupt(&mut self); + + /// Disable this alarm, preventing it from triggering an interrupt. + fn disable_interrupt(&mut self); + + /// Schedule the alarm to be finished after `countdown`. If [enable_interrupt] is called, + /// this will trigger interrupt whenever this time elapses. + /// + /// The RP2040 has been observed to take a little while to schedule an alarm. For this + /// reason, the minimum time that this function accepts is `10.microseconds()` + /// + /// [enable_interrupt]: #method.enable_interrupt + fn schedule>( + &mut self, + countdown: TIME, + ) -> Result<(), ScheduleAlarmError>; + + /// Return true if this alarm is finished. + fn finished(&self) -> bool; +} + macro_rules! impl_alarm { ($name:ident { rb: $timer_alarm:ident, int: $int_alarm:ident, int_name: $int_name:tt, armed_bit_mask: $armed_bit_mask: expr }) => { /// An alarm that can be used to schedule events in the future. Alarms can also be configured to trigger interrupts. pub struct $name(PhantomData<()>); - impl $name { + impl Alarm for $name { /// Clear the interrupt flag. This should be called after interrupt ` #[doc = $int_name] /// ` is called. /// /// The interrupt is unable to trigger a 2nd time until this interrupt is cleared. - pub fn clear_interrupt(&mut self) { + fn clear_interrupt(&mut self) { // safety: TIMER.intr is a write-clear register, so we can atomically clear our interrupt // by writing its value to this field // Only one instance of this alarm index can exist, and only this alarm interacts with this bit @@ -177,7 +210,7 @@ macro_rules! impl_alarm { /// After this interrupt is triggered, make sure to clear the interrupt with [clear_interrupt]. /// /// [clear_interrupt]: #method.clear_interrupt - pub fn enable_interrupt(&mut self) { + fn enable_interrupt(&mut self) { // safety: using the atomic set alias means we can atomically set our interrupt enable bit. // Only one instance of this alarm can exist, and only this alarm interacts with this bit // of the TIMER.inte register @@ -189,7 +222,7 @@ macro_rules! impl_alarm { } /// Disable this alarm, preventing it from triggering an interrupt. - pub fn disable_interrupt(&mut self) { + fn disable_interrupt(&mut self) { // safety: using the atomic set alias means we can atomically clear our interrupt enable bit. // Only one instance of this alarm can exist, and only this alarm interacts with this bit // of the TIMER.inte register @@ -207,7 +240,7 @@ macro_rules! impl_alarm { /// The RP2040 has been observed to take a little while to schedule an alarm. For this reason, the minimum time that this function accepts is `10.microseconds()` /// /// [enable_interrupt]: #method.enable_interrupt - pub fn schedule>( + fn schedule>( &mut self, countdown: TIME, ) -> Result<(), ScheduleAlarmError> { @@ -235,7 +268,7 @@ macro_rules! impl_alarm { } /// Return true if this alarm is finished. - pub fn finished(&self) -> bool { + fn finished(&self) -> bool { // safety: This is a read action and should not have any UB let bits: u32 = unsafe { &*TIMER::ptr() }.armed.read().bits(); (bits & $armed_bit_mask) == 0 From 5f793cde696f05421f73dbfe5b9cc78971a58e64 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Thu, 28 Apr 2022 16:20:35 +0000 Subject: [PATCH 15/17] Add adafruit-macropad_blinky example Also adds const XOSC_CRYSTAL_FREQ = 12_000_000, which is the right value according to https://learn.adafruit.com/assets/103270 Fixes #302 --- boards/adafruit-macropad/Cargo.toml | 4 ++ .../examples/adafruit-macropad_blinky.rs | 57 +++++++++++++++++++ boards/adafruit-macropad/src/lib.rs | 2 + 3 files changed, 63 insertions(+) create mode 100644 boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs diff --git a/boards/adafruit-macropad/Cargo.toml b/boards/adafruit-macropad/Cargo.toml index 9f418bc..8260135 100644 --- a/boards/adafruit-macropad/Cargo.toml +++ b/boards/adafruit-macropad/Cargo.toml @@ -15,6 +15,10 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.4.0"} cortex-m-rt = { version = "0.7", optional = true } +[dev-dependencies] +embedded-time = "0.12.0" +panic-halt= "0.2.0" +embedded-hal ="0.2.5" [features] default = ["rt", "boot2"] diff --git a/boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs b/boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs new file mode 100644 index 0000000..b0c345a --- /dev/null +++ b/boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs @@ -0,0 +1,57 @@ +//! Blinks the LED on a Adafruit MacroPad board +//! +//! This will blink on-board LED. +#![no_std] +#![no_main] + +use adafruit_macropad::{ + hal::{ + clocks::{init_clocks_and_plls, Clock}, + pac, + watchdog::Watchdog, + Sio, + }, + Pins, XOSC_CRYSTAL_FREQ, +}; +use cortex_m_rt::entry; +use embedded_hal::digital::v2::OutputPin; +use embedded_time::rate::*; +use panic_halt as _; + +#[entry] +fn main() -> ! { + let mut pac = pac::Peripherals::take().unwrap(); + let core = pac::CorePeripherals::take().unwrap(); + + let mut watchdog = Watchdog::new(pac.WATCHDOG); + + let clocks = init_clocks_and_plls( + XOSC_CRYSTAL_FREQ, + pac.XOSC, + pac.CLOCKS, + pac.PLL_SYS, + pac.PLL_USB, + &mut pac.RESETS, + &mut watchdog, + ) + .ok() + .unwrap(); + + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + + let sio = Sio::new(pac.SIO); + let pins = Pins::new( + pac.IO_BANK0, + pac.PADS_BANK0, + sio.gpio_bank0, + &mut pac.RESETS, + ); + let mut led_pin = pins.led.into_push_pull_output(); + + loop { + led_pin.set_high().unwrap(); + delay.delay_ms(1500); + led_pin.set_low().unwrap(); + delay.delay_ms(1500); + } +} diff --git a/boards/adafruit-macropad/src/lib.rs b/boards/adafruit-macropad/src/lib.rs index d197432..ac1207b 100644 --- a/boards/adafruit-macropad/src/lib.rs +++ b/boards/adafruit-macropad/src/lib.rs @@ -72,3 +72,5 @@ hal::bsp_pins!( aliases: { FunctionSpi: Miso } }, ); + +pub const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; From 623457a498d3d3d612300cf48912fdd09d7ddffb Mon Sep 17 00:00:00 2001 From: mqy Date: Mon, 18 Apr 2022 18:49:41 +0800 Subject: [PATCH 16/17] fixed typos --- README.md | 6 +++--- boards/adafruit-feather-rp2040/README.md | 6 +++--- boards/adafruit-itsy-bitsy-rp2040/README.md | 6 +++--- .../examples/adafruit_itsy_bitsy_blinky.rs | 2 +- boards/adafruit-kb2040/README.md | 6 +++--- boards/adafruit-macropad/README.md | 6 +++--- boards/adafruit-qt-py-rp2040/README.md | 6 +++--- boards/adafruit-trinkey-qt2040/README.md | 6 +++--- boards/pimoroni-pico-explorer/README.md | 6 +++--- boards/pimoroni-pico-lipo-16mb/README.md | 6 +++--- .../examples/pimoroni_pico_lipo_16mb_blinky.rs | 2 +- boards/pimoroni-tiny2040/README.md | 6 +++--- boards/rp-pico/README.md | 6 +++--- boards/rp-pico/examples/pico_blinky.rs | 2 +- boards/rp-pico/examples/pico_countdown_blinky.rs | 2 +- boards/rp-pico/examples/pico_gpio_in_out.rs | 2 +- boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs | 2 +- boards/rp-pico/examples/pico_i2c_pio.rs | 2 +- boards/rp-pico/examples/pico_pwm_blink.rs | 2 +- boards/rp-pico/examples/pico_spi_sd_card.rs | 4 ++-- boards/rp-pico/examples/pico_uart_irq_buffer.rs | 2 +- boards/rp-pico/examples/pico_uart_irq_echo.rs | 2 +- boards/rp-pico/examples/pico_usb_serial.rs | 2 +- boards/rp-pico/examples/pico_usb_serial_interrupt.rs | 2 +- boards/rp-pico/examples/pico_usb_twitchy_mouse.rs | 2 +- boards/rp-pico/examples/pico_ws2812_led.rs | 2 +- boards/solderparty-rp2040-stamp/README.md | 6 +++--- boards/sparkfun-pro-micro-rp2040/README.md | 6 +++--- rp2040-hal/examples/adc.rs | 2 +- rp2040-hal/examples/blinky.rs | 2 +- rp2040-hal/examples/dht11.rs | 2 +- rp2040-hal/examples/gpio_in_out.rs | 2 +- rp2040-hal/examples/gpio_irq_example.rs | 2 +- rp2040-hal/examples/i2c.rs | 2 +- rp2040-hal/examples/lcd_display.rs | 2 +- rp2040-hal/examples/multicore_fifo_blink.rs | 2 +- rp2040-hal/examples/pwm_blink.rs | 2 +- rp2040-hal/examples/rom_funcs.rs | 2 +- rp2040-hal/examples/spi.rs | 2 +- rp2040-hal/examples/uart.rs | 2 +- rp2040-hal/examples/watchdog.rs | 2 +- rp2040-hal/src/multicore.rs | 2 +- rp2040-hal/src/pio.rs | 2 +- 43 files changed, 70 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 212552e..0615408 100644 --- a/README.md +++ b/README.md @@ -390,9 +390,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/adafruit-feather-rp2040/README.md b/boards/adafruit-feather-rp2040/README.md index 08328b2..51b2779 100644 --- a/boards/adafruit-feather-rp2040/README.md +++ b/boards/adafruit-feather-rp2040/README.md @@ -90,9 +90,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/adafruit-itsy-bitsy-rp2040/README.md b/boards/adafruit-itsy-bitsy-rp2040/README.md index f8a2ae9..1b4a3d3 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/README.md +++ b/boards/adafruit-itsy-bitsy-rp2040/README.md @@ -90,9 +90,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs b/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs index 5350994..4176a8e 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs +++ b/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs @@ -4,7 +4,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/adafruit-kb2040/README.md b/boards/adafruit-kb2040/README.md index 3ebeb7b..c5e0553 100644 --- a/boards/adafruit-kb2040/README.md +++ b/boards/adafruit-kb2040/README.md @@ -86,9 +86,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/adafruit-macropad/README.md b/boards/adafruit-macropad/README.md index df7fbf8..049b78a 100644 --- a/boards/adafruit-macropad/README.md +++ b/boards/adafruit-macropad/README.md @@ -82,9 +82,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/adafruit-qt-py-rp2040/README.md b/boards/adafruit-qt-py-rp2040/README.md index 5db1ae6..5c04a69 100644 --- a/boards/adafruit-qt-py-rp2040/README.md +++ b/boards/adafruit-qt-py-rp2040/README.md @@ -86,9 +86,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/adafruit-trinkey-qt2040/README.md b/boards/adafruit-trinkey-qt2040/README.md index 1b62811..df6f07b 100644 --- a/boards/adafruit-trinkey-qt2040/README.md +++ b/boards/adafruit-trinkey-qt2040/README.md @@ -85,9 +85,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/pimoroni-pico-explorer/README.md b/boards/pimoroni-pico-explorer/README.md index 4d4541c..07d28e7 100644 --- a/boards/pimoroni-pico-explorer/README.md +++ b/boards/pimoroni-pico-explorer/README.md @@ -87,9 +87,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/pimoroni-pico-lipo-16mb/README.md b/boards/pimoroni-pico-lipo-16mb/README.md index c463495..a1146d8 100644 --- a/boards/pimoroni-pico-lipo-16mb/README.md +++ b/boards/pimoroni-pico-lipo-16mb/README.md @@ -88,9 +88,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs b/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs index 9674e9d..9dba727 100644 --- a/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs +++ b/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs @@ -5,7 +5,7 @@ //! This will blink an LED attached to GPIO25, which is the pin the Pico Lipo uses //! for the on-board LED. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/pimoroni-tiny2040/README.md b/boards/pimoroni-tiny2040/README.md index fde9271..d5f075d 100644 --- a/boards/pimoroni-tiny2040/README.md +++ b/boards/pimoroni-tiny2040/README.md @@ -87,9 +87,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/rp-pico/README.md b/boards/rp-pico/README.md index 4a24b82..7e47a04 100644 --- a/boards/rp-pico/README.md +++ b/boards/rp-pico/README.md @@ -129,9 +129,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/rp-pico/examples/pico_blinky.rs b/boards/rp-pico/examples/pico_blinky.rs index 87c2b34..aec90d9 100644 --- a/boards/rp-pico/examples/pico_blinky.rs +++ b/boards/rp-pico/examples/pico_blinky.rs @@ -5,7 +5,7 @@ //! This will blink an LED attached to GP25, which is the pin the Pico uses for //! the on-board LED. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_countdown_blinky.rs b/boards/rp-pico/examples/pico_countdown_blinky.rs index 15a79dd..d968f04 100644 --- a/boards/rp-pico/examples/pico_countdown_blinky.rs +++ b/boards/rp-pico/examples/pico_countdown_blinky.rs @@ -5,7 +5,7 @@ //! This will blink an LED attached to GP25, which is the pin the Pico uses for //! the on-board LED. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_gpio_in_out.rs b/boards/rp-pico/examples/pico_gpio_in_out.rs index fce0686..b0af50d 100644 --- a/boards/rp-pico/examples/pico_gpio_in_out.rs +++ b/boards/rp-pico/examples/pico_gpio_in_out.rs @@ -7,7 +7,7 @@ //! internally by this example. When the button is pressed, the LED will turn //! off. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs b/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs index c3d4fef..b9652de 100644 --- a/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs +++ b/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs @@ -36,7 +36,7 @@ //! - (o) connected lines //! ``` //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_i2c_pio.rs b/boards/rp-pico/examples/pico_i2c_pio.rs index 7552e7a..b4a263c 100644 --- a/boards/rp-pico/examples/pico_i2c_pio.rs +++ b/boards/rp-pico/examples/pico_i2c_pio.rs @@ -6,7 +6,7 @@ //! using the PIO peripheral as an I2C bus controller. //! The pins used for the I2C can be remapped to any other pin available to the PIO0 peripheral. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_pwm_blink.rs b/boards/rp-pico/examples/pico_pwm_blink.rs index 5a0a986..3ed8a0e 100644 --- a/boards/rp-pico/examples/pico_pwm_blink.rs +++ b/boards/rp-pico/examples/pico_pwm_blink.rs @@ -5,7 +5,7 @@ //! This will fade in/out the LED attached to GP25, which is the pin the Pico //! uses for the on-board LED. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_spi_sd_card.rs b/boards/rp-pico/examples/pico_spi_sd_card.rs index 3410dec..28de546 100644 --- a/boards/rp-pico/examples/pico_spi_sd_card.rs +++ b/boards/rp-pico/examples/pico_spi_sd_card.rs @@ -80,14 +80,14 @@ //! //! If there are 5 different error patterns, all with short blinking pulses: //! -//! - **2 short blink (in a loop)**: Block device could not be aquired, either +//! - **2 short blink (in a loop)**: Block device could not be acquired, either //! no SD card is present or some electrical problem. //! - **3 short blink (in a loop)**: Card size could not be retrieved. //! - **4 short blink (in a loop)**: Error getting volume/partition 0. //! - **5 short blink (in a loop)**: Error opening root directory. //! - **6 short blink (in a loop)**: Could not open file 'O.TST'. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_uart_irq_buffer.rs b/boards/rp-pico/examples/pico_uart_irq_buffer.rs index 4166207..63acd4c 100644 --- a/boards/rp-pico/examples/pico_uart_irq_buffer.rs +++ b/boards/rp-pico/examples/pico_uart_irq_buffer.rs @@ -12,7 +12,7 @@ //! * GPIO 1 - UART RX (in to the RP2040) //! * GPIO 25 - An LED we can blink (active high) //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_uart_irq_echo.rs b/boards/rp-pico/examples/pico_uart_irq_echo.rs index 314c5d7..cd143b3 100644 --- a/boards/rp-pico/examples/pico_uart_irq_echo.rs +++ b/boards/rp-pico/examples/pico_uart_irq_echo.rs @@ -10,7 +10,7 @@ //! * GPIO 1 - UART RX (in to the RP2040) //! * GPIO 25 - An LED we can blink (active high) //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_usb_serial.rs b/boards/rp-pico/examples/pico_usb_serial.rs index b28dba2..1f96eac 100644 --- a/boards/rp-pico/examples/pico_usb_serial.rs +++ b/boards/rp-pico/examples/pico_usb_serial.rs @@ -7,7 +7,7 @@ //! ASCII characters are converted to upercase, so you can tell it is working //! and not just local-echo! //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_usb_serial_interrupt.rs b/boards/rp-pico/examples/pico_usb_serial_interrupt.rs index d7e38e5..d039c70 100644 --- a/boards/rp-pico/examples/pico_usb_serial_interrupt.rs +++ b/boards/rp-pico/examples/pico_usb_serial_interrupt.rs @@ -7,7 +7,7 @@ //! ASCII characters are converted to upercase, so you can tell it is working //! and not just local-echo! //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs b/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs index 09818b9..f187416 100644 --- a/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs +++ b/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs @@ -6,7 +6,7 @@ //! It generates movement reports which will twitch the cursor up and down by a //! few pixels, several times a second. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. //! //! This is a port of //! https://github.com/atsamd-rs/atsamd/blob/master/boards/itsybitsy_m0/examples/twitching_usb_mouse.rs diff --git a/boards/rp-pico/examples/pico_ws2812_led.rs b/boards/rp-pico/examples/pico_ws2812_led.rs index cba725b..430b75e 100644 --- a/boards/rp-pico/examples/pico_ws2812_led.rs +++ b/boards/rp-pico/examples/pico_ws2812_led.rs @@ -35,7 +35,7 @@ //! - (o) connected lines //! ``` //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/boards/solderparty-rp2040-stamp/README.md b/boards/solderparty-rp2040-stamp/README.md index feb1318..f6c9700 100644 --- a/boards/solderparty-rp2040-stamp/README.md +++ b/boards/solderparty-rp2040-stamp/README.md @@ -86,9 +86,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/boards/sparkfun-pro-micro-rp2040/README.md b/boards/sparkfun-pro-micro-rp2040/README.md index e0ce5ad..8ec9dde 100644 --- a/boards/sparkfun-pro-micro-rp2040/README.md +++ b/boards/sparkfun-pro-micro-rp2040/README.md @@ -87,9 +87,9 @@ to intervene to uphold that code of conduct. ## License The contents of this repository are dual-licensed under the _MIT OR Apache -2.0_ License. That means you can chose either the MIT licence or the -Apache-2.0 licence when you re-use this code. See `MIT` or `APACHE2.0` for more -information on each specific licence. +2.0_ License. That means you can chose either the MIT license or the +Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more +information on each specific license. Any submissions to this project (e.g. as Pull Requests) must be made available under these terms. diff --git a/rp2040-hal/examples/adc.rs b/rp2040-hal/examples/adc.rs index c848d93..a5ffd1d 100644 --- a/rp2040-hal/examples/adc.rs +++ b/rp2040-hal/examples/adc.rs @@ -5,7 +5,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/blinky.rs b/rp2040-hal/examples/blinky.rs index a9587b8..a2a25f2 100644 --- a/rp2040-hal/examples/blinky.rs +++ b/rp2040-hal/examples/blinky.rs @@ -4,7 +4,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/dht11.rs b/rp2040-hal/examples/dht11.rs index 844d333..31f9dd4 100644 --- a/rp2040-hal/examples/dht11.rs +++ b/rp2040-hal/examples/dht11.rs @@ -7,7 +7,7 @@ //! //! NOTE: The DHT11 driver only works reliably when compiled in release mode. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/gpio_in_out.rs b/rp2040-hal/examples/gpio_in_out.rs index 7905cc8..2703058 100644 --- a/rp2040-hal/examples/gpio_in_out.rs +++ b/rp2040-hal/examples/gpio_in_out.rs @@ -4,7 +4,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/gpio_irq_example.rs b/rp2040-hal/examples/gpio_irq_example.rs index b3adb32..e5a84fd 100644 --- a/rp2040-hal/examples/gpio_irq_example.rs +++ b/rp2040-hal/examples/gpio_irq_example.rs @@ -17,7 +17,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/i2c.rs b/rp2040-hal/examples/i2c.rs index aed8739..1d08fdf 100644 --- a/rp2040-hal/examples/i2c.rs +++ b/rp2040-hal/examples/i2c.rs @@ -4,7 +4,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/lcd_display.rs b/rp2040-hal/examples/lcd_display.rs index 34e67c8..7788bc7 100644 --- a/rp2040-hal/examples/lcd_display.rs +++ b/rp2040-hal/examples/lcd_display.rs @@ -7,7 +7,7 @@ //! It drives the LCD by pushing data out of six GPIO pins. It may need to be //! adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/multicore_fifo_blink.rs b/rp2040-hal/examples/multicore_fifo_blink.rs index 7b305a9..14ed230 100644 --- a/rp2040-hal/examples/multicore_fifo_blink.rs +++ b/rp2040-hal/examples/multicore_fifo_blink.rs @@ -7,7 +7,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/pwm_blink.rs b/rp2040-hal/examples/pwm_blink.rs index 064d999..ee894ec 100644 --- a/rp2040-hal/examples/pwm_blink.rs +++ b/rp2040-hal/examples/pwm_blink.rs @@ -5,7 +5,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/rom_funcs.rs b/rp2040-hal/examples/rom_funcs.rs index 2509ac8..c2624dc 100644 --- a/rp2040-hal/examples/rom_funcs.rs +++ b/rp2040-hal/examples/rom_funcs.rs @@ -4,7 +4,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/spi.rs b/rp2040-hal/examples/spi.rs index 6d41922..e13e222 100644 --- a/rp2040-hal/examples/spi.rs +++ b/rp2040-hal/examples/spi.rs @@ -7,7 +7,7 @@ //! It may need to be adapted to your particular board layout and/or pin //! assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/uart.rs b/rp2040-hal/examples/uart.rs index 7e1cf79..a3ff431 100644 --- a/rp2040-hal/examples/uart.rs +++ b/rp2040-hal/examples/uart.rs @@ -6,7 +6,7 @@ //! It may need to be adapted to your particular board layout and/or pin //! assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/examples/watchdog.rs b/rp2040-hal/examples/watchdog.rs index f72ba56..ecdeff2 100644 --- a/rp2040-hal/examples/watchdog.rs +++ b/rp2040-hal/examples/watchdog.rs @@ -4,7 +4,7 @@ //! //! It may need to be adapted to your particular board layout and/or pin assignment. //! -//! See the `Cargo.toml` file for Copyright and licence details. +//! See the `Cargo.toml` file for Copyright and license details. #![no_std] #![no_main] diff --git a/rp2040-hal/src/multicore.rs b/rp2040-hal/src/multicore.rs index a16b46a..e18ae66 100644 --- a/rp2040-hal/src/multicore.rs +++ b/rp2040-hal/src/multicore.rs @@ -43,7 +43,7 @@ extern crate alloc; pub enum Error { /// Operation is invalid on this core. InvalidCore, - /// Core was unresposive to commands. + /// Core was unresponsive to commands. Unresponsive, } diff --git a/rp2040-hal/src/pio.rs b/rp2040-hal/src/pio.rs index d7a3d01..41a8fcc 100644 --- a/rp2040-hal/src/pio.rs +++ b/rp2040-hal/src/pio.rs @@ -656,7 +656,7 @@ impl StateMachine<(P, SM), Stopped> { } impl StateMachine<(P, SM), State> { - /// Create a group of state machines, which can be started/stopped synchonously + /// Create a group of state machines, which can be started/stopped synchronously pub fn with( self, other_sm: StateMachine<(P, SM2), State>, From 89371912adc7ebd7886ac345de315555ac6e7003 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 29 Apr 2022 08:30:37 +0200 Subject: [PATCH 17/17] Fix typo in rp2040-hal README.md --- rp2040-hal/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rp2040-hal/README.md b/rp2040-hal/README.md index 2bb87f6..9b46007 100644 --- a/rp2040-hal/README.md +++ b/rp2040-hal/README.md @@ -57,7 +57,7 @@ hardware-abstraction interfaces defined in the Rust Embedded Working Group's We also provide a series of *Board Support Package* (BSP) crates, which take this HAL crate and pre-configure the pins according to a specific PCB design. If -you are using on of the supported boards, you should use one of those crates in +you are using one of the supported boards, you should use one of those crates in preference, and return here to see documentation about specific peripherals on the RP2040 and how to use them. See the `boards` folder in https://github.com/rp-rs/rp-hal/ for more details.