add AdcCore for ADC measurement
This commit is contained in:
parent
f4759a0c71
commit
5288cba869
2 changed files with 27 additions and 2 deletions
|
|
@ -301,6 +301,7 @@ pub struct Sequences {
|
|||
// things that touch hardware
|
||||
pub struct Interfaces {
|
||||
pub pwm_core: SimplePwmCore<'static, ch32_hal::peripherals::TIM1>,
|
||||
pub adc_core: crate::AdcCore,
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,30 @@ use crate::app::sequencer::{DynamicSequence, SequenceEntry};
|
|||
|
||||
static LED0_SEQ: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
||||
|
||||
use hal::adc::Adc;
|
||||
use hal::peripherals::{ADC1, PD4};
|
||||
|
||||
pub struct AdcCore {
|
||||
adc: Adc<'static, ADC1>,
|
||||
battery_pin: PD4,
|
||||
}
|
||||
|
||||
impl AdcCore {
|
||||
pub fn new(mut adc: Adc<'static, ADC1>, pin: PD4) -> Self {
|
||||
adc.calibrate();
|
||||
Self {
|
||||
adc,
|
||||
battery_pin: pin,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make this a float or something
|
||||
pub fn get_battery_voltage(&mut self) -> u16 {
|
||||
self.adc
|
||||
.convert(&mut self.battery_pin, hal::adc::SampleTime::CYCLES241)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Flag {
|
||||
value: bool,
|
||||
|
|
@ -205,13 +229,13 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
|||
// adc
|
||||
let mut adc = hal::adc::Adc::new(p.ADC1, Default::default());
|
||||
let mut batt_monitor_pin = p.PD4;
|
||||
let adc_core = AdcCore::new(adc, batt_monitor_pin);
|
||||
|
||||
// adc2
|
||||
// let mut usb_detect_dc = hal::adc::Adc::new(p.ADC1, Default::default());
|
||||
let mut usb_detect_pin = p.PD5;
|
||||
|
||||
// println!("ADC_PIN CHANNEL: {}", adc_pin.channel().channel());
|
||||
let adc_cal = adc.calibrate();
|
||||
|
||||
// #[cfg(feature = "enable_print")]
|
||||
// println!("ADC calibration value: {}", adc_cal);
|
||||
|
|
@ -289,7 +313,7 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
|||
audio: &SEQUENCE_LIST,
|
||||
};
|
||||
|
||||
let app_interfaces = Interfaces { pwm_core };
|
||||
let app_interfaces = Interfaces { pwm_core, adc_core };
|
||||
|
||||
let mut app = App::new(app_config, app_services, app_sequences, app_interfaces);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue