kopia lustrzana https://github.com/espressif/esp-idf
Delete unneeded code fragments from GPIO-example
Closes https://github.com/espressif/esp-idf/pull/2822pull/3589/head
rodzic
9ade9f68b3
commit
4f8d5d25c4
|
@ -29,19 +29,10 @@
|
|||
|
||||
/**
|
||||
* Brief:
|
||||
* This test code shows how to configure gpio and how to use gpio interrupt.
|
||||
*
|
||||
* GPIO status:
|
||||
* GPIO18: output
|
||||
* GPIO19: output
|
||||
* GPIO4: input, pulled up, interrupt from rising edge and falling edge
|
||||
* GPIO5: input, pulled up, interrupt from rising edge.
|
||||
*
|
||||
* Test:
|
||||
* Connect GPIO18 with GPIO4
|
||||
* Connect GPIO19 with GPIO5
|
||||
* Generate pulses on GPIO18/19, that triggers interrupt on GPIO4/5
|
||||
*
|
||||
* This example Implemented BLE HID device profile related functions, in which the HID device
|
||||
* has 4 Reports (1 is mouse, 2 is keyboard and LED, 3 is Consumer Devices, 4 is Vendor devices).
|
||||
* Users can choose different reports according to their own application scenarios.
|
||||
* BLE HID profile inheritance and USB HID class.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -58,15 +49,6 @@
|
|||
#define HID_DEMO_TAG "HID_DEMO"
|
||||
|
||||
|
||||
#define GPIO_OUTPUT_IO_0 18
|
||||
#define GPIO_OUTPUT_IO_1 19
|
||||
#define GPIO_OUTPUT_PIN_SEL ((1<<GPIO_OUTPUT_IO_0) | (1<<GPIO_OUTPUT_IO_1))
|
||||
#define GPIO_INPUT_IO_0 21
|
||||
#define GPIO_INPUT_IO_1 27
|
||||
#define GPIO_INPUT_PIN_SEL ((1<<GPIO_INPUT_IO_0) | (1<<GPIO_INPUT_IO_1))
|
||||
#define ESP_INTR_FLAG_DEFAULT 0
|
||||
|
||||
static xQueueHandle gpio_evt_queue = NULL;
|
||||
static uint16_t hid_conn_id = 0;
|
||||
static bool sec_conn = false;
|
||||
static bool send_volum_up = false;
|
||||
|
@ -108,75 +90,6 @@ static esp_ble_adv_params_t hidd_adv_params = {
|
|||
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
|
||||
};
|
||||
|
||||
void IRAM_ATTR gpio_isr_handler(void* arg)
|
||||
{
|
||||
uint32_t gpio_num = (uint32_t) arg;
|
||||
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
|
||||
}
|
||||
|
||||
void gpio_task_example(void* arg)
|
||||
{
|
||||
static uint8_t i = 0;
|
||||
uint32_t io_num;
|
||||
for(;;) {
|
||||
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
|
||||
ESP_LOGI(HID_DEMO_TAG, "GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
|
||||
if(i == 0) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void gpio_demo_init(void)
|
||||
{
|
||||
gpio_config_t io_conf;
|
||||
//disable interrupt
|
||||
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||
//set as output mode
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
//bit mask of the pins that you want to set,e.g.GPIO18/19
|
||||
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
|
||||
//disable pull-down mode
|
||||
io_conf.pull_down_en = 0;
|
||||
//disable pull-up mode
|
||||
io_conf.pull_up_en = 0;
|
||||
//configure GPIO with the given settings
|
||||
gpio_config(&io_conf);
|
||||
|
||||
//interrupt of rising edge
|
||||
io_conf.intr_type = GPIO_PIN_INTR_POSEDGE;
|
||||
//bit mask of the pins, use GPIO4/5 here
|
||||
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
|
||||
//set as input mode
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
//enable pull-up mode
|
||||
io_conf.pull_up_en = 1;
|
||||
gpio_config(&io_conf);
|
||||
|
||||
//change gpio intrrupt type for one pin
|
||||
gpio_set_intr_type(GPIO_INPUT_IO_0, GPIO_INTR_ANYEDGE);
|
||||
|
||||
//create a queue to handle gpio event from isr
|
||||
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
|
||||
//start gpio task
|
||||
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
|
||||
|
||||
//install gpio isr service
|
||||
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
|
||||
//hook isr handler for specific gpio pin
|
||||
gpio_isr_handler_add(GPIO_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0);
|
||||
//hook isr handler for specific gpio pin
|
||||
gpio_isr_handler_add(GPIO_INPUT_IO_1, gpio_isr_handler, (void*) GPIO_INPUT_IO_1);
|
||||
|
||||
//remove isr handler for gpio number.
|
||||
gpio_isr_handler_remove(GPIO_INPUT_IO_0);
|
||||
//hook isr handler for specific gpio pin again
|
||||
gpio_isr_handler_add(GPIO_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void hidd_event_callback(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *param)
|
||||
{
|
||||
|
@ -333,9 +246,6 @@ void app_main()
|
|||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
|
||||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));
|
||||
|
||||
//init the gpio pin
|
||||
gpio_demo_init();
|
||||
xTaskCreate(&hid_demo_task, "hid_task", 2048, NULL, 5, NULL);
|
||||
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue