mirror of https://github.com/arendst/Tasmota.git
Change pin handling part 2
This commit is contained in:
parent
5d9be9a4d0
commit
24280bcdea
|
@ -1073,6 +1073,10 @@ int ResponseJsonEndEnd(void)
|
|||
* GPIO Module and Template management
|
||||
\*********************************************************************************************/
|
||||
|
||||
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception
|
||||
uint32_t Pin(uint32_t gpio, uint32_t index) ICACHE_RAM_ATTR;
|
||||
#endif
|
||||
|
||||
uint32_t Pin(uint32_t gpio, uint32_t index = 0);
|
||||
uint32_t Pin(uint32_t gpio, uint32_t index) {
|
||||
//#ifdef ESP8266
|
||||
|
|
|
@ -1573,7 +1573,8 @@ chknext:
|
|||
}
|
||||
if (!strncmp(vname,"pn[",3)) {
|
||||
GetNumericResult(vname+3,OPER_EQU,&fvar,0);
|
||||
fvar=pin[(uint8_t)fvar];
|
||||
// fvar=pin[(uint8_t)fvar];
|
||||
fvar=Pin(fvar);
|
||||
// skip ] bracket
|
||||
len++;
|
||||
goto exit;
|
||||
|
@ -1582,7 +1583,8 @@ chknext:
|
|||
GetNumericResult(vname+3,OPER_EQU,&fvar,0);
|
||||
uint8_t gpiopin=fvar;
|
||||
for (uint8_t i=0;i<GPIO_SENSOR_END;i++) {
|
||||
if (pin[i]==gpiopin) {
|
||||
// if (pin[i]==gpiopin) {
|
||||
if (Pin(i)==gpiopin) {
|
||||
fvar=i;
|
||||
// skip ] bracket
|
||||
len++;
|
||||
|
|
|
@ -71,8 +71,8 @@ void SSD1306InitDriver(void)
|
|||
}
|
||||
|
||||
uint8_t reset_pin = -1;
|
||||
if (pin[GPIO_OLED_RESET] < 99) {
|
||||
reset_pin = pin[GPIO_OLED_RESET];
|
||||
if (Pin(GPIO_OLED_RESET) < 99) {
|
||||
reset_pin = Pin(GPIO_OLED_RESET);
|
||||
}
|
||||
|
||||
// allocate screen buffer
|
||||
|
|
|
@ -90,7 +90,7 @@ void Ili9341InitDriver(void)
|
|||
if (Settings.display_height != ILI9341_TFTHEIGHT) {
|
||||
Settings.display_height = ILI9341_TFTHEIGHT;
|
||||
}
|
||||
tft = new Adafruit_ILI9341(pin[GPIO_SPI_CS], pin[GPIO_SPI_DC]);
|
||||
tft = new Adafruit_ILI9341(Pin(GPIO_SPI_CS), Pin(GPIO_SPI_DC));
|
||||
tft->begin();
|
||||
|
||||
#ifdef USE_DISPLAY_MODES1TO5
|
||||
|
@ -128,9 +128,9 @@ void Ili9341DisplayOnOff(uint8_t on)
|
|||
{
|
||||
// tft->showDisplay(on);
|
||||
// tft->invertDisplay(on);
|
||||
if (pin[GPIO_BACKLIGHT] < 99) {
|
||||
pinMode(pin[GPIO_BACKLIGHT], OUTPUT);
|
||||
digitalWrite(pin[GPIO_BACKLIGHT], on);
|
||||
if (Pin(GPIO_BACKLIGHT) < 99) {
|
||||
pinMode(Pin(GPIO_BACKLIGHT), OUTPUT);
|
||||
digitalWrite(Pin(GPIO_BACKLIGHT), on);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,13 +67,13 @@ 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)) {
|
||||
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]);
|
||||
if ((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CLK) < 99) && (Pin(GPIO_SPI_MOSI) < 99)) {
|
||||
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)) {
|
||||
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 if ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && (Pin(GPIO_SSPI_MOSI) < 99)) {
|
||||
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 {
|
||||
free(buffer);
|
||||
return;
|
||||
|
|
|
@ -65,15 +65,15 @@ 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)) {
|
||||
epd42->Begin(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_SCLK]);
|
||||
if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)) {
|
||||
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)) {
|
||||
epd42->Begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_CLK]);
|
||||
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) {
|
||||
epd42->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK));
|
||||
} else {
|
||||
free(buffer);
|
||||
return;
|
||||
|
|
|
@ -80,16 +80,16 @@ void ILI9488_InitDriver()
|
|||
bg_color = ILI9488_BLACK;
|
||||
|
||||
uint8_t bppin=BACKPLANE_PIN;
|
||||
if (pin[GPIO_BACKLIGHT]<99) {
|
||||
bppin=pin[GPIO_BACKLIGHT];
|
||||
if (Pin(GPIO_BACKLIGHT)<99) {
|
||||
bppin=Pin(GPIO_BACKLIGHT);
|
||||
}
|
||||
|
||||
// init renderer
|
||||
if ((pin[GPIO_SSPI_CS]<99) && (pin[GPIO_SSPI_MOSI]<99) && (pin[GPIO_SSPI_SCLK]<99)){
|
||||
ili9488 = new ILI9488(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_SCLK],bppin);
|
||||
if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){
|
||||
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)) {
|
||||
ili9488 = new ILI9488(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_CLK],bppin);
|
||||
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) {
|
||||
ili9488 = new ILI9488(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK),bppin);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -60,11 +60,11 @@ 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)){
|
||||
ssd1351 = new SSD1351(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_SCLK]);
|
||||
if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){
|
||||
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)){
|
||||
ssd1351 = new SSD1351(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_CLK]);
|
||||
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) {
|
||||
ssd1351 = new SSD1351(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -72,11 +72,11 @@ 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)) {
|
||||
ra8876 = new RA8876(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_MISO],pin[GPIO_SSPI_SCLK],pin[GPIO_BACKLIGHT]);
|
||||
if ((Pin(GPIO_SSPI_CS)<99) && (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)) {
|
||||
ra8876 = new RA8876(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_MISO],pin[GPIO_SPI_CLK],pin[GPIO_BACKLIGHT]);
|
||||
if ((Pin(GPIO_SPI_CS)<99) && (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;
|
||||
}
|
||||
|
|
|
@ -449,10 +449,10 @@ void Ws2812ShowScheme(void)
|
|||
|
||||
void Ws2812ModuleSelected(void)
|
||||
{
|
||||
if (pin[GPIO_WS2812] < 99) { // RGB led
|
||||
if (Pin(GPIO_WS2812) < 99) { // 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]);
|
||||
strip = new NeoPixelBus<selectedNeoFeatureType, selectedNeoSpeedType>(WS2812_MAX_LEDS, Pin(GPIO_WS2812));
|
||||
strip->Begin();
|
||||
|
||||
Ws2812Clear();
|
||||
|
|
|
@ -115,9 +115,9 @@ bool My92x1SetChannels(void)
|
|||
|
||||
void My92x1ModuleSelected(void)
|
||||
{
|
||||
if ((pin[GPIO_DCKI] < 99) && (pin[GPIO_DI] < 99)) {
|
||||
My92x1.pdi_pin = pin[GPIO_DI];
|
||||
My92x1.pdcki_pin = pin[GPIO_DCKI];
|
||||
if ((Pin(GPIO_DCKI) < 99) && (Pin(GPIO_DI) < 99)) {
|
||||
My92x1.pdi_pin = Pin(GPIO_DI);
|
||||
My92x1.pdcki_pin = Pin(GPIO_DCKI);
|
||||
|
||||
pinMode(My92x1.pdi_pin, OUTPUT);
|
||||
pinMode(My92x1.pdcki_pin, OUTPUT);
|
||||
|
|
|
@ -100,9 +100,9 @@ void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b)
|
|||
/*
|
||||
bool SM16716_ModuleSelected(void)
|
||||
{
|
||||
Sm16716.pin_clk = pin[GPIO_SM16716_CLK];
|
||||
Sm16716.pin_dat = pin[GPIO_SM16716_DAT];
|
||||
Sm16716.pin_sel = pin[GPIO_SM16716_SEL];
|
||||
Sm16716.pin_clk = Pin(GPIO_SM16716_CLK);
|
||||
Sm16716.pin_dat = Pin(GPIO_SM16716_DAT);
|
||||
Sm16716.pin_sel = Pin(GPIO_SM16716_SEL);
|
||||
DEBUG_DRIVER_LOG(PSTR(D_LOG_SM16716 "ModuleSelected; clk_pin=%d, dat_pin=%d)"), Sm16716.pin_clk, Sm16716.pin_dat);
|
||||
return (Sm16716.pin_clk < 99) && (Sm16716.pin_dat < 99);
|
||||
}
|
||||
|
@ -122,9 +122,9 @@ 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 (Pin(GPIO_PWM1, i-3) < 99) {
|
||||
//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]);
|
||||
analogWrite(Pin(GPIO_PWM1, i-3), bitRead(pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -138,17 +138,17 @@ bool Sm16716SetChannels(void)
|
|||
|
||||
void Sm16716ModuleSelected(void)
|
||||
{
|
||||
if ((pin[GPIO_SM16716_CLK] < 99) && (pin[GPIO_SM16716_DAT] < 99)) {
|
||||
Sm16716.pin_clk = pin[GPIO_SM16716_CLK];
|
||||
Sm16716.pin_dat = pin[GPIO_SM16716_DAT];
|
||||
Sm16716.pin_sel = pin[GPIO_SM16716_SEL];
|
||||
if ((Pin(GPIO_SM16716_CLK) < 99) && (Pin(GPIO_SM16716_DAT) < 99)) {
|
||||
Sm16716.pin_clk = Pin(GPIO_SM16716_CLK);
|
||||
Sm16716.pin_dat = Pin(GPIO_SM16716_DAT);
|
||||
Sm16716.pin_sel = Pin(GPIO_SM16716_SEL);
|
||||
|
||||
/*
|
||||
// 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) {
|
||||
pinMode(pin[GPIO_PWM1 +i], OUTPUT);
|
||||
if (Pin(GPIO_PWM1, i) < 99) {
|
||||
pinMode(Pin(GPIO_PWM1, i), OUTPUT);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -134,9 +134,9 @@ bool Sm2135SetChannels(void)
|
|||
|
||||
void Sm2135ModuleSelected(void)
|
||||
{
|
||||
if ((pin[GPIO_SM2135_CLK] < 99) && (pin[GPIO_SM2135_DAT] < 99)) {
|
||||
Sm2135.clk = pin[GPIO_SM2135_CLK];
|
||||
Sm2135.data = pin[GPIO_SM2135_DAT];
|
||||
if ((Pin(GPIO_SM2135_CLK) < 99) && (Pin(GPIO_SM2135_DAT) < 99)) {
|
||||
Sm2135.clk = Pin(GPIO_SM2135_CLK);
|
||||
Sm2135.data = Pin(GPIO_SM2135_DAT);
|
||||
|
||||
pinMode(Sm2135.data, OUTPUT);
|
||||
digitalWrite(Sm2135.data, HIGH);
|
||||
|
|
|
@ -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 ((Pin(GPIO_RXD) < 99) && (Pin(GPIO_TXD) < 99)) {
|
||||
SetSerial(19200, TS_SERIAL_8N1);
|
||||
|
||||
light_type = LT_RGB;
|
||||
|
|
|
@ -70,7 +70,7 @@ bool ElectriqMoodLSetChannels(void)
|
|||
|
||||
void ElectriqMoodLModuleSelected(void)
|
||||
{
|
||||
if (pin[GPIO_ELECTRIQ_MOODL_TX] < 99) {
|
||||
if (Pin(GPIO_ELECTRIQ_MOODL_TX) < 99) {
|
||||
SetSerial(9600, TS_SERIAL_8N1);
|
||||
light_type = LT_RGBW;
|
||||
light_flg = XLGT_06;
|
||||
|
|
|
@ -138,7 +138,7 @@ void HlwEvery200ms(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (pin[GPIO_NRG_CF1] < 99) {
|
||||
if (Pin(GPIO_NRG_CF1) < 99) {
|
||||
Hlw.cf1_timer++;
|
||||
if (Hlw.cf1_timer >= 8) {
|
||||
Hlw.cf1_timer = 0;
|
||||
|
@ -233,38 +233,42 @@ void HlwSnsInit(void)
|
|||
Hlw.current_ratio = HLW_IREF;
|
||||
}
|
||||
|
||||
if (pin[GPIO_NRG_SEL] < 99) {
|
||||
pinMode(pin[GPIO_NRG_SEL], OUTPUT);
|
||||
digitalWrite(pin[GPIO_NRG_SEL], Hlw.select_ui_flag);
|
||||
if (Pin(GPIO_NRG_SEL) < 99) {
|
||||
pinMode(Pin(GPIO_NRG_SEL), OUTPUT);
|
||||
digitalWrite(Pin(GPIO_NRG_SEL), Hlw.select_ui_flag);
|
||||
}
|
||||
if (pin[GPIO_NRG_CF1] < 99) {
|
||||
pinMode(pin[GPIO_NRG_CF1], INPUT_PULLUP);
|
||||
attachInterrupt(pin[GPIO_NRG_CF1], HlwCf1Interrupt, FALLING);
|
||||
if (Pin(GPIO_NRG_CF1) < 99) {
|
||||
pinMode(Pin(GPIO_NRG_CF1), INPUT_PULLUP);
|
||||
attachInterrupt(Pin(GPIO_NRG_CF1), HlwCf1Interrupt, FALLING);
|
||||
}
|
||||
pinMode(pin[GPIO_HLW_CF], INPUT_PULLUP);
|
||||
attachInterrupt(pin[GPIO_HLW_CF], HlwCfInterrupt, FALLING);
|
||||
pinMode(Pin(GPIO_HLW_CF), INPUT_PULLUP);
|
||||
attachInterrupt(Pin(GPIO_HLW_CF), HlwCfInterrupt, FALLING);
|
||||
}
|
||||
|
||||
void HlwDrvInit(void)
|
||||
{
|
||||
Hlw.model_type = 0; // HLW8012
|
||||
if (pin[GPIO_HJL_CF] < 99) {
|
||||
pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF];
|
||||
pin[GPIO_HJL_CF] = 99;
|
||||
if (Pin(GPIO_HJL_CF) < 99) {
|
||||
// pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF];
|
||||
// pin[GPIO_HJL_CF] = 99;
|
||||
SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF);
|
||||
SetPin(99, GPIO_HJL_CF);
|
||||
Hlw.model_type = 1; // HJL-01/BL0937
|
||||
}
|
||||
|
||||
if (pin[GPIO_HLW_CF] < 99) { // HLW8012 or HJL-01 based device Power monitor
|
||||
if (Pin(GPIO_HLW_CF) < 99) { // HLW8012 or HJL-01 based device Power monitor
|
||||
|
||||
Hlw.ui_flag = true; // Voltage on high
|
||||
if (pin[GPIO_NRG_SEL_INV] < 99) {
|
||||
pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV];
|
||||
pin[GPIO_NRG_SEL_INV] = 99;
|
||||
if (Pin(GPIO_NRG_SEL_INV) < 99) {
|
||||
// pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV];
|
||||
// pin[GPIO_NRG_SEL_INV] = 99;
|
||||
SetPin(Pin(GPIO_NRG_SEL_INV), GPIO_NRG_SEL);
|
||||
SetPin(99, GPIO_NRG_SEL_INV);
|
||||
Hlw.ui_flag = false; // Voltage on low
|
||||
}
|
||||
|
||||
if (pin[GPIO_NRG_CF1] < 99) { // Voltage and/or Current monitor
|
||||
if (99 == pin[GPIO_NRG_SEL]) { // Voltage and/or Current selector
|
||||
if (Pin(GPIO_NRG_CF1) < 99) { // Voltage and/or Current monitor
|
||||
if (99 == Pin(GPIO_NRG_SEL)) { // Voltage and/or Current selector
|
||||
Energy.current_available = false; // Assume Voltage
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
* CSE7759 and CSE7766 - Energy (Sonoff S31 and Sonoff Pow R2)
|
||||
* HLW8032 - Energy (Blitzwolf SHP5)
|
||||
*
|
||||
* Needs GPIO_CSE7766_RX only
|
||||
*
|
||||
* Based on datasheet from http://www.chipsea.com/UploadFiles/2017/08/11144342F01B5662.pdf
|
||||
\*********************************************************************************************/
|
||||
|
||||
|
@ -223,8 +225,8 @@ void CseEverySecond(void)
|
|||
void CseSnsInit(void)
|
||||
{
|
||||
// Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions
|
||||
// CseSerial = new TasmotaSerial(pin[GPIO_CSE7766_RX], pin[GPIO_CSE7766_TX], 1);
|
||||
CseSerial = new TasmotaSerial(pin[GPIO_CSE7766_RX], -1, 1);
|
||||
// CseSerial = new TasmotaSerial(Pin(GPIO_CSE7766_RX), Pin(GPIO_CSE7766_TX), 1);
|
||||
CseSerial = new TasmotaSerial(Pin(GPIO_CSE7766_RX), -1, 1);
|
||||
if (CseSerial->begin(4800, 2)) { // Fake Software Serial 8E1 by using two stop bits
|
||||
if (CseSerial->hardwareSerial()) {
|
||||
SetSerial(4800, TS_SERIAL_8E1);
|
||||
|
@ -243,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 ((Pin(GPIO_CSE7766_RX) < 99) && (Pin(GPIO_CSE7766_TX) < 99)) {
|
||||
if (Pin(GPIO_CSE7766_RX) < 99) {
|
||||
energy_flg = XNRG_02;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ void PzemEvery250ms(void)
|
|||
void PzemSnsInit(void)
|
||||
{
|
||||
// Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions
|
||||
PzemSerial = new TasmotaSerial(pin[GPIO_PZEM004_RX], pin[GPIO_PZEM0XX_TX], 1);
|
||||
PzemSerial = new TasmotaSerial(Pin(GPIO_PZEM004_RX), Pin(GPIO_PZEM0XX_TX), 1);
|
||||
if (PzemSerial->begin(9600)) {
|
||||
if (PzemSerial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
|
@ -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 ((Pin(GPIO_PZEM004_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { // Any device with a Pzem004T
|
||||
energy_flg = XNRG_03;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -562,7 +562,7 @@ void McpEverySecond(void)
|
|||
void McpSnsInit(void)
|
||||
{
|
||||
// Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions
|
||||
McpSerial = new TasmotaSerial(pin[GPIO_MCP39F5_RX], pin[GPIO_MCP39F5_TX], 1);
|
||||
McpSerial = new TasmotaSerial(Pin(GPIO_MCP39F5_RX), Pin(GPIO_MCP39F5_TX), 1);
|
||||
if (McpSerial->begin(MCP_BAUDRATE)) {
|
||||
if (McpSerial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
|
@ -578,10 +578,10 @@ void McpSnsInit(void)
|
|||
|
||||
void McpDrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_MCP39F5_RX] < 99) && (pin[GPIO_MCP39F5_TX] < 99)) {
|
||||
if (pin[GPIO_MCP39F5_RST] < 99) {
|
||||
pinMode(pin[GPIO_MCP39F5_RST], OUTPUT);
|
||||
digitalWrite(pin[GPIO_MCP39F5_RST], 0); // MCP disable - Reset Delta Sigma ADC's
|
||||
if ((Pin(GPIO_MCP39F5_RX) < 99) && (Pin(GPIO_MCP39F5_TX) < 99)) {
|
||||
if (Pin(GPIO_MCP39F5_RST) < 99) {
|
||||
pinMode(Pin(GPIO_MCP39F5_RST), OUTPUT);
|
||||
digitalWrite(Pin(GPIO_MCP39F5_RST), 0); // MCP disable - Reset Delta Sigma ADC's
|
||||
}
|
||||
mcp_calibrate = 0;
|
||||
mcp_timeout = 2; // Initial wait
|
||||
|
|
|
@ -117,7 +117,7 @@ void PzemAcEverySecond(void)
|
|||
|
||||
void PzemAcSnsInit(void)
|
||||
{
|
||||
PzemAcModbus = new TasmotaModbus(pin[GPIO_PZEM016_RX], pin[GPIO_PZEM0XX_TX]);
|
||||
PzemAcModbus = new TasmotaModbus(Pin(GPIO_PZEM016_RX), Pin(GPIO_PZEM0XX_TX));
|
||||
uint8_t result = PzemAcModbus->Begin(9600);
|
||||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
|
@ -130,7 +130,7 @@ void PzemAcSnsInit(void)
|
|||
|
||||
void PzemAcDrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_PZEM016_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) {
|
||||
if ((Pin(GPIO_PZEM016_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) {
|
||||
energy_flg = XNRG_05;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ void PzemDcEverySecond(void)
|
|||
|
||||
void PzemDcSnsInit(void)
|
||||
{
|
||||
PzemDcModbus = new TasmotaModbus(pin[GPIO_PZEM017_RX], pin[GPIO_PZEM0XX_TX]);
|
||||
PzemDcModbus = new TasmotaModbus(Pin(GPIO_PZEM017_RX), Pin(GPIO_PZEM0XX_TX));
|
||||
uint8_t result = PzemDcModbus->Begin(9600, 2); // Uses two stop bits!!
|
||||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
|
@ -127,7 +127,7 @@ void PzemDcSnsInit(void)
|
|||
|
||||
void PzemDcDrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_PZEM017_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) {
|
||||
if ((Pin(GPIO_PZEM017_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) {
|
||||
energy_flg = XNRG_06;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ void Ade7953EnergyEverySecond(void)
|
|||
|
||||
void Ade7953DrvInit(void)
|
||||
{
|
||||
if (pin[GPIO_ADE7953_IRQ] < 99) { // Irq on GPIO16 is not supported...
|
||||
if (Pin(GPIO_ADE7953_IRQ) < 99) { // 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) {
|
||||
|
|
|
@ -176,7 +176,7 @@ void SDM120Every250ms(void)
|
|||
|
||||
void Sdm120SnsInit(void)
|
||||
{
|
||||
Sdm120Modbus = new TasmotaModbus(pin[GPIO_SDM120_RX], pin[GPIO_SDM120_TX]);
|
||||
Sdm120Modbus = new TasmotaModbus(Pin(GPIO_SDM120_RX), Pin(GPIO_SDM120_TX));
|
||||
uint8_t result = Sdm120Modbus->Begin(SDM120_SPEED);
|
||||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
|
@ -187,7 +187,7 @@ void Sdm120SnsInit(void)
|
|||
|
||||
void Sdm120DrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_SDM120_RX] < 99) && (pin[GPIO_SDM120_TX] < 99)) {
|
||||
if ((Pin(GPIO_SDM120_RX) < 99) && (Pin(GPIO_SDM120_TX) < 99)) {
|
||||
energy_flg = XNRG_08;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ void Dds2382EverySecond(void)
|
|||
|
||||
void Dds2382SnsInit(void)
|
||||
{
|
||||
Dds2382Modbus = new TasmotaModbus(pin[GPIO_DDS2382_RX], pin[GPIO_DDS2382_TX]);
|
||||
Dds2382Modbus = new TasmotaModbus(Pin(GPIO_DDS2382_RX), Pin(GPIO_DDS2382_TX));
|
||||
uint8_t result = Dds2382Modbus->Begin(DDS2382_SPEED);
|
||||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
|
@ -102,7 +102,7 @@ void Dds2382SnsInit(void)
|
|||
|
||||
void Dds2382DrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_DDS2382_RX] < 99) && (pin[GPIO_DDS2382_TX] < 99)) {
|
||||
if ((Pin(GPIO_DDS2382_RX) < 99) && (Pin(GPIO_DDS2382_TX) < 99)) {
|
||||
energy_flg = XNRG_09;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ void SDM630Every250ms(void)
|
|||
|
||||
void Sdm630SnsInit(void)
|
||||
{
|
||||
Sdm630Modbus = new TasmotaModbus(pin[GPIO_SDM630_RX], pin[GPIO_SDM630_TX]);
|
||||
Sdm630Modbus = new TasmotaModbus(Pin(GPIO_SDM630_RX), Pin(GPIO_SDM630_TX));
|
||||
uint8_t result = Sdm630Modbus->Begin(SDM630_SPEED);
|
||||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
|
@ -186,7 +186,7 @@ void Sdm630SnsInit(void)
|
|||
|
||||
void Sdm630DrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_SDM630_RX] < 99) && (pin[GPIO_SDM630_TX] < 99)) {
|
||||
if ((Pin(GPIO_SDM630_RX) < 99) && (Pin(GPIO_SDM630_TX) < 99)) {
|
||||
energy_flg = XNRG_10;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ void DDSU666Every250ms(void)
|
|||
|
||||
void Ddsu666SnsInit(void)
|
||||
{
|
||||
Ddsu666Modbus = new TasmotaModbus(pin[GPIO_DDSU666_RX], pin[GPIO_DDSU666_TX]);
|
||||
Ddsu666Modbus = new TasmotaModbus(Pin(GPIO_DDSU666_RX), Pin(GPIO_DDSU666_TX));
|
||||
uint8_t result = Ddsu666Modbus->Begin(DDSU666_SPEED);
|
||||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
|
@ -144,7 +144,7 @@ void Ddsu666SnsInit(void)
|
|||
|
||||
void Ddsu666DrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_DDSU666_RX] < 99) && (pin[GPIO_DDSU666_TX] < 99)) {
|
||||
if ((Pin(GPIO_DDSU666_RX) < 99) && (Pin(GPIO_DDSU666_TX) < 99)) {
|
||||
energy_flg = XNRG_11;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -406,10 +406,10 @@ void solaxX1250MSecond(void) // Every Second
|
|||
void solaxX1SnsInit(void)
|
||||
{
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("SX1: Solax X1 Inverter Init"));
|
||||
DEBUG_SENSOR_LOG(PSTR("SX1: RX pin: %d, TX pin: %d"), pin[GPIO_SOLAXX1_RX], pin[GPIO_SOLAXX1_TX]);
|
||||
DEBUG_SENSOR_LOG(PSTR("SX1: RX pin: %d, TX pin: %d"), Pin(GPIO_SOLAXX1_RX), Pin(GPIO_SOLAXX1_TX));
|
||||
protocolStatus.status = 0b00100000; // hasAddress
|
||||
|
||||
solaxX1Serial = new TasmotaSerial(pin[GPIO_SOLAXX1_RX], pin[GPIO_SOLAXX1_TX], 1);
|
||||
solaxX1Serial = new TasmotaSerial(Pin(GPIO_SOLAXX1_RX), Pin(GPIO_SOLAXX1_TX), 1);
|
||||
if (solaxX1Serial->begin(SOLAXX1_SPEED)) {
|
||||
if (solaxX1Serial->hardwareSerial()) { ClaimSerial(); }
|
||||
} else {
|
||||
|
@ -419,7 +419,7 @@ void solaxX1SnsInit(void)
|
|||
|
||||
void solaxX1DrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_SOLAXX1_RX] < 99) && (pin[GPIO_SOLAXX1_TX] < 99)) {
|
||||
if ((Pin(GPIO_SOLAXX1_RX) < 99) && (Pin(GPIO_SOLAXX1_TX) < 99)) {
|
||||
energy_flg = XNRG_12;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ void FifLEEvery250ms(void)
|
|||
|
||||
void FifLESnsInit(void)
|
||||
{
|
||||
FifLEModbus = new TasmotaModbus(pin[GPIO_LE01MR_RX], pin[GPIO_LE01MR_TX]);
|
||||
FifLEModbus = new TasmotaModbus(Pin(GPIO_LE01MR_RX), Pin(GPIO_LE01MR_TX));
|
||||
uint8_t result = FifLEModbus->Begin(LE01MR_SPEED);
|
||||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
|
@ -224,7 +224,7 @@ void FifLESnsInit(void)
|
|||
|
||||
void FifLEDrvInit(void)
|
||||
{
|
||||
if ((pin[GPIO_LE01MR_RX] < 99) && (pin[GPIO_LE01MR_TX] < 99)) {
|
||||
if ((Pin(GPIO_LE01MR_RX) < 99) && (Pin(GPIO_LE01MR_TX) < 99)) {
|
||||
energy_flg = XNRG_13;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ void CounterUpdate(uint8_t index)
|
|||
|
||||
if (Counter.pin_state) {
|
||||
// handle low and high debounce times when configured
|
||||
if (digitalRead(pin[GPIO_CNTR1 +index]) == bitRead(Counter.pin_state, index)) {
|
||||
if (digitalRead(Pin(GPIO_CNTR1, index)) == bitRead(Counter.pin_state, index)) {
|
||||
// new pin state to be ignored because debounce time was not met during last IRQ
|
||||
return;
|
||||
}
|
||||
|
@ -127,15 +127,15 @@ 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 (Pin(GPIO_CNTR1, i) < 99) {
|
||||
Counter.any_counter = true;
|
||||
pinMode(pin[GPIO_CNTR1 +i], bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP);
|
||||
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)) {
|
||||
Counter.pin_state = 0;
|
||||
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING);
|
||||
attachInterrupt(Pin(GPIO_CNTR1, i), counter_callbacks[i], FALLING);
|
||||
} else {
|
||||
Counter.pin_state = 0x8f;
|
||||
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], CHANGE);
|
||||
attachInterrupt(Pin(GPIO_CNTR1, i), counter_callbacks[i], CHANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 (Pin(GPIO_CNTR1, i) < 99) {
|
||||
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 (Pin(GPIO_CNTR1, i) < 99) {
|
||||
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 (Pin(GPIO_CNTR1, i) < 99) {
|
||||
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) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) {
|
||||
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) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) {
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue