Giter VIP home page Giter VIP logo

Comments (4)

andber1 avatar andber1 commented on August 16, 2024

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.

from epd-waveshare.

kongschlong avatar kongschlong commented on August 16, 2024

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 DC pin is used. My assumption is that it is the MISO part of the SPI connection, so it makes sense that Spi::new() takes ownership of this pin. However, Epd2in13::new() also expects access to this DC pin, which is not possible because it was moved into Spi before.

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?

from epd-waveshare.

andber1 avatar andber1 commented on August 16, 2024

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).

from epd-waveshare.

kongschlong avatar kongschlong commented on August 16, 2024

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.

RPi Pico EPD Notes
8 DC
9 BUSY
10 CLK SCK pin of SPI bus
11 DIN MOSI pin of SPI bus
12 not connected MISO pin of SPI bus
13 RST
14 CS Chip Select for SPI bus

Display Config switch: B
Interface Config switch: 4-line SPI

from epd-waveshare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.