Skip to content

Commit

Permalink
[ui] Specialize displays for monochrome and color
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw authored and salkinium committed Apr 22, 2021
1 parent 4c80ba1 commit 295dbc3
Show file tree
Hide file tree
Showing 75 changed files with 1,407 additions and 1,298 deletions.
10 changes: 5 additions & 5 deletions examples/avr/display/dogm128/benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ main()
while (!timer.execute())
{
// rectangle in left side of screen
display.setColor(Color::black());
// TODO display.setColor(Color::black());
display.drawRectangle(Point(0, 0), 62, 62);

// rounded rectangle around text area
Expand All @@ -176,14 +176,14 @@ main()
display.drawCircle(Point(31, 31), 31);

// clear previous spinner position
display.setColor(Color::white());
// TODO display.setColor(Color::white());
display.fillRectangle(Point(87, 40), 16, 16);

static uint8_t loops = 0;
display.setColor(Color::black());
// TODO display.setColor(Color::black());
drawSpinner(Point(95, 48), loops++);

display.setColor(Color::white());
// TODO display.setColor(Color::white());
display.setCursor(Point(25, 40));
display << ++iter;
display.update();
Expand All @@ -192,7 +192,7 @@ main()
// print number of iterations in one second
display.clear();
display.setCursor(Point(80, 10));
display.setColor(Color::white());
// TODO display.setColor(Color::white());
display << "FPS=" << iter;
}
}
4 changes: 2 additions & 2 deletions examples/avr/display/dogm128/draw/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ main()

display.fillRectangle(Point(10, 10), 20, 20);
display.fillCircle(Point(45, 40), 23);
display.setColor(Color::white());
// TODO display.setColor(Color::white());
display.fillRectangle(Point(20, 20), 20, 20);
display.fillCircle(Point(55, 50), 8);

display.setColor(Color::black());
// TODO display.setColor(Color::black());
display.drawLine(Point(0, 0), Point(127, 63));

display.update();
Expand Down
18 changes: 9 additions & 9 deletions examples/avr/display/dogm128/touch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ modm::DogM128< lcd::SPI, lcd::Cs, lcd::A0, lcd::Reset, true > display;
void
drawCross(uint8_t x, uint8_t y)
{
display.drawPixel(x - 1, y - 1);
display.drawPixel(x - 1, y + 1);
display.drawPixel(x, y);
display.drawPixel(x + 1, y - 1);
display.drawPixel(x + 1, y + 1);
display.setPixel(x - 1, y - 1);
display.setPixel(x - 1, y + 1);
display.setPixel(x, y);
display.setPixel(x + 1, y - 1);
display.setPixel(x + 1, y + 1);
}

int
Expand Down Expand Up @@ -152,11 +152,11 @@ main()

if (x >= 0 && y >= 0)
{
display.drawPixel(x, y);
display.drawPixel(x, y+1);
display.setPixel(x, y);
display.setPixel(x, y+1);

display.drawPixel(x+1, y);
display.drawPixel(x+1, y+1);
display.setPixel(x+1, y);
display.setPixel(x+1, y+1);
}

display.update();
Expand Down
14 changes: 7 additions & 7 deletions examples/stm32_f4ve/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ initDisplay()

tft.initialize();
tft.enableBacklight(true);
tft.setRotation(Display::Rotation::Rotate90);
tft.setOrientation(modm::glcd::Orientation::Portrait90);
}


Expand All @@ -164,7 +164,7 @@ initTouchscreen()
// ----------------------------------------------------------------------------
/* screen calibration */
static void
drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center)
{
display.setColor(modm::glcd::Color::red());
display.drawLine(center.x - 15, center.y, center.x - 2, center.y);
Expand All @@ -187,7 +187,7 @@ drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
}

static void
calibrateTouchscreen(modm::GraphicDisplay& display, modm::glcd::Point *fixed_samples = NULL)
calibrateTouchscreen(modm::ColorGraphicDisplay& display, modm::glcd::Point *fixed_samples = nullptr)
{
MODM_LOG_DEBUG << __PRETTY_FUNCTION__ << modm::endl;
modm::glcd::Point calibrationPoint[3] = { { 45, 45 }, { 270, 90 }, { 100, 190 } };
Expand Down Expand Up @@ -229,10 +229,10 @@ drawPoint(modm::GraphicDisplay& display, modm::glcd::Point point)
return;
}

display.drawPixel(point.x, point.y);
display.drawPixel(point.x + 1, point.y);
display.drawPixel(point.x, point.y + 1);
display.drawPixel(point.x + 1, point.y + 1);
display.setPixel(point.x, point.y);
display.setPixel(point.x + 1, point.y);
display.setPixel(point.x, point.y + 1);
display.setPixel(point.x + 1, point.y + 1);
}

// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f469_discovery/display/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ main()
Board::initialize();
Board::initializeDisplay();

modm::GraphicDisplay& display = Board::getDisplay();
modm::ColorGraphicDisplay& display = Board::getDisplay();
display.setFont(modm::font::Assertion);

display.drawRectangle(0,0, 10, 10);
Expand Down
4 changes: 2 additions & 2 deletions examples/stm32f469_discovery/game_of_life/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static inline void touch(framebuffer_t buffer)
}
}

static inline void drawPixel(int x, int y, uint8_t color)
static inline void setPixel(int x, int y, uint8_t color)
{
#define DRAW(x, y) displayBuffer[(y) * 800 + (x)] = GET_TRAIL_COLOR(color).getValue();
#if SCALE >= 8
Expand Down Expand Up @@ -202,7 +202,7 @@ static inline void drawPixel(int x, int y, uint8_t color)
static inline void drawScreen(framebuffer_t before, framebuffer_t next)
{
for_yx(bw, bh) {
drawPixel(x*SCALE + SCALE/2, y*SCALE + SCALE/2, next[y][x]);
setPixel(x*SCALE + SCALE/2, y*SCALE + SCALE/2, next[y][x]);

before[y][x] = next[y][x];
}
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f469_discovery/touchscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class LineDrawer : public modm::pt::Protothread
private:
Touch::Data touchData;
Touch touch;
modm::GraphicDisplay& display;
modm::ColorGraphicDisplay& display;
int16_t px[2], py[2];
Color c[2];
};
Expand Down
12 changes: 6 additions & 6 deletions examples/stm32f4_discovery/open407v-d/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ initTouchscreen()
// ----------------------------------------------------------------------------
/* screen calibration */
static void
drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center)
{
display.setColor(modm::glcd::Color::red());
display.drawLine(center.x - 15, center.y, center.x - 2, center.y);
Expand All @@ -196,7 +196,7 @@ drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
}

static void
calibrateTouchscreen(modm::GraphicDisplay& display, modm::glcd::Point *fixed_samples = NULL)
calibrateTouchscreen(modm::ColorGraphicDisplay& display, modm::glcd::Point *fixed_samples = NULL)
{
modm::glcd::Point calibrationPoint[3] = { { 45, 45 }, { 270, 90 }, { 100, 190 } };
modm::glcd::Point sample[3];
Expand Down Expand Up @@ -236,10 +236,10 @@ drawPoint(modm::GraphicDisplay& display, modm::glcd::Point point)
return;
}

display.drawPixel(point.x, point.y);
display.drawPixel(point.x + 1, point.y);
display.drawPixel(point.x, point.y + 1);
display.drawPixel(point.x + 1, point.y + 1);
display.setPixel(point.x, point.y);
display.setPixel(point.x + 1, point.y);
display.setPixel(point.x, point.y + 1);
display.setPixel(point.x + 1, point.y + 1);
}

// ----------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions examples/stm32f4_discovery/open407v-d/touchscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ initTouchscreen()

// ----------------------------------------------------------------------------
static void
drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center)
{
display.setColor(modm::glcd::Color::red());
display.drawLine(center.x - 15, center.y, center.x - 2, center.y);
Expand All @@ -153,7 +153,7 @@ drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
}

static void
calibrateTouchscreen(modm::GraphicDisplay& display)
calibrateTouchscreen(modm::ColorGraphicDisplay& display)
{
modm::glcd::Point calibrationPoint[3] = { { 45, 45 }, { 270, 90 }, { 100, 190 } };
modm::glcd::Point sample[3];
Expand Down Expand Up @@ -186,10 +186,10 @@ drawPoint(modm::GraphicDisplay& display, modm::glcd::Point point)
return;
}

display.drawPixel(point.x, point.y);
display.drawPixel(point.x + 1, point.y);
display.drawPixel(point.x, point.y + 1);
display.drawPixel(point.x + 1, point.y + 1);
display.setPixel(point.x, point.y);
display.setPixel(point.x + 1, point.y);
display.setPixel(point.x, point.y + 1);
display.setPixel(point.x + 1, point.y + 1);
}

// ----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/modm/board/disco_f469ni/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <modm/platform.hpp>
#include <modm/architecture/interface/clock.hpp>
#include <modm/ui/display/graphic_display.hpp>
#include <modm/ui/display/color_graphic_display.hpp>
#include <modm/driver/touch/ft6x06.hpp>
#include <modm/debug/logger.hpp>

Expand Down Expand Up @@ -209,7 +209,7 @@ setDisplayBuffer(void * buffer);
void *
getDisplayBuffer();

modm::GraphicDisplay&
modm::ColorGraphicDisplay&
getDisplay();

inline void
Expand Down
37 changes: 24 additions & 13 deletions src/modm/board/disco_f469ni/board_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include "board.hpp"
#include <modm/architecture/interface/memory.hpp>

#include <algorithm>

extern void
board_initialize_display(uint8_t);

// Basic implementation of display running on memory mapped buffer
class DsiDisplay : public modm::GraphicDisplay
class DsiDisplay : public modm::ColorGraphicDisplay
{
public:
DsiDisplay() : buffer(new (modm::MemoryExternal) uint16_t[800*480])
Expand All @@ -32,40 +34,49 @@ class DsiDisplay : public modm::GraphicDisplay
getHeight() const override
{ return 480; }

inline std::size_t
getBufferWidth() const final
{
return 800;
}

inline std::size_t
getBufferHeight() const final
{
return 480;
}

void
clear() override
clear() final
{
for (int ii = 0; ii < 800*480; ii++)
{
buffer[ii] = this->backgroundColor.getValue();
}
std::fill(buffer, buffer + this->getBufferWidth()*this->getBufferHeight(), this->backgroundColor.getValue());
}

void
update() override
update() final
{
// FIXME: avoid tearing by using double buffering!
}

void
setPixel(int16_t x, int16_t y) override
setPixel(int16_t x, int16_t y) final
{
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return;
buffer[y * 800 + x] = this->foregroundColor.getValue();
}

void
clearPixel(int16_t x, int16_t y) override
clearPixel(int16_t x, int16_t y) final
{
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return;
buffer[y * 800 + x] = this->backgroundColor.getValue();
}

bool
getPixel(int16_t x, int16_t y) override
modm::glcd::Color
getPixel(int16_t x, int16_t y) const final
{
if (x < 0 or 800 <= x or y < 0 or 480 <= y) return false;
return (buffer[y * 800 + x] != this->backgroundColor.getValue());
return buffer[y * 800 + x];
}

protected:
Expand Down Expand Up @@ -97,7 +108,7 @@ Board::getDisplayBuffer()
return (void *) LTDC_Layer1->CFBAR;
}

modm::GraphicDisplay&
modm::ColorGraphicDisplay&
Board::getDisplay()
{
static DsiDisplay display;
Expand Down
6 changes: 3 additions & 3 deletions src/modm/driver/display/hd44780.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Hd44780 : public CharacterDisplay
clear();

protected:
typedef Hd44780Base<DATA, RW, RS, E> driver;
using driver = Hd44780Base<DATA, RW, RS, E>;

public:
/**
Expand Down Expand Up @@ -129,8 +129,8 @@ class Hd44780Dual : public CharacterDisplay
clear();

protected:
typedef Hd44780Base<DATA, RW, RS, E1> driver1;
typedef Hd44780Base<DATA, RW, RS, E2> driver2;
using driver1 = Hd44780Base<DATA, RW, RS, E1>;
using driver2 = Hd44780Base<DATA, RW, RS, E2>;
};

} // namespace modm
Expand Down
2 changes: 1 addition & 1 deletion src/modm/driver/display/hd44780_base_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ modm::Hd44780Base<DATA, RW, RS, E>::initialize(LineMode lineMode)
Bus<DATA, E, DATA::width>::writeHighNibble(Set4BitBus);
}

while(!writeCommand(static_cast<InternalCommand>(lineMode) |
while(!writeCommand(InternalCommand(lineMode) |
Bus<DATA, E, DATA::width>::Mode))
;
while(!writeCommand(DisableDisplay))
Expand Down
8 changes: 4 additions & 4 deletions src/modm/driver/display/hd44780_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template <typename DATA, typename RW, typename RS, typename E>
void
modm::Hd44780<DATA, RW, RS, E>::writeRaw(char c)
{
while(!driver::writeRAM(static_cast<uint8_t>(c)))
while(!driver::writeRAM(uint8_t(c)))
;
}

Expand All @@ -48,7 +48,7 @@ modm::Hd44780<DATA, RW, RS, E>::setCursor(uint8_t column, uint8_t line)

uint8_t address = this->column + 0x40 * this->line;
if (this->line >= 2) {
address += 20;
address += this->lineWidth;
}
while(!driver::writeAddress(address))
;
Expand Down Expand Up @@ -105,10 +105,10 @@ void
modm::Hd44780Dual<DATA, RW, RS, E1, E2>::writeRaw(char c)
{
if (this->line < 2) {
while(!driver1::writeRAM(static_cast<uint8_t>(c)))
while(!driver1::writeRAM(uint8_t(c)))
;
} else {
while(!driver2::writeRAM(static_cast<uint8_t>(c)))
while(!driver2::writeRAM(uint8_t(c)))
;
}
}
Expand Down
Loading

0 comments on commit 295dbc3

Please sign in to comment.