Skip to content
This repository was archived by the owner on Jun 15, 2020. It is now read-only.

Commit a944a0d

Browse files
committed
Use gpio interrupt service instead of registering own ISR
Fixes #58
1 parent 23706f7 commit a944a0d

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

components/camera/camera.c

+17-14
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ static size_t i2s_bytes_per_sample(i2s_sampling_mode_t mode)
115115
}
116116
}
117117

118+
static void vsync_intr_disable()
119+
{
120+
gpio_set_intr_type(s_state->config.pin_vsync, GPIO_INTR_DISABLE);
121+
}
122+
123+
static void vsync_intr_enable()
124+
{
125+
gpio_set_intr_type(s_state->config.pin_vsync, GPIO_INTR_NEGEDGE);
126+
}
127+
128+
118129
esp_err_t camera_probe(const camera_config_t* config, camera_model_t* out_camera_model)
119130
{
120131
if (s_state != NULL) {
@@ -321,13 +332,10 @@ esp_err_t camera_init(const camera_config_t* config)
321332
}
322333

323334
ESP_LOGD(TAG, "Initializing GPIO interrupts");
324-
gpio_set_intr_type(s_state->config.pin_vsync, GPIO_INTR_NEGEDGE);
325-
gpio_intr_enable(s_state->config.pin_vsync);
326-
err = gpio_isr_register(&gpio_isr, (void*) TAG,
327-
ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM,
328-
&s_state->vsync_intr_handle);
335+
vsync_intr_disable();
336+
err = gpio_isr_handler_add(s_state->config.pin_vsync, &gpio_isr, NULL);
329337
if (err != ESP_OK) {
330-
ESP_LOGE(TAG, "gpio_isr_register failed (%x)", err);
338+
ESP_LOGE(TAG, "gpio_isr_handler_add failed (%x)", err);
331339
goto fail;
332340
}
333341

@@ -364,10 +372,7 @@ esp_err_t camera_deinit()
364372
if (s_state->frame_ready) {
365373
vSemaphoreDelete(s_state->frame_ready);
366374
}
367-
if (s_state->vsync_intr_handle) {
368-
esp_intr_disable(s_state->vsync_intr_handle);
369-
esp_intr_free(s_state->vsync_intr_handle);
370-
}
375+
gpio_isr_handler_remove(s_state->config.pin_vsync);
371376
if (s_state->i2s_intr_handle) {
372377
esp_intr_disable(s_state->i2s_intr_handle);
373378
esp_intr_free(s_state->i2s_intr_handle);
@@ -605,7 +610,7 @@ static void i2s_init()
605610
static void i2s_stop()
606611
{
607612
esp_intr_disable(s_state->i2s_intr_handle);
608-
esp_intr_disable(s_state->vsync_intr_handle);
613+
vsync_intr_disable();
609614
i2s_conf_reset();
610615
I2S0.conf.rx_start = 0;
611616
size_t val = SIZE_MAX;
@@ -649,7 +654,7 @@ static void i2s_run()
649654
I2S0.int_ena.in_done = 1;
650655
esp_intr_enable(s_state->i2s_intr_handle);
651656
if (s_state->config.pixel_format == CAMERA_PF_JPEG) {
652-
esp_intr_enable(s_state->vsync_intr_handle);
657+
vsync_intr_enable();
653658
}
654659
I2S0.conf.rx_start = 1;
655660

@@ -684,8 +689,6 @@ static void IRAM_ATTR i2s_isr(void* arg)
684689

685690
static void IRAM_ATTR gpio_isr(void* arg)
686691
{
687-
GPIO.status1_w1tc.val = GPIO.status1.val;
688-
GPIO.status_w1tc = GPIO.status;
689692
bool need_yield = false;
690693
ESP_EARLY_LOGV(TAG, "gpio isr, cnt=%d", s_state->dma_received_count);
691694
if (gpio_get_level(s_state->config.pin_vsync) == 0 &&

components/camera/camera_common.h

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ typedef struct {
6565
i2s_sampling_mode_t sampling_mode;
6666
dma_filter_t dma_filter;
6767
intr_handle_t i2s_intr_handle;
68-
intr_handle_t vsync_intr_handle;
6968
QueueHandle_t data_ready;
7069
SemaphoreHandle_t frame_ready;
7170
TaskHandle_t dma_filter_task;

main/app_main.c

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ void app_main()
6969
ESP_ERROR_CHECK( nvs_flash_init() );
7070
}
7171

72+
ESP_ERROR_CHECK(gpio_install_isr_service(0));
73+
7274
camera_config_t camera_config = {
7375
.ledc_channel = LEDC_CHANNEL_0,
7476
.ledc_timer = LEDC_TIMER_0,

0 commit comments

Comments
 (0)