work towards interrupts
This commit is contained in:
parent
85077d4f1e
commit
5be93cc32e
1 changed files with 42 additions and 3 deletions
|
|
@ -4,9 +4,11 @@
|
||||||
#![feature(impl_trait_in_assoc_type)]
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
|
||||||
use adpcm_pwm_dac::dac::DpcmDac;
|
use adpcm_pwm_dac::dac::DpcmDac;
|
||||||
use hal::delay::Delay;
|
|
||||||
use hal::gpio::{AnyPin, Level, Output, Pin};
|
|
||||||
use {ch32_hal as hal};
|
use {ch32_hal as hal};
|
||||||
|
use hal::peripherals::EXTI4;
|
||||||
|
use hal::{bind_interrupts, interrupt};
|
||||||
|
use hal::delay::Delay;
|
||||||
|
use hal::gpio::{AnyPin, Level, Input, Output, Pin, Pull};
|
||||||
use hal::time::Hertz;
|
use hal::time::Hertz;
|
||||||
use hal::timer::low_level::CountingMode;
|
use hal::timer::low_level::CountingMode;
|
||||||
use hal::timer::simple_pwm::{PwmPin, SimplePwm};
|
use hal::timer::simple_pwm::{PwmPin, SimplePwm};
|
||||||
|
|
@ -30,6 +32,7 @@ const DPCM_DAC_DATA: [u8; 4] = [0xBB, 0xBB, 0xAA, 0xAA];
|
||||||
// const DATA2: [u8; 1] = [0x00u8];
|
// const DATA2: [u8; 1] = [0x00u8];
|
||||||
|
|
||||||
|
|
||||||
|
static mut IRQ1_FLAG: bool = false;
|
||||||
|
|
||||||
struct SimplePwmDacPin<'d, T: GeneralInstance16bit>{
|
struct SimplePwmDacPin<'d, T: GeneralInstance16bit>{
|
||||||
pin: SimplePwm<'d, T>,
|
pin: SimplePwm<'d, T>,
|
||||||
|
|
@ -95,6 +98,15 @@ fn pwm_blink<T: GeneralInstance16bit>(mut pwm_dac_pin: SimplePwmDacPin<'_, T>) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
#[qingke_rt::interrupt]
|
||||||
|
fn EXTI4(){
|
||||||
|
unsafe{IRQ1_FLAG = true;};
|
||||||
|
}
|
||||||
|
// bind_interrupts!(struct Irqs {
|
||||||
|
// EXTI4 => button_press();
|
||||||
|
// });
|
||||||
|
|
||||||
#[qingke_rt::entry]
|
#[qingke_rt::entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let mut config = hal::Config::default();
|
let mut config = hal::Config::default();
|
||||||
|
|
@ -102,6 +114,12 @@ fn main() -> ! {
|
||||||
let p = hal::init(config);
|
let p = hal::init(config);
|
||||||
|
|
||||||
|
|
||||||
|
// button 1 setup
|
||||||
|
// let b1 = Input::new(p.PA2, Pull::Up);
|
||||||
|
|
||||||
|
// p.EXTI4
|
||||||
|
let ei = hal::exti::ExtiInput::new(p.PD4, p.EXTI4, Pull::Up);
|
||||||
|
|
||||||
// let led_pin = PwmPin::new_ch4::<0>(p.PD0);
|
// let led_pin = PwmPin::new_ch4::<0>(p.PD0);
|
||||||
// let ch = hal::timer::Channel::Ch4;
|
// let ch = hal::timer::Channel::Ch4;
|
||||||
// let mut pwm = SimplePwm::new(
|
// let mut pwm = SimplePwm::new(
|
||||||
|
|
@ -120,6 +138,8 @@ fn main() -> ! {
|
||||||
// LED output setup
|
// LED output setup
|
||||||
let mut led = Output::new(p.PD0, Level::Low, Default::default());
|
let mut led = Output::new(p.PD0, Level::Low, Default::default());
|
||||||
|
|
||||||
|
// LED1 output setup
|
||||||
|
let mut led1 = Output::new(p.PD6, Level::High, Default::default());
|
||||||
|
|
||||||
|
|
||||||
// PWM DAC output pin setup
|
// PWM DAC output pin setup
|
||||||
|
|
@ -160,10 +180,22 @@ fn main() -> ! {
|
||||||
let led_blink_rate_hz = 3;
|
let led_blink_rate_hz = 3;
|
||||||
let led_tick_per_service = (tick_rate_hz/(led_blink_rate_hz * 2));
|
let led_tick_per_service = (tick_rate_hz/(led_blink_rate_hz * 2));
|
||||||
|
|
||||||
|
// LED1 servicer vars
|
||||||
|
let mut led1_need_service = false;
|
||||||
|
|
||||||
|
|
||||||
// pwm_blink(pwm_dac_pin);
|
// pwm_blink(pwm_dac_pin);
|
||||||
let mut tick: usize = 0;
|
let mut tick: usize = 0;
|
||||||
loop{
|
loop{
|
||||||
|
// handle IRQ flags
|
||||||
|
unsafe {
|
||||||
|
if(IRQ1_FLAG) {
|
||||||
|
led1_need_service = true;
|
||||||
|
// led_active = true;
|
||||||
|
IRQ1_FLAG = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let dac_need_service = ((tick % dac_tick_per_service) == 0);
|
let dac_need_service = ((tick % dac_tick_per_service) == 0);
|
||||||
if(dac_need_service && dac_active) {
|
if(dac_need_service && dac_active) {
|
||||||
dac_active = dac.output_next();
|
dac_active = dac.output_next();
|
||||||
|
|
@ -173,6 +205,12 @@ fn main() -> ! {
|
||||||
if(led_need_service && led_active) {
|
if(led_need_service && led_active) {
|
||||||
led.toggle();
|
led.toggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if led1_need_service {
|
||||||
|
led1.set_low();
|
||||||
|
led1_need_service = false;
|
||||||
|
}
|
||||||
|
|
||||||
tick = tick.wrapping_add(1);
|
tick = tick.wrapping_add(1);
|
||||||
delay.delay_us(tick_interval as u32);
|
delay.delay_us(tick_interval as u32);
|
||||||
};
|
};
|
||||||
|
|
@ -182,4 +220,5 @@ fn main() -> ! {
|
||||||
#[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