support ADC readings
This commit is contained in:
parent
cb73b71ffe
commit
3f4b8112fd
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)]
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
|
||||||
mod insert_coin;
|
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};
|
use insert_coin::{InsertCoin, SimplePwmCore, CoreConfig};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -155,7 +155,7 @@ impl Handler<hal::interrupt::typelevel::EXTI7_0> for Test {
|
||||||
unsafe fn on_interrupt() {
|
unsafe fn on_interrupt() {
|
||||||
println!("on_interrupt()");
|
println!("on_interrupt()");
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
clear_interrupt(4, 6);
|
clear_interrupt(2, 6);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -228,12 +228,26 @@ fn main() -> ! {
|
||||||
|
|
||||||
// === input setup ===
|
// === 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
|
// definitions
|
||||||
let coin_pin = p.PD4;
|
let coin_pin = p.PC2;
|
||||||
let button_pin = p.PD6;
|
let button_pin = p.PD6;
|
||||||
println!("coin pin: {} | coin port: {}", coin_pin.pin(), coin_pin.port());
|
println!("coin pin: {} | coin port: {}", coin_pin.pin(), coin_pin.port());
|
||||||
println!("push pin: {} | push port: {}", button_pin.pin(), button_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
|
// set up interrupts
|
||||||
unsafe {init_gpio_irq(coin_pin.pin(), coin_pin.port(), false, true)};
|
unsafe {init_gpio_irq(coin_pin.pin(), coin_pin.port(), false, true)};
|
||||||
unsafe {init_gpio_irq(button_pin.pin(), button_pin.port(), true, true)};
|
unsafe {init_gpio_irq(button_pin.pin(), button_pin.port(), true, true)};
|
||||||
|
|
@ -282,14 +296,22 @@ fn main() -> ! {
|
||||||
let mut lp_timer = TickTimerService::new(lp_timer_data, false);
|
let mut lp_timer = TickTimerService::new(lp_timer_data, false);
|
||||||
lp_timer.reset();
|
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;
|
let tick_interval_us = 1000000/interfaces.config.tick_rate_hz - 10;
|
||||||
|
|
||||||
// dac data
|
// dac data
|
||||||
let coin_sound = include_bytes!("../audio/sweep_dpcm_u4.raw");
|
let coin_sound = include_bytes!("../audio/sweep_dpcm_u4.raw");
|
||||||
let button_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.led0.set_amplitude(0);
|
||||||
interfaces.led1.set_amplitude(0);
|
interfaces.led1.set_amplitude(0);
|
||||||
|
|
@ -405,6 +427,7 @@ fn main() -> ! {
|
||||||
// timers
|
// timers
|
||||||
sp_timer.tick();
|
sp_timer.tick();
|
||||||
lp_timer.tick();
|
lp_timer.tick();
|
||||||
|
adc1_timer.tick();
|
||||||
|
|
||||||
if sp_timer.need_service() {
|
if sp_timer.need_service() {
|
||||||
println!("sp detect!");
|
println!("sp detect!");
|
||||||
|
|
@ -429,6 +452,16 @@ fn main() -> ! {
|
||||||
interfaces.led1.set_amplitude(0);
|
interfaces.led1.set_amplitude(0);
|
||||||
interfaces.service();
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delay.delay_us(tick_interval_us as u32);
|
delay.delay_us(tick_interval_us as u32);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue