diff --git a/App/application.cpp b/App/application.cpp index c5f712d..281e528 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() { @@ -57,6 +57,8 @@ Application::Application() void Application::Loop() { + char buffer[128]; + Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false)); lcd.SetScrollMode(true); @@ -69,13 +71,13 @@ void Application::Loop() } for(;;) { - if(m_lineReceived && m_transmissionCompleted) { - m_transmissionCompleted = false; + if(m_received && m_transmitted) { + m_transmitted = 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_lineReceived = false; + m_received = false; m_rcvdBuffer->busy = false; } @@ -86,25 +88,25 @@ void Application::Loop() 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); + 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); } } } void Application::LineReceived(void *userParam, SerialConsole<257>::Buffer *buffer) { - m_lineReceived = true; + m_received = true; m_rcvdBuffer = buffer; } void Application::TransmissionComplete(void *userParam, SerialConsole<257>::Buffer *buffer) { - m_transmissionCompleted = true; + m_transmitted = true; } diff --git a/App/application.h b/App/application.h index 38a5222..b9893a3 100644 --- a/App/application.h +++ b/App/application.h @@ -23,26 +23,25 @@ void MainLoop(); #include "globals.h" struct GlobalsInitializer { - GlobalsInitializer(f4ll_cpp::SerialConsole<257> *console) { + GlobalsInitializer(SerialConsole<257> *console) { g_console = console; } }; -class Application : public GlobalsInitializer, public f4ll_cpp::SerialConsole<257>::ISerialConsoleCallback { +class Application : public GlobalsInitializer, public SerialConsole<257>::ISerialConsoleCallback { public: Application(); void Loop(); private: - virtual void LineReceived(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer); - virtual void TransmissionComplete(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer); + virtual void LineReceived(void *userParam, SerialConsole<257>::Buffer *buffer); + virtual void TransmissionComplete(void *userParam, SerialConsole<257>::Buffer *buffer); - f4ll_cpp::SerialConsole<257> m_console; - volatile bool m_lineReceived = false; - volatile f4ll_cpp::SerialConsole<257>::Buffer *m_rcvdBuffer; - char m_appBuffer[128]; + SerialConsole<257> m_console; + volatile bool m_received = false; + volatile SerialConsole<257>::Buffer *m_rcvdBuffer; - volatile bool m_transmissionCompleted = true; + volatile bool m_transmitted = true; }; #endif // __cplusplus diff --git a/App/globals.cpp b/App/globals.cpp index e8c3c06..4e7a819 100644 --- a/App/globals.cpp +++ b/App/globals.cpp @@ -7,4 +7,4 @@ #include "globals.h" -f4ll_cpp::SerialConsole<257> *g_console = nullptr; +SerialConsole<257> *g_console = nullptr; diff --git a/App/globals.h b/App/globals.h index b9e6f07..135925a 100644 --- a/App/globals.h +++ b/App/globals.h @@ -11,7 +11,7 @@ #if defined(__cplusplus) -extern f4ll_cpp::SerialConsole<257> *g_console; +extern SerialConsole<257> *g_console; #endif // __cplusplus diff --git a/App/interrupt_handlers.cpp b/App/interrupt_handlers.cpp index bf3623c..3b659e2 100644 --- a/App/interrupt_handlers.cpp +++ b/App/interrupt_handlers.cpp @@ -12,7 +12,7 @@ void HandleLcdDmaIrq() { // DMA2 Stream4 - f4ll_cpp::Ili9341Fsmc::HandleDmaIrq(&f4ll_cpp::Ili9341Fsmc::Instance()); + Ili9341Fsmc::HandleDmaIrq(&Ili9341Fsmc::Instance()); } void HandleConsoleRxDmaIrq() diff --git a/components/f4ll_cpp/crcscheduler.cpp b/components/f4ll_cpp/crcscheduler.cpp index 1f46a6c..0ec6bb3 100644 --- a/components/f4ll_cpp/crcscheduler.cpp +++ b/components/f4ll_cpp/crcscheduler.cpp @@ -27,9 +27,6 @@ # define DIAG_INTERRUPT_OUT() #endif -namespace f4ll_cpp -{ - void Crc_StartNextTask(struct crcstatus_t *status); @@ -191,4 +188,3 @@ void CrcScheduler::_HandleDmaIrq() DIAG_INTERRUPT_OUT(); } -} // f4ll_cpp diff --git a/components/f4ll_cpp/crcscheduler.h b/components/f4ll_cpp/crcscheduler.h index ffa27ae..91ba259 100644 --- a/components/f4ll_cpp/crcscheduler.h +++ b/components/f4ll_cpp/crcscheduler.h @@ -17,9 +17,6 @@ #include #include -namespace f4ll_cpp -{ - class CrcScheduler { public: struct ICrcCallback { @@ -67,6 +64,5 @@ 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 f4b080e..47d051a 100644 --- a/components/f4ll_cpp/dmahelper.cpp +++ b/components/f4ll_cpp/dmahelper.cpp @@ -9,9 +9,6 @@ #define MOCKABLE(x) x #endif -namespace f4ll_cpp -{ - DmaHelper::DmaHelper(DMA_TypeDef *dma, uint32_t stream) { m_dma = dma; @@ -83,4 +80,3 @@ 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 90b8f5e..be4cf60 100644 --- a/components/f4ll_cpp/dmahelper.h +++ b/components/f4ll_cpp/dmahelper.h @@ -14,9 +14,6 @@ #define DECLARE_MOCK(x) #endif -namespace f4ll_cpp -{ - class DmaHelper { public: DmaHelper(DMA_TypeDef *dma, uint32_t stream); @@ -52,6 +49,16 @@ private: uint32_t m_tcMask; }; -} // f4ll_cpp + +#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 #endif /* DMA_HELPER_H_ */ diff --git a/components/f4ll_cpp/ili9341.cpp b/components/f4ll_cpp/ili9341.cpp index a4bbba4..9b6b271 100644 --- a/components/f4ll_cpp/ili9341.cpp +++ b/components/f4ll_cpp/ili9341.cpp @@ -16,8 +16,6 @@ #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) @@ -397,5 +395,3 @@ 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 02ce413..a9e0763 100644 --- a/components/f4ll_cpp/ili9341.h +++ b/components/f4ll_cpp/ili9341.h @@ -5,8 +5,6 @@ #include #include -namespace f4ll_cpp { - class Ili9341Fsmc : public Singleton, private DmaHelper { public: @@ -188,6 +186,4 @@ public: }; }; -} // f4ll_cpp - #endif diff --git a/components/f4ll_cpp/memcpydma.cpp b/components/f4ll_cpp/memcpydma.cpp index c34c11e..aba8a4b 100644 --- a/components/f4ll_cpp/memcpydma.cpp +++ b/components/f4ll_cpp/memcpydma.cpp @@ -7,8 +7,6 @@ #include #include -namespace f4ll_cpp { - MemcpyDma::MemcpyDma(DMA_TypeDef *dma, uint32_t stream) : DmaHelper(dma, stream), m_busy(false) @@ -35,5 +33,3 @@ void MemcpyDma::HandleDmaIrq(void) m_busy = false; } } - -} // f4ll_cpp diff --git a/components/f4ll_cpp/memcpydma.h b/components/f4ll_cpp/memcpydma.h index aa93b8c..9f6e33c 100644 --- a/components/f4ll_cpp/memcpydma.h +++ b/components/f4ll_cpp/memcpydma.h @@ -14,8 +14,6 @@ #include -namespace f4ll_cpp { - class MemcpyDma : public DmaHelper, public Singleton { public: @@ -28,6 +26,5 @@ 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 5f68891..545e700 100644 --- a/components/f4ll_cpp/packetuart.cpp +++ b/components/f4ll_cpp/packetuart.cpp @@ -30,9 +30,6 @@ #define STARTMARKER 0x95 -namespace f4ll_cpp -{ - static inline uint32_t RoundUpTo4(uint32_t inp) { return (inp + 3) & 0xfffc; @@ -283,4 +280,3 @@ void PacketUart::HandleUsartIrq() DIAG_INTERRUPT_OUT(); } -} // f4ll_cpp diff --git a/components/f4ll_cpp/packetuart.h b/components/f4ll_cpp/packetuart.h index b694a88..cc6135b 100644 --- a/components/f4ll_cpp/packetuart.h +++ b/components/f4ll_cpp/packetuart.h @@ -13,8 +13,6 @@ #define USART_STATS_DISABLED -namespace f4ll_cpp { - class PacketUart : public UartBase, public CrcScheduler::ICrcCallback { public: @@ -102,6 +100,4 @@ 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 16e91a2..d6bf32d 100644 --- a/components/f4ll_cpp/serialconsole.h +++ b/components/f4ll_cpp/serialconsole.h @@ -14,8 +14,6 @@ #include -namespace f4ll_cpp { - template class SerialConsole : protected UartBase { public: @@ -168,6 +166,4 @@ 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 75a52f8..7ca6e5c 100644 --- a/components/f4ll_cpp/singleton.h +++ b/components/f4ll_cpp/singleton.h @@ -10,8 +10,6 @@ #include -namespace f4ll_cpp { - template class Singleton { public: static T &Instance() { return *m_instance; } @@ -34,6 +32,4 @@ protected: template T* Singleton::m_instance = nullptr; -} // f4ll_cpp - #endif /* SINGLETON_H_ */ diff --git a/App/strutil.c b/components/f4ll_cpp/strutil.c similarity index 98% rename from App/strutil.c rename to components/f4ll_cpp/strutil.c index 12c5812..8ac84d3 100644 --- a/App/strutil.c +++ b/components/f4ll_cpp/strutil.c @@ -1,5 +1,5 @@ #include -#include "strutil.h" +#include ////////////////////////////////////////////////////////////////////////////// size_t strcpy_ex(char *dst, char const *src) diff --git a/App/strutil.h b/components/f4ll_cpp/strutil.h similarity index 86% rename from App/strutil.h rename to components/f4ll_cpp/strutil.h index f3771a4..49ddc39 100644 --- a/App/strutil.h +++ b/components/f4ll_cpp/strutil.h @@ -4,8 +4,9 @@ * Created on: Feb 11, 2017 * Author: compi */ -#ifndef _STRUTIL_H_ -#define _STRUTIL_H_ + +#ifndef _STM32PLUS_STRUTIL_H_ +#define _STM32PLUS_STRUTIL_H_ #include #include @@ -27,5 +28,4 @@ char tochr(const uint8_t in, const uint8_t upper); } #endif - -#endif // _STRUTIL_H_ +#endif /* _STM32PLUS_STRUTIL_H_ */ diff --git a/components/f4ll_cpp/uartbase.cpp b/components/f4ll_cpp/uartbase.cpp index 1c48d18..5e4e791 100644 --- a/components/f4ll_cpp/uartbase.cpp +++ b/components/f4ll_cpp/uartbase.cpp @@ -7,8 +7,6 @@ #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) @@ -46,4 +44,3 @@ 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 557916a..fceefa6 100644 --- a/components/f4ll_cpp/uartbase.h +++ b/components/f4ll_cpp/uartbase.h @@ -10,8 +10,6 @@ #include #include -namespace f4ll_cpp { - class UartBase { public: @@ -26,6 +24,4 @@ protected: DmaHelper m_txDma; }; -} // f4ll_cpp - #endif /* F4LL_CPP_UARTBASE_H_ */