#![no_std]
#![no_main]
#![allow(clippy::uninlined_format_args)]
#[cfg(feature = "defmt")]
use defmt_rtt as _;
use embedded_graphics::geometry::Point;
use embedded_graphics::mono_font::ascii::FONT_5X7;
use embedded_graphics::mono_font::MonoTextStyleBuilder;
use embedded_graphics::prelude::RgbColor;
use embedded_graphics::text::Alignment;
use embedded_graphics::text::Text;
use embedded_graphics::Drawable;
use esp_backtrace as _;
use esp_hal::clock::CpuClock;
use esp_hal::gpio::Pin;
use esp_hal::main;
use esp_hal::time::Rate;
use esp_hub75::framebuffer::bitplane::plain::DmaFrameBuffer;
use esp_hub75::framebuffer::compute_rows;
use esp_hub75::Color;
use esp_hub75::Hub75;
use esp_hub75::Hub75Pins16;
esp_bootloader_esp_idf::esp_app_desc!();
const ROWS: usize = 64;
const COLS: usize = 64;
const NROWS: usize = compute_rows(ROWS);
const PLANES: usize = 7;
type FBType = DmaFrameBuffer<NROWS, COLS, PLANES>;
macro_rules! mk_static {
($t:ty,$val:expr) => {{
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
#[deny(unused_attributes)]
let x = STATIC_CELL.uninit().write($val);
x
}};
}
#[main]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));
let tx_descriptors = esp_hub75::hub75_dma_descriptors!(FBType);
let pins = Hub75Pins16 {
red1: peripherals.GPIO16.degrade(),
grn1: peripherals.GPIO4.degrade(),
blu1: peripherals.GPIO17.degrade(),
red2: peripherals.GPIO18.degrade(),
grn2: peripherals.GPIO5.degrade(),
blu2: peripherals.GPIO19.degrade(),
addr0: peripherals.GPIO15.degrade(),
addr1: peripherals.GPIO13.degrade(),
addr2: peripherals.GPIO12.degrade(),
addr3: peripherals.GPIO14.degrade(),
addr4: peripherals.GPIO2.degrade(),
blank: peripherals.GPIO25.degrade(),
clock: peripherals.GPIO27.degrade(),
latch: peripherals.GPIO26.degrade(),
};
let fb = mk_static!(FBType, FBType::new());
let text_style = MonoTextStyleBuilder::new()
.font(&FONT_5X7)
.text_color(Color::YELLOW)
.background_color(Color::BLACK)
.build();
let point = Point::new(32, 31);
Text::with_alignment("Hello, World!", point, text_style, Alignment::Center)
.draw(fb)
.expect("failed to draw text");
let _hub75 = Hub75::new(
peripherals.I2S0,
pins,
peripherals.DMA_I2S0,
tx_descriptors,
Rate::from_mhz(20),
&*fb,
)
.expect("failed to create Hub75");
loop {
core::hint::spin_loop();
}
}