From 992362bcc1efd68601f58a84371ddd9984fdebb1 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Wed, 1 May 2019 10:24:50 +0100 Subject: [PATCH] Start adding U8g2 support for the OLED/LCD --- main/hal.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 3 deletions(-) diff --git a/main/hal.cpp b/main/hal.cpp index 9c4c736..6e42834 100644 --- a/main/hal.cpp +++ b/main/hal.cpp @@ -48,6 +48,10 @@ #include "font8x8_basic.h" #endif +#ifdef WITH_U8G2 +#include "u8g2.h" +#endif + // ====================================================================================================== /* The HELTEC AUtomation board WiFi LoRa 32 with sx1278 (RFM95) @@ -259,6 +263,7 @@ GPIO HELTEC TTGO JACEK T-Beam FollowMe Restrictions #ifdef WITH_TBEAM // T-Beam #define PIN_I2C_SCL GPIO_NUM_22 // SCL pin => this way the pin pattern fits the BMP280 module #define PIN_I2C_SDA GPIO_NUM_21 // SDA pin +#define OLED_I2C_ADDR 0x3C // I2C address of the OLED display #endif #ifdef WITH_FollowMe // @@ -278,7 +283,7 @@ uint8_t BARO_I2C = (uint8_t)I2C_BUS; #define PIN_BEEPER GPIO_NUM_17 #endif -#if !defined(WITH_OLED) && !defined(WITH_BMP180) && !defined(WITH_BMP280) && !defined(WITH_BME280) +#if !defined(WITH_OLED) && !defined(WITH_U8G2) && !defined(WITH_BMP180) && !defined(WITH_BMP280) && !defined(WITH_BME280) #undef PIN_I2C_SCL #undef PIN_I2C_SDA #endif @@ -825,6 +830,107 @@ esp_err_t OLED_Clear(uint8_t DispIdx) return espRc; } #endif +#ifdef WITH_U8G2 + +static i2c_cmd_handle_t U8G2_Cmd; + +static uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ +#ifdef DEBUG_PRINT + xSemaphoreTake(CONS_Mutex, portMAX_DELAY); + Format_String(CONS_UART_Write, "u8g2_byte_cb("); + CONS_UART_Write(','); + Format_UnsDec(CONS_UART_Write, (uint16_t)msg); + CONS_UART_Write(','); + Format_UnsDec(CONS_UART_Write, (uint16_t)arg_int); + Format_String(CONS_UART_Write, ") "); +#endif + switch(msg) + { case U8X8_MSG_BYTE_SET_DC: + break; + case U8X8_MSG_BYTE_INIT: + break; + case U8X8_MSG_BYTE_START_TRANSFER: + { U8G2_Cmd=i2c_cmd_link_create(); + uint8_t Addr = u8x8_GetI2CAddress(u8x8); +#ifdef DEBUG_PRINT + Format_Hex(CONS_UART_Write, Addr); +#endif + i2c_master_start(U8G2_Cmd); + i2c_master_write_byte(U8G2_Cmd, (Addr<<1) | I2C_MASTER_WRITE, true); + break; } + case U8X8_MSG_BYTE_SEND: + // { i2c_master_write(U8G2_Cmd, (uint8_t *)arg_ptr, arg_int, true); break; } + { uint8_t* Data = (uint8_t *)arg_ptr; + for( int Idx=0; Idx good, ESP_FAIL => failed to mound the file system, other => HW not working if(Ret!=ESP_OK) SD_Unmount(); - return Ret; } + return Ret; } // ESP_OK => all good, ESP_FAIL => failed to mount file system, other => failed to init. the SD card static esp_err_t SD_Init(void) { @@ -1117,9 +1223,11 @@ void IO_Configuration(void) uart_driver_install(ADSB_UART, 256, 256, 0, 0, 0); #endif -#if defined(WITH_OLED) && defined(PIN_OLED_RST) +#if defined(WITH_OLED) || defined(WITH_U8G2) +#ifdef PIN_OLED_RST gpio_set_direction(PIN_OLED_RST, GPIO_MODE_OUTPUT); #endif +#endif #if defined(PIN_I2C_SCL) && defined(PIN_I2C_SDA) i2c_config_t I2C_Config = // I2C for OLED and pressue sensor @@ -1151,6 +1259,10 @@ void IO_Configuration(void) #endif #endif +#ifdef WITH_U8G2 + U8G2_Init(); +#endif + #ifdef WITH_SD SD_Init(); #endif