1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2024-11-28 07:20:49 +01:00

Better debug handling

This commit is contained in:
whowechina 2024-04-29 17:44:18 +08:00
parent dee5521ce8
commit 8a7751de84
8 changed files with 87 additions and 100 deletions

View File

@ -13,7 +13,6 @@
typedef void (*aime_putc_func)(uint8_t byte); typedef void (*aime_putc_func)(uint8_t byte);
void aime_init(aime_putc_func putc_func); void aime_init(aime_putc_func putc_func);
void aime_debug(bool enable);
void aime_virtual_aic(bool enable); void aime_virtual_aic(bool enable);
void aime_set_mode(int mode); void aime_set_mode(int mode);

View File

@ -13,7 +13,6 @@
typedef void (*bana_putc_func)(uint8_t byte); typedef void (*bana_putc_func)(uint8_t byte);
void bana_init(bana_putc_func putc_func); void bana_init(bana_putc_func putc_func);
void bana_debug(bool enable);
bool bana_feed(int c); bool bana_feed(int c);

View File

@ -200,11 +200,8 @@ static void handle_level(int argc, char *argv[])
static void handle_debug() static void handle_debug()
{ {
static bool debug = true; aic_runtime.debug = !aic_runtime.debug;
printf("Debug: %s\n", debug ? "ON" : "OFF"); printf("Debug: %s\n", aic_runtime.debug ? "ON" : "OFF");
aime_debug(debug);
bana_debug(debug);
debug = !debug;
} }
void commands_init() void commands_init()

View File

@ -17,7 +17,7 @@ static aic_cfg_t default_cfg = {
.mode = 0, .mode = 0,
}; };
aic_runtime_t *aic_runtime; aic_runtime_t aic_runtime;
static void config_loaded() static void config_loaded()
{ {

View File

@ -21,12 +21,12 @@ typedef struct __attribute__((packed)) {
uint32_t reserved; uint32_t reserved;
} aic_cfg_t; } aic_cfg_t;
typedef struct { typedef volatile struct {
uint16_t fps[2]; bool debug;
} aic_runtime_t; } aic_runtime_t;
extern aic_cfg_t *aic_cfg; extern aic_cfg_t *aic_cfg;
extern aic_runtime_t *aic_runtime; extern aic_runtime_t aic_runtime;
void config_init(); void config_init();
void config_changed(); // Notify the config has changed void config_changed(); // Notify the config has changed

View File

@ -14,11 +14,12 @@
#include "hardware/gpio.h" #include "hardware/gpio.h"
#include "hardware/i2c.h" #include "hardware/i2c.h"
#include "config.h"
#include "nfc.h" #include "nfc.h"
#include "aime.h" #include "aime.h"
static bool debug = false; static bool debug = false;
#define DEBUG(...) if (debug) printf(__VA_ARGS__) #define DEBUG(...) if (aic_runtime.debug) printf(__VA_ARGS__)
#define AIME_EXPIRE_TIME 10000000ULL #define AIME_EXPIRE_TIME 10000000ULL
@ -98,11 +99,6 @@ void aime_init(aime_putc_func putc_func)
aime_putc = putc_func; aime_putc = putc_func;
} }
void aime_debug(bool enable)
{
debug = enable;
}
void aime_virtual_aic(bool enable) void aime_virtual_aic(bool enable)
{ {
virtual_aic.enabled = enable; virtual_aic.enabled = enable;
@ -184,7 +180,7 @@ static void send_response()
aime_putc(checksum); aime_putc(checksum);
DEBUG("\n\033[33mResp %2d:%02x >>", response.payload_len, response.cmd); DEBUG("\n\033[33m%6ld<< %02x:", time_us_32() / 1000, response.cmd);
for (int i = 0; i < response.payload_len; i++) { for (int i = 0; i < response.payload_len; i++) {
DEBUG(" %02x", response.payload[i]); DEBUG(" %02x", response.payload[i]);
} }

View File

@ -14,11 +14,12 @@
#include "hardware/gpio.h" #include "hardware/gpio.h"
#include "hardware/i2c.h" #include "hardware/i2c.h"
#include "config.h"
#include "nfc.h" #include "nfc.h"
#include "bana.h" #include "bana.h"
static bool debug = false; static bool debug = false;
#define DEBUG(...) if (debug) printf(__VA_ARGS__) #define DEBUG(...) if (aic_runtime.debug) printf(__VA_ARGS__)
#define BANA_EXPIRE_TIME 10000000ULL #define BANA_EXPIRE_TIME 10000000ULL
@ -40,11 +41,6 @@ void bana_init(bana_putc_func putc_func)
bana_putc = putc_func; bana_putc = putc_func;
} }
void bana_debug(bool enable)
{
debug = enable;
}
typedef union __attribute__((packed)) { typedef union __attribute__((packed)) {
struct { struct {
struct { struct {

View File

@ -35,7 +35,7 @@
#include "aime.h" #include "aime.h"
#include "bana.h" #include "bana.h"
#define DEBUG(...) { if (0) printf(__VA_ARGS__); } #define DEBUG(...) if (aic_runtime.debug) printf(__VA_ARGS__)
static struct { static struct {
uint8_t current[9]; uint8_t current[9];