Skip to content

Commit

Permalink
#3 fix mbed and cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
davetcc committed Sep 14, 2024
1 parent 7d6ae09 commit 47aa89e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 19 deletions.
14 changes: 14 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_library(TcMenuLog
../src/IoLogging.cpp
../src/TextUtilities.cpp
)

target_compile_definitions(TcMenuLog
PUBLIC BUILD_FOR_PICO_CMAKE=1 BUILD_PICO_FORCE_UART=1 IO_LOGGING_DEBUG=1
)

target_include_directories(TcMenuLog PUBLIC
${PROJECT_SOURCE_DIR}/lib/TcMenuLog/src
)

target_link_libraries(TcMenuLog PUBLIC pico_stdlib pico_sync)
27 changes: 27 additions & 0 deletions src/IoLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ const char* prettyLevel(SerLoggingLevel level) {

#ifdef BUILD_FOR_PICO_CMAKE
PrintfLogger LoggingPort;
unsigned long millis() {
return to_ms_since_boot(get_absolute_time());
}

unsigned long micros() {
return to_us_since_boot(get_absolute_time());
}
#endif

#ifdef LOGGING_USES_MBED
volatile bool timingStarted = false;
Timer ioaTimer;
unsigned long millis() {
if(!timingStarted) {
timingStarted = true;
ioaTimer.start();
}
return ioaTimer.read_ms();
}

unsigned long micros() {
if(!timingStarted) {
timingStarted = true;
ioaTimer.start();
}
return (unsigned long) ioaTimer.read_high_resolution_us();
}
#endif

#endif
30 changes: 14 additions & 16 deletions src/IoLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,7 @@ enum SerLoggingLevel {

#if defined(__MBED__) && !defined(BUILD_FOR_PICO_CMAKE) && !defined(ARDUINO_ARCH_MBED)
#define LOGGING_USES_MBED
#elif !defined(BUILD_FOR_PICO_CMAKE)
#include <Arduino.h>
#endif

#ifdef IO_LOGGING_DEBUG


/** This uint16_t stores the enabled logging levels, don't use directly */
extern unsigned int enabledLevels;

#ifdef LOGGING_USES_MBED
#include <mbed.h>

#include "PrintCompat.h"
#include <FileHandle.h>
Expand Down Expand Up @@ -87,10 +77,14 @@ unsigned long millis();
#define F(x) x
#define IOLOG_MBED_PORT_IF_NEEDED(tx, rx) BufferedSerial serPort(tx, rx);MBedLogger LoggingPort(serPort);
#define IOLOG_START_SERIAL serPort.set_baud(115200);
unsigned long millis();
unsigned long micros();
#elif defined(BUILD_FOR_PICO_CMAKE)
#include "PrintCompat.h"
#include <cstring>
#include <string.h>
#include <ctype.h>
#include <pico/time.h>
#include <hardware/uart.h>
#ifdef BUILD_PICO_FORCE_UART
class PrintfLogger : public Print {
private:
Expand Down Expand Up @@ -123,8 +117,9 @@ class PrintfLogger : public Print {
};
#define IOLOG_START_SERIAL stdio_init_all();
#endif
unsigned long millis();
unsigned long micros();
extern PrintfLogger LoggingPort;
unsigned long millis(); // available from task manager
#define F(x) x
#define IOLOG_MBED_PORT_IF_NEEDED(tx, rx)
#else
Expand All @@ -138,6 +133,12 @@ unsigned long millis(); // available from task manager
#define IOLOG_MBED_PORT_IF_NEEDED(tx, rx)
#endif

#ifdef IO_LOGGING_DEBUG


/** This uint16_t stores the enabled logging levels, don't use directly */
extern unsigned int enabledLevels;

const char* prettyLevel(SerLoggingLevel level);
#define logTimeAndLevel(title, lvl) LoggingPort.print(millis());LoggingPort.print('-');LoggingPort.print(prettyLevel(lvl));LoggingPort.print(':');LoggingPort.print(title)

Expand Down Expand Up @@ -216,9 +217,6 @@ inline void serdebugHexDump(const char *title, const void* data, size_t len) { s

#define startTaskManagerLogDelegate()

#define IOLOG_START_SERIAL
#define IOLOG_MBED_PORT_IF_NEEDED(tx, rx)

#define serEnableLevel(l, a)
#define serLevelEnabled(l) false
#endif // IO_LOGGING_DEBUG
Expand Down
7 changes: 7 additions & 0 deletions src/TextUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
* This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
*/

#ifdef __AVR__
#include <Arduino.h>
#else
#include <cstdint>
#include <cctype>
#include <valarray>
#endif
#include "TextUtilities.h"

void appendChar(char* str, char val, int len) {
Expand Down
6 changes: 3 additions & 3 deletions src/TextUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef IOABSTRACTION_TEXTUTILITIES_H
#define IOABSTRACTION_TEXTUTILITIES_H

#include <IoLogging.h>
#include <stdint.h>

/**
* @file TextUtilities.h
Expand Down Expand Up @@ -135,8 +135,8 @@ inline float tcFltAbs(float f1) {
#define lowByte(x) ((x) & 0xff)
#define ltoa(a,b,c) itoa(a,b,c)
# ifndef min
# define min(x, y) (((x) < (y))?(x):(y))
# define max(x, y) (((x) > (y))?(x):(y))
template<class T> void min(T x, T y) { return (((x) < (y))?(x):(y)); }
template<class T> void max(T x, T y) { return (((x) > (y))?(x):(y)); }
# endif //TCMENU_MBED_NO_MINMAX
#endif // IOA_USE_MBED

Expand Down

0 comments on commit 47aa89e

Please sign in to comment.