2016-12-07 01:18:10 -05:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef _DRIVER_RTC_GPIO_H_
|
|
|
|
#define _DRIVER_RTC_GPIO_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "driver/gpio.h"
|
2018-06-13 00:52:44 -04:00
|
|
|
#include "soc/rtc_periph.h"
|
2016-12-07 01:18:10 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum {
|
2019-06-13 03:37:58 -04:00
|
|
|
RTC_GPIO_MODE_INPUT_ONLY , /*!< Pad input */
|
|
|
|
RTC_GPIO_MODE_OUTPUT_ONLY, /*!< Pad output */
|
2017-11-29 14:56:00 -05:00
|
|
|
RTC_GPIO_MODE_INPUT_OUTPUT, /*!< Pad pull input + output */
|
2019-06-13 03:37:58 -04:00
|
|
|
RTC_GPIO_MODE_DISABLED, /*!< Pad (output + input) disable */
|
2016-12-07 01:18:10 -05:00
|
|
|
} rtc_gpio_mode_t;
|
|
|
|
|
2019-06-13 03:37:58 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2BETA
|
|
|
|
typedef enum {
|
|
|
|
RTCIO_MODE_OUTPUT = 0, /*!< Pad output normal mode */
|
|
|
|
RTCIO_MODE_OUTPUT_OD = 1, /*!< Pad output OD mode */
|
|
|
|
} rtc_io_out_mode_t;
|
|
|
|
#endif
|
|
|
|
|
2017-02-14 19:50:21 -05:00
|
|
|
/**
|
|
|
|
* @brief Determine if the specified GPIO is a valid RTC GPIO.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
2018-06-15 05:32:43 -04:00
|
|
|
* @return true if GPIO is valid for RTC GPIO use. false otherwise.
|
2017-02-14 19:50:21 -05:00
|
|
|
*/
|
|
|
|
inline static bool rtc_gpio_is_valid_gpio(gpio_num_t gpio_num)
|
|
|
|
{
|
2019-06-13 03:37:58 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2017-02-14 19:50:21 -05:00
|
|
|
return gpio_num < GPIO_PIN_COUNT
|
|
|
|
&& rtc_gpio_desc[gpio_num].reg != 0;
|
2019-06-13 03:37:58 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2BETA
|
|
|
|
return (gpio_num < RTC_GPIO_NUMBER);
|
|
|
|
#endif
|
2017-02-14 19:50:21 -05:00
|
|
|
}
|
|
|
|
|
2017-02-15 21:59:50 -05:00
|
|
|
#define RTC_GPIO_IS_VALID_GPIO(gpio_num) rtc_gpio_is_valid_gpio(gpio_num) // Deprecated, use rtc_gpio_is_valid_gpio()
|
2017-02-14 19:50:21 -05:00
|
|
|
|
2016-12-08 05:37:22 -05:00
|
|
|
/**
|
|
|
|
* @brief Init a GPIO as RTC GPIO
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* This function must be called when initializing a pad for an analog function.
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK success
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_init(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief Init a GPIO as digital GPIO
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK success
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief Get the RTC IO input level
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - 1 High level
|
|
|
|
* - 0 Low level
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
uint32_t rtc_gpio_get_level(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief Set the RTC IO output level
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
|
|
|
* @param level output level
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_set_level(gpio_num_t gpio_num, uint32_t level);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief RTC GPIO set direction
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* Configure RTC GPIO direction, such as output only, input only,
|
|
|
|
* output and input.
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
* @param mode GPIO direction
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_set_direction(gpio_num_t gpio_num, rtc_gpio_mode_t mode);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief RTC GPIO pullup enable
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* This function only works for RTC IOs. In general, call gpio_pullup_en,
|
|
|
|
* which will work both for normal GPIOs and RTC IOs.
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pullup_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief RTC GPIO pulldown enable
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* This function only works for RTC IOs. In general, call gpio_pulldown_en,
|
|
|
|
* which will work both for normal GPIOs and RTC IOs.
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pulldown_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief RTC GPIO pullup disable
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* This function only works for RTC IOs. In general, call gpio_pullup_dis,
|
|
|
|
* which will work both for normal GPIOs and RTC IOs.
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pullup_dis(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-08 05:37:22 -05:00
|
|
|
* @brief RTC GPIO pulldown disable
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* This function only works for RTC IOs. In general, call gpio_pulldown_dis,
|
|
|
|
* which will work both for normal GPIOs and RTC IOs.
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
2016-12-08 05:37:22 -05:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-07 01:18:10 -05:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-08 05:37:22 -05:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-07 01:18:10 -05:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pulldown_dis(gpio_num_t gpio_num);
|
|
|
|
|
2016-12-14 01:20:01 -05:00
|
|
|
/**
|
2017-03-19 11:59:19 -04:00
|
|
|
* @brief Enable hold function on an RTC IO pad
|
2016-12-14 01:20:01 -05:00
|
|
|
*
|
2017-03-19 11:59:19 -04:00
|
|
|
* Enabling HOLD function will cause the pad to latch current values of
|
|
|
|
* input enable, output enable, output value, function, drive strength values.
|
|
|
|
* This function is useful when going into light or deep sleep mode to prevent
|
|
|
|
* the pin configuration from changing.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable hold function on an RTC IO pad
|
|
|
|
*
|
|
|
|
* Disabling hold function will allow the pad receive the values of
|
|
|
|
* input enable, output enable, output value, function, drive strength from
|
|
|
|
* RTC_IO peripheral.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num);
|
|
|
|
|
2018-02-09 11:28:30 -05:00
|
|
|
/**
|
|
|
|
* @brief Helper function to disconnect internal circuits from an RTC IO
|
|
|
|
* This function disables input, output, pullup, pulldown, and enables
|
|
|
|
* hold feature for an RTC IO.
|
|
|
|
* Use this function if an RTC IO needs to be disconnected from internal
|
|
|
|
* circuits in deep sleep, to minimize leakage current.
|
|
|
|
*
|
|
|
|
* In particular, for ESP32-WROVER module, call
|
|
|
|
* rtc_gpio_isolate(GPIO_NUM_12) before entering deep sleep, to reduce
|
|
|
|
* deep sleep current.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12).
|
|
|
|
* @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_INVALID_ARG if GPIO is not an RTC IO
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num);
|
|
|
|
|
2017-03-19 11:59:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Disable force hold signal for all RTC IOs
|
|
|
|
*
|
|
|
|
* Each RTC pad has a "force hold" input signal from the RTC controller.
|
|
|
|
* If this signal is set, pad latches current values of input enable,
|
2016-12-14 01:20:01 -05:00
|
|
|
* function, output enable, and other signals which come from the RTC mux.
|
2017-03-19 11:59:19 -04:00
|
|
|
* Force hold signal is enabled before going into deep sleep for pins which
|
2016-12-14 01:20:01 -05:00
|
|
|
* are used for EXT1 wakeup.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void rtc_gpio_force_hold_dis_all(void);
|
2016-12-14 01:20:01 -05:00
|
|
|
|
2017-07-17 03:38:19 -04:00
|
|
|
/**
|
2018-08-13 18:57:32 -04:00
|
|
|
* @brief Set RTC GPIO pad drive capability
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number, only support output GPIOs
|
|
|
|
* @param strength Drive capability of the pad
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
2017-07-17 03:38:19 -04:00
|
|
|
esp_err_t rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength);
|
|
|
|
|
|
|
|
/**
|
2018-08-13 18:57:32 -04:00
|
|
|
* @brief Get RTC GPIO pad drive capability
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number, only support output GPIOs
|
|
|
|
* @param strength Pointer to accept drive capability of the pad
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
*/
|
2017-07-17 03:38:19 -04:00
|
|
|
esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
|
2016-12-14 01:20:01 -05:00
|
|
|
|
2018-08-13 18:57:32 -04:00
|
|
|
/**
|
|
|
|
* @brief Enable wakeup from sleep mode using specific GPIO
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
* @param intr_type Wakeup on high level (GPIO_INTR_HIGH_LEVEL) or low level
|
|
|
|
* (GPIO_INTR_LOW_LEVEL)
|
|
|
|
* @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO, or intr_type is not
|
|
|
|
* one of GPIO_INTR_HIGH_LEVEL, GPIO_INTR_LOW_LEVEL.
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable wakeup from sleep mode using specific GPIO
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
* @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_wakeup_disable(gpio_num_t gpio_num);
|
|
|
|
|
2019-06-13 03:37:58 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2BETA
|
|
|
|
/**
|
|
|
|
* @brief RTC IO set output mode
|
|
|
|
* @param gpio_num Configure GPIO pins number
|
|
|
|
* @param mode GPIO output mode
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_set_output_mode(gpio_num_t gpio_num, rtc_io_out_mode_t mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief RTC IO get output mode
|
|
|
|
* @param gpio_num Configure GPIO pins number
|
|
|
|
* @param mode GPIO output mode
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_get_output_mode(gpio_num_t gpio_num, rtc_io_out_mode_t *mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set RTC IO status in deep sleep
|
|
|
|
* In some application scenarios, IO needs to have another states during deep sleep.
|
|
|
|
* @param gpio_num Configure GPIO pins number
|
|
|
|
* @param input input mode. false: close; true: open;
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_sleep_input_enable(gpio_num_t gpio_num, bool input);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set RTC IO status in deep sleep
|
|
|
|
* In some application scenarios, IO needs to have another states during deep sleep.
|
|
|
|
* @param gpio_num Configure GPIO pins number
|
|
|
|
* @param output output mode. false: close; true: open;
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_sleep_output_enable(gpio_num_t gpio_num, bool output);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Close RTC IO status in deep sleep
|
|
|
|
* In some application scenarios, IO needs to have another states during deep sleep.
|
|
|
|
* @param gpio_num Configure GPIO pins number
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO error
|
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_sleep_mode_disable(gpio_num_t gpio_num);
|
2018-08-13 18:57:32 -04:00
|
|
|
|
2019-06-13 03:37:58 -04:00
|
|
|
/**
|
|
|
|
* @brief Enable force hold signal for all RTC IOs
|
|
|
|
*
|
|
|
|
* Each RTC pad has a "force hold" input signal from the RTC controller.
|
|
|
|
* If this signal is set, pad latches current values of input enable,
|
|
|
|
* function, output enable, and other signals which come from the RTC mux.
|
|
|
|
* Force hold signal is enabled before going into deep sleep for pins which
|
|
|
|
* are used for EXT1 wakeup.
|
|
|
|
*/
|
2019-08-11 22:06:07 -04:00
|
|
|
esp_err_t rtc_gpio_force_hold_all(void);
|
2019-06-13 03:37:58 -04:00
|
|
|
#endif
|
2018-08-13 18:57:32 -04:00
|
|
|
|
2016-12-07 01:18:10 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|