Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion lib/Arduino_RPi_DPI_RGBPanel_mod/Arduino_RGB_Display_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,96 @@
#include "Arduino_DataBus.h"
#include "Arduino_RGB_Display_mod.h"

namespace {

bool execute_custom_init_ops(Arduino_DataBus* bus, const uint8_t* ops, size_t len)
{
if(!bus || !ops || len == 0) return true;

size_t i = 0;
while(i < len) {
const uint8_t op = ops[i++];
switch(op) {
case BEGIN_WRITE:
bus->beginWrite();
break;
case END_WRITE:
bus->endWrite();
break;
case WRITE_COMMAND_8:
if(i >= len) return false;
bus->writeCommand(ops[i++]);
break;
case WRITE_C8_D8:
if(i + 1 >= len) return false;
bus->writeCommand(ops[i++]);
bus->write(ops[i++]);
break;
case WRITE_C8_D16:
if(i + 2 >= len) return false;
bus->writeCommand(ops[i++]);
bus->write(ops[i++]);
bus->write(ops[i++]);
break;
case WRITE_BYTES: {
if(i >= len) return false;
uint8_t n = ops[i++];
if(i + n > len) return false;
for(uint8_t k = 0; k < n; k++) bus->write(ops[i++]);
break;
}
case DELAY:
if(i >= len) return false;
delay(ops[i++]);
break;
case I2C_WRITE_REG:
if(i + 1 >= len) return false;
#if defined(USE_I2C_SW_SPI)
bus->writeRegisterI2COpcode(ops[i], ops[i + 1]);
i += 2;
#else
return false;
#endif
break;
case I2C_WRITE_SEQ:
if(i + 1 >= len) return false;
{
const uint8_t reg = ops[i++];
const uint8_t n = ops[i++];
if(i + n > len) return false;
#if defined(USE_I2C_SW_SPI)
bus->writeRegisterI2CSeqOpcode(reg, &ops[i], n);
i += n;
#else
return false;
#endif
}
break;
case REPEAT_IN:
if(i + 3 >= len) return false;
{
const uint8_t count = ops[i++];
const uint8_t nested_op = ops[i++];
if(nested_op != I2C_WRITE_REG) return false;
const uint8_t reg = ops[i++];
const uint8_t val = ops[i++];
#if defined(USE_I2C_SW_SPI)
for(uint8_t r = 0; r < count; r++) bus->writeRegisterI2COpcode(reg, val);
#else
return false;
#endif
}
break;
default:
return false;
}
}

return true;
}

} // namespace

Arduino_RGB_Display_Mod::Arduino_RGB_Display_Mod(int16_t w, int16_t h, Arduino_RGBPanel_Mod* rgbpanel, uint8_t r,
bool auto_flush, Arduino_DataBus* bus, int8_t rst,
const uint8_t* init_operations, size_t init_operations_len)
Expand Down Expand Up @@ -42,7 +132,9 @@ bool Arduino_RGB_Display_Mod::begin(int32_t speed)

if(_bus) {
if(_init_operations_len > 0) {
_bus->batchOperation((uint8_t*)_init_operations, _init_operations_len);
if(!execute_custom_init_ops(_bus, _init_operations, _init_operations_len)) {
_bus->batchOperation((uint8_t*)_init_operations, _init_operations_len);
}
}
}

Expand Down
214 changes: 214 additions & 0 deletions lib/Arduino_RPi_DPI_RGBPanel_mod/Arduino_RGB_Display_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
#include "Arduino_GFX.h"
#include "Arduino_RGBPanel_mod.h"

#ifndef I2C_WRITE_REG
#define I2C_WRITE_REG 0xE9
#endif

#ifndef REPEAT_IN
#define REPEAT_IN 0xEA
#endif

#ifndef I2C_WRITE_SEQ
#define I2C_WRITE_SEQ 0xEB
#endif

static const uint8_t st7701_4848S040_init_operations[] = {
BEGIN_WRITE,
WRITE_COMMAND_8, 0xFF,
Expand Down Expand Up @@ -396,6 +408,208 @@ static const uint8_t st7701_t_panel_init_operations[] = {

END_WRITE};

#if defined(HASP_LANBON_L10_TCA9554_GC9503V)
/* Lanbon L10 — GC9503V init via TCA9554 3-wire bus (same encoding as st7701_t_panel_init_operations). */
static const uint8_t gc9503v_l10_init_operations[] = {
BEGIN_WRITE,
DELAY, 120,
WRITE_C8_D8, 0xB1, 0x10,
WRITE_C8_D8, 0x3A, 0x50,
WRITE_COMMAND_8, 0xF0,
WRITE_BYTES, 5,
0x55, 0xAA, 0x52, 0x08,
0x00,
WRITE_C8_D16, 0xF6, 0x5A, 0x87,
WRITE_C8_D8, 0xC1, 0x3F,
WRITE_C8_D8, 0xC2, 0x0E,
WRITE_C8_D8, 0xC6, 0xF8,
WRITE_C8_D8, 0xC9, 0x10,
WRITE_C8_D8, 0xCD, 0x25,
WRITE_COMMAND_8, 0x87,
WRITE_BYTES, 3,
0x04, 0x03, 0x66,
WRITE_COMMAND_8, 0x86,
WRITE_BYTES, 4,
0x99, 0xA3, 0xA3, 0x51,
WRITE_C8_D8, 0xF8, 0x8A,
WRITE_C8_D8, 0xAC, 0x65,
WRITE_C8_D8, 0xA7, 0x47,
WRITE_C8_D8, 0xA0, 0xDD,
WRITE_COMMAND_8, 0xFA,
WRITE_BYTES, 4,
0x08, 0x08, 0x00, 0x04,
WRITE_C8_D8, 0xA3, 0x2E,
WRITE_COMMAND_8, 0xFD,
WRITE_BYTES, 3,
0x28, 0x3C, 0x00,
WRITE_C8_D8, 0x71, 0x48,
WRITE_C8_D8, 0x72, 0x48,
WRITE_C8_D16, 0x73, 0x00, 0x44,
WRITE_C8_D8, 0x97, 0xEE,
WRITE_C8_D8, 0x83, 0x93,
WRITE_C8_D8, 0x9A, 0x84,
WRITE_C8_D8, 0x9B, 0x54,
WRITE_C8_D16, 0x82, 0x5D, 0x5D,
WRITE_C8_D8, 0xB1, 0x10,
WRITE_C8_D16, 0x7A, 0x13, 0x1A,
WRITE_C8_D16, 0x7B, 0x13, 0x1A,
WRITE_COMMAND_8, 0x64,
WRITE_BYTES, 16,
0x18, 0x09, 0x03, 0x59,
0x03, 0x03, 0x18, 0x08,
0x03, 0x5A, 0x03, 0x03,
0x7A, 0x7A, 0x7A, 0x7A,
WRITE_COMMAND_8, 0x67,
WRITE_BYTES, 16,
0x18, 0x07, 0x03, 0x5B,
0x03, 0x03, 0x18, 0x06,
0x03, 0x5C, 0x03, 0x03,
0x7A, 0x7A, 0x7A, 0x7A,
WRITE_COMMAND_8, 0x68,
WRITE_BYTES, 13,
0x00, 0x08, 0x0A, 0x08,
0x09, 0x00, 0x00, 0x08,
0x0A, 0x08, 0x09, 0x00,
0x00,
WRITE_COMMAND_8, 0x60,
WRITE_BYTES, 8,
0x18, 0x08, 0x7A, 0x7A,
0x18, 0x02, 0x7A, 0x7A,
WRITE_COMMAND_8, 0x63,
WRITE_BYTES, 8,
0x18, 0x02, 0x6D, 0x6D,
0x18, 0x07, 0x7A, 0x7A,
WRITE_COMMAND_8, 0x69,
WRITE_BYTES, 7,
0x14, 0x22, 0x14, 0x22,
0x44, 0x22, 0x08,
WRITE_COMMAND_8, 0xD1,
WRITE_BYTES, 52,
0x00, 0x00, 0x00, 0x08,
0x00, 0x1D, 0x00, 0x5F,
0x00, 0x91, 0x00, 0xCE,
0x00, 0xF5, 0x01, 0x2B,
0x01, 0x7F, 0x01, 0xED,
0x02, 0x23, 0x02, 0x78,
0x02, 0xB2, 0x02, 0xB4,
0x02, 0xF1, 0x03, 0x29,
0x03, 0x49, 0x03, 0x6D,
0x03, 0x82, 0x03, 0x9B,
0x03, 0xA5, 0x03, 0xB0,
0x03, 0xB5, 0x03, 0xBF,
0x03, 0xDE, 0x03, 0xFF,
WRITE_COMMAND_8, 0xD2,
WRITE_BYTES, 52,
0x00, 0x00, 0x00, 0x08,
0x00, 0x1D, 0x00, 0x5F,
0x00, 0x91, 0x00, 0xCE,
0x00, 0xF5, 0x01, 0x2B,
0x01, 0x7F, 0x01, 0xED,
0x02, 0x23, 0x02, 0x78,
0x02, 0xB2, 0x02, 0xB4,
0x02, 0xF1, 0x03, 0x29,
0x03, 0x49, 0x03, 0x6D,
0x03, 0x82, 0x03, 0x9B,
0x03, 0xA5, 0x03, 0xB0,
0x03, 0xB5, 0x03, 0xBF,
0x03, 0xDE, 0x03, 0xFF,
WRITE_COMMAND_8, 0xD3,
WRITE_BYTES, 52,
0x00, 0x00, 0x00, 0x08,
0x00, 0x1D, 0x00, 0x5F,
0x00, 0x91, 0x00, 0xCE,
0x00, 0xF5, 0x01, 0x2B,
0x01, 0x7F, 0x01, 0xED,
0x02, 0x23, 0x02, 0x78,
0x02, 0xB2, 0x02, 0xB4,
0x02, 0xF1, 0x03, 0x29,
0x03, 0x49, 0x03, 0x6D,
0x03, 0x82, 0x03, 0x9B,
0x03, 0xA5, 0x03, 0xB0,
0x03, 0xB5, 0x03, 0xBF,
0x03, 0xDE, 0x03, 0xFF,
WRITE_COMMAND_8, 0xD4,
WRITE_BYTES, 52,
0x00, 0x00, 0x00, 0x08,
0x00, 0x1D, 0x00, 0x5F,
0x00, 0x91, 0x00, 0xCE,
0x00, 0xF5, 0x01, 0x2B,
0x01, 0x7F, 0x01, 0xED,
0x02, 0x23, 0x02, 0x78,
0x02, 0xB2, 0x02, 0xB4,
0x02, 0xF1, 0x03, 0x29,
0x03, 0x49, 0x03, 0x6D,
0x03, 0x82, 0x03, 0x9B,
0x03, 0xA5, 0x03, 0xB0,
0x03, 0xB5, 0x03, 0xBF,
0x03, 0xDE, 0x03, 0xFF,
WRITE_COMMAND_8, 0xD5,
WRITE_BYTES, 52,
0x00, 0x00, 0x00, 0x08,
0x00, 0x1D, 0x00, 0x5F,
0x00, 0x91, 0x00, 0xCE,
0x00, 0xF5, 0x01, 0x2B,
0x01, 0x7F, 0x01, 0xED,
0x02, 0x23, 0x02, 0x78,
0x02, 0xB2, 0x02, 0xB4,
0x02, 0xF1, 0x03, 0x29,
0x03, 0x49, 0x03, 0x6D,
0x03, 0x82, 0x03, 0x9B,
0x03, 0xA5, 0x03, 0xB0,
0x03, 0xB5, 0x03, 0xBF,
0x03, 0xDE, 0x03, 0xFF,
WRITE_COMMAND_8, 0xD6,
WRITE_BYTES, 52,
0x00, 0x00, 0x00, 0x08,
0x00, 0x1D, 0x00, 0x5F,
0x00, 0x91, 0x00, 0xCE,
0x00, 0xF5, 0x01, 0x2B,
0x01, 0x7F, 0x01, 0xED,
0x02, 0x23, 0x02, 0x78,
0x02, 0xB2, 0x02, 0xB4,
0x02, 0xF1, 0x03, 0x29,
0x03, 0x49, 0x03, 0x6D,
0x03, 0x82, 0x03, 0x9B,
0x03, 0xA5, 0x03, 0xB0,
0x03, 0xB5, 0x03, 0xBF,
0x03, 0xDE, 0x03, 0xFF,
DELAY, 5,
WRITE_COMMAND_8, 0x11,
DELAY, 121,

WRITE_COMMAND_8, 0x29,
DELAY, 22,

WRITE_COMMAND_8, 0x29,
DELAY, 4,

WRITE_C8_D8, 0xB1, 0x13,
DELAY,40,
WRITE_C8_D8, 0xB1, 0x13,
END_WRITE,

DELAY, 1,

BEGIN_WRITE,
I2C_WRITE_REG, 0x01, 0xF1,
I2C_WRITE_REG, 0x01, 0xF3,
END_WRITE,

DELAY, 1,
// 00 to 2F for 19 times
BEGIN_WRITE,
REPEAT_IN, 19, I2C_WRITE_REG, 0x2F, 0x00,
END_WRITE,
DELAY,255,
// Brightness control
// 0x01, Level, 0x00, 0xFF,0xFF screen always on

BEGIN_WRITE,
I2C_WRITE_SEQ, 0x21, 5, 0x01, 0x64, 0x00, 0x00, 0x14,
END_WRITE,
};
#endif /* HASP_LANBON_L10_TCA9554_GC9503V */

class Arduino_RGB_Display_Mod : public Arduino_GFX{
public:
Arduino_RGB_Display_Mod(
Expand Down
3 changes: 3 additions & 0 deletions src/dev/esp32/esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ long Esp32Device::get_uptime()
#warning Building for TTGo T-Watch
#include "dev/esp32/twatch.h"

#elif defined(HASP_ESP32_DEVICE_I2C_BACKLIGHT) && defined(HASP_USE_I2C_GPIO)
#include "dev/esp32/esp32_i2c_ledc.h"

#else
dev::Esp32Device haspDevice;
#endif
Expand Down
11 changes: 10 additions & 1 deletion src/dev/esp32/esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class Esp32Device : public BaseDevice {

bool is_system_pin(uint8_t pin) override;

protected:
/** For board-specific subclasses (e.g. I2C virtual backlight). Base = LEDC when pin is a real GPIO. */
virtual void update_backlight();
uint8_t get_backlight_pin() const
{
return _backlight_pin;
}

private:
std::string _hardware_id;
std::string _chip_model;
Expand All @@ -73,7 +81,6 @@ class Esp32Device : public BaseDevice {
bool _backlight_fading;
bool _backlight_fade;

void update_backlight();
static bool cb_backlight(const ledc_cb_param_t *param, void *user_arg);
void end_backlight_fade();
};
Expand All @@ -88,6 +95,8 @@ class Esp32Device : public BaseDevice {
#include "m5stackcore2.h"
#elif defined(TWATCH)
#include "twatch.h"
#elif defined(HASP_ESP32_DEVICE_I2C_BACKLIGHT) && defined(HASP_USE_I2C_GPIO)
#include "esp32_i2c_ledc.h"
#else
using dev::Esp32Device;
extern dev::Esp32Device haspDevice;
Expand Down
Loading