MeterLogger
gpio.h
Go to the documentation of this file.
1 /*
2  * ESPRSSIF 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 #ifndef _GPIO_H_
26 #define _GPIO_H_
27 
28 #define GPIO_PIN_ADDR(i) (GPIO_PIN0_ADDRESS + i*4)
29 
30 #define GPIO_ID_IS_PIN_REGISTER(reg_id) \
31  ((reg_id >= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT-1)))
32 
33 #define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id) - GPIO_ID_PIN0)
34 
35 typedef enum {
43 
44 #define GPIO_OUTPUT_SET(gpio_no, bit_value) \
45  gpio_output_set((bit_value)<<gpio_no, ((~(bit_value))&0x01)<<gpio_no, 1<<gpio_no,0)
46 #define GPIO_DIS_OUTPUT(gpio_no) gpio_output_set(0,0,0, 1<<gpio_no)
47 #define GPIO_INPUT_GET(gpio_no) ((gpio_input_get()>>gpio_no)&BIT0)
48 
49 /* GPIO interrupt handler, registered through gpio_intr_handler_register */
50 typedef void (* gpio_intr_handler_fn_t)(uint32 intr_mask, void *arg);
51 
52 
53 /*
54  * Initialize GPIO. This includes reading the GPIO Configuration DataSet
55  * to initialize "output enables" and pin configurations for each gpio pin.
56  * Must be called once during startup.
57  */
58 void gpio_init(void);
59 
60 /*
61  * Change GPIO pin output by setting, clearing, or disabling pins.
62  * In general, it is expected that a bit will be set in at most one
63  * of these masks. If a bit is clear in all masks, the output state
64  * remains unchanged.
65  *
66  * There is no particular ordering guaranteed; so if the order of
67  * writes is significant, calling code should divide a single call
68  * into multiple calls.
69  */
70 void gpio_output_set(uint32 set_mask,
71  uint32 clear_mask,
72  uint32 enable_mask,
73  uint32 disable_mask);
74 
75 /*
76  * Sample the value of GPIO input pins and returns a bitmask.
77  */
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 reg_id, uint32 value);
87 
88 /* Get the current value of the specified GPIO register. */
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. */
106 
107 /*
108  * Acknowledge GPIO interrupts.
109  * Intended to be called from the gpio_intr_handler_fn.
110  */
111 void gpio_intr_ack(uint32 ack_mask);
112 
113 void gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state);
114 
116 
117 void gpio_pin_intr_state_set(uint32 i, GPIO_INT_TYPE intr_state);
118 
119 #endif // _GPIO_H_
GPIO_INT_TYPE
Definition: gpio.h:35
void gpio_init(void)
void gpio_pin_intr_state_set(uint32 i, GPIO_INT_TYPE intr_state)
void gpio_register_set(uint32 reg_id, uint32 value)
void(* gpio_intr_handler_fn_t)(uint32 intr_mask, void *arg)
Definition: gpio.h:50
void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg)
uint32 gpio_register_get(uint32 reg_id)
unsigned int uint32
Definition: c_types.h:54
uint32 gpio_intr_pending(void)
uint32 gpio_input_get(void)
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
void gpio_intr_ack(uint32 ack_mask)
void gpio_pin_wakeup_disable()
void gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state)