From 5ad0a593f8eb30e74a66b0fac9106f8f288830e0 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Thu, 16 Feb 2023 00:49:43 +0000 Subject: [PATCH] Add board support crate example. --- .../microcontrollers/board-support.md | 16 ++ .../microcontrollers/examples/Cargo.lock | 186 +++++++++++++++++- .../microcontrollers/examples/Cargo.toml | 4 + .../examples/src/bin/board_support.rs | 32 +++ 4 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 src/bare-metal/microcontrollers/examples/src/bin/board_support.rs diff --git a/src/bare-metal/microcontrollers/board-support.md b/src/bare-metal/microcontrollers/board-support.md index de3bff80..f7b49318 100644 --- a/src/bare-metal/microcontrollers/board-support.md +++ b/src/bare-metal/microcontrollers/board-support.md @@ -1 +1,17 @@ # Board support crates + +Board support crates provide a further level of wrapping for a specific board for convenience. + +```rust,editable,compile_fail +{{#include examples/src/bin/board_support.rs:Example}} +``` + +
+ + * In this case the board support crate is just providing more useful names, and a bit of + initialisation. + * The crate may also include drivers for some on-board devices outside of the microcontroller + itself. + * `microbit-v2` includes a simple driver for the LED matrix. + +
diff --git a/src/bare-metal/microcontrollers/examples/Cargo.lock b/src/bare-metal/microcontrollers/examples/Cargo.lock index 0d17fcb1..da1b70ff 100644 --- a/src/bare-metal/microcontrollers/examples/Cargo.lock +++ b/src/bare-metal/microcontrollers/examples/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + [[package]] name = "bare-metal" version = "0.2.5" @@ -11,6 +17,12 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "bare-metal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" + [[package]] name = "bitfield" version = "0.13.2" @@ -35,19 +47,31 @@ dependencies = [ "vcell", ] +[[package]] +name = "bytemuck" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c041d3eab048880cb0b86b256447da3f18859a163c3b8d8893f4e6368abe6393" + [[package]] name = "cast" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "cortex-m" version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" dependencies = [ - "bare-metal", + "bare-metal 0.2.5", "bitfield", "embedded-hal", "volatile-register", @@ -73,6 +97,37 @@ dependencies = [ "syn", ] +[[package]] +name = "critical-section" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1706d332edc22aef4d9f23a6bb1c92360a403013c291af51247a737472dcae6" +dependencies = [ + "bare-metal 1.0.0", + "critical-section 1.1.1", +] + +[[package]] +name = "critical-section" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6548a0ad5d2549e111e1f6a11a6c2e2d00ce6a3dafe22948d67c2b443f775e52" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "embedded-dma" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c8c02e4347a0267ca60813c952017f4c5948c232474c6010a381a337f1bda4" +dependencies = [ + "stable_deref_trait", +] + [[package]] name = "embedded-dma" version = "0.2.0" @@ -92,6 +147,24 @@ dependencies = [ "void", ] +[[package]] +name = "embedded-storage" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca" + +[[package]] +name = "fixed" +version = "1.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55f3be4cf4fc227d3a63bb77512a2b7d364200b2a715f389155785c4d3345495" +dependencies = [ + "az", + "bytemuck", + "half", + "typenum", +] + [[package]] name = "gd32f1" version = "0.6.0" @@ -113,13 +186,42 @@ dependencies = [ "cast", "cortex-m", "cortex-m-rt", - "embedded-dma", + "embedded-dma 0.2.0", "embedded-hal", "gd32f1", "nb 1.0.0", "void", ] +[[package]] +name = "half" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" +dependencies = [ + "crunchy", +] + +[[package]] +name = "microbit-common" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45651d001be4281a6f4536c30f3d8522f231bc56fd58d5baf2c630f565d31256" +dependencies = [ + "embedded-hal", + "nrf52833-hal", + "tiny-led-matrix", +] + +[[package]] +name = "microbit-v2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9895242259950730bc112623e4a2e37345dc51ddb5fc8878c110489260d84e7" +dependencies = [ + "microbit-common", +] + [[package]] name = "microcontroller-examples" version = "0.1.0" @@ -128,6 +230,7 @@ dependencies = [ "embedded-hal", "gd32f1", "gd32f1x0-hal", + "microbit-v2", "panic-halt", ] @@ -146,6 +249,61 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" +[[package]] +name = "nrf-hal-common" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd37b3fd039327b4005cc0d4ef20bce0a41bf521071774d5adb854e4b1230639" +dependencies = [ + "cast", + "cfg-if", + "cortex-m", + "embedded-dma 0.1.2", + "embedded-hal", + "embedded-storage", + "fixed", + "nb 1.0.0", + "nrf-usbd", + "nrf52833-pac", + "rand_core", + "void", +] + +[[package]] +name = "nrf-usbd" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "640e88d4c108743c667f03320d0c9ab24a20f183a7a1b18bde7891ee13fd92c5" +dependencies = [ + "bare-metal 1.0.0", + "cortex-m", + "critical-section 0.2.8", + "usb-device", + "vcell", +] + +[[package]] +name = "nrf52833-hal" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f76d269c9a239ffe24edaa5ee0972b102c04e898b464e3e9a12ab0eacd5f76" +dependencies = [ + "embedded-hal", + "nrf-hal-common", + "nrf52833-pac", +] + +[[package]] +name = "nrf52833-pac" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd69bdb25903e18e098c040ef31dc863814437af010dea8bd55aa31f686cb461" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "vcell", +] + [[package]] name = "panic-halt" version = "0.2.0" @@ -170,6 +328,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + [[package]] name = "rustc_version" version = "0.2.3" @@ -211,12 +375,30 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tiny-led-matrix" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a718c727b686154a7c7913f70d7ebc8956f701cbab466bc22035cb27f378882b" + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "usb-device" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" + [[package]] name = "vcell" version = "0.1.3" diff --git a/src/bare-metal/microcontrollers/examples/Cargo.toml b/src/bare-metal/microcontrollers/examples/Cargo.toml index 7c8e8145..22a14b87 100644 --- a/src/bare-metal/microcontrollers/examples/Cargo.toml +++ b/src/bare-metal/microcontrollers/examples/Cargo.toml @@ -10,8 +10,12 @@ cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" gd32f1 = { version = "0.6.0", features = ["gd32f130", "rt"] } gd32f1x0-hal = { version = "0.7.1", features = ["rt", "gd32f130x8"] } +microbit-v2 = "0.13.0" panic-halt = "0.2.0" +[[bin]] +name = "board_support" + [[bin]] name = "pac" diff --git a/src/bare-metal/microcontrollers/examples/src/bin/board_support.rs b/src/bare-metal/microcontrollers/examples/src/bin/board_support.rs new file mode 100644 index 00000000..f8a4b943 --- /dev/null +++ b/src/bare-metal/microcontrollers/examples/src/bin/board_support.rs @@ -0,0 +1,32 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// ANCHOR: Example +#![no_main] +#![no_std] + +extern crate panic_halt as _; + +use cortex_m_rt::entry; +use microbit::{hal::prelude::*, Board}; + +#[entry] +fn main() -> ! { + let mut board = Board::take().unwrap(); + + board.display_pins.col1.set_low().unwrap(); + board.display_pins.row1.set_high().unwrap(); + + loop {} +}