2016-12-08 23:43:41 +02: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"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2017-02-23 01:11:57 +02:00
|
|
|
* @brief Pin function information for a single GPIO pad's RTC functions.
|
|
|
|
*
|
|
|
|
* This is an internal function of the driver, and is not usually useful
|
|
|
|
* for external use.
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2016-12-30 01:28:30 +02:00
|
|
|
uint32_t reg; /*!< Register of RTC pad, or 0 if not an RTC GPIO */
|
|
|
|
uint32_t mux; /*!< Bit mask for selecting digital pad or RTC pad */
|
|
|
|
uint32_t func; /*!< Shift of pad function (FUN_SEL) field */
|
|
|
|
uint32_t ie; /*!< Mask of input enable */
|
|
|
|
uint32_t pullup; /*!< Mask of pullup enable */
|
|
|
|
uint32_t pulldown; /*!< Mask of pulldown enable */
|
|
|
|
uint32_t slpsel; /*!< If slpsel bit is set, slpie will be used as pad input enabled signal in sleep mode */
|
|
|
|
uint32_t slpie; /*!< Mask of input enable in sleep mode */
|
|
|
|
uint32_t hold; /*!< Mask of hold_force bit for RTC IO in RTC_CNTL_HOLD_FORCE_REG */
|
|
|
|
int rtc_num; /*!< RTC IO number, or -1 if not an RTC GPIO */
|
2016-12-08 23:43:41 +02:00
|
|
|
} rtc_gpio_desc_t;
|
|
|
|
|
|
|
|
typedef enum {
|
2016-12-30 01:28:30 +02:00
|
|
|
RTC_GPIO_MODE_INPUT_ONLY , /*!< Pad output */
|
|
|
|
RTC_GPIO_MODE_OUTPUT_ONLY, /*!< Pad input */
|
|
|
|
RTC_GPIO_MODE_INPUT_OUTUT, /*!< Pad pull output + input */
|
|
|
|
RTC_GPIO_MODE_DISABLED, /*!< Pad (output + input) disable */
|
2016-12-08 23:43:41 +02:00
|
|
|
} rtc_gpio_mode_t;
|
|
|
|
|
2017-02-23 01:11:57 +02:00
|
|
|
/**
|
|
|
|
* @brief Provides access to a constant table of RTC I/O pin
|
|
|
|
* function information.
|
|
|
|
*
|
|
|
|
* This is an internal function of the driver, and is not usually useful
|
|
|
|
* for external use.
|
|
|
|
*/
|
2016-12-30 01:28:30 +02:00
|
|
|
extern const rtc_gpio_desc_t rtc_gpio_desc[GPIO_PIN_COUNT];
|
2016-12-08 23:43:41 +02:00
|
|
|
|
2017-02-23 01:11:57 +02:00
|
|
|
/**
|
|
|
|
* @brief Determine if the specified GPIO is a valid RTC GPIO.
|
|
|
|
*
|
|
|
|
* @param gpio_num GPIO number
|
|
|
|
* @return true if GPIO is valid for RTC GPIO use. talse otherwise.
|
|
|
|
*/
|
|
|
|
inline static bool rtc_gpio_is_valid_gpio(gpio_num_t gpio_num)
|
|
|
|
{
|
|
|
|
return gpio_num < GPIO_PIN_COUNT
|
|
|
|
&& rtc_gpio_desc[gpio_num].reg != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RTC_GPIO_IS_VALID_GPIO(gpio_num) rtc_gpio_is_valid_gpio(gpio_num) // Deprecated, use rtc_gpio_is_valid_gpio()
|
|
|
|
|
2016-12-30 01:28:30 +02:00
|
|
|
/**
|
|
|
|
* @brief Init a GPIO as RTC GPIO
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* This function must be called when initializing a pad for an analog function.
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK success
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_init(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief Init a GPIO as digital GPIO
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK success
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief Get the RTC IO input level
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - 1 High level
|
|
|
|
* - 0 Low level
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
uint32_t rtc_gpio_get_level(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief Set the RTC IO output level
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
|
|
|
* @param level output level
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_set_level(gpio_num_t gpio_num, uint32_t level);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief RTC GPIO set direction
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* Configure RTC GPIO direction, such as output only, input only,
|
|
|
|
* output and input.
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
* @param mode GPIO direction
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_set_direction(gpio_num_t gpio_num, rtc_gpio_mode_t mode);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief RTC GPIO pullup enable
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02: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-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pullup_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief RTC GPIO pulldown enable
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02: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-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pulldown_en(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief RTC GPIO pullup disable
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02: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-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pullup_dis(gpio_num_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
2016-12-30 01:28:30 +02:00
|
|
|
* @brief RTC GPIO pulldown disable
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02: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-08 23:43:41 +02:00
|
|
|
*
|
2016-12-30 01:28:30 +02:00
|
|
|
* @param gpio_num GPIO number (e.g. GPIO_NUM_12)
|
2016-12-08 23:43:41 +02:00
|
|
|
*
|
|
|
|
* @return
|
2016-12-30 01:28:30 +02:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
|
2016-12-08 23:43:41 +02:00
|
|
|
*/
|
|
|
|
esp_err_t rtc_gpio_pulldown_dis(gpio_num_t gpio_num);
|
|
|
|
|
2016-12-30 01:28:30 +02:00
|
|
|
/**
|
|
|
|
* @brief Disable "hold" signal for all RTC IOs
|
|
|
|
*
|
|
|
|
* Each RTC pad has a "hold" input signal from the RTC controller.
|
|
|
|
* If hold signal is set, pad latches current values of input enable,
|
|
|
|
* function, output enable, and other signals which come from the RTC mux.
|
|
|
|
* Hold signal is enabled before going into deep sleep for pins which
|
|
|
|
* are used for EXT1 wakeup.
|
|
|
|
*/
|
|
|
|
void rtc_gpio_unhold_all();
|
|
|
|
|
|
|
|
|
2016-12-08 23:43:41 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|