Kinda works

This commit is contained in:
Attila Body 2021-10-31 00:33:00 +02:00
parent f3d345e2e3
commit 662a7a9b12
40 changed files with 2851 additions and 26 deletions

118
Application/application.cpp Normal file
View file

@ -0,0 +1,118 @@
/*
* mainloop.cpp
*
* Created on: Sep 11, 2019
* Author: abody
*/
#include "../Application/application.h"
#include <f4ll_cpp/ili9341.h>
#include <initializer_list>
#include "main.h"
#include "../Application/globals.h"
#include "../Application/strutil.h"
#define BORDER 60
#define BARWIDTH 2
using namespace f4ll_cpp;
void AppInit()
{
static Application m;
m.Start();
}
uint8_t SpiIo(SPI_TypeDef *spi, uint8_t data)
{
while(!LL_SPI_IsActiveFlag_TXE(spi));
LL_SPI_TransmitData8(spi, data);
while(!LL_SPI_IsActiveFlag_RXNE(spi));
return LL_SPI_ReceiveData8(spi);
}
uint16_t ReadTouch(SPI_TypeDef *spi, bool x)
{
static uint8_t const CMD_X_READ=0b10010000;
static uint8_t const CMD_Y_READ=0b11010000;
uint16_t tmp;
LL_GPIO_ResetOutputPin(TOUCH_CS_GPIO_Port, TOUCH_CS_Pin);
SpiIo(spi, x ? CMD_X_READ: CMD_Y_READ);
tmp = (uint16_t)SpiIo(spi, 0) << 8;
tmp |= SpiIo(spi, 0);
LL_GPIO_SetOutputPin(TOUCH_CS_GPIO_Port, TOUCH_CS_Pin);
return tmp >> 3;
}
Application::Application()
: GlobalsInitializer(&m_console)
, Task(3)
, m_console(USART1, DMA2, LL_DMA_STREAM_2, LL_DMA_STREAM_7, this, nullptr)
{
}
void Application::TaskFn(void *taskObj)
{
static_cast<Application*>(reinterpret_cast<fsl::Task<Application, APPLICATION_STACK_SIZE>*>(taskObj))->Loop();
}
void Application::Loop()
{
Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false));
lcd.SetScrollMode(true);
lcd.FillRect(Ili9341Fsmc::ILI9341_BLACK, false);
LL_SPI_Enable(SPI2);
for(int i = 0; i < 100; ++i) {
m_console.SendLine("Lofasz a seggedbe!\r\n");
}
for(;;) {
if(m_lineReceived && m_transmissionCompleted) {
m_transmissionCompleted = false;
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_lineReceived = false;
m_rcvdBuffer->busy = false;
}
if(LL_GPIO_IsInputPinSet(PENIRQ_GPIO_Port, PENIRQ_Pin))
LL_GPIO_SetOutputPin(LED1_GPIO_Port, LED1_Pin);
else {
LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);
uint16_t x = ReadTouch(SPI2, true);
uint16_t y = ReadTouch(SPI2, false);
unsigned len = strcpy_ex(m_appBuffer, "X: ");
len += uitodec(m_appBuffer+len, x);
len += strcpy_ex(m_appBuffer + len, ", Y: ");
len += uitodec(m_appBuffer + len, y);
len += strcpy_ex(m_appBuffer + len, "\r\n");
lcd.Print(m_appBuffer, len);
m_console.SendLine(m_appBuffer, len);
}
}
}
void Application::LineReceived(void *userParam, SerialConsole<257>::Buffer *buffer)
{
m_lineReceived = true;
m_rcvdBuffer = buffer;
}
void Application::TransmissionComplete(void *userParam, SerialConsole<257>::Buffer *buffer)
{
m_transmissionCompleted = true;
}

60
Application/application.h Normal file
View file

