fw-rust: Use chip-generic interrupt utilities
Instead of manually enabling and disabling interrupts use the chip-generic interrupt utilities.
This commit is contained in:
parent
a688d4c5ed
commit
8315560daa
1 changed files with 99 additions and 103 deletions
|
@ -63,127 +63,123 @@ static ONDERS_ORG: [[u8; 48]; 2] = [
|
||||||
|
|
||||||
#[atmega_hal::entry]
|
#[atmega_hal::entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
// Disable interrupts when initializing
|
interrupt::free(|_cs| {
|
||||||
interrupt::disable();
|
// Get peripherals, pins and delay
|
||||||
|
let dp = Peripherals::take().unwrap();
|
||||||
|
let pins = pins!(dp);
|
||||||
|
let mut delay = Delay::<MHz8>::new();
|
||||||
|
|
||||||
// Get peripherals, pins and delay
|
// Init display backlight
|
||||||
let dp = Peripherals::take().unwrap();
|
let tc0 = dp.TC0;
|
||||||
let pins = pins!(dp);
|
tc0.tccr0a.write(|w| {
|
||||||
let mut delay = Delay::<MHz8>::new();
|
w.wgm0().pwm_fast();
|
||||||
|
w.com0b().match_clear();
|
||||||
|
w
|
||||||
|
});
|
||||||
|
tc0.tccr0b.write(|w| {
|
||||||
|
w.wgm02().set_bit();
|
||||||
|
w.cs0().prescale_64();
|
||||||
|
w
|
||||||
|
});
|
||||||
|
tc0.ocr0a.write(|w| unsafe { w.bits(255) });
|
||||||
|
// TODO: Use EEPROM
|
||||||
|
tc0.ocr0b.write(|w| unsafe { w.bits(0) });
|
||||||
|
pins.pd5.into_output();
|
||||||
|
|
||||||
// Init display backlight
|
// Init SPI
|
||||||
let tc0 = dp.TC0;
|
let (mut spi, _) = Spi::new(
|
||||||
tc0.tccr0a.write(|w| {
|
dp.SPI,
|
||||||
w.wgm0().pwm_fast();
|
pins.pb5.into_output(),
|
||||||
w.com0b().match_clear();
|
pins.pb3.into_output(),
|
||||||
w
|
pins.pb4.into_pull_up_input(),
|
||||||
});
|
pins.pb2.into_output(),
|
||||||
tc0.tccr0b.write(|w| {
|
Settings {
|
||||||
w.wgm02().set_bit();
|
data_order: DataOrder::MostSignificantFirst,
|
||||||
w.cs0().prescale_64();
|
clock: SerialClockRate::OscfOver2,
|
||||||
w
|
mode: Mode {
|
||||||
});
|
polarity: Polarity::IdleLow,
|
||||||
tc0.ocr0a.write(|w| unsafe { w.bits(255) });
|
phase: Phase::CaptureOnFirstTransition,
|
||||||
// TODO: Use EEPROM
|
},
|
||||||
tc0.ocr0b.write(|w| unsafe { w.bits(0) });
|
|
||||||
pins.pd5.into_output();
|
|
||||||
|
|
||||||
// Init SPI
|
|
||||||
let (mut spi, _) = Spi::new(
|
|
||||||
dp.SPI,
|
|
||||||
pins.pb5.into_output(),
|
|
||||||
pins.pb3.into_output(),
|
|
||||||
pins.pb4.into_pull_up_input(),
|
|
||||||
pins.pb2.into_output(),
|
|
||||||
Settings {
|
|
||||||
data_order: DataOrder::MostSignificantFirst,
|
|
||||||
clock: SerialClockRate::OscfOver2,
|
|
||||||
mode: Mode {
|
|
||||||
polarity: Polarity::IdleLow,
|
|
||||||
phase: Phase::CaptureOnFirstTransition,
|
|
||||||
},
|
},
|
||||||
},
|
);
|
||||||
);
|
|
||||||
|
|
||||||
// Init LCD
|
// Init LCD
|
||||||
let mut lcd_cd = pins.pb0.into_output();
|
let mut lcd_cd = pins.pb0.into_output();
|
||||||
let mut lcd_rst = pins.pb1.into_output();
|
let mut lcd_rst = pins.pb1.into_output();
|
||||||
// TODO: Test if delay is really needed
|
// TODO: Test if delay is really needed
|
||||||
delay.delay_ms(1_u8);
|
|
||||||
lcd_rst.set_high();
|
|
||||||
// TODO: Try to reduce delay to a minimum
|
|
||||||
delay.delay_ms(5_u8);
|
|
||||||
|
|
||||||
block!(spi.send(0x40)).unwrap(); // (6) Set Scroll Line: Display start line 0
|
|
||||||
block!(spi.send(0xA1)).unwrap(); // (13) Set SEG direction: SEG reverse
|
|
||||||
block!(spi.send(0xC0)).unwrap(); // (14) Set COM direction: Normal COM0 - COM63
|
|
||||||
block!(spi.send(0xA6)).unwrap(); // (11) Set Inverse Display: Display inverse off
|
|
||||||
block!(spi.send(0xA2)).unwrap(); // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65)
|
|
||||||
block!(spi.send(0x2F)).unwrap(); // (5) Set Power Control: Booster, Regulator and Follower on
|
|
||||||
block!(spi.send(0x27)).unwrap(); // (8) Set VLCD Resistor Ratio: Set Contrast
|
|
||||||
block!(spi.send(0x81)).unwrap(); // (9) Set Electronic Volume: Set Contrast
|
|
||||||
block!(spi.send(0x08)).unwrap(); // (9) Set Electronic Volume: Set Contrast // TODO: Use EEPROM
|
|
||||||
block!(spi.send(0xAF)).unwrap(); // (12) Set Display Enable: Display on
|
|
||||||
|
|
||||||
// Clear screen
|
|
||||||
for page in 0..8 {
|
|
||||||
block!(spi.send(0x00)).unwrap();
|
|
||||||
block!(spi.send(0x10)).unwrap();
|
|
||||||
block!(spi.send(0xB0 + page)).unwrap();
|
|
||||||
|
|
||||||
// TODO: This delay fixes issues, try find a better solution
|
|
||||||
delay.delay_ms(1_u8);
|
delay.delay_ms(1_u8);
|
||||||
lcd_cd.set_high();
|
lcd_rst.set_high();
|
||||||
|
// TODO: Try to reduce delay to a minimum
|
||||||
|
delay.delay_ms(5_u8);
|
||||||
|
|
||||||
for _ in 0..102 {
|
block!(spi.send(0x40)).unwrap(); // (6) Set Scroll Line: Display start line 0
|
||||||
|
block!(spi.send(0xA1)).unwrap(); // (13) Set SEG direction: SEG reverse
|
||||||
|
block!(spi.send(0xC0)).unwrap(); // (14) Set COM direction: Normal COM0 - COM63
|
||||||
|
block!(spi.send(0xA6)).unwrap(); // (11) Set Inverse Display: Display inverse off
|
||||||
|
block!(spi.send(0xA2)).unwrap(); // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65)
|
||||||
|
block!(spi.send(0x2F)).unwrap(); // (5) Set Power Control: Booster, Regulator and Follower on
|
||||||
|
block!(spi.send(0x27)).unwrap(); // (8) Set VLCD Resistor Ratio: Set Contrast
|
||||||
|
block!(spi.send(0x81)).unwrap(); // (9) Set Electronic Volume: Set Contrast
|
||||||
|
block!(spi.send(0x08)).unwrap(); // (9) Set Electronic Volume: Set Contrast // TODO: Use EEPROM
|
||||||
|
block!(spi.send(0xAF)).unwrap(); // (12) Set Display Enable: Display on
|
||||||
|
|
||||||
|
// Clear screen
|
||||||
|
for page in 0..8 {
|
||||||
block!(spi.send(0x00)).unwrap();
|
block!(spi.send(0x00)).unwrap();
|
||||||
|
block!(spi.send(0x10)).unwrap();
|
||||||
|
block!(spi.send(0xB0 + page)).unwrap();
|
||||||
|
|
||||||
|
// TODO: This delay fixes issues, try find a better solution
|
||||||
|
delay.delay_ms(1_u8);
|
||||||
|
lcd_cd.set_high();
|
||||||
|
|
||||||
|
for _ in 0..102 {
|
||||||
|
block!(spi.send(0x00)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: This delay fixes issues, try find a better solution
|
||||||
|
delay.delay_ms(1_u8);
|
||||||
|
lcd_cd.set_low();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This delay fixes issues, try find a better solution
|
// Draw sacred chao
|
||||||
delay.delay_ms(1_u8);
|
for (i, page) in SACRED_CHAO.iter().enumerate() {
|
||||||
lcd_cd.set_low();
|
block!(spi.send(0x0F)).unwrap();
|
||||||
}
|
block!(spi.send(0x11)).unwrap();
|
||||||
|
block!(spi.send(0xB1 + i as u8)).unwrap();
|
||||||
|
|
||||||
// Draw sacred chao
|
// TODO: This delay fixes issues, try find a better solution
|
||||||
for (i, page) in SACRED_CHAO.iter().enumerate() {
|
delay.delay_ms(1_u8);
|
||||||
block!(spi.send(0x0F)).unwrap();
|
lcd_cd.set_high();
|
||||||
block!(spi.send(0x11)).unwrap();
|
|
||||||
block!(spi.send(0xB1 + i as u8)).unwrap();
|
|
||||||
|
|
||||||
// TODO: This delay fixes issues, try find a better solution
|
for segment in page {
|
||||||
delay.delay_ms(1_u8);
|
block!(spi.send(*segment)).unwrap();
|
||||||
lcd_cd.set_high();
|
}
|
||||||
|
|
||||||
for segment in page {
|
// TODO: This delay fixes issues, try find a better solution
|
||||||
block!(spi.send(*segment)).unwrap();
|
delay.delay_ms(1_u8);
|
||||||
|
lcd_cd.set_low();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This delay fixes issues, try find a better solution
|
// Draw onders.org
|
||||||
delay.delay_ms(1_u8);
|
for (i, page) in ONDERS_ORG.iter().enumerate() {
|
||||||
lcd_cd.set_low();
|
block!(spi.send(0x0A)).unwrap();
|
||||||
}
|
block!(spi.send(0x11)).unwrap();
|
||||||
|
block!(spi.send(0xB6 + i as u8)).unwrap();
|
||||||
|
|
||||||
// Draw onders.org
|
// TODO: This delay fixes issues, try find a better solution
|
||||||
for (i, page) in ONDERS_ORG.iter().enumerate() {
|
delay.delay_ms(1_u8);
|
||||||
block!(spi.send(0x0A)).unwrap();
|
lcd_cd.set_high();
|
||||||
block!(spi.send(0x11)).unwrap();
|
|
||||||
block!(spi.send(0xB6 + i as u8)).unwrap();
|
|
||||||
|
|
||||||
// TODO: This delay fixes issues, try find a better solution
|
for segment in page {
|
||||||
delay.delay_ms(1_u8);
|
block!(spi.send(*segment)).unwrap();
|
||||||
lcd_cd.set_high();
|
}
|
||||||
|
|
||||||
for segment in page {
|
// TODO: This delay fixes issues, try find a better solution
|
||||||
block!(spi.send(*segment)).unwrap();
|
delay.delay_ms(1_u8);
|
||||||
|
lcd_cd.set_low();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// TODO: This delay fixes issues, try find a better solution
|
|
||||||
delay.delay_ms(1_u8);
|
|
||||||
lcd_cd.set_low();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable interrupts
|
|
||||||
unsafe { interrupt::enable() };
|
|
||||||
|
|
||||||
#[allow(clippy::empty_loop)]
|
#[allow(clippy::empty_loop)]
|
||||||
loop {}
|
loop {}
|
||||||
|
|
Loading…
Reference in a new issue