generated from luke-else/esp32-std-template
	Created generic display module
This commit is contained in:
		@@ -1,3 +1,5 @@
 | 
			
		||||
use crate::error::Error;
 | 
			
		||||
 | 
			
		||||
use embedded_graphics::{
 | 
			
		||||
    prelude::*,
 | 
			
		||||
    mono_font::{ascii::FONT_7X13, ascii::FONT_10X20, MonoTextStyle},
 | 
			
		||||
@@ -5,6 +7,17 @@ use embedded_graphics::{
 | 
			
		||||
    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
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
@@ -12,4 +25,23 @@ pub enum DisplayError {
 | 
			
		||||
    SetupError(display_interface::DisplayError),
 | 
			
		||||
    DrawingError,
 | 
			
		||||
    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
 | 
			
		||||
    ).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 latest_data = gpsdata::GpsData::default();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user