Skip to content

Commit

Permalink
Treat reviews + further beauty added
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Apr 17, 2021
1 parent 77e5fc1 commit 138fbd3
Show file tree
Hide file tree
Showing 24 changed files with 516 additions and 502 deletions.
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
10 changes: 5 additions & 5 deletions examples/stm32_f4ve/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center)
}

static void
calibrateTouchscreen(modm::ColorGraphicDisplay& 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
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
8 changes: 4 additions & 4 deletions examples/stm32f4_discovery/open407v-d/gui/main.cpp
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions examples/stm32f4_discovery/open407v-d/touchscreen/main.cpp
Original file line number Diff line number Diff line change
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
33 changes: 22 additions & 11 deletions src/modm/board/disco_f469ni/board_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "board.hpp"
#include <modm/architecture/interface/memory.hpp>

#include <algorithm>

extern void
board_initialize_display(uint8_t);

Expand All @@ -32,40 +34,49 @@ class DsiDisplay : public modm::ColorGraphicDisplay
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
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
92 changes: 57 additions & 35 deletions src/modm/driver/display/ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,16 @@ class Ili9341 : public Interface, public modm::ColorGraphicDisplay
{
static_assert(BufferSize >= 16, "at least a small buffer is required");

const uint16_t Width = 240;
const uint16_t Height = 320;
static constexpr uint16_t Width = 240;
static constexpr uint16_t Height = 320;
using BatchHandle = typename Interface::BatchHandle;
using Command = ili9341::Command;
public:
using Rotation = ili9341::Rotation;
using DisplayMode = ili9341::DisplayMode;

template<bool B=std::is_default_constructible_v<Interface>, std::enable_if_t<B, bool> = 0>
Ili9341(): Interface()
{
Reset::setOutput(modm::Gpio::High);
Backlight::setOutput(modm::Gpio::Low);
}

template<typename T, typename =std::enable_if_t<std::is_constructible_v<Interface, T&>, T>>
Ili9341(T& r): Interface(r)
template<typename... Args>
Ili9341(Args&&... args): Interface(std::forward<Args>(args)...)
{
Reset::setOutput(modm::Gpio::High);
Backlight::setOutput(modm::Gpio::Low);
Expand All @@ -187,24 +180,28 @@ class Ili9341 : public Interface, public modm::ColorGraphicDisplay

void
turnOn();

void
turnOff();

void
enableBacklight(bool enable)
{ Backlight::set(enable); }

void
setBrightness(uint8_t level);

void
setInvert(bool invert);

void
setIdle(bool enable);

void
enableSleep(bool enable);

virtual uint16_t
getWidth() const override
uint16_t
getWidth() const final
{
switch (rotation_)
{
Expand All @@ -215,8 +212,9 @@ class Ili9341 : public Interface, public modm::ColorGraphicDisplay
return Width;
}
}
virtual uint16_t
getHeight() const override

uint16_t
getHeight() const final
{
switch (rotation_)
{
Expand All @@ -228,59 +226,83 @@ class Ili9341 : public Interface, public modm::ColorGraphicDisplay
}
}

virtual void
clear() override;
virtual void
update() override
inline std::size_t
getBufferWidth() const final
{
return Width;
}

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

void
setPixel(int16_t x, int16_t y) final
{ setColoredPixel(x, y, foregroundColor); }

void
clearPixel(int16_t x, int16_t y) final
{ setColoredPixel(x, y, backgroundColor); }

// TODO implement getPixel for ili9341
glcd::Color
getPixel(int16_t x, int16_t y) const final
{
(void) x;
(void) y;
return glcd::Color::white();
}

void
clear() final;

inline void
update() final
{ /* nothing to do, data is directly written to TFT RAM */ }

void
setRotation(Rotation rotation);

void
fillRectangle(glcd::Point upperLeft, uint16_t width, uint16_t height);

inline void
fillRectangle(int16_t x, int16_t y, uint16_t width, uint16_t height)
{ fillRectangle(glcd::Point(x, y), width, height); }

void
fillCircle(glcd::Point center, uint16_t radius);

virtual void
void
drawImageRaw(glcd::Point upperLeft,
uint16_t width, uint16_t height,
modm::accessor::Flash<uint8_t> data) override;
modm::accessor::Flash<uint8_t> data) final;

virtual void
void
drawRaw(glcd::Point upperLeft, uint16_t width, uint16_t height, glcd::Color* data);

void
setScrollArea(uint16_t topFixedRows, uint16_t bottomFixedRows, uint16_t firstRow);

void
scrollTo(uint16_t row);

void
drawBitmap(glcd::Point upperLeft, uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t> data);

protected:
virtual void
setPixel(int16_t x, int16_t y) override
{ setColoredPixel(x, y, foregroundColor); }
virtual void
clearPixel(int16_t x, int16_t y) override
{ setColoredPixel(x, y, backgroundColor); }
virtual bool
getPixel(int16_t /*x*/, int16_t /*y*/) override
{ return false; }
void
drawHorizontalLine(glcd::Point start, uint16_t length) final;

virtual void
drawHorizontalLine(glcd::Point start, uint16_t length) override;
virtual void
drawVerticalLine(glcd::Point start, uint16_t length) override;
void
drawVerticalLine(glcd::Point start, uint16_t length) final;

private:
void
setColoredPixel(int16_t x, int16_t y, glcd::Color const &color);

void
setClipping(uint16_t x, uint16_t y, uint16_t width, uint16_t height);

Expand Down
Loading

0 comments on commit 138fbd3

Please sign in to comment.