Refactor pin test

This commit is contained in:
Theo Arends 2021-02-14 16:07:35 +01:00
parent 68464c5ebd
commit 541443f0aa
6 changed files with 10 additions and 12 deletions

View File

@ -1338,7 +1338,7 @@ int ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index) {
bool PinUsed(uint32_t gpio, uint32_t index = 0); bool PinUsed(uint32_t gpio, uint32_t index = 0);
bool PinUsed(uint32_t gpio, uint32_t index) { bool PinUsed(uint32_t gpio, uint32_t index) {
return (Pin(gpio, index) > -1); return (Pin(gpio, index) >= 0);
} }
uint32_t GetPin(uint32_t lpin) { uint32_t GetPin(uint32_t lpin) {

View File

@ -168,7 +168,7 @@ void RotaryInit(void) {
attachInterruptArg(Encoder[index].pina, RotaryIsrArg, &Encoder[index], FALLING); attachInterruptArg(Encoder[index].pina, RotaryIsrArg, &Encoder[index], FALLING);
} }
} }
Rotary.present |= (Encoder[index].pinb > -1); Rotary.present |= (Encoder[index].pinb >= 0);
} }
} }
@ -213,7 +213,7 @@ void RotaryHandler(void) {
#ifdef USE_LIGHT #ifdef USE_LIGHT
if (!Settings.flag4.rotary_uses_rules) { // SetOption98 - Use rules instead of light control if (!Settings.flag4.rotary_uses_rules) { // SetOption98 - Use rules instead of light control
bool second_rotary = (Encoder[1].pinb > -1); bool second_rotary = (Encoder[1].pinb >= 0);
if (0 == index) { // Rotary1 if (0 == index) { // Rotary1
if (button_pressed) { if (button_pressed) {
if (second_rotary) { // Color RGB if (second_rotary) { // Color RGB

View File

@ -412,7 +412,7 @@ void SetLedLink(uint32_t state)
if (-1 == led_pin) { // Legacy - LED1 is status if (-1 == led_pin) { // Legacy - LED1 is status
SetLedPowerIdx(0, state); SetLedPowerIdx(0, state);
} }
else if (led_pin > -1) { else if (led_pin >= 0) {
if (state) { state = 1; } if (state) { state = 1; }
digitalWrite(led_pin, (led_inv) ? !state : state); digitalWrite(led_pin, (led_inv) ? !state : state);
} }

View File

@ -1517,7 +1517,7 @@ void ZigbeeGlowPermitJoinLight(void) {
// change the led state // change the led state
int led_pin = Pin(GPIO_LEDLNK); int led_pin = Pin(GPIO_LEDLNK);
if (led_pin > -1) { if (led_pin >= 0) {
analogWrite(led_pin, TasmotaGlobal.ledlnk_inverted ? 1023 - led_power : led_power); analogWrite(led_pin, TasmotaGlobal.ledlnk_inverted ? 1023 - led_power : led_power);
} }
} }

View File

@ -44,6 +44,7 @@ void ILI9341_InitDriver()
#ifdef USE_M5STACK_CORE2 #ifdef USE_M5STACK_CORE2
if (TasmotaGlobal.spi_enabled) { if (TasmotaGlobal.spi_enabled) {
#else #else
// There are displays without CS
if (PinUsed(GPIO_ILI9341_CS) || PinUsed(GPIO_ILI9341_DC) && if (PinUsed(GPIO_ILI9341_CS) || PinUsed(GPIO_ILI9341_DC) &&
(TasmotaGlobal.spi_enabled || TasmotaGlobal.soft_spi_enabled)) { (TasmotaGlobal.spi_enabled || TasmotaGlobal.soft_spi_enabled)) {
#endif #endif
@ -66,11 +67,8 @@ void ILI9341_InitDriver()
#ifdef USE_M5STACK_CORE2 #ifdef USE_M5STACK_CORE2
// fixed pins on m5stack core2 // fixed pins on m5stack core2
ili9341_2 = new ILI9341_2(5, -2, 15, -2); ili9341_2 = new ILI9341_2(5, -2, 15, -2);
#else #else
// There are displays without CS
// check for special case with 2 SPI busses (ESP32 bitcoin) // check for special case with 2 SPI busses (ESP32 bitcoin)
if (TasmotaGlobal.soft_spi_enabled) { if (TasmotaGlobal.soft_spi_enabled) {
// Init renderer, may use hardware spi, however we use SSPI defintion because SD card uses SPI definition (2 spi busses) // Init renderer, may use hardware spi, however we use SSPI defintion because SD card uses SPI definition (2 spi busses)

View File

@ -62,7 +62,7 @@ void SM16716_SendByte(uint8_t v)
void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b) void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b)
{ {
if (Sm16716.pin_sel > -1) { if (Sm16716.pin_sel >= 0) {
bool should_enable = (duty_r | duty_g | duty_b); bool should_enable = (duty_r | duty_g | duty_b);
if (!Sm16716.enabled && should_enable) { if (!Sm16716.enabled && should_enable) {
DEBUG_DRIVER_LOG(PSTR(D_LOG_SM16716 "turning color on")); DEBUG_DRIVER_LOG(PSTR(D_LOG_SM16716 "turning color on"));
@ -104,7 +104,7 @@ bool SM16716_ModuleSelected(void)
Sm16716.pin_dat = Pin(GPIO_SM16716_DAT); Sm16716.pin_dat = Pin(GPIO_SM16716_DAT);
Sm16716.pin_sel = Pin(GPIO_SM16716_SEL); 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); DEBUG_DRIVER_LOG(PSTR(D_LOG_SM16716 "ModuleSelected; clk_pin=%d, dat_pin=%d)"), Sm16716.pin_clk, Sm16716.pin_dat);
return (Sm16716.pin_clk > -1) && (Sm16716.pin_dat > -1); return (Sm16716.pin_clk >= 0) && (Sm16716.pin_dat >= 0);
} }
*/ */
@ -165,7 +165,7 @@ void Sm16716ModuleSelected(void)
pinMode(Sm16716.pin_dat, OUTPUT); pinMode(Sm16716.pin_dat, OUTPUT);
digitalWrite(Sm16716.pin_dat, LOW); digitalWrite(Sm16716.pin_dat, LOW);
if (Sm16716.pin_sel > -1) { if (Sm16716.pin_sel >= 0) {
pinMode(Sm16716.pin_sel, OUTPUT); pinMode(Sm16716.pin_sel, OUTPUT);
digitalWrite(Sm16716.pin_sel, LOW); digitalWrite(Sm16716.pin_sel, LOW);
// no need to call SM16716_Init here, it will be called after sel goes HIGH // no need to call SM16716_Init here, it will be called after sel goes HIGH