Added support for Dingtian Relay Board v3.6.10 (#18535)

* Added support for Dingtian Relay Board v3.6.10

* Output OE was never initialized

* Removed white spaces trying to fix language builds

* Fix for https://github.com/arendst/Tasmota/pull/18535#pullrequestreview-1406978097

* Fixed language builds

---------

Co-authored-by: JeroenSt <nospam@nospam.org>
This commit is contained in:
Jeroen 2023-05-01 14:51:02 +02:00 committed by GitHub
parent c5612a50fb
commit 616652ea22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 59 additions and 19 deletions

View File

@ -210,6 +210,7 @@ enum UserSelectablePins {
GPIO_PCF8574_INT, // PCF8574 interrupt
GPIO_LOX_O2_RX, // LOX-O2 RX
GPIO_GM861_TX, GPIO_GM861_RX, // GM861 Serial interface
GPIO_DINGTIAN_OE, // New version of Dingtian relay board where PL is not shared with OE
GPIO_SENSOR_END };
// Error as warning to rethink GPIO usage with max 2045
@ -467,6 +468,7 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_PCF8574_INT "|"
D_SENSOR_LOX_O2_RX "|"
D_SENSOR_GM861_TX "|" D_SENSOR_GM861_RX "|"
D_GPIO_DINGTIAN_OE "|"
;
const char kSensorNamesFixed[] PROGMEM =
@ -1121,6 +1123,7 @@ const uint16_t kGpioNiceList[] PROGMEM = {
AGPIO(GPIO_DINGTIAN_SDI),
AGPIO(GPIO_DINGTIAN_Q7),
AGPIO(GPIO_DINGTIAN_PL),
AGPIO(GPIO_DINGTIAN_OE),
AGPIO(GPIO_DINGTIAN_RCK),
#endif

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCk"
#define D_SENSOR_CM11_TX "CM110x Tx"
#define D_SENSOR_CM11_RX "CM110x Rx"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian - SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian - Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian - PL"
#define D_GPIO_DINGTIAN_OE "Dingtian - OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian - RCK"
#define D_SENSOR_CM11_TX "CM110x - TX"
#define D_SENSOR_CM11_RX "CM110x - RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -919,6 +919,7 @@
#define D_GPIO_DINGTIAN_SDI "Dingtian SDI"
#define D_GPIO_DINGTIAN_Q7 "Dingtian Q7"
#define D_GPIO_DINGTIAN_PL "Dingtian PL"
#define D_GPIO_DINGTIAN_OE "Dingtian OE"
#define D_GPIO_DINGTIAN_RCK "Dingtian RCK"
#define D_SENSOR_CM11_TX "CM110x TX"
#define D_SENSOR_CM11_RX "CM110x RX"

View File

@ -30,6 +30,9 @@
#error DINGTIAN - Only one of DINGTIAN_USE_AS_BUTTON or DINGTIAN_USE_AS_SWITCH should be defined
#endif
#define DINGTIAN_SET_OUTPUT(pin,value) { pinMode((pin), OUTPUT); digitalWrite((pin), (value)); }
#define DINGTIAN_SET_INPUT(pin) { pinMode((pin), INPUT); }
/********************************************************************************************************
* Global private data
*/
@ -40,8 +43,9 @@ struct DINGTIAN_DATA {
uint8_t count; // number of relay and input (8 * numver of shift registers)
uint8_t first; // index of 1st Tasmota relay assigned to 1st Dingtian relays
int8_t key_offset; // index of virtual key
bool outputs_initialized; // set when the outputs are initialized
// pins
uint8_t pin_clk, pin_sdi, pin_q7, pin_pl, pin_rck;
uint8_t pin_clk, pin_sdi, pin_q7, pin_pl, pin_oe, pin_rck;
} *Dingtian = nullptr;
@ -56,7 +60,7 @@ uint32_t DingtianReadWrite(uint32_t outputs)
// setup
digitalWrite(Dingtian->pin_rck, 0); // rclk and clkinh to 0
digitalWrite(Dingtian->pin_pl, 1); // load inputs in '165, ready for shift-in (side effect '595 in tri-state)
if (PinUsed(GPIO_DINGTIAN_PL)) digitalWrite(Dingtian->pin_pl, 1); // load inputs in '165, ready for shift-in (side effect '595 in tri-state)
for ( int i = Dingtian->count ; i > 0 ; i-- ) {
// relay out to '595
digitalWrite(Dingtian->pin_sdi, outputs & 1);
@ -70,7 +74,13 @@ uint32_t DingtianReadWrite(uint32_t outputs)
}
// ending
digitalWrite(Dingtian->pin_rck, 1); // rclk pulse to load '595 into output registers
digitalWrite(Dingtian->pin_pl, 0); // re-enable '595 ouputs
if (PinUsed(GPIO_DINGTIAN_PL)) digitalWrite(Dingtian->pin_pl, 0); // re-enable '595 ouputs (old board version)
if (!Dingtian->outputs_initialized && PinUsed(GPIO_DINGTIAN_OE))
{
digitalWrite(Dingtian->pin_oe, 0); // enable '595 ouputs (new board version)
DINGTIAN_SET_OUTPUT(Dingtian->pin_oe, 0);
Dingtian->outputs_initialized = true;
}
#ifdef DINGTIAN_INPUTS_INVERTED
return ~inputs;
@ -83,12 +93,9 @@ uint32_t DingtianReadWrite(uint32_t outputs)
* Driver initialisation
*/
#define DINGTIAN_SET_OUTPUT(pin,value) { pinMode((pin), OUTPUT); digitalWrite((pin), (value)); }
#define DINGTIAN_SET_INPUT(pin) { pinMode((pin), INPUT); }
void DingtianInit(void) {
if (PinUsed(GPIO_DINGTIAN_CLK, GPIO_ANY) && PinUsed(GPIO_DINGTIAN_SDI) && PinUsed(GPIO_DINGTIAN_Q7)
&& PinUsed(GPIO_DINGTIAN_PL) && PinUsed(GPIO_DINGTIAN_RCK)) {
&& (PinUsed(GPIO_DINGTIAN_PL) || PinUsed(GPIO_DINGTIAN_OE)) && PinUsed(GPIO_DINGTIAN_RCK)) {
// allocate Dingtian data structure
Dingtian = (struct DINGTIAN_DATA*)calloc(1, sizeof(struct DINGTIAN_DATA));
if (Dingtian) {
@ -96,20 +103,23 @@ void DingtianInit(void) {
Dingtian->pin_clk = Pin(GPIO_DINGTIAN_CLK, GPIO_ANY); // shift clock : 595's SCLK & 165's CLK
Dingtian->pin_sdi = Pin(GPIO_DINGTIAN_SDI); // Serial out : 595's SER
Dingtian->pin_q7 = Pin(GPIO_DINGTIAN_Q7); // Serial in : 165's Q7
Dingtian->pin_pl = Pin(GPIO_DINGTIAN_PL); // Input load : 595's nOE & 165's PL (or SH/LD on some datasheet)
if (PinUsed(GPIO_DINGTIAN_PL)) Dingtian->pin_pl = Pin(GPIO_DINGTIAN_PL); // Input load : 595's nOE & 165's PL (or SH/LD on some datasheet)
if (PinUsed(GPIO_DINGTIAN_OE)) Dingtian->pin_oe = Pin(GPIO_DINGTIAN_OE); // Output enable : 595's nOE (v3.6.10)
Dingtian->pin_rck = Pin(GPIO_DINGTIAN_RCK); // Output load : 595's RCLK & 165's CLKINH
// number of shift registers is the CLK index
Dingtian->count = ((GetPin(Dingtian->pin_clk) - AGPIO(GPIO_DINGTIAN_CLK)) + 1) * 8;
AddLog(LOG_LEVEL_DEBUG, PSTR("DNGT: clk:%d, sdi:%d, q7:%d, pl:%d, rck:%d, count:%d"),
Dingtian->pin_clk, Dingtian->pin_sdi, Dingtian->pin_q7, Dingtian->pin_pl, Dingtian->pin_rck, Dingtian->count);
AddLog(LOG_LEVEL_DEBUG, PSTR("DNGT: clk:%d, sdi:%d, q7:%d, pl:%d, oe:%d, rck:%d, count:%d"),
Dingtian->pin_clk, Dingtian->pin_sdi, Dingtian->pin_q7, Dingtian->pin_pl, Dingtian->pin_oe, Dingtian->pin_rck, Dingtian->count);
DINGTIAN_SET_OUTPUT(Dingtian->pin_clk, 0);
DINGTIAN_SET_OUTPUT(Dingtian->pin_sdi, 0);
DINGTIAN_SET_INPUT( Dingtian->pin_q7);
DINGTIAN_SET_OUTPUT(Dingtian->pin_pl, 0);
//Do not initialize Dingtian->pin_oe so the relays will not toggle while restarting
DINGTIAN_SET_OUTPUT(Dingtian->pin_rck, 0);
Dingtian->outputs_initialized = false;
Dingtian->first = TasmotaGlobal.devices_present;
Dingtian->key_offset = -1;
UpdateDevicesPresent(Dingtian->count);