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