Rust decode nfc payload #18
+13
-18
@@ -15,6 +15,9 @@ use base64::{Engine as _, engine::general_purpose};
|
|||||||
use display_interface_spi::SPIInterface;
|
use display_interface_spi::SPIInterface;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::Timer;
|
use embassy_time::Timer;
|
||||||
|
use display_interface_spi::SPIInterface;
|
||||||
|
use embedded_graphics::{Drawable, geometry::Size, primitives::Rectangle};
|
||||||
|
use embedded_graphics::Pixel;
|
||||||
use embedded_graphics::mono_font::MonoTextStyle;
|
use embedded_graphics::mono_font::MonoTextStyle;
|
||||||
use embedded_graphics::mono_font::ascii::FONT_6X10;
|
use embedded_graphics::mono_font::ascii::FONT_6X10;
|
||||||
use embedded_graphics::pixelcolor::Rgb565;
|
use embedded_graphics::pixelcolor::Rgb565;
|
||||||
@@ -440,8 +443,7 @@ where
|
|||||||
// Bitwise operations are slightly faster than division/modulo
|
// Bitwise operations are slightly faster than division/modulo
|
||||||
let byte_index = pixel_index >> 1;
|
let byte_index = pixel_index >> 1;
|
||||||
let pixel_byte = sprite[byte_index];
|
let pixel_byte = sprite[byte_index];
|
||||||
|
let color_index = if pixel_index.is_multiple_of(2) {
|
||||||
let color_index = if pixel_index & 1 == 0 {
|
|
||||||
(pixel_byte >> 4) & 0x0F
|
(pixel_byte >> 4) & 0x0F
|
||||||
} else {
|
} else {
|
||||||
pixel_byte & 0x0F
|
pixel_byte & 0x0F
|
||||||
@@ -449,24 +451,13 @@ where
|
|||||||
|
|
||||||
let color = palette565[color_index as usize];
|
let color = palette565[color_index as usize];
|
||||||
|
|
||||||
let start_x = (x * scale) as i32;
|
let width = u32::try_from(end_x - start_x).unwrap();
|
||||||
let start_y = (y * scale) as i32;
|
let height = u32::try_from(end_y - start_y).unwrap();
|
||||||
let end_x = core::cmp::min(start_x + scale as i32, target_width as i32);
|
|
||||||
let end_y = core::cmp::min(start_y + scale as i32, target_width as i32);
|
|
||||||
|
|
||||||
let width = (end_x - start_x) as u32;
|
let area = Rectangle::new(Point::new(start_x.try_into().unwrap(), start_y.try_into().unwrap()), Size::new(width, height));
|
||||||
let height = (end_y - start_y) as u32;
|
|
||||||
|
|
||||||
if width == 0 || height == 0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// OPTIMIZATION 2: Draw a rectangle block.
|
let _ = ili9341.fill_solid(&area, color);
|
||||||
// The display driver sets the SPI window ONCE per block.
|
|
||||||
let rect = Rectangle::new(Point::new(start_x, start_y), Size::new(width, height));
|
|
||||||
let style = PrimitiveStyle::with_fill(color);
|
|
||||||
|
|
||||||
let _ = rect.into_styled(style).draw(ili9341);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -630,10 +621,14 @@ async fn main(spawner: Spawner) {
|
|||||||
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
||||||
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
||||||
|
|
||||||
|
|
||||||
|
let freq = Rate::from_khz(60_000);
|
||||||
|
info!("Display freq: {freq}");
|
||||||
|
|
||||||
let spi_bus = Spi::new(
|
let spi_bus = Spi::new(
|
||||||
peripherals.SPI2,
|
peripherals.SPI2,
|
||||||
Config::default()
|
Config::default()
|
||||||
.with_frequency(Rate::from_mhz(40))
|
.with_frequency(freq)
|
||||||
.with_mode(Mode::_0),
|
.with_mode(Mode::_0),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
Reference in New Issue
Block a user