Prepare adc usage
This commit is contained in:
parent
99df32a0b9
commit
38e294b619
1 changed files with 18 additions and 2 deletions
|
@ -4,11 +4,13 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
use alloc::string::ToString;
|
||||||
use bsp::entry;
|
use bsp::entry;
|
||||||
use defmt::*;
|
use defmt::*;
|
||||||
use defmt_rtt as _;
|
use defmt_rtt as _;
|
||||||
use embedded_hal::digital::v2::OutputPin;
|
use embedded_hal::digital::v2::OutputPin;
|
||||||
use embedded_time::fixed_point::FixedPoint;
|
|
||||||
use panic_probe as _;
|
use panic_probe as _;
|
||||||
|
|
||||||
// Provide an alias for our BSP so we can switch targets quickly.
|
// Provide an alias for our BSP so we can switch targets quickly.
|
||||||
|
@ -22,8 +24,11 @@ use bsp::hal::{
|
||||||
sio::Sio,
|
sio::Sio,
|
||||||
usb::UsbBus,
|
usb::UsbBus,
|
||||||
watchdog::Watchdog,
|
watchdog::Watchdog,
|
||||||
|
Adc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use embedded_hal::adc::OneShot;
|
||||||
|
|
||||||
use usb_device::{class_prelude::*, prelude::*};
|
use usb_device::{class_prelude::*, prelude::*};
|
||||||
use usbd_serial::SerialPort;
|
use usbd_serial::SerialPort;
|
||||||
|
|
||||||
|
@ -84,6 +89,12 @@ fn main() -> ! {
|
||||||
.device_class(2) // from: https://www.usb.org/defined-class-codes
|
.device_class(2) // from: https://www.usb.org/defined-class-codes
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
let mut adc = Adc::new(pac.ADC, &mut pac.RESETS);
|
||||||
|
|
||||||
|
let mut adc_pin_0 = pins.gpio26.into_floating_input();
|
||||||
|
// let mut adc_pin_1 = pins.gpio27.into_floating_input();
|
||||||
|
// let mut adc_pin_2 = pins.gpio28.into_floating_input();
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -98,7 +109,12 @@ fn main() -> ! {
|
||||||
|
|
||||||
if i == 100 {
|
if i == 100 {
|
||||||
i = 0;
|
i = 0;
|
||||||
serial_send(&mut serial, "test");
|
|
||||||
|
let adc_0_value: u16 = adc.read(&mut adc_pin_0).unwrap();
|
||||||
|
// let adc_1_value: u16 = adc.read(&mut adc_pin_1).unwrap();
|
||||||
|
// let adc_2_value: u16 = adc.read(&mut adc_pin_2).unwrap();
|
||||||
|
|
||||||
|
serial_send(&mut serial, &adc_0_value.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
delay.delay_ms(8);
|
delay.delay_ms(8);
|
||||||
|
|
Loading…
Reference in a new issue