]> granicus.if.org Git - esp-idf/commitdiff
driver(gpio): Add api support digital pad hold function.
authorkooho <2229179028@qq.com>
Tue, 3 Apr 2018 14:09:30 +0000 (22:09 +0800)
committerkooho <2229179028@qq.com>
Tue, 10 Apr 2018 03:31:59 +0000 (11:31 +0800)
components/driver/gpio.c
components/driver/include/driver/gpio.h

index 02c9e64f46388c317d4b0515aeafafe92dadc6ae..e8f6c632cb826f66b4c6bd33f30f0ea1c9dea741 100644 (file)
@@ -482,3 +482,68 @@ esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* stren
     }
     return ESP_OK;
 }
+
+static const uint32_t GPIO_HOLD_MASK[34] = {
+    0,
+    GPIO_SEL_1,
+    0,
+    GPIO_SEL_0,
+    0,
+    GPIO_SEL_8,
+    GPIO_SEL_2,
+    GPIO_SEL_3,
+    GPIO_SEL_4,
+    GPIO_SEL_5,
+    GPIO_SEL_6,
+    GPIO_SEL_7,
+    0,
+    0,
+    0,
+    0,
+    GPIO_SEL_9,
+    GPIO_SEL_10,
+    GPIO_SEL_11,
+    GPIO_SEL_12,
+    0,
+    GPIO_SEL_14,
+    GPIO_SEL_15,
+    GPIO_SEL_16,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+};
+
+esp_err_t gpio_hold_en(gpio_num_t gpio_num)
+{
+    GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "Only output-capable GPIO support this function", ESP_ERR_NOT_SUPPORTED);
+    esp_err_t r = ESP_OK;
+    if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
+        r = rtc_gpio_hold_en(gpio_num);
+    } else if (GPIO_HOLD_MASK[gpio_num]) {
+        SET_PERI_REG_MASK(RTC_IO_DIG_PAD_HOLD_REG, GPIO_HOLD_MASK[gpio_num]);
+    } else {
+        r = ESP_ERR_NOT_SUPPORTED;
+    }
+    return r == ESP_OK ? ESP_OK : ESP_ERR_NOT_SUPPORTED;
+}
+
+esp_err_t gpio_hold_dis(gpio_num_t gpio_num)
+{
+    GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "Only output-capable GPIO support this function", ESP_ERR_NOT_SUPPORTED);
+    esp_err_t r = ESP_OK;
+    if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
+        r = rtc_gpio_hold_dis(gpio_num);
+    } else if (GPIO_HOLD_MASK[gpio_num]) {
+        CLEAR_PERI_REG_MASK(RTC_IO_DIG_PAD_HOLD_REG, GPIO_HOLD_MASK[gpio_num]);
+    } else {
+        r = ESP_ERR_NOT_SUPPORTED;
+    }
+    return r == ESP_OK ? ESP_OK : ESP_ERR_NOT_SUPPORTED;
+}
\ No newline at end of file
index 8246c415ef361c37046fc3f85c9b8bcc48485d08..2f272ef5e7d9cd679dcaa63222cb6834eeb40a5a 100644 (file)
@@ -518,6 +518,35 @@ esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t streng
   */
 esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
 
+/**
+  * @brief Set gpio pad hold function.
+  *
+  * The gpio pad hold function works in both input and output modes, but must be output-capable gpios.
+  * If pad hold enabled:
+  *   in output mode: the output level of the pad will be force locked and can not be changed.
+  *   in input mode: the input value read will not change, regardless the changes of input signal.
+  *
+  * Power down or call gpio_hold_dis will disable this function.
+  *
+  * @param gpio_num GPIO number, only support output-capable GPIOs
+  *
+  * @return
+  *     - ESP_OK Success
+  *     - ESP_ERR_NOT_SUPPORTED Not support pad hold function
+  */
+esp_err_t gpio_hold_en(gpio_num_t gpio_num);
+
+/**
+  * @brief Unset gpio pad hold function.
+  *
+  * @param gpio_num GPIO number, only support output-capable GPIOs
+  *
+  * @return
+  *     - ESP_OK Success
+  *     - ESP_ERR_NOT_SUPPORTED Not support pad hold function
+  */
+ esp_err_t gpio_hold_dis(gpio_num_t gpio_num);
+
 #ifdef __cplusplus
 }
 #endif