Merge branch 'adc'
This commit is contained in:
commit
bdfef566bf
2 changed files with 39 additions and 6 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 412b9f5ee3a3708de8602d6103ec83c6dd436b63
|
||||
Subproject commit f41336744c4e2548c8f6ba9b323ae4aa39959f1d
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
mod insert_coin;
|
||||
use ch32_hal::{interrupt::typelevel::Handler, timer::low_level::OutputPolarity};
|
||||
use ch32_hal::{adc::AdcChannel, interrupt::typelevel::Handler, timer::low_level::OutputPolarity};
|
||||
use insert_coin::{InsertCoin, SimplePwmCore, CoreConfig};
|
||||
|
||||
|
||||
|
|
@ -226,7 +226,7 @@ impl Handler<hal::interrupt::typelevel::EXTI7_0> for Test {
|
|||
unsafe fn on_interrupt() {
|
||||
println!("on_interrupt()");
|
||||
critical_section::with(|_| {
|
||||
clear_interrupt(4, 6);
|
||||
clear_interrupt(2, 6);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -299,12 +299,26 @@ fn main() -> ! {
|
|||
|
||||
// === input setup ===
|
||||
|
||||
// adc
|
||||
let mut adc = hal::adc::Adc::new(p.ADC1, Default::default());
|
||||
let mut adc_pin = p.PD4;
|
||||
// println!("ADC_PIN CHANNEL: {}", adc_pin.channel().channel());
|
||||
delay.delay_ms(1000);
|
||||
let adc_cal = adc.calibrate();
|
||||
println!("ADC calibration value: {}", adc_cal);
|
||||
|
||||
|
||||
|
||||
// definitions
|
||||
let coin_pin = p.PD4;
|
||||
let coin_pin = p.PC2;
|
||||
let button_pin = p.PD6;
|
||||
println!("coin pin: {} | coin port: {}", coin_pin.pin(), coin_pin.port());
|
||||
println!("push pin: {} | push port: {}", button_pin.pin(), button_pin.port());
|
||||
|
||||
//2025-09-10 00:32:23.514: coin pin: 4 | coin port: 3
|
||||
// 2025-09-10 00:32:23.515: push pin: 6 | push port: 3
|
||||
|
||||
|
||||
// set up interrupts
|
||||
unsafe {init_gpio_irq(coin_pin.pin(), coin_pin.port(), false, true)};
|
||||
unsafe {init_gpio_irq(button_pin.pin(), button_pin.port(), true, true)};
|
||||
|
|
@ -353,14 +367,22 @@ fn main() -> ! {
|
|||
let mut lp_timer = TickTimerService::new(lp_timer_data, false);
|
||||
lp_timer.reset();
|
||||
|
||||
let mut delay = Delay;
|
||||
// battery read timer
|
||||
let adc1_ticks = 5 * interfaces.config.tick_rate_hz;
|
||||
let adc1_timer_data = TickServiceData::new(adc1_ticks);
|
||||
let mut adc1_timer = TickTimerService::new(adc1_timer_data, false);
|
||||
adc1_timer.reset();
|
||||
adc1_timer.enable(true);
|
||||
|
||||
|
||||
|
||||
let tick_interval_us = 1000000/interfaces.config.tick_rate_hz - 10;
|
||||
|
||||
// dac data
|
||||
let coin_sound = include_bytes!("../audio/sweep_dpcm_u4.raw");
|
||||
let button_sound = include_bytes!("../audio/sweep_dpcm_u4.raw");
|
||||
|
||||
let mut system_state = SystemState::DeepSleep;
|
||||
let mut system_state = SystemState::Active;
|
||||
|
||||
interfaces.led0.set_amplitude(0);
|
||||
interfaces.led1.set_amplitude(0);
|
||||
|
|
@ -446,6 +468,7 @@ fn main() -> ! {
|
|||
// timers
|
||||
sp_timer.tick();
|
||||
lp_timer.tick();
|
||||
adc1_timer.tick();
|
||||
|
||||
if sp_timer.need_service() {
|
||||
println!("sp detect!");
|
||||
|
|
@ -470,6 +493,16 @@ fn main() -> ! {
|
|||
interfaces.led1.set_amplitude(0);
|
||||
interfaces.service();
|
||||
}
|
||||
|
||||
if adc1_timer.need_service() {
|
||||
let val = adc.convert(&mut adc_pin, hal::adc::SampleTime::CYCLES241);
|
||||
println!("ADC value: {}", val);
|
||||
|
||||
adc1_timer.reset();
|
||||
adc1_timer.enable(true);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
match system_state {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue