Skip to content

Commit

Permalink
Merge branch 'bit-resolution-Spi' into rewrite-graphics-API
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Sep 30, 2021
2 parents 00318cf + 8bb67ed commit b8d05e6
Show file tree
Hide file tree
Showing 23 changed files with 254 additions and 196 deletions.
16 changes: 7 additions & 9 deletions examples/nucleo_l452re/graphics_touch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace touch
//using Interrupt = modm::platform::GpioA10;
}

modm::Touch2046<touch::Spi, touch::Cs> touchController;
modm::Touch2046<touch::Spi, touch::Cs, 320, 240> touchController;


int
Expand All @@ -75,12 +75,10 @@ main()
touch::Mosi::Mosi>();
touch::Spi::initialize<SystemClock, 2500_kHz>();
modm::touch2046::Calibration cal{
.OffsetX = -11,
.OffsetY = 335,
.FactorX = 22018,
.OffsetX = -11,
.FactorY = -29358,
.MaxX = 240,
.MaxY = 320,
.OffsetY = 335,
.ThresholdZ = 500,
};
touchController.setCalibration(cal);
Expand All @@ -107,22 +105,22 @@ main()

int16_t X = 0;
int16_t Y = 0;
int16_t Z = 0;
// int16_t Z = 0;

while (true)
{
LedGreen::set();

std::tie(X, Y, Z) = RF_CALL_BLOCKING(touchController.getRawValues());
std::tie(X, Y) = RF_CALL_BLOCKING(touchController.getTouchPosition());
tftController.setColor(Red);
tftController.fillRectangle({30, 50}, 90, 115);
tftController.setColor(Black);
tftController.setCursor(0, 50);
tftController << "X=" << X;
tftController.setCursor(0, 90);
tftController << "Y=" << Y;
tftController.setCursor(0, 130);
tftController << "Z=" << Z;
// tftController.setCursor(0, 130);
// tftController << "Z=" << Z;

tftController.setColor(Red);
tftController.fillRectangle({30, 220}, 120, 35);
Expand Down
2 changes: 1 addition & 1 deletion examples/nucleo_l452re/lvgl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace touch
//using Interrupt = modm::platform::GpioA10;
}

modm::Touch2046<touch::Spi, touch::Cs> touchController;
modm::Touch2046<touch::Spi, touch::Cs, 320, 240> touchController;


static lv_disp_draw_buf_t disp_buf;
Expand Down
3 changes: 2 additions & 1 deletion src/modm/driver/can/mcp2515_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ modm::Mcp2515<SPI, CS, INT>::writeIdentifier(const uint32_t& identifier,
spi.transferBlocking(uint8_t(*((uint16_t *) ptr) >> 3));
spi.transferBlocking(uint8_t(*((uint8_t *) ptr) << 5));

spi.transferBlocking(uint16_t(0));
spi.transferBlocking(uint8_t(0));
spi.transferBlocking(uint8_t(0));
}
}

Expand Down
93 changes: 44 additions & 49 deletions src/modm/driver/display/ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <modm/architecture/interface/delay.hpp>
#include <modm/architecture/interface/register.hpp>
// #include <modm/platform/gpio/base.hpp> ???
#include <modm/processing/resumable.hpp>

#include <modm/ui/graphic/display.hpp>
Expand All @@ -30,100 +29,96 @@
#include "ili9341_interface_parallel.hpp"
#include "ili9341_interface_spi.hpp"

using namespace modm::shape;
using namespace modm::color;
using namespace modm::graphic;
namespace modm
{

/// @ingroup modm_driver_ili9341

template<class Interface, class Reset, size_t BC = 512>
template<class Transport, class Reset, size_t BC = 512>
// requires std::derived_from<Painter, RemotePainter<R>>
class Ili9341 : public Interface,
public Display<color::Rgb565, Size(320, 240), true>
class Ili9341 : public Transport, public graphic::Display<color::Rgb565, shape::Size(320, 240), true>
{
// OPTIMIZE determine good contraints
static_assert(BC >= 32, "Conversion Buffer < 64 pixels produces too much overhead.");
static_assert(BC <= 4096, "Conversion Buffer > 4048 pixels doesn't make it better.");
static_assert(BC <= 2048, "Conversion Buffer > 2048 pixels doesn't make it any better.");

using Toggle = ili9341_register::Toggle;
using ReadWrite = ili9341_register::ReadWrite;
using Command = ili9341_register::Command;
using ReadCommand = ili9341_register::ReadCommand;

public:
using ColorType = Rgb565;
using BufferLandscape = Buffer<Rgb565, ResolutionVector>;
using BufferPortrait = Buffer<Rgb565, ResolutionVector.swapped()>;
using ColorType = color::Rgb565;
using BufferLandscape = graphic::Buffer<ColorType, ResolutionVector>;
using BufferPortrait = graphic::Buffer<ColorType, ResolutionVector.swapped()>;

ColorType color;
ColorType* colormap;

template<typename... Args>
Ili9341(Args &&...args)
: Interface(std::forward<Args>(args)...)
: Transport(std::forward<Args>(args)...)
{ Reset::setOutput(modm::Gpio::High); }

~Ili9341(){};

modm::ResumableResult<void>
ResumableResult<void>
initialize();

modm::ResumableResult<void>
ResumableResult<void>
reset(bool hardReset = false);

modm::ResumableResult<uint16_t>
ResumableResult<uint16_t>
getIcModel();

/* modm::ResumableResult<uint32_t>
/* ResumableResult<uint32_t>
getStatus(); // 5 bytes, Datasheet P92
modm::ResumableResult<uint16_t>
ResumableResult<uint16_t>
getPowerMode(); // 2 bytes, Datasheet P94
modm::ResumableResult<uint16_t>
ResumableResult<uint16_t>
getMadCtl(); // 2 bytes, Datasheet P95
modm::ResumableResult<uint16_t>
ResumableResult<uint16_t>
getPixelFormat(); // 2 bytes, Datasheet P96 */

modm::ResumableResult<void>
ResumableResult<void>
set(Toggle toggle, bool state);

modm::ResumableResult<void>
ResumableResult<void>
set(ReadWrite reg, uint8_t value);

modm::ResumableResult<uint8_t>
ResumableResult<uint8_t>
get(ReadWrite reg);

modm::ResumableResult<void>
setOrientation(Orientation orientation);
ResumableResult<void>
setOrientation(graphic::Orientation orientation);

modm::ResumableResult<void>
ResumableResult<void>
setScrollArea(uint16_t topFixedRows, uint16_t firstRow, uint16_t bottomFixedRows);

modm::ResumableResult<void>
ResumableResult<void>
scrollTo(uint16_t row);

template<ColorPattern P>
modm::ResumableResult<void>
writePattern(Rectangle rectangle, P pattern);
template<graphic::ColorPattern P>
ResumableResult<void>
writePattern(shape::Rectangle rectangle, P pattern);

modm::ResumableResult<void>
clear(ColorType color = html::Black);
ResumableResult<void>
clear(ColorType color = 0);
private:
// Static variables for resumable functions
Section section;
Point cursor;
shape::Section section;
shape::Point cursor;
// ##################################################################

protected:
modm::ResumableResult<void>
ResumableResult<void>
updateClipping();

modm::ResumableResult<void>
setClipping(Point point);
ResumableResult<void>
setClipping(shape::Point point);

/**
* Write Image with foreign Color
Expand All @@ -132,8 +127,8 @@ class Ili9341 : public Interface,
* @param placement Placement for the image
*/
template<Color CO, template<typename> class Accessor>
modm::ResumableResult<void>
writeImage(ImageAccessor<CO, Accessor> accessor);
ResumableResult<void>
writeImage(graphic::ImageAccessor<CO, Accessor> accessor);

/**
* Write Image with same Color
Expand All @@ -142,16 +137,16 @@ class Ili9341 : public Interface,
* @param placement Placement for the image
*/
template<template<typename> class Accessor>
modm::ResumableResult<void>
writeImage(ImageAccessor<ColorType, Accessor> accessor);
ResumableResult<void>
writeImage(graphic::ImageAccessor<ColorType, Accessor> accessor);

modm::ResumableResult<void> drawBlind(const Point& point);
modm::ResumableResult<void> drawBlind(const Section& section);
modm::ResumableResult<void> drawBlind(const HLine& hline);
modm::ResumableResult<void> drawBlind(const VLine& vline);
ResumableResult<void> drawBlind(const shape::Point& point);
ResumableResult<void> drawBlind(const shape::Section& section);
ResumableResult<void> drawBlind(const shape::HLine& hline);
ResumableResult<void> drawBlind(const shape::VLine& vline);

modm::ResumableResult<Rgb565>
getBlind(const Point& point) const;
ResumableResult<ColorType>
getBlind(const shape::Point& point) const;

private:
// Static variables for resumable functions
Expand All @@ -168,14 +163,14 @@ class Ili9341 : public Interface,
{
uint16_t buff_cmd_clipping[2];

Rgb565 buffer[BC]; // Conversion buffer
ColorType buffer[BC]; // Conversion buffer
size_t i; // index in conversion buffer
Point scanner; // index on display

size_t pixels; // Number of remaining pixels of transaction
uint64_t pixels; // Must fit R.x * R.y = 76800
size_t pixels_bulk; // Number of pixels of current bulk

Rgb565 temp_color; // Temporary storage for a color
ColorType temp_color; // Temporary storage for a color
} p; // p for parallel
};
};
Expand Down
5 changes: 4 additions & 1 deletion src/modm/driver/display/ili9341.lb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020, Mike Wolfram
# Copyright (c) 2021, Thomas Sommer
#
# This file is part of the modm project.
#
Expand Down Expand Up @@ -29,5 +30,7 @@ def build(env):
env.copy("ili9341_defines.hpp")
env.copy("ili9341.hpp")
env.copy("ili9341_impl.hpp")
env.copy("ili9341_interface_spi.hpp")
env.copy("ili9341_interface_parallel.hpp")

env.substitutions = {'spi_16bit_hardware': env[":target"].has_driver("spi:stm32")}
env.template("ili9341_interface_spi.hpp.in")
Loading

0 comments on commit b8d05e6

Please sign in to comment.