-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I create a SpiDevice to initialize a WaveshareDisplay? #195
Comments
It seems that only a SpiBus is implemented in rp-hal, not a SpiDevice. See here. You can implement a SpiDevice yourself. The embedded-hal-bus crate provides mechanisms to connect a SpiBus and a SpiDevice. The ExclusiveDevice seems to be the easiest way. |
Hi! Thank you so much, that really helped me out. Unfortunately I'm still not fully able to compile my project because I'm not sure how the Here's a snippet of the relevant part of my program: #[rp2040_hal::entry]
fn main() -> ! {
// [...]
// Set the pins to their default state
let pins = hal::gpio::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
let pin_cs = pins.gpio14.into_push_pull_output();
let pin_busy = pins.gpio12.into_floating_input();
let pin_dc = pins.gpio8.into_push_pull_output();
let pin_rst = pins.gpio13.into_push_pull_output();
// These are implicitly used by the spi driver if they are in the correct mode
let spi_mosi = pins.gpio11.into_function::<hal::gpio::FunctionSpi>(); // DIN
// This doesn't work, and it shouldn't. (It doesn't make sense to initialize the same pin twice)
// But how do I pass the same pin into `Spi` and into `Epd2in13`?
let spi_miso = pins.gpio8.into_function::<hal::gpio::FunctionSpi>(); // DC
let spi_sclk = pins.gpio10.into_function::<hal::gpio::FunctionSpi>();
let spi = hal::spi::Spi::<_, _, _, 8>::new(pac.SPI1, (spi_mosi, spi_miso, spi_sclk));
// Exchange the uninitialised SPI driver for an initialised one
let mut spi = spi.init(
&mut pac.RESETS,
clocks.peripheral_clock.freq(),
16.MHz(),
embedded_hal::spi::MODE_0,
);
let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let mut spi_device = ExclusiveDevice::new(spi, pin_cs, timer);
info!("Setting up display");
let mut display = Display2in13::default();
let mut epd = Epd2in13::new(&mut spi_device, pin_busy, pin_dc, pin_rst, &mut timer, None).expect("EPD setup error");
epd.update_frame(&mut spi_device, display.buffer(), &mut timer).expect("Update frame");
epd.display_frame(&mut spi_device, &mut timer).expect("Display new frame");
loop {
cortex_m::asm::wfi();
}
} So basically my question is: How can I pass the same DC pin into both the Spi driver and the EPD driver? |
The pins MOSI, MISO and SCLK make the SPI bus. Together with CS (chip select) this is the SPI device. EPD needs the SPI device, BUSY, DC (to distinguish between data and control bytes, has nothing to do with SPI) and RESET. These are all different pins. Maybe the confusion is that most e-paper modules do not have a MISO pin (master in, slave out), because the e-paper does not need to send data to the host. You can leave this pin unconnected. MOSI (master out, slave in) is often described as DIN (data in) or SDI (slave data in). |
Thank you so much for your help, it's finally working now (well, the colors are inverted and the screen is rotated 90 degrees, but I'm sure I'll figure that out later). For future reference, the following pin mapping is tested on a Raspberry Pi Pico connected to the Waveshare 2.13" Display (Rev. 4) using the universal Driver HAT.
|
TL;DR: I need help with using this crate together with the
rp2040_hal
Hi everyone!
I am trying to connect a Waveshare 2.13" (v4) E-Paper display to a Raspberry Pi Pico using the
rp2040_hal
. Unfortunately I'm not able to build a working example since I'm having trouble understanding some of the types used byepd-waveshare
andembedded-hal
.This is what my code looks like:
The issue occurs when calling
Epd2in13::new()
: This method requires anSPI
type that implements theembedded_hal::spi::SpiDevice
trait.The example uses a linux hal that opens a
SpidevDevice
for the SPI Interface. I assume that thisSpidevDevice
implements the requiredSpiDevice
trait?However, my
spi
variable has the typerp2040_hal::spi::Spi
, which does not seem to implementSpiDevice
, so I cannot pass it into theEpd2in13::new()
function. I have to admit that I'm new to embedded Rust, and I'm not quite sure how the HALs work. So right now I'm stuck with the following question: How do I get aSpiDevice
that I can use to communicate with the E-Paper display?Maybe I'm missing something very simple that is obvious to most other users, but I think it could be helpful to add a few other examples to the crate that target some embedded microcontroller (STM32 or RP2040?), just to show how the connection to the display is established on different hardware platforms.
Thanks in advance!
For reference, these are the crates I am using:
The text was updated successfully, but these errors were encountered: