From b1caa0cf0408aa40df2c40e4662bff772d753cd0 Mon Sep 17 00:00:00 2001 From: amatilda Date: Thu, 5 Sep 2024 16:13:57 +0300 Subject: [PATCH 1/4] fix NULL pointer --- .../arduino/zunoG2/libraries/ZMEButtons/ZMEButtons.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/zunoG2/libraries/ZMEButtons/ZMEButtons.cpp b/hardware/arduino/zunoG2/libraries/ZMEButtons/ZMEButtons.cpp index 72e62b3b..88f68732 100644 --- a/hardware/arduino/zunoG2/libraries/ZMEButtons/ZMEButtons.cpp +++ b/hardware/arduino/zunoG2/libraries/ZMEButtons/ZMEButtons.cpp @@ -36,9 +36,15 @@ bool ZMEVirtButtons::isReleased(uint8_t channel) { return !isChannelPressed(channel, d); } bool ZMEVirtButtons::isIdled(uint8_t channel) { + ZMEButtonState_t *s; + uint8_t st; + zunoEnterCritical(); - ZMEButtonState_t * s = _extractChannelState(channel); - uint8_t st = s->state; + s = _extractChannelState(channel); + if (s != NULL) + st = s->state; + else + st = ZMEBUTTON_STATE_IDLE; zunoExitCritical(); return st == ZMEBUTTON_STATE_IDLE; } From 2ea5130ee18133964eda29b614205872e5cbcd2a Mon Sep 17 00:00:00 2001 From: amatilda Date: Tue, 10 Sep 2024 21:00:41 +0300 Subject: [PATCH 2/4] restore --- .../cores/ZWSupport/ZWCCUserCredential.cpp | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCUserCredential.cpp b/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCUserCredential.cpp index 65f25b6e..b770e2ce 100644 --- a/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCUserCredential.cpp +++ b/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCUserCredential.cpp @@ -29,7 +29,7 @@ static_assert(USER_CREDENTIAL_NUMBER <= 0xFFFF && USER_CREDENTIAL_NUMBER >= 0x1, static_assert(USER_CREDENTIAL_NUMBER_PIN_CODE <= 0xFFFF && USER_CREDENTIAL_NUMBER_PIN_CODE >= 0x1, "USER_CREDENTIAL_NUMBER_PIN_CODE - max 0xFFFF and min 0x1!!!"); static_assert(USER_CREDENTIAL_NUMBER_PIN_CODE_MIN_LENGHT >= 0x1, "USER_CREDENTIAL_NUMBER_PIN_CODE_MIN_LENGHT - min 0x1!!!"); static_assert(USER_CREDENTIAL_NUMBER_PIN_CODE_MAX_LENGHT <= 0xFFFF, "USER_CREDENTIAL_NUMBER_PIN_CODE_MAX_LENGHT - max 0xFFFF!!!"); -static_assert(USER_CREDENTIAL_NUMBER_PIN_CODE_MIN_LENGHT < USER_CREDENTIAL_NUMBER_PIN_CODE_MAX_LENGHT, "Must USER_CREDENTIAL_NUMBER_PIN_CODE_MAX_LENGHT < USER_CREDENTIAL_NUMBER_PIN_CODE_MIN_LENGHT!!!"); +static_assert(USER_CREDENTIAL_NUMBER_PIN_CODE_MIN_LENGHT <= USER_CREDENTIAL_NUMBER_PIN_CODE_MAX_LENGHT, "Must USER_CREDENTIAL_NUMBER_PIN_CODE_MAX_LENGHT < USER_CREDENTIAL_NUMBER_PIN_CODE_MIN_LENGHT!!!"); #endif #if defined(USER_CREDENTIAL_NUMBER_PASSWORD) static_assert(USER_CREDENTIAL_NUMBER_PASSWORD <= 0xFFFF && USER_CREDENTIAL_NUMBER_PASSWORD >= 0x1, "USER_CREDENTIAL_NUMBER_PASSWORD - max 0xFFFF and min 0x1!!!"); @@ -1133,4 +1133,50 @@ int zuno_CCUserCredentialHandler(ZUNOCommandPacket_t *cmd, ZUNOCommandPacketRepo (void)frame_report; } + +static bool _user_credential_find_key(const uint8_t *CredentialData, uint8_t CredentialLength, UserCredentialSaveCredential_t *credential, const UserCredentialSaveArg_t *arg) { + uint16_t crc16; + + crc16 = CrcClass::crc16_ccitt_aug(credential, sizeof(credential[0x0]) + arg->CredentialLengthMax); + credential->CredentialLength = CredentialLength; + memcpy(&credential->CredentialData[0x0], CredentialData, CredentialLength); + memset(&credential->CredentialData[CredentialLength], 0x0, arg->CredentialLengthMax - CredentialLength); + crc16 = CrcClass::crc16_ccitt_aug(&credential->CredentialData[0x0], arg->CredentialLengthMax); + if (_credential_test_uniq(crc16) == true) + return (true); + return (false); +} + + +bool user_credential_find_key(const uint8_t *CredentialData, uint8_t CredentialLength) { + uint8_t UserUniqueIdentifier; + uint8_t CredentialType; + uint32_t addr; + #if defined(USER_CREDENTIAL_NUMBER_PIN_CODE) + uint8_t PIN_CODE[(sizeof(UserCredentialSaveCredential_t) + USER_CREDENTIAL_NUMBER_PIN_CODE_MAX_LENGHT)]; + #endif + UserCredentialSaveCredential_t *credential; + const UserCredentialSaveArg_t *arg; + + UserUniqueIdentifier = 0x1; + CredentialType = USER_CREDENTIAL_TYPE_PIN_CODE; + switch (CredentialType) { + #if defined(USER_CREDENTIAL_NUMBER_PIN_CODE) + USER_CREDENTIAL_SWTCH_SET_ARG(PIN_CODE) + #endif + #if defined(USER_CREDENTIAL_NUMBER_PASSWORD) + USER_CREDENTIAL_SWTCH_SET_ARG(PASSWORD) + #endif + #if defined(USER_CREDENTIAL_NUMBER_RFID_CODE) + USER_CREDENTIAL_SWTCH_SET_ARG(RFID_CODE) + #endif + default: + return (false); + break ; + } + return (_user_credential_find_key(CredentialData, CredentialLength, credential, arg)); + (void)addr; +} + + #endif//WITH_CC_USER_CREDENTIAL \ No newline at end of file From d4d022615472000cdbdad71f9a3213336bb8ea90 Mon Sep 17 00:00:00 2001 From: amatilda Date: Mon, 16 Sep 2024 21:13:52 +0300 Subject: [PATCH 3/4] added the ability to delete the system config parameters altogether --- .../cores/ZWSupport/ZWCCConfiguration.cpp | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCConfiguration.cpp b/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCConfiguration.cpp index 7db58185..a57b59e8 100644 --- a/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCConfiguration.cpp +++ b/hardware/arduino/zunoG2/cores/ZWSupport/ZWCCConfiguration.cpp @@ -52,6 +52,7 @@ const ZunoCFGParameter_t *zunoCFGParameter(size_t param) { #define CONFIGPARAMETERS_HIDEN_SEARCH_SYS_CERT_BUILD (true) #endif +#ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM1 const ZunoCFGParameter_t SYSCFGPARAM1 = { .name = "Debug mode", @@ -66,6 +67,8 @@ const ZunoCFGParameter_t SYSCFGPARAM1 = .advanced = true, .hiden_search = CONFIGPARAMETERS_HIDEN_SEARCH_SYS_ALL }; +#endif +#ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM2 const ZunoCFGParameter_t SYSCFGPARAM2 = { .name = "Activity LED", @@ -80,6 +83,8 @@ const ZunoCFGParameter_t SYSCFGPARAM2 = .advanced = true, .hiden_search = CONFIGPARAMETERS_HIDEN_SEARCH_SYS_ALL }; +#endif +#ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM7 const ZunoCFGParameter_t SYSCFGPARAM7 = { .name = "Security", @@ -94,6 +99,8 @@ const ZunoCFGParameter_t SYSCFGPARAM7 = .advanced = true, .hiden_search = CONFIGPARAMETERS_HIDEN_SEARCH_SYS_SECURITY }; +#endif +#ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM8 const ZunoCFGParameter_t SYSCFGPARAM8 = { .name = "RF logging", @@ -107,7 +114,9 @@ const ZunoCFGParameter_t SYSCFGPARAM8 = .altering = false, .advanced = true, .hiden_search = CONFIGPARAMETERS_HIDEN_SEARCH_SYS_ALL -}; +}; +#endif +#ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM9 #if defined(SKETCH_FLAGS) and (SKETCH_FLAGS == HEADER_FLAGS_REBOOT_CFG) #pragma message "parameter 9 DEBUG version" const ZunoCFGParameter_t SYSCFGPARAM9 = @@ -140,6 +149,8 @@ const ZunoCFGParameter_t SYSCFGPARAM9 = .hiden_search = CONFIGPARAMETERS_HIDEN_SEARCH_SYS_CERT_BUILD }; #endif +#endif +#ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM11 const ZunoCFGParameter_t SYSCFGPARAM11 = { .name = "Multilevel report interval", @@ -154,6 +165,8 @@ const ZunoCFGParameter_t SYSCFGPARAM11 = .advanced = true, .hiden_search = CONFIGPARAMETERS_HIDEN_SEARCH_SYS_ALL }; +#endif +#ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM20 const ZunoCFGParameter_t SYSCFGPARAM20 = { .name = "OTA confirmation", @@ -168,23 +181,52 @@ const ZunoCFGParameter_t SYSCFGPARAM20 = .advanced = true, .hiden_search = CONFIGPARAMETERS_HIDEN_SEARCH_SYS_CERT_BUILD }; +#endif static const ZunoCFGParameter_t *zunoCFGParameterProxy(size_t param){ switch(param){ case ZUNO_SYSCFGPARAM_DBG: + #ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM1 return &SYSCFGPARAM1; + #else + return (ZUNO_CFG_PARAMETER_UNKNOWN); + #endif case ZUNO_SYSCFGPARAM_ACTIVITY_LED: + #ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM2 return &SYSCFGPARAM2; + #else + return (ZUNO_CFG_PARAMETER_UNKNOWN); + #endif case ZUNO_SYSCFGPARAM_SECURITY: + #ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM7 return &SYSCFGPARAM7; + #else + return (ZUNO_CFG_PARAMETER_UNKNOWN); + #endif case ZUNO_SYSCFGPARAM_LOGGING: + #ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM8 return &SYSCFGPARAM8; + #else + return (ZUNO_CFG_PARAMETER_UNKNOWN); + #endif case ZUNO_SYSCFGPARAM_FREQUENCY: + #ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM9 return &SYSCFGPARAM9; + #else + return (ZUNO_CFG_PARAMETER_UNKNOWN); + #endif case ZUNO_SYSCFGPARAM_REPORT_TIME: + #ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM11 return &SYSCFGPARAM11; + #else + return (ZUNO_CFG_PARAMETER_UNKNOWN); + #endif case ZUNO_SYSCFGPARAM_OTA_CONFIRM_PIN: + #ifndef CONFIGPARAMETERS_DEL_SYSCFGPARAM20 return &SYSCFGPARAM20; + #else + return (ZUNO_CFG_PARAMETER_UNKNOWN); + #endif } // Return user-defined callback result for user-defined parameters return zunoCFGParameter(param); From 4f34ea974cdb5c80be5cea01af89cc498afcda4c Mon Sep 17 00:00:00 2001 From: amatilda Date: Tue, 17 Sep 2024 11:32:45 +0300 Subject: [PATCH 4/4] add alt for vdac --- .../arduino/zunoG2/cores/LLCore/zuno_dac.cpp | 96 ++++++++++++------- .../arduino/zunoG2/cores/LLCore/zuno_dac.h | 4 + 2 files changed, 68 insertions(+), 32 deletions(-) diff --git a/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.cpp b/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.cpp index eafc5f44..95142485 100644 --- a/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.cpp +++ b/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.cpp @@ -19,8 +19,22 @@ static ZunoGpioBus_t _get_bus_type(uint8_t channel) { } return (type); } + +static uint8_t _get_bus_alt_channel(ZunoDacClassChannelProcess_t *process) { + uint8_t real_pin; + + if (process->vdac_port != vdacChPortB) + return (UNKNOWN_CHANNEL); + if ((real_pin = process->real_pin) == 0x0) + return (0x0); + if (real_pin == 0x1) + return (0x1); + return (UNKNOWN_CHANNEL); +} + #endif +#if defined(_SILICON_LABS_32B_SERIES_2) /* Public Constructors */ ZunoDacClass::ZunoDacClass(void): _vRef(ZunoDacClassRef1V25), _init(false){ size_t i; @@ -76,32 +90,43 @@ bool ZunoDacClass::disable(uint8_t pin) { } /* Private Methods */ -bool ZunoDacClass::_test_free_channel(ZunoDacClassChannelProcess_t *process) { - uint8_t i; - uint8_t i_free; +bool ZunoDacClass::_test_already_channel(ZunoDacClassChannelProcess_t *process) { uint8_t n; - i = 0x0; - i_free = 0x0; n = 0x0; while (n < (sizeof(this->_save) / sizeof(this->_save[0x0]))) { - if (this->_save[n].pin == process[i].pin) { - process[i].channel = n; + if (this->_save[n].pin == process->pin) { + process->channel = n; break ; } n++; } - if (n >= (sizeof(this->_save) / sizeof(this->_save[0x0]))) { - while (i_free < (sizeof(this->_save) / sizeof(this->_save[0x0]))) { - if (this->_save[i_free].pin == UNKNOWN_PIN) { - process[i].channel = i_free; - break ; - } - i_free++; + if (n < (sizeof(this->_save) / sizeof(this->_save[0x0]))) + return (true); + return (false); +} + +bool ZunoDacClass::_test_free_channel(ZunoDacClassChannelProcess_t *process) { + uint8_t i_free; + uint8_t alt_channel; + + alt_channel = _get_bus_alt_channel(process); + if (alt_channel != UNKNOWN_CHANNEL && alt_channel < (sizeof(this->_save) / sizeof(this->_save[0x0])) && this->_save[alt_channel].pin == UNKNOWN_PIN) { + process->channel = alt_channel; + process->alt = true; + return (true); + } + process->alt = false; + i_free = 0x0; + while (i_free < (sizeof(this->_save) / sizeof(this->_save[0x0]))) { + if (this->_save[i_free].pin == UNKNOWN_PIN) { + process->channel = i_free; + break ; } - if (i_free >= (sizeof(this->_save) / sizeof(this->_save[0x0]))) - return (false); + i_free++; } + if (i_free >= (sizeof(this->_save) / sizeof(this->_save[0x0]))) + return (false); return (true); } @@ -135,32 +160,38 @@ bool ZunoDacClass::_write(ZunoDacClassChannelProcess_t *process) { VDAC_InitChannel_TypeDef initChannel; ZunoGpioBus_t type; + if (this->_test_already_channel(process) == true) { + if (this->_save[process->channel].value == process->value) + return (true); + this->_save[process->channel].value = process->value; + VDAC_ChannelOutputSet(VDAC0, process->channel, process->value); + return (true); + } if (this->_test_free_channel(process) == false) return (false); - if (this->_save[process->channel].pin == UNKNOWN_PIN) { + if (process->alt == false) { if ((type = _get_bus_type(process->channel)) == ZunoGpioBusUnknown) return (false); if (zme_gpio_bus_alloc(process->pin, type) == false) return (false); - initChannel = VDAC_INITCHANNEL_DEFAULT; - //initChannel.highCapLoadEnable = false; - //initChannel.powerMode = vdacPowerModeLowPower; + } + initChannel = VDAC_INITCHANNEL_DEFAULT; + //initChannel.highCapLoadEnable = false; + //initChannel.powerMode = vdacPowerModeLowPower; + if (process->alt == true) { + initChannel.auxOutEnable = false; + initChannel.mainOutEnable = true; + } + else { initChannel.auxOutEnable = true; initChannel.mainOutEnable = false; initChannel.port = process->vdac_port; initChannel.pin = process->real_pin; - VDAC_InitChannel(VDAC0, &initChannel, process->channel); - VDAC_Enable(VDAC0, process->channel, true); - this->_save[process->channel].value = process->value; - this->_save[process->channel].pin = process->pin; - } - else { - if (this->_save[process->channel].value == process->value) - return (true); - this->_save[process->channel].value = process->value; - VDAC_ChannelOutputSet(VDAC0, process->channel, process->value); - return (true); } + VDAC_InitChannel(VDAC0, &initChannel, process->channel); + VDAC_Enable(VDAC0, process->channel, true); + this->_save[process->channel].value = process->value; + this->_save[process->channel].pin = process->pin; i = 0x0; while (i < (sizeof(this->_save) / sizeof(this->_save[0x0]))) { if (this->_save[i].pin != UNKNOWN_PIN) { @@ -217,4 +248,5 @@ void ZunoDacClass::_dac_init(ZunoDacClassRef_t ref) { } #endif -ZunoDacClass DAC = ZunoDacClass(); \ No newline at end of file +ZunoDacClass DAC = ZunoDacClass(); +#endif \ No newline at end of file diff --git a/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.h b/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.h index 41369a1c..0d18af96 100644 --- a/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.h +++ b/hardware/arduino/zunoG2/cores/LLCore/zuno_dac.h @@ -3,6 +3,7 @@ #include "em_vdac.h" +#if defined(_SILICON_LABS_32B_SERIES_2) typedef enum ZunoDacClassRef_e { ZunoDacClassRef1V25 = vdacRef1V25, @@ -17,6 +18,7 @@ typedef struct ZunoDacClassChannelProcess_s #if defined(_SILICON_LABS_32B_SERIES_2) uint8_t real_pin; VDAC_ChPortSel_t vdac_port; + bool alt; #endif } ZunoDacClassChannelProcess_t; @@ -35,6 +37,7 @@ class ZunoDacClass { bool disable(uint8_t pin); private: + inline bool _test_already_channel(ZunoDacClassChannelProcess_t *process); inline bool _test_free_channel(ZunoDacClassChannelProcess_t *process); inline bool _write(ZunoDacClassChannelProcess_t *process); inline bool _get_values(ZunoDacClassChannelProcess_t *process, uint8_t pin, float v); @@ -48,5 +51,6 @@ class ZunoDacClass { }; extern ZunoDacClass DAC; +#endif #endif//ZUNO_DAC_H \ No newline at end of file