diff --git a/src/commands.c b/src/commands.c index 99e5e37..344edf9 100644 --- a/src/commands.c +++ b/src/commands.c @@ -248,7 +248,7 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1 // 0 1 GET_CTMU_VOLTAGE 2 GET_CAPACITANCE 3 GET_FREQUENCY Undefined, MULTIMETER_GetCTMUVolts, MULTIMETER_GetCapacitance, Unimplemented, // 4 GET_INDUCTANCE 5 GET_VERSION 6 7 - Unimplemented, DEVICE_GetVersion, Undefined, Undefined, + Unimplemented, DEVICE_GetVersion, DEVICE_get_fw_version, Undefined, // 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 diff --git a/src/helpers/device.c b/src/helpers/device.c index 9089c78..8fa9ef9 100644 --- a/src/helpers/device.c +++ b/src/helpers/device.c @@ -1,11 +1,26 @@ #include +#include #include "../bus/uart/uart.h" #include "../commands.h" #include "../registers/system/pin_manager.h" #include "../registers/system/watchdog.h" +#define SEMVERS 3 + const uint8_t VERSION_HW[] = "PSLab V6"; /** Hardware version. **/ +union { + struct { + uint8_t const major; + uint8_t const minor; + uint8_t const patch; + }; + uint8_t const version[SEMVERS]; +} VERSION_FW = {{ + .major = 3, + .minor = 0, + .patch = 0 +}}; response_t DEVICE_GetVersion(void) { uint8_t i; @@ -14,6 +29,13 @@ response_t DEVICE_GetVersion(void) { return DO_NOT_BOTHER; } +response_t DEVICE_get_fw_version(void) { + for (size_t i = 0; i < SEMVERS; ++i) { + UART1_Write(VERSION_FW.version[i]); + } + return DO_NOT_BOTHER; +} + response_t DEVICE_Reset(void) { __asm__ volatile ("reset"); return DO_NOT_BOTHER; diff --git a/src/helpers/device.h b/src/helpers/device.h index 82001c5..5144700 100644 --- a/src/helpers/device.h +++ b/src/helpers/device.h @@ -11,6 +11,12 @@ extern "C" { */ response_t DEVICE_GetVersion(void); + /** + * @brief Get firmware version. + * @return MAJOR (uint8_t), MINOR (uint8_t), PATCH (uint8_t) + */ + response_t DEVICE_get_fw_version(void); + /** * @brief Reset the device by moving program counter to 0x0000 * @return DO_NOT_BOTHER