Initial BSP for Pimoroni Badger2040 (#334)

This commit is contained in:
9names 2022-07-11 19:45:44 +10:00 committed by GitHub
parent 7d11e2f15e
commit 69c2dd2c2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 331 additions and 0 deletions

View file

@ -10,6 +10,7 @@ members = [
"boards/adafruit-qt-py-rp2040", "boards/adafruit-qt-py-rp2040",
"boards/adafruit-trinkey-qt2040", "boards/adafruit-trinkey-qt2040",
"boards/arduino_nano_connect", "boards/arduino_nano_connect",
"boards/pimoroni-badger2040",
"boards/pimoroni-pico-explorer", "boards/pimoroni-pico-explorer",
"boards/pimoroni-pico-lipo-16mb", "boards/pimoroni-pico-lipo-16mb",
"boards/pimoroni-plasma-2040", "boards/pimoroni-plasma-2040",

11
boards/pimoroni-badger2040/.gitignore vendored Normal file
View file

@ -0,0 +1,11 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

View file

@ -0,0 +1,8 @@
# 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]

View file

@ -0,0 +1,32 @@
[package]
name = "pimoroni_badger2040"
version = "0.1.0"
authors = ["9names", "The rp-rs Developers"]
edition = "2018"
homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/pimoroni-badger2040"
description = "Board Support Package for the Pimoroni Badger2040"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rp-rs/rp-hal.git"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0"}
cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0"
embedded-hal ="0.2.5"
[dev-dependencies]
panic-halt= "0.2.0"
nb = "1.0"
embedded-graphics = "0.7.1"
defmt = "0.2.0"
defmt-rtt = "0.2.0"
[features]
default = ["boot2", "rt"]
boot2 = ["rp2040-boot2"]
rt = ["cortex-m-rt","rp2040-hal/rt"]

View file

@ -0,0 +1,96 @@
# [pimoroni-badger2040] - Board Support for the [Pimoroni Badger2040]
You should include this crate if you are writing code that you want to run on
a [Pimoroni Badger2040] - a conference-style badge built around an e-paper
display and an rp2040
This crate includes the [rp2040-hal], but also configures each pin of the
RP2040 chip according to how it is connected up on the Badger2040.
[Pimoroni Badger2040]: https://shop.pimoroni.com/products/badger-2040/
[pimoroni-badger2040]: https://github.com/rp-rs/rp-hal/tree/main/boards/pimoroni-badger2040
[rp2040-hal]: https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal
[Raspberry Silicon RP2040]: https://www.raspberrypi.org/products/rp2040/
## Using
To use this crate, your `Cargo.toml` file should contain:
```toml
pimoroni-badger2040 = "0.1.0"
```
In your program, you will need to call `pimoroni_badger2040::Board::take().unwrap()` to create
a new `Boards` structure. This will set up all the GPIOs for any on-board
devices and configure common clocks. See the [examples](./examples) folder for more details.
## Examples
### General Instructions
To compile an example, clone the _rp-hal_ repository and run:
```console
rp-hal/boards/pimoroni-badger2040 $ cargo build --release --example <name>
```
You will get an ELF file called
`./target/thumbv6m-none-eabi/release/examples/<name>`, where the `target`
folder is located at the top of the _rp-hal_ repository checkout. Normally
you would also need to specify `--target=thumbv6m-none-eabi` but when
building examples from this git repository, that is set as the default.
If you want to convert the ELF file to a UF2 and automatically copy it to the
USB drive exported by the RP2040 bootloader, simply boot your board into
bootloader mode and run:
```console
rp-hal/boards/pimoroni-badger2040 $ cargo run --release --example <name>
```
If you get an error about not being able to find `elf2uf2-rs`, try:
```console
$ cargo install elf2uf2-rs
```
then try repeating the `cargo run` command above.
### [badger_blinky](./examples/badger_blinky.rs)
Flashes the Badger2040's activity LED on and off.
## Contributing
Contributions are what make the open source community such an amazing place to
be learn, inspire, and create. Any contributions you make are **greatly
appreciated**.
The steps are:
1. Fork the Project by clicking the 'Fork' button at the top of the page.
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Make some changes to the code or documentation.
4. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
5. Push to the Feature Branch (`git push origin feature/AmazingFeature`)
6. Create a [New Pull Request](https://github.com/rp-rs/rp-hal/pulls)
7. An admin will review the Pull Request and discuss any changes that may be required.
8. Once everyone is happy, the Pull Request can be merged by an admin, and your work is part of our project!
## Code of Conduct
Contribution to this crate is organized under the terms of the [Rust Code of
Conduct][CoC], and the maintainer of this crate, the [rp-rs team], promises
to intervene to uphold that code of conduct.
[CoC]: CODE_OF_CONDUCT.md
[rp-rs team]: https://github.com/orgs/rp-rs/teams/rp-rs
## 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.
Any submissions to this project (e.g. as Pull Requests) must be made available
under these terms.

View file

@ -0,0 +1,86 @@
//! # Badger2040 Blinky Example
//!
//! Blinks the activity LED on a badger2040 board, using an RP2040 Timer in Count-down mode.
//!
//! See the `Cargo.toml` file for Copyright and licence details.
#![no_std]
#![no_main]
// The macro for our start-up function
use pimoroni_badger2040::entry;
// GPIO traits
use embedded_hal::digital::v2::OutputPin;
// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;
// A shorter alias for the Peripheral Access Crate, which provides low-level
// register access
use pimoroni_badger2040::hal::pac;
use pimoroni_badger2040::hal::Timer;
// A shorter alias for the Hardware Abstraction Layer, which provides
// higher-level drivers.
use pimoroni_badger2040::hal;
// A few traits required for using the CountDown timer
use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions;
#[entry]
fn main() -> ! {
// Grab our singleton objects
let mut pac = pac::Peripherals::take().unwrap();
// Set up the watchdog driver - needed by the clock setup code
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
// Configure the clocks
//
// The default is to generate a 125 MHz system clock
let _clocks = hal::clocks::init_clocks_and_plls(
pimoroni_badger2040::XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();
// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);
// Set the pins up according to their function on this particular board
let pins = pimoroni_badger2040::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
// Configure the timer peripheral to be a CountDown timer for our blinky delay
let timer = Timer::new(pac.TIMER, &mut pac.RESETS);
let mut delay = timer.count_down();
// Set the LED to be an output
let mut led_pin = pins.led.into_push_pull_output();
// Blink the LED at 1 Hz
loop {
// LED on, and wait for 500ms
led_pin.set_high().unwrap();
delay.start(500.milliseconds());
let _ = nb::block!(delay.wait());
// LED off, and wait for 500ms
led_pin.set_low().unwrap();
delay.start(500.milliseconds());
let _ = nb::block!(delay.wait());
}
}

View file

@ -0,0 +1,97 @@
#![no_std]
pub extern crate rp2040_hal as hal;
#[cfg(feature = "rt")]
extern crate cortex_m_rt;
#[cfg(feature = "rt")]
pub use cortex_m_rt::entry;
pub use hal::pac;
/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
#[cfg(feature = "boot2")]
#[link_section = ".boot2"]
#[no_mangle]
#[used]
pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
hal::bsp_pins!(
Gpio0 {
name: gpio0,
aliases: {
/// UART Function alias for pin [crate::Pins::gpio0].
FunctionUart: UartTx
}
},
Gpio1 {
name: gpio1,
aliases: {
/// UART Function alias for pin [crate::Pins::gpio1].
FunctionUart: UartRx
}
},
Gpio3 { name: i2c_int },
Gpio4 {
name: gpio4,
aliases: {
/// I2C Function alias for pin [crate::Pins::gpio4].
FunctionI2C: I2cSda
}
},
Gpio5 {
name: gpio5,
aliases: {
/// I2C Function alias for pin [crate::Pins::gpio5].
FunctionI2C: I2cScl
}
},
Gpio10 { name: p3v3_en },
Gpio11 { name: sw_down },
Gpio12 { name: sw_a },
Gpio13 { name: sw_b },
Gpio14 { name: sw_c },
Gpio15 { name: sw_up },
Gpio16 {
name: miso,
aliases: {
/// SPI Function alias for pin [crate::Pins::gpio16].
FunctionSpi: Miso
}
},
Gpio17 {
name: inky_cs_gpio,
aliases: {
/// SPI Function alias for pin [crate::Pins::gpio17].
FunctionSpi: InkyCs
}
},
Gpio18 {
name: sclk,
aliases: {
/// SPI Function alias for pin [crate::Pins::gpio18].
FunctionSpi: Sclk
}
},
Gpio19 {
name: mosi,
aliases: {
/// SPI Function alias for pin [crate::Pins::gpio19].
FunctionSpi: Mosi
}
},
Gpio20 { name: inky_dc },
Gpio21 { name: inky_res },
Gpio23 { name: user_sw },
/// GPIO 24 is connected to vbus_detect of the badger2040.
Gpio24 { name: vbus_detect },
/// GPIO 25 is connected to activity LED of the badger2040.
Gpio25 { name: led },
Gpio26 { name: inky_busy },
Gpio27 { name: vref_power },
Gpio28 { name: vref_1v24 },
/// GPIO 29 is connected to battery monitor of the badger2040
Gpio29 { name: vbat_sense },
);
pub const XOSC_CRYSTAL_FREQ: u32 = 12_000_000;