use crate::gpio::{NUM_COLS, NUM_ROWS};
use tiny_led_matrix::{Frame, Matrix, RowPlan};
pub struct MicrobitMatrix();
#[cfg(feature = "v1")]
const MICROBIT_LED_LAYOUT: [[Option<(usize, usize)>; 3]; 9] = [
[Some((0, 0)), Some((4, 2)), Some((2, 4))],
[Some((2, 0)), Some((0, 2)), Some((4, 4))],
[Some((4, 0)), Some((2, 2)), Some((0, 4))],
[Some((4, 3)), Some((1, 0)), Some((0, 1))],
[Some((3, 3)), Some((3, 0)), Some((1, 1))],
[Some((2, 3)), Some((3, 4)), Some((2, 1))],
[Some((1, 3)), Some((1, 4)), Some((3, 1))],
[Some((0, 3)), None, Some((4, 1))],
[Some((1, 2)), None, Some((3, 2))],
];
impl Matrix for MicrobitMatrix {
const MATRIX_COLS: usize = NUM_COLS;
const MATRIX_ROWS: usize = NUM_ROWS;
const IMAGE_COLS: usize = 5;
const IMAGE_ROWS: usize = 5;
#[cfg(feature = "v1")]
fn image_coordinates(col: usize, row: usize) -> Option<(usize, usize)> {
MICROBIT_LED_LAYOUT[col][row]
}
#[cfg(feature = "v2")]
fn image_coordinates(col: usize, row: usize) -> Option<(usize, usize)> {
Some((col, row))
}
}
#[derive(Copy, Clone, Debug)]
pub struct MicrobitFrame([RowPlan; MicrobitFrame::ROWS]);
impl MicrobitFrame {
pub const fn default() -> MicrobitFrame {
MicrobitFrame([RowPlan::default(); MicrobitFrame::ROWS])
}
}
impl Default for MicrobitFrame {
fn default() -> MicrobitFrame {
MicrobitFrame::default()
}
}
impl Frame for MicrobitFrame {
type Mtx = MicrobitMatrix;
fn row_plan(&self, row: usize) -> &RowPlan {
&self.0[row]
}
fn row_plan_mut(&mut self, row: usize) -> &mut RowPlan {
&mut self.0[row]
}
}