@ -0,0 +1,60 @@
/*
* mainloop.h
*
* Created on: Sep 11, 2019
* Author: abody
*/
#ifndef MAINLOOP_H_
#define MAINLOOP_H_
#if defined(__cplusplus)
extern "C" {
#endif
void AppInit();
#if defined(__cplusplus)
}
#endif
#if defined(__cplusplus)
#include <f4ll_cpp/serialconsole.h>
#include <fsl/task.h>
#include "../Application/globals.h"
struct GlobalsInitializer {
GlobalsInitializer(f4ll_cpp::SerialConsole<257> *console) {
g_console = console;
}
};
#define APPLICATION_STACK_SIZE 16384
class Application : public GlobalsInitializer
, public f4ll_cpp::SerialConsole<257>::ISerialConsoleCallback
, public fsl::Task<Application, APPLICATION_STACK_SIZE>
{
public:
Application();
void Loop();
friend class fsl::Task<Application, APPLICATION_STACK_SIZE>;
private:
static void TaskFn(void *taskObj);
virtual void LineReceived(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
virtual void TransmissionComplete(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
virtual char const * getName() { return "Application"; }
f4ll_cpp::SerialConsole<257> m_console;
volatile bool m_lineReceived = false;
volatile f4ll_cpp::SerialConsole<257>::Buffer *m_rcvdBuffer;
char m_appBuffer[128];
volatile bool m_transmissionCompleted = true;
};
#endif // __cplusplus
#endif /* MAINLOOP_H_ */

10
Application/globals.cpp Normal file
View file

@ -0,0 +1,10 @@
/*
* globals.c
*
* Created on: Aug 29, 2019
* Author: abody
*/
#include "../Application/globals.h"
f4ll_cpp::SerialConsole<257> *g_console = nullptr;

18
Application/globals.h Normal file
View file

@ -0,0 +1,18 @@
/*
* globals.h
*
* Created on: Aug 29, 2019
* Author: abody
*/
#ifndef GLOBALS_H_
#define GLOBALS_H_
#include <f4ll_cpp/serialconsole.h>
#if defined(__cplusplus)
extern f4ll_cpp::SerialConsole<257> *g_console;
#endif // __cplusplus
#endif /* GLOBALS_H_ */

View file

@ -0,0 +1,35 @@
/*
* interrupt.c
*
* Created on: Aug 29, 2019
* Author: abody
*/
#include "../Application/interrupt_handlers.h"
#include "main.h"
#include <f4ll_cpp/ili9341.h>
#include "../Application/globals.h"
void HandleLcdDmaIrq()
{
// DMA2 Stream4
f4ll_cpp::Ili9341Fsmc::HandleDmaIrq(&f4ll_cpp::Ili9341Fsmc::Instance());
}
void HandleConsoleRxDmaIrq()
{
if(g_console)
g_console->HandleRxDmaIrq();
}
void HandleConsoleTxDmaIrq()
{
if(g_console)
g_console->HandleTxDmaIrq();
}
void HandleConsoleUsartIrq()
{
if(g_console)
g_console->HandleUsartIrq();
}

View file

@ -0,0 +1,25 @@
/*
* interrupt.h
*
* Created on: Aug 29, 2019
* Author: abody
*/
#ifndef INTERRUPT_HANDLERS_H_
#define INTERRUPT_HANDLERS_H_
#ifdef __cplusplus
extern "C" {
#endif
void HandleLcdDmaIrq();
void HandleConsoleRxDmaIrq();
void HandleConsoleTxDmaIrq();
void HandleConsoleUsartIrq();
#ifdef __cplusplus
}
#endif
#endif /* INTERRUPT_HANDLERS_H_ */

111
Application/strutil.c Normal file
View file

@ -0,0 +1,111 @@
#include "../Application/strutil.h"
#include <stdint.h>
//////////////////////////////////////////////////////////////////////////////
size_t strcpy_ex(char *dst, char const *src)
{
size_t ret = 0;
do {
*dst++ = *src;
++ret;
} while(*src++);
return ret - 1;
}
//////////////////////////////////////////////////////////////////////////////
void strrev(char *first, char *last)
{
char tmp;
while(last > first) {
tmp = *first;
*first++ = *last;
*last-- = tmp;
}
}
//////////////////////////////////////////////////////////////////////////////
char tochr(const uint8_t in, const uint8_t upper)
{
return in + ((in < 10) ? '0' : (upper ? 'A' : 'a') - 10);
}
//////////////////////////////////////////////////////////////////////////////
size_t uitodec(char* buffer, uint32_t data)
{
char *b2 = buffer;
if(!data) {
*b2++ = '0';
*b2 = '\0';
return 1;
}
while(data) {
*b2++ = (data % 10) + '0';
data /= 10;
}
size_t ret = b2 - buffer;
*b2-- = 0;
strrev(buffer, b2);
return ret;
}
//////////////////////////////////////////////////////////////////////////////
size_t uitohex(char* buffer, uint32_t data, uint8_t chars)
{
char *b2 = buffer;
size_t ret = 0;
if(chars == 0xff || !chars)
{
if(!data) {
*b2++ = '0';
*b2 = '\0';
return 1;
}
while(data) {
uint8_t curval = data & 0x0f;
*b2++ = tochr(curval, 1);
data >>= 4;
}
ret = b2 - buffer;
}
else
{
ret = chars;
for(uint8_t pos = 0; pos < (uint8_t)ret; ++pos) {
*b2++ = tochr(data & 0x0f, 1);
data >>= 4;
}
}
*b2-- = 0;
strrev(buffer, b2);
return ret;
}
//////////////////////////////////////////////////////////////////////////////
size_t itodec(char* buffer, int data)
{
if(data < 0) {
*buffer++ = '-';
return uitodec(buffer, -data) + 1;
}
return uitodec(buffer, data);
}
//////////////////////////////////////////////////////////////////////////////
size_t itohex(char* buffer, int data)
{
if(data < 0) {
*buffer++ = '-';
return uitohex(buffer, -data, 0) + 1;
}
return uitohex(buffer, data, 0);
}

31
Application/strutil.h Normal file
View file

@ -0,0 +1,31 @@
/*
* strutil.h
*
* Created on: Feb 11, 2017
* Author: compi
*/
#ifndef _STRUTIL_H_
#define _STRUTIL_H_
#include <stddef.h>
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
//////////////////////////////////////////////////////////////////////////////
size_t strcpy_ex(char *dst, char const *src);
size_t uitodec(char* buffer, uint32_t data);
size_t uitohex(char* buffer, uint32_t data, uint8_t chars);
size_t itodec(char* buffer, int data);
size_t itohex(char* buffer, int data);
void strrev(char *first, char *last);
char tochr(const uint8_t in, const uint8_t upper);
#ifdef __cplusplus
}
#endif
#endif // _STRUTIL_H_

98
Application/zxpix_font.h Normal file
View file

@ -0,0 +1,98 @@
const unsigned char font[96][6] = {
{0x00,0x00,0x00,0x00,0x00,0x00}, //
{0x2f,0x00,0x00,0x00,0x00,0x00}, // !
{0x03,0x00,0x03,0x00,0x00,0x00}, // "
{0x12,0x3f,0x12,0x12,0x3f,0x12}, // #
{0x2e,0x2a,0x7f,0x2a,0x3a,0x00}, // $
{0x23,0x13,0x08,0x04,0x32,0x31}, // %
{0x10,0x2a,0x25,0x2a,0x10,0x20}, // &
{0x02,0x01,0x00,0x00,0x00,0x00}, // '
{0x1e,0x21,0x00,0x00,0x00,0x00}, // (
{0x21,0x1e,0x00,0x00,0x00,0x00}, // )
{0x08,0x2a,0x1c,0x2a,0x08,0x08}, // *
{0x08,0x08,0x3e,0x08,0x08,0x08}, // +
{0x80,0x60,0x00,0x00,0x00,0x00}, // ,
{0x08,0x08,0x08,0x08,0x08,0x00}, // -
{0x30,0x30,0x00,0x00,0x00,0x00}, // .
{0x20,0x10,0x08,0x04,0x02,0x00}, // /
{0x1e,0x31,0x29,0x25,0x23,0x1e}, // 0
{0x22,0x21,0x3f,0x20,0x20,0x20}, // 1
{0x32,0x29,0x29,0x29,0x29,0x26}, // 2
{0x12,0x21,0x21,0x25,0x25,0x1a}, // 3
{0x18,0x14,0x12,0x3f,0x10,0x10}, // 4
{0x17,0x25,0x25,0x25,0x25,0x19}, // 5
{0x1e,0x25,0x25,0x25,0x25,0x18}, // 6
{0x01,0x01,0x31,0x09,0x05,0x03}, // 7
{0x1a,0x25,0x25,0x25,0x25,0x1a}, // 8
{0x06,0x29,0x29,0x29,0x29,0x1e}, // 9
{0x24,0x00,0x00,0x00,0x00,0x00}, // :
{0x80,0x64,0x00,0x00,0x00,0x00}, // ;
{0x08,0x14,0x22,0x00,0x00,0x00}, // <
{0x14,0x14,0x14,0x14,0x14,0x00}, // =
{0x22,0x14,0x08,0x00,0x00,0x00}, // >
{0x02,0x01,0x01,0x29,0x05,0x02}, // ?
{0x1e,0x21,0x2d,0x2b,0x2d,0x0e}, // @
{0x3e,0x09,0x09,0x09,0x09,0x3e}, // A
{0x3f,0x25,0x25,0x25,0x25,0x1a}, // B
{0x1e,0x21,0x21,0x21,0x21,0x12}, // C
{0x3f,0x21,0x21,0x21,0x12,0x0c}, // D
{0x3f,0x25,0x25,0x25,0x25,0x21}, // E
{0x3f,0x05,0x05,0x05,0x05,0x01}, // F
{0x1e,0x21,0x21,0x21,0x29,0x1a}, // G
{0x3f,0x04,0x04,0x04,0x04,0x3f}, // H
{0x21,0x21,0x3f,0x21,0x21,0x21}, // I
{0x10,0x20,0x20,0x20,0x20,0x1f}, // J
{0x3f,0x04,0x0c,0x0a,0x11,0x20}, // K
{0x3f,0x20,0x20,0x20,0x20,0x20}, // L
{0x3f,0x02,0x04,0x04,0x02,0x3f}, // M
{0x3f,0x02,0x04,0x08,0x10,0x3f}, // N
{0x1e,0x21,0x21,0x21,0x21,0x1e}, // O
{0x3f,0x09,0x09,0x09,0x09,0x06}, // P
{0x1e,0x21,0x29,0x31,0x21,0x1e}, // Q
{0x3f,0x09,0x09,0x09,0x19,0x26}, // R
{0x12,0x25,0x25,0x25,0x25,0x18}, // S
{0x01,0x01,0x01,0x3f,0x01,0x01}, // T
{0x1f,0x20,0x20,0x20,0x20,0x1f}, // U
{0x0f,0x10,0x20,0x20,0x10,0x0f}, // V
{0x1f,0x20,0x10,0x10,0x20,0x1f}, // W
{0x21,0x12,0x0c,0x0c,0x12,0x21}, // X
{0x01,0x02,0x0c,0x38,0x04,0x02}, // Y
{0x21,0x31,0x29,0x25,0x23,0x21}, // Z
{0x3f,0x21,0x00,0x00,0x00,0x00}, // [
{0x02,0x04,0x08,0x10,0x20,0x00}, // "\"
{0x21,0x3f,0x00,0x00,0x00,0x00}, // ]
{0x04,0x02,0x3f,0x02,0x04,0x00}, // ^
{0x40,0x40,0x40,0x40,0x40,0x40}, // _
{0x01,0x02,0x00,0x00,0x00,0x00}, // `
{0x10,0x30,0x2a,0x2a,0x3c,0x00}, // a
{0x3f,0x24,0x24,0x24,0x18,0x00}, // b
{0x0c,0x14,0x22,0x22,0x00,0x00}, // c
{0x18,0x24,0x24,0x24,0x3f,0x00}, // d
{0x1c,0x2c,0x2a,0x2a,0x24,0x00}, // e
{0x3e,0x05,0x01,0x00,0x00,0x00}, // f
{0x18,0x28,0xa4,0xa4,0x7c,0x00}, // g
{0x3f,0x04,0x04,0x0c,0x30,0x00}, // h
{0x24,0x3d,0x20,0x00,0x00,0x00}, // i
{0x20,0x40,0x40,0x3d,0x00,0x00}, // j
{0x3f,0x0c,0x12,0x20,0x00,0x00}, // k
{0x1f,0x20,0x20,0x00,0x00,0x00}, // l
{0x3e,0x02,0x3c,0x02,0x3c,0x00}, // m
{0x3e,0x02,0x02,0x02,0x3c,0x00}, // n
{0x0c,0x14,0x22,0x32,0x0c,0x00}, // o
{0xfc,0x24,0x24,0x24,0x18,0x00}, // p
{0x18,0x24,0x24,0x24,0xfc,0x80}, // q
{0x3c,0x04,0x02,0x02,0x00,0x00}, // r
{0x24,0x2c,0x2a,0x2a,0x10,0x00}, // s
{0x02,0x1f,0x22,0x20,0x00,0x00}, // t
{0x1e,0x20,0x20,0x20,0x1e,0x00}, // u
{0x06,0x18,0x20,0x18,0x06,0x00}, // v
{0x1e,0x30,0x1c,0x30,0x0e,0x00}, // w
{0x22,0x14,0x08,0x14,0x22,0x00}, // x
{0x0c,0x10,0xa0,0xa0,0x7c,0x00}, // y
{0x22,0x32,0x2a,0x26,0x22,0x22}, // z
{0x0c,0x3f,0x21,0x00,0x00,0x00}, // {
{0x3f,0x00,0x00,0x00,0x00,0x00}, // |
{0x21,0x3f,0x0c,0x00,0x00,0x00}, // }
{0x02,0x01,0x02,0x01,0x00,0x00}, // ~
{0x00,0x00,0x00,0x00,0x00,0x00}
};