add additional InputFlags and minor refactor
This commit is contained in:
parent
73e4b482a6
commit
b1d7574a80
2 changed files with 66 additions and 32 deletions
|
|
@ -127,13 +127,28 @@ pub enum SystemState {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct InputFlags {
|
||||
coin_flag: bool,
|
||||
button_flag: bool,
|
||||
sense_coin_flag: bool,
|
||||
main_btn_flag: bool,
|
||||
volume_btn_flag: bool,
|
||||
light_ctrl_btn_flag: bool,
|
||||
}
|
||||
|
||||
impl Default for InputFlags {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
sense_coin_flag: false,
|
||||
main_btn_flag: false,
|
||||
volume_btn_flag: false,
|
||||
light_ctrl_btn_flag: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static mut INPUT_FLAGS: InputFlags = InputFlags {
|
||||
coin_flag: false,
|
||||
button_flag: false,
|
||||
sense_coin_flag: false,
|
||||
main_btn_flag: false,
|
||||
volume_btn_flag: false,
|
||||
light_ctrl_btn_flag: false,
|
||||
};
|
||||
|
||||
struct Test {}
|
||||
|
|
@ -248,8 +263,12 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
println!("ADC calibration value: {}", adc_cal);
|
||||
|
||||
// definitions
|
||||
let coin_pin = p.PC2;
|
||||
let button_pin = p.PD6;
|
||||
let sense_coin_pin = p.PC2;
|
||||
let main_btn_pin = p.PD6;
|
||||
let volume_btn_pin = p.PC6;
|
||||
let light_ctrl_btn_pin = p.PC7;
|
||||
let amp_en = p.PC5;
|
||||
|
||||
// println!(
|
||||
// "coin pin: {} | coin port: {}",
|
||||
// coin_pin.pin(),
|
||||
|
|
@ -265,13 +284,30 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
// 2025-09-10 00:32:23.515: push pin: 6 | push port: 3
|
||||
|
||||
// set up interrupts
|
||||
unsafe { system::init_gpio_irq(coin_pin.pin(), coin_pin.port(), false, true) };
|
||||
unsafe { system::init_gpio_irq(button_pin.pin(), button_pin.port(), true, true) };
|
||||
unsafe { system::init_gpio_irq(sense_coin_pin.pin(), sense_coin_pin.port(), false, true) };
|
||||
unsafe { system::init_gpio_irq(main_btn_pin.pin(), main_btn_pin.port(), true, true) };
|
||||
unsafe { system::init_gpio_irq(volume_btn_pin.pin(), volume_btn_pin.port(), true, true) };
|
||||
unsafe {
|
||||
system::init_gpio_irq(
|
||||
light_ctrl_btn_pin.pin(),
|
||||
light_ctrl_btn_pin.port(),
|
||||
true,
|
||||
true,
|
||||
)
|
||||
};
|
||||
|
||||
// coin debouncer (100ms)
|
||||
let mut coin_input = DebouncedGPIO::new(coin_pin.degrade(), core_config.tick_rate_hz, 100);
|
||||
let mut sense_coin_input =
|
||||
DebouncedGPIO::new(sense_coin_pin.degrade(), core_config.tick_rate_hz, 100);
|
||||
// main button debouncer (100ms)
|
||||
let mut main_btn_input =
|
||||
DebouncedGPIO::new(main_btn_pin.degrade(), core_config.tick_rate_hz, 100);
|
||||
// button debouncer (100ms)
|
||||
let mut button_input = DebouncedGPIO::new(button_pin.degrade(), core_config.tick_rate_hz, 100);
|
||||
let mut volume_btn_input =
|
||||
DebouncedGPIO::new(volume_btn_pin.degrade(), core_config.tick_rate_hz, 100);
|
||||
// button debouncer (100ms)
|
||||
let mut light_ctrl_btn_input =
|
||||
DebouncedGPIO::new(light_ctrl_btn_pin.degrade(), core_config.tick_rate_hz, 100);
|
||||
|
||||
let pwm_core = SimplePwmCore::new(pwm);
|
||||
|
||||
|
|
@ -321,6 +357,7 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
// dac data
|
||||
// let coin_sound = include_bytes!("../audio/coin.raw");
|
||||
let coin_sound = include_bytes!("../audio/sweep_dpcm_u4.raw");
|
||||
let button_sounds = [include_bytes!("../audio/sweep_dpcm_u4.raw")];
|
||||
// let button_sound = include_bytes!("../audio/coinMixTest1_dpcm_u4.raw");
|
||||
|
||||
let mut system_state = SystemState::Active;
|
||||
|
|
@ -353,11 +390,11 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
{
|
||||
// system input servicing
|
||||
unsafe {
|
||||
if INPUT_FLAGS.coin_flag {
|
||||
if INPUT_FLAGS.sense_coin_flag {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("coin flag active");
|
||||
INPUT_FLAGS.coin_flag = false;
|
||||
coin_input.begin();
|
||||
INPUT_FLAGS.sense_coin_flag = false;
|
||||
sense_coin_input.begin();
|
||||
// enter the active state
|
||||
system_state = SystemState::Active;
|
||||
|
||||
|
|
@ -366,31 +403,31 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
tt1.enable(true);
|
||||
interfaces.dac.load_data(coin_sound);
|
||||
}
|
||||
if INPUT_FLAGS.button_flag {
|
||||
if INPUT_FLAGS.main_btn_flag {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("button flag active");
|
||||
INPUT_FLAGS.button_flag = false;
|
||||
button_input.begin();
|
||||
INPUT_FLAGS.main_btn_flag = false;
|
||||
main_btn_input.begin();
|
||||
}
|
||||
}
|
||||
|
||||
// debouncer
|
||||
coin_input.service();
|
||||
button_input.service();
|
||||
sense_coin_input.service();
|
||||
main_btn_input.service();
|
||||
|
||||
if coin_input.ready() {
|
||||
if sense_coin_input.ready() {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("debounced coin_input value: {}", coin_input.value());
|
||||
coin_input.reset();
|
||||
println!("debounced coin_input value: {}", sense_coin_input.value());
|
||||
sense_coin_input.reset();
|
||||
}
|
||||
if button_input.ready() {
|
||||
let value = button_input.value();
|
||||
button_input.reset();
|
||||
if main_btn_input.ready() {
|
||||
let value = main_btn_input.value();
|
||||
main_btn_input.reset();
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("debounced button_input value: {}", value);
|
||||
|
||||
if !value {
|
||||
// interfaces.dac.load_data(button_sound);
|
||||
interfaces.dac.load_data(button_sounds[0]);
|
||||
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("reset hold timers + enable");
|
||||
|
|
@ -458,7 +495,7 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
hal::rcc::init(config.rcc);
|
||||
}
|
||||
unsafe {
|
||||
if INPUT_FLAGS.coin_flag {
|
||||
if INPUT_FLAGS.sense_coin_flag {
|
||||
system_state = SystemState::Active;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,7 @@ pub unsafe fn init_gpio_irq(pin: u8, port: u8, rising: bool, falling: bool) {
|
|||
|
||||
// FIXME: should return a vec of the interrupts
|
||||
pub fn clear_interrupt(coin_pin: u8, button_pin: u8) -> crate::InputFlags {
|
||||
let mut input_flags = crate::InputFlags {
|
||||
coin_flag: false,
|
||||
button_flag: false,
|
||||
};
|
||||
let mut input_flags = crate::InputFlags::default();
|
||||
|
||||
let exti = &hal::pac::EXTI;
|
||||
|
||||
|
|
@ -44,7 +41,7 @@ pub fn clear_interrupt(coin_pin: u8, button_pin: u8) -> crate::InputFlags {
|
|||
if (bits & (0x1 << coin_pin)) != 0x0 {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("coin irq!");
|
||||
input_flags.coin_flag = true;
|
||||
input_flags.sense_coin_flag = true;
|
||||
// unsafe {
|
||||
// INPUT_FLAGS.coin_flag = true;
|
||||
// }
|
||||
|
|
@ -54,7 +51,7 @@ pub fn clear_interrupt(coin_pin: u8, button_pin: u8) -> crate::InputFlags {
|
|||
if (bits & (0x1 << button_pin)) != 0x0 {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("button irq!");
|
||||
input_flags.button_flag = true;
|
||||
input_flags.main_btn_flag = true;
|
||||
// unsafe {
|
||||
// INPUT_FLAGS.button_flag = true;
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue