diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7609df3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,7 @@ +[submodule "components/ucglib"] + path = components/ucglib + url = https://github.com/olikraus/ucglib.git + branch = master +[submodule "components/ESP32_TFT_library"] + path = components/ESP32_TFT_library + url = https://github.com/jeremyjh/ESP32_TFT_library.git diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..366e3bb --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//main/main.c=ISO-8859-1 diff --git a/CMakeLists.txt b/CMakeLists.txt index bda6977..98643ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,6 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) + set(EXTRA_COMPONENT_DIRS + externals/ESP32_TFT_library/components) project(app-template) diff --git a/components/display/CMakeLists.txt b/components/display/CMakeLists.txt new file mode 100644 index 0000000..13fee21 --- /dev/null +++ b/components/display/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "esp32_ucglib_hal.c" "display.c" + INCLUDE_DIRS "." + REQUIRES ucglib driver tft) \ No newline at end of file diff --git a/components/display/display.c b/components/display/display.c new file mode 100644 index 0000000..fc16368 --- /dev/null +++ b/components/display/display.c @@ -0,0 +1,203 @@ +/* + * display.c + * + * Created on: 19 Apr 2020 + * Author: Chris + */ + +#include "display.h" + +#include "tftspi.h" +#include "tft.h" + +#define SPI_BUS TFT_VSPI_HOST + +typedef struct { + int datetimeW; + int datetimeA; + int dateTimeLeft; + int datetimeBaseline; + int innenW; + int aussenW; + int locA; + int tempW; + int degCW; + int tempA; + int humW; + int percentW; + int humA; + int pressW; + int pressA; + int hpaW; + int datetimebarH; + int margin; + int borderVMargin; + int innenBaseline; + int aussenBaseline; + int pressBaseline; + int humBaseline; + int tempBaseline; + int unitMaxW; + int unitW; + int ioW; + int unitLeft; + int innenLeft; + int aussenLeft; +} layout_t; + +static layout_t layout; + +layout_t create_layout() +{ + layout_t layout; + int screenW = tft_width; + int screenH = tft_height; + layout.datetimebarH = 20; // Can be calculated too + layout.margin = 5; + layout.borderVMargin = 10; + + TFT_setFont(UBUNTU16_FONT, NULL); + layout.datetimebarH = 20; + layout.datetimeW = TFT_getStringWidth("25.12.2031 08:31"); + layout.datetimeA = TFT_getfontheight(); + layout.dateTimeLeft = (screenW - layout.datetimeW) / 2; + layout.datetimeBaseline = (layout.datetimebarH - layout.datetimeA) / 2; + + layout.innenW = TFT_getStringWidth("Innen"); + layout.aussenW = TFT_getStringWidth("Außen"); + layout.locA = TFT_getfontheight(); + + TFT_setFont(DEJAVU18_FONT, NULL); + layout.tempW = TFT_getStringWidth("-35.2"); + layout.degCW = TFT_getStringWidth(" C"); + layout.tempA = TFT_getfontheight(); + + TFT_setFont(UBUNTU16_FONT, NULL); + layout.humW = TFT_getStringWidth("25.2"); + layout.percentW = TFT_getStringWidth("%"); + layout.humA = TFT_getfontheight(); + + layout.pressW = TFT_getStringWidth("1281"); + layout.pressA = TFT_getfontheight(); + layout.hpaW = TFT_getStringWidth("hPa"); + + layout.innenBaseline = layout.datetimebarH + layout.borderVMargin; + layout.aussenBaseline = layout.innenBaseline; + layout.pressBaseline = screenH - layout.borderVMargin - layout.pressA; + layout.humBaseline = layout.pressBaseline - layout.pressA - layout.margin; + layout.tempBaseline = (layout.humBaseline - layout.humA + layout.innenBaseline) / 2 + + 0.5*layout.tempA - 1; + + int unitMaxW = layout.degCW; + if (layout.percentW > unitMaxW) unitMaxW = layout.percentW; + if (layout.hpaW > unitMaxW) unitMaxW = layout.hpaW; + layout.unitW = 2*layout.margin + unitMaxW; + layout.ioW = (screenW - layout.unitW) / 2; + layout.unitLeft = screenW - layout.unitW + layout.margin; + layout.innenLeft = layout.margin; + layout.aussenLeft = layout.innenLeft + layout.ioW; + + ESP_LOGI("main", "innen: %d x %d, aussen: %d x %d", layout.innenW, + layout.locA, layout.aussenW, layout.locA); + ESP_LOGI("main", "temps: %d x %d, unit: %d x %d", layout.tempW, + layout.tempA, layout.degCW, layout.tempA); + ESP_LOGI("main", "hum: %d x %d, unit: %d x %d", layout.humW, layout.humA, + layout.percentW, layout.humA); + ESP_LOGI("main", "press: %d x %d, unit: %d x %d", layout.pressW, layout.pressA, + layout.hpaW, layout.pressA); + + ESP_LOGI("main", "Baselines - innen: %d, aussen: %d, press: %d, hum: %d, temp: %d", + layout.innenBaseline, layout.aussenBaseline, + layout.pressBaseline, layout.humBaseline, layout.tempBaseline); + ESP_LOGI("main", "Width - units: %d, i/o: %d", layout.unitW, layout.ioW); + ESP_LOGI("main", "Left - units: %d", layout.unitLeft); + return layout; +} + +void display_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, + int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw) +{ + TFT_setFont(UBUNTU16_FONT, NULL); + TFT_fillScreen(TFT_BLACK); + tft_fg = TFT_WHITE; + + const color_t red = {0, 0, 255}; + const color_t green = {0, 255, 0}; + const color_t blue = {255, 0, 0}; + const color_t yellow = {255, 255, 0}; + + TFT_print("25.12.2031 08:31", layout.dateTimeLeft, layout.datetimeBaseline); + TFT_drawFastHLine(0, 20, 160, TFT_WHITE); + + TFT_print("Innen", layout.innenLeft, layout.innenBaseline); + TFT_print("Aussen", layout.aussenLeft, layout.aussenBaseline); + + TFT_setFont(DEJAVU18_FONT, NULL); + tft_fg = red; + TFT_print("-42,2", layout.innenLeft, layout.tempBaseline); + tft_fg = yellow; + TFT_print("-35,2", layout.aussenLeft, layout.tempBaseline); + tft_fg = TFT_WHITE; + TFT_print(" C", layout.unitLeft, layout.tempBaseline); + TFT_drawCircle(layout.unitLeft+3, layout.tempBaseline+3, 3, TFT_WHITE); + + TFT_setFont(UBUNTU16_FONT, NULL); + TFT_print("25,2", layout.innenLeft, layout.humBaseline); + TFT_print("42,2", layout.aussenLeft, layout.humBaseline); + TFT_print("%", layout.unitLeft, layout.humBaseline); + + TFT_print("1288", layout.innenLeft, layout.pressBaseline); + TFT_print("2563", layout.aussenLeft, layout.pressBaseline); + TFT_print("hPa", layout.unitLeft, layout.pressBaseline); +} + +esp_err_t init_display() +{ + tft_max_rdclock = 4000000; + TFT_PinsInit(); + spi_lobo_device_handle_t spi; + + spi_lobo_bus_config_t buscfg={ + .miso_io_num=PIN_NUM_MISO, // set SPI MISO pin + .mosi_io_num=PIN_NUM_MOSI, // set SPI MOSI pin + .sclk_io_num=PIN_NUM_CLK, // set SPI CLK pin + .quadwp_io_num=-1, + .quadhd_io_num=-1, + .max_transfer_sz = 6*1024, + }; + spi_lobo_device_interface_config_t devcfg={ + .clock_speed_hz=8000000, + .mode=0, + .spics_io_num=-1, + .spics_ext_io_num=PIN_NUM_CS, + .flags=LB_SPI_DEVICE_HALFDUPLEX, + }; + esp_err_t ret; + ret=spi_lobo_bus_add_device(SPI_BUS, &buscfg, &devcfg, &spi); + if (ret != ESP_OK) + { + return ret; + } + tft_disp_spi = spi; + + TFT_display_init(); + + tft_max_rdclock = find_rd_speed(); + + spi_lobo_set_speed(spi, DEFAULT_SPI_CLOCK); + + tft_font_rotate = 0; + tft_text_wrap = 0; + tft_font_transparent = 0; + tft_font_forceFixed = 0; + tft_gray_scale = 0; + TFT_setGammaCurve(DEFAULT_GAMMA_CURVE); + TFT_setRotation(LANDSCAPE_FLIP); + TFT_setFont(DEFAULT_FONT, NULL); + TFT_resetclipwin(); + tft_image_debug = 0; + + layout = create_layout(); + + return ESP_OK; +} diff --git a/components/display/display.h b/components/display/display.h new file mode 100644 index 0000000..6851d7f --- /dev/null +++ b/components/display/display.h @@ -0,0 +1,26 @@ +/* + * display.h + * + * Created on: 19 Apr 2020 + * Author: Chris + */ + +#ifndef COMPONENTS_DISPLAY_DISPLAY_H_ +#define COMPONENTS_DISPLAY_DISPLAY_H_ + +#include +#include +#include +#include + +//#include "esp32_ucglib_hal.h" +//#include "ucg.h" + +esp_err_t init_display(); +void display_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, + int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw); +//void update_temp1(int32_t temp1); + +void test_tft_lib(); + +#endif /* COMPONENTS_DISPLAY_DISPLAY_H_ */ diff --git a/components/display/esp32_ucglib_hal.c b/components/display/esp32_ucglib_hal.c new file mode 100644 index 0000000..2f08f5d --- /dev/null +++ b/components/display/esp32_ucglib_hal.c @@ -0,0 +1,290 @@ +#include "esp32_ucglib_hal.h" + +static spi_device_handle_t spi_hdl; +static ucg_esp32_hal_t pins; +static uint8_t* buffer_1 = 0; +static uint8_t* buffer_2 = 0; +static uint8_t* buffer_3 = 0; + +int16_t ucg_esp32_hal(ucg_t *ucg, int16_t msg, uint16_t arg, uint8_t *data) { + //ESP_LOGI("hal", "spi_byte_cb: Received a msg: %d, arg: %d, arg_ptr: %p", + // msg, arg, data); + switch (msg) { + case UCG_COM_MSG_POWER_UP: + //ESP_LOGI("hal", "UCG_COM_MSG_POWER_UP"); + /* "data" is a pointer to ucg_com_info_t structure with the following information: */ + /* ((ucg_com_info_t *)data)->serial_clk_speed value in nanoseconds */ + /* ((ucg_com_info_t *)data)->parallel_clk_speed value in nanoseconds */ + /* "arg" is not used */ + + /* This message is sent once at the uC startup and for power up. */ + /* setup i/o or do any other setup */ + ; + + buffer_1 = (uint8_t*) heap_caps_malloc(1, MALLOC_CAP_DMA); + buffer_2 = (uint8_t*) heap_caps_malloc(1, MALLOC_CAP_DMA); + buffer_3 = (uint8_t*) heap_caps_malloc(1, MALLOC_CAP_DMA); + + pins.clk = GPIO_NUM_18; + pins.cs = GPIO_NUM_17; + pins.dc = GPIO_NUM_2; + pins.mosi = GPIO_NUM_23; + pins.reset = GPIO_NUM_14; + + gpio_config_t gp_config; + gp_config.intr_type = GPIO_INTR_DISABLE; + gp_config.mode = GPIO_MODE_OUTPUT; + gp_config.pin_bit_mask = ((1ULL << pins.reset) | (1ULL << pins.cs) | (1ULL << pins.dc)); + gp_config.pull_down_en = GPIO_PULLDOWN_ENABLE; + gp_config.pull_up_en = GPIO_PULLUP_DISABLE; + gpio_config(&gp_config); + + spi_bus_config_t* bus_config; + bus_config = heap_caps_calloc(1, sizeof(spi_bus_config_t), MALLOC_CAP_8BIT); + bus_config->mosi_io_num = pins.mosi; + bus_config->miso_io_num = -1; + bus_config->sclk_io_num = pins.clk; + bus_config->quadwp_io_num = -1; + bus_config->quadhd_io_num = -1; + bus_config->max_transfer_sz = 4094; + bus_config->flags = 0; + bus_config->intr_flags = 0; + esp_err_t err = spi_bus_initialize(VSPI_HOST, bus_config, 1); + if (err != ESP_OK) { + ESP_LOGE("hal", "Could not initialize spi bus..."); + switch (err) { + case ESP_ERR_INVALID_ARG: + ESP_LOGE("hal", "ESP_ERR_INVALID_ARG"); + break; + case ESP_ERR_INVALID_STATE: + ESP_LOGE("hal", "ESP_ERR_INVALID_STATE"); + break; + case ESP_ERR_NO_MEM: + ESP_LOGE("hal", "ESP_ERR_NO_MEM"); + break; + default: + ESP_LOGE("hal", "Unknown err!"); + } + } + ESP_LOGI("hal", "successfully init bus!"); + + spi_device_interface_config_t* dev_config; + dev_config = heap_caps_calloc(1, sizeof(spi_device_interface_config_t), MALLOC_CAP_8BIT); + dev_config->address_bits = 0; + dev_config->command_bits = 0; + dev_config->dummy_bits = 0; + dev_config->mode = 0; + dev_config->duty_cycle_pos = 0; + dev_config->cs_ena_posttrans = 0; + dev_config->cs_ena_pretrans = 0; + dev_config->clock_speed_hz = SPI_MASTER_FREQ_40M; + dev_config->spics_io_num = pins.cs; + dev_config->queue_size = 200; + dev_config->flags = 0; + dev_config->pre_cb = NULL; + dev_config->post_cb = NULL; + err = spi_bus_add_device(VSPI_HOST, dev_config, &spi_hdl); + if (err != ESP_OK) { + ESP_LOGE("hal", "Could not initialize spi bus..."); + switch (err) { + case ESP_ERR_INVALID_ARG: + ESP_LOGE("hal", "ESP_ERR_INVALID_ARG"); + break; + case ESP_ERR_INVALID_STATE: + ESP_LOGE("hal", "ESP_ERR_INVALID_STATE"); + break; + case ESP_ERR_NO_MEM: + ESP_LOGE("hal", "ESP_ERR_NO_MEM"); + break; + default: + ESP_LOGE("hal", "Unknown err!"); + } + } + ESP_LOGI("hal", "successfully init bus device!"); + break; + + case UCG_COM_MSG_POWER_DOWN: + //ESP_LOGI("hal", "UCG_COM_MSG_POWER_DOWN"); + /* "data" and "arg" are not used*/ + /* This message is sent for a power down request */ + spi_bus_remove_device(spi_hdl); + spi_bus_free(HSPI_HOST); + heap_caps_free(buffer_1); + heap_caps_free(buffer_2); + heap_caps_free(buffer_3); + break; + case UCG_COM_MSG_DELAY: + //ESP_LOGI("hal", "UCG_COM_MSG_DELAY"); + /* "data" is not used */ + /* "arg" contains the number of microseconds for the delay */ + /* By receiving this message, the following code should delay by */ + /* "arg" microseconds. One microsecond is 0.000001 second */ + //vTaskDelay(arg / portTICK_PERIOD_MS / 100); + break; + case UCG_COM_MSG_CHANGE_RESET_LINE: + //ESP_LOGI("hal", "UCG_COM_MSG_CHANGE_RESET_LINE"); + /* "data" is not used */ + /* "arg" = 1: set the reset output line to 1 */ + /* "arg" = 0: set the reset output line to 0 */ + gpio_set_level(pins.reset, arg); + break; + case UCG_COM_MSG_CHANGE_CD_LINE: + //ESP_LOGI("hal", "UCG_COM_MSG_CHANGE_CD_LINE"); + /* "ucg->com_status" bit 0 contains the old level for the CD line */ + /* "data" is not used */ + /* "arg" = 1: set the command/data (a0) output line to 1 */ + /* "arg" = 0: set the command/data (a0) output line to 0 */ + gpio_set_level(pins.dc, arg); + break; + case UCG_COM_MSG_CHANGE_CS_LINE: + //ESP_LOGI("hal", "UCG_COM_MSG_CHANGE_CS_LINE"); + /* "ucg->com_status" bit 1 contains the old level for the CS line */ + /* "data" is not used */ + /* "arg" = 1: set the chipselect output line to 1 */ + /* "arg" = 0: set the chipselect output line to 0 */ + gpio_set_level(pins.cs, arg); + break; + case UCG_COM_MSG_SEND_BYTE: + //ESP_LOGI("hal", "UCG_COM_MSG_SEND_BYTE"); + /* "data" is not used */ + /* "arg" contains one byte, which should be sent to the display */ + /* The current status of the CD line is available */ + /* in bit 0 of u8g->com_status */ + ; + *buffer_1 = (uint8_t) arg; + spi_transaction_t transaction; + transaction.addr = 0; + transaction.cmd = 0; + transaction.length = 8; + transaction.rxlength = 0; + transaction.tx_buffer = buffer_1; + transaction.rx_buffer = NULL; + transaction.flags = SPI_TRANS_USE_RXDATA ; + spi_device_transmit(spi_hdl, &transaction); + break; + case UCG_COM_MSG_REPEAT_1_BYTE: + { + ESP_LOGW("hal", "UCG_COM_MSG_REPEAT_1_BYTE"); + /* "data[0]" contains one byte */ + /* repeat sending the byte in data[0] "arg" times */ + /* The current status of the CD line is available */ + /* in bit 0 of u8g->com_status */ + //spi_transaction_t transaction; + //transaction.length = 8; + //transaction.tx_buffer = data[0]; + //transaction.flags = SPI_TRANS_USE_TXDATA; + //int i; + //for (i = 0; i < arg; i++) { + // spi_device_polling_transmit(spi_hdl, &transaction); + //} + + + break; + } + case UCG_COM_MSG_REPEAT_2_BYTES: + { + ESP_LOGW("hal", "UCG_COM_MSG_REPEAT_2_BYTES"); +// spi_transaction_t transaction1; +// transaction.flags = SPI_TRANS_USE_TXDATA; +// transaction.length = 8; +// transaction.tx_buffer = data[0]; +// spi_transaction_t transaction2; +// transaction2.flags = SPI_TRANS_USE_TXDATA; +// transaction2.length = 8; +// transaction2.tx_buffer = data[1]; +// int i; +// for (i = 0; i < arg; i++) { +// spi_device_polling_transmit(spi_hdl, &transaction1); +// spi_device_polling_transmit(spi_hdl, &transaction2); +// } + /* "data[0]" contains first byte */ + /* "data[1]" contains second byte */ + /* repeat sending the two bytes "arg" times */ + /* The current status of the CD line is available */ + /* in bit 0 of u8g->com_status */ + + break; + } + case UCG_COM_MSG_REPEAT_3_BYTES: + { + //ESP_LOGI("hal", "UCG_COM_MSG_REPEAT_3_BYTES"); + /* "data[0]" contains first byte */ + /* "data[1]" contains second byte */ + /* "data[2]" contains third byte */ + /* repeat sending the three bytes "arg" times */ + /* The current status of the CD line is available */ + /* in bit 0 of u8g->com_status */ + buffer_3[0] = data[0]; + buffer_3[1] = data[1]; + buffer_3[2] = data[2]; + spi_transaction_t transaction; + transaction.addr = 0; + transaction.cmd = 0; + transaction.length = 3*8; + transaction.rxlength = 0; + transaction.tx_buffer = buffer_3; + transaction.rx_buffer = NULL; + transaction.flags = SPI_TRANS_USE_RXDATA ; + int i; + for (i = 0; i < arg; i++) { + spi_device_transmit(spi_hdl, &transaction); + } +// spi_transaction_t transaction1; +// transaction1.flags = SPI_TRANS_USE_TXDATA ; +// transaction1.length = 8; +// transaction1.tx_buffer = &data[0]; +// spi_transaction_t transaction2; +// transaction2.flags = SPI_TRANS_USE_TXDATA ; +// transaction2.length = 8; +// transaction2.tx_buffer = &data[1]; +// spi_transaction_t transaction3; +// transaction3.flags = SPI_TRANS_USE_TXDATA ; +// transaction3.length = 8; +// transaction3.tx_buffer = &data[2]; +// int i; +// for (i = 0; i < arg; i++) { +// spi_device_polling_transmit(spi_hdl, &transaction1); +// spi_device_polling_transmit(spi_hdl, &transaction2); +// spi_device_polling_transmit(spi_hdl, &transaction3); +// } + break; + } + case UCG_COM_MSG_SEND_STR: + { + ESP_LOGW("hal", "UCG_COM_MSG_SEND_STR"); + /* "data" is an array with "arg" bytes */ + /* send "arg" bytes to the display */ + spi_transaction_t transaction1; + transaction1.flags = SPI_TRANS_USE_RXDATA | SPI_TRANS_USE_TXDATA ; + transaction1.length = 8*arg; + transaction1.tx_buffer = &data[0]; + spi_device_polling_transmit(spi_hdl, &transaction1); + break; + } + case UCG_COM_MSG_SEND_CD_DATA_SEQUENCE: + { + //ESP_LOGW("hal", "UCG_COM_MSG_SEND_CD_DATA_SEQUENCE"); + /* "data" is a pointer to two bytes, which contain the cd line */ + /* status and display data */ + /* "arg" contains the number of these two byte tuples which need to */ + /* be analysed and sent. Bellow is a example sequence */ + /* The content of bit 0 in u8g->com_status is undefined for this message */ + + while (arg > 0) { + if (*data != 0) { + if (*data == 1) { + /* set CD (=D/C=A0) line to low */ + } else { + /* set CD (=D/C=A0) line to high */ + } + } + data++; + /* send *data to the display */ + data++; + arg--; + } + break; + } + } + return 1; +} diff --git a/components/display/esp32_ucglib_hal.h b/components/display/esp32_ucglib_hal.h new file mode 100644 index 0000000..95c6153 --- /dev/null +++ b/components/display/esp32_ucglib_hal.h @@ -0,0 +1,22 @@ +#ifndef ESP32_UCGLIB_HAL_H +#define ESP32_UCGLIB_HAL_H + +#include + +#include "driver/gpio.h" +#include "driver/spi_master.h" +#include "driver/i2c.h" +#include "esp_intr_alloc.h" +#include + +typedef struct { + gpio_num_t clk; + gpio_num_t mosi; + gpio_num_t cs; + gpio_num_t reset; + gpio_num_t dc; +} ucg_esp32_hal_t ; + +int16_t ucg_esp32_hal(ucg_t *ucg, int16_t msg, uint16_t arg, uint8_t *data); + +#endif /* ESP32_UCGLIB_HAL_H */ diff --git a/components/u8g2 b/components/u8g2 deleted file mode 160000 index 12ed2e4..0000000 --- a/components/u8g2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 12ed2e48354566216bfeee77449fc7ea41e5df2c diff --git a/doc/display.pdf b/doc/display.pdf deleted file mode 100644 index bcb1511..0000000 Binary files a/doc/display.pdf and /dev/null differ diff --git a/doc/display_pins.png b/doc/display_pins.png new file mode 100644 index 0000000..d5a58b9 Binary files /dev/null and b/doc/display_pins.png differ diff --git a/externals/ESP32_TFT_library b/externals/ESP32_TFT_library new file mode 160000 index 0000000..a06a578 --- /dev/null +++ b/externals/ESP32_TFT_library @@ -0,0 +1 @@ +Subproject commit a06a578356e0e6ad27b5efd1b815f9614a97f1bc diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 60f0e66..fb7306a 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -2,7 +2,7 @@ set(COMPONENT_REQUIRES ) set(COMPONENT_PRIV_REQUIRES ) -set(COMPONENT_SRCS "main.c" "u8g2_esp32_hal.c" "bme280.c") +set(COMPONENT_SRCS "main.c" "bme280.c") set(COMPONENT_ADD_INCLUDEDIRS "") register_component() diff --git a/main/main.c b/main/main.c index c29c3bc..e1b64ed 100644 --- a/main/main.c +++ b/main/main.c @@ -1,453 +1,456 @@ -#include "bme280.h" -#include "bme280_defs.h" -#include "driver/i2c.h" -#include -#include "u8g2_esp32_hal.h" +//#include "bme280.h" +//#include "bme280_defs.h" +//#include "driver/i2c.h" +#include "display.h" #include -#include -#include "freertos/event_groups.h" -#include "nvs_flash.h" -#include -#include +#include +#include +//#include +//#include "freertos/event_groups.h" +//#include "nvs_flash.h" +//#include +//#include -#define WIFI_SSID "Netzknecht" -#define WIFI_PASS "SpvtNVYsSRTsX36I" -#define WIFI_RETRIES 10 +//#define WIFI_SSID "Netzknecht" +//#define WIFI_PASS "SpvtNVYsSRTsX36I" +//#define WIFI_RETRIES 10 +// +//static EventGroupHandle_t s_wifi_event_group; +//#define WIFI_CONNECTED_BIT BIT0 +//#define WIFI_FAIL_BIT BIT1 +// +//static const char *TAG = "wifi station"; +//static int s_retry_num = 0; +// +//char cur_value_str[255]; +// +///* An HTTP GET handler */ +//static esp_err_t hello_get_handler(httpd_req_t *req) +//{ +// char* buf; +// size_t buf_len; +// +// /* Get header value string length and allocate memory for length + 1, +// * extra byte for null termination */ +// buf_len = httpd_req_get_hdr_value_len(req, "Host") + 1; +// if (buf_len > 1) { +// buf = malloc(buf_len); +// /* Copy null terminated value string into buffer */ +// if (httpd_req_get_hdr_value_str(req, "Host", buf, buf_len) == ESP_OK) { +// ESP_LOGI(TAG, "Found header => Host: %s", buf); +// } +// free(buf); +// } +// +// buf_len = httpd_req_get_hdr_value_len(req, "Test-Header-2") + 1; +// if (buf_len > 1) { +// buf = malloc(buf_len); +// if (httpd_req_get_hdr_value_str(req, "Test-Header-2", buf, buf_len) == ESP_OK) { +// ESP_LOGI(TAG, "Found header => Test-Header-2: %s", buf); +// } +// free(buf); +// } +// +// buf_len = httpd_req_get_hdr_value_len(req, "Test-Header-1") + 1; +// if (buf_len > 1) { +// buf = malloc(buf_len); +// if (httpd_req_get_hdr_value_str(req, "Test-Header-1", buf, buf_len) == ESP_OK) { +// ESP_LOGI(TAG, "Found header => Test-Header-1: %s", buf); +// } +// free(buf); +// } +// +// /* Read URL query string length and allocate memory for length + 1, +// * extra byte for null termination */ +// buf_len = httpd_req_get_url_query_len(req) + 1; +// if (buf_len > 1) { +// buf = malloc(buf_len); +// if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) { +// ESP_LOGI(TAG, "Found URL query => %s", buf); +// char param[32]; +// /* Get value of expected key from query string */ +// if (httpd_query_key_value(buf, "query1", param, sizeof(param)) == ESP_OK) { +// ESP_LOGI(TAG, "Found URL query parameter => query1=%s", param); +// } +// if (httpd_query_key_value(buf, "query3", param, sizeof(param)) == ESP_OK) { +// ESP_LOGI(TAG, "Found URL query parameter => query3=%s", param); +// } +// if (httpd_query_key_value(buf, "query2", param, sizeof(param)) == ESP_OK) { +// ESP_LOGI(TAG, "Found URL query parameter => query2=%s", param); +// } +// } +// free(buf); +// } +// +// /* Set some custom headers */ +// httpd_resp_set_hdr(req, "Custom-Header-1", "Custom-Value-1"); +// httpd_resp_set_hdr(req, "Custom-Header-2", "Custom-Value-2"); +// +// /* Send response with custom headers and body set as the +// * string passed in user context*/ +// const char* resp_str = cur_value_str; +// httpd_resp_send(req, resp_str, strlen(resp_str)); +// +// /* After sending the HTTP response the old HTTP request +// * headers are lost. Check if HTTP request headers can be read now. */ +// if (httpd_req_get_hdr_value_len(req, "Host") == 0) { +// ESP_LOGI(TAG, "Request headers lost"); +// } +// return ESP_OK; +//} +// +//static httpd_uri_t hello = { +// .uri = "/hello", +// .method = HTTP_GET, +// .handler = hello_get_handler, +// /* Let's pass response string in user +// * context to demonstrate it's usage */ +// .user_ctx = "Hello World!" +//}; +// +//static httpd_handle_t start_webserver(void) +//{ +// httpd_handle_t server = NULL; +// httpd_config_t config = HTTPD_DEFAULT_CONFIG(); +// +// // Start the httpd server +// ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port); +// if (httpd_start(&server, &config) == ESP_OK) { +// // Set URI handlers +// ESP_LOGI(TAG, "Registering URI handlers"); +// httpd_register_uri_handler(server, &hello); +// return server; +// } +// +// ESP_LOGI(TAG, "Error starting server!"); +// return NULL; +//} +// +//static void stop_webserver(httpd_handle_t server) +//{ +// // Stop the httpd server +// httpd_stop(server); +//} +// +//static void disconnect_handler(void* arg, esp_event_base_t event_base, +// int32_t event_id, void* event_data) +//{ +// httpd_handle_t* server = (httpd_handle_t*) arg; +// if (*server) { +// ESP_LOGI(TAG, "Stopping webserver"); +// stop_webserver(*server); +// *server = NULL; +// } +//} +// +//static void connect_handler(void* arg, esp_event_base_t event_base, +// int32_t event_id, void* event_data) +//{ +// httpd_handle_t* server = (httpd_handle_t*) arg; +// if (*server == NULL) { +// ESP_LOGI(TAG, "Starting webserver"); +// *server = start_webserver(); +// } +//} +// +//static void event_handler(void* arg, esp_event_base_t event_base, +// int32_t event_id, void* event_data) +//{ +// if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { +// esp_wifi_connect(); +// } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { +// if (s_retry_num < WIFI_RETRIES) { +// esp_wifi_connect(); +// s_retry_num++; +// ESP_LOGI(TAG, "retry to connect to the AP"); +// } else { +// xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); +// } +// ESP_LOGI(TAG,"connect to the AP fail"); +// } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { +// ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; +// ESP_LOGI(TAG, "got ip:%s", +// ip4addr_ntoa(&event->ip_info.ip)); +// s_retry_num = 0; +// xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); +// } +//} -static EventGroupHandle_t s_wifi_event_group; -#define WIFI_CONNECTED_BIT BIT0 -#define WIFI_FAIL_BIT BIT1 +//void wifi_init_sta() +//{ +// s_wifi_event_group = xEventGroupCreate(); +// +// tcpip_adapter_init(); +// +// ESP_ERROR_CHECK(esp_event_loop_create_default()); +// +// wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); +// ESP_ERROR_CHECK(esp_wifi_init(&cfg)); +// +// //tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); +// //tcpip_adapter_ip_info_t info; +// //ip4_addr_t gw; +// //gw.addr = ipaddr_addr("192.168.0.1"); +// //info.gw = gw; +// //ip4_addr_t ip; +// //ip.addr = ipaddr_addr("192.168.0.110"); +// //info.ip = ip; +// //ip4_addr_t netmask; +// //netmask.addr = ipaddr_addr("255.255.255.0"); +// //info.netmask = netmask; +// //tcpip_adapter_sta_start(0, &info); +// +// ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); +// ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); +// +// wifi_config_t wifi_config = { +// .sta = { +// .ssid = WIFI_SSID, +// .password = WIFI_PASS +// }, +// }; +// ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); +// ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) ); +// ESP_ERROR_CHECK(esp_wifi_start() ); +// +// ESP_LOGI(TAG, "wifi_init_sta finished."); +// +// /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum +// * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ +// EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, +// WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, +// pdFALSE, +// pdFALSE, +// portMAX_DELAY); +// +// //tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &info); +// /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually +// * happened. */ +// if (bits & WIFI_CONNECTED_BIT) { +// ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", +// WIFI_SSID, WIFI_PASS); +// } else if (bits & WIFI_FAIL_BIT) { +// ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", +// WIFI_SSID, WIFI_PASS); +// } else { +// ESP_LOGE(TAG, "UNEXPECTED EVENT"); +// } +// +// ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler)); +// ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler)); +// vEventGroupDelete(s_wifi_event_group); +//} +// +//void i2c_setup() +//{ +// printf("Setting up I�C driver on port 1... "); +// i2c_config_t config; +// config.mode = I2C_MODE_MASTER; +// config.sda_io_num = 33; +// config.sda_pullup_en = GPIO_PULLUP_ENABLE; +// config.scl_io_num = 32; +// config.scl_pullup_en = GPIO_PULLUP_ENABLE; +// config.master.clk_speed = 100000; +// i2c_param_config(I2C_NUM_0, &config); +// printf("Set driver parameters... "); +// esp_err_t err = i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0); +// if (err == ESP_OK) +// printf("Driver installed!\n"); +// else if (err == ESP_ERR_INVALID_ARG) +// printf("Driver install failed, invalid arguments!\n"); +// else +// printf("Driver install failed!\n"); +//} +// +//int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len) { +// i2c_cmd_handle_t cmd = i2c_cmd_link_create(); +// i2c_master_start(cmd); +// i2c_master_write_byte(cmd, dev_id << 1 | I2C_MASTER_WRITE, 1); +// i2c_master_write_byte(cmd, reg_addr, 1); +// i2c_master_start(cmd); +// i2c_master_write_byte(cmd, dev_id << 1 | I2C_MASTER_READ, 1); +// if (len > 1) { +// i2c_master_read(cmd, data, len - 1, I2C_MASTER_ACK); +// } +// i2c_master_read_byte(cmd, data + len - 1, I2C_MASTER_NACK); +// i2c_master_stop(cmd); +// i2c_master_cmd_begin(I2C_NUM_0, cmd, 500 / portTICK_RATE_MS); +// i2c_cmd_link_delete(cmd); +// return 0; +//} +// +//int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len) { +// //printf("Writing to bus: dev_id=%x, reg_addr=%x, data=%p, length=%u\n", dev_id, reg_addr, data, len); +// i2c_cmd_handle_t cmd = i2c_cmd_link_create(); +// i2c_master_start(cmd); +// i2c_master_write_byte(cmd, (dev_id << 1) | I2C_MASTER_WRITE, 1); +// i2c_master_write_byte(cmd, reg_addr, 1); +// i2c_master_write(cmd, data, len, 1); +// i2c_master_stop(cmd); +// i2c_master_cmd_begin(I2C_NUM_0, cmd, 500 / portTICK_RATE_MS); +// i2c_cmd_link_delete(cmd); +// return 0; +//} +// +//void i2c_delay(uint32_t period) { +// vTaskDelay(period / portTICK_PERIOD_MS); +//} +// +//void i2c_shutdown() +//{ +// printf("Shutting down I�C bus... "); +// esp_err_t err = i2c_driver_delete(I2C_NUM_0); +// if (err == ESP_ERR_INVALID_ARG) +// printf("Failed, invalid arguments!\n"); +// else +// printf("Success!\n"); +//} +// +//void read_sensor(struct bme280_dev* dev, int32_t* temp, uint32_t* pressure, uint32_t* humidity) { +// +// uint8_t settings_sel; +// uint32_t req_delay; +// struct bme280_data comp_data; +// +// dev->settings.osr_h = BME280_OVERSAMPLING_16X; +// dev->settings.osr_p = BME280_OVERSAMPLING_16X; +// dev->settings.osr_t = BME280_OVERSAMPLING_16X; +// dev->settings.filter = BME280_FILTER_COEFF_16; +// +// settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL; +// bme280_set_sensor_settings(settings_sel, dev); +// +// req_delay = 12*bme280_cal_meas_delay(&(dev->settings)); +// +// /* Continuously stream sensor data */ +// bme280_set_sensor_mode(BME280_FORCED_MODE, dev); +// /* Wait for the measurement to complete and print data @25Hz */ +// dev->delay_ms(req_delay / portTICK_PERIOD_MS); +// bme280_get_sensor_data(BME280_ALL, &comp_data, dev); +// *temp = comp_data.temperature; +// *pressure = comp_data.pressure; +// *humidity = comp_data.humidity; +//} +// +//void read_sensor2(struct bme280_dev* dev, int32_t* temp, uint32_t* pressure, uint32_t* humidity) { +// +// uint8_t settings_sel; +// uint32_t req_delay; +// struct bme280_data comp_data; +// +// dev->settings.osr_h = BME280_OVERSAMPLING_16X; +// dev->settings.osr_p = BME280_OVERSAMPLING_16X; +// dev->settings.osr_t = BME280_OVERSAMPLING_16X; +// dev->settings.filter = BME280_FILTER_COEFF_16; +// +// settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL; +// bme280_set_sensor_settings(settings_sel, dev); +// /*Calculate the minimum delay required between consecutive measurement based upon the sensor enabled +// * and the oversampling configuration. */ +// req_delay = 12*bme280_cal_meas_delay(&(dev->settings)); +// +// bme280_set_sensor_mode(BME280_FORCED_MODE, dev); +// /* Wait for the measurement to complete and print data @25Hz */ +// dev->delay_ms(req_delay / portTICK_PERIOD_MS); +// bme280_get_sensor_data(BME280_ALL, &comp_data, dev); +// *temp = comp_data.temperature; +// *pressure = comp_data.pressure; +// *humidity = comp_data.humidity; +//} -static const char *TAG = "wifi station"; -static int s_retry_num = 0; +//void print_data(u8g2_t* u8g2, int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, +// int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw) { +// // Calc temperature pre and post comma values +// int32_t temp_pre = temp_raw / 100; +// int32_t temp_post = (abs(temp_raw) % 100) / 10; +// int32_t temp2_pre = temp2_raw / 100; +// int32_t temp2_post = (abs(temp2_raw) % 100) / 10; +// +// // Calc pressure values +// uint32_t press = pressure_raw / 100; +// uint32_t press2 = pressure2_raw / 100; +// +// // Calc humidity pre and post comma values +// uint32_t humid_pre = humidity_raw / 1024; +// uint32_t humid_post = (humidity_raw - humid_pre*1024) * 10 / 1024; +// uint32_t humid2_pre = humidity2_raw / 1024; +// uint32_t humid2_post = (humidity2_raw - humid2_pre*1024) * 10 / 1024; +// +// // Format temperatures +// char temp_str[2*(sizeof(int)*8+1)+5] = ""; // "" +// char temp_pre_str[sizeof(int)*8+1]; +// itoa(temp_pre, temp_pre_str, 10); +// char temp_post_str[sizeof(int)*8+1]; +// itoa(temp_post, temp_post_str, 10); +// char temp2_pre_str[sizeof(int)*8+1]; +// itoa(temp2_pre, temp2_pre_str, 10); +// char temp2_post_str[sizeof(int)*8+1]; +// itoa(temp2_post, temp2_post_str, 10); +// if (temp_pre < 10) +// strcat(temp_str, " "); // Add space if first temperatur is just one digit long " " +// strcat(temp_str, temp_pre_str); // " 1" +// strcat(temp_str, ","); // " 1," +// strcat(temp_str, temp_post_str); // " 1,3" +// strcat(temp_str, " "); // " 1,3 " +// if (temp2_pre >= 0) +// strcat(temp_str, " "); // Add space if there is no minus sign " 1,3 " +// if (temp2_pre < 10) +// strcat(temp_str, " "); // Add space if second temperatur is just one digit long " 1,3 " +// strcat(temp_str, temp2_pre_str); // " 1,3 7" +// strcat(temp_str, ","); // " 1,3 7," +// strcat(temp_str, temp2_post_str); // " 1,3 7,2" +// strcat(temp_str, " �C"); // " 1,3 7,2 �C" +// +// // Format temperatures +// char humid_str[2*(sizeof(int)*8+1)+5] = ""; // "" +// char humid_pre_str[sizeof(int)*8+1]; +// itoa(humid_pre, humid_pre_str, 10); +// char humid_post_str[sizeof(int)*8+1]; +// itoa(humid_post, humid_post_str, 10); +// char humid2_pre_str[sizeof(int)*8+1]; +// itoa(humid2_pre, humid2_pre_str, 10); +// char humid2_post_str[sizeof(int)*8+1]; +// itoa(humid2_post, humid2_post_str, 10); +// strcat(humid_str, humid_pre_str); // "12" +// strcat(humid_str, ","); // "12," +// strcat(humid_str, humid_post_str); // "12,5" +// strcat(humid_str, " "); // "12,5 " +// strcat(humid_str, humid2_pre_str); // "12,5 45" +// strcat(humid_str, ","); // "12,5 45," +// strcat(humid_str, humid2_post_str); // "12,5 45,23" +// strcat(humid_str, " %"); // "12,5 45,23 %" +// +// // Format pressure +// char pressure_str[2*(sizeof(int)*8+1)+5] = ""; // "" +// char press1_str[sizeof(int)*8+1]; +// itoa(press, press1_str, 10); +// char press2_str[sizeof(int)*8+1]; +// itoa(press2, press2_str, 10); +// if (press < 1000) +// strcat(pressure_str, " "); +// strcat(pressure_str, press1_str); +// strcat(pressure_str, " "); +// if (press2 < 1000) +// strcat(pressure_str, " "); +// strcat(pressure_str, press2_str); +// strcat(pressure_str, " hPa"); +// +// u8g2_ClearBuffer(u8g2); +// u8g2_SetFont(u8g2, u8g2_font_profont17_mf); +// int8_t fontheight = u8g2_GetAscent(u8g2); +// int8_t fontmargin = abs(u8g2_GetDescent(u8g2))+2; +// u8g2_DrawStr(u8g2, 0, fontheight, " IN OUT "); +// u8g2_DrawStr(u8g2, 0, 2*fontheight + fontmargin, temp_str); +// u8g2_DrawStr(u8g2, 0, 3*fontheight + 2*fontmargin, humid_str); +// u8g2_DrawStr(u8g2, 0, 4*fontheight + 3*fontmargin, pressure_str); +// u8g2_SendBuffer(u8g2); +//} -char cur_value_str[255]; -/* An HTTP GET handler */ -static esp_err_t hello_get_handler(httpd_req_t *req) -{ - char* buf; - size_t buf_len; - - /* Get header value string length and allocate memory for length + 1, - * extra byte for null termination */ - buf_len = httpd_req_get_hdr_value_len(req, "Host") + 1; - if (buf_len > 1) { - buf = malloc(buf_len); - /* Copy null terminated value string into buffer */ - if (httpd_req_get_hdr_value_str(req, "Host", buf, buf_len) == ESP_OK) { - ESP_LOGI(TAG, "Found header => Host: %s", buf); - } - free(buf); - } - - buf_len = httpd_req_get_hdr_value_len(req, "Test-Header-2") + 1; - if (buf_len > 1) { - buf = malloc(buf_len); - if (httpd_req_get_hdr_value_str(req, "Test-Header-2", buf, buf_len) == ESP_OK) { - ESP_LOGI(TAG, "Found header => Test-Header-2: %s", buf); - } - free(buf); - } - - buf_len = httpd_req_get_hdr_value_len(req, "Test-Header-1") + 1; - if (buf_len > 1) { - buf = malloc(buf_len); - if (httpd_req_get_hdr_value_str(req, "Test-Header-1", buf, buf_len) == ESP_OK) { - ESP_LOGI(TAG, "Found header => Test-Header-1: %s", buf); - } - free(buf); - } - - /* Read URL query string length and allocate memory for length + 1, - * extra byte for null termination */ - buf_len = httpd_req_get_url_query_len(req) + 1; - if (buf_len > 1) { - buf = malloc(buf_len); - if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) { - ESP_LOGI(TAG, "Found URL query => %s", buf); - char param[32]; - /* Get value of expected key from query string */ - if (httpd_query_key_value(buf, "query1", param, sizeof(param)) == ESP_OK) { - ESP_LOGI(TAG, "Found URL query parameter => query1=%s", param); - } - if (httpd_query_key_value(buf, "query3", param, sizeof(param)) == ESP_OK) { - ESP_LOGI(TAG, "Found URL query parameter => query3=%s", param); - } - if (httpd_query_key_value(buf, "query2", param, sizeof(param)) == ESP_OK) { - ESP_LOGI(TAG, "Found URL query parameter => query2=%s", param); - } - } - free(buf); - } - - /* Set some custom headers */ - httpd_resp_set_hdr(req, "Custom-Header-1", "Custom-Value-1"); - httpd_resp_set_hdr(req, "Custom-Header-2", "Custom-Value-2"); - - /* Send response with custom headers and body set as the - * string passed in user context*/ - const char* resp_str = cur_value_str; - httpd_resp_send(req, resp_str, strlen(resp_str)); - - /* After sending the HTTP response the old HTTP request - * headers are lost. Check if HTTP request headers can be read now. */ - if (httpd_req_get_hdr_value_len(req, "Host") == 0) { - ESP_LOGI(TAG, "Request headers lost"); - } - return ESP_OK; -} - -static httpd_uri_t hello = { - .uri = "/hello", - .method = HTTP_GET, - .handler = hello_get_handler, - /* Let's pass response string in user - * context to demonstrate it's usage */ - .user_ctx = "Hello World!" -}; - -static httpd_handle_t start_webserver(void) -{ - httpd_handle_t server = NULL; - httpd_config_t config = HTTPD_DEFAULT_CONFIG(); - - // Start the httpd server - ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port); - if (httpd_start(&server, &config) == ESP_OK) { - // Set URI handlers - ESP_LOGI(TAG, "Registering URI handlers"); - httpd_register_uri_handler(server, &hello); - return server; - } - - ESP_LOGI(TAG, "Error starting server!"); - return NULL; -} - -static void stop_webserver(httpd_handle_t server) -{ - // Stop the httpd server - httpd_stop(server); -} - -static void disconnect_handler(void* arg, esp_event_base_t event_base, - int32_t event_id, void* event_data) -{ - httpd_handle_t* server = (httpd_handle_t*) arg; - if (*server) { - ESP_LOGI(TAG, "Stopping webserver"); - stop_webserver(*server); - *server = NULL; - } -} - -static void connect_handler(void* arg, esp_event_base_t event_base, - int32_t event_id, void* event_data) -{ - httpd_handle_t* server = (httpd_handle_t*) arg; - if (*server == NULL) { - ESP_LOGI(TAG, "Starting webserver"); - *server = start_webserver(); - } -} - -static void event_handler(void* arg, esp_event_base_t event_base, - int32_t event_id, void* event_data) -{ - if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { - esp_wifi_connect(); - } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { - if (s_retry_num < WIFI_RETRIES) { - esp_wifi_connect(); - s_retry_num++; - ESP_LOGI(TAG, "retry to connect to the AP"); - } else { - xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); - } - ESP_LOGI(TAG,"connect to the AP fail"); - } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { - ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; - ESP_LOGI(TAG, "got ip:%s", - ip4addr_ntoa(&event->ip_info.ip)); - s_retry_num = 0; - xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); - } -} - -void wifi_init_sta() -{ - s_wifi_event_group = xEventGroupCreate(); - - tcpip_adapter_init(); - - ESP_ERROR_CHECK(esp_event_loop_create_default()); - - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - - //tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); - //tcpip_adapter_ip_info_t info; - //ip4_addr_t gw; - //gw.addr = ipaddr_addr("192.168.0.1"); - //info.gw = gw; - //ip4_addr_t ip; - //ip.addr = ipaddr_addr("192.168.0.110"); - //info.ip = ip; - //ip4_addr_t netmask; - //netmask.addr = ipaddr_addr("255.255.255.0"); - //info.netmask = netmask; - //tcpip_adapter_sta_start(0, &info); - - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); - - wifi_config_t wifi_config = { - .sta = { - .ssid = WIFI_SSID, - .password = WIFI_PASS - }, - }; - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); - ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) ); - ESP_ERROR_CHECK(esp_wifi_start() ); - - ESP_LOGI(TAG, "wifi_init_sta finished."); - - /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum - * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ - EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, - WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, - pdFALSE, - pdFALSE, - portMAX_DELAY); - - //tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &info); - /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually - * happened. */ - if (bits & WIFI_CONNECTED_BIT) { - ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", - WIFI_SSID, WIFI_PASS); - } else if (bits & WIFI_FAIL_BIT) { - ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", - WIFI_SSID, WIFI_PASS); - } else { - ESP_LOGE(TAG, "UNEXPECTED EVENT"); - } - - ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler)); - ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler)); - vEventGroupDelete(s_wifi_event_group); -} - -void i2c_setup() -{ - printf("Setting up I²C driver on port 1... "); - i2c_config_t config; - config.mode = I2C_MODE_MASTER; - config.sda_io_num = 33; - config.sda_pullup_en = GPIO_PULLUP_ENABLE; - config.scl_io_num = 32; - config.scl_pullup_en = GPIO_PULLUP_ENABLE; - config.master.clk_speed = 100000; - i2c_param_config(I2C_NUM_0, &config); - printf("Set driver parameters... "); - esp_err_t err = i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0); - if (err == ESP_OK) - printf("Driver installed!\n"); - else if (err == ESP_ERR_INVALID_ARG) - printf("Driver install failed, invalid arguments!\n"); - else - printf("Driver install failed!\n"); -} - -int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len) { - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, dev_id << 1 | I2C_MASTER_WRITE, 1); - i2c_master_write_byte(cmd, reg_addr, 1); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, dev_id << 1 | I2C_MASTER_READ, 1); - if (len > 1) { - i2c_master_read(cmd, data, len - 1, I2C_MASTER_ACK); - } - i2c_master_read_byte(cmd, data + len - 1, I2C_MASTER_NACK); - i2c_master_stop(cmd); - i2c_master_cmd_begin(I2C_NUM_0, cmd, 500 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - return 0; -} - -int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len) { - //printf("Writing to bus: dev_id=%x, reg_addr=%x, data=%p, length=%u\n", dev_id, reg_addr, data, len); - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (dev_id << 1) | I2C_MASTER_WRITE, 1); - i2c_master_write_byte(cmd, reg_addr, 1); - i2c_master_write(cmd, data, len, 1); - i2c_master_stop(cmd); - i2c_master_cmd_begin(I2C_NUM_0, cmd, 500 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - return 0; -} - -void i2c_delay(uint32_t period) { - vTaskDelay(period / portTICK_PERIOD_MS); -} - -void i2c_shutdown() -{ - printf("Shutting down I²C bus... "); - esp_err_t err = i2c_driver_delete(I2C_NUM_0); - if (err == ESP_ERR_INVALID_ARG) - printf("Failed, invalid arguments!\n"); - else - printf("Success!\n"); -} - -void read_sensor(struct bme280_dev* dev, int32_t* temp, uint32_t* pressure, uint32_t* humidity) { - - uint8_t settings_sel; - uint32_t req_delay; - struct bme280_data comp_data; - - dev->settings.osr_h = BME280_OVERSAMPLING_16X; - dev->settings.osr_p = BME280_OVERSAMPLING_16X; - dev->settings.osr_t = BME280_OVERSAMPLING_16X; - dev->settings.filter = BME280_FILTER_COEFF_16; - - settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL; - bme280_set_sensor_settings(settings_sel, dev); - - req_delay = 12*bme280_cal_meas_delay(&(dev->settings)); - - /* Continuously stream sensor data */ - bme280_set_sensor_mode(BME280_FORCED_MODE, dev); - /* Wait for the measurement to complete and print data @25Hz */ - dev->delay_ms(req_delay / portTICK_PERIOD_MS); - bme280_get_sensor_data(BME280_ALL, &comp_data, dev); - *temp = comp_data.temperature; - *pressure = comp_data.pressure; - *humidity = comp_data.humidity; -} - -void read_sensor2(struct bme280_dev* dev, int32_t* temp, uint32_t* pressure, uint32_t* humidity) { - - uint8_t settings_sel; - uint32_t req_delay; - struct bme280_data comp_data; - - dev->settings.osr_h = BME280_OVERSAMPLING_16X; - dev->settings.osr_p = BME280_OVERSAMPLING_16X; - dev->settings.osr_t = BME280_OVERSAMPLING_16X; - dev->settings.filter = BME280_FILTER_COEFF_16; - - settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL; - bme280_set_sensor_settings(settings_sel, dev); - /*Calculate the minimum delay required between consecutive measurement based upon the sensor enabled - * and the oversampling configuration. */ - req_delay = 12*bme280_cal_meas_delay(&(dev->settings)); - - bme280_set_sensor_mode(BME280_FORCED_MODE, dev); - /* Wait for the measurement to complete and print data @25Hz */ - dev->delay_ms(req_delay / portTICK_PERIOD_MS); - bme280_get_sensor_data(BME280_ALL, &comp_data, dev); - *temp = comp_data.temperature; - *pressure = comp_data.pressure; - *humidity = comp_data.humidity; -} - -void print_data(u8g2_t* u8g2, int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, - int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw) { - // Calc temperature pre and post comma values - int32_t temp_pre = temp_raw / 100; - int32_t temp_post = (abs(temp_raw) % 100) / 10; - int32_t temp2_pre = temp2_raw / 100; - int32_t temp2_post = (abs(temp2_raw) % 100) / 10; - - // Calc pressure values - uint32_t press = pressure_raw / 100; - uint32_t press2 = pressure2_raw / 100; - - // Calc humidity pre and post comma values - uint32_t humid_pre = humidity_raw / 1024; - uint32_t humid_post = (humidity_raw - humid_pre*1024) * 10 / 1024; - uint32_t humid2_pre = humidity2_raw / 1024; - uint32_t humid2_post = (humidity2_raw - humid2_pre*1024) * 10 / 1024; - - // Format temperatures - char temp_str[2*(sizeof(int)*8+1)+5] = ""; // "" - char temp_pre_str[sizeof(int)*8+1]; - itoa(temp_pre, temp_pre_str, 10); - char temp_post_str[sizeof(int)*8+1]; - itoa(temp_post, temp_post_str, 10); - char temp2_pre_str[sizeof(int)*8+1]; - itoa(temp2_pre, temp2_pre_str, 10); - char temp2_post_str[sizeof(int)*8+1]; - itoa(temp2_post, temp2_post_str, 10); - if (temp_pre < 10) - strcat(temp_str, " "); // Add space if first temperatur is just one digit long " " - strcat(temp_str, temp_pre_str); // " 1" - strcat(temp_str, ","); // " 1," - strcat(temp_str, temp_post_str); // " 1,3" - strcat(temp_str, " "); // " 1,3 " - if (temp2_pre >= 0) - strcat(temp_str, " "); // Add space if there is no minus sign " 1,3 " - if (temp2_pre < 10) - strcat(temp_str, " "); // Add space if second temperatur is just one digit long " 1,3 " - strcat(temp_str, temp2_pre_str); // " 1,3 7" - strcat(temp_str, ","); // " 1,3 7," - strcat(temp_str, temp2_post_str); // " 1,3 7,2" - strcat(temp_str, " °C"); // " 1,3 7,2 °C" - - // Format temperatures - char humid_str[2*(sizeof(int)*8+1)+5] = ""; // "" - char humid_pre_str[sizeof(int)*8+1]; - itoa(humid_pre, humid_pre_str, 10); - char humid_post_str[sizeof(int)*8+1]; - itoa(humid_post, humid_post_str, 10); - char humid2_pre_str[sizeof(int)*8+1]; - itoa(humid2_pre, humid2_pre_str, 10); - char humid2_post_str[sizeof(int)*8+1]; - itoa(humid2_post, humid2_post_str, 10); - strcat(humid_str, humid_pre_str); // "12" - strcat(humid_str, ","); // "12," - strcat(humid_str, humid_post_str); // "12,5" - strcat(humid_str, " "); // "12,5 " - strcat(humid_str, humid2_pre_str); // "12,5 45" - strcat(humid_str, ","); // "12,5 45," - strcat(humid_str, humid2_post_str); // "12,5 45,23" - strcat(humid_str, " %"); // "12,5 45,23 %" - - // Format pressure - char pressure_str[2*(sizeof(int)*8+1)+5] = ""; // "" - char press1_str[sizeof(int)*8+1]; - itoa(press, press1_str, 10); - char press2_str[sizeof(int)*8+1]; - itoa(press2, press2_str, 10); - if (press < 1000) - strcat(pressure_str, " "); - strcat(pressure_str, press1_str); - strcat(pressure_str, " "); - if (press2 < 1000) - strcat(pressure_str, " "); - strcat(pressure_str, press2_str); - strcat(pressure_str, " hPa"); - - u8g2_ClearBuffer(u8g2); - u8g2_SetFont(u8g2, u8g2_font_profont17_mf); - int8_t fontheight = u8g2_GetAscent(u8g2); - int8_t fontmargin = abs(u8g2_GetDescent(u8g2))+2; - u8g2_DrawStr(u8g2, 0, fontheight, " IN OUT "); - u8g2_DrawStr(u8g2, 0, 2*fontheight + fontmargin, temp_str); - u8g2_DrawStr(u8g2, 0, 3*fontheight + 2*fontmargin, humid_str); - u8g2_DrawStr(u8g2, 0, 4*fontheight + 3*fontmargin, pressure_str); - u8g2_SendBuffer(u8g2); -} void app_main(void) { - int32_t temp = 0; + int32_t temp = -12; uint32_t pressure = 0; uint32_t humidity = 0; int32_t temp2 = 0; @@ -455,62 +458,48 @@ void app_main(void) uint32_t humidity2 = 0; // INIT SENSOR - i2c_setup(); - struct bme280_dev dev; - dev.dev_id = 0x76; - dev.intf = BME280_I2C_INTF; - dev.read = i2c_read; - dev.write = i2c_write; - dev.delay_ms = i2c_delay; - bme280_init(&dev); +// i2c_setup(); +// struct bme280_dev dev; +// dev.dev_id = 0x76; +// dev.intf = BME280_I2C_INTF; +// dev.read = i2c_read; +// dev.write = i2c_write; +// dev.delay_ms = i2c_delay; +// bme280_init(&dev); // INIT SENSOR2 - struct bme280_dev dev2; - dev2.dev_id = 0x77; - dev2.intf = BME280_I2C_INTF; - dev2.read = i2c_read; - dev2.write = i2c_write; - dev2.delay_ms = i2c_delay; - bme280_init(&dev2); - - // INIT DISPLAY - u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT; - u8g2_esp32_hal.sda = 18; - u8g2_esp32_hal.scl = 19; - - u8g2_esp32_hal_init(u8g2_esp32_hal); - u8g2_t u8g2; - u8g2_Setup_ssd1306_i2c_128x64_vcomh0_f(&u8g2, U8G2_R0, u8g2_esp32_i2c_byte_cb, - u8g2_esp32_gpio_and_delay_cb); - u8x8_SetI2CAddress(&u8g2.u8x8,0x3C << 1); - u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this, - u8g2_SetPowerSave(&u8g2, 0); // wake up display +// struct bme280_dev dev2; +// dev2.dev_id = 0x77; +// dev2.intf = BME280_I2C_INTF; +// dev2.read = i2c_read; +// dev2.write = i2c_write; +// dev2.delay_ms = i2c_delay; +// bme280_init(&dev2); // INIT WIFI //Initialize NVS - esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); - } - ESP_ERROR_CHECK(ret); - - ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); - wifi_init_sta(); +// esp_err_t ret = nvs_flash_init(); +// if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { +// ESP_ERROR_CHECK(nvs_flash_erase()); +// ret = nvs_flash_init(); +// } +// ESP_ERROR_CHECK(ret); +// +// ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); +// wifi_init_sta(); // INIT WEBSERVER - static httpd_handle_t server = NULL; - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server)); - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server)); - server = start_webserver(); +// static httpd_handle_t server = NULL; +// ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server)); +// ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server)); +// server = start_webserver(); + + init_display(); + while (1) { - read_sensor(&dev, &temp, &pressure, &humidity); - read_sensor(&dev2, &temp2, &pressure2, &humidity2); - printf("%i °c, %i hPa, %i %%\r\n", temp, pressure, humidity); - printf("%i °c, %i hPa, %i %%\r\n", temp2, pressure2, humidity2); - print_data(&u8g2, temp, pressure, humidity, temp2, pressure2, humidity2); - vTaskDelay(250 / portTICK_PERIOD_MS); + display_data(temp, pressure, humidity, temp2, pressure2, humidity2); + vTaskDelay(1000 / portTICK_PERIOD_MS); } } diff --git a/main/u8g2_esp32_hal.c b/main/u8g2_esp32_hal.c deleted file mode 100644 index 72ae016..0000000 --- a/main/u8g2_esp32_hal.c +++ /dev/null @@ -1,166 +0,0 @@ -#include -#include - -#include "sdkconfig.h" -#include "esp_log.h" - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" - -#include "u8g2_esp32_hal.h" - -static const char *TAG = "u8g2_hal"; -static const unsigned int I2C_TIMEOUT_MS = 1000; - -static i2c_cmd_handle_t handle_i2c; // I2C handle. -static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data. - -#undef ESP_ERROR_CHECK -#define ESP_ERROR_CHECK(x) do { esp_err_t rc = (x); if (rc != ESP_OK) { ESP_LOGE("err", "esp_err_t = %d", rc); assert(0 && #x);} } while(0); - -/* - * Initialze the ESP32 HAL. - */ -void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param) { - u8g2_esp32_hal = u8g2_esp32_hal_param; -} // u8g2_esp32_hal_init - -/* - * HAL callback function as prescribed by the U8G2 library. This callback is invoked - * to handle I2C communications. - */ -uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { - //ESP_LOGD(TAG, "i2c_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg, arg_int, arg_ptr); - - switch(msg) { - case U8X8_MSG_BYTE_SET_DC: { - if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { - gpio_set_level(u8g2_esp32_hal.dc, arg_int); - } - break; - } - - case U8X8_MSG_BYTE_INIT: { - if (u8g2_esp32_hal.sda == U8G2_ESP32_HAL_UNDEFINED || - u8g2_esp32_hal.scl == U8G2_ESP32_HAL_UNDEFINED) { - break; - } - - i2c_config_t conf; - conf.mode = I2C_MODE_MASTER; - ESP_LOGI(TAG, "sda_io_num %d", u8g2_esp32_hal.sda); - conf.sda_io_num = u8g2_esp32_hal.sda; - conf.sda_pullup_en = GPIO_PULLUP_ENABLE; - ESP_LOGI(TAG, "scl_io_num %d", u8g2_esp32_hal.scl); - conf.scl_io_num = u8g2_esp32_hal.scl; - conf.scl_pullup_en = GPIO_PULLUP_ENABLE; - ESP_LOGI(TAG, "clk_speed %d", I2C_MASTER_FREQ_HZ); - conf.master.clk_speed = I2C_MASTER_FREQ_HZ; - ESP_LOGI(TAG, "i2c_param_config %d", conf.mode); - ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf)); - ESP_LOGI(TAG, "i2c_driver_install %d", I2C_MASTER_NUM); - ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0)); - break; - } - - case U8X8_MSG_BYTE_SEND: { - uint8_t* data_ptr = (uint8_t*)arg_ptr; - ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, arg_int, ESP_LOG_VERBOSE); - - while( arg_int > 0 ) { - ESP_ERROR_CHECK(i2c_master_write_byte(handle_i2c, *data_ptr, ACK_CHECK_EN)); - data_ptr++; - arg_int--; - } - break; - } - - case U8X8_MSG_BYTE_START_TRANSFER: { - uint8_t i2c_address = u8x8_GetI2CAddress(u8x8); - handle_i2c = i2c_cmd_link_create(); - ESP_LOGD(TAG, "Start I2C transfer to %02X.", i2c_address>>1); - ESP_ERROR_CHECK(i2c_master_start(handle_i2c)); - ESP_ERROR_CHECK(i2c_master_write_byte(handle_i2c, i2c_address | I2C_MASTER_WRITE, ACK_CHECK_EN)); - break; - } - - case U8X8_MSG_BYTE_END_TRANSFER: { - ESP_LOGD(TAG, "End I2C transfer."); - ESP_ERROR_CHECK(i2c_master_stop(handle_i2c)); - ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c, I2C_TIMEOUT_MS / portTICK_RATE_MS)); - i2c_cmd_link_delete(handle_i2c); - break; - } - } - return 0; -} // u8g2_esp32_i2c_byte_cb - -/* - * HAL callback function as prescribed by the U8G2 library. This callback is invoked - * to handle callbacks for GPIO and delay functions. - */ -uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { - ESP_LOGD(TAG, "gpio_and_delay_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg, arg_int, arg_ptr); - - switch(msg) { - // Initialize the GPIO and DELAY HAL functions. If the pins for DC and RESET have been - // specified then we define those pins as GPIO outputs. - case U8X8_MSG_GPIO_AND_DELAY_INIT: { - uint64_t bitmask = 0; - if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { - bitmask = bitmask | (1ull<