initial setup to use interrupts for I/O
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -36,6 +36,7 @@ name = "avr-calc"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arduino-hal",
|
"arduino-hal",
|
||||||
|
"avr-device",
|
||||||
"calc-math",
|
"calc-math",
|
||||||
"embedded-hal 1.0.0",
|
"embedded-hal 1.0.0",
|
||||||
"nb 1.1.0",
|
"nb 1.1.0",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ ufmt = "0.2.0"
|
|||||||
nb = "1.1.0"
|
nb = "1.1.0"
|
||||||
embedded-hal = "1.0"
|
embedded-hal = "1.0"
|
||||||
calc-math = { path = "../calc-math", features = ["ufmt"] }
|
calc-math = { path = "../calc-math", features = ["ufmt"] }
|
||||||
|
avr-device = "0.7.0"
|
||||||
|
|
||||||
[dependencies.arduino-hal]
|
[dependencies.arduino-hal]
|
||||||
git = "https://github.com/rahix/avr-hal"
|
git = "https://github.com/rahix/avr-hal"
|
||||||
|
|||||||
22
src/main.rs
22
src/main.rs
@@ -1,3 +1,4 @@
|
|||||||
|
#![feature(abi_avr_interrupt)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
@@ -40,6 +41,20 @@ pub const STACK_DEPTH: usize = 7;
|
|||||||
|
|
||||||
type Calc = StackCalc<f32, STACK_DEPTH, 5, u8>;
|
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> {
|
struct IOSelect<'p> {
|
||||||
display_no: usize,
|
display_no: usize,
|
||||||
pin: &'p mut Pin<Output>,
|
pin: &'p mut Pin<Output>,
|
||||||
@@ -442,8 +457,15 @@ fn main() -> ! {
|
|||||||
calculator: CalcluclatorState::EnterSignificant,
|
calculator: CalcluclatorState::EnterSignificant,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: configure timer, enable it to interrupt: dp.TC1.tifr1
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
avr_device::interrupt::enable();
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut last_key_readout: Option<KeyReadout> = None;
|
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()) {
|
for (mut io_select, ss) in io.iter_mut().zip(display.iter_segments()) {
|
||||||
ss.apply(&mut seg);
|
ss.apply(&mut seg);
|
||||||
io_select.set_on();
|
io_select.set_on();
|
||||||
|
|||||||
Reference in New Issue
Block a user