diff --git a/main/main.c b/main/main.c index 97ff927..d3c1a2b 100644 --- a/main/main.c +++ b/main/main.c @@ -30,6 +30,10 @@ static const char *TAG = "eth_tester"; #define IP_FSTRING "%3d.%3d.%3d.%3d" #define SIGNAL_SHUTDOWN 1 +#define SIGNAL_BUTTON 2 + +#define SIGNAL_PAR_OFFSET 24 +#define SIGNAL_MASK 0x00FFFFFF #define LINE_STATUS_MAIN 0 @@ -53,6 +57,9 @@ int dns_resolv = -1; bool blink_mod = false; +#define ex_button_count 4 +uint32_t ex_buttons[ex_button_count] = {15, 14, 2, 5}; + static uint8_t get_byte(uint32_t addr, int n) { return (addr >> (8 * n)) & 0xFF; @@ -225,18 +232,41 @@ static void IRAM_ATTR isr_shutdown(void* arg) xQueueSendFromISR(signal_queue, &sig, NULL); } +static void IRAM_ATTR isr_button(void* arg) +{ + uint32_t sig = SIGNAL_BUTTON; + uint32_t mod = (uint32_t)arg; + + sig = sig | (mod << SIGNAL_PAR_OFFSET); + + xQueueSendFromISR(signal_queue, &sig, NULL); +} + static void task_signals(void* arg) { + uint32_t dat; uint32_t sig; + uint32_t par; for(;;) { - if(xQueueReceive(signal_queue, &sig, portMAX_DELAY)) { + if(xQueueReceive(signal_queue, &dat, portMAX_DELAY)) { + + //ESP_LOGI(TAG, "Signal: %x", dat); + + sig = dat & SIGNAL_MASK; + par = sig >> SIGNAL_PAR_OFFSET; + if (sig == SIGNAL_SHUTDOWN) { ESP_LOGI(TAG, "Got shutdown trigger, going to sleep..."); ssd1306_clear_screen(&display, false); esp_sleep_enable_ext0_wakeup(34, 0); esp_deep_sleep_start(); } + + if (sig == SIGNAL_BUTTON) { + //ESP_LOGI(TAG, "Button pressed: %d", par); + } + } } } @@ -314,6 +344,7 @@ void app_main(void) ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); + ssd1306_display_text(&display, 0, "Waiting for eth", 15, false, 0); display = dev; @@ -398,22 +429,48 @@ void app_main(void) adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_11); // gpio setup + + // front buttons + //zero-initialize the config structure. gpio_config_t io_conf = {}; //interrupt of rising edge - io_conf.intr_type = GPIO_INTR_POSEDGE; - //bit mask of the pins, here 34 + io_conf.intr_type = GPIO_INTR_NEGEDGE; + //bit mask of the pins, here 34 + front buttons io_conf.pin_bit_mask = 1ULL<<34; + + for (int i = 0; i < ex_button_count; i++) { + io_conf.pin_bit_mask = io_conf.pin_bit_mask | (1ULL<