formatting
This commit is contained in:
parent
8c88456fcb
commit
08d7289c93
1 changed files with 66 additions and 68 deletions
|
|
@ -113,10 +113,14 @@ unsafe fn enter_standby(pin: usize) {
|
|||
// get current value of PWR_CTLR
|
||||
let mut reg: u32 = 0x4000_7000;
|
||||
let mut val: u32 = 0;
|
||||
unsafe { val = (reg as *mut u32).read_volatile(); }
|
||||
unsafe {
|
||||
val = (reg as *mut u32).read_volatile();
|
||||
}
|
||||
// modify PDDS
|
||||
val |= 1 << 1; // PWR_CTLR[1] -> PDDS
|
||||
unsafe { (reg as *mut u32).write_volatile(val); }
|
||||
unsafe {
|
||||
(reg as *mut u32).write_volatile(val);
|
||||
}
|
||||
|
||||
// // disable all exti interrupts
|
||||
let exti = &hal::pac::EXTI;
|
||||
|
|
@ -129,7 +133,6 @@ unsafe fn enter_standby(pin: usize) {
|
|||
// clear all pending exti interrupts
|
||||
let bits = 0xFFFFFFFF;
|
||||
exti.intfr().write(|w| w.0 = bits);
|
||||
|
||||
|
||||
// enable all exti interrupts
|
||||
let exti = &hal::pac::EXTI;
|
||||
|
|
@ -144,20 +147,18 @@ unsafe fn enter_standby(pin: usize) {
|
|||
qingke::pfic::enable_interrupt(Interrupt::EXTI7_0 as u8);
|
||||
}
|
||||
|
||||
|
||||
// execute WFI
|
||||
#[cfg(feature="enable_print")]
|
||||
// execute WFI
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("WFI CONFIGURED HOPEFULLY");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
unsafe fn init_gpio_irq(pin: u8, port: u8, rising: bool, falling: bool) {
|
||||
critical_section::with(|_| {
|
||||
#[cfg(feature="enable_print")]
|
||||
println!("init_gpio_irq");
|
||||
let exti = &hal::pac::EXTI;
|
||||
let afio = &hal::pac::AFIO;
|
||||
critical_section::with(|_| {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("init_gpio_irq");
|
||||
let exti = &hal::pac::EXTI;
|
||||
let afio = &hal::pac::AFIO;
|
||||
|
||||
let port = port as u8;
|
||||
let pin = pin as usize;
|
||||
|
|
@ -187,7 +188,7 @@ fn clear_interrupt(coin_pin: u8, button_pin: u8) {
|
|||
|
||||
// coin_flag
|
||||
if (bits & (0x1 << coin_pin)) != 0x0 {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("coin irq!");
|
||||
unsafe {
|
||||
INPUT_FLAGS.coin_flag = true;
|
||||
|
|
@ -196,7 +197,7 @@ fn clear_interrupt(coin_pin: u8, button_pin: u8) {
|
|||
|
||||
// button_flag
|
||||
if (bits & (0x1 << button_pin)) != 0x0 {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("button irq!");
|
||||
unsafe {
|
||||
INPUT_FLAGS.button_flag = true;
|
||||
|
|
@ -230,7 +231,7 @@ static mut INPUT_FLAGS: InputFlags = InputFlags {
|
|||
struct Test {}
|
||||
impl Handler<hal::interrupt::typelevel::EXTI7_0> for Test {
|
||||
unsafe fn on_interrupt() {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("on_interrupt()");
|
||||
critical_section::with(|_| {
|
||||
clear_interrupt(2, 6);
|
||||
|
|
@ -247,27 +248,29 @@ use insert_coin::TickTimerService;
|
|||
use insert_coin::{TickService, TickServiceData};
|
||||
|
||||
fn debug_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
||||
// LED0 output setup
|
||||
use hal::gpio::{Output, Level};
|
||||
// LED0 output setup
|
||||
use hal::gpio::{Level, Output};
|
||||
let mut led0_pin = Output::new(p.PC3, Level::High, Default::default());
|
||||
|
||||
// button pin setup
|
||||
let button_pin = p.PD6;
|
||||
unsafe {init_gpio_irq(button_pin.pin(), button_pin.port(), false, true)};
|
||||
let button_pin = p.PD6;
|
||||
unsafe { init_gpio_irq(button_pin.pin(), button_pin.port(), false, true) };
|
||||
let mut button_input = Input::new(button_pin, Pull::Up);
|
||||
|
||||
delay.delay_ms(1000);
|
||||
|
||||
unsafe{enter_standby(4)};
|
||||
|
||||
unsafe { enter_standby(4) };
|
||||
delay.delay_ms(1000);
|
||||
riscv::asm::wfi();
|
||||
|
||||
// get the clocks re-initialized
|
||||
let mut config = hal::Config::default();
|
||||
config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI;
|
||||
unsafe { hal::rcc::init(config.rcc); }
|
||||
unsafe {
|
||||
hal::rcc::init(config.rcc);
|
||||
}
|
||||
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("begin loop");
|
||||
|
||||
loop {
|
||||
|
|
@ -277,7 +280,6 @@ fn debug_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
}
|
||||
|
||||
fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
||||
|
||||
// === output setup ===
|
||||
|
||||
// LED0 output setup
|
||||
|
|
@ -294,8 +296,8 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
|
||||
// LED2 output setup
|
||||
let led2_pin = PwmPin::new_ch2::<0>(p.PA1);
|
||||
let led2_ch = hal::timer::Channel::Ch2;
|
||||
|
||||
let led2_ch = hal::timer::Channel::Ch2;
|
||||
|
||||
// DAC output setup
|
||||
let dac_pin = PwmPin::new_ch4::<0>(p.PC4);
|
||||
// let dac_ch = hal::timer::Channel::Ch4;
|
||||
|
|
@ -329,26 +331,26 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
// adc2
|
||||
// let mut usb_detect_dc = hal::adc::Adc::new(p.ADC1, Default::default());
|
||||
let mut usb_adc_pin = p.PD5;
|
||||
|
||||
|
||||
// println!("ADC_PIN CHANNEL: {}", adc_pin.channel().channel());
|
||||
delay.delay_ms(1000);
|
||||
let adc_cal = adc.calibrate();
|
||||
|
||||
#[cfg(feature="enable_print")]
|
||||
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("ADC calibration value: {}", adc_cal);
|
||||
|
||||
// definitions
|
||||
let coin_pin = p.PC2;
|
||||
let button_pin = p.PD6;
|
||||
// println!(
|
||||
// "coin pin: {} | coin port: {}",
|
||||
// coin_pin.pin(),
|
||||
// coin_pin.port()
|
||||
// "coin pin: {} | coin port: {}",
|
||||
// coin_pin.pin(),
|
||||
// coin_pin.port()
|
||||
// );
|
||||
// println!(
|
||||
// "push pin: {} | push port: {}",
|
||||
// button_pin.pin(),
|
||||
// button_pin.port()
|
||||
// "push pin: {} | push port: {}",
|
||||
// button_pin.pin(),
|
||||
// button_pin.port()
|
||||
// );
|
||||
|
||||
//2025-09-10 00:32:23.514: coin pin: 4 | coin port: 3
|
||||
|
|
@ -424,8 +426,8 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
|
||||
// qingke::pfic::unpend_interrupt(Interrupt::EXTI7_0 as u8);
|
||||
clear_interrupt(2, 6);
|
||||
qingke::pfic::enable_interrupt(Interrupt::EXTI7_0 as u8);
|
||||
// qingke::pfic::enable_interrupt(CoreInterrupt::SysTick as u8);
|
||||
qingke::pfic::enable_interrupt(Interrupt::EXTI7_0 as u8);
|
||||
// qingke::pfic::enable_interrupt(CoreInterrupt::SysTick as u8);
|
||||
}
|
||||
|
||||
// MAIN APPLICATION
|
||||
|
|
@ -436,14 +438,14 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
// -depress the big button for approx 2s and it puts the led into low light mode. Just making it dimmer than usual.
|
||||
// -depress the big button for 5s and it goes into deep sleep, everything off with the low sleep current draw
|
||||
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("begin");
|
||||
loop {
|
||||
{
|
||||
// system input servicing
|
||||
unsafe {
|
||||
if INPUT_FLAGS.coin_flag {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("coin flag active");
|
||||
INPUT_FLAGS.coin_flag = false;
|
||||
coin_input.begin();
|
||||
|
|
@ -456,7 +458,7 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
interfaces.dac.load_data(coin_sound);
|
||||
}
|
||||
if INPUT_FLAGS.button_flag {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("button flag active");
|
||||
INPUT_FLAGS.button_flag = false;
|
||||
button_input.begin();
|
||||
|
|
@ -468,20 +470,20 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
button_input.service();
|
||||
|
||||
if coin_input.ready() {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("debounced coin_input value: {}", coin_input.value());
|
||||
coin_input.reset();
|
||||
}
|
||||
if button_input.ready() {
|
||||
let value = button_input.value();
|
||||
button_input.reset();
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("debounced button_input value: {}", value);
|
||||
|
||||
if !value {
|
||||
// interfaces.dac.load_data(button_sound);
|
||||
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("reset hold timers + enable");
|
||||
sp_timer.reset();
|
||||
sp_timer.enable(true);
|
||||
|
|
@ -499,7 +501,7 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
adc1_timer.tick();
|
||||
|
||||
if sp_timer.need_service() {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("sp detect!");
|
||||
sp_timer.reset();
|
||||
|
||||
|
|
@ -512,7 +514,7 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
}
|
||||
|
||||
if lp_timer.need_service() {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("lp detect!");
|
||||
lp_timer.reset();
|
||||
|
||||
|
|
@ -527,7 +529,7 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
if adc1_timer.need_service() {
|
||||
let val = adc.convert(&mut adc_pin, hal::adc::SampleTime::CYCLES241);
|
||||
let val = adc.convert(&mut usb_adc_pin, hal::adc::SampleTime::CYCLES241);
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("ADC value: {}", val);
|
||||
|
||||
adc1_timer.reset();
|
||||
|
|
@ -537,24 +539,24 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
|
||||
match system_state {
|
||||
SystemState::DeepSleep => {
|
||||
// TODO: make this REALLY deep sleep
|
||||
unsafe{enter_standby(4)};
|
||||
loop {
|
||||
riscv::asm::wfi();
|
||||
let mut config = hal::Config::default();
|
||||
config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI;
|
||||
unsafe { hal::rcc::init(config.rcc); }
|
||||
unsafe{
|
||||
if INPUT_FLAGS.coin_flag {
|
||||
system_state = SystemState::Active;
|
||||
break;
|
||||
}
|
||||
};
|
||||
// TODO: make this REALLY deep sleep
|
||||
unsafe { enter_standby(4) };
|
||||
loop {
|
||||
riscv::asm::wfi();
|
||||
let mut config = hal::Config::default();
|
||||
config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI;
|
||||
unsafe {
|
||||
hal::rcc::init(config.rcc);
|
||||
}
|
||||
},
|
||||
SystemState::Idle => {
|
||||
|
||||
},
|
||||
unsafe {
|
||||
if INPUT_FLAGS.coin_flag {
|
||||
system_state = SystemState::Active;
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
SystemState::Idle => {}
|
||||
SystemState::Active => {
|
||||
tt0.tick();
|
||||
tt1.tick();
|
||||
|
|
@ -587,7 +589,7 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
|
||||
#[qingke_rt::entry]
|
||||
fn main() -> ! {
|
||||
#[cfg(feature="enable_print")]
|
||||
#[cfg(feature = "enable_print")]
|
||||
hal::debug::SDIPrint::enable();
|
||||
|
||||
let mut config = hal::Config::default();
|
||||
|
|
@ -599,12 +601,8 @@ fn main() -> ! {
|
|||
delay.delay_ms(1000);
|
||||
|
||||
debug_main(p, delay);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue