# HG changeset patch # User Ethan Zonca # Date 2015-11-28 14:29:25 # Node ID 857e86bbc10dbfca6c8de187a0be1684e212cdf7 # Parent 0dfb00c8792be5d1dc6dc22da1e7f2f774cbaae6 Refactor ssd1306 functions diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -48,15 +48,15 @@ void display_process(therm_settings_t* s { // Write text to OLED // [ therm :: idle ] - ssd1306_DrawString("therm :: idle ", 0, 40); + ssd1306_drawstring("therm :: idle ", 0, 40); status->pid_enabled = 0; if(temp_changed) { char tempstr[6]; itoa_fp(status->temp, status->temp_frac, tempstr); - ssd1306_DrawString("Temp: ", 3, 40); - ssd1306_DrawString(" ", 3, 72); - ssd1306_DrawString(tempstr, 3, 72); + ssd1306_drawstring("Temp: ", 3, 40); + ssd1306_drawstring(" ", 3, 72); + ssd1306_drawstring(tempstr, 3, 72); } ssd1306_drawlogo(); @@ -64,22 +64,22 @@ void display_process(therm_settings_t* s switch(goto_mode) { case 3: { - ssd1306_DrawString("-> loader ", 1, 40); + ssd1306_drawstring("-> loader ", 1, 40); } break; case 2: { - ssd1306_DrawString("-> heat ", 1, 40); + ssd1306_drawstring("-> heat ", 1, 40); } break; case 1: { - ssd1306_DrawString("-> setup ", 1, 40); + ssd1306_drawstring("-> setup ", 1, 40); } break; case 0: { - ssd1306_DrawString("-> reset ", 1, 40); + ssd1306_drawstring("-> reset ", 1, 40); } } @@ -89,9 +89,9 @@ void display_process(therm_settings_t* s case 3: { ssd1306_clearscreen(); - ssd1306_DrawString("Bootloader Entered", 0, 0); - ssd1306_DrawString("Device won't boot", 2, 0); - ssd1306_DrawString("until reflashed!", 3, 0); + ssd1306_drawstring("Bootloader Entered", 0, 0); + ssd1306_drawstring("Device won't boot", 2, 0); + ssd1306_drawstring("until reflashed!", 3, 0); bootloader_enter(); // Resets into bootloader status->state = STATE_IDLE; // Just in case } break; @@ -129,16 +129,16 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm :: set p ] // [ p = 12 ] - ssd1306_DrawString("Proportional", 0, 40); + ssd1306_drawstring("Proportional", 0, 40); ssd1306_drawlogo(); char tempstr[6]; itoa(set->val.k_p, tempstr, 10); - ssd1306_DrawString("P=", 1, 45); - ssd1306_DrawString(" ", 1, 57); - ssd1306_DrawString(tempstr, 1, 57); + ssd1306_drawstring("P=", 1, 45); + ssd1306_drawstring(" ", 1, 57); + ssd1306_drawstring(tempstr, 1, 57); - ssd1306_DrawString("Press to accept", 3, 40); + ssd1306_drawstring("Press to accept", 3, 40); // Button handler if(SW_BTN_PRESSED) { @@ -158,16 +158,16 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm :: set i ] // [ i = 12 ] - ssd1306_DrawString("Integral", 0, 40); + ssd1306_drawstring("Integral", 0, 40); ssd1306_drawlogo(); char tempstr[6]; itoa(set->val.k_i, tempstr, 10); - ssd1306_DrawString("I=", 1, 45); - ssd1306_DrawString(" ", 1, 57); - ssd1306_DrawString(tempstr, 1, 57); + ssd1306_drawstring("I=", 1, 45); + ssd1306_drawstring(" ", 1, 57); + ssd1306_drawstring(tempstr, 1, 57); - ssd1306_DrawString("Press to accept", 3, 40); + ssd1306_drawstring("Press to accept", 3, 40); // Button handler if(SW_BTN_PRESSED) { @@ -187,16 +187,16 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm :: set d ] // [ d = 12 ] - ssd1306_DrawString("Derivative", 0, 40); + ssd1306_drawstring("Derivative", 0, 40); ssd1306_drawlogo(); char tempstr[6]; itoa(set->val.k_d, tempstr, 10); - ssd1306_DrawString("D=", 1, 45); - ssd1306_DrawString(" ", 1, 57); - ssd1306_DrawString(tempstr, 1, 57); + ssd1306_drawstring("D=", 1, 45); + ssd1306_drawstring(" ", 1, 57); + ssd1306_drawstring(tempstr, 1, 57); - ssd1306_DrawString("Press to accept", 3, 40); + ssd1306_drawstring("Press to accept", 3, 40); // Button handler if(SW_BTN_PRESSED) { @@ -216,16 +216,16 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm :: set windup ] // [ g = 12 ] - ssd1306_DrawString("Windup Guard", 0, 40); + ssd1306_drawstring("Windup Guard", 0, 40); ssd1306_drawlogo(); char tempstr[6]; itoa(set->val.windup_guard, tempstr, 10); - ssd1306_DrawString("G=", 1, 45); - ssd1306_DrawString(" ", 1, 57); - ssd1306_DrawString(tempstr, 1, 57); + ssd1306_drawstring("G=", 1, 45); + ssd1306_drawstring(" ", 1, 57); + ssd1306_drawstring(tempstr, 1, 57); - ssd1306_DrawString("Press to accept", 3, 40); + ssd1306_drawstring("Press to accept", 3, 40); // Button handler if(SW_BTN_PRESSED) { @@ -245,17 +245,17 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm :: set windup ] // [ g = 12 ] - ssd1306_DrawString("Start on Boot", 0, 40); + ssd1306_drawstring("Start on Boot", 0, 40); ssd1306_drawlogo(); - ssd1306_DrawString("sob=", 1, 45); + ssd1306_drawstring("sob=", 1, 45); if(set->val.boottobrew) - ssd1306_DrawString("Enabled ", 1, 70); + ssd1306_drawstring("Enabled ", 1, 70); else - ssd1306_DrawString("Disabled", 1, 70); + ssd1306_drawstring("Disabled", 1, 70); - ssd1306_DrawString("Press to accept", 3, 40); + ssd1306_drawstring("Press to accept", 3, 40); // Button handler if(SW_BTN_PRESSED) { @@ -278,15 +278,15 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm :: set windup ] // [ g = 12 ] - ssd1306_DrawString("Units: ", 0, 40); + ssd1306_drawstring("Units: ", 0, 40); ssd1306_drawlogo(); if(set->val.temp_units == TEMP_UNITS_FAHRENHEIT) - ssd1306_DrawString("Fahrenheit", 1, 60); + ssd1306_drawstring("Fahrenheit", 1, 60); else - ssd1306_DrawString("Celsius ", 1, 60); + ssd1306_drawstring("Celsius ", 1, 60); - ssd1306_DrawString("Press to accept", 3, 40); + ssd1306_drawstring("Press to accept", 3, 40); // Button handler if(SW_BTN_PRESSED) { @@ -310,16 +310,16 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm :: set temp offset ] // [ g = 12 ] - ssd1306_DrawString("Temp Cal Offset", 0, 40); + ssd1306_drawstring("Temp Cal Offset", 0, 40); ssd1306_drawlogo(); char tempstr[6]; itoa(set->val.temp_offset, tempstr, 10); - ssd1306_DrawString("O=", 1, 45); - ssd1306_DrawString(" ", 1, 57); - ssd1306_DrawString(tempstr, 1, 57); + ssd1306_drawstring("O=", 1, 45); + ssd1306_drawstring(" ", 1, 57); + ssd1306_drawstring(tempstr, 1, 57); - ssd1306_DrawString("Press to accept", 3, 40); + ssd1306_drawstring("Press to accept", 3, 40); // Button handler if(SW_BTN_PRESSED) { @@ -341,7 +341,7 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm : preheating brew ] // [ 30 => 120 C ] - ssd1306_DrawString("Preheating...", 0, 0); + ssd1306_drawstring("Preheating...", 0, 0); //ssd1306_drawlogo(); draw_setpoint(status); @@ -368,7 +368,7 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm : ready to brew ] // [ 30 => 120 C ] - ssd1306_DrawString("Preheated!", 0, 0); + ssd1306_drawstring("Preheated!", 0, 0); //ssd1306_drawlogo(); draw_setpoint(status); status->pid_enabled = 1; @@ -392,7 +392,7 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm : preheating steam ] // [ 30 => 120 C ] - ssd1306_DrawString("Preheating...", 0, 0); + ssd1306_drawstring("Preheating...", 0, 0); //ssd1306_drawlogo(); draw_setpoint(status); status->pid_enabled = 1; @@ -418,7 +418,7 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm : ready to steam ] // [ 30 => 120 C ] - ssd1306_DrawString("Ready to Steam!", 0, 0); + ssd1306_drawstring("Ready to Steam!", 0, 0); //ssd1306_drawlogo(); draw_setpoint(status); status->pid_enabled = 1; @@ -442,24 +442,24 @@ void display_process(therm_settings_t* s // Write text to OLED // [ therm : ready to steam ] // [ 30 => 120 C ] - ssd1306_DrawString("Error: ", 0, 0); + ssd1306_drawstring("Error: ", 0, 0); char tempstr[6]; itoa(status->tc_errno, tempstr, 10); - ssd1306_DrawString(tempstr, 0, 57); + ssd1306_drawstring(tempstr, 0, 57); if(status->tc_errno == 1) - ssd1306_DrawString(" TC Open Circuit", 1, 0); + ssd1306_drawstring(" TC Open Circuit", 1, 0); else if(status->tc_errno == 4) - ssd1306_DrawString(" TC Short to GND", 1, 0); + ssd1306_drawstring(" TC Short to GND", 1, 0); else if(status->tc_errno == 8) - ssd1306_DrawString(" TC Short to VCC", 1, 0); + ssd1306_drawstring(" TC Short to VCC", 1, 0); else - ssd1306_DrawString("#?, Unknown Error", 1, 0); - ssd1306_DrawString(" ", 2, 0); + ssd1306_drawstring("#?, Unknown Error", 1, 0); + ssd1306_drawstring(" ", 2, 0); - ssd1306_DrawString("-> to ignore all or", 2, 0); - ssd1306_DrawString("press to continue", 3, 0); + ssd1306_drawstring("-> to ignore all or", 2, 0); + ssd1306_drawstring("press to continue", 3, 0); // Button handler if(SW_BTN_PRESSED) { @@ -508,18 +508,18 @@ void draw_setpoint(therm_status_t* statu if(status->temp != temp_last || trigger_drawsetpoint) { char tempstr[3]; itoa_fp(status->temp, status->temp_frac, tempstr); - ssd1306_DrawStringBig(" ", 3, 0); - ssd1306_DrawStringBig(tempstr, 3, 0); + ssd1306_drawstringbig(" ", 3, 0); + ssd1306_drawstringbig(tempstr, 3, 0); } if(trigger_drawsetpoint) - ssd1306_DrawStringBig(">", 3, 74); + ssd1306_drawstringbig(">", 3, 74); if(status->setpoint != setpoint_last || trigger_drawsetpoint) { char tempstr[3]; itoa(status->setpoint, tempstr, 10); - ssd1306_DrawStringBig(" ", 3, 90); - ssd1306_DrawStringBig(tempstr, 3, 90); + ssd1306_drawstringbig(" ", 3, 90); + ssd1306_drawstringbig(tempstr, 3, 90); } trigger_drawsetpoint = 0; diff --git a/flash.c b/flash.c --- a/flash.c +++ b/flash.c @@ -16,12 +16,12 @@ static void __flash_write(therm_settings void flash_save(therm_settings_t* tosave) { ssd1306_clearscreen(); - ssd1306_DrawString("Erase...", 0, 0); + ssd1306_drawstring("Erase...", 0, 0); HAL_Delay(100); - ssd1306_DrawString("Save...", 1, 0); + ssd1306_drawstring("Save...", 1, 0); __flash_write(tosave); HAL_Delay(100); - ssd1306_DrawString("Done!", 2, 0); + ssd1306_drawstring("Done!", 2, 0); HAL_Delay(500); } @@ -29,11 +29,11 @@ void flash_save(therm_settings_t* tosave void flash_restore(therm_settings_t *torestore) { ssd1306_clearscreen(); - ssd1306_DrawString("READING SAVE", 1, 0); + ssd1306_drawstring("READING SAVE", 1, 0); if(eeprom[EEPROM_MAGIC_INDEX] != EEPROM_MAGIC_VALUE) { - ssd1306_DrawString("No data to read!", 2, 0); + ssd1306_drawstring("No data to read!", 2, 0); return; } @@ -42,7 +42,7 @@ void flash_restore(therm_settings_t *tor for(i=0;i<128;i++) torestore->data[i] = *(eeprom+i); - ssd1306_DrawString("READ COMPLETE", 3, 0); + ssd1306_drawstring("READ COMPLETE", 3, 0); } diff --git a/gpio.c b/gpio.c --- a/gpio.c +++ b/gpio.c @@ -4,8 +4,10 @@ #include // Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow... -uint32_t change_time_reset = 0; +static uint32_t change_time_reset = 0; + +// Increment/decrement unsigned variable with up/down buttons void user_input(uint16_t* to_modify) { if(CHANGE_ELAPSED) { @@ -20,6 +22,8 @@ void user_input(uint16_t* to_modify) } } + +// Increment/decrement signed variable with up/down buttons void user_input_signed(int16_t* to_modify) { // TODO: Bounds check on int16_t @@ -36,8 +40,9 @@ void user_input_signed(int16_t* to_modif } -void gpio_init(void) { - +// Initialize GPIO +void gpio_init(void) +{ GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -49,7 +49,7 @@ int main(void) spi_init(); // Init OLED over SPI - ssd1306_Init(); + ssd1306_init(); ssd1306_clearscreen(); // Default settings @@ -76,8 +76,8 @@ int main(void) status.state = STATE_PREHEAT_BREW; // Startup screen - ssd1306_DrawString("therm v0.2", 1, 40); - ssd1306_DrawString("protofusion.org/therm", 3, 0); + ssd1306_drawstring("therm v0.2", 1, 40); + ssd1306_drawstring("protofusion.org/therm", 3, 0); HAL_Delay(1000); @@ -145,7 +145,7 @@ int main(void) { char tempstr[6]; itoa(ssr_output, tempstr, 10); - ssd1306_DrawString(tempstr, 0, 90); + ssd1306_drawstring(tempstr, 0, 90); HAL_GPIO_WritePin(SSR_PIN, 1); HAL_GPIO_WritePin(LED_POWER, 1); diff --git a/ssd1306.c b/ssd1306.c --- a/ssd1306.c +++ b/ssd1306.c @@ -2,7 +2,7 @@ #include "ssd1306.h" // Write command to OLED -void WriteCommand(unsigned char command) +static void WriteCommand(unsigned char command) { SSD_CS_Low(); SSD_A0_Low(); @@ -11,7 +11,7 @@ void WriteCommand(unsigned char command) } // Write data to OLED -void WriteData(unsigned char data) +static void WriteData(unsigned char data) { SSD_CS_Low(); SSD_A0_High(); @@ -20,7 +20,7 @@ void WriteData(unsigned char data) } // Initialize OLED -void ssd1306_Init(void) +void ssd1306_init(void) { /* Generate a reset */ @@ -179,13 +179,13 @@ static const char fontData[][5] = }; -void setStartPage(unsigned char d) +static void setStartPage(unsigned char d) { WriteCommand(0xB0|d); // Set Page Start Address for Page Addressing Mode // Default => 0xB0 (0x00) } /* Below are functions used to configure the OLED */ -void setStartColumn(unsigned char d) +static void setStartColumn(unsigned char d) { WriteCommand(0x00+d%16); // Set Lower Column Start Address for Page Addressing Mode WriteCommand(0x10+d/16); // Set Higher Column Start Address for Page Addressing Mode @@ -259,7 +259,7 @@ void ssd1306_drawlogo() } /* Print a single character from font.cpp */ -void ssd1306_DrawChar(char ascii, unsigned char row, unsigned char xPos) +void ssd1306_drawchar(char ascii, unsigned char row, unsigned char xPos) { char *srcPointer = -1; unsigned char i; @@ -277,7 +277,7 @@ void ssd1306_DrawChar(char ascii, unsign WriteData(0x00); } -void ssd1306_DrawCharBig(char ascii, unsigned char row, unsigned char xPos) +void ssd1306_drawcharbig(char ascii, unsigned char row, unsigned char xPos) { char *srcPointer = -1; unsigned char i; @@ -340,16 +340,16 @@ void ssd1306_DrawCharBig(char ascii, uns } -void ssd1306_DrawString(const char *dataPtr, unsigned char row, unsigned char xPos) +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 + ssd1306_drawchar(' ',row,xPos); // NBSP must be written first before the string start while(1) { - ssd1306_DrawChar(*srcPointer,row,xPos); + ssd1306_drawchar(*srcPointer,row,xPos); srcPointer++; xPos+=6; if(*srcPointer == 0) break; @@ -357,16 +357,16 @@ void ssd1306_DrawString(const char *data } -void ssd1306_DrawStringBig(const char *dataPtr, unsigned char row, unsigned char xPos) +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 + ssd1306_drawcharbig(' ',row,xPos); // NBSP must be written first before the string start while(1) { - ssd1306_DrawCharBig(*srcPointer,row,xPos); + ssd1306_drawcharbig(*srcPointer,row,xPos); srcPointer++; xPos+=12; if(*srcPointer == 0) break; diff --git a/ssd1306.h b/ssd1306.h --- a/ssd1306.h +++ b/ssd1306.h @@ -12,26 +12,19 @@ #define SSD_CS_Low() HAL_GPIO_WritePin(SSD_CS, 0) #define SSD_CS_High() HAL_GPIO_WritePin(SSD_CS, 1) -// Use stdperiph - -//extern SPI_HandleTypeDef spi1; - -extern SPI_HandleTypeDef hspi1; - // EMZ FIXME this won't really work -#define SPI_SendByte(data) HAL_SPI_Transmit(&hspi1, &data, 1, 100) +#define SPI_SendByte(data) HAL_SPI_Transmit(spi_get(), &data, 1, 100) //#define SPI_SendByte(data) #define SPI_Wait() //#define SPI_SendByte(data) SPI_I2S_SendData(SPI1,data) - //#define SPI_Wait() while(!(SPI1->SR&SPI_FLAG_TXE));while(SPI1->SR&SPI_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_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();