void gpio_config(GPIO_ConfigTypeDef *pGPIOConfig) { uint32 gpio_pin_mask = pGPIOConfig->GPIO_Pin; uint32 gpio_pin_mask_high = pGPIOConfig->GPIO_Pin_high; uint32 io_reg; uint8 io_num = 0; uint32 pin_reg; uint32 bit_valid; if (pGPIOConfig->GPIO_Mode == GPIO_Mode_Input) { GPIO_AS_INPUT(gpio_pin_mask); GPIO_AS_INPUT_HIGH(gpio_pin_mask_high); } else if (pGPIOConfig->GPIO_Mode == GPIO_Mode_Output) { GPIO_AS_OUTPUT(gpio_pin_mask); GPIO_AS_OUTPUT_HIGH(gpio_pin_mask_high); } do { bit_valid = (io_num >= 32 ? (gpio_pin_mask_high & (0x1 << (io_num - 32))) : (gpio_pin_mask & (0x1 << io_num))); if (bit_valid && (io_reg = GPIO_PIN_REG[io_num])) { if (pGPIOConfig->GPIO_Mode == GPIO_Mode_Input) { SET_PERI_REG_MASK(io_reg, FUN_IE); } //for ESP32 function 2 of every pad is allways GPIO func PIN_FUNC_SELECT(io_reg, 2); if (pGPIOConfig->GPIO_Pullup) { PIN_PULLUP_EN(io_reg); } else { PIN_PULLUP_DIS(io_reg); } if (pGPIOConfig->GPIO_Pulldown) { PIN_PULLDWN_EN(io_reg); } else { PIN_PULLDWN_DIS(io_reg); } if (pGPIOConfig->GPIO_Mode == GPIO_Mode_Out_OD) { portENTER_CRITICAL(); pin_reg = GPIO_REG_READ(GPIO_PIN_ADDR(io_num)); //pin_reg &= (~GPIO_GPIO_PIN0_PAD_DRIVER); pin_reg |= GPIO_GPIO_PIN0_PAD_DRIVER; GPIO_REG_WRITE(GPIO_PIN_ADDR(io_num), pin_reg); portEXIT_CRITICAL(); } gpio_pin_intr_state_set(io_num, pGPIOConfig->GPIO_IntrType); } io_num++; } while (io_num < GPIO_PIN_COUNT); }
/** * Sets the pull up and pull down registers for a pin. */ static void ICACHE_FLASH_ATTR easygpio_setupPulls(uint32_t gpio_name, bool pullUp, bool pullDown) { if (pullUp) { PIN_PULLDWN_DIS(gpio_name); PIN_PULLUP_EN(gpio_name); } else if (pullDown) { PIN_PULLUP_DIS(gpio_name); PIN_PULLDWN_EN(gpio_name); } else { PIN_PULLDWN_DIS(gpio_name); PIN_PULLUP_DIS(gpio_name); } }
/** * Sets the pull up and pull down registers for a pin. * This seems to do very little for the actual pull effect * - it's always pull up for both EASYGPIO_PULLUP and EASYGPIO_PULLDOWN. * But that is something the SDK needs to fix. */ static void ICACHE_FLASH_ATTR easygpio_setupPullsByName(uint32_t gpio_name, EasyGPIO_PullStatus pullStatus) { if (EASYGPIO_PULLUP == pullStatus){ PIN_PULLDWN_DIS(gpio_name); PIN_PULLUP_EN(gpio_name); } else if (EASYGPIO_PULLDOWN == pullStatus){ PIN_PULLUP_DIS(gpio_name); PIN_PULLDWN_EN(gpio_name); } else { PIN_PULLDWN_DIS(gpio_name); PIN_PULLUP_DIS(gpio_name); } }
int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull ) { // NODE_DBG("Function platform_gpio_mode() is called. pin_mux:%d, func:%d\n",pin_mux[pin],pin_func[pin]); if (pin >= NUM_GPIO) return -1; if(pin == 0){ if(mode==PLATFORM_GPIO_INPUT) gpio16_input_conf(); else gpio16_output_conf(); return 1; } platform_pwm_close(pin); // closed from pwm module, if it is used in pwm switch(pull){ case PLATFORM_GPIO_PULLUP: PIN_PULLDWN_DIS(pin_mux[pin]); PIN_PULLUP_EN(pin_mux[pin]); break; case PLATFORM_GPIO_PULLDOWN: PIN_PULLUP_DIS(pin_mux[pin]); PIN_PULLDWN_EN(pin_mux[pin]); break; case PLATFORM_GPIO_FLOAT: PIN_PULLUP_DIS(pin_mux[pin]); PIN_PULLDWN_DIS(pin_mux[pin]); break; default: PIN_PULLUP_DIS(pin_mux[pin]); PIN_PULLDWN_DIS(pin_mux[pin]); break; } switch(mode){ case PLATFORM_GPIO_INPUT: #if defined( LUA_USE_MODULES_GPIO ) && defined( GPIO_INTERRUPT_ENABLE ) lua_gpio_unref(pin); // unref the lua ref call back. #endif GPIO_DIS_OUTPUT(pin_num[pin]); case PLATFORM_GPIO_OUTPUT: ETS_GPIO_INTR_DISABLE(); #ifdef GPIO_INTERRUPT_ENABLE pin_int_type[pin] = GPIO_PIN_INTR_DISABLE; #endif PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]); //disable interrupt gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), GPIO_PIN_INTR_DISABLE); //clear interrupt status GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin])); GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin]))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); //disable open drain; ETS_GPIO_INTR_ENABLE(); break; #ifdef GPIO_INTERRUPT_ENABLE case PLATFORM_GPIO_INT: ETS_GPIO_INTR_DISABLE(); PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]); GPIO_DIS_OUTPUT(pin_num[pin]); gpio_register_set(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); ETS_GPIO_INTR_ENABLE(); break; #endif default: break; } return 1; }