Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ee207b5

Browse files
committedJan 23, 2024
SE05X: Use Arduino_DebugUtils for debugging
1 parent 5020fd4 commit ee207b5

File tree

4 files changed

+46
-61
lines changed

4 files changed

+46
-61
lines changed
 

‎libraries/SE05X/src/SE05X.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "SE05X.h"
21+
#include "lib/platform/arduino/sm_port.h"
2122

2223
/**
2324
* 26 bytes see ecc_der_header_nist256

‎libraries/SE05X/src/SE05X.h

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ extern "C" {
2727
#endif
2828

2929
#include "lib/apdu/se05x_APDU_apis.h"
30-
#include "lib/platform/arduino/sm_port.h"
3130

3231
#ifdef __cplusplus
3332
}

‎libraries/SE05X/src/lib/platform/arduino/sm_port.cpp

+22-10
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,27 @@
1919

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

22-
void smlog_print(const char *format, ...) {
23-
char debug_buf[1024];
24-
va_list argptr;
25-
va_start(argptr, format);
26-
vsprintf(debug_buf, format, argptr);
27-
va_end(argptr);
28-
Serial.print(debug_buf);
29-
}
22+
#if defined __has_include
23+
#if __has_include (<Arduino_DebugUtils.h>)
24+
#include <Arduino_DebugUtils.h>
25+
#define SE05X_DEBUG_ENABLE 1
26+
#else
27+
#define SE05X_DEBUG_ENABLE 0
28+
#endif
29+
#else
30+
#define SE05X_DEBUG_ENABLE 0
31+
#endif
3032

31-
void smlog_none(const char *format, ...) {
32-
(void)format;
33+
void smlog_print(int const lvl, const char *fmt, ...) {
34+
#if SE05X_DEBUG_ENABLE
35+
va_list args;
36+
va_start(args, fmt);
37+
Debug.newlineOff();
38+
Debug.print(lvl, fmt, args);
39+
Debug.newlineOn();
40+
va_end(args);
41+
#else
42+
(void)lvl;
43+
(void)fmt;
44+
#endif
3345
}

‎libraries/SE05X/src/lib/platform/arduino/sm_port.h

+23-50
Original file line numberDiff line numberDiff line change
@@ -22,59 +22,33 @@
2222
#include "Arduino.h"
2323

2424
/*
25-
* 0: NONE
26-
* 1: ERROR
27-
* 2: WARNING
28-
* 3: INFO
29-
* 4: DEBUG
30-
* 5: APDU
25+
* -1: NONE
26+
* 0: ERROR
27+
* 1: WARNING
28+
* 2: INFO
29+
* 3: DEBUG
30+
* 4: VERBOSE/APDU
3131
*/
32-
#define DEBUG_LEVEL 0
3332

34-
#if DEBUG_LEVEL > 0
35-
#define SMLOG_E smlog_print
36-
#else
37-
#define SMLOG_E smlog_none
38-
#endif
33+
#define SMLOG_E(fmt, ...) smlog_print(0, fmt, ## __VA_ARGS__)
34+
#define SMLOG_W(fmt, ...) smlog_print(1, fmt, ## __VA_ARGS__)
35+
#define SMLOG_I(fmt, ...) smlog_print(2, fmt, ## __VA_ARGS__)
36+
#define SMLOG_D(fmt, ...) smlog_print(3, fmt, ## __VA_ARGS__)
3937

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

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

52-
#if DEBUG_LEVEL > 3
53-
#define SMLOG_D smlog_print
54-
#else
55-
#define SMLOG_D smlog_none
56-
#endif
57-
58-
#if DEBUG_LEVEL > 4
59-
#define SMLOG_AU8_D(BUF, LEN) \
60-
smlog_print("%s", ":"); \
61-
for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \
62-
smlog_print("%02x ", BUF[bufIndex]); \
63-
} \
64-
smlog_print("%s","\n")
65-
66-
#define SMLOG_MAU8_D(MSG, BUF, LEN) \
67-
smlog_print("%s", MSG); \
68-
smlog_print("%s", ":"); \
69-
for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \
70-
smlog_print("%02x ", BUF[bufIndex]); \
71-
} \
72-
smlog_print("%s","\n")
73-
74-
#else
75-
#define SMLOG_AU8_D(BUF, LEN)
76-
#define SMLOG_MAU8_D(MSG, BUF, LEN)
77-
#endif
7852

7953
#define SM_MUTEX_DEFINE(x)
8054
#define SM_MUTEX_INIT(x)
@@ -98,8 +72,7 @@
9872
#ifdef __cplusplus
9973
extern "C" {
10074
#endif
101-
void smlog_print(const char *format, ...);
102-
void smlog_none(const char *format, ...);
75+
void smlog_print(int const lvl, const char *fmt, ...);
10376
#ifdef __cplusplus
10477
}
10578
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.