Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
SE05X: Use Arduino_DebugUtils for debugging
  • Loading branch information
pennam committed Jan 23, 2024
commit ee207b5ad839e0c06fc3b678ada5636201f1b398
1 change: 1 addition & 0 deletions libraries/SE05X/src/SE05X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "SE05X.h"
#include "lib/platform/arduino/sm_port.h"

/**
* 26 bytes see ecc_der_header_nist256
Expand Down
1 change: 0 additions & 1 deletion libraries/SE05X/src/SE05X.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extern "C" {
#endif

#include "lib/apdu/se05x_APDU_apis.h"
#include "lib/platform/arduino/sm_port.h"

#ifdef __cplusplus
}
Expand Down
32 changes: 22 additions & 10 deletions libraries/SE05X/src/lib/platform/arduino/sm_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@

#include "../../platform/arduino/sm_port.h"

void smlog_print(const char *format, ...) {
char debug_buf[1024];
va_list argptr;
va_start(argptr, format);
vsprintf(debug_buf, format, argptr);
va_end(argptr);
Serial.print(debug_buf);
}
#if defined __has_include
#if __has_include (<Arduino_DebugUtils.h>)
#include <Arduino_DebugUtils.h>
#define SE05X_DEBUG_ENABLE 1
#else
#define SE05X_DEBUG_ENABLE 0
#endif
#else
#define SE05X_DEBUG_ENABLE 0
#endif

void smlog_none(const char *format, ...) {
(void)format;
void smlog_print(int const lvl, const char *fmt, ...) {
#if SE05X_DEBUG_ENABLE
va_list args;
va_start(args, fmt);
Debug.newlineOff();
Debug.print(lvl, fmt, args);
Debug.newlineOn();
va_end(args);
#else
(void)lvl;
(void)fmt;
#endif
}
73 changes: 23 additions & 50 deletions libraries/SE05X/src/lib/platform/arduino/sm_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,33 @@
#include "Arduino.h"

/*
* 0: NONE
* 1: ERROR
* 2: WARNING
* 3: INFO
* 4: DEBUG
* 5: APDU
* -1: NONE
* 0: ERROR
* 1: WARNING
* 2: INFO
* 3: DEBUG
* 4: VERBOSE/APDU
*/
#define DEBUG_LEVEL 0

#if DEBUG_LEVEL > 0
#define SMLOG_E smlog_print
#else
#define SMLOG_E smlog_none
#endif
#define SMLOG_E(fmt, ...) smlog_print(0, fmt, ## __VA_ARGS__)
#define SMLOG_W(fmt, ...) smlog_print(1, fmt, ## __VA_ARGS__)
#define SMLOG_I(fmt, ...) smlog_print(2, fmt, ## __VA_ARGS__)
#define SMLOG_D(fmt, ...) smlog_print(3, fmt, ## __VA_ARGS__)

#if DEBUG_LEVEL > 1
#define SMLOG_W smlog_print
#else
#define SMLOG_W smlog_none
#endif
#define SMLOG_AU8_D(BUF, LEN) \
smlog_print(4, ":"); \
for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \
smlog_print(4, "%02x ", BUF[bufIndex]); \
} \
smlog_print(4, "\n")

#if DEBUG_LEVEL > 2
#define SMLOG_I smlog_print
#else
#define SMLOG_I smlog_none
#endif
#define SMLOG_MAU8_D(MSG, BUF, LEN) \
smlog_print(4, "%s:", MSG); \
for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \
smlog_print(4, "%02x ", BUF[bufIndex]); \
} \
smlog_print(4, "\n")

#if DEBUG_LEVEL > 3
#define SMLOG_D smlog_print
#else
#define SMLOG_D smlog_none
#endif

#if DEBUG_LEVEL > 4
#define SMLOG_AU8_D(BUF, LEN) \
smlog_print("%s", ":"); \
for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \
smlog_print("%02x ", BUF[bufIndex]); \
} \
smlog_print("%s","\n")

#define SMLOG_MAU8_D(MSG, BUF, LEN) \
smlog_print("%s", MSG); \
smlog_print("%s", ":"); \
for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \
smlog_print("%02x ", BUF[bufIndex]); \
} \
smlog_print("%s","\n")

#else
#define SMLOG_AU8_D(BUF, LEN)
#define SMLOG_MAU8_D(MSG, BUF, LEN)
#endif

#define SM_MUTEX_DEFINE(x)
#define SM_MUTEX_INIT(x)
Expand All @@ -98,8 +72,7 @@
#ifdef __cplusplus
extern "C" {
#endif
void smlog_print(const char *format, ...);
void smlog_none(const char *format, ...);
void smlog_print(int const lvl, const char *fmt, ...);
#ifdef __cplusplus
}
#endif
Expand Down