17 namespace duds {
namespace hardware {
namespace devices {
namespace displays {
26 std::chrono::nanoseconds delay
48 std::chrono::nanoseconds delay
51 if ((w > 256) || (w < 16) || (h > 64) || (h < 16)) {
58 if (!outPins.havePins() || !enablePin) {
62 if (outPins.size() != 5) {
66 std::vector<duds::hardware::interface::DigitalPinCap> caps =
67 outPins.capabilities();
69 std::vector<duds::hardware::interface::DigitalPinCap>::const_iterator iter =
72 for (; iter != caps.cend(); ++pos, ++iter) {
74 if (!iter->canOutput()) {
82 iter->firstOutputDriveConfigFlags()
95 auto remain =
soonestSend - std::chrono::high_resolution_clock::now();
96 if (remain.count() > 0) {
141 soonestSend = std::chrono::high_resolution_clock::now();
152 static const std::uint8_t initdata[] {
168 std::this_thread::sleep_for(std::chrono::milliseconds(4));
170 int loop =
sizeof(initdata) - 1;
171 for (; loop >=
sizeof(initdata) - 4; --loop) {
173 std::this_thread::sleep_for(std::chrono::milliseconds(2));
175 for (; loop >= 0; --loop) {
177 std::this_thread::sleep_for(std::chrono::milliseconds(2));
204 const std::uint16_t *start,
205 const std::uint16_t *end,
212 sendByte(acc, ((pos >> 8) & 0x3F) | 0x80);
221 }
while (start++ != end);
228 int wblk =
width() / 16 + (((
width() % 16) > 0) ? 1 : 0);
230 for (
int h = 0; h <
height(); ++h) {
233 const std::uint16_t *spix = (std::uint16_t*)img->
bufferLine(h);
234 std::uint16_t *cx =
nullptr, *lx;
236 for (
int w = 0; w < wblk; ++dpix, ++spix, ++w) {
238 if (*dpix != *spix) {
248 else if (lx < (dpix - 1)) {
const ImageDimensions & dimensions() const
Returns the dimensions of the image.
duds::hardware::interface::DigitalPinSetAccess output
The set used for the 4 data pins and the text flag, more commonly referred to as "RS".
boost::error_info< struct Info_ImageDimensions, ImageDimensions > ImageErrorDimensions
Image dimensions relevant to the error.
int height() const
Returns the height of the frame buffer.
void preparePins(Access &acc)
Obtains access to the pins and configures them for output.
An attempt was made to use an uninitialized display object.
void YieldingWait(Duration duration)
Waits for a minumum period of time by calling std::this_thread::yield() in a loop.
void write(Int val, int bits) const
Writes out a number in binary to the pins.
const PixelBlock * bufferLine(int py) const
Returns a pointer to the start of the given line.
Defines the configuration for a digital general purpose I/O pin.
ST7920()
Initializes the object with an invalid display size and no pins to use.
The operation has too few or much data to work on the pins, which can alternately be stated as having...
void on()
Commands the display to turn on.
duds::hardware::interface::DigitalPinSet outputs
Represents the 5 output lines, other than enable, that are needed to communicate with the LCD...
duds::hardware::interface::ChipAccess enable
Used to assert the enable line of the LCD.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
A pin required for the operation does not exist or is unavailable to the process. ...
DigitalPinConfig modifyConfig(unsigned int pos, const DigitalPinConfig &conf) const
Modifies the configuration of a pin.
boost::error_info< struct Info_PinId, unsigned int > PinErrorId
The pin global ID involved in the error.
Stores the dimensions of an image.
Stores access objects together.
An object to wrap together a ChipSelectManager and chip ID to simplify code that needs to repeatedly ...
The specified display size is unsupported, or there is a display size mismatch.
std::chrono::nanoseconds nibblePeriod
The amount of time to allow the display to read data.
void initialize()
Initializes the display for use.
Represents a set of pins on a single DigitalPort.
Flag for sending text to the display rather than a command.
std::unique_ptr< DigitalPinSetAccess > access() const
Obtains an access object for all the pins in this set.
bool havePins() const
Returns true if this object has been given any pins to represent.
Flag to send only a nibble rather than a whole byte; used in display initalization.
void off()
Commands the display to turn off.
void deselect()
Deselects the chip.
int width() const
Returns the width of the frame buffer.
std::unique_ptr< ChipAccess > access()
Obtains a ChipAccess object.
virtual ~ST7920()
Calls off().
void output(unsigned int pos, bool state) const
Changes the output state of a pin.
void resize(const duds::ui::graphics::ImageDimensions &newdim)
Changes the size of the image.
Indicates that a request to configure a pin to output was made of a pin that cannot output...
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 ...
std::chrono::high_resolution_clock::time_point soonestSend
The soonest time a new command can be sent to the display.
void sendByte(Access &acc, int val)
Sends a byte to the display a nibble at a time.
duds::ui::graphics::BppImage frmbuf
The frame buffer.
void clearImage()
Clears every pixel (change to false) in the image.
General graphics related code.
Integer ReverseBits(Integer i)
Reverses the bits in a given value.
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.
BppGraphicDisplay()=default
Construct with an empty frame buffer.
void wait() const
Waits until the time in soonestSend has passed.
void select()
Selects the chip.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
An image that uses a single bit to represent the state of each pixel; a black or white picture...
void setImage()
Sets every pixel (set to true) in the image.
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...
std::vector< duds::hardware::interface::DigitalPinConfig > outcfg
The best output configuration for the display bus given the port in use.
duds::hardware::interface::ChipSelect enable
Used to represent the enable line of the LCD.