From ba34922951a9b016c637a0ac76350b44ab200b0a Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Sun, 15 Nov 2020 21:23:48 +0100 Subject: [PATCH 1/3] Renamed two members in Application class for better understandability --- App/application.cpp | 10 +++++----- App/application.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/App/application.cpp b/App/application.cpp index 281e528..643016c 100644 --- a/App/application.cpp +++ b/App/application.cpp @@ -71,13 +71,13 @@ void Application::Loop() } for(;;) { - if(m_received && m_transmitted) { - m_transmitted = false; + if(m_lineReceived && m_transmissionCompleted) { + m_transmissionCompleted = false; const char *line = const_cast(m_rcvdBuffer->buffer); m_console.SendLine(line, m_rcvdBuffer->len); lcd.Print(line); lcd.Print("\r\n", 2); - m_received = false; + m_lineReceived = false; m_rcvdBuffer->busy = false; } @@ -101,12 +101,12 @@ void Application::Loop() void Application::LineReceived(void *userParam, SerialConsole<257>::Buffer *buffer) { - m_received = true; + m_lineReceived = true; m_rcvdBuffer = buffer; } void Application::TransmissionComplete(void *userParam, SerialConsole<257>::Buffer *buffer) { - m_transmitted = true; + m_transmissionCompleted = true; } diff --git a/App/application.h b/App/application.h index b9893a3..7ffd219 100644 --- a/App/application.h +++ b/App/application.h @@ -38,10 +38,10 @@ private: virtual void TransmissionComplete(void *userParam, SerialConsole<257>::Buffer *buffer); SerialConsole<257> m_console; - volatile bool m_received = false; + volatile bool m_lineReceived = false; volatile SerialConsole<257>::Buffer *m_rcvdBuffer; - volatile bool m_transmitted = true; + volatile bool m_transmissionCompleted = true; }; #endif // __cplusplus From 0e09fd9a7ad1e815010abc730168573e5a828147 Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Mon, 16 Nov 2020 00:17:19 +0100 Subject: [PATCH 2/3] moving application communications buffer to the application class --- App/application.cpp | 16 +++++++--------- App/application.h | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/App/application.cpp b/App/application.cpp index 643016c..2ab42a8 100644 --- a/App/application.cpp +++ b/App/application.cpp @@ -57,8 +57,6 @@ Application::Application() void Application::Loop() { - char buffer[128]; - Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false)); lcd.SetScrollMode(true); @@ -88,13 +86,13 @@ void Application::Loop() uint16_t x = ReadTouch(SPI2, true); uint16_t y = ReadTouch(SPI2, false); - unsigned len = strcpy_ex(buffer, "X: "); - len += uitodec(buffer+len, x); - len += strcpy_ex(buffer + len, ", Y: "); - len += uitodec(buffer + len, y); - len += strcpy_ex(buffer + len, "\r\n"); - lcd.Print(buffer, len); - m_console.SendLine(buffer, len); + 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); } } } diff --git a/App/application.h b/App/application.h index 7ffd219..4b7a497 100644 --- a/App/application.h +++ b/App/application.h @@ -40,6 +40,7 @@ private: SerialConsole<257> m_console; volatile bool m_lineReceived = false; volatile SerialConsole<257>::Buffer *m_rcvdBuffer; + char m_appBuffer[128]; volatile bool m_transmissionCompleted = true; }; From 8c6213677370f33a8e275116cc7ff81e4c65bcd9 Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Mon, 16 Nov 2020 13:24:15 +0100 Subject: [PATCH 3/3] moved f4ll_cpp imto its own namespace moved strutil to the application --- App/application.cpp | 4 ++-- App/application.h | 12 ++++++------ App/globals.cpp | 2 +- App/globals.h | 2 +- App/interrupt_handlers.cpp | 2 +- {components/f4ll_cpp => App}/strutil.c | 2 +- {components/f4ll_cpp => App}/strutil.h | 8 ++++---- components/f4ll_cpp/crcscheduler.cpp | 4 ++++ components/f4ll_cpp/crcscheduler.h | 4 ++++ components/f4ll_cpp/dmahelper.cpp | 4 ++++ components/f4ll_cpp/dmahelper.h | 15 ++++----------- components/f4ll_cpp/ili9341.cpp | 4 ++++ components/f4ll_cpp/ili9341.h | 4 ++++ components/f4ll_cpp/memcpydma.cpp | 4 ++++ components/f4ll_cpp/memcpydma.h | 3 +++ components/f4ll_cpp/packetuart.cpp | 4 ++++ components/f4ll_cpp/packetuart.h | 4 ++++ components/f4ll_cpp/serialconsole.h | 4 ++++ components/f4ll_cpp/singleton.h | 4 ++++ components/f4ll_cpp/uartbase.cpp | 3 +++ components/f4ll_cpp/uartbase.h | 4 ++++ 21 files changed, 70 insertions(+), 27 deletions(-) rename {components/f4ll_cpp => App}/strutil.c (98%) rename {components/f4ll_cpp => App}/strutil.h (86%) diff --git a/App/application.cpp b/App/application.cpp index 2ab42a8..c5f712d 100644 --- a/App/application.cpp +++ b/App/application.cpp @@ -6,16 +6,16 @@ */ #include -#include #include #include #include "main.h" #include "globals.h" +#include "strutil.h" #define BORDER 60 #define BARWIDTH 2 - +using namespace f4ll_cpp; void MainLoop() { diff --git a/App/application.h b/App/application.h index 4b7a497..38a5222 100644 --- a/App/application.h +++ b/App/application.h @@ -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; diff --git a/App/globals.cpp b/App/globals.cpp index 4e7a819..e8c3c06 100644 --- a/App/globals.cpp +++ b/App/globals.cpp @@ -7,4 +7,4 @@ #include "globals.h" -SerialConsole<257> *g_console = nullptr; +f4ll_cpp::SerialConsole<257> *g_console = nullptr; diff --git a/App/globals.h b/App/globals.h index 135925a..b9e6f07 100644 --- a/App/globals.h +++ b/App/globals.h @@ -11,7 +11,7 @@ #if defined(__cplusplus) -extern SerialConsole<257> *g_console; +extern f4ll_cpp::SerialConsole<257> *g_console; #endif // __cplusplus diff --git a/App/interrupt_handlers.cpp b/App/interrupt_handlers.cpp index 3b659e2..bf3623c 100644 --- a/App/interrupt_handlers.cpp +++ b/App/interrupt_handlers.cpp @@ -12,7 +12,7 @@ void HandleLcdDmaIrq() { // DMA2 Stream4 - Ili9341Fsmc::HandleDmaIrq(&Ili9341Fsmc::Instance()); + f4ll_cpp::Ili9341Fsmc::HandleDmaIrq(&f4ll_cpp::Ili9341Fsmc::Instance()); } void HandleConsoleRxDmaIrq() diff --git a/components/f4ll_cpp/strutil.c b/App/strutil.c similarity index 98% rename from components/f4ll_cpp/strutil.c rename to App/strutil.c index 8ac84d3..12c5812 100644 --- a/components/f4ll_cpp/strutil.c +++ b/App/strutil.c @@ -1,5 +1,5 @@ #include -#include +#include "strutil.h" ////////////////////////////////////////////////////////////////////////////// size_t strcpy_ex(char *dst, char const *src) diff --git a/components/f4ll_cpp/strutil.h b/App/strutil.h similarity index 86% rename from components/f4ll_cpp/strutil.h rename to App/strutil.h index 49ddc39..f3771a4 100644 --- a/components/f4ll_cpp/strutil.h +++ b/App/strutil.h @@ -4,9 +4,8 @@ * Created on: Feb 11, 2017 * Author: compi */ - -#ifndef _STM32PLUS_STRUTIL_H_ -#define _STM32PLUS_STRUTIL_H_ +#ifndef _STRUTIL_H_ +#define _STRUTIL_H_ #include #include @@ -28,4 +27,5 @@ char tochr(const uint8_t in, const uint8_t upper); } #endif -#endif /* _STM32PLUS_STRUTIL_H_ */ + +#endif // _STRUTIL_H_ diff --git a/components/f4ll_cpp/crcscheduler.cpp b/components/f4ll_cpp/crcscheduler.cpp index 0ec6bb3..1f46a6c 100644 --- a/components/f4ll_cpp/crcscheduler.cpp +++ b/components/f4ll_cpp/crcscheduler.cpp @@ -27,6 +27,9 @@ # define DIAG_INTERRUPT_OUT() #endif +namespace f4ll_cpp +{ + void Crc_StartNextTask(struct crcstatus_t *status); @@ -188,3 +191,4 @@ void CrcScheduler::_HandleDmaIrq() DIAG_INTERRUPT_OUT(); } +} // f4ll_cpp diff --git a/components/f4ll_cpp/crcscheduler.h b/components/f4ll_cpp/crcscheduler.h index 91ba259..ffa27ae 100644 --- a/components/f4ll_cpp/crcscheduler.h +++ b/components/f4ll_cpp/crcscheduler.h @@ -17,6 +17,9 @@ #include #include +namespace f4ll_cpp +{ + class CrcScheduler { public: struct ICrcCallback { @@ -64,5 +67,6 @@ private: crcslot_t *m_firstSlot; }; +} // f4ll_cpp #endif /* CRC_HANDLER_H_ */ diff --git a/components/f4ll_cpp/dmahelper.cpp b/components/f4ll_cpp/dmahelper.cpp index 47d051a..f4b080e 100644 --- a/components/f4ll_cpp/dmahelper.cpp +++ b/components/f4ll_cpp/dmahelper.cpp @@ -9,6 +9,9 @@ #define MOCKABLE(x) x #endif +namespace f4ll_cpp +{ + DmaHelper::DmaHelper(DMA_TypeDef *dma, uint32_t stream) { m_dma = dma; @@ -80,3 +83,4 @@ uint32_t DmaHelper::_GetTcMask(uint32_t stream) return tcMasks[stream]; } +} // f4ll_cpp diff --git a/components/f4ll_cpp/dmahelper.h b/components/f4ll_cpp/dmahelper.h index be4cf60..90b8f5e 100644 --- a/components/f4ll_cpp/dmahelper.h +++ b/components/f4ll_cpp/dmahelper.h @@ -14,6 +14,9 @@ #define DECLARE_MOCK(x) #endif +namespace f4ll_cpp +{ + class DmaHelper { public: DmaHelper(DMA_TypeDef *dma, uint32_t stream); @@ -49,16 +52,6 @@ private: uint32_t m_tcMask; }; - -#ifdef UNITTEST -DECLARE_MOCK(Dma_GetIsReg); -DECLARE_MOCK(Dma_GetIfcReg); -DECLARE_MOCK(Dma_GetDmeMask); -DECLARE_MOCK(Dma_GetTeMask); -DECLARE_MOCK(Dma_GetHtMask); -DECLARE_MOCK(Dma_GetTcMask); -DECLARE_MOCK(Dma_GetFeMask); -DECLARE_MOCK(Dma_Init); -#endif +} // f4ll_cpp #endif /* DMA_HELPER_H_ */ diff --git a/components/f4ll_cpp/ili9341.cpp b/components/f4ll_cpp/ili9341.cpp index 9b6b271..a4bbba4 100644 --- a/components/f4ll_cpp/ili9341.cpp +++ b/components/f4ll_cpp/ili9341.cpp @@ -16,6 +16,8 @@ #define RGB2U16(R,G,B) ((R & 0xf8) << 8 | (G & 0xfc) << 3 | (B & 0xf8) >> 3) #define MSBSPLIT(x) ((uint8_t)(x >> 8)), ((uint8_t)x) +namespace f4ll_cpp { + Ili9341Fsmc::Ili9341Fsmc(volatile uint16_t *reg, volatile uint16_t *ram, DMA_TypeDef *dma, uint32_t dmaStream, bool horizontal) @@ -395,3 +397,5 @@ const uint8_t Ili9341Fsmc::m_font[CHRCOUNT][CHRWIDTH] = { {0x02,0x01,0x02,0x01,0x00,0x00}, // ~ {0x00,0x00,0x00,0x00,0x00,0x00} }; + +} // f4ll_cpp diff --git a/components/f4ll_cpp/ili9341.h b/components/f4ll_cpp/ili9341.h index a9e0763..02ce413 100644 --- a/components/f4ll_cpp/ili9341.h +++ b/components/f4ll_cpp/ili9341.h @@ -5,6 +5,8 @@ #include #include +namespace f4ll_cpp { + class Ili9341Fsmc : public Singleton, private DmaHelper { public: @@ -186,4 +188,6 @@ public: }; }; +} // f4ll_cpp + #endif diff --git a/components/f4ll_cpp/memcpydma.cpp b/components/f4ll_cpp/memcpydma.cpp index aba8a4b..c34c11e 100644 --- a/components/f4ll_cpp/memcpydma.cpp +++ b/components/f4ll_cpp/memcpydma.cpp @@ -7,6 +7,8 @@ #include #include +namespace f4ll_cpp { + MemcpyDma::MemcpyDma(DMA_TypeDef *dma, uint32_t stream) : DmaHelper(dma, stream), m_busy(false) @@ -33,3 +35,5 @@ void MemcpyDma::HandleDmaIrq(void) m_busy = false; } } + +} // f4ll_cpp diff --git a/components/f4ll_cpp/memcpydma.h b/components/f4ll_cpp/memcpydma.h index 9f6e33c..aa93b8c 100644 --- a/components/f4ll_cpp/memcpydma.h +++ b/components/f4ll_cpp/memcpydma.h @@ -14,6 +14,8 @@ #include +namespace f4ll_cpp { + class MemcpyDma : public DmaHelper, public Singleton { public: @@ -26,5 +28,6 @@ private: volatile bool m_busy; }; +} // namespace f4ll_cpp #endif /* MEMCPY_DMA_H_ */ diff --git a/components/f4ll_cpp/packetuart.cpp b/components/f4ll_cpp/packetuart.cpp index 545e700..5f68891 100644 --- a/components/f4ll_cpp/packetuart.cpp +++ b/components/f4ll_cpp/packetuart.cpp @@ -30,6 +30,9 @@ #define STARTMARKER 0x95 +namespace f4ll_cpp +{ + static inline uint32_t RoundUpTo4(uint32_t inp) { return (inp + 3) & 0xfffc; @@ -280,3 +283,4 @@ void PacketUart::HandleUsartIrq() DIAG_INTERRUPT_OUT(); } +} // f4ll_cpp diff --git a/components/f4ll_cpp/packetuart.h b/components/f4ll_cpp/packetuart.h index cc6135b..b694a88 100644 --- a/components/f4ll_cpp/packetuart.h +++ b/components/f4ll_cpp/packetuart.h @@ -13,6 +13,8 @@ #define USART_STATS_DISABLED +namespace f4ll_cpp { + class PacketUart : public UartBase, public CrcScheduler::ICrcCallback { public: @@ -100,4 +102,6 @@ private: Buffer rxBuffers[2]; }; +} // f4ll_cpp + #endif /* UART_HANDLER_H_ */ diff --git a/components/f4ll_cpp/serialconsole.h b/components/f4ll_cpp/serialconsole.h index d6bf32d..16e91a2 100644 --- a/components/f4ll_cpp/serialconsole.h +++ b/components/f4ll_cpp/serialconsole.h @@ -14,6 +14,8 @@ #include +namespace f4ll_cpp { + template class SerialConsole : protected UartBase { public: @@ -166,4 +168,6 @@ template void SerialConsole::SendLine(char const } } +} // f4ll_cpp + #endif /* CONSOLEHANDLER_H_ */ diff --git a/components/f4ll_cpp/singleton.h b/components/f4ll_cpp/singleton.h index 7ca6e5c..75a52f8 100644 --- a/components/f4ll_cpp/singleton.h +++ b/components/f4ll_cpp/singleton.h @@ -10,6 +10,8 @@ #include +namespace f4ll_cpp { + template class Singleton { public: static T &Instance() { return *m_instance; } @@ -32,4 +34,6 @@ protected: template T* Singleton::m_instance = nullptr; +} // f4ll_cpp + #endif /* SINGLETON_H_ */ diff --git a/components/f4ll_cpp/uartbase.cpp b/components/f4ll_cpp/uartbase.cpp index 5e4e791..1c48d18 100644 --- a/components/f4ll_cpp/uartbase.cpp +++ b/components/f4ll_cpp/uartbase.cpp @@ -7,6 +7,8 @@ #include +namespace f4ll_cpp { + UartBase::UartBase(USART_TypeDef *uart, DMA_TypeDef *dma, uint32_t stream_rx, uint32_t stream_tx) : m_uart(uart) , m_rxDma(dma, stream_rx) @@ -44,3 +46,4 @@ void UartBase::SetupTransmit(void *buffer, uint16_t length) LL_DMA_EnableStream(m_txDma.GetDma(), m_txDma.GetStream()); } +} // f4ll_cpp diff --git a/components/f4ll_cpp/uartbase.h b/components/f4ll_cpp/uartbase.h index fceefa6..557916a 100644 --- a/components/f4ll_cpp/uartbase.h +++ b/components/f4ll_cpp/uartbase.h @@ -10,6 +10,8 @@ #include #include +namespace f4ll_cpp { + class UartBase { public: @@ -24,4 +26,6 @@ protected: DmaHelper m_txDma; }; +} // f4ll_cpp + #endif /* F4LL_CPP_UARTBASE_H_ */