initial setup to use interrupts for I/O
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -1,3 +1,4 @@
|
||||
#![feature(abi_avr_interrupt)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
@@ -40,6 +41,20 @@ pub const STACK_DEPTH: usize = 7;
|
||||
|
||||
type Calc = StackCalc<f32, STACK_DEPTH, 5, u8>;
|
||||
|
||||
// Interrupt driven I/O
|
||||
//
|
||||
// * Run timer at 100Hz (10ms) to step through segments.
|
||||
// * On each segment interrupt configure segments and enable output (LEDs on).
|
||||
// * Set another timer to run for 1ms.
|
||||
// * On another timer interrupt expire disable display (LEDs off) and handle keyboard input.
|
||||
|
||||
#[avr_device::interrupt(atmega328p)]
|
||||
fn TIMER1_OVF() {
|
||||
//TODO: Handle timer interrupt to display next segment
|
||||
// file:///home/hxd/projects/avr-calc/target/avr-none/doc/avr_device/interrupt/index.html
|
||||
// ...
|
||||
}
|
||||
|
||||
struct IOSelect<'p> {
|
||||
display_no: usize,
|
||||
pin: &'p mut Pin<Output>,
|
||||
@@ -442,8 +457,15 @@ fn main() -> ! {
|
||||
calculator: CalcluclatorState::EnterSignificant,
|
||||
};
|
||||
|
||||
// TODO: configure timer, enable it to interrupt: dp.TC1.tifr1
|
||||
|
||||
unsafe {
|
||||
avr_device::interrupt::enable();
|
||||
}
|
||||
|
||||
loop {
|
||||
let mut last_key_readout: Option<KeyReadout> = None;
|
||||
// Timing: 1ms display, 0.230ms read key; every 12ms/83Hz
|
||||
for (mut io_select, ss) in io.iter_mut().zip(display.iter_segments()) {
|
||||
ss.apply(&mut seg);
|
||||
io_select.set_on();
|
||||
|
||||
Reference in New Issue
Block a user