In hopes of better understanding the OLED object, and ultimately being able to code some nice graphics, I will start a rant about the OLED code here.
(Note that in 1.0.12, there is no easy way of embedding the display object so as to edit it freely, because the way “includes” are handled has not been fixed yet (hopefully fixed in v1.1.0). Long story. Use the object skeleton patch, display gills skeleton.axp provided below.
Let’s look at the gills/display object (Local Data) but ignore all the low-level controller stuff for now.
It looks like the function fill(uint8_t) inside the gills (big genes) OLED object is a good starting point.
void fill(uint8_t v) {
i2cAcquireBus(&I2CD1);
cmd(COLUMNADDR, 0, 127); /* Column start end */
cmd(PAGEADDR, 0, 7); /* Page start end */
txbuf[0] = 0x40;
uint8_t i; for (i = 1; i < 129; i++) {
txbuf[i] = v;
}
uint8_t p; for (p = 0; p < 8; p++) {
i2cMasterTransmitTimeout(&I2CD1, __I2C_ADDR, txbuf, 129, rxbuf, 0, 30);
}
i2cReleaseBus(&I2CD1);
}
Let’s look at each line and figure out what it does:
i2cAcquireBus()
→ blah blah some hardware stuff to take control of the I2C system. &I2CD1 here means “to the address of I2C1 driver”, that’s just fixed by hardware and ChibiOS. Pins PB8 and PB9, it is what it is.
cmd(xxx)
This is a simple function (also found inside the OLED object) to push a quick set of bytes to the OLED controller, so it carries out the respective command. the relevant list of commands can be found in the SSH1106 datasheet, or we can just look at the KSO_OLED enum in our OLED object. Anyway,
cmd(COLUMNADDR, 0, 127); /* Column start end */
cmd(PAGEADDR, 0, 7); /* Page start end */
is telling the OLED that we are going to write 128 pixels, from 0 to 127 (the full range of columns, as the OLED is 128 pixels wide) and pages 0 to 7.
