moved f4ll_cpp imto its own namespace

moved strutil to the application
This commit is contained in:
Attila Body 2020-11-16 13:24:15 +01:00
parent 3a20a7d846
commit fb5670a950
21 changed files with 70 additions and 27 deletions

View file

@ -6,16 +6,16 @@
*/
#include <f4ll_cpp/ili9341.h>
#include <f4ll_cpp/strutil.h>
#include <application.h>
#include <initializer_list>
#include "main.h"
#include "globals.h"
#include "strutil.h"
#define BORDER 60
#define BARWIDTH 2
using namespace f4ll_cpp;
void MainLoop()
{

View file

@ -23,23 +23,23 @@ void MainLoop();
#include "globals.h"
struct GlobalsInitializer {
GlobalsInitializer(SerialConsole<257> *console) {
GlobalsInitializer(f4ll_cpp::SerialConsole<257> *console) {
g_console = console;
}
};
class Application : public GlobalsInitializer, public SerialConsole<257>::ISerialConsoleCallback {
class Application : public GlobalsInitializer, public f4ll_cpp::SerialConsole<257>::ISerialConsoleCallback {
public:
Application();
void Loop();
private:
virtual void LineReceived(void *userParam, SerialConsole<257>::Buffer *buffer);
virtual void TransmissionComplete(void *userParam, SerialConsole<257>::Buffer *buffer);
virtual void LineReceived(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
virtual void TransmissionComplete(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
SerialConsole<257> m_console;
f4ll_cpp::SerialConsole<257> m_console;
volatile bool m_lineReceived = false;
volatile SerialConsole<257>::Buffer *m_rcvdBuffer;
volatile f4ll_cpp::SerialConsole<257>::Buffer *m_rcvdBuffer;
char m_appBuffer[128];
volatile bool m_transmissionCompleted = true;

View file

@ -7,4 +7,4 @@
#include "globals.h"
SerialConsole<257> *g_console = nullptr;
f4ll_cpp::SerialConsole<257> *g_console = nullptr;

View file

@ -11,7 +11,7 @@
#if defined(__cplusplus)
extern SerialConsole<257> *g_console;
extern f4ll_cpp::SerialConsole<257> *g_console;
#endif // __cplusplus

View file

@ -12,7 +12,7 @@
void HandleLcdDmaIrq()
{
// DMA2 Stream4
Ili9341Fsmc::HandleDmaIrq(&Ili9341Fsmc::Instance());
f4ll_cpp::Ili9341Fsmc::HandleDmaIrq(&f4ll_cpp::Ili9341Fsmc::Instance());
}
void HandleConsoleRxDmaIrq()

110
App/strutil.c Normal file
View file

@ -0,0 +1,110 @@
#include <stdint.h>
#include "strutil.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
App/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_