Merge pull request #2 from robamu-org/mueller/gpio-refactoring
Update to v0.1.1
This commit is contained in:
commit
448b18c9ed
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "vorago-reb1"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["Robin Mueller <robin.mueller.m@gmail.com>"]
|
||||
edition = "2021"
|
||||
description = "Board Support Crate for the Vorago REB1 development board"
|
||||
@ -20,5 +20,5 @@ panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
|
||||
rtt-target = { version = "0.3", features = ["cortex-m"] }
|
||||
|
||||
[dependencies.va108xx-hal]
|
||||
version = "0.1"
|
||||
version = "0.2"
|
||||
features = ["rt"]
|
||||
|
@ -25,6 +25,12 @@ you can build the blinky example with
|
||||
cargo build --example blinky-leds
|
||||
```
|
||||
|
||||
If you have not done this yet, it is recommended to read some of the excellent resources
|
||||
available to learn Rust:
|
||||
|
||||
- [Rust Embedded Book](https://docs.rust-embedded.org/book/)
|
||||
- [Rust Discovery Book](https://docs.rust-embedded.org/discovery/)
|
||||
|
||||
## Flashing from the command line
|
||||
|
||||
A `jlink.gdb` file is provided to allow flashing of the board from the command line.
|
||||
|
@ -9,7 +9,7 @@
|
||||
use cortex_m_rt::entry;
|
||||
use embedded_hal::digital::v2::ToggleableOutputPin;
|
||||
use panic_halt as _;
|
||||
use va108xx_hal::{pac, prelude::*};
|
||||
use va108xx_hal::{gpio::pins::PinsA, pac, prelude::*};
|
||||
use vorago_reb1::leds::Leds;
|
||||
|
||||
// REB LED pin definitions. All on port A
|
||||
@ -27,7 +27,7 @@ enum LibType {
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut dp = pac::Peripherals::take().unwrap();
|
||||
let porta = dp.PORTA.split(&mut dp.SYSCONFIG).unwrap();
|
||||
|
||||
let lib_type = LibType::Bsp;
|
||||
|
||||
match lib_type {
|
||||
@ -60,15 +60,10 @@ fn main() -> ! {
|
||||
}
|
||||
}
|
||||
LibType::Hal => {
|
||||
let mut led1 = porta
|
||||
.pa10
|
||||
.into_push_pull_output(&mut dp.IOCONFIG, &mut dp.PORTA);
|
||||
let mut led2 = porta
|
||||
.pa7
|
||||
.into_push_pull_output(&mut dp.IOCONFIG, &mut dp.PORTA);
|
||||
let mut led3 = porta
|
||||
.pa6
|
||||
.into_push_pull_output(&mut dp.IOCONFIG, &mut dp.PORTA);
|
||||
let pins = PinsA::new(&mut dp.SYSCONFIG, Some(dp.IOCONFIG), dp.PORTA);
|
||||
let mut led1 = pins.pa10.into_push_pull_output();
|
||||
let mut led2 = pins.pa7.into_push_pull_output();
|
||||
let mut led3 = pins.pa6.into_push_pull_output();
|
||||
for _ in 0..10 {
|
||||
led1.set_low().ok();
|
||||
led2.set_low().ok();
|
||||
@ -89,7 +84,7 @@ fn main() -> ! {
|
||||
}
|
||||
}
|
||||
LibType::Bsp => {
|
||||
let mut leds = Leds::new(porta, &mut dp.IOCONFIG, &mut dp.PORTA);
|
||||
let mut leds = Leds::new(PinsA::new(&mut dp.SYSCONFIG, Some(dp.IOCONFIG), dp.PORTA));
|
||||
loop {
|
||||
for _ in 0..10 {
|
||||
// Blink all LEDs quickly
|
||||
|
25
src/leds.rs
25
src/leds.rs
@ -1,25 +1,22 @@
|
||||
use va108xx_hal::{
|
||||
gpio::{
|
||||
porta::{Parts, PA10, PA6, PA7},
|
||||
Output, Pin, PushPull,
|
||||
},
|
||||
pac::{IOCONFIG, PORTA},
|
||||
gpio::dynpins::DynPin,
|
||||
gpio::pins::{Pin, PinsA, PushPullOutput, PA10, PA6, PA7},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
pub type LD2 = PA10<Output<PushPull>>;
|
||||
pub type LD3 = PA7<Output<PushPull>>;
|
||||
pub type LD4 = PA6<Output<PushPull>>;
|
||||
pub type LD2 = Pin<PA10, PushPullOutput>;
|
||||
pub type LD3 = Pin<PA7, PushPullOutput>;
|
||||
pub type LD4 = Pin<PA6, PushPullOutput>;
|
||||
|
||||
pub struct Leds {
|
||||
leds: [Led; 3],
|
||||
}
|
||||
|
||||
impl Leds {
|
||||
pub fn new(led_parts: Parts, iocfg: &mut IOCONFIG, porta: &mut PORTA) -> Self {
|
||||
let led2 = led_parts.pa10.into_push_pull_output(iocfg, porta);
|
||||
let led3 = led_parts.pa7.into_push_pull_output(iocfg, porta);
|
||||
let led4 = led_parts.pa6.into_push_pull_output(iocfg, porta);
|
||||
pub fn new(led_parts: PinsA) -> Self {
|
||||
let led2 = led_parts.pa10.into_push_pull_output();
|
||||
let led3 = led_parts.pa7.into_push_pull_output();
|
||||
let led4 = led_parts.pa6.into_push_pull_output();
|
||||
Leds {
|
||||
leds: [led2.into(), led3.into(), led4.into()],
|
||||
}
|
||||
@ -55,7 +52,7 @@ impl core::ops::IndexMut<usize> for Leds {
|
||||
}
|
||||
|
||||
pub struct Led {
|
||||
pin: Pin<Output<PushPull>>,
|
||||
pin: DynPin,
|
||||
}
|
||||
|
||||
macro_rules! ctor {
|
||||
@ -64,7 +61,7 @@ macro_rules! ctor {
|
||||
impl From<$ldx> for Led {
|
||||
fn from(led: $ldx) -> Self {
|
||||
Led {
|
||||
pin: led.downgrade(),
|
||||
pin: led.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user