MCPcopy Create free account
hub / github.com/OpenStickCommunity/GP2040-CE / obdI2CInit

Function obdI2CInit

lib/OneBitDisplay/OneBitDisplay.cpp:458–600  ·  view source on GitHub ↗

Initializes the OLED controller into "page mode"

Source from the content-addressed store, hash-verified

456// Initializes the OLED controller into "page mode"
457//
458int obdI2CInit(OBDISP *pOBD, int iType, int iAddr, int bFlip, int bInvert, int bWire, PeripheralI2C* i2cController, int reset)
459{
460 unsigned char uc[32];
461 uint8_t u8Len, *s;
462 int rc = OLED_NOT_FOUND;
463
464 pOBD->ucScreen = NULL; // reset backbuffer; user must provide one later
465 pOBD->type = iType;
466 pOBD->flip = bFlip;
467 pOBD->invert = bInvert;
468 pOBD->wrap = 0; // default - disable text wrap
469 pOBD->i2c = i2cController;
470 pOBD->bWire = bWire;
471 pOBD->com_mode = COM_I2C; // communication mode
472
473 //I2CInit(&pOBD->bbi2c, iSpeed); // on Linux, SDA = bus number, SCL = device address
474
475 // Reset it
476 if (reset != -1)
477 {
478 gpio_set_dir(reset, true);
479 gpio_put(reset, HIGH);
480 sleep_ms(50);
481 gpio_put(reset, LOW);
482 sleep_ms(50);
483 gpio_put(reset, HIGH);
484 sleep_ms(10);
485 }
486 // find the device address if requested
487 if (iAddr == -1 || iAddr == 0 || iAddr == 0xff) // find it
488 {
489 pOBD->i2c->test(0x3c);
490 if (pOBD->i2c->test(0x3c))
491 pOBD->oled_addr = 0x3c;
492 else if (pOBD->i2c->test(0x3d))
493 pOBD->oled_addr = 0x3d;
494 else
495 return rc; // no display found!
496 }
497 else
498 {
499 pOBD->oled_addr = iAddr;
500 pOBD->i2c->test(iAddr);
501 if (!pOBD->i2c->test(iAddr))
502 return rc; // no display found
503 }
504
505 // Detect the display controller (SSD1306, SH1107 or SH1106)
506 uint8_t u = 0;
507 pOBD->i2c->readRegister(pOBD->oled_addr, 0x00, &u, 1); // read the status register
508 u &= 0x0f; // mask off power on/off bit
509 if ((u == 0x7 || u == 0xf) && pOBD->type == OLED_128x128) // SH1107
510 { // A single SSD1306 display returned 7, so only act on it if the
511 // user specified that they're working with a 128x128 display
512 rc = OLED_SH1107_3C;
513 bFlip = !bFlip; // SH1107 seems to have this reversed from the usual direction
514 }
515 else if (u == 0x8) // SH1106

Callers 2

initMethod · 0.85
initDisplayMethod · 0.85

Calls 3

memcpyFunction · 0.85
testMethod · 0.80
readRegisterMethod · 0.45

Tested by

no test coverage detected