Skip to content

Instantly share code, notes, and snippets.

@ProtoJazz
Created October 7, 2024 01:17
Show Gist options
  • Select an option

  • Save ProtoJazz/ba8753e939a335fe7808c2975853c10e to your computer and use it in GitHub Desktop.

Select an option

Save ProtoJazz/ba8753e939a335fe7808c2975853c10e to your computer and use it in GitHub Desktop.
use std::borrow::Borrow;
use esp_idf_hal::gpio;
use esp_idf_hal::gpio::*;
use esp_idf_hal::peripheral::Peripheral;
use esp_idf_hal::peripheral::PeripheralRef;
use esp_idf_hal::spi::*;
use esp_idf_hal::prelude::*;
mod epaper_display;
fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches();
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();
log::info!("Hello, world!");
let peripherals = Peripherals::take().unwrap();
let pins = peripherals.pins;
let sclk: AnyOutputPin = pins.gpio8.into(); // d8
let cs: AnyOutputPin = pins.gpio3.into(); // d1
let rst: AnyOutputPin = pins.gpio2.into(); // d0
let dc: AnyOutputPin = pins.gpio5.into(); // d3
let din: AnyOutputPin = pins.gpio10.into(); // mosi d10
let busy: AnyInputPin = pins.gpio7.into(); // d5
let mut cs_driver = PinDriver::output(cs).unwrap();
let mut rst_driver = PinDriver::output(rst).unwrap();
let mut dc_driver = PinDriver::output(dc).unwrap();
let spi_driver = SpiDriver::new(
peripherals.spi2,
sclk,
din,
Option::<gpio::AnyIOPin>::None,
&SpiDriverConfig::new(),
).unwrap();
let mut spi = SpiDeviceDriver::new(
spi_driver,
Some(cs),
&SpiConfig::new().baudrate(MegaHertz(8).into()),
).unwrap();
epaper_display::init_display(&mut spi, &mut dc_driver, &mut cs_driver, &mut rst_driver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment