fw-rust: Create a PWM signal for the backlight
To have a dimmable backlight, generate a variable duty-cycle PWM signal which is consumed by the backlight driver circuit.
This commit is contained in:
parent
d2772291bf
commit
aa59bc302d
3 changed files with 29 additions and 8 deletions
|
@ -1,20 +1,39 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use atmega_hal::{clock::MHz8, delay::Delay, pins, Peripherals};
|
||||
use embedded_hal::blocking::delay::DelayMs;
|
||||
use atmega_hal::{pins, Peripherals};
|
||||
use avr_device::interrupt;
|
||||
use panic_halt as _;
|
||||
|
||||
#[atmega_hal::entry]
|
||||
fn main() -> ! {
|
||||
// Disable interrupts when initializing
|
||||
interrupt::disable();
|
||||
|
||||
// Get peripherals and pins
|
||||
let dp = Peripherals::take().unwrap();
|
||||
let pins = pins!(dp);
|
||||
|
||||
let mut led = pins.pd5.into_output();
|
||||
let mut delay = Delay::<MHz8>::new();
|
||||
// Init display backlight
|
||||
let tc0 = dp.TC0;
|
||||
tc0.tccr0a.write(|w| {
|
||||
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();
|
||||
|
||||
loop {
|
||||
led.toggle();
|
||||
delay.delay_ms(255_u8);
|
||||
}
|
||||
// Enable interrupts
|
||||
unsafe { interrupt::enable() };
|
||||
|
||||
#[allow(clippy::empty_loop)]
|
||||
loop {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue