From 8dbb88397103add72166a73501ad307dc75de553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 11 May 2022 20:53:29 +0000 Subject: [PATCH] Add helper macros to parse nibbles Also made the button operations and nibbles constant since they should not be modified. --- Firmware/mmu2/errors_list.h | 6 ++++-- Firmware/mmu2_reporting.cpp | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Firmware/mmu2/errors_list.h b/Firmware/mmu2/errors_list.h index 244597ef8..682037b1b 100644 --- a/Firmware/mmu2/errors_list.h +++ b/Firmware/mmu2/errors_list.h @@ -243,8 +243,6 @@ static const char * const errorDescs[] PROGMEM = { descRUNTIME_ERROR, }; -#define BUTTON_OP_HIGH_NIBBLE_MSK 0xF0 -#define BUTTON_OP_LOW_NIBBLE_MSK 0x0F /// Will be mapped onto dialog button responses in the FW /// Those responses have their unique+translated texts as well @@ -285,6 +283,10 @@ static const char * const btnOperation[] PROGMEM = { btnDisableMMU }; +// Helper macros to parse the operations from Btns() +#define BUTTON_OP_HI_NIBBLE(X) ( ( X & 0xF0 ) >> 4 ) +#define BUTTON_OP_LO_NIBBLE(X) ( X & 0x0F ) + // We have 8 different operations/buttons at this time, so we need at least 4 bits to encode each. // Since one of the buttons is always "More", we can skip that one. // Therefore we need just 1 byte to describe the necessary buttons for each screen. diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index 6d87ba8a5..fb2ee7b01 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -32,9 +32,9 @@ void ReportErrorHook(CommandInProgress cip, uint16_t ec) { // Read and determine what operations should be shown on the menu // Note: uint16_t is used here to avoid compiler warning. uint8_t is only half the size of void* - uint8_t button_operation = reinterpret_cast(const_cast(pgm_read_ptr(&errorButtons[ei]))); - uint8_t button_high_nibble = (button_operation & BUTTON_OP_HIGH_NIBBLE_MSK) >> 4; - uint8_t button_low_nibble = button_operation & BUTTON_OP_LOW_NIBBLE_MSK; + const uint8_t button_operation = reinterpret_cast(const_cast(pgm_read_ptr(&errorButtons[ei]))); + const uint8_t button_high_nibble = BUTTON_OP_HI_NIBBLE(button_operation); + const uint8_t button_low_nibble = BUTTON_OP_LO_NIBBLE(button_operation); // Check if the menu should have three or two choices if (button_low_nibble == (uint8_t)ButtonOperations::NoOperation)