Esp8266/Components/esp8266/include/gpio.h
Go to the documentation of this file.
1 /*
2  * ESPRESSIF MIT License
3  *
4  * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 #pragma once
26 
27 #include <c_types.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define GPIO_PIN_ADDR(i) (GPIO_PIN0_ADDRESS + i * 4)
34 
35 #define GPIO_ID_IS_PIN_REGISTER(reg_id) ((reg_id >= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT - 1)))
36 
37 #define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id)-GPIO_ID_PIN0)
38 
39 typedef enum {
47 
48 #define GPIO_OUTPUT_SET(gpio_no, bit_value) \
49  gpio_output_set((bit_value) << gpio_no, ((~(bit_value)) & 0x01) << gpio_no, 1 << gpio_no, 0)
50 #define GPIO_DIS_OUTPUT(gpio_no) gpio_output_set(0, 0, 0, 1 << gpio_no)
51 #define GPIO_INPUT_GET(gpio_no) ((gpio_input_get() >> gpio_no) & BIT0)
52 
53 /* GPIO interrupt handler, registered through gpio_intr_handler_register */
54 typedef void (*gpio_intr_handler_fn_t)(uint32_t intr_mask, void* arg);
55 
56 /*
57  * Initialize GPIO. This includes reading the GPIO Configuration DataSet
58  * to initialize "output enables" and pin configurations for each gpio pin.
59  * Must be called once during startup.
60  */
61 void gpio_init(void);
62 
63 /*
64  * Change GPIO pin output by setting, clearing, or disabling pins.
65  * In general, it is expected that a bit will be set in at most one
66  * of these masks. If a bit is clear in all masks, the output state
67  * remains unchanged.
68  *
69  * There is no particular ordering guaranteed; so if the order of
70  * writes is significant, calling code should divide a single call
71  * into multiple calls.
72  */
73 void gpio_output_set(uint32_t set_mask, uint32_t clear_mask, uint32_t enable_mask, uint32_t disable_mask);
74 
75 /*
76  * Sample the value of GPIO input pins and returns a bitmask.
77  */
78 uint32_t gpio_input_get(void);
79 
80 /*
81  * Set the specified GPIO register to the specified value.
82  * This is a very general and powerful interface that is not
83  * expected to be used during normal operation. It is intended
84  * mainly for debug, or for unusual requirements.
85  */
86 void gpio_register_set(uint32_t reg_id, uint32_t value);
87 
88 /* Get the current value of the specified GPIO register. */
89 uint32_t gpio_register_get(uint32_t reg_id);
90 
91 /*
92  * Register an application-specific interrupt handler for GPIO pin
93  * interrupts. Once the interrupt handler is called, it will not
94  * be called again until after a call to gpio_intr_ack. Any GPIO
95  * interrupts that occur during the interim are masked.
96  *
97  * The application-specific handler is called with a mask of
98  * pending GPIO interrupts. After processing pin interrupts, the
99  * application-specific handler may wish to use gpio_intr_pending
100  * to check for any additional pending interrupts before it returns.
101  */
103 
104 /* Determine which GPIO interrupts are pending. */
105 uint32_t gpio_intr_pending(void);
106 
107 /*
108  * Acknowledge GPIO interrupts.
109  * Intended to be called from the gpio_intr_handler_fn.
110  */
111 void gpio_intr_ack(uint32_t ack_mask);
112 
113 void gpio_pin_wakeup_enable(uint32_t i, GPIO_INT_TYPE intr_state);
114 
116 
117 void gpio_pin_intr_state_set(uint32_t i, GPIO_INT_TYPE intr_state);
118 
119 #ifdef __cplusplus
120 }
121 #endif
void gpio_pin_wakeup_disable()
@ GPIO_PIN_INTR_DISABLE
Definition: Esp8266/Components/esp8266/include/gpio.h:40
uint32_t gpio_intr_pending(void)
uint32_t gpio_input_get(void)
void gpio_register_set(uint32_t reg_id, uint32_t value)
uint32_t gpio_register_get(uint32_t reg_id)
void gpio_init(void)
@ GPIO_PIN_INTR_NEGEDGE
Definition: Esp8266/Components/esp8266/include/gpio.h:42
GPIO_INT_TYPE
Defines the GPIO interrupt type.
Definition: Esp8266/Components/esp8266/include/gpio.h:39
@ GPIO_PIN_INTR_ANYEDGE
Definition: Esp8266/Components/esp8266/include/gpio.h:43
void gpio_pin_intr_state_set(uint32_t i, GPIO_INT_TYPE intr_state)
void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg)
void gpio_intr_ack(uint32_t ack_mask)
@ GPIO_PIN_INTR_LOLEVEL
Definition: Esp8266/Components/esp8266/include/gpio.h:44
void(* gpio_intr_handler_fn_t)(uint32_t intr_mask, void *arg)
Definition: Esp8266/Components/esp8266/include/gpio.h:54
void gpio_pin_wakeup_enable(uint32_t i, GPIO_INT_TYPE intr_state)
@ GPIO_PIN_INTR_HILEVEL
Definition: Esp8266/Components/esp8266/include/gpio.h:45
void gpio_output_set(uint32_t set_mask, uint32_t clear_mask, uint32_t enable_mask, uint32_t disable_mask)
@ GPIO_PIN_INTR_POSEDGE
Definition: Esp8266/Components/esp8266/include/gpio.h:41