Skip to content

Commit b8d05e6

Browse files
committed
Merge branch 'bit-resolution-Spi' into rewrite-graphics-API
2 parents 00318cf + 8bb67ed commit b8d05e6

23 files changed

+254
-196
lines changed

Diff for: examples/nucleo_l452re/graphics_touch/main.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace touch
5151
//using Interrupt = modm::platform::GpioA10;
5252
}
5353

54-
modm::Touch2046<touch::Spi, touch::Cs> touchController;
54+
modm::Touch2046<touch::Spi, touch::Cs, 320, 240> touchController;
5555

5656

5757
int
@@ -75,12 +75,10 @@ main()
7575
touch::Mosi::Mosi>();
7676
touch::Spi::initialize<SystemClock, 2500_kHz>();
7777
modm::touch2046::Calibration cal{
78-
.OffsetX = -11,
79-
.OffsetY = 335,
8078
.FactorX = 22018,
79+
.OffsetX = -11,
8180
.FactorY = -29358,
82-
.MaxX = 240,
83-
.MaxY = 320,
81+
.OffsetY = 335,
8482
.ThresholdZ = 500,
8583
};
8684
touchController.setCalibration(cal);
@@ -107,22 +105,22 @@ main()
107105

108106
int16_t X = 0;
109107
int16_t Y = 0;
110-
int16_t Z = 0;
108+
// int16_t Z = 0;
111109

112110
while (true)
113111
{
114112
LedGreen::set();
115113

116-
std::tie(X, Y, Z) = RF_CALL_BLOCKING(touchController.getRawValues());
114+
std::tie(X, Y) = RF_CALL_BLOCKING(touchController.getTouchPosition());
117115
tftController.setColor(Red);
118116
tftController.fillRectangle({30, 50}, 90, 115);
119117
tftController.setColor(Black);
120118
tftController.setCursor(0, 50);
121119
tftController << "X=" << X;
122120
tftController.setCursor(0, 90);
123121
tftController << "Y=" << Y;
124-
tftController.setCursor(0, 130);
125-
tftController << "Z=" << Z;
122+
// tftController.setCursor(0, 130);
123+
// tftController << "Z=" << Z;
126124

127125
tftController.setColor(Red);
128126
tftController.fillRectangle({30, 220}, 120, 35);

Diff for: examples/nucleo_l452re/lvgl/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace touch
5959
//using Interrupt = modm::platform::GpioA10;
6060
}
6161

62-
modm::Touch2046<touch::Spi, touch::Cs> touchController;
62+
modm::Touch2046<touch::Spi, touch::Cs, 320, 240> touchController;
6363

6464

6565
static lv_disp_draw_buf_t disp_buf;

Diff for: src/modm/driver/can/mcp2515_impl.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ modm::Mcp2515<SPI, CS, INT>::writeIdentifier(const uint32_t& identifier,
394394
spi.transferBlocking(uint8_t(*((uint16_t *) ptr) >> 3));
395395
spi.transferBlocking(uint8_t(*((uint8_t *) ptr) << 5));
396396

397-
spi.transferBlocking(uint16_t(0));
397+
spi.transferBlocking(uint8_t(0));
398+
spi.transferBlocking(uint8_t(0));
398399
}
399400
}
400401

Diff for: src/modm/driver/display/ili9341.hpp

+44-49
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include <modm/architecture/interface/delay.hpp>
1818
#include <modm/architecture/interface/register.hpp>
19-
// #include <modm/platform/gpio/base.hpp> ???
2019
#include <modm/processing/resumable.hpp>
2120

2221
#include <modm/ui/graphic/display.hpp>
@@ -30,100 +29,96 @@
3029
#include "ili9341_interface_parallel.hpp"
3130
#include "ili9341_interface_spi.hpp"
3231

33-
using namespace modm::shape;
34-
using namespace modm::color;
35-
using namespace modm::graphic;
3632
namespace modm
3733
{
3834

3935
/// @ingroup modm_driver_ili9341
4036

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

5045
using Toggle = ili9341_register::Toggle;
5146
using ReadWrite = ili9341_register::ReadWrite;
5247
using Command = ili9341_register::Command;
5348
using ReadCommand = ili9341_register::ReadCommand;
5449

5550
public:
56-
using ColorType = Rgb565;
57-
using BufferLandscape = Buffer<Rgb565, ResolutionVector>;
58-
using BufferPortrait = Buffer<Rgb565, ResolutionVector.swapped()>;
51+
using ColorType = color::Rgb565;
52+
using BufferLandscape = graphic::Buffer<ColorType, ResolutionVector>;
53+
using BufferPortrait = graphic::Buffer<ColorType, ResolutionVector.swapped()>;
5954

6055
ColorType color;
6156
ColorType* colormap;
6257

6358
template<typename... Args>
6459
Ili9341(Args &&...args)
65-
: Interface(std::forward<Args>(args)...)
60+
: Transport(std::forward<Args>(args)...)
6661
{ Reset::setOutput(modm::Gpio::High); }
6762

6863
~Ili9341(){};
6964

70-
modm::ResumableResult<void>
65+
ResumableResult<void>
7166
initialize();
7267

73-
modm::ResumableResult<void>
68+
ResumableResult<void>
7469
reset(bool hardReset = false);
7570

76-
modm::ResumableResult<uint16_t>
71+
ResumableResult<uint16_t>
7772
getIcModel();
7873

79-
/* modm::ResumableResult<uint32_t>
74+
/* ResumableResult<uint32_t>
8075
getStatus(); // 5 bytes, Datasheet P92
8176
82-
modm::ResumableResult<uint16_t>
77+
ResumableResult<uint16_t>
8378
getPowerMode(); // 2 bytes, Datasheet P94
8479
85-
modm::ResumableResult<uint16_t>
80+
ResumableResult<uint16_t>
8681
getMadCtl(); // 2 bytes, Datasheet P95
8782
88-
modm::ResumableResult<uint16_t>
83+
ResumableResult<uint16_t>
8984
getPixelFormat(); // 2 bytes, Datasheet P96 */
9085

91-
modm::ResumableResult<void>
86+
ResumableResult<void>
9287
set(Toggle toggle, bool state);
9388

94-
modm::ResumableResult<void>
89+
ResumableResult<void>
9590
set(ReadWrite reg, uint8_t value);
9691

97-
modm::ResumableResult<uint8_t>
92+
ResumableResult<uint8_t>
9893
get(ReadWrite reg);
9994

100-
modm::ResumableResult<void>
101-
setOrientation(Orientation orientation);
95+
ResumableResult<void>
96+
setOrientation(graphic::Orientation orientation);
10297

103-
modm::ResumableResult<void>
98+
ResumableResult<void>
10499
setScrollArea(uint16_t topFixedRows, uint16_t firstRow, uint16_t bottomFixedRows);
105100

106-
modm::ResumableResult<void>
101+
ResumableResult<void>
107102
scrollTo(uint16_t row);
108103

109-
template<ColorPattern P>
110-
modm::ResumableResult<void>
111-
writePattern(Rectangle rectangle, P pattern);
104+
template<graphic::ColorPattern P>
105+
ResumableResult<void>
106+
writePattern(shape::Rectangle rectangle, P pattern);
112107

113-
modm::ResumableResult<void>
114-
clear(ColorType color = html::Black);
108+
ResumableResult<void>
109+
clear(ColorType color = 0);
115110
private:
116111
// Static variables for resumable functions
117-
Section section;
118-
Point cursor;
112+
shape::Section section;
113+
shape::Point cursor;
119114
// ##################################################################
120115

121116
protected:
122-
modm::ResumableResult<void>
117+
ResumableResult<void>
123118
updateClipping();
124119

125-
modm::ResumableResult<void>
126-
setClipping(Point point);
120+
ResumableResult<void>
121+
setClipping(shape::Point point);
127122

128123
/**
129124
* Write Image with foreign Color
@@ -132,8 +127,8 @@ class Ili9341 : public Interface,
132127
* @param placement Placement for the image
133128
*/
134129
template<Color CO, template<typename> class Accessor>
135-
modm::ResumableResult<void>
136-
writeImage(ImageAccessor<CO, Accessor> accessor);
130+
ResumableResult<void>
131+
writeImage(graphic::ImageAccessor<CO, Accessor> accessor);
137132

138133
/**
139134
* Write Image with same Color
@@ -142,16 +137,16 @@ class Ili9341 : public Interface,
142137
* @param placement Placement for the image
143138
*/
144139
template<template<typename> class Accessor>
145-
modm::ResumableResult<void>
146-
writeImage(ImageAccessor<ColorType, Accessor> accessor);
140+
ResumableResult<void>
141+
writeImage(graphic::ImageAccessor<ColorType, Accessor> accessor);
147142

148-
modm::ResumableResult<void> drawBlind(const Point& point);
149-
modm::ResumableResult<void> drawBlind(const Section& section);
150-
modm::ResumableResult<void> drawBlind(const HLine& hline);
151-
modm::ResumableResult<void> drawBlind(const VLine& vline);
143+
ResumableResult<void> drawBlind(const shape::Point& point);
144+
ResumableResult<void> drawBlind(const shape::Section& section);
145+
ResumableResult<void> drawBlind(const shape::HLine& hline);
146+
ResumableResult<void> drawBlind(const shape::VLine& vline);
152147

153-
modm::ResumableResult<Rgb565>
154-
getBlind(const Point& point) const;
148+
ResumableResult<ColorType>
149+
getBlind(const shape::Point& point) const;
155150

156151
private:
157152
// Static variables for resumable functions
@@ -168,14 +163,14 @@ class Ili9341 : public Interface,
168163
{
169164
uint16_t buff_cmd_clipping[2];
170165

171-
Rgb565 buffer[BC]; // Conversion buffer
166+
ColorType buffer[BC]; // Conversion buffer
172167
size_t i; // index in conversion buffer
173168
Point scanner; // index on display
174169

175-
size_t pixels; // Number of remaining pixels of transaction
170+
uint64_t pixels; // Must fit R.x * R.y = 76800
176171
size_t pixels_bulk; // Number of pixels of current bulk
177172

178-
Rgb565 temp_color; // Temporary storage for a color
173+
ColorType temp_color; // Temporary storage for a color
179174
} p; // p for parallel
180175
};
181176
};

Diff for: src/modm/driver/display/ili9341.lb

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
#
44
# Copyright (c) 2020, Mike Wolfram
5+
# Copyright (c) 2021, Thomas Sommer
56
#
67
# This file is part of the modm project.
78
#
@@ -29,5 +30,7 @@ def build(env):
2930
env.copy("ili9341_defines.hpp")
3031
env.copy("ili9341.hpp")
3132
env.copy("ili9341_impl.hpp")
32-
env.copy("ili9341_interface_spi.hpp")
3333
env.copy("ili9341_interface_parallel.hpp")
34+
35+
env.substitutions = {'spi_16bit_hardware': env[":target"].has_driver("spi:stm32")}
36+
env.template("ili9341_interface_spi.hpp.in")

0 commit comments

Comments
 (0)