Created
October 7, 2024 02:02
-
-
Save ProtoJazz/a374ea38bf62f327b456226d291036a1 to your computer and use it in GitHub Desktop.
epaper display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use esp_idf_hal::gpio::*; | |
| use esp_idf_hal::peripheral::Peripheral; | |
| use esp_idf_hal::spi::{SpiDeviceDriver, SpiDriver}; | |
| use std::thread::sleep; | |
| use std::time::Duration; | |
| const BOOSTER_SOFT_START: u8 = 0x06; | |
| const POWER_ON: u8 = 0x04; | |
| const PANEL_SETTING: u8 = 0x00; | |
| const POWER_OFF: u8 = 0x02; | |
| pub fn init_display<'a>(spi: &mut SpiDeviceDriver<'a, SpiDriver<'a>>, dc: &mut PinDriver<'_, AnyOutputPin, Output>, cs: &mut PinDriver<'_, AnyOutputPin, Output>, rst: &mut PinDriver<'_, AnyOutputPin, Output>) { | |
| reset(rst); | |
| send_command(spi, dc, cs, BOOSTER_SOFT_START); | |
| send_data(spi, dc, cs, &[0x17]); | |
| send_command(spi, dc, cs, POWER_ON); | |
| sleep(Duration::from_millis(100)); | |
| send_command(spi, dc, cs, PANEL_SETTING); | |
| send_data(spi, dc, cs, &[0x0F]); | |
| } | |
| fn reset<'a>(rst: &mut PinDriver<'_, AnyOutputPin, Output>) { | |
| rst.set_low().unwrap(); | |
| sleep(Duration::from_millis(10)); | |
| rst.set_high().unwrap(); | |
| sleep(Duration::from_millis(10)); | |
| } | |
| fn send_command<'a>(spi: &mut SpiDeviceDriver<'a, SpiDriver<'a>>, dc: &mut PinDriver<'_, AnyOutputPin, Output>, cs: &mut PinDriver<'_, AnyOutputPin, Output>, command: u8) { | |
| dc.set_low().unwrap(); | |
| cs.set_low().unwrap(); | |
| spi.write(&[command]).unwrap(); | |
| cs.set_high().unwrap(); | |
| } | |
| fn send_data<'a>(spi: &mut SpiDeviceDriver<'a, SpiDriver<'a>>, dc: &mut PinDriver<'_, AnyOutputPin, Output>, cs: &mut PinDriver<'_, AnyOutputPin, Output>, data: &[u8]) { | |
| dc.set_high().unwrap(); | |
| cs.set_low().unwrap(); | |
| spi.write(data).unwrap(); | |
| cs.set_high().unwrap(); | |
| } | |
| pub fn power_off<'a>(spi: &mut SpiDeviceDriver<'a, SpiDriver<'a>>, dc: &mut PinDriver<'_, AnyOutputPin, Output>, cs: &mut PinDriver<'_, AnyOutputPin, Output>) { | |
| send_command(spi, dc, cs, POWER_OFF); | |
| sleep(Duration::from_millis(100)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment