Code Monkey home page Code Monkey logo

st7565's Introduction

st7565

DOGM132W-5 display showing the graphics example

Crates.io Crates.io License Build Status docs.rs

This crate aims to provide an embedded-graphics compatible driver for displays based on the ST7565 chipset.

Example

The following example is intended for the DOGM132W-5 display connected to an nRF52840 microcontroller.

Note the MODE_3 of the SPI. The DOGM132W-5 display expects the clock to be configured with CPOL=1 and CPHA=1, which is also called SPI Mode 3.

// Create DOGM132W-5 spi bus
let disp_spi = SPIInterface::new(
    hal::Spim::new(
        peripherals.SPIM0,
        hal::spim::Pins {
            sck: disp_scl,
            mosi: Some(disp_si),
            miso: None,
        },
        hal::spim::Frequency::M8,
        hal::spim::MODE_3,
        0,
    ),
    disp_a0,
    disp_cs,
);

// Create DOGM132W-5 display driver
let mut page_buffer = GraphicsPageBuffer::new();
let mut disp = ST7565::new(disp_spi, DOGM132W5).into_graphics_mode(&mut page_buffer);
disp.reset(&mut disp_rst, &mut timer).unwrap();
disp.flush().unwrap();
disp.set_display_on(true).unwrap();

// Draw on it using the embedded_graphics library
Circle::new(Point::new(10, 6), 20)
    .into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 2))
    .draw(&mut disp)
    .unwrap();
disp.flush().unwrap();

Note the DOGM132W5 object. This is the display specification that contains all the display specific configuration options that need to be applied to the ST7565 chip.

Further note the into_graphics_mode() call, which switches the driver from its initial mode to the embedded-graphics driver mode. The disp object can then be used as a DrawTarget in embedded-graphics calls.

After drawing something, a flush() call has to be issued to actually send the modified data to the display.

Adding support for new ST7565 based displays

The example above uses the DOGM132W5 struct in the [ST7565::new()] call.

To initialize the ST7565 driver struct with a different display, a new display specification has to be created. This can be done by creating an empty struct that implements the [DisplaySpecs] trait.

For example, the definition of the DOGM132W5 struct looks like this:

pub struct DOGM132W5;
impl DisplaySpecs<132, 32, 4> for DOGM132W5 {
    const FLIP_ROWS: bool = false;
    const FLIP_COLUMNS: bool = true;
    const INVERTED: bool = false;
    const BIAS_MODE_1: bool = false;
    const POWER_CONTROL: PowerControlMode = PowerControlMode {
        booster_circuit: true,
        voltage_regulator_circuit: true,
        voltage_follower_circuit: true,
    };
    const VOLTAGE_REGULATOR_RESISTOR_RATIO: u8 = 0b011;
    const ELECTRONIC_VOLUME: u8 = 0b011111;
    const BOOSTER_RATIO: BoosterRatio = BoosterRatio::StepUp2x3x4x;
    const COLUMN_OFFSET: u8 = 0;
}

The exact values for the respective display have to be taken from the display's manual.

If you created a specification for a new display, please open a pull request on https://github.com/Finomnis/st7565/pulls to make it available to the public.

st7565's People

Contributors

agrif avatar deltronix avatar dependabot[bot] avatar eparmstrong avatar finomnis avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

st7565's Issues

Add API for low-power modes

Will add this as soon as someone requests this feature. So please, everyone, feel free to write a message here if this is something you want.

Access to `set_line_offset` in graphics mode.

My ST7565 controller does not appear to set the line offset to 0 after a reset. I'm not sure yet whether this is a weird cloned ST7565 or if something else is going on. Right now I'm setting a 0 line offset manually.

However, set_line_offset is only available in raw mode, and there doesn't appear to be any way to move from raw mode to graphics mode or vice versa. At the moment, I'm detaching the display from the SPI interface and sending the raw command myself.

I can think of a few ways to make this less awkward. Any one of these would be enough, but they're not exclusive.

  • Set the line offset to 0 inside either reset or flush. There's some indication in the datasheet that this is normal. This is what the original firmware driving my display does during reset.

  • Move set_line_offset (and maybe a few other settings commands) into the common interface accessible from all modes. It would be neat, for example, to invert the entire screen or turn on all pixels cheaply even in graphics mode.

  • Add a way to move from graphics mode to raw mode and back. I haven't thought too hard about whether this would cause problems.

How to make a shared reference to a display?

As the title says, how would I go about making a shared reference to a display. I cannot seem to make a Trait object of DrawableTarget or a shared reference to the ST7565 struct.

The driver takes exclusive ownership of the SPI bus, which is a shared resource.

The SPI bus is designed to be used with multiple chips. In my case I wish to read font data from a different chip before writing it to the st7565. I imagine this working like:

(spi, disp) = st7565.into_graphics_mode_release_spi();
disp.flush(&mut spi);

The st7564 struct should maintain ownership of the CS and DC pins, as they are what lets st7564 maintain it's state.

This does mess with display_interface, and the st7564 does have two different interfaces, SPI and parallel, and it would be nice to not have to deal with that inside st7565.

If it's something you think is doable, but you don't have time, I could work on it.
If it's something you don't want in st7565 I can go do my own thing.

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.