diff --git a/Firmware/Chameleon-Mini/Codec/Codec.c b/Firmware/Chameleon-Mini/Codec/Codec.c index bb845e8..2a23415 100644 --- a/Firmware/Chameleon-Mini/Codec/Codec.c +++ b/Firmware/Chameleon-Mini/Codec/Codec.c @@ -23,7 +23,6 @@ static volatile struct { } ReaderFieldFlags = { false }; uint8_t CodecBuffer[CODEC_BUFFER_SIZE]; -uint16_t ReaderThreshold = 400; // standard value // the following three functions prevent sending data directly after turning on the reader field void CodecReaderFieldStart(void) // DO NOT CALL THIS FUNCTION INSIDE APPLICATION! diff --git a/Firmware/Chameleon-Mini/Codec/Codec.h b/Firmware/Chameleon-Mini/Codec/Codec.h index 4ac44c6..9ee49b0 100644 --- a/Firmware/Chameleon-Mini/Codec/Codec.h +++ b/Firmware/Chameleon-Mini/Codec/Codec.h @@ -13,6 +13,7 @@ #include #include "../Common.h" #include "../Configuration.h" +#include "../Settings.h" #include "ISO14443-2A.h" #include "Reader14443-2A.h" @@ -89,7 +90,6 @@ #define CodecPtrRegister1 (*((volatile uint8_t**) &GPIOR8)) #define CodecPtrRegister2 (*((volatile uint8_t**) &GPIORA)) -extern uint16_t ReaderThreshold; extern uint16_t Reader_FWT; #define FWI2FWT(x) ((uint32_t)(256 * 16 * ((uint32_t)1 << (x))) / (CODEC_CARRIER_FREQ / 1000) + 1) @@ -172,7 +172,7 @@ INLINE void CodecInitCommon(void) DACB.CTRLB = DAC_CHSEL_SINGLE_gc; DACB.CTRLC = DAC_REFSEL_AVCC_gc; DACB.CTRLA = DAC_IDOEN_bm | DAC_ENABLE_bm; - DACB.CH0DATA = ReaderThreshold; // real threshold voltage can be calculated with ch0data * Vref / 0xFFF + DACB.CH0DATA = GlobalSettings.ActiveSettingPtr->ReaderThreshold; // real threshold voltage can be calculated with ch0data * Vref / 0xFFF /* Configure Analog Comparator 0 to detect changes in demodulated reader field */ ACA.AC0MUXCTRL = AC_MUXPOS_DAC_gc | AC_MUXNEG_PIN7_gc; diff --git a/Firmware/Chameleon-Mini/Settings.c b/Firmware/Chameleon-Mini/Settings.c index 90cbaf6..1505cc7 100644 --- a/Firmware/Chameleon-Mini/Settings.c +++ b/Firmware/Chameleon-Mini/Settings.c @@ -25,7 +25,8 @@ SettingsType EEMEM StoredSettings = { .LogMode = DEFAULT_LOG_MODE, .LEDRedFunction = DEFAULT_RED_LED_ACTION, .LEDGreenFunction = DEFAULT_GREEN_LED_ACTION, - .PendingTaskTimeout = DEFAULT_PENDING_TASK_TIMEOUT + .PendingTaskTimeout = DEFAULT_PENDING_TASK_TIMEOUT, + .ReaderThreshold = 400 }} }; diff --git a/Firmware/Chameleon-Mini/Settings.h b/Firmware/Chameleon-Mini/Settings.h index 29e4b9e..507d900 100644 --- a/Firmware/Chameleon-Mini/Settings.h +++ b/Firmware/Chameleon-Mini/Settings.h @@ -29,6 +29,7 @@ typedef struct { LEDHookEnum LEDRedFunction; /// Red LED function for this setting. LEDHookEnum LEDGreenFunction; /// Green LED function for this setting. uint16_t PendingTaskTimeout; /// Timeout for timeout commands for this setting, in multiples of 100 ms. + uint16_t ReaderThreshold; } SettingsEntryType; typedef struct { diff --git a/Firmware/Chameleon-Mini/Terminal/Commands.c b/Firmware/Chameleon-Mini/Terminal/Commands.c index 84057c6..4033146 100644 --- a/Firmware/Chameleon-Mini/Terminal/Commands.c +++ b/Firmware/Chameleon-Mini/Terminal/Commands.c @@ -578,7 +578,7 @@ CommandStatusIdType CommandSetTimeout(char* OutMessage, const char* InParam) CommandStatusIdType CommandGetThreshold(char* OutParam) { - snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("%u"), ReaderThreshold); + snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("%u"), GlobalSettings.ActiveSettingPtr->ReaderThreshold); return COMMAND_INFO_OK_WITH_TEXT_ID; } @@ -593,7 +593,7 @@ CommandStatusIdType CommandSetThreshold(char* OutMessage, const char* InParam) if (!sscanf_P(InParam, PSTR("%5d"), &tmp) || tmp > CODEC_MAXIMUM_THRESHOLD) return COMMAND_ERR_INVALID_PARAM_ID; DACB.CH0DATA = tmp; - ReaderThreshold = tmp; + GlobalSettings.ActiveSettingPtr->ReaderThreshold = tmp; return COMMAND_INFO_OK_ID; }