Remove some macros and declarations that are already in rom/gpio.h

This commit is contained in:
Wangjialin 2016-09-21 12:08:42 +08:00
parent f7b10745be
commit 92569082c6
2 changed files with 47 additions and 72 deletions

View file

@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <esp_types.h> #include <esp_types.h>
#include "rom/ets_sys.h"
#include "esp_err.h" #include "esp_err.h"
#include "esp_intr.h" #include "esp_intr.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/xtensa_api.h" #include "freertos/xtensa_api.h"
#include "soc/soc.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "soc/soc.h"
//TODO: move debug options to menuconfig //TODO: move debug options to menuconfig
#define GPIO_DBG_ENABLE (0) #define GPIO_DBG_ENABLE (0)
@ -105,7 +104,7 @@ esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type)
{ {
if(!is_valid_gpio(gpio_num)) if(!is_valid_gpio(gpio_num))
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
if(intr_type >= GPIO_PIN_INTR_MAX) { if(intr_type >= GPIO_INTR_MAX) {
GPIO_ERROR("Unknown GPIO intr:%u\n",intr_type); GPIO_ERROR("Unknown GPIO intr:%u\n",intr_type);
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
@ -320,7 +319,7 @@ esp_err_t gpio_config(gpio_config_t *pGPIOConfig)
return ESP_OK; return ESP_OK;
} }
esp_err_t gpio_intr_handler_register(uint32_t gpio_intr_num, void (*fn)(void*), void * arg) esp_err_t gpio_isr_register(uint32_t gpio_intr_num, void (*fn)(void*), void * arg)
{ {
if(fn == NULL) if(fn == NULL)
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
@ -332,12 +331,12 @@ esp_err_t gpio_intr_handler_register(uint32_t gpio_intr_num, void (*fn)(void*),
} }
/*only level interrupt can be used for wake-up function*/ /*only level interrupt can be used for wake-up function*/
esp_err_t gpio_pin_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type) esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
{ {
if(!is_valid_gpio(gpio_num)) if(!is_valid_gpio(gpio_num))
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
if((intr_type == GPIO_PIN_INTR_LOW_LEVEL) || (intr_type == GPIO_PIN_INTR_HIGH_LEVEL)) { if((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) {
GPIO.pin[gpio_num].int_type = intr_type; GPIO.pin[gpio_num].int_type = intr_type;
GPIO.pin[gpio_num].wakeup_enable = 0x1; GPIO.pin[gpio_num].wakeup_enable = 0x1;
} else { } else {
@ -347,7 +346,7 @@ esp_err_t gpio_pin_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
return ret; return ret;
} }
esp_err_t gpio_pin_wakeup_disable(gpio_num_t gpio_num) esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num)
{ {
if(!is_valid_gpio(gpio_num)) if(!is_valid_gpio(gpio_num))
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;

View file

@ -20,6 +20,7 @@
#include "soc/gpio_struct.h" #include "soc/gpio_struct.h"
#include "soc/rtc_io_reg.h" #include "soc/rtc_io_reg.h"
#include "soc/io_mux_reg.h" #include "soc/io_mux_reg.h"
#include "rom/gpio.h"
#include "esp_attr.h" #include "esp_attr.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -108,15 +109,11 @@ extern "C" {
#define GPIO_PRO_CPU_NMI_INTR_ENA (BIT(3)) #define GPIO_PRO_CPU_NMI_INTR_ENA (BIT(3))
#define GPIO_SDIO_EXT_INTR_ENA (BIT(4)) #define GPIO_SDIO_EXT_INTR_ENA (BIT(4))
#define GPIO_PIN_COUNT 40
#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_MODE_DEF_INPUT (BIT0) #define GPIO_MODE_DEF_INPUT (BIT0)
#define GPIO_MODE_DEF_OUTPUT (BIT1) #define GPIO_MODE_DEF_OUTPUT (BIT1)
#define GPIO_MODE_DEF_OD (BIT2) #define GPIO_MODE_DEF_OD (BIT2)
#define GPIO_PIN_COUNT 40
extern const uint32_t GPIO_PIN_MUX_REG[GPIO_PIN_COUNT]; extern const uint32_t GPIO_PIN_MUX_REG[GPIO_PIN_COUNT];
typedef enum { typedef enum {
@ -160,13 +157,13 @@ typedef enum {
} gpio_num_t; } gpio_num_t;
typedef enum { typedef enum {
GPIO_PIN_INTR_DISABLE = 0, /* disable GPIO interrupt */ GPIO_INTR_DISABLE = 0, /* disable GPIO interrupt */
GPIO_PIN_INTR_POSEDGE = 1, /* GPIO interrupt type : rising edge */ GPIO_INTR_POSEDGE = 1, /* GPIO interrupt type : rising edge */
GPIO_PIN_INTR_NEGEDGE = 2, /* GPIO interrupt type : falling edge */ GPIO_INTR_NEGEDGE = 2, /* GPIO interrupt type : falling edge */
GPIO_PIN_INTR_ANYEDGE = 3, /* GPIO interrupt type : both rising and falling edge */ GPIO_INTR_ANYEDGE = 3, /* GPIO interrupt type : both rising and falling edge */
GPIO_PIN_INTR_LOW_LEVEL = 4, /* GPIO interrupt type : input low level trigger */ GPIO_INTR_LOW_LEVEL = 4, /* GPIO interrupt type : input low level trigger */
GPIO_PIN_INTR_HIGH_LEVEL = 5, /* GPIO interrupt type : input high level trigger */ GPIO_INTR_HIGH_LEVEL = 5, /* GPIO interrupt type : input high level trigger */
GPIO_PIN_INTR_MAX, GPIO_INTR_MAX,
} gpio_int_type_t; } gpio_int_type_t;
typedef enum { typedef enum {
@ -341,44 +338,26 @@ esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode);
esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull); esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull);
/** /**
* @brief bind input signal to the GPIO * @brief enable GPIO wake-up function.
* *
* bind input signal to the GPIO,when you want to bind the signal to the GPIO * @param gpio_num_t gpio_num : GPIO number.
* First , configure the pad as GPIO,use the gpio_config function or pin_func_as_gpio function *
* Second , enable the GPIO input,if you use pin_func_as_gpio,you can use gpio_set_direction function * @param gpio_int_type_t intr_type : only GPIO_INTR_LOLEVEL\GPIO_INTR_HILEVEL can be used
* Third , call gpio_matrix_in function *
* * @return ESP_OK: success
* @parameter[in] GPIO : Configure GPIO pins number,it should be GPIO number. * ESP_ERR_INVALID_ARG: parameter error
* If you want to configure GPIO16, gpio_num should be GPIO_NUM_16 (16); */
* @parameter[in] signal_idx : the signal_idx,find the signal index from gpio_sig_map.h esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
*
* @parameter[in] inverse : the signal input inverse, default inverse=0
*
* @return None
*
*/
void gpio_matrix_in(uint32_t GPIO, uint32_t signal_idx, bool inverse) ROMFN_ATTR;
/** /**
* @brief bind output signal to the GPIO * @brief disable GPIO wake-up function.
* *
* bind output signal to the GPIO,when you want to bind the signal to the GPIO * @param gpio_num_t gpio_num: GPIO number
* First , configure the pad as GPIO,use the gpio_config function or pin_func_as_gpio function *
* Second , enable the GPIO output,if you use pin_func_as_gpio,you can use gpio_set_direction function * @return ESP_OK: success
* Third , call gpio_matrix_out function * ESP_ERR_INVALID_ARG: parameter error
* */
* @parameter[in] GPIO : Configure GPIO pins number,it should GPIO number. esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num);
* If you want to configure GPIO16,gpio_num should be GPIO_NUM_16 (16);
* @parameter[in] signal_idx : the signal_idx,find the signal index from gpio_sig_map.h
*
* @parameter[in] out_inv : the signal output inverse, default out_inv=0
*
* @parameter[in] oen_inv : the signal output enable inverse, default oen_inv=0
*
* @return None
*
*/
void gpio_matrix_out(uint32_t GPIO, uint32_t signal_idx, bool out_inv, bool oen_inv) ROMFN_ATTR;
/** /**
* @brief register GPIO interrupt handler, the handler is an ISR. * @brief register GPIO interrupt handler, the handler is an ISR.
@ -392,27 +371,24 @@ void gpio_matrix_out(uint32_t GPIO, uint32_t signal_idx, bool out_inv, bool oen_
* @parameter void * arg : parameter for handler function * @parameter void * arg : parameter for handler function
* *
* @return ESP_OK : success ; * @return ESP_OK : success ;
* ESP_FAIL: gpio_ error * ESP_FAIL: gpio error
*/ */
esp_err_t gpio_intr_handler_register(uint32_t gpio_intr_num, void (*fn)(void*), void * arg); esp_err_t gpio_isr_register(uint32_t gpio_intr_num, void (*fn)(void*), void * arg);
/** /**
* *************** ATTENTION ********************/ * *************** ATTENTION ********************/
/** /**
* *
* Each GPIO have their separated registers, so we don't have to use * Each GPIO has its own separate configuration register, so we do not use
* lock for multi-task issues. * a lock to serialize access to them. This works under the assumption that
* Please make sure that there would be no such situation, in which, * no situation will occur where two tasks try to configure the same GPIO
* different tasks read-then-write the same GPIO register. * pin simultaneously. It is up to the application developer to guarantee this.
*/ */
/*----------EXAMPLE TO CONIFGURE GPIO AS OUTPUT ------------ */ /*----------EXAMPLE TO CONIFGURE GPIO AS OUTPUT ------------ */
/* gpio_config_t io_conf; /* gpio_config_t io_conf;
* io_conf.intr_type = GPIO_PIN_INTR_DISABLE; //disable interrupt * io_conf.intr_type = GPIO_INTR_DISABLE; //disable interrupt
* io_conf.mode = GPIO_MODE_OUTPUT; //set as output mode * io_conf.mode = GPIO_MODE_OUTPUT; //set as output mode
* io_conf.pin_bit_mask = GPIO_SEL_18 | GPIO_SEL_19; //bit mask of the pins that you want to set,e.g.GPIO18/19 * io_conf.pin_bit_mask = GPIO_SEL_18 | GPIO_SEL_19; //bit mask of the pins that you want to set,e.g.GPIO18/19
* io_conf.pull_down_en = 0; //disable pull-down mode * io_conf.pull_down_en = 0; //disable pull-down mode
@ -420,14 +396,14 @@ esp_err_t gpio_intr_handler_register(uint32_t gpio_intr_num, void (*fn)(void*),
* gpio_config(&io_conf); //configure GPIO with the given settings * gpio_config(&io_conf); //configure GPIO with the given settings
**/ **/
/*----------EXAMPLE TO CONIFGURE GPIO AS OUTPUT ------------ */ /*----------EXAMPLE TO CONIFGURE GPIO AS OUTPUT ------------ */
/* io_conf.intr_type = GPIO_PIN_INTR_POSEDGE; //set posedge interrupt /* io_conf.intr_type = GPIO_INTR_POSEDGE; //set posedge interrupt
* io_conf.mode = GPIO_MODE_INPUT; //set as input * io_conf.mode = GPIO_MODE_INPUT; //set as input
* io_conf.pin_bit_mask = GPIO_SEL_4 | GPIO_SEL_5; //bit mask of the pins that you want to set, e.g.,GPIO4/5 * io_conf.pin_bit_mask = GPIO_SEL_4 | GPIO_SEL_5; //bit mask of the pins that you want to set, e.g.,GPIO4/5
* io_conf.pull_down_en = 0; //disable pull-down mode * io_conf.pull_down_en = 0; //disable pull-down mode
* io_conf.pull_up_en = 1; //enable pull-up mode * io_conf.pull_up_en = 1; //enable pull-up mode
* gpio_config(&io_conf); //configure GPIO with the given settings * gpio_config(&io_conf); //configure GPIO with the given settings
*----------EXAMPLE TO SET ISR HANDLER ----------------------*/ *----------EXAMPLE TO SET ISR HANDLER ----------------------*/
/* gpio_intr_handler_register(18,gpio_intr_test,NULL); //hook the isr handler for GPIO interrupt /* gpio_isr_register(18,gpio_intr_test,NULL); //hook the isr handler for GPIO interrupt
* //the first parameter is INUM, you can pick one form interrupt level 1/2 which is not used by the system. * //the first parameter is INUM, you can pick one form interrupt level 1/2 which is not used by the system.
* //NOTE1:user should arrange the INUMs that used, better not to use a same INUM for different interrupt. * //NOTE1:user should arrange the INUMs that used, better not to use a same INUM for different interrupt.
* //NOTE2:do not pick the INUM that already occupied by the system. * //NOTE2:do not pick the INUM that already occupied by the system.
@ -446,20 +422,20 @@ esp_err_t gpio_intr_handler_register(uint32_t gpio_intr_num, void (*fn)(void*),
* do { * do {
* if(gpio_num < 32) { * if(gpio_num < 32) {
* if(gpio_intr_status & BIT(gpio_num)) { //gpio0-gpio31 * if(gpio_intr_status & BIT(gpio_num)) { //gpio0-gpio31
* ets_printf("Intr Gpio%d ,val: %d\n",gpio_num,gpio_get_level(gpio_num)); * ets_printf("Intr GPIO%d ,val: %d\n",gpio_num,gpio_get_level(gpio_num));
* //This is a 'isr' handler, you should post an event to process it in RTOS queue. * //This is an isr handler, you should post an event to process it in RTOS queue.
* } * }
* } else { * } else {
* if(gpio_intr_status_h & BIT(gpio_num - 32)) { * if(gpio_intr_status_h & BIT(gpio_num - 32)) {
* ets_printf("Intr Gpio%d, val : %d\n",gpio_num,gpio_get_level(gpio_num)); * ets_printf("Intr GPIO%d, val : %d\n",gpio_num,gpio_get_level(gpio_num));
* //This is a 'isr' handler, you should post an event to process it in RTOS queue. * //This is an isr handler, you should post an event to process it in RTOS queue.
* } * }
* } * }
* } while(++gpio_num < GPIO_PIN_COUNT); * } while(++gpio_num < GPIO_PIN_COUNT);
*} *}
*----EXAMPLE OF I2C CONFIG AND PICK SIGNAL FOR IO MATRIX---*/ *----EXAMPLE OF I2C CONFIG AND PICK SIGNAL FOR IO MATRIX---*/
/* gpio_config_t io_conf; /* gpio_config_t io_conf;
* io_conf.intr_type = GPIO_PIN_INTR_DISABLE; //disable interrupt * io_conf.intr_type = GPIO_INTR_DISABLE; //disable interrupt
* io_conf.mode = GPIO_MODE_INPUT_OUTPUT_OD; //set as output mode * io_conf.mode = GPIO_MODE_INPUT_OUTPUT_OD; //set as output mode
* io_conf.pin_bit_mask = GPIO_SEL_21 | GPIO_SEL_22; //bit mask of the pins that you want to set,e.g.GPIO21/22 * io_conf.pin_bit_mask = GPIO_SEL_21 | GPIO_SEL_22; //bit mask of the pins that you want to set,e.g.GPIO21/22
* io_conf.pull_down_en = 0; //disable pull-down mode * io_conf.pull_down_en = 0; //disable pull-down mode