minor Cleanup

This commit is contained in:
Attila Body 2020-01-31 15:15:32 +01:00
parent 642dc26314
commit 482d3b8248
4 changed files with 113 additions and 133 deletions

View file

@ -14,111 +14,12 @@
#define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* DC = 0 */ #define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* DC = 0 */
#define LCD_RAM (*((volatile unsigned short *) 0x60080000)) /* DC = 1 */ #define LCD_RAM (*((volatile unsigned short *) 0x60080000)) /* DC = 1 */
#define ILI9341_NOP 0x00
#define ILI9341_RESET 0x01
#define ILI9341_READ_DISPLAY_IDENTIFICATION_INFORMATION 0x04
#define ILI9341_READ_DISPLAY_STATUS 0x09
#define ILI9341_READ_DISPLAY_POWER_MODE 0x0A
#define ILI9341_READ_DISPLAY_MADCTL 0x0B
#define ILI9341_READ_DISPLAY_PIXEL_FORMAT 0x0C
#define ILI9341_READ_DISPLAY_IMAGE_FORMAT 0x0D
#define ILI9341_READ_DISPLAY_SIGNAL_MODE 0x0E
#define ILI9341_READ_DISPLAY_SELF_DIAGNOSTIC_RESULT 0x0F
#define ILI9341_ENTER_SLEEP_MODE 0x10
#define ILI9341_SLEEP_OUT 0x11
#define ILI9341_PARTIAL_MODE_ON 0x12
#define ILI9341_NORMAL_DISPLAY_MODE_ON 0x13
#define ILI9341_DISPLAY_INVERSION_OFF 0x20
#define ILI9341_DISPLAY_INVERSION_ON 0x21
#define ILI9341_GAMMA 0x26
#define ILI9341_DISPLAY_OFF 0x28
#define ILI9341_DISPLAY_ON 0x29
#define ILI9341_COLUMN_ADDR 0x2A
#define ILI9341_PAGE_ADDR 0x2B
#define ILI9341_GRAM 0x2C
#define ILI9341_COLOR_SET 0x2D
#define ILI9341_MEMORY_READ 0x2E
#define ILI9341_PARTIAL_AREA 0x30
#define ILI9341_VERTICAL_SCROLLING_DEFINITION 0x33
#define ILI9341_TEARING_EFFECT_LINE_OFF 0x34
#define ILI9341_TEARING_EFFECT_LINE_ON 0x35
#define ILI9341_MAC 0x36
#define ILI9341_VERTICAL_SCROLLING_START_ADDRESS 0x37
#define ILI9341_IDLE_MODE_OFF 0x38
#define ILI9341_IDLE_MODE_ON 0x39
#define ILI9341_PIXEL_FORMAT 0x3A
#define ILI9341_WMC 0x3C
#define ILI9341_RMC 0x3E
#define ILI9341_SET_TEAR_SCANLINE 0x44
#define ILI9341_WDB 0x51
#define ILI9341_READ_DISPLAY_BRIGHTNESS 0x52
#define ILI9341_WCD 0x53
#define ILI9341_READ_CTRL_DISPLAY 0x54
#define ILI9341_WCABC 0x55
#define ILI9341_RCABC 0x56
#define ILI9341_WCABCMB 0x5E
#define ILI9341_RCABCMB 0x5F
#define ILI9341_RGB_INTERFACE 0xB0
#define ILI9341_FRC 0xB1
#define ILI9341_FRAME_CTRL_NM 0xB2
#define ILI9341_FRAME_CTRL_IM 0xB3
#define ILI9341_FRAME_CTRL_PM 0xB4
#define ILI9341_BPC 0xB5
#define ILI9341_DFC 0xB6
#define ILI9341_ENTRY_MODE_SET 0xB7
#define ILI9341_BACKLIGHT_CONTROL_1 0xB8
#define ILI9341_BACKLIGHT_CONTROL_2 0xB9
#define ILI9341_BACKLIGHT_CONTROL_3 0xBA
#define ILI9341_BACKLIGHT_CONTROL_4 0xBB
#define ILI9341_BACKLIGHT_CONTROL_5 0xBC
#define ILI9341_BACKLIGHT_CONTROL_6 0xBD
#define ILI9341_BACKLIGHT_CONTROL_7 0xBE
#define ILI9341_BACKLIGHT_CONTROL_8 0xBF
#define ILI9341_POWER1 0xC0
#define ILI9341_POWER2 0xC1
#define ILI9341_VCOM1 0xC5
#define ILI9341_VCOM2 0xC7
#define ILI9341_POWERA 0xCB
#define ILI9341_POWERB 0xCF
#define ILI9341_READ_ID1 0xDA
#define ILI9341_READ_ID2 0xDB
#define ILI9341_READ_ID3 0xDC
#define ILI9341_PGAMMA 0xE0
#define ILI9341_NGAMMA 0xE1
#define ILI9341_DTCA 0xE8
#define ILI9341_DTCB 0xEA
#define ILI9341_POWER_SEQ 0xED
#define ILI9341_3GAMMA_EN 0xF2
#define ILI9341_INTERFACE 0xF6
#define ILI9341_PRC 0xF7
// Color definitions
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
#define ILI9341_RED 0xF800 /* 255, 0, 0 */
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define ILI9341_PINK 0xF81F
Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram, Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram,
DMA_TypeDef *dma, uint32_t dmaStream, DMA_TypeDef *dma, uint32_t dmaStream,
bool horizontal) bool horizontal)
: m_reg(reg) : m_reg(reg ? reg : (volatile unsigned short *) 0x60000000)
, m_ram(ram) , m_ram(ram ? ram : (volatile unsigned short *) 0x60080000)
, m_dma(dma) , m_dma(dma)
, m_dmaStream(dmaStream) , m_dmaStream(dmaStream)
, m_width(horizontal ? LCD_L : LCD_S) , m_width(horizontal ? LCD_L : LCD_S)
@ -159,7 +60,7 @@ Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram,
WriteCmd(ILI9341_DISPLAY_ON); WriteCmd(ILI9341_DISPLAY_ON);
} }
void Ili9341Fsmc::WriteCmd(uint16_t cmd, std::initializer_list<uint16_t> params) void Ili9341Fsmc::WriteCmd(uint16_t cmd, std::initializer_list<const uint16_t> params)
{ {
*m_reg = cmd; *m_reg = cmd;
for(uint16_t param : params) for(uint16_t param : params)

View file

@ -6,28 +6,6 @@
#include <initializer_list> #include <initializer_list>
#include "main.h" #include "main.h"
// Color definitions
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
#define ILI9341_RED 0xF800 /* 255, 0, 0 */
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define ILI9341_PINK 0xF81F
class Ili9341Fsmc : public Singleton<Ili9341Fsmc> class Ili9341Fsmc : public Singleton<Ili9341Fsmc>
{ {
public: public:
@ -48,7 +26,7 @@ public:
private: private:
inline void WriteCmd(uint16_t cmd) { *m_reg = cmd; } inline void WriteCmd(uint16_t cmd) { *m_reg = cmd; }
inline void WriteCmd(uint16_t cmd, uint16_t param) { *m_reg = cmd; *m_ram = param; } inline void WriteCmd(uint16_t cmd, uint16_t param) { *m_reg = cmd; *m_ram = param; }
void WriteCmd(uint16_t cmd, std::initializer_list<uint16_t> params); void WriteCmd(uint16_t cmd, std::initializer_list<const uint16_t> params);
void WriteCmd_(uint16_t cmd, uint16_t cnt, ...); void WriteCmd_(uint16_t cmd, uint16_t cnt, ...);
void SetRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height); void SetRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
@ -71,6 +49,109 @@ private:
uint16_t m_rectY; uint16_t m_rectY;
uint16_t m_rectWidth; uint16_t m_rectWidth;
uint16_t m_rectHeight; uint16_t m_rectHeight;
enum Commands {
ILI9341_NOP = 0x00,
ILI9341_RESET = 0x01,
ILI9341_READ_DISPLAY_IDENTIFICATION_INFORMATION = 0x04,
ILI9341_READ_DISPLAY_STATUS = 0x09,
ILI9341_READ_DISPLAY_POWER_MODE = 0x0A,
ILI9341_READ_DISPLAY_MADCTL = 0x0B,
ILI9341_READ_DISPLAY_PIXEL_FORMAT = 0x0C,
ILI9341_READ_DISPLAY_IMAGE_FORMAT = 0x0D,
ILI9341_READ_DISPLAY_SIGNAL_MODE = 0x0E,
ILI9341_READ_DISPLAY_SELF_DIAGNOSTIC_RESULT = 0x0F,
ILI9341_ENTER_SLEEP_MODE = 0x10,
ILI9341_SLEEP_OUT = 0x11,
ILI9341_PARTIAL_MODE_ON = 0x12,
ILI9341_NORMAL_DISPLAY_MODE_ON = 0x13,
ILI9341_DISPLAY_INVERSION_OFF = 0x20,
ILI9341_DISPLAY_INVERSION_ON = 0x21,
ILI9341_GAMMA = 0x26,
ILI9341_DISPLAY_OFF = 0x28,
ILI9341_DISPLAY_ON = 0x29,
ILI9341_COLUMN_ADDR = 0x2A,
ILI9341_PAGE_ADDR = 0x2B,
ILI9341_GRAM = 0x2C,
ILI9341_COLOR_SET = 0x2D,
ILI9341_MEMORY_READ = 0x2E,
ILI9341_PARTIAL_AREA = 0x30,
ILI9341_VERTICAL_SCROLLING_DEFINITION = 0x33,
ILI9341_TEARING_EFFECT_LINE_OFF = 0x34,
ILI9341_TEARING_EFFECT_LINE_ON = 0x35,
ILI9341_MAC = 0x36,
ILI9341_VERTICAL_SCROLLING_START_ADDRESS = 0x37,
ILI9341_IDLE_MODE_OFF = 0x38,
ILI9341_IDLE_MODE_ON = 0x39,
ILI9341_PIXEL_FORMAT = 0x3A,
ILI9341_WMC = 0x3C,
ILI9341_RMC = 0x3E,
ILI9341_SET_TEAR_SCANLINE = 0x44,
ILI9341_WDB = 0x51,
ILI9341_READ_DISPLAY_BRIGHTNESS = 0x52,
ILI9341_WCD = 0x53,
ILI9341_READ_CTRL_DISPLAY = 0x54,
ILI9341_WCABC = 0x55,
ILI9341_RCABC = 0x56,
ILI9341_WCABCMB = 0x5E,
ILI9341_RCABCMB = 0x5F,
ILI9341_RGB_INTERFACE = 0xB0,
ILI9341_FRC = 0xB1,
ILI9341_FRAME_CTRL_NM = 0xB2,
ILI9341_FRAME_CTRL_IM = 0xB3,
ILI9341_FRAME_CTRL_PM = 0xB4,
ILI9341_BPC = 0xB5,
ILI9341_DFC = 0xB6,
ILI9341_ENTRY_MODE_SET = 0xB7,
ILI9341_BACKLIGHT_CONTROL_1 = 0xB8,
ILI9341_BACKLIGHT_CONTROL_2 = 0xB9,
ILI9341_BACKLIGHT_CONTROL_3 = 0xBA,
ILI9341_BACKLIGHT_CONTROL_4 = 0xBB,
ILI9341_BACKLIGHT_CONTROL_5 = 0xBC,
ILI9341_BACKLIGHT_CONTROL_6 = 0xBD,
ILI9341_BACKLIGHT_CONTROL_7 = 0xBE,
ILI9341_BACKLIGHT_CONTROL_8 = 0xBF,
ILI9341_POWER1 = 0xC0,
ILI9341_POWER2 = 0xC1,
ILI9341_VCOM1 = 0xC5,
ILI9341_VCOM2 = 0xC7,
ILI9341_POWERA = 0xCB,
ILI9341_POWERB = 0xCF,
ILI9341_READ_ID1 = 0xDA,
ILI9341_READ_ID2 = 0xDB,
ILI9341_READ_ID3 = 0xDC,
ILI9341_PGAMMA = 0xE0,
ILI9341_NGAMMA = 0xE1,
ILI9341_DTCA = 0xE8,
ILI9341_DTCB = 0xEA,
ILI9341_POWER_SEQ = 0xED,
ILI9341_3GAMMA_EN = 0xF2,
ILI9341_INTERFACE = 0xF6,
ILI9341_PRC = 0xF7,
};
public:
enum Colors {
ILI9341_BLACK = 0x0000, /* 0, 0, 0 */
ILI9341_NAVY = 0x000F, /* 0, 0, 128 */
ILI9341_DARKGREEN = 0x03E0, /* 0, 128, 0 */
ILI9341_DARKCYAN = 0x03EF, /* 0, 128, 128 */
ILI9341_MAROON = 0x7800, /* 128, 0, 0 */
ILI9341_PURPLE = 0x780F, /* 128, 0, 128 */
ILI9341_OLIVE = 0x7BE0, /* 128, 128, 0 */
ILI9341_LIGHTGREY = 0xC618, /* 192, 192, 192 */
ILI9341_DARKGREY = 0x7BEF, /* 128, 128, 128 */
ILI9341_BLUE = 0x001F, /* 0, 0, 255 */
ILI9341_GREEN = 0x07E0, /* 0, 255, 0 */
ILI9341_CYAN = 0x07FF, /* 0, 255, 255 */
ILI9341_RED = 0xF800, /* 255, 0, 0 */
ILI9341_MAGENTA = 0xF81F, /* 255, 0, 255 */
ILI9341_YELLOW = 0xFFE0, /* 255, 255, 0 */
ILI9341_WHITE = 0xFFFF, /* 255, 255, 255 */
ILI9341_ORANGE = 0xFD20, /* 255, 165, 0 */
ILI9341_GREENYELLOW = 0xAFE5, /* 173, 255, 47 */
ILI9341_PINK = 0xF81F,
};
}; };

View file

@ -10,16 +10,14 @@
#include <mainloop.h> #include <mainloop.h>
#include <initializer_list> #include <initializer_list>
#define LCD_REG 0x60000000 /* DC = 0 */
#define LCD_RAM 0x60080000 /* DC = 1 */
#define BORDER 60 #define BORDER 60
#define BARWIDTH 2 #define BARWIDTH 2
void MainLoop() void MainLoop()
{ {
uint16_t colors[] = { uint16_t colors[] = {
ILI9341_RED, ILI9341_ORANGE, ILI9341_YELLOW, ILI9341_GREENYELLOW, Ili9341Fsmc::ILI9341_RED, Ili9341Fsmc::ILI9341_ORANGE, Ili9341Fsmc::ILI9341_YELLOW, Ili9341Fsmc::ILI9341_GREENYELLOW,
ILI9341_GREEN, ILI9341_CYAN, ILI9341_BLUE, ILI9341_MAGENTA Ili9341Fsmc::ILI9341_GREEN, Ili9341Fsmc::ILI9341_CYAN, Ili9341Fsmc::ILI9341_BLUE, Ili9341Fsmc::ILI9341_MAGENTA
}; };
static uint16_t const colorCount = sizeof(colors)/sizeof(colors[0]); static uint16_t const colorCount = sizeof(colors)/sizeof(colors[0]);
uint32_t lastTick = 0; uint32_t lastTick = 0;
@ -28,10 +26,10 @@ void MainLoop()
//LL_SYSTICK_EnableIT(); //LL_SYSTICK_EnableIT();
Ili9341Fsmc &lcd(Ili9341Fsmc::Instance((volatile unsigned short *) LCD_REG, (volatile unsigned short *) LCD_RAM, DMA2, LL_DMA_STREAM_4, true)); Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, true));
lcd.FillRect(ILI9341_WHITE); lcd.FillRect(Ili9341Fsmc::ILI9341_WHITE);
lcd.FillRect(BORDER, BORDER, lcd.Width()- BORDER * 2, lcd.Height()-BORDER * 2, ILI9341_BLACK); lcd.FillRect(BORDER, BORDER, lcd.Width()- BORDER * 2, lcd.Height()-BORDER * 2, Ili9341Fsmc::ILI9341_BLACK);
uint16_t offset = 0; uint16_t offset = 0;
uint16_t maxidx = (lcd.Width() - BARWIDTH) / BARWIDTH; uint16_t maxidx = (lcd.Width() - BARWIDTH) / BARWIDTH;
for(;;) { for(;;) {

View file

@ -14,7 +14,7 @@ template<typename T> class Singleton {
public: public:
static T &Instance() { return *m_instance; } static T &Instance() { return *m_instance; }
template<typename ... Args> template<typename ... Args>
static T &Instance(Args &&... args) static T &Init(Args &&... args)
{ {
static T instance{ std::forward<Args>(args)... }; static T instance{ std::forward<Args>(args)... };
if(!m_instance) if(!m_instance)