From 8d6a4c0e5a0f4982d74d9bce5b6b1769ff8bb986 Mon Sep 17 00:00:00 2001 From: geens Date: Wed, 2 Jul 2025 22:15:12 +0200 Subject: [PATCH] Channel 0 working --- .gitmodules | 9 +++++++++ firmware/src/adc.rs | 8 +++++--- firmware/src/hardware.rs | 10 ++++++++++ firmware/src/main.rs | 20 +++++++++++++++++--- firmware/stm32f0xx-hal | 2 +- 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/.gitmodules b/.gitmodules index cab7898..81e1e71 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,12 @@ [submodule "image/yocto/poky"] path = image/yocto/poky url = https://git.yoctoproject.org/poky + branch = scarthgap +[submodule "image/yocto/meta-openembedded"] + path = image/yocto/meta-openembedded + url = git://git.openembedded.org/meta-openembedded + branch = scarthgap +[submodule "image/yocto/meta-rust-bin"] + path = image/yocto/meta-rust-bin + url = https://github.com/rust-embedded/meta-rust-bin.git + branch = master diff --git a/firmware/src/adc.rs b/firmware/src/adc.rs index 199e4db..972ff22 100644 --- a/firmware/src/adc.rs +++ b/firmware/src/adc.rs @@ -1,7 +1,7 @@ use stm32f0xx_hal as hal; use hal::prelude::*; use hal::spi::{Spi, Mode, Phase, Polarity, EightBit}; -use hal::gpio::{Output, PushPull, Alternate, AF0}; +use hal::gpio::{Output, PushPull, Alternate, AF0, AF5}; use embedded_hal::blocking::spi::Transfer; use defmt::*; @@ -14,7 +14,7 @@ const IIR_ALPHA: u16 = 51; pub struct Tlc0832 { spi: Spi>, + hal::gpio::gpiob::PB10>, hal::gpio::gpiob::PB14>, hal::gpio::gpiob::PB15>, EightBit>, @@ -35,7 +35,7 @@ impl Tlc0832 { rcc: &mut hal::rcc::Rcc, ) -> Self { cortex_m::interrupt::free(|critical_section| { - let sck = sck.into_alternate_af0(critical_section); + let sck = sck.into_alternate_af5(critical_section); let miso = miso.into_alternate_af0(critical_section); let mosi = mosi.into_alternate_af0(critical_section); let cs = cs.into_push_pull_output(critical_section); @@ -220,6 +220,7 @@ impl Tlc0832 { } } + /* match self.read_channel(1) { Ok(raw_b) => { self.apply_iir_filter(1, raw_b); @@ -235,6 +236,7 @@ impl Tlc0832 { error!("Error reading channel 1: {}", e); } } + */ (midi_a_change, midi_b_change) } diff --git a/firmware/src/hardware.rs b/firmware/src/hardware.rs index 4c46785..500dffc 100644 --- a/firmware/src/hardware.rs +++ b/firmware/src/hardware.rs @@ -4,6 +4,7 @@ use hal::{delay::Delay, serial::Serial, stm32}; use hal::gpio::{Input, Floating, gpiob}; use embedded_midi::{MidiOut, MidiIn}; use crate::bus::Bus; +use crate::adc::Tlc0832; pub struct Hardware { pub delay: Delay, @@ -12,6 +13,7 @@ pub struct Hardware { pub bus: Bus, pub midi_tx: MidiOut>, pub midi_rx: MidiIn>, + pub adc: Tlc0832, } impl Hardware { @@ -52,6 +54,13 @@ impl Hardware { let midi_tx = MidiOut::new(tx); let midi_rx = MidiIn::new(rx); + let adc_sck = cortex_m::interrupt::free(|cs| gpiob.pb10.into_floating_input(cs)); + let adc_miso = cortex_m::interrupt::free(|cs| gpiob.pb14.into_floating_input(cs)); + let adc_mosi = cortex_m::interrupt::free(|cs| gpiob.pb15.into_floating_input(cs)); + let adc_cs = cortex_m::interrupt::free(|cs| gpiob.pb12.into_floating_input(cs)); + + let adc = Tlc0832::new(dp.SPI2, adc_sck, adc_miso, adc_mosi, adc_cs, &mut rcc); + Self { delay, button_1_5, @@ -59,6 +68,7 @@ impl Hardware { bus, midi_tx, midi_rx, + adc, } } } \ No newline at end of file diff --git a/firmware/src/main.rs b/firmware/src/main.rs index 6264e9d..ef9794a 100755 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -1,12 +1,13 @@ #![no_std] #![no_main] -mod led_state; +mod adc; mod bus; mod button; -mod midi; -mod hardware; mod display; +mod hardware; +mod led_state; +mod midi; use cortex_m_rt::entry; use panic_halt as _; @@ -17,6 +18,8 @@ use button::ButtonHandler; use midi::MidiProcessor; use hardware::Hardware; use display::DisplayController; +use embedded_midi::MidiMessage; +use midi_types::{Control, Channel, Value7}; defmt::timestamp!("{=u32}", { static mut COUNTER: u32 = 0; @@ -52,6 +55,17 @@ fn main() -> ! { MidiProcessor::process_message(&mut hardware.midi_rx, &mut led_state); } + let (pedal_a_change, pedal_b_change) = hardware.adc.update_and_get_midi_changes(); + + if let Some(value) = pedal_a_change { + let msg = MidiMessage::ControlChange(Channel::C1, Control::from(1), Value7::from(value)); + hardware.midi_tx.write(&msg).ok(); + } + + if let Some(value) = pedal_b_change { + let msg = MidiMessage::ControlChange(Channel::C1, Control::from(7), Value7::from(value)); + hardware.midi_tx.write(&msg).ok(); + } } } diff --git a/firmware/stm32f0xx-hal b/firmware/stm32f0xx-hal index c743505..0c9060e 160000 --- a/firmware/stm32f0xx-hal +++ b/firmware/stm32f0xx-hal @@ -1 +1 @@ -Subproject commit c743505a730d7d7c36ec1dc29e7b54b162519c25 +Subproject commit 0c9060e16e2e12f02bb79caecb4bc93215191edd