コード例 #1
0
ファイル: main.c プロジェクト: ricardoquesada/unijoysticle
static void setup_gpios()
{
    // Input:
    //     4: Joy #2 Pot x
    //
    // Output:
    //     5: Joy #1 Pot X
    //    21: Joy #1 Pot X

    // Output: 5 (LED) and 21
    gpio_config_t io_conf;
    io_conf.intr_type = GPIO_INTR_DISABLE;
    io_conf.mode = GPIO_MODE_OUTPUT;
    io_conf.pin_bit_mask = ((1ULL << GPIO_NUM_21) | (1ULL << GPIO_NUM_5));
    io_conf.pull_down_en = false;
    io_conf.pull_up_en = false;
    ESP_ERROR_CHECK( gpio_config(&io_conf) );

    // Input: read POT X
    io_conf.intr_type = GPIO_INTR_POSEDGE;
    io_conf.mode = GPIO_MODE_INPUT;
    io_conf.pin_bit_mask = 1ULL << GPIO_NUM_18;
    io_conf.pull_down_en = false;
    io_conf.pull_up_en = true;
    ESP_ERROR_CHECK( gpio_config(&io_conf) );

    // install gpio isr service
    ESP_ERROR_CHECK( gpio_install_isr_service(0) );

    //hook isr handler for specific gpio pin
    ESP_ERROR_CHECK( gpio_isr_handler_add(GPIO_NUM_18, gpio_isr_handler_up, (void*) GPIO_NUM_18) );

 //   ESP_ERROR_CHECK( gpio_isr_register(gpio_isr_handler_up, (void*) GPIO_NUM_4, 0, NULL) );
}
コード例 #2
0
ファイル: sdcard.c プロジェクト: xieweimin/esp-adf
esp_err_t sdcard_init(int card_detect_pin, void (*detect_intr_handler)(void *), void *isr_context)
{
    esp_err_t ret = ESP_OK;
    if (card_detect_pin >= 0) {
        gpio_set_direction(card_detect_pin, GPIO_MODE_INPUT);
        if (detect_intr_handler) {
            gpio_set_intr_type(card_detect_pin, GPIO_INTR_ANYEDGE);
            gpio_isr_handler_add(card_detect_pin, detect_intr_handler, isr_context);
            gpio_intr_enable(card_detect_pin);
        }
        gpio_pullup_en(card_detect_pin);
    }
    g_gpio = card_detect_pin;
    return ret;
}