This commit is contained in:
Attila Body 2020-02-12 17:11:08 +01:00
parent 49383b1b32
commit 229846fe6d
5 changed files with 79 additions and 42 deletions

View file

@ -5,7 +5,7 @@
* Author: abody
*/
#include <ili9341.h>
#include <f4ll_cpp/ili9341.h>
#include <application.h>
#include <initializer_list>
#include "main.h"
@ -31,26 +31,23 @@ Application::Application()
void Application::Loop()
{
//LL_SYSTICK_EnableIT();
Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false));
lcd.FillRect(Ili9341Fsmc::ILI9341_BLACK, false);
//lcd.Test();
lcd.SetCursor( 10, 10, Ili9341Fsmc::ILI9341_WHITE, Ili9341Fsmc::ILI9341_BLACK);
lcd.Print("Baszod");
lcd.FillRect(Ili9341Fsmc::ILI9341_ORANGE, false);
lcd.Test();
lcd.Print("0 1 2 3 4 5 6 7 8 9 A B C D E F\r\n");
for(;;) {
if(m_received && m_transmitted) {
m_transmitted = false;
m_console.SendLine(reinterpret_cast<char*>(const_cast<char*>(m_rcvdBuffer->buffer)), m_rcvdBuffer->len);
const char *line = const_cast<const char*>(m_rcvdBuffer->buffer);
m_console.SendLine(line, m_rcvdBuffer->len);
lcd.Print(line);
lcd.Print("\r\n", 2);
m_received = false;
m_rcvdBuffer->busy = false;
}
}
//LL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
//LL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
//LL_mDelay(25);
}
void Application::LineReceived(void *userParam, SerialConsole<257>::Buffer *buffer)

View file

