Skip to content

Commit

Permalink
Add debug messages over serial
Browse files Browse the repository at this point in the history
  • Loading branch information
bessman committed Nov 12, 2023
1 parent 8923454 commit 161d533
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ else()
message("Building for PSLab v6")
endif(LEGACY_HARDWARE)

if (ENABLE_DEBUG)
message("Debug messages enabled")
add_compile_definitions(PSLAB_DEBUG)
endif(ENABLE_DEBUG)

bin2hex(pslab-firmware.elf)
5 changes: 3 additions & 2 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "bus/uart/uart.h"
#include "bus/spi/spi.h"
#include "helpers/buffer.h"
#include "helpers/debug.h"
#include "helpers/device.h"
#include "helpers/interval.h"
#include "helpers/light.h"
Expand Down Expand Up @@ -247,8 +248,8 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1
{ // 11 COMMON
// 0 1 GET_CTMU_VOLTAGE 2 GET_CAPACITANCE 3 GET_FREQUENCY
Undefined, MULTIMETER_GetCTMUVolts, MULTIMETER_GetCapacitance, Unimplemented,
// 4 GET_INDUCTANCE 5 GET_VERSION 6 GET_FW_VERSION 7
Unimplemented, DEVICE_GetVersion, DEVICE_get_fw_version, Undefined,
// 4 GET_INDUCTANCE 5 GET_VERSION 6 GET_FW_VERSION 7 DEBUG_IS_ENABLED
Unimplemented, DEVICE_GetVersion, DEVICE_get_fw_version, DEBUG_is_enabled,
// 8 RETRIEVE_BUFFER 9 GET_HIGH_FREQUENCY 10 CLEAR_BUFFER 11 SET_RGB1
BUFFER_Retrieve, Unimplemented, BUFFER_Clear, Removed,
// 12 READ_PROGRAM_ADDRESS 13 WRITE_PROGRAM_ADDRESS 14 READ_DATA_ADDRESS 15 WRITE_DATA_ADDRESS
Expand Down
1 change: 1 addition & 0 deletions src/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target_sources(pslab-firmware.elf PRIVATE
buffer.c
debug.c
delay.c
device.c
interval.c
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdbool.h>

#include "../bus/uart/uart.h"
#include "../commands.h"
#include "debug.h"

response_t DEBUG_is_enabled(void) {
#ifdef PSLAB_DEBUG
bool const IS_DEBUG_ENABLED = true;
#else
bool const IS_DEBUG_ENABLED = false;
#endif // PSLAB_DEBUG

UART1_Write(IS_DEBUG_ENABLED);
return DO_NOT_BOTHER;
}
18 changes: 18 additions & 0 deletions src/helpers/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _DEBUG_H
#define _DEBUG_H

#include "../commands.h"

#ifdef PSLAB_DEBUG
#define DEBUG_write_u8(byte) UART1_Write(byte)
#define DEBUG_write_u16(word) UART1_WriteInt(word)
#define DEBUG_write_u32(dword) UART1_write_u32(dword)
#else
#define DEBUG_write_u8(byte) ((void)byte)
#define DEBUG_write_u16(word) ((void)word)
#define DEBUG_write_u32(dword) ((void)dword)
#endif // PSLAB_DEBUG

response_t DEBUG_is_enabled(void);

#endif // _DEBUG_H

0 comments on commit 161d533

Please sign in to comment.