Fix udisplay positional replacements (#21121)

This commit is contained in:
Theo Arends 2024-07-12 14:57:27 +02:00
parent 59de2fd979
commit f68ac4377a
2 changed files with 21 additions and 15 deletions

View File

@ -1074,10 +1074,11 @@ Renderer *uDisplay::Init(void) {
wire = &Wire1; wire = &Wire1;
} }
#endif // ESP32 #endif // ESP32
/*
if (i2c_sda != i2c_scl) { if (i2c_sda != i2c_scl) {
wire->begin(i2c_sda, i2c_scl); // TODO: aren't I2C buses already initialized? Shouldn't this be moved to display driver? wire->begin(i2c_sda, i2c_scl); // TODO: aren't I2C buses already initialized? Shouldn't this be moved to display driver?
} }
*/
#ifdef UDSP_DEBUG #ifdef UDSP_DEBUG
Serial.printf("I2C cmds: %d\n", dsp_ncmds); Serial.printf("I2C cmds: %d\n", dsp_ncmds);
#endif #endif

View File

@ -171,9 +171,11 @@ int8_t cs;
} }
//,3c,22,21,-1 //,3c,22,21,-1
uint8_t i2caddr = strtol(cp, &cp, 16); uint8_t i2caddr = strtol(cp, &cp, 16);
int8_t scl, sda; //,22,21,-1
scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n - 1)); cp++;
sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n - 1)); //22,21,-1
int8_t scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n - 1));
int8_t sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n - 1));
replacepin(&cp, Pin(GPIO_OLED_RESET)); replacepin(&cp, Pin(GPIO_OLED_RESET));
if (wire_n == 1) { if (wire_n == 1) {
@ -346,19 +348,17 @@ int8_t cs;
cp += 2; cp += 2;
uint8_t i2caddr = strtol(cp, &cp, 16); uint8_t i2caddr = strtol(cp, &cp, 16);
int8_t scl, sda, irq = -1, rst = -1; cp++;
scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n)); int8_t scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n));
sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n)); int8_t sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n));
int8_t irq = -1;
if (*(cp - 1) == ',') { if (*(cp - 1) == ',') {
irq = strtol(cp, &cp, 10); irq = strtol(cp, &cp, 10);
} else {
irq = -1;
} }
int8_t rst = -1;
if (*cp == ',') { if (*cp == ',') {
cp++; cp++;
rst = strtol(cp, &cp, 10); rst = strtol(cp, &cp, 10);
} else {
rst = -1;
} }
if (wire_n == 0) { if (wire_n == 0) {
@ -523,15 +523,20 @@ int8_t cs;
int8_t replacepin(char **cp, int16_t pin) { int8_t replacepin(char **cp, int16_t pin) {
int8_t res = 0; int8_t res = 0;
char *lp = *cp; char *lp = *cp;
if (*lp == ',') lp++; // cp = 6,*,* and pin = 4 => lp = 6,*,* and cp = *,*
if (*lp == '*') { // cp = *,*,* and pin = 4 => lp = 4,*,* and cp = *,*
// cp = ,*,* and pin = 4 => lp = 4,*,* and cp = *,*
if ((*lp == '*') || (*lp == ',')) {
char val[8]; char val[8];
itoa(pin, val, 10); itoa(pin, val, 10);
uint16_t slen = strlen(val); uint16_t slen = strlen(val);
//AddLog(LOG_LEVEL_INFO, PSTR("replace pin: %d"), pin); //AddLog(LOG_LEVEL_INFO, PSTR("replace pin: %d"), pin);
memmove(lp + slen, lp + 1, strlen(lp)); uint32_t idx = 0;
if (*lp == '*') { idx++; }
memmove(lp + slen, lp + idx, strlen(lp));
memmove(lp, val, slen); memmove(lp, val, slen);
} }
res = strtol(lp, 0, 10); res = strtol(lp, 0, 10);
char *np = strchr(lp, ','); char *np = strchr(lp, ',');
if (np) { if (np) {