Merge pull request #13921 from jziolkowski/support_74hc595

Add support for 74x595 shift registers
This commit is contained in:
Theo Arends 2021-12-05 14:16:15 +01:00 committed by GitHub
commit a6bcb38ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 299 additions and 3 deletions

View File

@ -716,6 +716,9 @@
#define D_CMND_BR_RUN ""
#define D_BR_NOT_STARTED "Berry not started"
// Commands xdrv_60_shift595.ino - 74x595 family shift register driver
#define D_CMND_SHIFT595_DEVICE_COUNT "Shift595DeviceCount"
// Commands xsns_02_analog.ino
#define D_CMND_ADCPARAM "AdcParam"

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "te laag"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pomptyd oorskry"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_AF_AF_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "твърде ниско"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "превишено време за помпане"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_BG_BG_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_CS_CZ_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "zu niedrig"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "Pumpzeit überschritten"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_DE_DE_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_EL_GR_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_EN_GB_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "muy bajo"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "tiempo de bomba excedido"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_ES_ES_H_

View File

@ -1082,4 +1082,10 @@
#define D_NEOPOOL_PH_LOW "Trop bas"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "durée pompage expirée"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_FR_FR_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_FY_NL_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_HE_HE_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_HU_HU_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "troppo basso"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "tempo pompa superato"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_IT_IT_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_KO_KO_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "te laag"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pomptijd bereikt"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_NL_NL_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "czas pompowania przekroczony"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_PL_PL_D_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "Muito baixo"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "tempo da bomba excedido"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_PT_BR_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "Muito baixo"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "tempo da bomba excedido"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_PT_PT_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_RO_RO_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_RU_RU_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_SK_SK_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_SV_SE_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_TR_TR_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_UK_UA_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_VI_VN_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_ZH_CN_H_

View File

@ -1083,4 +1083,10 @@
#define D_NEOPOOL_PH_LOW "too low"
#define D_NEOPOOL_PUMP_TIME_EXCEEDED "pump time exceeded"
// xdrv_60_shift595.ino
#define D_GPIO_SHIFT595_SRCLK "74x595 SRCLK"
#define D_GPIO_SHIFT595_RCLK "74x595 RCLK"
#define D_GPIO_SHIFT595_OE "74x595 OE"
#define D_GPIO_SHIFT595_SER "74x595 SER"
#endif // _LANGUAGE_ZH_TW_H_

View File

@ -893,6 +893,10 @@
// -- Other sensors/drivers -----------------------
// #define USE_SHIFT595
#define SHIFT595_INVERT_OUTPUTS false // [SetOption133] Don't invert outputs of 74x595 shift register
#define SHIFT595_DEVICE_COUNT 1 // [Shift595DeviceCount] Set the number of connected 74x595 shift registers
//#define USE_TM1638 // Add support for TM1638 switches copying Switch1 .. Switch8 (+1k code)
//#define USE_HX711 // Add support for HX711 load cell (+1k5 code)
// #define USE_HX711_GUI // Add optional web GUI to HX711 as scale (+1k8 code)

View File

