generated from luke-else/esp32-std-template
Created generic display module
This commit is contained in:
parent
6625351e38
commit
6c157f65f6
@ -37,6 +37,7 @@ nmea-parser = "0.10.0"
|
|||||||
embedded-graphics = "0.8.0"
|
embedded-graphics = "0.8.0"
|
||||||
ssd1306 = "0.8.0"
|
ssd1306 = "0.8.0"
|
||||||
display-interface = "0.4.1"
|
display-interface = "0.4.1"
|
||||||
|
display-interface-i2c = "0.4.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
embuild = "0.31.2"
|
embuild = "0.31.2"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use crate::error::Error;
|
||||||
|
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
mono_font::{ascii::FONT_7X13, ascii::FONT_10X20, MonoTextStyle},
|
mono_font::{ascii::FONT_7X13, ascii::FONT_10X20, MonoTextStyle},
|
||||||
@ -5,6 +7,17 @@ use embedded_graphics::{
|
|||||||
text::{Text, Alignment},
|
text::{Text, Alignment},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use esp_idf_hal::{
|
||||||
|
self,
|
||||||
|
prelude::Peripherals,
|
||||||
|
units::Hertz,
|
||||||
|
i2c::{I2cConfig, I2cDriver, I2c}
|
||||||
|
};
|
||||||
|
|
||||||
|
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
||||||
|
|
||||||
|
use display_interface_i2c;
|
||||||
|
|
||||||
|
|
||||||
/// Enum to make clear the stage of failure of the display
|
/// Enum to make clear the stage of failure of the display
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -13,3 +26,22 @@ pub enum DisplayError {
|
|||||||
DrawingError,
|
DrawingError,
|
||||||
FlushError,
|
FlushError,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Display<'a, SIZE: DisplaySize> {
|
||||||
|
display: Ssd1306<I2CInterface<I2cDriver<'a>>, SIZE, ssd1306::mode::BufferedGraphicsMode<SIZE>>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, SIZE: DisplaySize> Display<'a, SIZE>
|
||||||
|
{
|
||||||
|
pub fn new(i2c: I2cDriver<'a>, size: SIZE) -> Result<Display<'a, SIZE>, Error> {
|
||||||
|
// Construct the I2C driver into a display interface
|
||||||
|
let interface = I2CDisplayInterface::new(i2c);
|
||||||
|
|
||||||
|
// Construct display with new anew driver
|
||||||
|
let mut display = Ssd1306::new(interface, size, DisplayRotation::Rotate0)
|
||||||
|
.into_buffered_graphics_mode();
|
||||||
|
display.init().map_err(|err| Error::DisplayError(DisplayError::SetupError(err)))?;
|
||||||
|
|
||||||
|
Ok(Display{display})
|
||||||
|
}
|
||||||
|
}
|
@ -49,11 +49,6 @@ fn main() -> Result<(), Error> {
|
|||||||
&config
|
&config
|
||||||
).map_err(|err| Error::EspError(err))?;
|
).map_err(|err| Error::EspError(err))?;
|
||||||
|
|
||||||
let interface = I2CDisplayInterface::new(i2c);
|
|
||||||
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
|
|
||||||
.into_buffered_graphics_mode();
|
|
||||||
display.init().map_err(|err| Error::DisplayError(DisplayError::SetupError(err)))?;
|
|
||||||
|
|
||||||
let mut app_state = appstate::AppState::default();
|
let mut app_state = appstate::AppState::default();
|
||||||
let mut latest_data = gpsdata::GpsData::default();
|
let mut latest_data = gpsdata::GpsData::default();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user