fw-rust: Prepare to implement Si5351 commands
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Show settings of Si5351 channels on home screen. Initialize I2c and
Si5351.
This commit is contained in:
finga 2022-04-01 01:12:51 +02:00
parent 134db298f6
commit 52bf0e6eec
8 changed files with 188 additions and 13 deletions

View file

@ -1,5 +1,10 @@
use super::{Draw, Event, Screens, Setup, Splash};
use crate::{lcd::Lcd, Input};
use crate::{
assets::{OFF, ON, PLL_A, PLL_B},
lcd::Lcd,
Input,
};
use si5351::PLL;
enum Selection {
Ch1,
@ -8,14 +13,53 @@ enum Selection {
Setup,
}
struct Channel {
freq: u32,
enabled: bool,
pll: PLL,
}
impl Channel {
fn print(&self, lcd: &mut Lcd, page: u8) {
lcd.print_freq(25, page, self.freq);
lcd.print_icon(91, page, if self.enabled { &ON } else { &OFF });
lcd.print_icon(
94,
page + 1,
match self.pll {
PLL::A => &PLL_A,
PLL::B => &PLL_B,
},
);
}
}
pub struct Home {
active: Selection,
channels: [Channel; 3],
}
impl Home {
pub fn new() -> Self {
Self {
active: Selection::Ch1,
channels: [
Channel {
freq: 0,
enabled: false,
pll: PLL::A,
},
Channel {
freq: 0,
enabled: false,
pll: PLL::A,
},
Channel {
freq: 0,
enabled: false,
pll: PLL::A,
},
],
}
}
@ -56,26 +100,38 @@ impl Draw for Home {
match &self.active {
Selection::Ch1 => {
lcd.print_inverted(0, 0, "CH1");
self.channels[0].print(lcd, 0);
lcd.print(0, 2, "CH2");
self.channels[1].print(lcd, 2);
lcd.print(0, 4, "CH3");
self.channels[2].print(lcd, 4);
lcd.print(33, 6, "SETUP");
}
Selection::Ch2 => {
lcd.print(0, 0, "CH1");
self.channels[0].print(lcd, 0);
lcd.print_inverted(0, 2, "CH2");
self.channels[1].print(lcd, 2);
lcd.print(0, 4, "CH3");
self.channels[2].print(lcd, 4);
lcd.print(33, 6, "SETUP");
}
Selection::Ch3 => {
lcd.print(0, 0, "CH1");
self.channels[0].print(lcd, 0);
lcd.print(0, 2, "CH2");
self.channels[1].print(lcd, 2);
lcd.print_inverted(0, 4, "CH3");
self.channels[2].print(lcd, 4);
lcd.print(33, 6, "SETUP");
}
Selection::Setup => {
lcd.print(0, 0, "CH1");
self.channels[0].print(lcd, 0);
lcd.print(0, 2, "CH2");
self.channels[1].print(lcd, 2);
lcd.print(0, 4, "CH3");
self.channels[2].print(lcd, 4);
lcd.print_inverted(33, 6, "SETUP");
}
}