|
1 | 1 | //! Display size
|
2 | 2 |
|
3 |
| -// TODO: Add to prelude |
4 |
| -/// Display size enumeration |
5 |
| -#[derive(Clone, Copy)] |
6 |
| -pub enum DisplaySize { |
7 |
| - /// 128 by 64 pixels |
8 |
| - Display128x64, |
9 |
| - /// 128 by 32 pixels |
10 |
| - Display128x32, |
11 |
| - /// 96 by 16 pixels |
12 |
| - Display96x16, |
13 |
| - /// 70 by 42 pixels |
14 |
| - Display72x40, |
15 |
| - /// 64 by 48 pixels |
16 |
| - Display64x48, |
| 3 | +use super::command::Command; |
| 4 | +use display_interface::{DisplayError, WriteOnlyDataCommand}; |
| 5 | +use generic_array::{ |
| 6 | + typenum::{U1024, U192, U360, U384, U512}, |
| 7 | + ArrayLength, |
| 8 | +}; |
| 9 | + |
| 10 | +/// Display information |
| 11 | +/// |
| 12 | +/// This trait describes information related to a particular display. |
| 13 | +/// This includes resolution, offset and framebuffer size. |
| 14 | +pub trait DisplaySize { |
| 15 | + /// Width in pixels |
| 16 | + const WIDTH: u8; |
| 17 | + |
| 18 | + /// Height in pixels |
| 19 | + const HEIGHT: u8; |
| 20 | + |
| 21 | + /// Horizontal offset in pixels |
| 22 | + const OFFSETX: u8 = 0; |
| 23 | + |
| 24 | + /// Vertical offset in pixels |
| 25 | + const OFFSETY: u8 = 0; |
| 26 | + |
| 27 | + /// Size of framebuffer. Because the display is monocrome, this is |
| 28 | + /// width * height / 8 |
| 29 | + type BufferSize: ArrayLength<u8>; |
| 30 | + |
| 31 | + /// Send resolution-dependent configuration to the display |
| 32 | + /// |
| 33 | + /// See [`Command::ComPinConfig`](../command/enum.Command.html#variant.ComPinConfig) |
| 34 | + /// for more information |
| 35 | + fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError>; |
17 | 36 | }
|
18 | 37 |
|
19 |
| -impl DisplaySize { |
20 |
| - /// Get integral dimensions from DisplaySize |
21 |
| - // TODO: Use whatever vec2 impl I decide to use here |
22 |
| - pub fn dimensions(self) -> (u8, u8) { |
23 |
| - match self { |
24 |
| - DisplaySize::Display128x64 => (128, 64), |
25 |
| - DisplaySize::Display128x32 => (128, 32), |
26 |
| - DisplaySize::Display96x16 => (96, 16), |
27 |
| - DisplaySize::Display72x40 => (72, 40), |
28 |
| - DisplaySize::Display64x48 => (64, 48), |
29 |
| - } |
| 38 | +/// Size information for the common 128x64 variants |
| 39 | +#[derive(Debug, Copy, Clone)] |
| 40 | +pub struct DisplaySize128x64; |
| 41 | +impl DisplaySize for DisplaySize128x64 { |
| 42 | + const WIDTH: u8 = 128; |
| 43 | + const HEIGHT: u8 = 64; |
| 44 | + type BufferSize = U1024; |
| 45 | + |
| 46 | + fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { |
| 47 | + Command::ComPinConfig(true, false).send(iface) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +/// Size information for the common 128x32 variants |
| 52 | +#[derive(Debug, Copy, Clone)] |
| 53 | +pub struct DisplaySize128x32; |
| 54 | +impl DisplaySize for DisplaySize128x32 { |
| 55 | + const WIDTH: u8 = 128; |
| 56 | + const HEIGHT: u8 = 32; |
| 57 | + type BufferSize = U512; |
| 58 | + |
| 59 | + fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { |
| 60 | + Command::ComPinConfig(false, false).send(iface) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +/// Size information for the common 96x16 variants |
| 65 | +#[derive(Debug, Copy, Clone)] |
| 66 | +pub struct DisplaySize96x16; |
| 67 | +impl DisplaySize for DisplaySize96x16 { |
| 68 | + const WIDTH: u8 = 96; |
| 69 | + const HEIGHT: u8 = 16; |
| 70 | + type BufferSize = U192; |
| 71 | + |
| 72 | + fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { |
| 73 | + Command::ComPinConfig(false, false).send(iface) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +/// Size information for the common 72x40 variants |
| 78 | +#[derive(Debug, Copy, Clone)] |
| 79 | +pub struct DisplaySize72x40; |
| 80 | +impl DisplaySize for DisplaySize72x40 { |
| 81 | + const WIDTH: u8 = 72; |
| 82 | + const HEIGHT: u8 = 40; |
| 83 | + const OFFSETX: u8 = 28; |
| 84 | + const OFFSETY: u8 = 0; |
| 85 | + type BufferSize = U360; |
| 86 | + |
| 87 | + fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { |
| 88 | + Command::ComPinConfig(true, false).send(iface) |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +/// Size information for the common 64x48 variants |
| 93 | +#[derive(Debug, Copy, Clone)] |
| 94 | +pub struct DisplaySize64x48; |
| 95 | +impl DisplaySize for DisplaySize64x48 { |
| 96 | + const WIDTH: u8 = 64; |
| 97 | + const HEIGHT: u8 = 48; |
| 98 | + const OFFSETX: u8 = 32; |
| 99 | + const OFFSETY: u8 = 0; |
| 100 | + type BufferSize = U384; |
| 101 | + |
| 102 | + fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { |
| 103 | + Command::ComPinConfig(true, false).send(iface) |
30 | 104 | }
|
31 | 105 | }
|
0 commit comments