Move the Led struct and PERIOD const to main module

These definitions are board-specific and do not belong in the more
generic `led_ring` module.
This commit is contained in:
Paul van Tilburg 2019-04-06 17:36:17 +02:00
parent 8e31b2c27d
commit 80fabf85e8
Signed by: paul
GPG Key ID: C6DE073EDA9EEC4D
2 changed files with 9 additions and 13 deletions

View File

@ -1,12 +1,7 @@
//! Module for manipulating the LED ring. //! Module for manipulating the LED ring.
use hal::gpio::{Output, PushPull};
use hal::prelude::*;
/// Type alias for a generic LED output. /// The cycle direction of the LED ring.
pub type Led = hal::gpio::gpiod::PD<Output<PushPull>>;
/// The cycle direction of the LED ring
/// ///
/// The direction can be interpreted as such when the mini-USB port of the board is being held /// The direction can be interpreted as such when the mini-USB port of the board is being held
/// down. /// down.
@ -55,9 +50,6 @@ pub struct LedRing {
} }
impl LedRing { impl LedRing {
/// The number of cycles between LED ring updates (used by tasks).
pub const PERIOD: u32 = 8_000_000;
/// Sets up the LED ring using using four LED GPIO outputs. /// Sets up the LED ring using using four LED GPIO outputs.
pub fn from(leds: [Led; 4]) -> LedRing { pub fn from(leds: [Led; 4]) -> LedRing {
LedRing { LedRing {

View File

@ -10,7 +10,7 @@
mod led_ring; mod led_ring;
use crate::led_ring::{Led, LedRing}; use crate::led_ring::LedRing;
use core::fmt::Write; use core::fmt::Write;
use cortex_m_semihosting::hprintln; use cortex_m_semihosting::hprintln;
use hal::{ use hal::{
@ -28,6 +28,7 @@ use rtfm::app;
type Accelerometer = hal::spi::Spi<SPI1, (Spi1Sck, Spi1Miso, Spi1Mosi)>; type Accelerometer = hal::spi::Spi<SPI1, (Spi1Sck, Spi1Miso, Spi1Mosi)>;
type AccelerometerCs = hal::gpio::gpioe::PE3<Output<PushPull>>; type AccelerometerCs = hal::gpio::gpioe::PE3<Output<PushPull>>;
type Led = hal::gpio::gpiod::PD<Output<PushPull>>;
type SerialTx = hal::serial::Tx<USART2>; type SerialTx = hal::serial::Tx<USART2>;
type SerialRx = hal::serial::Rx<USART2>; type SerialRx = hal::serial::Rx<USART2>;
type Spi1Sck = hal::gpio::gpioa::PA5<Alternate<AF5>>; type Spi1Sck = hal::gpio::gpioa::PA5<Alternate<AF5>>;
@ -35,11 +36,14 @@ type Spi1Miso = hal::gpio::gpioa::PA6<Alternate<AF5>>;
type Spi1Mosi = hal::gpio::gpioa::PA7<Alternate<AF5>>; type Spi1Mosi = hal::gpio::gpioa::PA7<Alternate<AF5>>;
type UserButton = hal::gpio::gpioa::PA0<Input<Floating>>; type UserButton = hal::gpio::gpioa::PA0<Input<Floating>>;
/// The number of cycles between LED ring updates (used by tasks).
const PERIOD: u32 = 8_000_000;
#[app(device = hal::stm32)] #[app(device = hal::stm32)]
const APP: () = { const APP: () = {
static mut button: UserButton = (); static mut button: UserButton = ();
static mut buffer: Vec<u8, U8> = (); static mut buffer: Vec<u8, U8> = ();
static mut led_ring: LedRing = (); static mut led_ring: LedRing<Led> = ();
static mut exti: EXTI = (); static mut exti: EXTI = ();
static mut serial_rx: SerialRx = (); static mut serial_rx: SerialRx = ();
static mut serial_tx: SerialTx = (); static mut serial_tx: SerialTx = ();
@ -125,7 +129,7 @@ const APP: () = {
if led_ring.is_mode_cycle() { if led_ring.is_mode_cycle() {
led_ring.advance(); led_ring.advance();
schedule schedule
.cycle_leds(scheduled + LedRing::PERIOD.cycles()) .cycle_leds(scheduled + PERIOD.cycles())
.unwrap(); .unwrap();
} }
}); });
@ -154,7 +158,7 @@ const APP: () = {
let directions = [acc_y < 0, acc_x < 0, acc_y > 0, acc_x > 0]; let directions = [acc_y < 0, acc_x < 0, acc_y > 0, acc_x > 0];
led_ring.specific_on(directions); led_ring.specific_on(directions);
schedule schedule
.accel_leds(scheduled + LedRing::PERIOD.cycles()) .accel_leds(scheduled + PERIOD.cycles())
.unwrap(); .unwrap();
} }
}) })