microbit_common/display/nonblocking/
matrix.rs1use crate::gpio::{NUM_COLS, NUM_ROWS};
10use tiny_led_matrix::{Frame, Matrix, RowPlan};
11
12pub struct MicrobitMatrix();
16
17#[cfg(feature = "v1")]
20const MICROBIT_LED_LAYOUT: [[Option<(usize, usize)>; 3]; 9] = [
21 [Some((0, 0)), Some((4, 2)), Some((2, 4))],
22 [Some((2, 0)), Some((0, 2)), Some((4, 4))],
23 [Some((4, 0)), Some((2, 2)), Some((0, 4))],
24 [Some((4, 3)), Some((1, 0)), Some((0, 1))],
25 [Some((3, 3)), Some((3, 0)), Some((1, 1))],
26 [Some((2, 3)), Some((3, 4)), Some((2, 1))],
27 [Some((1, 3)), Some((1, 4)), Some((3, 1))],
28 [Some((0, 3)), None, Some((4, 1))],
29 [Some((1, 2)), None, Some((3, 2))],
30];
31
32impl Matrix for MicrobitMatrix {
33 const MATRIX_COLS: usize = NUM_COLS;
35 const MATRIX_ROWS: usize = NUM_ROWS;
37 const IMAGE_COLS: usize = 5;
39 const IMAGE_ROWS: usize = 5;
41
42 #[cfg(feature = "v1")]
43 fn image_coordinates(col: usize, row: usize) -> Option<(usize, usize)> {
44 MICROBIT_LED_LAYOUT[col][row]
45 }
46
47 #[cfg(feature = "v2")]
48 fn image_coordinates(col: usize, row: usize) -> Option<(usize, usize)> {
49 Some((col, row))
50 }
51}
52
53#[derive(Copy, Clone, Debug)]
64pub struct MicrobitFrame([RowPlan; MicrobitFrame::ROWS]);
65
66impl MicrobitFrame {
67 pub const fn default() -> MicrobitFrame {
69 MicrobitFrame([RowPlan::default(); MicrobitFrame::ROWS])
70 }
71}
72
73impl Default for MicrobitFrame {
74 fn default() -> MicrobitFrame {
76 MicrobitFrame::default()
77 }
78}
79
80impl Frame for MicrobitFrame {
81 type Mtx = MicrobitMatrix;
82
83 fn row_plan(&self, row: usize) -> &RowPlan {
84 &self.0[row]
85 }
86
87 fn row_plan_mut(&mut self, row: usize) -> &mut RowPlan {
88 &mut self.0[row]
89 }
90}