Пример #1
0
/**
 * Sets the 'gpio_pin' pin as a GPIO and sets the interrupt to trigger on that pin.
 * The 'interruptArg' is the function argument that will be sent to your interruptHandler
 */
bool ICACHE_FLASH_ATTR
easygpio_attachInterrupt(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, void (*interruptHandler)(void *arg), void *interruptArg) {
  uint32_t gpio_name;
  uint8_t gpio_func;

  if (gpio_pin == 16) {
    os_printf("easygpio_setupInterrupt Error: GPIO16 does not have interrupts\n");
    return false;
  }
  if (!easygpio_getGPIONameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
    return false;
  }

  ETS_GPIO_INTR_ATTACH(interruptHandler, interruptArg);
  ETS_GPIO_INTR_DISABLE();

  PIN_FUNC_SELECT(gpio_name, gpio_func);

  easygpio_setupPullsByName(gpio_name, pullStatus);

  // disable output
  GPIO_DIS_OUTPUT(gpio_pin);

  gpio_register_set(GPIO_PIN_ADDR(gpio_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));

  //clear gpio14 status
  GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(gpio_pin));
  ETS_GPIO_INTR_ENABLE();

  return true;
}
Пример #2
0
/**
 * Sets the 'gpio_pin' pin as a GPIO and sets the pull-up and
 * pull-down registers for that pin.
 * 'pullStatus' has no effect on output pins or GPIO16
 */
bool ICACHE_FLASH_ATTR
easygpio_pinMode(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, EasyGPIO_PinMode pinMode) {
  uint32_t gpio_name;
  uint8_t gpio_func;

  if (16==gpio_pin) {
    // ignoring pull status on GPIO16 for now
    if (EASYGPIO_OUTPUT == pinMode) {
      gpio16_output_conf();
    } else {
      gpio16_input_conf();
    }
    return true;
  } else if (!easygpio_getGPIONameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
    return false;
  }

  PIN_FUNC_SELECT(gpio_name, gpio_func);
  easygpio_setupPullsByName(gpio_name, pullStatus);

  if (EASYGPIO_OUTPUT != pinMode) {
    GPIO_DIS_OUTPUT(GPIO_ID_PIN(gpio_pin));
  } else {
    // must enable the pin or else the WRITE_PERI_REG won't work
    gpio_output_set(0, 0, BIT(GPIO_ID_PIN(gpio_pin)),0);
  }
  return true;
}
Пример #3
0
/**
 * Sets the pull up and pull down registers for a pin.
 */
bool ICACHE_FLASH_ATTR
easygpio_pullMode(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus) {
  uint32_t gpio_name;
  uint8_t gpio_func;

  if (!easygpio_getGPIONameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
    return false;
  }

  easygpio_setupPullsByName(gpio_name, pullStatus);
  return true;
}
Пример #4
0
/**
 * Sets the 'gpio_pin' pin as an input GPIO and sets the pull up and
 * pull down registers for that pin.
 */
bool ICACHE_FLASH_ATTR
easygpio_pinMode(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, EasyGPIO_PinMode pinMode) {
  uint32_t gpio_name;
  uint8_t gpio_func;

  if (!easygpio_getGPIONameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
    return false;
  }

  PIN_FUNC_SELECT(gpio_name, gpio_func);
  easygpio_setupPullsByName(gpio_name, pullStatus);

  if (EASYGPIO_OUTPUT != pinMode) {
    GPIO_DIS_OUTPUT(gpio_pin);
  }
  return true;
}