void RA8876::initExternalFontRom(int spiIf, enum ExternalFontRom chip)
{
// See data sheet figure 16-10
// TODO: GT30L24T3Y supports FAST_READ command (0x0B) and runs at 20MHz. Are the other font chips the same?
// Find a clock divisor. Values are in the range 2..512 in steps of 2.
int divisor;
uint32_t speed = 20000; // 20MHz target speed
for (divisor = 2; divisor <= 512; divisor += 2)
{
if (m_corePll.freq / divisor <= speed)
break;
}
m_fontRomInfo.present = true;
m_fontRomInfo.spiInterface = spiIf;
m_fontRomInfo.spiClockDivisor = divisor;
m_fontRomInfo.chip = chip;
if (deBug & 0x4) {
Serial.print("External font SPI divisor: ");
Serial.println(divisor);
}
SPI.beginTransaction(m_spiSettings);
// Ensure SPI is enabled in chip config register
uint8_t ccr = readReg(RA8876_REG_CCR);
if (!(ccr & 0x02))
writeReg(RA8876_REG_CCR, ccr | 0x02);
if (deBug & 0x4) {
Serial.print("SFL_CTRL: ");
Serial.println(((spiIf & 1) << 7) | 0x14, HEX);
}
writeReg(RA8876_REG_SFL_CTRL, ((spiIf & 1) << 7) | 0x14); // Font mode, 24-bit address, standard timing, supports FAST_READ
if (deBug & 0x4) {
Serial.print("SPI_DIVSOR: ");
Serial.println((divisor >> 1) - 1, HEX);
}
writeReg(RA8876_REG_SPI_DIVSOR, (divisor >> 1) - 1);
if (deBug & 0x4) {
Serial.print("GTFNT_SEL: ");
Serial.println((chip & 0x07) << 5, HEX);
}
writeReg(RA8876_REG_GTFNT_SEL, (chip & 0x07) << 5);
SPI.endTransaction();
}
void RA8876::selectExternalFont(enum ExternalFontFamily family, enum FontSize size, enum FontEncoding enc, FontFlags flags)
{
m_fontSource = RA8876_FONT_SOURCE_EXT_ROM;
m_fontSize = size;
m_fontFlags = flags;
SPI.beginTransaction(m_spiSettings);
if (deBug & 0x4) {
Serial.print("CCR0: ");
Serial.println(0x40 | ((size & 0x03) << 4), HEX);
}
writeReg(RA8876_REG_CCR0, 0x40 | ((size & 0x03) << 4)); // Select external font ROM and size
uint8_t ccr1 = readReg(RA8876_REG_CCR1);
#ifdef TRANSPARENT
if ((ccr1 & 0x40) == 0) {
ccr1 |= 0x40; // Transparent background
writeReg(RA8876_REG_CCR1, ccr1);
}
#else
if (ccr1 & 0x40) {
ccr1 &= ~0x40; // no Transparent background
writeReg(RA8876_REG_CCR1, ccr1);
}
#endif
if (deBug & 0x4) {
Serial.print("CCR1: ");
Serial.println(ccr1, HEX);
}
if (deBug & 0x4) {
Serial.print("GTFNT_CR: ");
Serial.println((enc << 3) | (family & 0x03), HEX);
}
writeReg(RA8876_REG_GTFNT_CR, (enc << 3) | (family & 0x03)); // Character encoding and family
SPI.endTransaction();
}