Touch pt. 1

This commit is contained in:
Attila Body 2020-02-28 15:20:22 +01:00
parent 22982db966
commit 46a5748e75
22 changed files with 3528 additions and 613 deletions

View file

@ -14,7 +14,7 @@
#define LCD_RAM (*((volatile unsigned short *) 0x60080000)) /* DC = 1 */
#define RGB2U16(R,G,B) ((R & 0xf8) << 8 | (G & 0xfc) << 3 | (B & 0xf8) >> 3)
#define SPLIT(x) ((uint8_t)(x >> 8)), ((uint8_t)x)
#define MSBSPLIT(x) ((uint8_t)(x >> 8)), ((uint8_t)x)
Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram,
DMA_TypeDef *dma, uint32_t dmaStream,
@ -58,7 +58,6 @@ Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram,
WriteCmd(ILI9341_SLEEP_OUT);
LL_mDelay(100);
WriteCmd(ILI9341_DISPLAY_ON);
WriteCmd(ILI9341_VERTICAL_SCROLLING_DEFINITION, {0x00, 0x00, SPLIT(m_height), 0x00, 0x00});
}
void Ili9341Fsmc::WriteCmd(uint16_t cmd, std::initializer_list<const uint16_t> params)
@ -80,6 +79,17 @@ void Ili9341Fsmc::WriteCmd_(uint16_t cmd, uint16_t cnt, ...)
va_end(argp);
}
void Ili9341Fsmc::SetScrollMode(bool on)
{
if(on != m_scrollMode) {
if(on)
WriteCmd(ILI9341_VERTICAL_SCROLLING_DEFINITION, {0x00, 0x00, MSBSPLIT(m_height), 0x00, 0x00});
else
WriteCmd(ILI9341_NORMAL_DISPLAY_MODE_ON);
m_scrollMode = on;
}
}
void Ili9341Fsmc::WritePixels(void *src, uint32_t count, bool increment, bool async)
{
WriteCmd(ILI9341_GRAM);
@ -130,7 +140,7 @@ void Ili9341Fsmc::ReadPixels(uint16_t *dst, uint32_t count)
void Ili9341Fsmc::SetScrollOffset()
{
uint16_t offsetData[2] = { SPLIT(m_scrollOffset) };
uint16_t offsetData[2] = { MSBSPLIT(m_scrollOffset) };
WriteCmd(ILI9341_VERTICAL_SCROLLING_START_ADDRESS);
*m_ram = offsetData[0];
*m_ram = offsetData[1];
@ -151,8 +161,8 @@ void Ili9341Fsmc::SetRect(uint16_t x, uint16_t y, uint16_t width, uint16_t heigh
uint16_t right = x + m_rectWidth - 1;
uint16_t bottom = y + m_rectHeight - 1;
WriteCmd(ILI9341_COLUMN_ADDR, { SPLIT(x), SPLIT(right) });
WriteCmd(ILI9341_PAGE_ADDR, { SPLIT(y), SPLIT(bottom) });
WriteCmd(ILI9341_COLUMN_ADDR, { MSBSPLIT(x), MSBSPLIT(right) });
WriteCmd(ILI9341_PAGE_ADDR, { MSBSPLIT(y), MSBSPLIT(bottom) });
}
void Ili9341Fsmc::FillRect(uint16_t color, bool async)
@ -237,7 +247,7 @@ void Ili9341Fsmc::PrintChar(char c, uint16_t x, uint16_t y, uint16_t fgColor, ui
PrintChar(c);
}
void Ili9341Fsmc::Print(char const *str, uint8_t len)
void Ili9341Fsmc::Print(char const *str, uint8_t len, bool transparent)
{
if(!len)
len = strlen(str);
@ -253,11 +263,12 @@ void Ili9341Fsmc::Print(char const *str, uint8_t len)
m_scrollOffset -= m_height;
WaitDmaIdle();
SetScrollOffset();
FillRect(0, AdjustY(m_yPos), m_width, CHRHEIGHT, m_bgColor);
if(!transparent)
FillRect(0, AdjustY(m_yPos), m_width, CHRHEIGHT, m_bgColor);
}
}
else
PrintChar(*str, false);
PrintChar(*str, transparent);
++str;
}
}

View file

@ -16,6 +16,7 @@ public:
DMA_TypeDef *dma, uint32_t dmaStream,
bool horizontal = true);
void SetScrollMode(bool on);
void FillRect(uint16_t color, bool async = true);
void FillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color, bool async = true);
uint16_t Width() { return m_width; }
@ -26,7 +27,7 @@ public:
void SetCursor(uint16_t x, uint16_t y);
void PrintChar(char c, uint16_t x, uint16_t y, uint16_t fgColor, uint16_t bgColor);
void PrintChar(char c, bool transparent = false);
void Print(char const *str, uint8_t len = 0);
void Print(char const *str, uint8_t len = 0, bool transparent = false);
inline void WaitDmaIdle() { while(m_dmaEngineBusy); }
@ -65,6 +66,7 @@ private:
uint16_t m_rectWidth;
uint16_t m_rectHeight;
bool m_scrollMode = false;
uint16_t m_scrollOffset = 0;
uint16_t m_xPos = 0;

View file

@ -40,6 +40,8 @@ public:
void HandleUsartIrq();
private:
void SetupTransmit(void *buffer, uint16_t length);
bool m_activeRxBuffer = false;
Buffer m_rxBuffers[2];
Buffer m_txBuffer;
@ -59,6 +61,12 @@ template<unsigned int bufSize> SerialConsole<bufSize>::SerialConsole(
SetupReceive(m_rxBuffers[m_activeRxBuffer].buffer, bufSize);
}
template<unsigned int bufSize> void SerialConsole<bufSize>::SetupTransmit(void *buffer, uint16_t length)
{
m_txBuffer.busy = true;
UartBase::SetupTransmit(buffer, length);
}
template<unsigned int bufSize> void SerialConsole<bufSize>::HandleRxDmaIrq()
{
if(*m_rxDma.GetIsReg() & m_rxDma.GetTcMask()) {
@ -150,7 +158,7 @@ template<unsigned int bufSize> void SerialConsole<bufSize>::SendLine(char const
if(length) {
while( m_txBuffer.busy );
memcpy(m_txBuffer.buffer, buffer, length);
if(m_txBuffer.buffer[length-1 != '\n']) {
if(m_txBuffer.buffer[length-1] != '\n') {
m_txBuffer.buffer[length++] = '\r';
m_txBuffer.buffer[length++] = '\n';
}