diff --git a/Cargo.toml b/Cargo.toml index 6613515bbc01..4d9c8027ed4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "atsamd-hal-macros", "pac/*", "boards/*", + "manage", ] [profile.dev] diff --git a/boards/doit.sh b/boards/doit.sh new file mode 100755 index 000000000000..3022242a4159 --- /dev/null +++ b/boards/doit.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set +e + +for b in *; do + [ "$b" == "$(basename "$0")" ] && continue + for e in "$b"/examples/*.rs; do + newname="$b"-$(basename "$e") + cp "$e" ../examples/"$newname" + done +done \ No newline at end of file diff --git a/boards/feather_m4/Cargo.toml b/boards/feather_m4/Cargo.toml index 205125bc391f..29b5d532aecf 100644 --- a/boards/feather_m4/Cargo.toml +++ b/boards/feather_m4/Cargo.toml @@ -35,12 +35,20 @@ version = "0.3.1" [dev-dependencies] heapless = "0.7" panic-halt = "0.2" -cortex-m-semihosting = "0.5.0" panic-semihosting = "0.5" -rtic = {version = "2.1.1", features = ["thumbv7-backend"]} +panic-probe = "1.0.0" +cortex-m-semihosting = "0.5.0" +rtic = { version = "2.1.1", features = ["thumbv7-backend"] } smart-leds = "0.3" usbd-serial = "0.2" ws2812-timer-delay = "0.3" +embassy-executor = { version = "0.7.0", features = [ + "arch-cortex-m", + "executor-thread", + "task-arena-size-8192", +] } +defmt = "1.0.1" +defmt-rtt = "1.0.0" [features] # ask the HAL to enable atsamd51j support @@ -126,3 +134,7 @@ name = "uart_poll_echo" [[example]] name = "usb_echo" required-features = ["usb"] + +[[example]] +name = "async_dmac" +required-features = ["async", "dma"] diff --git a/boards/feather_m4/examples/async_dmac.rs b/boards/feather_m4/examples/async_dmac.rs new file mode 100644 index 000000000000..64566bd25128 --- /dev/null +++ b/boards/feather_m4/examples/async_dmac.rs @@ -0,0 +1,75 @@ + +//! This example shows a safe API to +//! execute a memory-to-memory DMA transfer +#![no_std] +#![no_main] + +use defmt_rtt as _; +use panic_probe as _; + +use bsp::hal; +use bsp::pac; +use feather_m4 as bsp; + +use hal::{ + clock::GenericClockController, + dmac::{DmaController, PriorityLevel, TriggerAction, TriggerSource}, +}; + +atsamd_hal::bind_multiple_interrupts!(struct Irqs { + DMAC: [DMAC_0, DMAC_1, DMAC_2, DMAC_OTHER] => atsamd_hal::dmac::InterruptHandler; +}); + +#[embassy_executor::main] +async fn main(_s: embassy_executor::Spawner) { + let mut peripherals = pac::Peripherals::take().unwrap(); + let _core = pac::CorePeripherals::take().unwrap(); + + let _clocks = GenericClockController::with_external_32kosc( + peripherals.gclk, + &mut peripherals.mclk, + &mut peripherals.osc32kctrl, + &mut peripherals.oscctrl, + &mut peripherals.nvmctrl, + ); + + // Initialize DMA Controller + let dmac = DmaController::init(peripherals.dmac, &mut peripherals.pm); + + // Turn dmac into an async controller + let mut dmac = dmac.into_future(crate::Irqs); + // Get individual handles to DMA channels + let channels = dmac.split(); + + // Initialize DMA Channel 0 + let mut channel = channels.0.init(PriorityLevel::Lvl0); + + let mut source = [0xff; 100]; + let mut dest = [0x0; 100]; + + defmt::info!( + "Launching a DMA transfer.\n\tSource: {:#x}\n\tDestination: {:#x}", + &source, + &dest + ); + + channel + .transfer_future( + &mut source, + &mut dest, + TriggerSource::Disable, + TriggerAction::Block, + ) + .await + .unwrap(); + + defmt::info!( + "Finished DMA transfer.\n\tSource: {:#x}\n\tDestination: {:#x}", + &source, + &dest + ); + + loop { + cortex_m::asm::wfi(); + } +} \ No newline at end of file diff --git a/boards/feather_m4/examples/blinky_basic.rs b/boards/feather_m4/examples/blinky_basic.rs index de7ef38ba305..a4633fbb5b7c 100644 --- a/boards/feather_m4/examples/blinky_basic.rs +++ b/boards/feather_m4/examples/blinky_basic.rs @@ -2,17 +2,21 @@ #![no_main] use feather_m4 as bsp; + +use bsp::hal; +use bsp::pac; + #[cfg(not(feature = "use_semihosting"))] use panic_halt as _; #[cfg(feature = "use_semihosting")] use panic_semihosting as _; use bsp::entry; -use bsp::hal; use hal::clock::GenericClockController; -use hal::delay::Delay; -use hal::pac::{CorePeripherals, Peripherals}; use hal::prelude::*; +use pac::{CorePeripherals, Peripherals}; + +use hal::delay::Delay; #[entry] fn main() -> ! { @@ -29,9 +33,9 @@ fn main() -> ! { let mut red_led = pins.d13.into_push_pull_output(); let mut delay = Delay::new(core.SYST, &mut clocks); loop { - delay.delay_ms(2000u16); + delay.delay_ms(200u8); red_led.set_high().unwrap(); - delay.delay_ms(2000u16); + delay.delay_ms(200u8); red_led.set_low().unwrap(); } } diff --git a/boards/grand_central_m4/Cargo.toml b/boards/grand_central_m4/Cargo.toml index 80601184ea0f..978a2053b2d7 100644 --- a/boards/grand_central_m4/Cargo.toml +++ b/boards/grand_central_m4/Cargo.toml @@ -30,9 +30,17 @@ features = ["critical-section-single-core"] cortex-m = "0.7" usbd-serial = "0.2" panic-halt = "1.0.0" +panic-probe = "1.0.0" panic-semihosting = "0.6" smart-leds = "0.3" ws2812-timer-delay = "0.3" +embassy-executor = { version = "0.7.0", features = [ + "arch-cortex-m", + "executor-thread", + "task-arena-size-8192", +] } +defmt = "1.0.1" +defmt-rtt = "1.0.0" [features] default = ["rt", "atsamd-hal/samd51p"] @@ -41,6 +49,7 @@ max-channels = ["dma", "atsamd-hal/max-channels"] rt = ["cortex-m-rt", "atsamd-hal/samd51p-rt"] usb = ["atsamd-hal/usb", "usb-device"] use_semihosting = [] +async = ["atsamd-hal/async"] # for cargo flash [package.metadata] @@ -62,3 +71,7 @@ name = "neopixel_rainbow" [[example]] name = "usb_serial" required-features = ["usb"] + +[[example]] +name = "async_dmac" +required-features = ["async", "dma"] diff --git a/boards/grand_central_m4/examples/async_dmac.rs b/boards/grand_central_m4/examples/async_dmac.rs new file mode 100644 index 000000000000..0ff5191a1c6c --- /dev/null +++ b/boards/grand_central_m4/examples/async_dmac.rs @@ -0,0 +1,75 @@ + +//! This example shows a safe API to +//! execute a memory-to-memory DMA transfer +#![no_std] +#![no_main] + +use defmt_rtt as _; +use panic_probe as _; + +use bsp::hal; +use bsp::pac; +use grand_central_m4 as bsp; + +use hal::{ + clock::GenericClockController, + dmac::{DmaController, PriorityLevel, TriggerAction, TriggerSource}, +}; + +atsamd_hal::bind_multiple_interrupts!(struct Irqs { + DMAC: [DMAC_0, DMAC_1, DMAC_2, DMAC_OTHER] => atsamd_hal::dmac::InterruptHandler; +}); + +#[embassy_executor::main] +async fn main(_s: embassy_executor::Spawner) { + let mut peripherals = pac::Peripherals::take().unwrap(); + let _core = pac::CorePeripherals::take().unwrap(); + + let _clocks = GenericClockController::with_external_32kosc( + peripherals.gclk, + &mut peripherals.mclk, + &mut peripherals.osc32kctrl, + &mut peripherals.oscctrl, + &mut peripherals.nvmctrl, + ); + + // Initialize DMA Controller + let dmac = DmaController::init(peripherals.dmac, &mut peripherals.pm); + + // Turn dmac into an async controller + let mut dmac = dmac.into_future(crate::Irqs); + // Get individual handles to DMA channels + let channels = dmac.split(); + + // Initialize DMA Channel 0 + let mut channel = channels.0.init(PriorityLevel::Lvl0); + + let mut source = [0xff; 100]; + let mut dest = [0x0; 100]; + + defmt::info!( + "Launching a DMA transfer.\n\tSource: {:#x}\n\tDestination: {:#x}", + &source, + &dest + ); + + channel + .transfer_future( + &mut source, + &mut dest, + TriggerSource::Disable, + TriggerAction::Block, + ) + .await + .unwrap(); + + defmt::info!( + "Finished DMA transfer.\n\tSource: {:#x}\n\tDestination: {:#x}", + &source, + &dest + ); + + loop { + cortex_m::asm::wfi(); + } +} \ No newline at end of file diff --git a/boards/metro_m4/examples/async_dmac.rs b/boards/metro_m4/examples/async_dmac.rs index 81a1a120bd30..f85f6eeff842 100644 --- a/boards/metro_m4/examples/async_dmac.rs +++ b/boards/metro_m4/examples/async_dmac.rs @@ -1,6 +1,6 @@ + //! This example shows a safe API to //! execute a memory-to-memory DMA transfer - #![no_std] #![no_main] @@ -9,11 +9,12 @@ use panic_probe as _; use bsp::hal; use bsp::pac; +use metro_m4 as bsp; + use hal::{ clock::GenericClockController, dmac::{DmaController, PriorityLevel, TriggerAction, TriggerSource}, }; -use metro_m4 as bsp; atsamd_hal::bind_multiple_interrupts!(struct Irqs { DMAC: [DMAC_0, DMAC_1, DMAC_2, DMAC_OTHER] => atsamd_hal::dmac::InterruptHandler; @@ -71,4 +72,4 @@ async fn main(_s: embassy_executor::Spawner) { loop { cortex_m::asm::wfi(); } -} +} \ No newline at end of file diff --git a/boards/wio_terminal/.cargo/config.toml b/boards/wio_terminal/.cargo/config.toml deleted file mode 100644 index e8f7edb3cf74..000000000000 --- a/boards/wio_terminal/.cargo/config.toml +++ /dev/null @@ -1,14 +0,0 @@ -[target.thumbv7em-none-eabihf] -runner = "arm-none-eabi-gdb" -#runner = 'probe-run --chip ATSAMD51P19A' - -[build] -target = "thumbv7em-none-eabihf" -rustflags = [ - - # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x - # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 - "-C", "link-arg=--nmagic", - - "-C", "link-arg=-Tlink.x", -] diff --git a/boards/wio_terminal/.rustfmt.toml b/boards/wio_terminal/.rustfmt.toml deleted file mode 100644 index 14660176fe39..000000000000 --- a/boards/wio_terminal/.rustfmt.toml +++ /dev/null @@ -1,5 +0,0 @@ -# `wrap_comments` currently requires nightly; if you are not on the nightly -# channel it will give you a warning but otherwise be ignored. - -edition = "2021" -wrap_comments = true diff --git a/boards/wio_terminal/CHANGELOG.md b/boards/wio_terminal/CHANGELOG.md deleted file mode 100644 index 5ef6233f7e49..000000000000 --- a/boards/wio_terminal/CHANGELOG.md +++ /dev/null @@ -1,66 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## [0.8.0](https://github.com/atsamd-rs/atsamd/compare/wio_terminal-0.7.3...wio_terminal-0.8.0) - 2025-05-09 - -### Dependencies - -- *(wio_terminal)* [**breaking**] Update wio_terminal to hal 0.21.0 ([#865](https://github.com/atsamd-rs/atsamd/pull/865)) -- *(wio_terminal)* [**breaking**] Update `embedded_sdmmc` dependency from `0.3` to `0.8` ([#874](https://github.com/atsamd-rs/atsamd/pull/874)) - -## [0.7.3](https://github.com/atsamd-rs/atsamd/compare/wio_terminal-0.7.2...wio_terminal-0.7.3) - 2025-04-17 - -### Examples - -- *(wio_terminal)* Update wio terminal examples ([#834](https://github.com/atsamd-rs/atsamd/pull/834)) - -## [0.7.2](https://github.com/atsamd-rs/atsamd/compare/wio_terminal-0.7.1...wio_terminal-0.7.2) - 2025-01-20 - -### Fixed - -- *(examples)* Fix arrow in wio_terminal/examples/buttons (#812) - -## [0.7.1](https://github.com/atsamd-rs/atsamd/compare/wio_terminal-0.7.0...wio_terminal-0.7.1) - 2024-10-17 - -### Refactored - -- update path of Cargo config ([#749](https://github.com/atsamd-rs/atsamd/pull/749)) -- Remove build profiles from Cargo.toml ([#762](https://github.com/atsamd-rs/atsamd/pull/762)) - -## v0.7.0 - -- Replace homebrew time library with `fugit` (#672) -- Fix end-of-line glyph loss in usb_serial_display example -- Fix display frequency in examples that did not work -- Fix display offsets in buttons example -- Fix buttons by re-enabling debounce code -- Fix various documentation and clippy warnings -- Fix Wi-Fi by delaying UART init until device reset -- Demote to tier 2, as there have been difficulties maintaining this board, and no current maintainer owns one -- Added an example program which is the snake game (`snake.rs`). User can control the direction of the snake using the 5-way-switch. - -## v0.6.1 - -- Update to `atsamd-hal` version `0.15.1` - -## v0.6.0 - -- Fix removed deprecated modules from HAL -- Update `lib.rs` and examples to reflect removal of `v1` APIs and promotion of `v2` APIs -- Update `i2c_master` convenience function to use the new `sercom::v2::i2c` API -- Add an `i2c` example - -## v0.5.0 - -- Update library and examples to use `atsamd-hal` V2 APIs and upgrade BSP to Tier 1. -- Moved crates used only in examples to `[dev-dependencies]` - ---- - -Changelog tracking started at v0.4.0 diff --git a/boards/wio_terminal/Cargo.toml b/boards/wio_terminal/Cargo.toml deleted file mode 100644 index 13cb4b18314c..000000000000 --- a/boards/wio_terminal/Cargo.toml +++ /dev/null @@ -1,106 +0,0 @@ -[package] -name = "wio_terminal" -version = "0.8.0" -authors = [ - "Jesse Braham ", - "Tom " -] -edition = "2021" -description = "Board support crate for the Seeed Studio Wio Terminal" -documentation = "https://docs.rs/wio-terminal/" -readme = "README.md" -repository = "https://github.com/atsamd-rs/atsamd" -license = "MIT OR Apache-2.0" -keywords = [ - "arm", - "cortex-m", - "embedded-hal", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -exclude = ["assets"] - -# for cargo flash -[package.metadata] -chip = "ATSAMD51P19A" - -[dependencies] -bitfield = "0.13" -cortex-m-rt = { version = "0.7", optional = true } - -embedded-hal-bus = "0.3.0" -display-interface-spi = "0.5" -heapless = "0.8" -ili9341 = "0.6.0" -lis3dh = "0.3.0" -embedded-sdmmc = "0.8.0" -usb-device = { version = "0.3", optional = true } -nb = "1.0" -bbqueue = { version = "0.5", optional = true } -generic-array = { version = "0.14", optional = true } -seeed-erpc = { version = "0.1.2", optional = true } - -[dependencies.cortex-m] -features = ["critical-section-single-core"] -version = "0.7" - -[dependencies.atsamd-hal] -version = "0.21.0" -default-features = false - -[dev-dependencies] -usbd-serial = "0.2" -embedded-graphics = "0.8.1" -panic-halt = "0.2" -oorandom = "11.1.3" -nom = { version = "6.2.2", default-features = false } - -[features] -default = ["atsamd-hal/samd51p", "rt", "usb", "wifi"] -rt = ["atsamd-hal/samd51p-rt", "cortex-m-rt"] -usb = ["atsamd-hal/usb", "usb-device"] -# enable feature for RTL8720 firmware older than 2.1.2 -wifi-fw-before-212 = [] -wifi = ["bbqueue", "generic-array", "seeed-erpc"] - -[[example]] -name = "blinky" - -[[example]] -name = "buttons" - -[[example]] -name = "clock" -required-features = ["usb"] - -[[example]] -name = "microphone" - -[[example]] -name = "orientation" - -[[example]] -name = "usb_serial_display" -required-features = ["usb"] - -[[example]] -name = "sdcard" - -[[example]] -name = "qspi" - -[[example]] -name = "wifi_scan" -required-features = ["wifi"] - -[[example]] -name = "wifi_connect" -required-features = ["wifi"] - -[[example]] -name = "snake" diff --git a/boards/wio_terminal/README.md b/boards/wio_terminal/README.md deleted file mode 100644 index c65ae39386ed..000000000000 --- a/boards/wio_terminal/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# `wio-terminal` - -[![Crates.io](https://img.shields.io/crates/v/wio-terminal.svg)](https://crates.io/crates/wio-terminal) -[![Docs](https://docs.rs/wio-terminal/badge.svg)](https://docs.rs/wio-terminal/) -![License](https://img.shields.io/badge/License-MIT%20OR%20Apache--2.0-blue) - -> A Board Support Package (BSP) which provides a type-safe API for the Seeed Studio [Wio Terminal](https://www.seeedstudio.com/Wio-Terminal-p-4509.html). - -This project is made possible thanks to the following crates: - -* [atsamd-hal](https://github.com/atsamd-rs/atsamd) -* [ili9341-rs](https://github.com/yuri91/ili9341-rs) -* [lis3dh-rs](https://github.com/BenBergman/lis3dh-rs) -* [embedded-sdmmc](https://github.com/rust-embedded-community/embedded-sdmmc-rs) -* [seeed-erpc-rs](https://github.com/twitchyliquid64/seeed-erpc-rs) - -## [Documentation] - -[Documentation]: https://docs.rs/wio-terminal/ - -## Resources - -* [Wio Terminal product page](https://www.seeedstudio.com/Wio-Terminal-p-4509.html) -* [Wio Terminal wiki](https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/) -* [Wio Terminal user manual](https://files.seeedstudio.com/wiki/Wio-Terminal/res/Wio-Terminal-User-Manual.pdf) - -## Display - -The ILI9341 datasheet suggests that the maximum speed would be 10 MHz, but -this is conservative and based on low voltage sources. 58 MHz is used in the BSP examples. - -## Wifi - -If you want to use the Wifi features of this crate, you must have updated the wifi core firmware to at least version `2.0.1`. You -can read instructions for this process [here](https://wiki.seeedstudio.com/Wio-Terminal-Network-Overview/). - -## Examples - -For information on building and flashing the examples to your device, as well as a list of all examples with brief explanations, please see the [examples README](examples/README.md). - -## License - -Licensed under either of: - -* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or - http://www.apache.org/licenses/LICENSE-2.0) -* MIT license ([LICENSE-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/boards/wio_terminal/assets/ferris.raw b/boards/wio_terminal/assets/ferris.raw deleted file mode 100644 index 9733889c577b..000000000000 Binary files a/boards/wio_terminal/assets/ferris.raw and /dev/null differ diff --git a/boards/wio_terminal/build.rs b/boards/wio_terminal/build.rs deleted file mode 100644 index 44c87ffae9a2..000000000000 --- a/boards/wio_terminal/build.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - if env::var_os("CARGO_FEATURE_RT").is_some() { - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - println!("cargo:rerun-if-changed=memory.x"); - } - println!("cargo:rerun-if-changed=build.rs"); -} diff --git a/boards/wio_terminal/examples/README.md b/boards/wio_terminal/examples/README.md deleted file mode 100644 index b1fe0720354f..000000000000 --- a/boards/wio_terminal/examples/README.md +++ /dev/null @@ -1,93 +0,0 @@ -# `wio-terminal` Examples - -Various examples demonstrating the use of the Wio Terminal's peripherals. - -## Getting Started - -All commands below are executed from the project's root directory, ie. that containing `Cargo.toml`. - -### Building - -Build all examples, in developer mode: - -```bash -$ cargo build --examples -``` - -Build one specific example, in release mode: - -```bash -$ cargo build --release --example=blinky -``` - -### Flashing - -Regardless of which method used, be sure to put your device in bootloader mode first by toggling the reset switch twice. - -### Linux permissions - -On Linux, you may wish to use udev to grant you access to the bootloader USB port, -without being root. You can do this by creating a file `/etc/udev/rules.d/99-wio-terminal.rules` -with the following contents: - -``` -ATTRS{idVendor}=="2886", ATTRS{idProduct}=="002d", ENV{ID_MM_DEVICE_IGNORE}="1" -SUBSYSTEM=="usb", ATTRS{idVendor}=="2886", ATTRS{idProduct}=="002d", MODE="0666" -SUBSYSTEM=="tty", ATTRS{idVendor}=="2886", ATTRS{idProduct}=="002d", MODE="0666" -``` - -And reloading your udev rules like this: - -```shell -sudo udevadm control --reload-rules -sudo udevadm trigger -``` - -### arm-none-eabi-objcopy & bossac - -Make sure you have built the desired example in release mode first, as described above. - -Convert the resulting file to a binary using `arm-none-eabi-objcopy` (make sure this is on your `PATH` first!), then flash to your device using BOSSA. Make sure you change `` in the command to the appropriate value. - -```bash -$ arm-none-eabi-objcopy \ -> -O binary \ -> /target/thumbv7em-none-eabihf/release/examples/blinky \ -> /target/thumbv7em-none-eabihf/release/examples/blinky.bin -> # alternatively, use cargo-binutils, you can `rust-objcopy` with the same flags, or combine it with the `cargo build` step and use `cargo objcopy` -$ bossac \ -> -i -d -v \ -> --port= -U \ -> -w /target/thumbv7em-none-eabihf/release/examples/blinky.bin \ -> -R -``` - -### cargo-hf2 - -The [hf2-rs](https://github.com/jacobrosenthal/hf2-rs) project provides a crate, [cargo-hf2](https://github.com/jacobrosenthal/hf2-rs/tree/master/cargo-hf2), which allows us to build and flash all in one go using `cargo`: - -```bash -$ cargo install cargo-hf2 -$ cargo hf2 --release --example=blinky --vid 0x2886 --pid 0x002d -``` - -## Examples - -### [`blinky`](blinky.rs) - -Flash the (blue) User LED, located on the bottom of the device beside the USB port, at a set interval. - -### [`buttons`](buttons.rs) - -Demonstrate the use of the buttons and 5-way switch. Displays arrows indicating which button was pressed. - -### [`orientation`](orientation.rs) - -Display Ferris centered on the screen. Maintain the correct orientation of the image as determined by the accelerometer. - -### [`usb_serial_display`](usb_serial_display.rs) - -Makes the Wio Terminal appear as a USB serial port. The screen can be written to by sending messages down the serial port. - -### [`snake`](snake.rs) -Generic snake game where you use the 5-way-switch to control the snake. \ No newline at end of file diff --git a/boards/wio_terminal/examples/blinky.rs b/boards/wio_terminal/examples/blinky.rs deleted file mode 100644 index a3ff297c39f4..000000000000 --- a/boards/wio_terminal/examples/blinky.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![no_std] -#![no_main] - -use panic_halt as _; -use wio_terminal as wio; - -use wio::entry; -use wio::hal::clock::GenericClockController; -use wio::hal::delay::Delay; -use wio::pac::{CorePeripherals, Peripherals}; -use wio::prelude::*; - -#[entry] -fn main() -> ! { - let mut peripherals = Peripherals::take().unwrap(); - let core = CorePeripherals::take().unwrap(); - - let mut clocks = GenericClockController::with_external_32kosc( - peripherals.gclk, - &mut peripherals.mclk, - &mut peripherals.osc32kctrl, - &mut peripherals.oscctrl, - &mut peripherals.nvmctrl, - ); - let mut delay = Delay::new(core.SYST, &mut clocks); - - let sets = wio::Pins::new(peripherals.port).split(); - let mut user_led = sets.user_led.into_push_pull_output(); - user_led.set_low().unwrap(); - - loop { - user_led.toggle().ok(); - delay.delay_ms(200u8); - } -} diff --git a/boards/wio_terminal/examples/buttons.rs b/boards/wio_terminal/examples/buttons.rs deleted file mode 100644 index a7b1dd592de5..000000000000 --- a/boards/wio_terminal/examples/buttons.rs +++ /dev/null @@ -1,186 +0,0 @@ -#![no_std] -#![no_main] -#![allow(static_mut_refs)] - -use embedded_graphics as eg; -use panic_halt as _; -use wio_terminal as wio; - -use eg::pixelcolor::Rgb565; -use eg::prelude::*; -use eg::primitives::{Circle, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle, Triangle}; - -use wio::hal::clock::GenericClockController; -use wio::hal::delay::Delay; -use wio::pac::{interrupt, CorePeripherals, Peripherals}; -use wio::prelude::*; -use wio::{button_interrupt, entry, Button, ButtonController, ButtonEvent}; - -use cortex_m::interrupt::{free as disable_interrupts, CriticalSection}; - -use heapless::spsc::Queue; - -#[entry] -fn main() -> ! { - let mut peripherals = Peripherals::take().unwrap(); - let mut core = CorePeripherals::take().unwrap(); - - let mut clocks = GenericClockController::with_external_32kosc( - peripherals.gclk, - &mut peripherals.mclk, - &mut peripherals.osc32kctrl, - &mut peripherals.oscctrl, - &mut peripherals.nvmctrl, - ); - let mut delay = Delay::new(core.SYST, &mut clocks); - - let sets = wio::Pins::new(peripherals.port).split(); - - // Initialize the ILI9341-based LCD display. Create a black backdrop the size of - // the screen, load an image of Ferris from a RAW file, and draw it to the - // screen. - // By default, the display is in the LandscapeFlipped orientation. - let (mut display, _backlight) = sets - .display - .init( - &mut clocks, - peripherals.sercom7, - &mut peripherals.mclk, - 58.MHz(), - &mut delay, - ) - .unwrap(); - - let style = PrimitiveStyleBuilder::new() - .fill_color(Rgb565::BLACK) - .build(); - let backdrop = - Rectangle::with_corners(Point::new(0, 0), Point::new(320, 320)).into_styled(style); - backdrop.draw(&mut display).unwrap(); - - let button_ctrlr = sets - .buttons - .init(peripherals.eic, &mut clocks, &mut peripherals.mclk); - let nvic = &mut core.NVIC; - disable_interrupts(|_| unsafe { - button_ctrlr.enable(nvic); - BUTTON_CTRLR = Some(button_ctrlr); - }); - - let mut consumer = unsafe { Q.split().1 }; - loop { - if let Some(press) = consumer.dequeue() { - let color = match press.down { - true => Rgb565::RED, - false => Rgb565::BLACK, - }; - - draw_button_marker( - &mut display, - press.button, - PrimitiveStyleBuilder::new().fill_color(color).build(), - ); - } - } -} - -fn draw_button_marker(display: &mut D, button: Button, style: PrimitiveStyle) -where - D: DrawTarget, -{ - match button { - Button::TopLeft => { - Rectangle::with_corners(Point::new(5, 5), Point::new(5, 35)) - .into_styled(style) - .draw(display) - .ok(); - Triangle::new(Point::new(0, 5), Point::new(5, 0), Point::new(10, 5)) - .into_styled(style) - .draw(display) - .ok(); - } - Button::TopMiddle => { - Rectangle::with_corners(Point::new(80, 5), Point::new(80, 35)) - .into_styled(style) - .draw(display) - .ok(); - Triangle::new(Point::new(75, 5), Point::new(80, 0), Point::new(85, 5)) - .into_styled(style) - .draw(display) - .ok(); - } - Button::Left => { - Rectangle::with_corners(Point::new(100, 120), Point::new(130, 120)) - .into_styled(style) - .draw(display) - .ok(); - Triangle::new( - Point::new(100, 115), - Point::new(95, 120), - Point::new(100, 125), - ) - .into_styled(style) - .draw(display) - .ok(); - } - Button::Right => { - Rectangle::with_corners(Point::new(190, 120), Point::new(220, 120)) - .into_styled(style) - .draw(display) - .ok(); - Triangle::new( - Point::new(220, 115), - Point::new(225, 120), - Point::new(220, 125), - ) - .into_styled(style) - .draw(display) - .ok(); - } - Button::Down => { - Rectangle::with_corners(Point::new(160, 150), Point::new(160, 180)) - .into_styled(style) - .draw(display) - .ok(); - Triangle::new( - Point::new(155, 180), - Point::new(160, 185), - Point::new(165, 180), - ) - .into_styled(style) - .draw(display) - .ok(); - } - Button::Up => { - Rectangle::with_corners(Point::new(160, 60), Point::new(160, 90)) - .into_styled(style) - .draw(display) - .ok(); - Triangle::new( - Point::new(155, 60), - Point::new(160, 55), - Point::new(165, 60), - ) - .into_styled(style) - .draw(display) - .ok(); - } - Button::Click => { - Circle::with_center(Point::new(160, 120), 15) - .into_styled(style) - .draw(display) - .ok(); - } - } -} - -static mut BUTTON_CTRLR: Option = None; -static mut Q: Queue = Queue::new(); - -button_interrupt!( - BUTTON_CTRLR, - unsafe fn on_button_event(_cs: &CriticalSection, event: ButtonEvent) { - let mut q = Q.split().0; - q.enqueue(event).ok(); - } -); diff --git a/boards/wio_terminal/examples/clock.rs b/boards/wio_terminal/examples/clock.rs deleted file mode 100644 index ab6f496950e5..000000000000 --- a/boards/wio_terminal/examples/clock.rs +++ /dev/null @@ -1,246 +0,0 @@ -#![no_std] -#![no_main] -#![allow(static_mut_refs)] - -/// Makes the wio_terminal appear as a USB serial port, and display -/// the time on the screen. -/// -/// You can tell the terminal the time by running (on linux): -/// - sudo stty -F /dev/ttyACM0 115200 raw -echo -/// - sudo bash -c "echo 'time=hour:minute:second' > /dev/ttyACM0" -use embedded_graphics as eg; -use panic_halt as _; -use wio_terminal as wio; - -use eg::mono_font::{ascii::FONT_10X20, MonoTextStyle}; -use eg::pixelcolor::Rgb565; -use eg::prelude::*; -use eg::primitives::{PrimitiveStyleBuilder, Rectangle}; -use eg::text::{Baseline, Text}; - -use cortex_m::interrupt::free as disable_interrupts; -use cortex_m::peripheral::NVIC; - -use wio::entry; -use wio::hal::clock::GenericClockController; -use wio::hal::delay::Delay; -use wio::pac::{interrupt, CorePeripherals, Peripherals}; -use wio::prelude::*; - -use core::fmt::Write; -use heapless::String; -use wio::hal::rtc; - -use usb_device::bus::UsbBusAllocator; -use usb_device::prelude::*; -use usbd_serial::{SerialPort, USB_CLASS_CDC}; -use wio::hal::usb::UsbBus; - -#[entry] -fn main() -> ! { - let mut peripherals = Peripherals::take().unwrap(); - let mut core = CorePeripherals::take().unwrap(); - - let mut clocks = GenericClockController::with_external_32kosc( - peripherals.gclk, - &mut peripherals.mclk, - &mut peripherals.osc32kctrl, - &mut peripherals.oscctrl, - &mut peripherals.nvmctrl, - ); - - let mut delay = Delay::new(core.SYST, &mut clocks); - let sets = wio::Pins::new(peripherals.port).split(); - - // Configure the RTC. a 1024 Hz clock is configured for us when enabling our - // main clock - let rtc = rtc::Rtc::clock_mode(peripherals.rtc, 1024.Hz(), &mut peripherals.mclk); - - unsafe { - RTC = Some(rtc); - } - - // Initialize the ILI9341-based LCD display. Create a black backdrop the size of - // the screen. - let (mut display, _backlight) = sets - .display - .init( - &mut clocks, - peripherals.sercom7, - &mut peripherals.mclk, - 58.MHz(), - &mut delay, - ) - .unwrap(); - Rectangle::with_corners(Point::new(0, 0), Point::new(320, 240)) - .into_styled( - PrimitiveStyleBuilder::new() - .fill_color(Rgb565::BLACK) - .build(), - ) - .draw(&mut display) - .ok() - .unwrap(); - - // Initialize USB. - let bus_allocator = unsafe { - USB_ALLOCATOR = Some(sets.usb.usb_allocator( - peripherals.usb, - &mut clocks, - &mut peripherals.mclk, - )); - USB_ALLOCATOR.as_ref().unwrap() - }; - unsafe { - USB_SERIAL = Some(SerialPort::new(bus_allocator)); - USB_BUS = Some( - UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd)) - .strings(&[StringDescriptors::new(LangID::EN) - .manufacturer("Fake company") - .product("Serial port") - .serial_number("TEST")]) - .expect("Failed to set strings") - .device_class(USB_CLASS_CDC) - .build(), - ); - } - unsafe { - core.NVIC.set_priority(interrupt::USB_OTHER, 1); - core.NVIC.set_priority(interrupt::USB_TRCPT0, 1); - core.NVIC.set_priority(interrupt::USB_TRCPT1, 1); - NVIC::unmask(interrupt::USB_OTHER); - NVIC::unmask(interrupt::USB_TRCPT0); - NVIC::unmask(interrupt::USB_TRCPT1); - } - - let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE); - - loop { - delay.delay_ms(1000_u16); - let time = - disable_interrupts(|_| unsafe { RTC.as_mut().map(|rtc| rtc.current_time()) }).unwrap(); - - let mut data = String::<16>::new(); - write!( - data, - "{:02}:{:02}:{:02}", - time.hours, time.minutes, time.seconds - ) - .ok() - .unwrap(); - - Rectangle::with_corners(Point::new(55, 80), Point::new(250, 112)) - .into_styled( - PrimitiveStyleBuilder::new() - .fill_color(Rgb565::BLACK) - .build(), - ) - .draw(&mut display) - .ok() - .unwrap(); - - Text::with_baseline(data.as_str(), Point::new(55, 80), style, Baseline::Top) - .draw(&mut display) - .ok() - .unwrap(); - } -} - -static mut USB_ALLOCATOR: Option> = None; -static mut USB_BUS: Option> = None; -static mut USB_SERIAL: Option> = None; -static mut RTC: Option> = None; - -fn poll_usb() { - unsafe { - if let Some(usb_dev) = USB_BUS.as_mut() { - if let Some(serial) = USB_SERIAL.as_mut() { - usb_dev.poll(&mut [serial]); - let mut buf = [0u8; 32]; - - if let Ok(count) = serial.read(&mut buf) { - // terminal.enqueue((buf, count)).ok().unwrap(); - let mut buffer: &[u8] = &buf[..count]; - - while buffer.len() > 5 { - match timespec(buffer) { - Ok((remaining, time)) => { - buffer = remaining; - - disable_interrupts(|_| { - if let Some(rtc) = RTC.as_mut() { - rtc.set_time(rtc::Datetime { - seconds: time.second as u8, - minutes: time.minute as u8, - hours: time.hour as u8, - day: 0, - month: 0, - year: 0, - }); - } - }); - } - _ => break, - }; - } - }; - } - } - }; -} - -#[interrupt] -fn USB_OTHER() { - poll_usb(); -} - -#[interrupt] -fn USB_TRCPT0() { - poll_usb(); -} - -#[interrupt] -fn USB_TRCPT1() { - poll_usb(); -} - -#[derive(Clone)] -pub struct Time { - hour: u32, - minute: u32, - second: u32, -} - -fn atoi(digits: &[u8]) -> u32 { - let mut num: u32 = 0; - let len = digits.len(); - for (i, digit) in digits.iter().enumerate() { - let digit = (*digit - b'0') as u32; - let mut exp = 1; - for _ in 0..(len - i - 1) { - exp *= 10; - } - num += exp * digit; - } - num -} - -use nom::character::streaming::digit1 as nom_ascii_digit; -use nom::{char, do_parse, opt, tag}; - -nom::named!( - pub timespec