Change pin handling part 3

This commit is contained in:
Theo Arends 2020-04-27 12:54:07 +02:00
parent 24280bcdea
commit c939077514
62 changed files with 151 additions and 146 deletions

View File

@ -1094,6 +1094,11 @@ uint32_t Pin(uint32_t gpio, uint32_t index) {
*/
}
boolean PinUsed(uint32_t gpio, uint32_t index = 0);
boolean PinUsed(uint32_t gpio, uint32_t index) {
return (Pin(gpio, index) < 99);
}
void SetPin(uint32_t lpin, uint32_t gpio) {
//#ifdef ESP8266
pin[gpio] = lpin;
@ -1106,7 +1111,7 @@ void SetPin(uint32_t lpin, uint32_t gpio) {
void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state)
{
if (Pin(gpio_pin, index) < 99) {
if (PinUsed(gpio_pin, index)) {
digitalWrite(Pin(gpio_pin, index), state &1);
}
}

View File

@ -60,7 +60,7 @@ void ButtonInit(void)
{
Button.present = 0;
for (uint32_t i = 0; i < MAX_KEYS; i++) {
if (Pin(GPIO_KEY1, i) < 99) {
if (PinUsed(GPIO_KEY1, i)) {
Button.present++;
pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
}
@ -135,7 +135,7 @@ void ButtonHandler(void)
}
else
#endif // ESP8266
if (Pin(GPIO_KEY1, button_index) < 99) {
if (PinUsed(GPIO_KEY1, button_index)) {
button_present = 1;
button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index));
}

View File

@ -60,7 +60,7 @@ void ButtonInit(void)
{
Button.present = 0;
for (uint32_t i = 0; i < MAX_KEYS; i++) {
if (Pin(GPIO_KEY1, i) < 99) {
if (PinUsed(GPIO_KEY1, i)) {
Button.present++;
pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
}
@ -132,7 +132,7 @@ void ButtonHandler(void)
}
else
#endif // ESP8266
if (Pin(GPIO_KEY1, button_index) < 99) {
if (PinUsed(GPIO_KEY1, button_index)) {
button_present = 1;
button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index));
}
@ -266,7 +266,7 @@ void ButtonHandler(void)
} else {
SendKey(KEY_BUTTON, button_index +1, Button.press_counter[button_index] +9); // 2,3,4 and 5 press send just the key value (11,12,13 and 14) for rules
if (0 == button_index) { // BUTTON1 can toggle up to 5 relays if present. If a relay is not present will send out the key value (2,11,12,13 and 14) for rules
if ((Button.press_counter[button_index] > 1 && Pin(GPIO_REL1, Button.press_counter[button_index]-1) < 99) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) {
if ((Button.press_counter[button_index] > 1 && PinUsed(GPIO_REL1, Button.press_counter[button_index]-1)) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) {
ExecuteCommandPower(button_index + Button.press_counter[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: Relay%d found on GPIO%d"), Button.press_counter[button_index], Pin(GPIO_REL1, Button.press_counter[button_index]-1));
}

View File

@ -1167,7 +1167,7 @@ void CmndTemplate(void)
void CmndPwm(void)
{
if (pwm_present && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PWMS)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && (Pin(GPIO_PWM1, XdrvMailbox.index -1) < 99)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && PinUsed(GPIO_PWM1, XdrvMailbox.index -1)) {
Settings.pwm_value[XdrvMailbox.index -1] = XdrvMailbox.payload;
analogWrite(Pin(GPIO_PWM1, XdrvMailbox.index -1), bitRead(pwm_inverted, XdrvMailbox.index -1) ? Settings.pwm_range - XdrvMailbox.payload : XdrvMailbox.payload);
}

View File

@ -80,7 +80,7 @@ bool RotaryButtonPressed(void)
void RotaryInit(void)
{
Rotary.present = 0;
if ((Pin(GPIO_ROT1A) < 99) && (Pin(GPIO_ROT1B) < 99)) {
if (PinUsed(GPIO_ROT1A) && PinUsed(GPIO_ROT1B)) {
Rotary.present++;
pinMode(Pin(GPIO_ROT1A), INPUT_PULLUP);
pinMode(Pin(GPIO_ROT1B), INPUT_PULLUP);

View File

@ -86,7 +86,7 @@ void SwitchProbe(void)
uint8_t force_low = (Settings.switch_debounce % 50) &2; // 52, 102, 152 etc
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if (Pin(GPIO_SWT1, i) < 99) {
if (PinUsed(GPIO_SWT1, i)) {
// Olimex user_switch2.c code to fix 50Hz induced pulses
if (1 == digitalRead(Pin(GPIO_SWT1, i))) {
@ -127,7 +127,7 @@ void SwitchInit(void)
Switch.present = 0;
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
Switch.last_state[i] = 1; // Init global to virtual switch state;
if (Pin(GPIO_SWT1, i) < 99) {
if (PinUsed(GPIO_SWT1, i)) {
Switch.present++;
pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_SWT1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
Switch.last_state[i] = digitalRead(Pin(GPIO_SWT1, i)); // Set global now so doesn't change the saved power state on first switch check
@ -148,7 +148,7 @@ void SwitchHandler(uint8_t mode)
uint16_t loops_per_second = 1000 / Settings.switch_debounce;
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if ((Pin(GPIO_SWT1, i) < 99) || (mode)) {
if (PinUsed(GPIO_SWT1, i) || (mode)) {
uint8_t button = Switch.virtual_state[i];
uint8_t switchflag = POWER_TOGGLE +1;

View File

@ -325,7 +325,7 @@ void SetPowerOnState(void)
// Issue #526 and #909
for (uint32_t i = 0; i < devices_present; i++) {
if (!Settings.flag3.no_power_feedback) { // SetOption63 - Don't scan relay power state at restart - #5594 and #5663
if ((i < MAX_RELAYS) && (Pin(GPIO_REL1, i) < 99)) {
if ((i < MAX_RELAYS) && PinUsed(GPIO_REL1, i)) {
bitWrite(power, i, digitalRead(Pin(GPIO_REL1, i)) ^ bitRead(rel_inverted, i));
}
}
@ -339,11 +339,11 @@ void SetPowerOnState(void)
void SetLedPowerIdx(uint32_t led, uint32_t state)
{
if ((99 == Pin(GPIO_LEDLNK)) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present
if (Pin(GPIO_LED1, 1) < 99) {
if (PinUsed(GPIO_LED1, 1)) {
led = 1;
}
}
if (Pin(GPIO_LED1, led) < 99) {
if (PinUsed(GPIO_LED1, led)) {
uint32_t mask = 1 << led;
if (state) {
state = 1;
@ -608,7 +608,7 @@ void MqttShowPWMState(void)
ResponseAppend_P(PSTR("\"" D_CMND_PWM "\":{"));
bool first = true;
for (uint32_t i = 0; i < MAX_PWMS; i++) {
if (Pin(GPIO_PWM1, i) < 99) {
if (PinUsed(GPIO_PWM1, i)) {
ResponseAppend_P(PSTR("%s\"" D_CMND_PWM "%d\":%d"), first ? "" : ",", i+1, Settings.pwm_value[i]);
first = false;
}
@ -703,9 +703,9 @@ bool MqttShowSensor(void)
int json_data_start = strlen(mqtt_data);
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
#ifdef USE_TM1638
if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) {
if (PinUsed(GPIO_SWT1, i) || (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB))) {
#else
if (Pin(GPIO_SWT1, i) < 99) {
if (PinUsed(GPIO_SWT1, i)) {
#endif // USE_TM1638
ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(SwitchState(i)));
}
@ -913,7 +913,7 @@ void Every250mSeconds(void)
if (200 == blinks) blinks = 0; // Disable blink
}
}
if (Settings.ledstate &1 && (Pin(GPIO_LEDLNK) < 99 || !(blinks || restart_flag || ota_state_flag)) ) {
if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(blinks || restart_flag || ota_state_flag)) ) {
bool tstate = power & Settings.ledmask;
#ifdef ESP8266
if ((SONOFF_TOUCH == my_module_type) || (SONOFF_T11 == my_module_type) || (SONOFF_T12 == my_module_type) || (SONOFF_T13 == my_module_type)) {
@ -1320,7 +1320,7 @@ void SerialInput(void)
void ResetPwm(void)
{
for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
if (Pin(GPIO_PWM1, i) < 99) {
if (PinUsed(GPIO_PWM1, i)) {
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range : 0);
// analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
}
@ -1446,7 +1446,7 @@ void GpioInit(void)
analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c)
#ifdef USE_SPI
spi_flg = ((((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || (((Pin(GPIO_SPI_DC) < 99) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12)));
spi_flg = (((PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || ((PinUsed(GPIO_SPI_DC) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12)));
if (spi_flg) {
for (uint32_t i = 0; i < GPIO_MAX; i++) {
if ((Pin(i) >= 12) && (Pin(i) <=14)) { SetPin(99, i); }
@ -1458,7 +1458,7 @@ void GpioInit(void)
my_module.io[14] = GPIO_SPI_CLK;
SetPin(14, GPIO_SPI_CLK);
}
soft_spi_flg = ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && ((Pin(GPIO_SSPI_MOSI) < 99) || (Pin(GPIO_SSPI_MOSI) < 99)));
soft_spi_flg = (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MOSI)));
#endif // USE_SPI
// Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino
@ -1474,7 +1474,7 @@ void GpioInit(void)
}
#ifdef USE_I2C
i2c_flg = ((Pin(GPIO_I2C_SCL) < 99) && (Pin(GPIO_I2C_SDA) < 99));
i2c_flg = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA));
if (i2c_flg) {
Wire.begin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
}
@ -1506,7 +1506,7 @@ void GpioInit(void)
#endif // ESP8266
for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
if (Pin(GPIO_PWM1, i) < 99) {
if (PinUsed(GPIO_PWM1, i)) {
pinMode(Pin(GPIO_PWM1, i), OUTPUT);
if (light_type) {
// force PWM GPIOs to low or high mode, see #7165
@ -1519,7 +1519,7 @@ void GpioInit(void)
}
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
if (Pin(GPIO_REL1, i) < 99) {
if (PinUsed(GPIO_REL1, i)) {
pinMode(Pin(GPIO_REL1, i), OUTPUT);
devices_present++;
#ifdef ESP8266
@ -1532,7 +1532,7 @@ void GpioInit(void)
}
for (uint32_t i = 0; i < MAX_LEDS; i++) {
if (Pin(GPIO_LED1, i) < 99) {
if (PinUsed(GPIO_LED1, i)) {
#ifdef USE_ARILUX_RF
if ((3 == i) && (leds_present < 2) && (99 == Pin(GPIO_ARIRFSEL))) {
SetPin(Pin(GPIO_LED4), GPIO_ARIRFSEL); // Legacy support where LED4 was Arilux RF enable
@ -1547,13 +1547,13 @@ void GpioInit(void)
#endif
}
}
if (Pin(GPIO_LEDLNK) < 99) {
if (PinUsed(GPIO_LEDLNK)) {
pinMode(Pin(GPIO_LEDLNK), OUTPUT);
digitalWrite(Pin(GPIO_LEDLNK), ledlnk_inverted);
}
#ifdef USE_PWM_DIMMER
if (PWM_DIMMER == my_module_type && Pin(GPIO_REL1) < 99) { devices_present--; }
if (PWM_DIMMER == my_module_type && PinUsed(GPIO_REL1)) { devices_present--; }
#endif // USE_PWM_DIMMER
ButtonInit();

View File

@ -1244,7 +1244,7 @@ bool LightModuleInit(void)
if (Settings.flag.pwm_control) { // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL
for (uint32_t i = 0; i < MAX_PWMS; i++) {
if (Pin(GPIO_PWM1, i) < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
if (PinUsed(GPIO_PWM1, i)) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
}
}
@ -1347,12 +1347,12 @@ void LightInit(void)
if (light_type < LT_PWM6) { // PWM
for (uint32_t i = 0; i < light_type; i++) {
Settings.pwm_value[i] = 0; // Disable direct PWM control
if (Pin(GPIO_PWM1, i) < 99) {
if (PinUsed(GPIO_PWM1, i)) {
pinMode(Pin(GPIO_PWM1, i), OUTPUT);
}
}
if (Pin(GPIO_ARIRFRCV) < 99) {
if (Pin(GPIO_ARIRFSEL) < 99) {
if (PinUsed(GPIO_ARIRFRCV)) {
if (PinUsed(GPIO_ARIRFSEL)) {
pinMode(Pin(GPIO_ARIRFSEL), OUTPUT);
digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF
}
@ -2133,7 +2133,7 @@ void LightSetOutputs(const uint16_t *cur_col_10) {
// now apply the actual PWM values, adjusted and remapped 10-bits range
if (light_type < LT_PWM6) { // only for direct PWM lights, not for Tuya, Armtronix...
for (uint32_t i = 0; i < (Light.subtype - Light.pwm_offset); i++) {
if (Pin(GPIO_PWM1, i) < 99) {
if (PinUsed(GPIO_PWM1, i)) {
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d"), i, cur_col_10[i]);
uint16_t cur_col = cur_col_10[i + Light.pwm_offset];
if (!isChannelCT(i)) { // if CT don't use pwm_min and pwm_max

View File

@ -279,28 +279,28 @@ bool Xdrv05(uint8_t function)
{
bool result = false;
if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) {
if (PinUsed(GPIO_IRSEND) || PinUsed(GPIO_IRRECV)) {
switch (function) {
case FUNC_PRE_INIT:
if (Pin(GPIO_IRSEND) < 99) {
if (PinUsed(GPIO_IRSEND)) {
IrSendInit();
}
#ifdef USE_IR_RECEIVE
if (Pin(GPIO_IRRECV) < 99) {
if (PinUsed(GPIO_IRRECV)) {
IrReceiveInit();
}
#endif // USE_IR_RECEIVE
break;
case FUNC_EVERY_50_MSECOND:
#ifdef USE_IR_RECEIVE
if (Pin(GPIO_IRRECV) < 99) {
if (PinUsed(GPIO_IRRECV)) {
IrReceiveCheck(); // check if there's anything on IR side
}
#endif // USE_IR_RECEIVE
irsend_active = false; // re-enable IR reception
break;
case FUNC_COMMAND:
if (Pin(GPIO_IRSEND) < 99) {
if (PinUsed(GPIO_IRSEND)) {
result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand);
}
break;

View File

@ -635,24 +635,24 @@ bool Xdrv05(uint8_t function)
{
bool result = false;
if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) {
if (PinUsed(GPIO_IRSEND) || PinUsed(GPIO_IRRECV)) {
switch (function) {
case FUNC_PRE_INIT:
if (Pin(GPIO_IRSEND) < 99) {
if (PinUsed(GPIO_IRSEND)) {
IrSendInit();
}
if (Pin(GPIO_IRRECV) < 99) {
if (PinUsed(GPIO_IRRECV)) {
IrReceiveInit();
}
break;
case FUNC_EVERY_50_MSECOND:
if (Pin(GPIO_IRRECV) < 99) {
if (PinUsed(GPIO_IRRECV)) {
IrReceiveCheck(); // check if there's anything on IR side
}
irsend_active = false; // re-enable IR reception
break;
case FUNC_COMMAND:
if (Pin(GPIO_IRSEND) < 99) {
if (PinUsed(GPIO_IRSEND)) {
result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand);
}
break;

View File

@ -576,7 +576,7 @@ void HandleDomoticzConfiguration(void)
i +1, i, Settings.domoticz_relay_idx[i],
i +1, i, Settings.domoticz_key_idx[i]);
}
if (Pin(GPIO_SWT1, i) < 99) {
if (PinUsed(GPIO_SWT1, i)) {
WSContentSend_P(HTTP_FORM_DOMOTICZ_SWITCH,
i +1, i, Settings.domoticz_switch_idx[i]);
}

View File

@ -87,7 +87,7 @@ void SerialBridgeInput(void)
void SerialBridgeInit(void)
{
serial_bridge_active = false;
if ((Pin(GPIO_SBR_RX) < 99) && (Pin(GPIO_SBR_TX) < 99)) {
if (PinUsed(GPIO_SBR_RX) && PinUsed(GPIO_SBR_TX)) {
SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX));
if (SerialBridgeSerial->begin(Settings.sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits
if (SerialBridgeSerial->hardwareSerial()) {

View File

@ -580,9 +580,9 @@ void RulesEvery50ms(void)
// Boot time SWITCHES Status
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
#ifdef USE_TM1638
if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) {
if (PinUsed(GPIO_SWT1, i) || (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB))) {
#else
if (Pin(GPIO_SWT1, i) < 99) {
if (PinUsed(GPIO_SWT1, i)) {
#endif // USE_TM1638
snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (SwitchState(i)));
RulesProcessEvent(json_event);

View File

@ -370,7 +370,7 @@ void HAssAnnounceSwitches(void)
uint8_t hold = 0;
uint8_t pir = 0;
if (Pin(GPIO_SWT1, switch_index) < 99) { switch_present = 1; }
if (PinUsed(GPIO_SWT1, switch_index)) { switch_present = 1; }
if (KeyTopicActive(1) && strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), mqtt_topic)) // Enable Discovery for Switches only if Switchtopic is set to a custom name
{
@ -451,7 +451,7 @@ void HAssAnnounceButtons(void)
} else
#endif
{
if (Pin(GPIO_KEY1, button_index) < 99) {
if (PinUsed(GPIO_KEY1, button_index)) {
button_present = 1;
}
}

View File

@ -232,7 +232,7 @@ bool Xdrv14(uint8_t function)
{
bool result = false;
if (Pin(GPIO_MP3_DFR562) < 99) {
if (PinUsed(GPIO_MP3_DFR562)) {
switch (function) {
case FUNC_PRE_INIT:
MP3PlayerInit(); // init and start communication

View File

@ -596,7 +596,7 @@ void TuyaNormalPowerModePacketProcess(void)
bool TuyaModuleSelected(void)
{
if (!(Pin(GPIO_TUYA_RX) < 99) || !(Pin(GPIO_TUYA_TX) < 99)) { // fallback to hardware-serial if not explicitly selected
if (!PinUsed(GPIO_TUYA_RX) || !PinUsed(GPIO_TUYA_TX)) { // fallback to hardware-serial if not explicitly selected
SetPin(1, GPIO_TUYA_TX);
SetPin(3, GPIO_TUYA_RX);
Settings.my_gp.io[1] = GPIO_TUYA_TX;

View File

@ -81,10 +81,10 @@ void RfReceiveCheck(void)
void RfInit(void)
{
if (Pin(GPIO_RFSEND) < 99) {
if (PinUsed(GPIO_RFSEND)) {
mySwitch.enableTransmit(Pin(GPIO_RFSEND));
}
if (Pin(GPIO_RFRECV) < 99) {
if (PinUsed(GPIO_RFRECV)) {
pinMode( Pin(GPIO_RFRECV), INPUT);
mySwitch.enableReceive(Pin(GPIO_RFRECV));
}
@ -170,15 +170,15 @@ bool Xdrv17(uint8_t function)
{
bool result = false;
if ((Pin(GPIO_RFSEND) < 99) || (Pin(GPIO_RFRECV) < 99)) {
if (PinUsed(GPIO_RFSEND) || PinUsed(GPIO_RFRECV)) {
switch (function) {
case FUNC_EVERY_50_MSECOND:
if (Pin(GPIO_RFRECV) < 99) {
if (PinUsed(GPIO_RFRECV)) {
RfReceiveCheck();
}
break;
case FUNC_COMMAND:
if (Pin(GPIO_RFSEND) < 99) {
if (PinUsed(GPIO_RFSEND)) {
result = DecodeCommand(kRfSendCommands, RfSendCommand);
}
break;

View File

@ -162,7 +162,7 @@ void ZigbeeInit(void)
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP_getFreeHeap());
zigbee.active = false;
if ((Pin(GPIO_ZIGBEE_RX) < 99) && (Pin(GPIO_ZIGBEE_TX) < 99)) {
if (PinUsed(GPIO_ZIGBEE_RX) && PinUsed(GPIO_ZIGBEE_TX)) {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX));
// if seriallog_level is 0, we allow GPIO 13/15 to switch to Hardware Serial
ZigbeeSerial = new TasmotaSerial(Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX), seriallog_level ? 1 : 2, 0, 256); // set a receive buffer of 256 bytes

View File

@ -111,7 +111,7 @@ bool BuzzerPinState(void)
void BuzzerInit(void)
{
if (Pin(GPIO_BUZZER) < 99) {
if (PinUsed(GPIO_BUZZER)) {
pinMode(Pin(GPIO_BUZZER), OUTPUT);
BuzzerOff();
} else {

View File

@ -93,7 +93,7 @@ void CmndDoTurn(void) {
}
void CmndSetMIS(void) {
if ((Pin(GPIO_A4988_MS1) < 99) && (Pin(GPIO_A4988_MS2) < 99) && (Pin(GPIO_A4988_MS3) < 99) && (XdrvMailbox.data_len > 0)) {
if (PinUsed(GPIO_A4988_MS1) && PinUsed(GPIO_A4988_MS2) && PinUsed(GPIO_A4988_MS3) && (XdrvMailbox.data_len > 0)) {
short newMIS = strtoul(XdrvMailbox.data,nullptr,10);
myA4988->setMIS(newMIS);
ResponseCmndDone();
@ -122,7 +122,7 @@ void CmndSetRPM(void) {
bool Xdrv25(uint8_t function)
{
bool result = false;
if ((Pin(GPIO_A4988_DIR) < 99) && (Pin(GPIO_A4988_STP) < 99)) {
if (PinUsed(GPIO_A4988_DIR) && PinUsed(GPIO_A4988_STP)) {
switch (function) {
case FUNC_INIT:
A4988Init();

View File

@ -147,7 +147,7 @@ void AriluxRfHandler(void)
void AriluxRfInit(void)
{
if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) {
if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) {
if (Settings.last_module != Settings.module) {
Settings.rf_code[1][6] = 0;
Settings.rf_code[1][7] = 0;
@ -162,7 +162,7 @@ void AriluxRfInit(void)
void AriluxRfDisable(void)
{
if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) {
if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) {
detachInterrupt(Pin(GPIO_ARIRFRCV));
digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF
}
@ -178,7 +178,7 @@ bool Xdrv26(uint8_t function)
switch (function) {
case FUNC_EVERY_50_MSECOND:
if (Pin(GPIO_ARIRFRCV) < 99) { AriluxRfHandler(); }
if (PinUsed(GPIO_ARIRFRCV)) { AriluxRfHandler(); }
break;
case FUNC_EVERY_SECOND:
if (10 == uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts

View File

@ -201,7 +201,7 @@ void ShutterInit(void)
}
} else {
Shutter.mode = SHT_OFF_ON__OPEN_CLOSE;
if ((Pin(GPIO_PWM1, i) < 99) && (Pin(GPIO_CNTR1, i) < 99)) {
if (PinUsed(GPIO_PWM1, i) && PinUsed(GPIO_CNTR1, i)) {
Shutter.mode = SHT_OFF_ON__OPEN_CLOSE_STEPPER;
Shutter.pwm_frequency[i] = 0;
Shutter.accelerator[i] = 0;

View File

@ -54,7 +54,7 @@ bool DeepSleepEnabled(void)
return false; // Disabled
}
if (Pin(GPIO_DEEPSLEEP) < 99) {
if (PinUsed(GPIO_DEEPSLEEP)) {
pinMode(Pin(GPIO_DEEPSLEEP), INPUT_PULLUP);
return (digitalRead(Pin(GPIO_DEEPSLEEP))); // Disable DeepSleep if user holds pin GPIO_DEEPSLEEP low
}

View File

@ -437,15 +437,15 @@ void TasmotaSlave_Init(void)
return;
}
if (!TSlave.SerialEnabled) {
if ((Pin(GPIO_TASMOTASLAVE_RXD) < 99) && (Pin(GPIO_TASMOTASLAVE_TXD) < 99) &&
((Pin(GPIO_TASMOTASLAVE_RST) < 99) || (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99))) {
if (PinUsed(GPIO_TASMOTASLAVE_RXD) && PinUsed(GPIO_TASMOTASLAVE_TXD) &&
(PinUsed(GPIO_TASMOTASLAVE_RST) || PinUsed(GPIO_TASMOTASLAVE_RST_INV))) {
TasmotaSlave_Serial = new TasmotaSerial(Pin(GPIO_TASMOTASLAVE_RXD), Pin(GPIO_TASMOTASLAVE_TXD), 1, 0, 200);
if (TasmotaSlave_Serial->begin(USE_TASMOTA_SLAVE_SERIAL_SPEED)) {
if (TasmotaSlave_Serial->hardwareSerial()) {
ClaimSerial();
}
TasmotaSlave_Serial->setTimeout(50);
if (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99) {
if (PinUsed(GPIO_TASMOTASLAVE_RST_INV)) {
SetPin(Pin(GPIO_TASMOTASLAVE_RST_INV), GPIO_TASMOTASLAVE_RST);
SetPin(99, GPIO_TASMOTASLAVE_RST_INV);
TSlave.inverted = HIGH;

View File

@ -73,7 +73,7 @@ bool NRF24initRadio()
bool NRF24Detect(void)
{
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_DC)<99)){
if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_DC)) {
SPI.pins(SCK,MOSI,MISO,-1);
if(NRF24initRadio()){
NRF24.chipType = 32; // SPACE

View File

@ -94,7 +94,7 @@ void PWMModulePreInit(void)
PWMDimmerSetPoweredOffLed();
// The relay initializes to on. If the power is supposed to be off, turn the relay off.
if (!power && Pin(GPIO_REL1) < 99) digitalWrite(Pin(GPIO_REL1), bitRead(rel_inverted, 0) ? 1 : 0);
if (!power && PinUsed(GPIO_REL1)) digitalWrite(Pin(GPIO_REL1), bitRead(rel_inverted, 0) ? 1 : 0);
#ifdef USE_PWM_DIMMER_REMOTE
// If remote device mode is enabled, set the device group count to the number of buttons
@ -104,7 +104,7 @@ void PWMModulePreInit(void)
device_group_count = 0;
for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) {
if (Pin(GPIO_KEY1, button_index) < 99) device_group_count++;
if (PinUsed(GPIO_KEY1, button_index)) device_group_count++;
}
remote_pwm_dimmer_count = device_group_count - 1;
@ -156,7 +156,7 @@ void PWMDimmerSetBrightnessLeds(int32_t operation)
void PWMDimmerSetPoweredOffLed(void)
{
// Set the powered-off LED state.
if (Pin(GPIO_LEDLNK) < 99) {
if (PinUsed(GPIO_LEDLNK)) {
bool power_off_led_on = !power && Settings.flag4.powered_off_led;
if (ledlnk_inverted) power_off_led_on ^= 1;
digitalWrite(Pin(GPIO_LEDLNK), power_off_led_on);

View File

@ -71,7 +71,7 @@ void SSD1306InitDriver(void)
}
uint8_t reset_pin = -1;
if (Pin(GPIO_OLED_RESET) < 99) {
if (PinUsed(GPIO_OLED_RESET)) {
reset_pin = Pin(GPIO_OLED_RESET);
}

View File

@ -128,7 +128,7 @@ void Ili9341DisplayOnOff(uint8_t on)
{
// tft->showDisplay(on);
// tft->invertDisplay(on);
if (Pin(GPIO_BACKLIGHT) < 99) {
if (PinUsed(GPIO_BACKLIGHT)) {
pinMode(Pin(GPIO_BACKLIGHT), OUTPUT);
digitalWrite(Pin(GPIO_BACKLIGHT), on);
}

View File

@ -67,11 +67,11 @@ void EpdInitDriver29()
epd = new Epd(EPD_WIDTH,EPD_HEIGHT);
// whiten display with full update, takes 3 seconds
if ((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CLK) < 99) && (Pin(GPIO_SPI_MOSI) < 99)) {
if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MOSI)) {
epd->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK));
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: HardSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SPI_CS), Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI));
}
else if ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && (Pin(GPIO_SSPI_MOSI) < 99)) {
else if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && PinUsed(GPIO_SSPI_MOSI)) {
epd->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK));
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: SoftSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SSPI_CS), Pin(GPIO_SSPI_SCLK), Pin(GPIO_SSPI_MOSI));
} else {

View File

@ -65,14 +65,14 @@ void EpdInitDriver42()
epd42 = new Epd42(EPD_WIDTH42,EPD_HEIGHT42);
#ifdef USE_SPI
if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)) {
if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)) {
epd42->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK));
} else {
free(buffer);
return;
}
#else
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) {
if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) {
epd42->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK));
} else {
free(buffer);

View File

@ -80,15 +80,15 @@ void ILI9488_InitDriver()
bg_color = ILI9488_BLACK;
uint8_t bppin=BACKPLANE_PIN;
if (Pin(GPIO_BACKLIGHT)<99) {
if (PinUsed(GPIO_BACKLIGHT)) {
bppin=Pin(GPIO_BACKLIGHT);
}
// init renderer
if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){
if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)) {
ili9488 = new ILI9488(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK),bppin);
} else {
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) {
if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) {
ili9488 = new ILI9488(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK),bppin);
} else {
return;

View File

@ -60,10 +60,10 @@ void SSD1351_InitDriver() {
bg_color = SSD1351_BLACK;
// init renderer
if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){
if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)){
ssd1351 = new SSD1351(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK));
} else {
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) {
if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) {
ssd1351 = new SSD1351(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK));
} else {
return;

View File

@ -72,10 +72,10 @@ void RA8876_InitDriver()
bg_color = RA8876_BLACK;
// init renderer, must use hardware spi
if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)==13) && (Pin(GPIO_SSPI_MISO)==12) && (Pin(GPIO_SSPI_SCLK)==14)) {
if (PinUsed(GPIO_SSPI_CS) && (Pin(GPIO_SSPI_MOSI)==13) && (Pin(GPIO_SSPI_MISO)==12) && (Pin(GPIO_SSPI_SCLK)==14)) {
ra8876 = new RA8876(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_MISO),Pin(GPIO_SSPI_SCLK),Pin(GPIO_BACKLIGHT));
} else {
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)==13) && (Pin(GPIO_SPI_MISO)==12) && (Pin(GPIO_SPI_CLK)==14)) {
if (PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_MOSI)==13) && (Pin(GPIO_SPI_MISO)==12) && (Pin(GPIO_SPI_CLK)==14)) {
ra8876 = new RA8876(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_MISO),Pin(GPIO_SPI_CLK),Pin(GPIO_BACKLIGHT));
} else {
return;

View File

@ -449,7 +449,7 @@ void Ws2812ShowScheme(void)
void Ws2812ModuleSelected(void)
{
if (Pin(GPIO_WS2812) < 99) { // RGB led
if (PinUsed(GPIO_WS2812)) { // RGB led
// For DMA, the Pin is ignored as it uses GPIO3 due to DMA hardware use.
strip = new NeoPixelBus<selectedNeoFeatureType, selectedNeoSpeedType>(WS2812_MAX_LEDS, Pin(GPIO_WS2812));

View File

@ -115,7 +115,7 @@ bool My92x1SetChannels(void)
void My92x1ModuleSelected(void)
{
if ((Pin(GPIO_DCKI) < 99) && (Pin(GPIO_DI) < 99)) {
if (PinUsed(GPIO_DCKI) && PinUsed(GPIO_DI)) {
My92x1.pdi_pin = Pin(GPIO_DI);
My92x1.pdcki_pin = Pin(GPIO_DCKI);

View File

@ -122,7 +122,7 @@ bool Sm16716SetChannels(void)
/*
// handle any PWM pins, skipping the first 3 values for sm16716
for (uint32_t i = 3; i < Light.subtype; i++) {
if (Pin(GPIO_PWM1, i-3) < 99) {
if (PinUsed(GPIO_PWM1, i-3)) {
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d, Pwm%d %d"), i, cur_col[i], i+1, curcol);
analogWrite(Pin(GPIO_PWM1, i-3), bitRead(pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]);
}
@ -138,7 +138,7 @@ bool Sm16716SetChannels(void)
void Sm16716ModuleSelected(void)
{
if ((Pin(GPIO_SM16716_CLK) < 99) && (Pin(GPIO_SM16716_DAT) < 99)) {
if (PinUsed(GPIO_SM16716_CLK) && PinUsed(GPIO_SM16716_DAT)) {
Sm16716.pin_clk = Pin(GPIO_SM16716_CLK);
Sm16716.pin_dat = Pin(GPIO_SM16716_DAT);
Sm16716.pin_sel = Pin(GPIO_SM16716_SEL);
@ -147,7 +147,7 @@ void Sm16716ModuleSelected(void)
// init PWM
for (uint32_t i = 0; i < Light.subtype; i++) {
Settings.pwm_value[i] = 0; // Disable direct PWM control
if (Pin(GPIO_PWM1, i) < 99) {
if (PinUsed(GPIO_PWM1, i)) {
pinMode(Pin(GPIO_PWM1, i), OUTPUT);
}
}

View File

@ -134,7 +134,7 @@ bool Sm2135SetChannels(void)
void Sm2135ModuleSelected(void)
{
if ((Pin(GPIO_SM2135_CLK) < 99) && (Pin(GPIO_SM2135_DAT) < 99)) {
if (PinUsed(GPIO_SM2135_CLK) && PinUsed(GPIO_SM2135_DAT)) {
Sm2135.clk = Pin(GPIO_SM2135_CLK);
Sm2135.data = Pin(GPIO_SM2135_DAT);

View File

@ -221,7 +221,7 @@ bool SnfL1SetChannels(void)
void SnfL1ModuleSelected(void)
{
if (SONOFF_L1 == my_module_type) {
if ((Pin(GPIO_RXD) < 99) && (Pin(GPIO_TXD) < 99)) {
if (PinUsed(GPIO_RXD) && PinUsed(GPIO_TXD)) {
SetSerial(19200, TS_SERIAL_8N1);
light_type = LT_RGB;

View File

@ -70,7 +70,7 @@ bool ElectriqMoodLSetChannels(void)
void ElectriqMoodLModuleSelected(void)
{
if (Pin(GPIO_ELECTRIQ_MOODL_TX) < 99) {
if (PinUsed(GPIO_ELECTRIQ_MOODL_TX)) {
SetSerial(9600, TS_SERIAL_8N1);
light_type = LT_RGBW;
light_flg = XLGT_06;

View File

@ -138,7 +138,7 @@ void HlwEvery200ms(void)
}
}
if (Pin(GPIO_NRG_CF1) < 99) {
if (PinUsed(GPIO_NRG_CF1)) {
Hlw.cf1_timer++;
if (Hlw.cf1_timer >= 8) {
Hlw.cf1_timer = 0;
@ -233,11 +233,11 @@ void HlwSnsInit(void)
Hlw.current_ratio = HLW_IREF;
}
if (Pin(GPIO_NRG_SEL) < 99) {
if (PinUsed(GPIO_NRG_SEL)) {
pinMode(Pin(GPIO_NRG_SEL), OUTPUT);
digitalWrite(Pin(GPIO_NRG_SEL), Hlw.select_ui_flag);
}
if (Pin(GPIO_NRG_CF1) < 99) {
if (PinUsed(GPIO_NRG_CF1)) {
pinMode(Pin(GPIO_NRG_CF1), INPUT_PULLUP);
attachInterrupt(Pin(GPIO_NRG_CF1), HlwCf1Interrupt, FALLING);
}
@ -248,7 +248,7 @@ void HlwSnsInit(void)
void HlwDrvInit(void)
{
Hlw.model_type = 0; // HLW8012
if (Pin(GPIO_HJL_CF) < 99) {
if (PinUsed(GPIO_HJL_CF)) {
// pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF];
// pin[GPIO_HJL_CF] = 99;
SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF);
@ -256,10 +256,10 @@ void HlwDrvInit(void)
Hlw.model_type = 1; // HJL-01/BL0937
}
if (Pin(GPIO_HLW_CF) < 99) { // HLW8012 or HJL-01 based device Power monitor
if (PinUsed(GPIO_HLW_CF)) { // HLW8012 or HJL-01 based device Power monitor
Hlw.ui_flag = true; // Voltage on high
if (Pin(GPIO_NRG_SEL_INV) < 99) {
if (PinUsed(GPIO_NRG_SEL_INV)) {
// pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV];
// pin[GPIO_NRG_SEL_INV] = 99;
SetPin(Pin(GPIO_NRG_SEL_INV), GPIO_NRG_SEL);
@ -267,7 +267,7 @@ void HlwDrvInit(void)
Hlw.ui_flag = false; // Voltage on low
}
if (Pin(GPIO_NRG_CF1) < 99) { // Voltage and/or Current monitor
if (PinUsed(GPIO_NRG_CF1)) { // Voltage and/or Current monitor
if (99 == Pin(GPIO_NRG_SEL)) { // Voltage and/or Current selector
Energy.current_available = false; // Assume Voltage
}

View File

@ -245,8 +245,8 @@ void CseDrvInit(void)
{
Cse.rx_buffer = (uint8_t*)(malloc(CSE_BUFFER_SIZE));
if (Cse.rx_buffer != nullptr) {
// if ((Pin(GPIO_CSE7766_RX) < 99) && (Pin(GPIO_CSE7766_TX) < 99)) {
if (Pin(GPIO_CSE7766_RX) < 99) {
// if (PinUsed(GPIO_CSE7766_RX) && PinUsed(GPIO_CSE7766_TX)) {
if (PinUsed(GPIO_CSE7766_RX)) {
energy_flg = XNRG_02;
}
}

View File

@ -256,7 +256,7 @@ void PzemSnsInit(void)
void PzemDrvInit(void)
{
if ((Pin(GPIO_PZEM004_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { // Any device with a Pzem004T
if (PinUsed(GPIO_PZEM004_RX) && PinUsed(GPIO_PZEM0XX_TX)) { // Any device with a Pzem004T
energy_flg = XNRG_03;
}
}

View File

@ -578,8 +578,8 @@ void McpSnsInit(void)
void McpDrvInit(void)
{
if ((Pin(GPIO_MCP39F5_RX) < 99) && (Pin(GPIO_MCP39F5_TX) < 99)) {
if (Pin(GPIO_MCP39F5_RST) < 99) {
if (PinUsed(GPIO_MCP39F5_RX) && PinUsed(GPIO_MCP39F5_TX)) {
if (PinUsed(GPIO_MCP39F5_RST)) {
pinMode(Pin(GPIO_MCP39F5_RST), OUTPUT);
digitalWrite(Pin(GPIO_MCP39F5_RST), 0); // MCP disable - Reset Delta Sigma ADC's
}

View File

@ -130,7 +130,7 @@ void PzemAcSnsInit(void)
void PzemAcDrvInit(void)
{
if ((Pin(GPIO_PZEM016_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) {
if (PinUsed(GPIO_PZEM016_RX) && PinUsed(GPIO_PZEM0XX_TX)) {
energy_flg = XNRG_05;
}
}

View File

@ -127,7 +127,7 @@ void PzemDcSnsInit(void)
void PzemDcDrvInit(void)
{
if ((Pin(GPIO_PZEM017_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) {
if (PinUsed(GPIO_PZEM017_RX) && PinUsed(GPIO_PZEM0XX_TX)) {
energy_flg = XNRG_06;
}
}

View File

@ -199,7 +199,7 @@ void Ade7953EnergyEverySecond(void)
void Ade7953DrvInit(void)
{
if (Pin(GPIO_ADE7953_IRQ) < 99) { // Irq on GPIO16 is not supported...
if (PinUsed(GPIO_ADE7953_IRQ)) { // Irq on GPIO16 is not supported...
delay(100); // Need 100mS to init ADE7953
if (I2cSetDevice(ADE7953_ADDR)) {
if (HLW_PREF_PULSE == Settings.energy_power_calibration) {

View File

@ -187,7 +187,7 @@ void Sdm120SnsInit(void)
void Sdm120DrvInit(void)
{
if ((Pin(GPIO_SDM120_RX) < 99) && (Pin(GPIO_SDM120_TX) < 99)) {
if (PinUsed(GPIO_SDM120_RX) && PinUsed(GPIO_SDM120_TX)) {
energy_flg = XNRG_08;
}
}

View File

@ -102,7 +102,7 @@ void Dds2382SnsInit(void)
void Dds2382DrvInit(void)
{
if ((Pin(GPIO_DDS2382_RX) < 99) && (Pin(GPIO_DDS2382_TX) < 99)) {
if (PinUsed(GPIO_DDS2382_RX) && PinUsed(GPIO_DDS2382_TX)) {
energy_flg = XNRG_09;
}
}

View File

@ -186,7 +186,7 @@ void Sdm630SnsInit(void)
void Sdm630DrvInit(void)
{
if ((Pin(GPIO_SDM630_RX) < 99) && (Pin(GPIO_SDM630_TX) < 99)) {
if (PinUsed(GPIO_SDM630_RX) && PinUsed(GPIO_SDM630_TX)) {
energy_flg = XNRG_10;
}
}

View File

@ -144,7 +144,7 @@ void Ddsu666SnsInit(void)
void Ddsu666DrvInit(void)
{
if ((Pin(GPIO_DDSU666_RX) < 99) && (Pin(GPIO_DDSU666_TX) < 99)) {
if (PinUsed(GPIO_DDSU666_RX) && PinUsed(GPIO_DDSU666_TX)) {
energy_flg = XNRG_11;
}
}

View File

@ -419,7 +419,7 @@ void solaxX1SnsInit(void)
void solaxX1DrvInit(void)
{
if ((Pin(GPIO_SOLAXX1_RX) < 99) && (Pin(GPIO_SOLAXX1_TX) < 99)) {
if (PinUsed(GPIO_SOLAXX1_RX) && PinUsed(GPIO_SOLAXX1_TX)) {
energy_flg = XNRG_12;
}
}

View File

@ -224,7 +224,7 @@ void FifLESnsInit(void)
void FifLEDrvInit(void)
{
if ((Pin(GPIO_LE01MR_RX) < 99) && (Pin(GPIO_LE01MR_TX) < 99)) {
if (PinUsed(GPIO_LE01MR_RX) && PinUsed(GPIO_LE01MR_TX)) {
energy_flg = XNRG_13;
}
}

View File

@ -127,7 +127,7 @@ void CounterInit(void)
function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 };
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
if (Pin(GPIO_CNTR1, i) < 99) {
if (PinUsed(GPIO_CNTR1, i)) {
Counter.any_counter = true;
pinMode(Pin(GPIO_CNTR1, i), bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP);
if ((0 == Settings.pulse_counter_debounce_low) && (0 == Settings.pulse_counter_debounce_high)) {
@ -144,7 +144,7 @@ void CounterInit(void)
void CounterEverySecond(void)
{
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
if (Pin(GPIO_CNTR1, i) < 99) {
if (PinUsed(GPIO_CNTR1, i)) {
if (bitRead(Settings.pulse_counter_type, i)) {
uint32_t time = micros() - Counter.timer[i];
if (time > 4200000000) { // 70 minutes
@ -158,7 +158,7 @@ void CounterEverySecond(void)
void CounterSaveState(void)
{
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
if (Pin(GPIO_CNTR1, i) < 99) {
if (PinUsed(GPIO_CNTR1, i)) {
Settings.pulse_counter[i] = RtcSettings.pulse_counter[i];
}
}
@ -169,7 +169,7 @@ void CounterShow(bool json)
bool header = false;
uint8_t dsxflg = 0;
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
if (Pin(GPIO_CNTR1, i) < 99) {
if (PinUsed(GPIO_CNTR1, i)) {
char counter[33];
if (bitRead(Settings.pulse_counter_type, i)) {
dtostrfd((double)RtcSettings.pulse_counter[i] / 1000000, 6, counter);
@ -213,7 +213,7 @@ void CounterShow(bool json)
void CmndCounter(void)
{
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) {
if ((XdrvMailbox.data_len > 0) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) {
if ((XdrvMailbox.data_len > 0) && PinUsed(GPIO_CNTR1, XdrvMailbox.index -1)) {
if ((XdrvMailbox.data[0] == '-') || (XdrvMailbox.data[0] == '+')) {
RtcSettings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload;
Settings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload;
@ -229,7 +229,7 @@ void CmndCounter(void)
void CmndCounterType(void)
{
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && PinUsed(GPIO_CNTR1, XdrvMailbox.index -1)) {
bitWrite(Settings.pulse_counter_type, XdrvMailbox.index -1, XdrvMailbox.payload &1);
RtcSettings.pulse_counter[XdrvMailbox.index -1] = 0;
Settings.pulse_counter[XdrvMailbox.index -1] = 0;

View File

@ -304,10 +304,10 @@ void Ds18x20Init(void)
{
uint64_t ids[DS18X20_MAX_SENSORS];
ds18x20_pin = pin[GPIO_DSB];
ds18x20_pin = Pin(GPIO_DSB);
if (pin[GPIO_DSB_OUT] < 99) {
ds18x20_pin_out = pin[GPIO_DSB_OUT];
if (PinUsed(GPIO_DSB_OUT)) {
ds18x20_pin_out = Pin(GPIO_DSB_OUT);
ds18x20_dual_mode = true; // Dual pins mode as used by Shelly
pinMode(ds18x20_pin_out, OUTPUT);
pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor
@ -518,7 +518,7 @@ bool Xsns05(uint8_t function)
{
bool result = false;
if (pin[GPIO_DSB] < 99) {
if (PinUsed(GPIO_DSB)) {
switch (function) {
case FUNC_INIT:
Ds18x20Init();

View File

@ -204,8 +204,8 @@ bool DhtPinState()
void DhtInit(void)
{
if (dht_sensors) {
if (pin[GPIO_DHT11_OUT] < 99) {
dht_pin_out = pin[GPIO_DHT11_OUT];
if (PinUsed(GPIO_DHT11_OUT)) {
dht_pin_out = Pin(GPIO_DHT11_OUT);
dht_dual_mode = true; // Dual pins mode as used by Shelly
dht_sensors = 1; // We only support one sensor in pseudo mode
pinMode(dht_pin_out, OUTPUT);

View File

@ -159,8 +159,8 @@ bool ShtRead(void)
void ShtDetect(void)
{
sht_sda_pin = pin[GPIO_I2C_SDA];
sht_scl_pin = pin[GPIO_I2C_SCL];
sht_sda_pin = Pin(GPIO_I2C_SDA);
sht_scl_pin = Pin(GPIO_I2C_SCL);
if (ShtRead()) {
sht_type = 1;
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND));

View File

@ -325,8 +325,8 @@ bool MhzCommandSensor(void)
void MhzInit(void)
{
mhz_type = 0;
if ((pin[GPIO_MHZ_RXD] < 99) && (pin[GPIO_MHZ_TXD] < 99)) {
MhzSerial = new TasmotaSerial(pin[GPIO_MHZ_RXD], pin[GPIO_MHZ_TXD], 1);
if (PinUsed(GPIO_MHZ_RXD) && PinUsed(GPIO_MHZ_TXD)) {
MhzSerial = new TasmotaSerial(Pin(GPIO_MHZ_RXD), Pin(GPIO_MHZ_TXD), 1);
if (MhzSerial->begin(9600)) {
if (MhzSerial->hardwareSerial()) { ClaimSerial(); }
mhz_type = 1;

View File

@ -132,8 +132,8 @@ void Senseair250ms(void) // Every 250 mSec
void SenseairInit(void)
{
senseair_type = 0;
if ((pin[GPIO_SAIR_RX] < 99) && (pin[GPIO_SAIR_TX] < 99)) {
SenseairModbus = new TasmotaModbus(pin[GPIO_SAIR_RX], pin[GPIO_SAIR_TX]);
if (PinUsed(GPIO_SAIR_RX) && PinUsed(GPIO_SAIR_TX)) {
SenseairModbus = new TasmotaModbus(Pin(GPIO_SAIR_RX), Pin(GPIO_SAIR_TX));
uint8_t result = SenseairModbus->Begin(SENSEAIR_MODBUS_SPEED);
if (result) {
if (2 == result) { ClaimSerial(); }

View File

@ -171,7 +171,7 @@ bool PmsReadData(void)
bool PmsCommandSensor(void)
{
if ((pin[GPIO_PMS5003_TX] < 99) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) {
if (PinUsed(GPIO_PMS5003_TX) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) {
if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) {
// Set Active Mode if interval is less than 60 seconds
Settings.pms_wake_interval = 0;
@ -239,12 +239,12 @@ void PmsSecond(void) // Every second
void PmsInit(void)
{
Pms.type = 0;
if (pin[GPIO_PMS5003_RX] < 99) {
PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], (pin[GPIO_PMS5003_TX] < 99) ? pin[GPIO_PMS5003_TX] : -1, 1);
if (PinUsed(GPIO_PMS5003_RX)) {
PmsSerial = new TasmotaSerial(Pin(GPIO_PMS5003_RX), (PinUsed(GPIO_PMS5003_TX)) ? Pin(GPIO_PMS5003_TX) : -1, 1);
if (PmsSerial->begin(9600)) {
if (PmsSerial->hardwareSerial()) { ClaimSerial(); }
if (99 == pin[GPIO_PMS5003_TX]) { // setting interval not supported if TX pin not connected
if (99 == Pin(GPIO_PMS5003_TX)) { // setting interval not supported if TX pin not connected
Settings.pms_wake_interval = 0;
Pms.ready = 1;
}

View File

@ -202,8 +202,8 @@ bool NovaSdsCommandSensor(void)
void NovaSdsInit(void)
{
novasds_type = 0;
if (pin[GPIO_SDS0X1_RX] < 99 && pin[GPIO_SDS0X1_TX] < 99) {
NovaSdsSerial = new TasmotaSerial(pin[GPIO_SDS0X1_RX], pin[GPIO_SDS0X1_TX], 1);
if (PinUsed(GPIO_SDS0X1_RX) && PinUsed(GPIO_SDS0X1_TX)) {
NovaSdsSerial = new TasmotaSerial(Pin(GPIO_SDS0X1_RX), Pin(GPIO_SDS0X1_TX), 1);
if (NovaSdsSerial->begin(9600)) {
if (NovaSdsSerial->hardwareSerial()) {
ClaimSerial();

View File

@ -40,10 +40,10 @@ TasmotaSerial* sonar_serial = nullptr;
uint8_t Sr04TModeDetect(void)
{
sr04_type = 0;
if (99 == pin[GPIO_SR04_ECHO]) { return sr04_type; }
if (99 == Pin(GPIO_SR04_ECHO)) { return sr04_type; }
int sr04_echo_pin = pin[GPIO_SR04_ECHO];
int sr04_trig_pin = (pin[GPIO_SR04_TRIG] < 99) ? pin[GPIO_SR04_TRIG] : pin[GPIO_SR04_ECHO]; // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only
int sr04_echo_pin = Pin(GPIO_SR04_ECHO);
int sr04_trig_pin = (PinUsed(GPIO_SR04_TRIG)) ? Pin(GPIO_SR04_TRIG) : Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only
sonar_serial = new TasmotaSerial(sr04_echo_pin, sr04_trig_pin, 1);
if (sonar_serial->begin(9600,1)) {
@ -62,7 +62,7 @@ uint8_t Sr04TModeDetect(void)
delete sonar_serial;
sonar_serial = nullptr;
if (-1 == sr04_trig_pin) {
sr04_trig_pin = pin[GPIO_SR04_ECHO]; // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only
sr04_trig_pin = Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only
}
sonar = new NewPing(sr04_trig_pin, sr04_echo_pin, 300);
} else {
@ -193,7 +193,7 @@ bool Xsns22(uint8_t function)
if (sr04_type) {
switch (function) {
case FUNC_INIT:
result = (pin[GPIO_SR04_ECHO]<99);
result = (PinUsed(GPIO_SR04_ECHO));
break;
case FUNC_EVERY_SECOND:
Sr04TReading();

View File

@ -144,10 +144,10 @@ uint8_t Tm1638GetButtons(void)
void TmInit(void)
{
tm1638_type = 0;
if ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99)) {
tm1638_clock_pin = pin[GPIO_TM16CLK];
tm1638_data_pin = pin[GPIO_TM16DIO];
tm1638_strobe_pin = pin[GPIO_TM16STB];
if (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB)) {
tm1638_clock_pin = Pin(GPIO_TM16CLK);
tm1638_data_pin = Pin(GPIO_TM16DIO);
tm1638_strobe_pin = Pin(GPIO_TM16STB);
pinMode(tm1638_data_pin, OUTPUT);
pinMode(tm1638_clock_pin, OUTPUT);