@ -7,7 +7,7 @@
#include <interrupt_handlers.h>
#include "main.h"
#include "globals.h"
#include "ili9341.h"
#include <f4ll_cpp/ili9341.h>
void HandleLcdDmaIrq()
{

View file

@ -1,6 +1,5 @@
#include <ili9341.h>
#include "stm32f4xx_hal.h"
#include "main.h"
#include <f4ll_cpp/ili9341.h>
#include <platform/core_ll.h>
#include <inttypes.h>
#include <string.h>
#include <stdarg.h>
@ -32,7 +31,7 @@ Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram,
LL_DMA_EnableIT_TE(GetDma(), GetStream());
WriteCmd(ILI9341_RESET);
HAL_Delay(10);
LL_mDelay(10);
WriteCmd(ILI9341_DISPLAY_OFF);
WriteCmd(ILI9341_POWERA, {0x39, 0x2C, 0x00, 0x34, 0x02});
WriteCmd(ILI9341_POWERB, {0x00, 0xC1, 0x30});
@ -55,7 +54,7 @@ Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram,
WriteCmd(ILI9341_PGAMMA, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00});
WriteCmd(ILI9341_NGAMMA, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F});
WriteCmd(ILI9341_SLEEP_OUT);
HAL_Delay(100);
LL_mDelay(100);
WriteCmd(ILI9341_DISPLAY_ON);
}
@ -154,21 +153,38 @@ void Ili9341Fsmc::SetCursor(uint16_t x, uint16_t y, uint16_t fgColor, uint16_t b
m_bgColor = bgColor;
}
void Ili9341Fsmc::PrintChar(char c)
void Ili9341Fsmc::PrintChar(char c, bool transparent)
{
// fonts are rotated, one byte representing one column
if(m_xPos >= m_width - CHRWIDTH || m_yPos >= m_height - CHRHEIGHT || c < ' ' || c >= '~')
return;
uint8_t const *chrPtr = m_font[c - 32];
SetRect(m_xPos, m_yPos, CHRWIDTH, CHRHEIGHT);
if(transparent) {
WaitDmaIdle();
WriteCmd(ILI9341_MEMORY_READ);
*m_ram;
LL_DMA_SetM2MSrcAddress(GetDma(), GetStream(), reinterpret_cast<uint32_t>(m_ram));
LL_DMA_SetPeriphIncMode(GetDma(), GetStream(), LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetM2MDstAddress(GetDma(), GetStream(), reinterpret_cast<uint32_t>(m_fontBuffer));
LL_DMA_SetMemoryIncMode(GetDma(), GetStream(), LL_DMA_MEMORY_INCREMENT);
SetupDmaSize(sizeof(m_fontBuffer)/sizeof(m_fontBuffer[0][0]));
m_dmaEngineBusy = true;
LL_DMA_EnableStream(GetDma(), GetStream());
}
WaitDmaIdle();
WriteCmd(ILI9341_GRAM);
for(uint8_t y = 0; y < CHRWIDTH; ++y ) {
uint8_t mask = 0x80;
for(uint8_t x = 0; x < CHRHEIGHT; ++x)
*m_ram = (chrPtr[x] & mask) ? m_fgColor : m_fgColor;
mask >>= 1;
for(uint8_t y = 0; y < CHRHEIGHT; ++y ) {
uint8_t mask = 1 << y;
for(uint8_t x = 0; x < CHRWIDTH; ++x) {
*m_ram = (chrPtr[x] & mask) ? m_fgColor : (transparent ? m_fontBuffer[y][x] : m_bgColor);
}
m_xPos += CHRHEIGHT;
}
m_xPos += CHRWIDTH;
}
void Ili9341Fsmc::PrintChar(char c, uint16_t x, uint16_t y, uint16_t fgColor, uint16_t bgColor)
{
SetCursor(x, y, fgColor, bgColor);
@ -179,23 +195,40 @@ void Ili9341Fsmc::Print(char const *str, uint8_t len)
{
if(!len)
len = strlen(str);
while(len--)
PrintChar(*str++);
while(len--) {
if(*str == '\r')
m_xPos = 0;
else if(*str == '\n')
m_yPos += CHRHEIGHT;
else
PrintChar(*str, false);
++str;
}
}
void Ili9341Fsmc::Test() {
FillRect(ILI9341_PINK, false);
void Ili9341Fsmc::Test()
{
static uint16_t linebuf[320];
uint16_t x;
WriteCmd(ILI9341_READ_ID4);
for( x= 0; x < 4; ++x)
linebuf[x] = *m_ram;
// uint16_t *bufptr = linebuf;
// WriteCmd(ILI9341_MEMORY_READ);
// for(x = 0; x < m_width; ++x)
// *bufptr++ = *m_ram;
WriteCmd(ILI9341_GRAM);
uint16_t fillers[4] = { 0xf800, 0x7e0, 0x1f, 0xffff };
for(uint32_t y = 0; y < m_height; ++y) {
uint32_t x;
for(x = 0; x < m_width / 2; ++x)
*m_ram = fillers[ (x&0x18) >> 3 ];
for( ; x < m_width; ++x)
*m_ram = 0;
}
}

View file

@ -4,8 +4,6 @@
#include <f4ll_cpp/singleton.h>
#include <f4ll_cpp/dmahelper.h>
#include <inttypes.h>
#include <initializer_list>
#include "main.h"
class Ili9341Fsmc : public Singleton<Ili9341Fsmc>, private DmaHelper
{
@ -20,7 +18,7 @@ public:
uint16_t Height() { return m_height; }
void SetCursor(uint16_t x, uint16_t y, uint16_t fgColor, uint16_t bgColor);
void PrintChar(char c, uint16_t x, uint16_t y, uint16_t fgColor, uint16_t bgColor);
void PrintChar(char c);
void PrintChar(char c, bool transparent = false);
void Print(char const *str, uint8_t len = 0);
inline void WaitDmaIdle() { while(m_dmaEngineBusy); }
@ -128,6 +126,7 @@ private:
ILI9341_READ_ID1 = 0xDA,
ILI9341_READ_ID2 = 0xDB,
ILI9341_READ_ID3 = 0xDC,
ILI9341_READ_ID4 = 0xD3,
ILI9341_PGAMMA = 0xE0,
ILI9341_NGAMMA = 0xE1,
ILI9341_DTCA = 0xE8,
@ -138,10 +137,11 @@ private:
ILI9341_PRC = 0xF7,
};
static const uint8_t CHRHEIGHT = 8;
static const uint8_t CHRHEIGHT = 8; // SHOULD BE 8
static const uint8_t CHRWIDTH = 6;
static const uint8_t CHRCOUNT = 96;
static const uint8_t m_font[CHRCOUNT][CHRWIDTH];
uint16_t m_fontBuffer[CHRHEIGHT][CHRWIDTH];
public:
enum Colors {
@ -167,11 +167,4 @@ public:
};
};
/* Includes ------------------------------------------------------------------*/
void ili9341_Reset(void);
void ili9341_writeData(char Data);
void ili9341_writeCommand(char Command);
void ili9341_init(void);
#endif

View file

@ -0,0 +1,14 @@
/*
* core_ll.h
*
* Created on: Feb 12, 2020
* Author: abody
*/
#ifndef FIRMWARE_PLATFORM_CORE_LL_H_
#define FIRMWARE_PLATFORM_CORE_LL_H_
#include <stm32f4xx_ll_cortex.h>
#include <stm32f4xx_ll_utils.h>
#endif /* FIRMWARE_PLATFORM_CORE_LL_H_ */