Channel 0 working

This commit is contained in:
geens 2025-07-02 22:15:12 +02:00
parent 515f8ed36c
commit 8d6a4c0e5a
5 changed files with 42 additions and 7 deletions

9
.gitmodules vendored
View File

@ -4,3 +4,12 @@
[submodule "image/yocto/poky"] [submodule "image/yocto/poky"]
path = image/yocto/poky path = image/yocto/poky
url = https://git.yoctoproject.org/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

View File

@ -1,7 +1,7 @@
use stm32f0xx_hal as hal; use stm32f0xx_hal as hal;
use hal::prelude::*; use hal::prelude::*;
use hal::spi::{Spi, Mode, Phase, Polarity, EightBit}; 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 embedded_hal::blocking::spi::Transfer;
use defmt::*; use defmt::*;
@ -14,7 +14,7 @@ const IIR_ALPHA: u16 = 51;
pub struct Tlc0832 { pub struct Tlc0832 {
spi: Spi<hal::stm32::SPI2, spi: Spi<hal::stm32::SPI2,
hal::gpio::gpiob::PB10<Alternate<AF0>>, hal::gpio::gpiob::PB10<Alternate<AF5>>,
hal::gpio::gpiob::PB14<Alternate<AF0>>, hal::gpio::gpiob::PB14<Alternate<AF0>>,
hal::gpio::gpiob::PB15<Alternate<AF0>>, hal::gpio::gpiob::PB15<Alternate<AF0>>,
EightBit>, EightBit>,
@ -35,7 +35,7 @@ impl Tlc0832 {
rcc: &mut hal::rcc::Rcc, rcc: &mut hal::rcc::Rcc,
) -> Self { ) -> Self {
cortex_m::interrupt::free(|critical_section| { 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 miso = miso.into_alternate_af0(critical_section);
let mosi = mosi.into_alternate_af0(critical_section); let mosi = mosi.into_alternate_af0(critical_section);
let cs = cs.into_push_pull_output(critical_section); let cs = cs.into_push_pull_output(critical_section);
@ -220,6 +220,7 @@ impl Tlc0832 {
} }
} }
/*
match self.read_channel(1) { match self.read_channel(1) {
Ok(raw_b) => { Ok(raw_b) => {
self.apply_iir_filter(1, raw_b); self.apply_iir_filter(1, raw_b);
@ -235,6 +236,7 @@ impl Tlc0832 {
error!("Error reading channel 1: {}", e); error!("Error reading channel 1: {}", e);
} }
} }
*/
(midi_a_change, midi_b_change) (midi_a_change, midi_b_change)
} }

View File

@ -4,6 +4,7 @@ use hal::{delay::Delay, serial::Serial, stm32};
use hal::gpio::{Input, Floating, gpiob}; use hal::gpio::{Input, Floating, gpiob};
use embedded_midi::{MidiOut, MidiIn}; use embedded_midi::{MidiOut, MidiIn};
use crate::bus::Bus; use crate::bus::Bus;
use crate::adc::Tlc0832;
pub struct Hardware { pub struct Hardware {
pub delay: Delay, pub delay: Delay,
@ -12,6 +13,7 @@ pub struct Hardware {
pub bus: Bus, pub bus: Bus,
pub midi_tx: MidiOut<hal::serial::Tx<stm32::USART1>>, pub midi_tx: MidiOut<hal::serial::Tx<stm32::USART1>>,
pub midi_rx: MidiIn<hal::serial::Rx<stm32::USART1>>, pub midi_rx: MidiIn<hal::serial::Rx<stm32::USART1>>,
pub adc: Tlc0832,
} }
impl Hardware { impl Hardware {
@ -52,6 +54,13 @@ impl Hardware {
let midi_tx = MidiOut::new(tx); let midi_tx = MidiOut::new(tx);
let midi_rx = MidiIn::new(rx); 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 { Self {
delay, delay,
button_1_5, button_1_5,
@ -59,6 +68,7 @@ impl Hardware {
bus, bus,
midi_tx, midi_tx,
midi_rx, midi_rx,
adc,
} }
} }
} }

View File

@ -1,12 +1,13 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
mod led_state; mod adc;
mod bus; mod bus;
mod button; mod button;
mod midi;
mod hardware;
mod display; mod display;
mod hardware;
mod led_state;
mod midi;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use panic_halt as _; use panic_halt as _;
@ -17,6 +18,8 @@ use button::ButtonHandler;
use midi::MidiProcessor; use midi::MidiProcessor;
use hardware::Hardware; use hardware::Hardware;
use display::DisplayController; use display::DisplayController;
use embedded_midi::MidiMessage;
use midi_types::{Control, Channel, Value7};
defmt::timestamp!("{=u32}", { defmt::timestamp!("{=u32}", {
static mut COUNTER: u32 = 0; static mut COUNTER: u32 = 0;
@ -52,6 +55,17 @@ fn main() -> ! {
MidiProcessor::process_message(&mut hardware.midi_rx, &mut led_state); 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();
}
} }
} }

@ -1 +1 @@
Subproject commit c743505a730d7d7c36ec1dc29e7b54b162519c25 Subproject commit 0c9060e16e2e12f02bb79caecb4bc93215191edd