|
DUDS
|
Distributed Update of Data from Something
|
Implements graphic output to the ST7920 LCD controller using a 4-bit parallel interface. More...
#include <ST7920.hpp>
Classes | |
| struct | Access |
| Stores access objects together. More... | |
Public Member Functions | |
| ST7920 () | |
| Initializes the object with an invalid display size and no pins to use. More... | |
| ST7920 (duds::hardware::interface::DigitalPinSet &&outPins, duds::hardware::interface::ChipSelect &&enablePin, unsigned int w, unsigned int h, std::chrono::nanoseconds delay=std::chrono::nanoseconds(8000)) | |
| Initializes the object with everything required to begin communicating with the display, but does not initalize the display. More... | |
| virtual | ~ST7920 () |
| Calls off(). More... | |
| void | configure (duds::hardware::interface::DigitalPinSet &&outPins, duds::hardware::interface::ChipSelect &&enablePin, unsigned int w, unsigned int h, std::chrono::nanoseconds delay=std::chrono::nanoseconds(8000)) |
| Sets the pins to use for communicating with the display. More... | |
| void | initialize () |
| Initializes the display for use. More... | |
| void | off () |
| Commands the display to turn off. More... | |
| void | on () |
| Commands the display to turn on. More... | |
Public Member Functions inherited from duds::hardware::display::BppGraphicDisplay | |
| const duds::ui::graphics::ImageDimensions & | dimensions () const |
| Returns the dimensions of the frame buffer. More... | |
| const duds::ui::graphics::BppImage & | frame () const |
| Provides access to the image in the frame buffer. More... | |
| int | height () const |
| Returns the height of the frame buffer. More... | |
| int | width () const |
| Returns the width of the frame buffer. More... | |
| void | write (const duds::ui::graphics::BppImage *img) |
| Writes the new image to the display. More... | |
| void | write (const std::shared_ptr< const duds::ui::graphics::BppImage > &img) |
| Writes the new image to the display. More... | |
Private Types | |
| enum | { dataMask = 0xFF, textFlag = 0x100, writeFlag = 0x200, nibbleFlag = 0x400 } |
Private Member Functions | |
| virtual void | outputFrame (const duds::ui::graphics::BppImage *img) |
| Writes out only the changed portions of the image to the display, and updates the image in frmbuf to match. More... | |
| void | preparePins (Access &acc) |
| Obtains access to the pins and configures them for output. More... | |
| void | sendByte (Access &acc, int val) |
| Sends a byte to the display a nibble at a time. More... | |
| void | wait () const |
| Waits until the time in soonestSend has passed. More... | |
| void | writeBlock (ST7920::Access &acc, const std::uint16_t *start, const std::uint16_t *end, int pos) |
| Writes a contiguous block of pixel data to the display after setting the next location to write. More... | |
Private Attributes | |
| duds::hardware::interface::ChipSelect | enable |
| Used to represent the enable line of the LCD. More... | |
| std::chrono::nanoseconds | nibblePeriod |
| The amount of time to allow the display to read data. More... | |
| std::vector< duds::hardware::interface::DigitalPinConfig > | outcfg |
| The best output configuration for the display bus given the port in use. More... | |
| duds::hardware::interface::DigitalPinSet | outputs |
| Represents the 5 output lines, other than enable, that are needed to communicate with the LCD. More... | |
| std::chrono::high_resolution_clock::time_point | soonestSend |
| The soonest time a new command can be sent to the display. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from duds::hardware::display::BppGraphicDisplay | |
| BppGraphicDisplay ()=default | |
| Construct with an empty frame buffer. More... | |
| BppGraphicDisplay (const duds::ui::graphics::ImageDimensions &dim) | |
| Construct with a frame buffer of the specified size. More... | |
Protected Attributes inherited from duds::hardware::display::BppGraphicDisplay | |
| duds::ui::graphics::BppImage | frmbuf |
| The frame buffer. More... | |
Implements graphic output to the ST7920 LCD controller using a 4-bit parallel interface.
The controller manages a display up to 256 by 64 pixels with an internal frame buffer. This driver maintains its own frame buffer so that it can update only the portions of the frame that change. The controller has a parallel interface that is almost identical to the HD44780's. It has three control lines and 4 or 8 data lines. Only the 4-bit wide data interface is supported, and only sending data to the display is supported. This limits the number of digital I/O lines required.
This class is not thread-safe because using it directly from multiple threads makes little sense.
Definition at line 42 of file ST7920.hpp.
|
private |
Definition at line 75 of file ST7920.hpp.
| duds::hardware::devices::displays::ST7920::ST7920 | ( | ) |
Initializes the object with an invalid display size and no pins to use.
Definition at line 19 of file ST7920.cpp.
| duds::hardware::devices::displays::ST7920::ST7920 | ( | duds::hardware::interface::DigitalPinSet && | outPins, |
| duds::hardware::interface::ChipSelect && | enablePin, | ||
| unsigned int | w, | ||
| unsigned int | h, | ||
| std::chrono::nanoseconds | delay = std::chrono::nanoseconds(8000) |
||
| ) |
Initializes the object with everything required to begin communicating with the display, but does not initalize the display.
| outPins | The set of pins used for 4-bit data output and the text flag. This object is moved to an internal member. The pins are, in order:
|
| enablePin | The chip select used for the enable line on the display. It is often labeled "E". The object is moved to an internal member. |
| w | The width of the display in pixels. It must not exceed 256. |
| h | The height of the display in pixels. It must not exceed 64. |
| delay | The number of nanoseconds to delay while the display reads in data. Delays as short as 1000ns should be possible. Specific circuits, especially non-permanent prototypes like ones on breadboards, may require longer delays. The default value seems to work well for such prototypes. |
| duds::hardware::display::DisplaySizeError | Either the width or height size is outside the supported range. |
| duds::hardware::interface::PinDoesNotExist | outPins or enablePin is empty. |
| duds::hardware::interface::PinRangeError | outPins lacks all the required pins. |
| duds::hardware::interface::DigitalPinCannotOutputError | A pin in outPins does not support output. |
Definition at line 21 of file ST7920.cpp.
|
virtual |
Calls off().
Definition at line 37 of file ST7920.cpp.
| void duds::hardware::devices::displays::ST7920::configure | ( | duds::hardware::interface::DigitalPinSet && | outPins, |
| duds::hardware::interface::ChipSelect && | enablePin, | ||
| unsigned int | w, | ||
| unsigned int | h, | ||
| std::chrono::nanoseconds | delay = std::chrono::nanoseconds(8000) |
||
| ) |
Sets the pins to use for communicating with the display.
After calling this, initialize() must be called before using the display.
| outPins | The set of pins used for 4-bit data output and the text flag. This object is moved to an internal member. The pins are, in order:
|
| enablePin | The chip select used for the enable line on the display. It is often labeled "E". The object is moved to an internal member. |
| w | The width of the display in pixels. It must not exceed 256. |
| h | The height of the display in pixels. It must not exceed 64. |
| delay | The number of nanoseconds to delay while the display reads in data. Delays as short as 1000ns should be possible. Specific circuits, especially non-permanent prototypes like ones on breadboards, may require longer delays. The default value seems to work well for such prototypes. |
| duds::hardware::display::DisplaySizeError | Either the width or height size is outside the supported range. |
| duds::hardware::interface::PinDoesNotExist | outPins or enablePin is empty. |
| duds::hardware::interface::PinRangeError | outPins lacks all the required pins. |
| duds::hardware::interface::DigitalPinCannotOutputError | A pin in outPins does not support output. |
Definition at line 43 of file ST7920.cpp.
Referenced by ST7920().
| void duds::hardware::devices::displays::ST7920::initialize | ( | ) |
Initializes the display for use.
This function must be called before sending text or any other commands to the display. It may be called more than once.
| DisplayUninitialized | The display object has not been given any pins to use. |
Definition at line 149 of file ST7920.cpp.
| void duds::hardware::devices::displays::ST7920::off | ( | ) |
Commands the display to turn off.
This should make the display appear blank, but it does not clear the display's frame buffer. Sending any command or data to the display will cause it to start displaying its image again.
Definition at line 190 of file ST7920.cpp.
Referenced by ~ST7920().
| void duds::hardware::devices::displays::ST7920::on | ( | ) |
Commands the display to turn on.
There is no need to use this with the ST7920 LCD controller; any display command will cause the display to show the contents of its frame buffer. The function exists for consistency with other display classes.
Definition at line 196 of file ST7920.cpp.
|
privatevirtual |
Writes out only the changed portions of the image to the display, and updates the image in frmbuf to match.
| img | The new image to show. |
Implements duds::hardware::display::BppGraphicDisplay.
Definition at line 224 of file ST7920.cpp.
Referenced by initialize().
|
private |
Obtains access to the pins and configures them for output.
Before obtaining access, a call to wait() is made. In the case of sending a single byte to the display, this allows at least 78us for other threads to use the hardware.
| acc | The object that contains the access objects to fill. |
| DisplayUninitialized | The display object has not been given any pins to use. |
Definition at line 101 of file ST7920.cpp.
Referenced by initialize(), off(), on(), and outputFrame().
|
private |
Sends a byte to the display a nibble at a time.
| acc | The access objects required to communicate with the display. |
| val | The data to send. The value within dataMask is sent over the four data lines. If textFlag is set, the text flag line, more commonly known as "RS", will be set. Otherwise, it will be cleared. If nibbleFlag is set, only the value in the mask 0xF0 will be sent, and only one send will be done instead of the normal two. |
Definition at line 116 of file ST7920.cpp.
Referenced by initialize(), off(), on(), and writeBlock().
|
private |
Waits until the time in soonestSend has passed.
This is used to assure that the display isn't sent data too rapidly while allowing the thread a chance to do other work rather than always wait on the display. It is called in preparePins() so that functions needing to call sendByte() once do not need to call wait, and so that the wait occurs without hardware access to allow other threads a chance to use the hardware.
Definition at line 94 of file ST7920.cpp.
Referenced by preparePins(), and writeBlock().
|
private |
Writes a contiguous block of pixel data to the display after setting the next location to write.
| acc | The access objects required to communicate with the display. |
| start | The starting address of the pixel data to send. |
| end | The ending address of the pixel data to send. May be the same as start, but should not extend past the end of the current horizontal line. |
| pos | The starting position to send to the display. The Y-coordinate is in the LSB, and the X-coordinate is shifted to lose the low order 4 bits and placed in the next significant byte. |
Definition at line 202 of file ST7920.cpp.
Referenced by outputFrame().
|
private |
Used to represent the enable line of the LCD.
It must go low to make the display read data.
Definition at line 60 of file ST7920.hpp.
Referenced by configure(), and preparePins().
|
private |
The amount of time to allow the display to read data.
Definition at line 74 of file ST7920.hpp.
Referenced by configure(), and sendByte().
|
private |
The best output configuration for the display bus given the port in use.
Definition at line 64 of file ST7920.hpp.
Referenced by configure(), and preparePins().
|
private |
Represents the 5 output lines, other than enable, that are needed to communicate with the LCD.
The pins are, in order:
Definition at line 52 of file ST7920.hpp.
Referenced by configure(), preparePins(), and ~ST7920().
|
private |
The soonest time a new command can be sent to the display.
The display requires some time to process incoming data. This value allows that time to elapse while the thread does something else.
Definition at line 70 of file ST7920.hpp.
Referenced by sendByte(), and wait().