Changeset - 4157af9eb546
[Not reviewed]
default
0 3 0
Ethan Zonca - 10 years ago 2014-10-18 17:09:51
ez@ethanzonca.com
Large font rendering supported
3 files changed with 88 insertions and 4 deletions:
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -88,14 +88,15 @@ int main(void)
 
    // Init OLED over SPI
 
    ssd1306_Init();
 
    ssd1306_clearscreen();
 
 
    // Check for problems on startup
 
    if(clock_fail) {
 
        ssd1306_DrawString("ERROR: Check Xtal", 3, 0);
 
        delay(2000);
 
        //ssd1306_DrawStringBig("ERROR: Check Xtal", 2, 0);
 
        ssd1306_DrawStringBig("XTAL ERR", 2, 0);
 
        delay(5000);
 
    }
 
 
    // Init USB
 
    //Set_System(); // hw_config.h
 
    Set_USBClock();
 
    USB_Interrupts_Config();
 
@@ -289,13 +290,13 @@ void draw_setpoint() {
 
    ssd1306_DrawString("-> ", 3, 80);
 
    itoa(setpoint, tempstr);
 
    ssd1306_DrawString("    ", 3, 95);
 
    ssd1306_DrawString(tempstr, 3, 95);
 
}
 
 
uint8_t goto_mode = 1;
 
uint8_t goto_mode = 2;
 
 
// State machine
 
uint8_t sw_btn_last = 0;
 
uint8_t sw_up_last = 0;
 
uint8_t sw_down_last = 0;
 
uint8_t sw_left_last = 0;
ssd1306.c
Show inline comments
 
@@ -256,13 +256,13 @@ void ssd1306_drawlogo()
 
    WriteData(0x00);
 
}
 
 
/* Print a single character from font.cpp */
 
void ssd1306_DrawChar(char ascii, unsigned char row, unsigned char xPos)
 
{
 
    char *srcPointer = 0;
 
    char *srcPointer = -1;
 
    unsigned char i;
 
 
    srcPointer = &fontData[(ascii-32)][0];
 
 
    setStartPage(row);
 
    setStartColumn(xPos);
 
@@ -272,12 +272,75 @@ void ssd1306_DrawChar(char ascii, unsign
 
        WriteData(*srcPointer);
 
        srcPointer++;
 
    }
 
    WriteData(0x00);
 
}
 
 
void ssd1306_DrawCharBig(char ascii, unsigned char row, unsigned char xPos)
 
{
 
    char *srcPointer = -1;
 
    unsigned char i;
 
 
    srcPointer = &fontData[(ascii-32)][0];
 
 
    setStartPage(row-1);
 
    setStartColumn(xPos);
 
 
    // Write first row
 
    for(i=0;i<5;i++)
 
    {
 
        uint8_t data = 0;
 
        data |= ((*srcPointer) & 0b1000) << 4; // get top 4 bits
 
        data |= ((*srcPointer) & 0b1000) << 3; // get top 4 bits
 
 
        data |= ((*srcPointer) & 0b0100) << 3; // get top 4 bits
 
        data |= ((*srcPointer) & 0b0100) << 2; // get top 4 bits
 
 
        data |= ((*srcPointer) & 0b0010) << 2; // get top 4 bits
 
        data |= ((*srcPointer) & 0b0010) << 1; // get top 4 bits
 
 
        data |= ((*srcPointer) & 0b0001) << 1; // get top 4 bits
 
        data |= ((*srcPointer) & 0b0001); // get top 4 bits
 
 
        WriteData(data);
 
        WriteData(data);
 
 
        srcPointer++;
 
    }
 
    WriteData(0x00);
 
 
    srcPointer -= 5;
 
 
    setStartPage(row);
 
    setStartColumn(xPos);
 
 
    // Write second row
 
    for(i=0;i<5;i++)
 
    {
 
        uint8_t data = 0;
 
        data |=  (*srcPointer) & 0b10000000; // get top 4 bits
 
        data |= ((*srcPointer) & 0b10000000) >> 1; // get top 4 bits
 
 
        data |= ((*srcPointer) & 0b01000000) >> 1; // get top 4 bits
 
        data |= ((*srcPointer) & 0b01000000) >> 2; // get top 4 bits
 
 
        data |= ((*srcPointer) & 0b00100000) >> 2; // get top 4 bits
 
        data |= ((*srcPointer) & 0b00100000) >> 3; // get top 4 bits
 
 
        data |= ((*srcPointer) & 0b00010000) >> 3; // get top 4 bits
 
        data |= ((*srcPointer) & 0b00010000) >> 4; // get top 4 bits
 
 
        WriteData(data);
 
        WriteData(data);
 
 
        srcPointer++;
 
    }
 
    WriteData(0x00);
 
 
 
}
 
 
void ssd1306_DrawString(const char *dataPtr, unsigned char row, unsigned char xPos)
 
{
 
    char *srcPointer;
 
 
    srcPointer = (char*)dataPtr;
 
    ssd1306_DrawChar(' ',row,xPos); // NBSP must be written first before the string start
 
@@ -288,7 +351,25 @@ void ssd1306_DrawString(const char *data
 
        srcPointer++;
 
        xPos+=6;
 
        if(*srcPointer == 0) break;
 
    }
 
}
 
 
 
void ssd1306_DrawStringBig(const char *dataPtr, unsigned char row, unsigned char xPos)
 
{
 
    char *srcPointer;
 
 
    srcPointer = (char*)dataPtr;
 
    ssd1306_DrawCharBig(' ',row,xPos); // NBSP must be written first before the string start
 
 
    while(1)
 
    {
 
        ssd1306_DrawCharBig(*srcPointer,row,xPos);
 
        srcPointer++;
 
        xPos+=12;
 
        if(*srcPointer == 0) break;
 
    }
 
}
 
 
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
ssd1306.h
Show inline comments
 
@@ -16,13 +16,15 @@
 
#define   SPI_SendByte(data)  SPI_I2S_SendData(SPI1,data) 
 
#define   SPI_Wait()       while(!(SPI1->SR&SPI_I2S_FLAG_TXE));while(SPI1->SR&SPI_I2S_FLAG_BSY); 
 
 
 
void ssd1306_Init(void);
 
void ssd1306_DrawChar(char ascii, unsigned char row, unsigned char xPos);
 
void ssd1306_DrawCharBig(char ascii, unsigned char row, unsigned char xPos);
 
void ssd1306_DrawString(const char *dataPtr, unsigned char row, unsigned char xPos);
 
void ssd1306_DrawStringBig(const char *dataPtr, unsigned char row, unsigned char xPos);
 
void ssd1306_drawlogo();
 
void ssd1306_clearscreen();
 
 
#endif
 
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
0 comments (0 inline, 0 general)