First leds and debugging midi
This commit is contained in:
parent
63d5522fd9
commit
9510ba04be
1
firmware/Cargo.lock
generated
1
firmware/Cargo.lock
generated
@ -271,6 +271,7 @@ dependencies = [
|
|||||||
"defmt 0.3.100",
|
"defmt 0.3.100",
|
||||||
"defmt-rtt",
|
"defmt-rtt",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
|
"nb 1.1.0",
|
||||||
"panic-halt",
|
"panic-halt",
|
||||||
"stm32f0xx-hal",
|
"stm32f0xx-hal",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -7,9 +7,10 @@ version = "0.1.0"
|
|||||||
cortex-m = { version = "0.7", features = ["inline-asm", "critical-section-single-core"] }
|
cortex-m = { version = "0.7", features = ["inline-asm", "critical-section-single-core"] }
|
||||||
cortex-m-rt = "0.7"
|
cortex-m-rt = "0.7"
|
||||||
critical-section = "1"
|
critical-section = "1"
|
||||||
stm32f0xx-hal = { version = "0.18", features = ["stm32f042", "rt"] }
|
|
||||||
embedded-hal = "0.2"
|
embedded-hal = "0.2"
|
||||||
|
nb = "1"
|
||||||
panic-halt = "0.2"
|
panic-halt = "0.2"
|
||||||
|
stm32f0xx-hal = { version = "0.18", features = ["stm32f042", "rt"] }
|
||||||
|
|
||||||
# For debugging and logging
|
# For debugging and logging
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
|
|||||||
@ -3,8 +3,13 @@
|
|||||||
|
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use stm32f0xx_hal::{
|
use stm32f0xx_hal::serial::Error;
|
||||||
delay::Delay, prelude::*, stm32
|
use stm32f0xx_hal as hal;
|
||||||
|
use hal::prelude::*;
|
||||||
|
use hal::stm32;
|
||||||
|
use hal::{
|
||||||
|
delay::Delay,
|
||||||
|
serial::Serial,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Bus {
|
struct Bus {
|
||||||
@ -33,7 +38,7 @@ fn main() -> ! {
|
|||||||
.sysclk(48.mhz())
|
.sysclk(48.mhz())
|
||||||
.pclk(24.mhz())
|
.pclk(24.mhz())
|
||||||
.freeze(&mut dp.FLASH);
|
.freeze(&mut dp.FLASH);
|
||||||
|
|
||||||
// Set up delay provider
|
// Set up delay provider
|
||||||
let mut delay = Delay::new(cp.SYST, &rcc);
|
let mut delay = Delay::new(cp.SYST, &rcc);
|
||||||
|
|
||||||
@ -55,28 +60,46 @@ fn main() -> ! {
|
|||||||
pb7: gpiob.pb7.into_push_pull_output(cs),
|
pb7: gpiob.pb7.into_push_pull_output(cs),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut serial = cortex_m::interrupt::free(|cs| {
|
||||||
|
let tx = gpioa.pa9.into_alternate_af1(cs);
|
||||||
|
let rx = gpioa.pa10.into_alternate_af1(cs);
|
||||||
|
//dp.USART1.cr1.write(|w| w.uesm().enabled());
|
||||||
|
Serial::usart1(dp.USART1, (tx, rx), 31_250.bps(), &mut rcc)
|
||||||
|
});
|
||||||
|
|
||||||
// Loop
|
// Loop
|
||||||
loop {
|
loop {
|
||||||
for ic in 0..=2 {
|
use stm32f0xx_hal::serial::Error;
|
||||||
for i in 0..256 {
|
//type Error = nb::Error<stm32f0xx_hal::serial::Error>;
|
||||||
bus.output(ic, 1 << i, &mut delay);
|
//use embedded_hal::serial::nb::Error;
|
||||||
delay.delay_ms(100u16);
|
match serial.read() {
|
||||||
|
Ok(_) => {
|
||||||
|
bus.led_button_1(&mut delay);
|
||||||
|
}
|
||||||
|
Err(nb::Error::WouldBlock) => {
|
||||||
|
bus.led_button_3(&mut delay);
|
||||||
|
}
|
||||||
|
Err(nb::Error::Other(Error::Framing)) => {
|
||||||
|
bus.led_button_2(&mut delay);
|
||||||
|
}
|
||||||
|
Err(nb::Error::Other(Error::Noise)) => {
|
||||||
|
bus.led_button_9(&mut delay);
|
||||||
|
}
|
||||||
|
Err(nb::Error::Other(_)) => {
|
||||||
|
bus.led_button_10(&mut delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delay.delay_ms(1000u16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bus {
|
impl Bus {
|
||||||
fn output(&mut self, ic: u8, data: u8, delay: &mut Delay) {
|
fn output(&mut self, ic: u8, data: u8, delay: &mut Delay) {
|
||||||
match ic {
|
match ic {
|
||||||
0 => self.select(1, delay),
|
0 | 3 => self.select(1, delay),
|
||||||
1 => self.select(0, delay),
|
1 | 10 => self.select(0, delay),
|
||||||
2 => self.select(5, delay),
|
2 | 11 => self.select(5, delay),
|
||||||
|
|
||||||
3 => self.select(1, delay),
|
|
||||||
10 => self.select(0, delay),
|
|
||||||
11 => self.select(5, delay),
|
|
||||||
|
|
||||||
_ => self.select(2, delay),
|
_ => self.select(2, delay),
|
||||||
}
|
}
|
||||||
@ -89,14 +112,14 @@ impl Bus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, data: u8) {
|
fn write(&mut self, data: u8) {
|
||||||
self.pb0.set_state((data & 0b00000001 != 0).into()).ok();
|
self.pb0.set_state((data & 0b_0000_0001 != 0).into()).ok();
|
||||||
self.pb1.set_state((data & 0b00000010 != 0).into()).ok();
|
self.pb1.set_state((data & 0b_0000_0010 != 0).into()).ok();
|
||||||
self.pb2.set_state((data & 0b00000100 != 0).into()).ok();
|
self.pb2.set_state((data & 0b_0000_0100 != 0).into()).ok();
|
||||||
self.pb3.set_state((data & 0b00001000 != 0).into()).ok();
|
self.pb3.set_state((data & 0b_0000_1000 != 0).into()).ok();
|
||||||
self.pb4.set_state((data & 0b00010000 != 0).into()).ok();
|
self.pb4.set_state((data & 0b_0001_0000 != 0).into()).ok();
|
||||||
self.pb5.set_state((data & 0b00100000 != 0).into()).ok();
|
self.pb5.set_state((data & 0b_0010_0000 != 0).into()).ok();
|
||||||
self.pb6.set_state((data & 0b01000000 != 0).into()).ok();
|
self.pb6.set_state((data & 0b_0100_0000 != 0).into()).ok();
|
||||||
self.pb7.set_state((data & 0b10000000 != 0).into()).ok();
|
self.pb7.set_state((data & 0b_1000_0000 != 0).into()).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_en(&mut self, enable: bool) {
|
fn select_en(&mut self, enable: bool) {
|
||||||
@ -196,4 +219,34 @@ impl Bus {
|
|||||||
delay.delay_ms(10u16);
|
delay.delay_ms(10u16);
|
||||||
self.select_en.set_high().ok();
|
self.select_en.set_high().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn led_button_1(&mut self, delay: &mut Delay) {
|
||||||
|
self.output(03, 0b1111_1011, delay);
|
||||||
|
self.output(10, 0b0001_0000, delay);
|
||||||
|
self.output(11, 0b0000_0000, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn led_button_2(&mut self, delay: &mut Delay) {
|
||||||
|
self.output(03, 0b1111_1101, delay);
|
||||||
|
self.output(10, 0b0001_0000, delay);
|
||||||
|
self.output(11, 0b0000_0000, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn led_button_3(&mut self, delay: &mut Delay) {
|
||||||
|
self.output(03, 0b1111_1110, delay);
|
||||||
|
self.output(10, 0b0001_0000, delay);
|
||||||
|
self.output(11, 0b0000_0000, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn led_button_9(&mut self, delay: &mut Delay) {
|
||||||
|
self.output(03, 0b1110_1111, delay);
|
||||||
|
self.output(10, 0b0001_0000, delay);
|
||||||
|
self.output(11, 0b0000_0000, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn led_button_10(&mut self, delay: &mut Delay) {
|
||||||
|
self.output(03, 0b1111_0111, delay);
|
||||||
|
self.output(10, 0b0001_0000, delay);
|
||||||
|
self.output(11, 0b0000_0000, delay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user