4 // Panic provider crate
5 use panic_persist as _;
7 // Used to set the program entry point
8 use cortex_m_rt::entry;
10 extern crate feather_m4 as hal;
13 use hal::clock::GenericClockController;
14 use hal::pac::{CorePeripherals,Peripherals};
16 use hal::delay::Delay;
18 use hal::{i2c_master,spi_master};
19 use hal::time::U32Ext;
21 use rtt_target::{rprintln, rtt_init_print};
23 use embedded_graphics::{
24 fonts::{Font8x16, Text},
27 style::TextStyleBuilder,
30 use bbq10kbd::{Bbq10Kbd, KeyRaw};
34 use ili9341::{Ili9341, Orientation};
39 Ok(()) => cortex_m::peripheral::SCB::sys_reset(),
44 fn inner_main() -> Result<(), &'static str> {
45 let mut peripherals = Peripherals::take().ok_or("Error getting board!")?;
46 let mut _pins = Pins::new(peripherals.PORT);
47 let _core = CorePeripherals::take().unwrap();
49 let mut _rng: Trng = Trng::new(&mut peripherals.MCLK, peripherals.TRNG);
50 let mut _clocks = GenericClockController::with_external_32kosc(
52 &mut peripherals.MCLK,
53 &mut peripherals.OSC32KCTRL,
54 &mut peripherals.OSCCTRL,
55 &mut peripherals.NVMCTRL,
57 let mut delay = Delay::new(_core.SYST, &mut _clocks);
59 // use ChannelMode::NoBlockS
60 rtt_init_print!(NoBlockSkip, 4096);
62 if let Some(msg) = panic_persist::get_panic_message_utf8() {
65 rprintln!("Clean boot!");
68 let kbd_lcd_reset = _pins.d5;
69 let _stm_cs = _pins.d6;
70 let lcd_cs = _pins.d9;
71 let lcd_dc = _pins.d10;
73 // i2c keyboard interface
77 let kbd_i2c = i2c_master(
81 &mut peripherals.MCLK,
87 let mut kbd = Bbq10Kbd::new(kbd_i2c);
89 let lcd_spi = spi_master(
93 &mut peripherals.MCLK,
100 let mut lcd = Ili9341::new_spi(
102 lcd_cs.into_push_pull_output(&mut _pins.port),
103 lcd_dc.into_push_pull_output(&mut _pins.port),
104 kbd_lcd_reset.into_push_pull_output(&mut _pins.port),
108 lcd.set_orientation(Orientation::Landscape).unwrap();
110 let mut _buffy = [0u16; 24 * 32];
111 let mut buffy2 = [[0u16; 320]; 240];
113 let mut fbuffy = buffer::FrameBuffer::new(&mut buffy2);
115 // // rrrrr gggggg bbbbb
116 // buffy.iter_mut().for_each(|px| *px = 0b11111_000000_00000);
118 let mut style = TextStyleBuilder::new(Font8x16)
119 .text_color(Rgb565::WHITE)
120 .background_color(Rgb565::BLACK)
123 kbd.set_backlight(255).unwrap();
125 let vers = kbd.get_version().unwrap();
127 rprintln!("Vers: {:?}", vers);
129 kbd.sw_reset().unwrap();
130 delay.delay_ms(10u8);
132 let vers = kbd.get_version().unwrap();
134 rprintln!("Vers: {:?}", vers);
136 let mut cursor = Cursor { x: 0, y: 0 };
138 lcd.clear(Rgb565::BLACK).map_err(|_| "Fade to error")?;
139 fbuffy.clear(Rgb565::BLACK).map_err(|_| "Fade to error")?;
142 let key = kbd.get_fifo_key_raw().map_err(|_| "bad fifo")?;
146 KeyRaw::Pressed(6) => {
147 style = TextStyleBuilder::new(Font8x16)
148 .text_color(Rgb565::WHITE)
149 .background_color(Rgb565::BLACK)
153 KeyRaw::Pressed(17) => {
154 style = TextStyleBuilder::new(Font8x16)
155 .text_color(Rgb565::RED)
156 .background_color(Rgb565::BLACK)
160 KeyRaw::Pressed(7) => {
161 style = TextStyleBuilder::new(Font8x16)
162 .text_color(Rgb565::GREEN)
163 .background_color(Rgb565::BLACK)
167 KeyRaw::Pressed(18) => {
168 style = TextStyleBuilder::new(Font8x16)
169 .text_color(Rgb565::BLUE)
170 .background_color(Rgb565::BLACK)
174 KeyRaw::Pressed(1) => {
178 KeyRaw::Pressed(2) => {
182 KeyRaw::Pressed(3) => {
186 KeyRaw::Pressed(4) => {
190 KeyRaw::Pressed(5) => {
191 kbd.sw_reset().unwrap();
192 cursor = Cursor { x: 0, y: 0 };
193 fbuffy.clear(Rgb565::BLACK).map_err(|_| "Fade to error")?;
196 KeyRaw::Pressed(8) => {
198 Text::new(" ", cursor.pos())
201 .map_err(|_| "bad lcd")?;
204 KeyRaw::Pressed(10) => {
207 KeyRaw::Pressed(k) => {
208 rprintln!("Got key {}", k);
209 if let Ok(s) = core::str::from_utf8(&[k]) {
210 Text::new(s, cursor.pos())
213 .map_err(|_| "bad lcd")?;
219 if let Some(buf) = fbuffy.inner() {
220 // timer.start(1_000_000u32);
221 lcd.draw_raw(0, 0, 319, 239, buf).map_err(|_| "bad buffy")?;
222 // let done = timer.read();
223 // rprintln!("Drew in {}ms.", done / 1000);
225 delay.delay_ms(38u8);
265 fn right(&mut self) {
273 fn enter(&mut self) {
280 fn pos(&self) -> Point {
281 Point::new(self.x * 8, self.y * 16)