]> granicus.if.org Git - esp-idf/commitdiff
feat(gpio): add function allowing switching input source from GPIO back to IOMUX
authorMichael (XIAO Xufeng) <xiaoxufeng@espressif.com>
Mon, 23 Apr 2018 17:23:12 +0000 (01:23 +0800)
committermichael <xiaoxufeng@espressif.com>
Tue, 8 May 2018 07:47:25 +0000 (15:47 +0800)
components/driver/gpio.c
components/driver/include/driver/gpio.h

index 9563b1506676258a019ab8a361fbe769e464ec85..e017cd87dff6628d78ba042cec370dee9bb90068 100644 (file)
@@ -546,4 +546,17 @@ esp_err_t gpio_hold_dis(gpio_num_t gpio_num)
         r = ESP_ERR_NOT_SUPPORTED;
     }
     return r == ESP_OK ? ESP_OK : ESP_ERR_NOT_SUPPORTED;
-}
\ No newline at end of file
+}
+
+void gpio_iomux_in(uint32_t gpio, uint32_t signal_idx)
+{
+    GPIO.func_in_sel_cfg[signal_idx].sig_in_sel = 0;
+    PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio]);
+}
+
+void gpio_iomux_out(uint8_t gpio_num, int func, bool oen_inv)
+{
+    GPIO.func_out_sel_cfg[gpio_num].oen_sel = 0;
+    GPIO.func_out_sel_cfg[gpio_num].oen_inv_sel = oen_inv;
+    PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[gpio_num], func);
+}
index f8900d32e87eaf4d377b4e239965f6a078211d99..d5cb7c08c03668f3a0d8dc3628291a81198894f5 100644 (file)
@@ -31,11 +31,11 @@ extern "C" {
 
 #define GPIO_SEL_0              (BIT(0))                         /*!< Pin 0 selected */
 #define GPIO_SEL_1              (BIT(1))                         /*!< Pin 1 selected */
-#define GPIO_SEL_2              (BIT(2))                         /*!< Pin 2 selected 
+#define GPIO_SEL_2              (BIT(2))                         /*!< Pin 2 selected
                                                                       @note There are more macros
                                                                       like that up to pin 39,
                                                                       excluding pins 20, 24 and 28..31.
-                                                                      They are not shown here 
+                                                                      They are not shown here
                                                                       to reduce redundant information. */
 /** @cond */
 #define GPIO_SEL_3              (BIT(3))                         /*!< Pin 3 selected */
@@ -172,7 +172,7 @@ typedef enum {
     GPIO_NUM_38 = 38,   /*!< GPIO38, input mode only */
     GPIO_NUM_39 = 39,   /*!< GPIO39, input mode only */
     GPIO_NUM_MAX = 40,
-/** @endcond */    
+/** @endcond */
 } gpio_num_t;
 
 typedef enum {
@@ -550,6 +550,22 @@ esp_err_t gpio_hold_en(gpio_num_t gpio_num);
   */
  esp_err_t gpio_hold_dis(gpio_num_t gpio_num);
 
+/**
+  * @brief Set pad input to a peripheral signal through the IOMUX.
+  * @param gpio_num GPIO number of the pad.
+  * @param signal_idx Peripheral signal id to input. One of the ``*_IN_IDX`` signals in ``soc/gpio_sig_map.h``.
+  */
+void gpio_iomux_in(uint32_t gpio_num, uint32_t signal_idx);
+
+/**
+  * @brief Set peripheral output to an GPIO pad through the IOMUX.
+  * @param gpio_num gpio_num GPIO number of the pad.
+  * @param func The function number of the peripheral pin to output pin.
+  *        One of the ``FUNC_X_*`` of specified pin (X) in ``soc/io_mux_reg.h``.
+  * @param oen_inv True if the output enable needs to be inversed, otherwise False.
+  */
+void gpio_iomux_out(uint8_t gpio_num, int func, bool oen_inv);
+
 #ifdef __cplusplus
 }
 #endif