I can't understand why. Can anybody help me?
app_main : 1) pin for input from IR receiver 2) built-in LED 3) debug output each 5 sec to UART 4) xTaskCreate
Code: Select all
void app_main()
{
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_ANYEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
setvbuf(stdout, NULL, _IONBF, 0);
HW_HS0038B_event_queue = xQueueCreate(200,sizeof(HW_HS0038B_event));
xTaskCreate(HW_HS0038B_task, "HW_HS0038B", 4096, NULL, 10, NULL);
gpio_install_isr_service(0);
gpio_isr_handler_add(GPIO_INPUT_IO_0, HW_HS0038B_ISR_handler, (void*)GPIO_INPUT_IO_0 );
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL<<2);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
int cnt = 0;
while(1) {
int64_t ts = esp_timer_get_time();
ts /= 1000;
printf("%" PRId64 "\n", ts);
vTaskDelay(5000 / portTICK_RATE_MS);
}
Code: Select all
typedef struct {
uint64_t t;
int level;
} HW_HS0038B_event;
static uint32_t HW_HS0038B_prev_ts;
static xQueueHandle HW_HS0038B_event_queue = NULL;
static int debugH = 0;
static void IRAM_ATTR HW_HS0038B_ISR_handler(void* arg) // gpio_num = (uint32_t)arg;
{
int64_t ts = esp_timer_get_time();
HW_HS0038B_event e;
e.t = ts - HW_HS0038B_prev_ts;
HW_HS0038B_prev_ts = ts;
e.level = gpio_get_level( (uint32_t)arg );
gpio_set_level(2,(debugH++)%2);
xQueueSendFromISR(HW_HS0038B_event_queue, &e, NULL);
}
Code: Select all
static uint64_t HW_HS0038B_cmd;
static int HW_HS0038B_pos;
static void HW_HS0038B_task(void* arg)
{
HW_HS0038B_event e;
while(true) {
if ( pdPASS != xQueueReceive(HW_HS0038B_event_queue, &e, portMAX_DELAY) )
continue;
if ( e.t >= 2000 ) {
HW_HS0038B_cmd = HW_HS0038B_pos = 0;
continue;
}
if ( e.t < 1000 )
HW_HS0038B_cmd |= (1<<HW_HS0038B_pos);
printf("%d 0x%" PRIx64 "\n", HW_HS0038B_pos, HW_HS0038B_cmd);
HW_HS0038B_pos++;
}
}