mirror of https://github.com/arendst/Tasmota.git
Merge pull request #2 from kueblc/sm16716
Final fixes, cleanup, and optimizations
This commit is contained in:
commit
3d13490736
|
@ -417,7 +417,7 @@
|
|||
// #define USE_THEO_V2 // Add support for decoding Theo V2 sensors as documented on https://sidweb.nl using 434MHz RF sensor receiver (+1k4 code)
|
||||
// #define USE_ALECTO_V2 // Add support for decoding Alecto V2 sensors like ACH2010, WS3000 and DKW2012 weather stations using 868MHz RF sensor receiver (+1k7 code)
|
||||
|
||||
#define USE_SM16716 // Add support for SM16716 RGB LED controller
|
||||
#define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code)
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Debug features are only supported in development branch
|
||||
|
|
|
@ -168,6 +168,8 @@ typedef unsigned long power_t; // Power (Relay) type
|
|||
#define NEO_RGBW 5 // Neopixel RGBW leds
|
||||
#define NEO_GRBW 6 // Neopixel GRBW leds
|
||||
|
||||
#define LT_SM16716 16 // Lights that use SM16716 will have this bit set in light_type
|
||||
|
||||
#define MQTT_PUBSUBCLIENT 1 // Mqtt PubSubClient library
|
||||
#define MQTT_TASMOTAMQTT 2 // Mqtt TasmotaMqtt library based on esp-mqtt-arduino - soon obsolete
|
||||
#define MQTT_ESPMQTTARDUINO 3 // Mqtt esp-mqtt-arduino library by Ingo Randolf - obsolete but define is present for debugging purposes
|
||||
|
|
|
@ -2425,7 +2425,7 @@ void GpioInit(void)
|
|||
#ifdef USE_SM16716
|
||||
if (SM16716_ModuleSelected()) {
|
||||
light_type += 3;
|
||||
light_type |= 16;
|
||||
light_type |= LT_SM16716;
|
||||
}
|
||||
#endif // ifdef USE_SM16716
|
||||
if (!light_type) {
|
||||
|
|
|
@ -1827,6 +1827,7 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
|
|||
0, 0, 0
|
||||
},
|
||||
{ "SYF05", // Sunyesmart SYF05 (a.k.a. Fcmila) = TYWE3S + SM16726
|
||||
// Also works with Merkury 904 RGBW Bulbs with 13 set to GPIO_SM16716_SEL
|
||||
// https://www.flipkart.com/fc-mila-bxav-xs-ad-smart-bulb/p/itmf85zgs45fzr7n
|
||||
// https://docs.tuya.com/en/hardware/WiFi-module/wifi-e3s-module.html
|
||||
// http://www.datasheet-pdf.com/PDF/SM16716-Datasheet-Sunmoon-932771
|
||||
|
@ -1834,17 +1835,17 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
|
|||
0,
|
||||
GPIO_USER, // GPIO02 N.C.
|
||||
0,
|
||||
GPIO_SM16716_CLK, // GPIO04
|
||||
GPIO_PWM1, // GPIO05 Cold White
|
||||
GPIO_SM16716_CLK, // GPIO04 SM16716 Clock
|
||||
GPIO_PWM1, // GPIO05 White
|
||||
// GPIO06
|
||||
// GPIO07
|
||||
// GPIO08
|
||||
0, // GPIO09
|
||||
0, // GPIO10
|
||||
// GPIO11
|
||||
GPIO_PWM2, // GPIO12 Warm White
|
||||
GPIO_SM16716_SEL, // GPIO13
|
||||
GPIO_SM16716_DAT, // GPIO14
|
||||
GPIO_USER, // GPIO12 Alt. White on some devices
|
||||
GPIO_USER, // GPIO13 SM16716 Select on some devices
|
||||
GPIO_SM16716_DAT, // GPIO14 SM16716 Data
|
||||
0, // GPIO15 wired to GND
|
||||
GPIO_USER, // GPIO16 N.C.
|
||||
GPIO_FLAG_ADC0 // ADC0 A0 Analog input
|
||||
|
|
|
@ -367,11 +367,12 @@ void LightMy92x1Duty(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b, uint8_t dut
|
|||
\*********************************************************************************************/
|
||||
|
||||
// Enable this for debug logging
|
||||
#define D_LOG_SM16716 "SM16716: "
|
||||
//#define D_LOG_SM16716 "SM16716: "
|
||||
|
||||
uint8_t sm16716_pin_clk = 100;
|
||||
uint8_t sm16716_pin_dat = 100;
|
||||
uint8_t sm16716_pin_sel = 100;
|
||||
uint8_t sm16716_enabled = 0;
|
||||
|
||||
void SM16716_SendBit(uint8_t v)
|
||||
{
|
||||
|
@ -399,19 +400,25 @@ void SM16716_SendByte(uint8_t v)
|
|||
void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b)
|
||||
{
|
||||
if (sm16716_pin_sel < 99) {
|
||||
if (duty_r | duty_g | duty_b) {
|
||||
uint8_t sm16716_should_enable = (duty_r | duty_g | duty_b);
|
||||
if (!sm16716_enabled && sm16716_should_enable) {
|
||||
#ifdef D_LOG_SM16716
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SM16716 "turning color on"));
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
#endif // D_LOG_SM16716
|
||||
sm16716_enabled = 1;
|
||||
digitalWrite(sm16716_pin_sel, HIGH);
|
||||
delayMicroseconds(20);
|
||||
// in testing I found it takes a minimum of ~380us to wake up the chip
|
||||
// tested on a Merkury RGBW with an SM726EB
|
||||
delayMicroseconds(400);
|
||||
SM16716_Init();
|
||||
} else {
|
||||
}
|
||||
else if (sm16716_enabled && !sm16716_should_enable) {
|
||||
#ifdef D_LOG_SM16716
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SM16716 "turning color off"));
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
#endif // D_LOG_SM16716
|
||||
sm16716_enabled = 0;
|
||||
digitalWrite(sm16716_pin_sel, LOW);
|
||||
}
|
||||
}
|
||||
|
@ -510,7 +517,7 @@ void LightInit(void)
|
|||
}
|
||||
#endif // USE_WS2812 ************************************************************************
|
||||
#ifdef USE_SM16716
|
||||
else if (16 & light_type) {
|
||||
else if (LT_SM16716 == light_type - light_subtype) {
|
||||
// init PWM
|
||||
for (uint8_t i = 0; i < light_subtype; i++) {
|
||||
Settings.pwm_value[i] = 0; // Disable direct PWM control
|
||||
|
@ -528,9 +535,11 @@ void LightInit(void)
|
|||
if (sm16716_pin_sel < 99) {
|
||||
pinMode(sm16716_pin_sel, OUTPUT);
|
||||
digitalWrite(sm16716_pin_sel, LOW);
|
||||
// no need to call SM16716_Init here, it will be called after sel goes HIGH
|
||||
} else {
|
||||
// no sel pin means you have an 'always on' chip, so init right away
|
||||
SM16716_Init();
|
||||
}
|
||||
|
||||
SM16716_Init();
|
||||
}
|
||||
#endif // ifdef USE_SM16716
|
||||
else {
|
||||
|
@ -976,7 +985,8 @@ void LightAnimate(void)
|
|||
}
|
||||
#endif // USE_ES2812 ************************************************************************
|
||||
#ifdef USE_SM16716
|
||||
else if (16 & light_type) {
|
||||
else if (LT_SM16716 == light_type - light_subtype) {
|
||||
// handle any PWM pins, skipping the first 3 values for sm16716
|
||||
for (uint8_t i = 3; i < light_subtype; i++) {
|
||||
if (pin[GPIO_PWM1 +i-3] < 99) {
|
||||
if (cur_col[i] > 0xFC) {
|
||||
|
@ -988,6 +998,7 @@ void LightAnimate(void)
|
|||
analogWrite(pin[GPIO_PWM1 +i-3], bitRead(pwm_inverted, i-3) ? Settings.pwm_range - curcol : curcol);
|
||||
}
|
||||
}
|
||||
// handle sm16716 update
|
||||
SM16716_Update(cur_col[0], cur_col[1], cur_col[2]);
|
||||
}
|
||||
#endif // ifdef USE_SM16716
|
||||
|
|
Loading…
Reference in New Issue