2019-03-14 09:29:32 +00:00
|
|
|
// Copyright 2010-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 _ROM_GPIO_H_
|
|
|
|
#define _ROM_GPIO_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
global: move the soc component out of the common list
This MR removes the common dependency from every IDF components to the SOC component.
Currently, in the ``idf_functions.cmake`` script, we include the header path of SOC component by default for all components.
But for better code organization (or maybe also benifits to the compiling speed), we may remove the dependency to SOC components for most components except the driver and kernel related components.
In CMAKE, we have two kinds of header visibilities (set by include path visibility):
(Assume component A --(depends on)--> B, B is the current component)
1. public (``COMPONENT_ADD_INCLUDEDIRS``): means this path is visible to other depending components (A) (visible to A and B)
2. private (``COMPONENT_PRIV_INCLUDEDIRS``): means this path is only visible to source files inside the component (visible to B only)
and we have two kinds of depending ways:
(Assume component A --(depends on)--> B --(depends on)--> C, B is the current component)
1. public (```COMPONENT_REQUIRES```): means B can access to public include path of C. All other components rely on you (A) will also be available for the public headers. (visible to A, B)
2. private (``COMPONENT_PRIV_REQUIRES``): means B can access to public include path of C, but don't propagate this relation to other components (A). (visible to B)
1. remove the common requirement in ``idf_functions.cmake``, this makes the SOC components invisible to all other components by default.
2. if a component (for example, DRIVER) really needs the dependency to SOC, add a private dependency to SOC for it.
3. some other components that don't really depends on the SOC may still meet some errors saying "can't find header soc/...", this is because it's depended component (DRIVER) incorrectly include the header of SOC in its public headers. Moving all this kind of #include into source files, or private headers
4. Fix the include requirements for some file which miss sufficient #include directives. (Previously they include some headers by the long long long header include link)
This is a breaking change. Previous code may depends on the long include chain.
You may need to include the following headers for some files after this commit:
- soc/soc.h
- soc/soc_memory_layout.h
- driver/gpio.h
- esp_sleep.h
The major broken include chain includes:
1. esp_system.h no longer includes esp_sleep.h. The latter includes driver/gpio.h and driver/touch_pad.h.
2. ets_sys.h no longer includes soc/soc.h
3. freertos/portmacro.h no longer includes soc/soc_memory_layout.h
some peripheral headers no longer includes their hw related headers, e.g. rom/gpio.h no longer includes soc/gpio_pins.h and soc/gpio_reg.h
BREAKING CHANGE
2019-04-03 05:17:38 +00:00
|
|
|
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_LEGACY_INCLUDE_COMMON_HEADERS
|
2019-03-14 09:29:32 +00:00
|
|
|
#include "soc/gpio_reg.h"
|
2020-04-20 06:01:09 +00:00
|
|
|
#include "soc/gpio_caps.h"
|
global: move the soc component out of the common list
This MR removes the common dependency from every IDF components to the SOC component.
Currently, in the ``idf_functions.cmake`` script, we include the header path of SOC component by default for all components.
But for better code organization (or maybe also benifits to the compiling speed), we may remove the dependency to SOC components for most components except the driver and kernel related components.
In CMAKE, we have two kinds of header visibilities (set by include path visibility):
(Assume component A --(depends on)--> B, B is the current component)
1. public (``COMPONENT_ADD_INCLUDEDIRS``): means this path is visible to other depending components (A) (visible to A and B)
2. private (``COMPONENT_PRIV_INCLUDEDIRS``): means this path is only visible to source files inside the component (visible to B only)
and we have two kinds of depending ways:
(Assume component A --(depends on)--> B --(depends on)--> C, B is the current component)
1. public (```COMPONENT_REQUIRES```): means B can access to public include path of C. All other components rely on you (A) will also be available for the public headers. (visible to A, B)
2. private (``COMPONENT_PRIV_REQUIRES``): means B can access to public include path of C, but don't propagate this relation to other components (A). (visible to B)
1. remove the common requirement in ``idf_functions.cmake``, this makes the SOC components invisible to all other components by default.
2. if a component (for example, DRIVER) really needs the dependency to SOC, add a private dependency to SOC for it.
3. some other components that don't really depends on the SOC may still meet some errors saying "can't find header soc/...", this is because it's depended component (DRIVER) incorrectly include the header of SOC in its public headers. Moving all this kind of #include into source files, or private headers
4. Fix the include requirements for some file which miss sufficient #include directives. (Previously they include some headers by the long long long header include link)
This is a breaking change. Previous code may depends on the long include chain.
You may need to include the following headers for some files after this commit:
- soc/soc.h
- soc/soc_memory_layout.h
- driver/gpio.h
- esp_sleep.h
The major broken include chain includes:
1. esp_system.h no longer includes esp_sleep.h. The latter includes driver/gpio.h and driver/touch_pad.h.
2. ets_sys.h no longer includes soc/soc.h
3. freertos/portmacro.h no longer includes soc/soc_memory_layout.h
some peripheral headers no longer includes their hw related headers, e.g. rom/gpio.h no longer includes soc/gpio_pins.h and soc/gpio_reg.h
BREAKING CHANGE
2019-04-03 05:17:38 +00:00
|
|
|
#endif
|
2019-03-14 09:29:32 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** \defgroup gpio_apis, uart configuration and communication related apis
|
|
|
|
* @brief gpio apis
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @addtogroup gpio_apis
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define GPIO_REG_READ(reg) READ_PERI_REG(reg)
|
|
|
|
#define GPIO_REG_WRITE(reg, val) WRITE_PERI_REG(reg, val)
|
|
|
|
#define GPIO_ID_PIN0 0
|
|
|
|
#define GPIO_ID_PIN(n) (GPIO_ID_PIN0+(n))
|
|
|
|
#define GPIO_PIN_ADDR(i) (GPIO_PIN0_REG + i*4)
|
|
|
|
|
|
|
|
#define GPIO_FUNC_IN_HIGH 0x38
|
|
|
|
#define GPIO_FUNC_IN_LOW 0x30
|
|
|
|
|
|
|
|
#define GPIO_ID_IS_PIN_REGISTER(reg_id) \
|
|
|
|
((reg_id >= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT-1)))
|
|
|
|
|
|
|
|
#define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id) - GPIO_ID_PIN0)
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GPIO_PIN_INTR_DISABLE = 0,
|
|
|
|
GPIO_PIN_INTR_POSEDGE = 1,
|
|
|
|
GPIO_PIN_INTR_NEGEDGE = 2,
|
|
|
|
GPIO_PIN_INTR_ANYEDGE = 3,
|
|
|
|
GPIO_PIN_INTR_LOLEVEL = 4,
|
|
|
|
GPIO_PIN_INTR_HILEVEL = 5
|
|
|
|
} GPIO_INT_TYPE;
|
|
|
|
|
|
|
|
#define GPIO_OUTPUT_SET(gpio_no, bit_value) \
|
|
|
|
((gpio_no < 32) ? gpio_output_set(bit_value<<gpio_no, (bit_value ? 0 : 1)<<gpio_no, 1<<gpio_no,0) : \
|
|
|
|
gpio_output_set_high(bit_value<<(gpio_no - 32), (bit_value ? 0 : 1)<<(gpio_no - 32), 1<<(gpio_no -32),0))
|
|
|
|
#define GPIO_DIS_OUTPUT(gpio_no) ((gpio_no < 32) ? gpio_output_set(0,0,0, 1<<gpio_no) : gpio_output_set_high(0,0,0, 1<<(gpio_no - 32)))
|
|
|
|
#define GPIO_INPUT_GET(gpio_no) ((gpio_no < 32) ? ((gpio_input_get()>>gpio_no)&BIT0) : ((gpio_input_get_high()>>(gpio_no - 32))&BIT0))
|
|
|
|
|
|
|
|
/* GPIO interrupt handler, registered through gpio_intr_handler_register */
|
|
|
|
typedef void (* gpio_intr_handler_fn_t)(uint32_t intr_mask, bool high, void *arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize GPIO. This includes reading the GPIO Configuration DataSet
|
|
|
|
* to initialize "output enables" and pin configurations for each gpio pin.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param None
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_init(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change GPIO(0-31) pin output by setting, clearing, or disabling pins, GPIO0<->BIT(0).
|
|
|
|
* There is no particular ordering guaranteed; so if the order of writes is significant,
|
|
|
|
* calling code should divide a single call into multiple calls.
|
|
|
|
*
|
|
|
|
* @param uint32_t set_mask : the gpios that need high level.
|
|
|
|
*
|
|
|
|
* @param uint32_t clear_mask : the gpios that need low level.
|
|
|
|
*
|
|
|
|
* @param uint32_t enable_mask : the gpios that need be changed.
|
|
|
|
*
|
|
|
|
* @param uint32_t disable_mask : the gpios that need diable output.
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_output_set(uint32_t set_mask, uint32_t clear_mask, uint32_t enable_mask, uint32_t disable_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change GPIO(32-39) pin output by setting, clearing, or disabling pins, GPIO32<->BIT(0).
|
|
|
|
* There is no particular ordering guaranteed; so if the order of writes is significant,
|
|
|
|
* calling code should divide a single call into multiple calls.
|
|
|
|
*
|
|
|
|
* @param uint32_t set_mask : the gpios that need high level.
|
|
|
|
*
|
|
|
|
* @param uint32_t clear_mask : the gpios that need low level.
|
|
|
|
*
|
|
|
|
* @param uint32_t enable_mask : the gpios that need be changed.
|
|
|
|
*
|
|
|
|
* @param uint32_t disable_mask : the gpios that need diable output.
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_output_set_high(uint32_t set_mask, uint32_t clear_mask, uint32_t enable_mask, uint32_t disable_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sample the value of GPIO input pins(0-31) and returns a bitmask.
|
|
|
|
*
|
|
|
|
* @param None
|
|
|
|
*
|
|
|
|
* @return uint32_t : bitmask for GPIO input pins, BIT(0) for GPIO0.
|
|
|
|
*/
|
|
|
|
uint32_t gpio_input_get(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sample the value of GPIO input pins(32-39) and returns a bitmask.
|
|
|
|
*
|
|
|
|
* @param None
|
|
|
|
*
|
|
|
|
* @return uint32_t : bitmask for GPIO input pins, BIT(0) for GPIO32.
|
|
|
|
*/
|
|
|
|
uint32_t gpio_input_get_high(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Register an application-specific interrupt handler for GPIO pin interrupts.
|
|
|
|
* Once the interrupt handler is called, it will not be called again until after a call to gpio_intr_ack.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param gpio_intr_handler_fn_t fn : gpio application-specific interrupt handler
|
|
|
|
*
|
|
|
|
* @param void *arg : gpio application-specific interrupt handler argument.
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get gpio interrupts which happens but not processed.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param None
|
|
|
|
*
|
|
|
|
* @return uint32_t : bitmask for GPIO pending interrupts, BIT(0) for GPIO0.
|
|
|
|
*/
|
|
|
|
uint32_t gpio_intr_pending(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get gpio interrupts which happens but not processed.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param None
|
|
|
|
*
|
|
|
|
* @return uint32_t : bitmask for GPIO pending interrupts, BIT(0) for GPIO32.
|
|
|
|
*/
|
|
|
|
uint32_t gpio_intr_pending_high(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Ack gpio interrupts to process pending interrupts.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param uint32_t ack_mask: bitmask for GPIO ack interrupts, BIT(0) for GPIO0.
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_intr_ack(uint32_t ack_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Ack gpio interrupts to process pending interrupts.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param uint32_t ack_mask: bitmask for GPIO ack interrupts, BIT(0) for GPIO32.
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_intr_ack_high(uint32_t ack_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set GPIO to wakeup the ESP32.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param uint32_t i: gpio number.
|
|
|
|
*
|
|
|
|
* @param GPIO_INT_TYPE intr_state : only GPIO_PIN_INTR_LOLEVEL\GPIO_PIN_INTR_HILEVEL can be used
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pin_wakeup_enable(uint32_t i, GPIO_INT_TYPE intr_state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief disable GPIOs to wakeup the ESP32.
|
|
|
|
* Please do not call this function in SDK.
|
|
|
|
*
|
|
|
|
* @param None
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pin_wakeup_disable(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief set gpio input to a signal, one gpio can input to several signals.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio : gpio number, 0~0x27
|
|
|
|
* gpio == 0x30, input 0 to signal
|
|
|
|
* gpio == 0x34, ???
|
|
|
|
* gpio == 0x38, input 1 to signal
|
|
|
|
*
|
|
|
|
* @param uint32_t signal_idx : signal index.
|
|
|
|
*
|
|
|
|
* @param bool inv : the signal is inv or not
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_matrix_in(uint32_t gpio, uint32_t signal_idx, bool inv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief set signal output to gpio, one signal can output to several gpios.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio : gpio number, 0~0x27
|
|
|
|
*
|
|
|
|
* @param uint32_t signal_idx : signal index.
|
|
|
|
* signal_idx == 0x100, cancel output put to the gpio
|
|
|
|
*
|
|
|
|
* @param bool out_inv : the signal output is inv or not
|
|
|
|
*
|
|
|
|
* @param bool oen_inv : the signal output enable is inv or not
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_matrix_out(uint32_t gpio, uint32_t signal_idx, bool out_inv, bool oen_inv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Select pad as a gpio function from IOMUX.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio_num : gpio number, 0~0x27
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pad_select_gpio(uint8_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set pad driver capability.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio_num : gpio number, 0~0x27
|
|
|
|
*
|
|
|
|
* @param uint8_t drv : 0-3
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pad_set_drv(uint8_t gpio_num, uint8_t drv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Pull up the pad from gpio number.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio_num : gpio number, 0~0x27
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pad_pullup(uint8_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Pull down the pad from gpio number.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio_num : gpio number, 0~0x27
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pad_pulldown(uint8_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unhold the pad from gpio number.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio_num : gpio number, 0~0x27
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pad_unhold(uint8_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Hold the pad from gpio number.
|
|
|
|
*
|
|
|
|
* @param uint32_t gpio_num : gpio number, 0~0x27
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void gpio_pad_hold(uint8_t gpio_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _ROM_GPIO_H_ */
|