mirror of
https://github.com/martin-ger/esp_wifi_repeater.git
synced 2026-07-27 19:56:03 +00:00
Merge pull request #303 from bchabrier/small_fixes
Fixes to GPIO features
This commit is contained in:
+36
-17
@@ -849,7 +849,6 @@ static void ICACHE_FLASH_ATTR OtaUpdate() {
|
|||||||
#if GPIO_CMDS
|
#if GPIO_CMDS
|
||||||
void do_outputSet(uint8_t pin, uint8_t value, uint16_t duration);
|
void do_outputSet(uint8_t pin, uint8_t value, uint16_t duration);
|
||||||
|
|
||||||
static os_timer_t inttimerchange;
|
|
||||||
static uint8_t prev_values[17] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
static uint8_t prev_values[17] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
||||||
|
|
||||||
void handlePinValueChange(uint16_t pin) {
|
void handlePinValueChange(uint16_t pin) {
|
||||||
@@ -892,30 +891,46 @@ void handlePinValueChange(uint16_t pin) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICACHE_FLASH_ATTR int_timerchange_func(void *arg){
|
typedef struct {
|
||||||
uint16_t pin = (intptr_t)arg;
|
uint32_t gpio_status;
|
||||||
handlePinValueChange(pin);
|
os_timer_t timer;
|
||||||
|
} status_timer_t;
|
||||||
|
|
||||||
// Reactivate interrupts for GPIO
|
void ICACHE_FLASH_ATTR int_timerchange_func(void *arg){
|
||||||
gpio_pin_intr_state_set(GPIO_ID_PIN(pin), GPIO_PIN_INTR_ANYEDGE);
|
status_timer_t *inttimerchange = arg;
|
||||||
|
uint32_t gpio_status = inttimerchange->gpio_status;
|
||||||
|
uint16_t pin;
|
||||||
|
for (pin = 0; pin <= 16; pin++) {
|
||||||
|
if (gpio_status & BIT(pin)) {
|
||||||
|
handlePinValueChange(pin);
|
||||||
|
|
||||||
|
// Reactivate interrupts for GPIO
|
||||||
|
gpio_pin_intr_state_set(GPIO_ID_PIN(pin), GPIO_PIN_INTR_ANYEDGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os_free(inttimerchange);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void gpio_change_handler(void *arg)
|
LOCAL void gpio_change_handler(void *arg)
|
||||||
{
|
{
|
||||||
uint16_t pin = (intptr_t)arg;
|
uint16_t pin = (intptr_t)arg; // not used
|
||||||
|
|
||||||
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
|
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
|
||||||
|
for (pin = 0; pin <= 16; pin++) {
|
||||||
if (gpio_status & BIT(pin)) {
|
if (gpio_status & BIT(pin)) {
|
||||||
gpio_pin_intr_state_set(GPIO_ID_PIN(pin), GPIO_PIN_INTR_DISABLE);
|
gpio_pin_intr_state_set(GPIO_ID_PIN(pin), GPIO_PIN_INTR_DISABLE);
|
||||||
|
}
|
||||||
// Clear interrupt status for GPIO
|
|
||||||
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(pin));
|
|
||||||
|
|
||||||
// Start the timer
|
|
||||||
os_timer_setfn(&inttimerchange, int_timerchange_func, (void *)(intptr_t)pin);
|
|
||||||
os_timer_arm(&inttimerchange, 50, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear interrupt status
|
||||||
|
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
|
||||||
|
|
||||||
|
// Start the timer
|
||||||
|
status_timer_t *inttimerchange = os_malloc(sizeof(status_timer_t));
|
||||||
|
inttimerchange->gpio_status = gpio_status;
|
||||||
|
os_timer_setfn(&inttimerchange->timer, int_timerchange_func, inttimerchange);
|
||||||
|
os_timer_arm(&inttimerchange->timer, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GPIO_CMDS */
|
#endif /* GPIO_CMDS */
|
||||||
@@ -3848,6 +3863,8 @@ struct espconn *pCon;
|
|||||||
if (config.gpiomode[i] == OUT) {
|
if (config.gpiomode[i] == OUT) {
|
||||||
easygpio_pinMode(i, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
|
easygpio_pinMode(i, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
for (i=0; i<17; i++) {
|
||||||
if (config.gpiomode[i] == IN) {
|
if (config.gpiomode[i] == IN) {
|
||||||
#if MQTT_CLIENT
|
#if MQTT_CLIENT
|
||||||
easygpio_attachInterrupt(i, EASYGPIO_NOPULL, gpio_change_handler, (void *)(intptr_t)i);
|
easygpio_attachInterrupt(i, EASYGPIO_NOPULL, gpio_change_handler, (void *)(intptr_t)i);
|
||||||
@@ -3855,6 +3872,7 @@ struct espconn *pCon;
|
|||||||
#else
|
#else
|
||||||
easygpio_pinMode(i, EASYGPIO_NOPULL, EASYGPIO_INPUT);
|
easygpio_pinMode(i, EASYGPIO_NOPULL, EASYGPIO_INPUT);
|
||||||
#endif
|
#endif
|
||||||
|
handlePinValueChange(i);
|
||||||
}
|
}
|
||||||
if (config.gpiomode[i] == IN_PULLUP) {
|
if (config.gpiomode[i] == IN_PULLUP) {
|
||||||
#if MQTT_CLIENT
|
#if MQTT_CLIENT
|
||||||
@@ -3863,6 +3881,7 @@ struct espconn *pCon;
|
|||||||
#else
|
#else
|
||||||
easygpio_pinMode(i, EASYGPIO_PULLUP, EASYGPIO_INPUT);
|
easygpio_pinMode(i, EASYGPIO_PULLUP, EASYGPIO_INPUT);
|
||||||
#endif
|
#endif
|
||||||
|
handlePinValueChange(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user