From cfc8bcfba9ec62015396484787c162336e55a00f Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Fri, 9 Feb 2024 10:28:34 +0100 Subject: [PATCH] Fixed ok button reset problem. The TFTe user configuration is used now to decide which diesplay is used in the esp32 osci implementation. --- ESP32_Oscilloscope/ESP32_Oscilloscope.ino | 24 ++++++++++++++++++++-- ESP32_Oscilloscope/options_handler.ino | 25 ++++++++--------------- ESP32_Oscilloscope/screen.ino | 15 ++++++++++++++ 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/ESP32_Oscilloscope/ESP32_Oscilloscope.ino b/ESP32_Oscilloscope/ESP32_Oscilloscope.ino index 13e3758..b79b47f 100644 --- a/ESP32_Oscilloscope/ESP32_Oscilloscope.ino +++ b/ESP32_Oscilloscope/ESP32_Oscilloscope.ino @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -17,8 +18,21 @@ #define DEBUG_DELAY 250 // Width and height of sprite +#ifdef ILI9341_DRIVER +#warning "Use ILI9341 display settings." #define DISPLAY_HEIGHT 240 #define DISPLAY_WIDTH 320 +#endif + +#ifdef ST7789_DRIVER +#warning "Use ST7789 display settings." +#define DISPLAY_HEIGHT 240 +#define DISPLAY_WIDTH 280 +#endif + +#ifndef DISPLAY_HEIGHT +#error "No display driver defined" +#endif #define ADC_CHANNEL ADC1_CHANNEL_5 // GPIO33 #define NUM_SAMPLES 1000 // number of samples @@ -114,6 +128,10 @@ void IRAM_ATTR btback() void setup() { Serial.begin(115200); + esp_reset_reason_t reset_reason = esp_reset_reason(); + Serial.print("Reset reason: "); + Serial.println(reset_reason); + configure_i2s(1000000); setup_screen(); @@ -193,6 +211,7 @@ void core1_task(void *pvParameters) if (stop_change) { i2s_adc_enable(I2S_NUM_0); + i2s_zero_dma_buffer(I2S_NUM_0); stop_change = false; } ADC_Sampling(i2s_buff); @@ -202,7 +221,8 @@ void core1_task(void *pvParameters) { if (!stop_change) { - i2s_adc_disable(I2S_NUM_0); + // TODO the disable function causes an esp32 reset + //i2s_adc_disable(I2S_NUM_0); i2s_zero_dma_buffer(I2S_NUM_0); stop_change = true; } @@ -210,7 +230,7 @@ void core1_task(void *pvParameters) // Serial.println("CORE1"); vTaskDelay(pdMS_TO_TICKS(300)); } - else + else // else single trigger { float old_mean = 0; while (single_trigger) diff --git a/ESP32_Oscilloscope/options_handler.ino b/ESP32_Oscilloscope/options_handler.ino index 901ad5d..6122ca4 100644 --- a/ESP32_Oscilloscope/options_handler.ino +++ b/ESP32_Oscilloscope/options_handler.ino @@ -132,6 +132,7 @@ void button() { set_value = 0; btnbk = 0; + btnok = 0; } } else @@ -143,8 +144,8 @@ void button() { opt = 1; } - Serial.print("option : "); - Serial.println(opt); + //Serial.print("option : "); + //Serial.println(opt); btnpl = 0; } if (btnmn == 1) @@ -154,8 +155,8 @@ void button() { opt = 9; } - Serial.print("option : "); - Serial.println(opt); + //Serial.print("option : "); + //Serial.println(opt); btnmn = 0; } if (btnbk == 1) @@ -172,29 +173,19 @@ void button() break; case Vdiv: - set_value = true; - break; - case Sdiv: - set_value = true; - break; - case Offset: + case TOffset: set_value = true; break; case Stop: stop = !stop; - Serial.print("Stop : "); - Serial.println(stop); + //Serial.print("Stop : "); + //Serial.println(stop); set_value = false; break; - case TOffset: - set_value = true; - // set_value = false; - break; - case Single: single_trigger = true; set_value = false; diff --git a/ESP32_Oscilloscope/screen.ino b/ESP32_Oscilloscope/screen.ino index 51561df..1a5e951 100644 --- a/ESP32_Oscilloscope/screen.ino +++ b/ESP32_Oscilloscope/screen.ino @@ -1,7 +1,12 @@ void setup_screen() { // Initialise the TFT registers tft.init(); +#ifdef ILI9341_DRIVER tft.setRotation(3); +#endif +#ifdef ST7789_DRIVER + tft.setRotation(1); +#endif // Optionally set colour depth to 8 or 16 bits, default is 16 if not spedified spr.setColorDepth(8); @@ -165,7 +170,12 @@ void draw_sprite(float freq, draw_channel1(trigger, 0, i2s_buff, sample_rate); } +#ifdef ILI9341_DRIVER + int shift = DISPLAY_WIDTH - 130; +#endif +#ifdef ST7789_DRIVER int shift = DISPLAY_WIDTH - 110; +#endif if (menu) { spr.drawLine( 0, DISPLAY_HEIGHT/2, DISPLAY_WIDTH, DISPLAY_HEIGHT/2, TFT_WHITE); //center line spr.fillRect(shift, 0, (DISPLAY_HEIGHT/2)-18, (DISPLAY_HEIGHT/2)+15, TFT_BLACK); @@ -199,7 +209,12 @@ void draw_sprite(float freq, spr.drawString(offset_line, shift + 25, (DISPLAY_HEIGHT/2)-8); if (set_value) { +#ifdef ILI9341_DRIVER uint16_t t_left = shift+161; +#endif +#ifdef ST7789_DRIVER + uint16_t t_left = shift+149; // previously hard coeded value 229 +#endif // Plus symbols while setting a value spr.fillRect(t_left, 0, 11, 11, TFT_BLUE); spr.drawRect(t_left, 0, 11, 11, TFT_WHITE);