Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
p0lyg0n1 committed Sep 19, 2024
2 parents 76c5c54 + 4f34ea9 commit 0435d97
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 36 deletions.
96 changes: 64 additions & 32 deletions hardware/arduino/zunoG2/cores/LLCore/zuno_dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -217,4 +248,5 @@ void ZunoDacClass::_dac_init(ZunoDacClassRef_t ref) {
}
#endif

ZunoDacClass DAC = ZunoDacClass();
ZunoDacClass DAC = ZunoDacClass();
#endif
4 changes: 4 additions & 0 deletions hardware/arduino/zunoG2/cores/LLCore/zuno_dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "em_vdac.h"

#if defined(_SILICON_LABS_32B_SERIES_2)
typedef enum ZunoDacClassRef_e
{
ZunoDacClassRef1V25 = vdacRef1V25,
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -48,5 +51,6 @@ class ZunoDacClass {
};

extern ZunoDacClass DAC;
#endif

#endif//ZUNO_DAC_H
44 changes: 43 additions & 1 deletion hardware/arduino/zunoG2/cores/ZWSupport/ZWCCConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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 =
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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);
Expand Down
48 changes: 47 additions & 1 deletion hardware/arduino/zunoG2/cores/ZWSupport/ZWCCUserCredential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!");
Expand Down Expand Up @@ -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
10 changes: 8 additions & 2 deletions hardware/arduino/zunoG2/libraries/ZMEButtons/ZMEButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0435d97

Please sign in to comment.