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
 
@@ -82,26 +82,27 @@ int main(void)
 
    RCC_GetClocksFreq(&RCC_Clocks);
 
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
 
 
    // Init SPI busses
 
    init_spi();
 
 
    // 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();
 
    USB_Init();
 
    //SYSCFG_USBPuCmd(ENABLE);
 
    //PowerOn();
 
 
    // Startup screen 
 
    ssd1306_DrawString("therm v0.1", 1, 40);
 
@@ -283,25 +284,25 @@ void process()
 
 
void draw_setpoint() {
 
    char tempstr[3];
 
    itoa_fp(temp, temp_frac, tempstr);
 
    //ssd1306_DrawString("        ", 3, 40);
 
    ssd1306_DrawString(tempstr, 3, 40);
 
    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;
 
uint8_t sw_right_last = 0;
 
 
#define SW_BTN_PRESSED (sw_btn_last == 0 && sw_btn == 1) // rising edge on buttonpress
 
#define SW_UP_PRESSED (sw_up_last == 0 && sw_up == 1)
 
#define SW_DOWN_PRESSED (sw_down_last == 0 && sw_down == 1)
 
#define SW_LEFT_PRESSED (sw_left_last == 0 && sw_left == 1)
ssd1306.c
Show inline comments
 
@@ -250,45 +250,126 @@ void ssd1306_drawlogo()
 
    setStartPage(0);
 
    setStartColumn(0);
 
    for(i = 0; i<32; i++)
 
    {
 
        WriteData(row[3][i]);
 
    }
 
    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);
 
 
    for(i=0;i<5;i++)
 
    {
 
        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
 
 
    while(1)
 
    {
 
        ssd1306_DrawChar(*srcPointer,row,xPos);
 
        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
 
@@ -10,19 +10,21 @@
 
#define   SSD_A0_Low()      GPIO_ResetBits(SSD_A0)
 
#define   SSD_A0_High()     GPIO_SetBits(SSD_A0)
 
#define   SSD_CS_Low()      GPIO_ResetBits(SSD_CS)
 
#define   SSD_CS_High()     GPIO_SetBits(SSD_CS)
 
 
// Use stdperiph
 
#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)