#![no_std]
#![no_main]
use esp_hal::clock::CpuClock;
use esp_hal::main;
use embedded_graphics::{
pixelcolor::Rgb565,
prelude::*,
primitives::{Circle, PrimitiveStyleBuilder},
};
use defmt::{error, info};
use {defmt_rtt as _, esp_backtrace as _};
use m5dial_bsp::bsp;
extern crate alloc;
#[main]
fn main() -> ! {
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
let mut board = bsp::init(peripherals);
board.set_backlight(true);
const COLOR_LIST: [Rgb565; 7] = [
RgbColor::BLUE,
RgbColor::RED,
RgbColor::GREEN,
RgbColor::CYAN,
RgbColor::YELLOW,
RgbColor::MAGENTA,
RgbColor::WHITE,
];
let mut style_index: usize = 0;
esp_alloc::heap_allocator!(72 * 1024);
info!("On screen counter demo running!");
let (w, h) = board.display.bounds();
let mut point = Point::new((w / 2).into(), (h / 2).into());
let mut need_redraw = true;
loop {
if let Some(state) = board.has_button_changed() {
if state == false {
style_index = (style_index + 1) % COLOR_LIST.len();
need_redraw = true;
}
}
if let Some(_) = board.touch_count() {
let p = board.touch_position(0);
info!("Pos: x={} y={}", p.x, p.y);
point.x = p.x.into();
point.y = p.y.into();
need_redraw = true;
}
if need_redraw {
board.display.clear();
let style = PrimitiveStyleBuilder::new()
.stroke_color(COLOR_LIST[style_index])
.stroke_width(3)
.fill_color(Rgb565::BLACK)
.build();
Circle::with_center(point, 50)
.into_styled(style)
.draw(&mut board.display)
.unwrap();
if board.display.flush().is_err() {
error!("Display flush error");
}
need_redraw = false;
}
}
}