@ -162,7 +162,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t show_heap_with_timestamp : 1; // bit 16 (v9.5.0.9) - SetOption130 - (Debug) Show heap with logging timestamp
uint32_t tuya_allow_dimmer_0 : 1; // bit 17 (v10.0.0.3) - SetOption131 - (Tuya) Allow save dimmer = 0 receved by MCU
uint32_t tls_use_fingerprint : 1; // bit 18 (v10.0.0.4) - SetOption132 - (TLS) use fingerprint validation instead of CA based
uint32_t shift595_option : 1; // bit 19 (v10.0.0.4) - SetOption133 - (595)
uint32_t shift595_invert_outputs : 1; // bit 19 (v10.0.0.4) - SetOption133 - (Shift595) invert outputs of 74x595 shift registers
uint32_t spare20 : 1; // bit 20
uint32_t spare21 : 1; // bit 21
uint32_t spare22 : 1; // bit 22
@ -688,7 +688,7 @@ typedef struct {
uint8_t free_ea6[32]; // EA6
uint8_t shift595; // EC6
uint8_t shift595_device_count; // EC6
uint8_t sta_config; // EC7
uint8_t sta_active; // EC8
uint8_t rule_stop; // EC9

View File

@ -1196,6 +1196,9 @@ void SettingsDefaultSet2(void) {
flag4.mqtt_tls |= MQTT_TLS_ENABLED;
flag4.mqtt_no_retain |= MQTT_NO_RETAIN;
flag5.shift595_invert_outputs |= SHIFT595_INVERT_OUTPUTS;
Settings->shift595_device_count = SHIFT595_DEVICE_COUNT;
Settings->flag = flag;
Settings->flag2 = flag2;
Settings->flag3 = flag3;

View File

@ -176,6 +176,7 @@ enum UserSelectablePins {
GPIO_BL0942_RX, // BL0942 Serial interface
GPIO_HM330X_SET, // HM330X SET pin (sleep when low)
GPIO_HEARTBEAT, GPIO_HEARTBEAT_INV,
GPIO_SHIFT595_SRCLK, GPIO_SHIFT595_RCLK, GPIO_SHIFT595_OE, GPIO_SHIFT595_SER, // 74x595 Shift register
GPIO_SENSOR_END };
enum ProgramSelectablePins {
@ -372,7 +373,9 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_BL0942_RX "|"
D_SENSOR_HM330X_SET "|"
D_SENSOR_HEARTBEAT "|" D_SENSOR_HEARTBEAT "_i|"
;
D_GPIO_SHIFT595_SRCLK "|" D_GPIO_SHIFT595_RCLK "|" D_GPIO_SHIFT595_OE "|" D_GPIO_SHIFT595_SER "|"
;
const char kSensorNamesFixed[] PROGMEM =
D_SENSOR_USER;
@ -930,6 +933,13 @@ const uint16_t kGpioNiceList[] PROGMEM = {
AGPIO(GPIO_ADC_JOY) + MAX_ADCS, // Joystick
AGPIO(GPIO_ADC_PH) + MAX_ADCS, // Analog PH Sensor
#endif // ESP32
#ifdef USE_SHIFT595
AGPIO(GPIO_SHIFT595_SRCLK), // 74x595 shift register
AGPIO(GPIO_SHIFT595_RCLK),
AGPIO(GPIO_SHIFT595_OE),
AGPIO(GPIO_SHIFT595_SER),
#endif
};
/*-------------------------------------------------------------------------------------------*\

View File

@ -0,0 +1,120 @@
/*
xdrv_60_shift595.ino - 74x595 shift register family support for Tasmota
Copyright (C) 2021 Jacek Ziółkowski
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_SHIFT595
#define XDRV_60 60
const char kShift595Commands[] PROGMEM = "|" D_CMND_SHIFT595_DEVICE_COUNT ;
void (* const Shift595Command[])(void) PROGMEM = { &CmndShift595Devices };
struct Shift595 {
uint8_t pinSRCLK;
uint8_t pinRCLK;
uint8_t pinSER;
uint8_t pinOE;
uint8_t outputs;
uint8_t first;
bool connected = false;
} *Shift595 = nullptr;
void Shift595ConfigurePin(uint8_t pin, uint8_t value = 0){
pinMode(pin, OUTPUT);
digitalWrite(pin, value);
}
void Shift595Init(void)
{
if (PinUsed(GPIO_SHIFT595_SRCLK) && PinUsed(GPIO_SHIFT595_RCLK) && PinUsed(GPIO_SHIFT595_SER)) {
Shift595 = (struct Shift595*)calloc(1, sizeof(struct Shift595));
Shift595->pinSRCLK = Pin(GPIO_SHIFT595_SRCLK);
Shift595->pinRCLK = Pin(GPIO_SHIFT595_RCLK);
Shift595->pinSER = Pin(GPIO_SHIFT595_SER);
Shift595ConfigurePin(Shift595->pinSRCLK);
Shift595ConfigurePin(Shift595->pinRCLK);
Shift595ConfigurePin(Shift595->pinSER);
if (PinUsed(GPIO_SHIFT595_OE)) {
Shift595->pinOE = Pin(GPIO_SHIFT595_OE);
Shift595ConfigurePin(Shift595->pinOE, 1);
}
Shift595->first = TasmotaGlobal.devices_present;
Shift595->outputs = Settings->shift595_device_count * 8;
TasmotaGlobal.devices_present += Shift595->outputs;
Shift595->connected = true;
AddLog(LOG_LEVEL_DEBUG, PSTR("595: Controlling relays POWER%d to POWER%d"), Shift595->first + 1, Shift595->first + Shift595->outputs);
}
}
void Shift595LatchPin(uint8_t pin) {
digitalWrite(pin, 1);
digitalWrite(pin, 0);
}
void Shift595SwitchRelay(void)
{
if (Shift595 && Shift595->connected == true) {
for (uint32_t i = 0; i < Shift595->outputs; i++) {
uint8_t relay_state = bitRead(XdrvMailbox.index, Shift595->first + Shift595->outputs -1 -i);
digitalWrite(Shift595->pinSER, Settings->flag5.shift595_invert_outputs ? !relay_state : relay_state);
Shift595LatchPin(Shift595->pinSRCLK);
}
Shift595LatchPin(Shift595->pinRCLK);
if (PinUsed(GPIO_SHIFT595_OE)) {
digitalWrite(Shift595->pinOE, 0);
}
}
}
void CmndShift595Devices(void) {
if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= 3)) {
Settings->shift595_device_count = (1 == XdrvMailbox.payload) ? SHIFT595_DEVICE_COUNT : XdrvMailbox.payload;
TasmotaGlobal.restart_flag = 2;
}
ResponseCmndNumber(Settings->shift595_device_count);
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xdrv60(uint8_t function)
{
bool result = false;
if (FUNC_PRE_INIT == function) {
Shift595Init();
} else if (Shift595) {
switch (function) {
case FUNC_SET_POWER:
Shift595SwitchRelay();
break;
case FUNC_COMMAND:
result = DecodeCommand(kShift595Commands, Shift595Command);
break;
}
}
return result;
}
#endif // USE_SHIFT595