#include "stm32f0xx_hal.h"
#include "ssd1306.h"
#include "stringhelpers.h"
#include "display.h"
#include "config.h"
#include "states.h"
#include "syslib.h"
#include "flash.h"
#include "gpio.h"
#ifdef MAX31865_RTD_SENSOR
#include "max31865.h"
#endif
// Private function prototypes
static void draw_setpoint(therm_status_t* status);
// Button transition variables
static uint8_t sw_btn_last = 0;
static uint8_t sw_up_last = 0;
static uint8_t sw_down_last = 0;
static uint8_t sw_left_last = 0;
static uint8_t sw_right_last = 0;
@@ -150,25 +140,25 @@ void display_process(therm_settings_t* s
itoa(set->val.k_p, tempstr, 10);
ssd1306_drawstring("P=", 1, 45);
ssd1306_drawstring(" ", 1, 57);
ssd1306_drawstring(tempstr, 1, 57);
ssd1306_drawstring("Press to accept", 3, 40);
// Button handler
if(SW_BTN_PRESSED) {
status->state = STATE_SETI;
}
else {
user_input(&set->val.k_p);
user_input((uint16_t*)&set->val.k_p);
// Event Handler
// N/A
} break;
case STATE_SETI:
{
// Write text to OLED
// [ therm :: set i ]
// [ i = 12 ]
@@ -179,25 +169,25 @@ void display_process(therm_settings_t* s
itoa(set->val.k_i, tempstr, 10);
ssd1306_drawstring("I=", 1, 45);
status->state = STATE_SETD;
user_input(&set->val.k_i);
user_input((uint16_t*)&set->val.k_i);
case STATE_SETD:
// [ therm :: set d ]
// [ d = 12 ]
@@ -208,25 +198,25 @@ void display_process(therm_settings_t* s
itoa(set->val.k_d, tempstr, 10);
ssd1306_drawstring("D=", 1, 45);
status->state = STATE_SETWINDUP;
user_input(&set->val.k_d);
user_input((uint16_t*)&set->val.k_d);
case STATE_SETWINDUP:
// [ therm :: set windup ]
// [ g = 12 ]
@@ -237,25 +227,25 @@ void display_process(therm_settings_t* s
itoa(set->val.windup_guard, tempstr, 10);
ssd1306_drawstring("G=", 1, 45);
status->state = STATE_SETBOOTTOBREW;
user_input(&set->val.windup_guard);
user_input((uint16_t*)&set->val.windup_guard);
case STATE_SETBOOTTOBREW:
@@ -332,25 +322,25 @@ void display_process(therm_settings_t* s
ssd1306_drawstring("O=", 1, 45);
flash_save(set);
status->state = STATE_IDLE;
user_input_signed(&set->val.temp_offset);
user_input_signed((int16_t*)(&set->val.temp_offset));
case STATE_PREHEAT:
// [ therm : preheating brew ]
@@ -358,25 +348,25 @@ void display_process(therm_settings_t* s
ssd1306_drawstring("Preheating...", 0, 0);
//ssd1306_drawlogo();
draw_setpoint(status);
status->pid_enabled = 1;
status->setpoint = set->val.setpoint_brew;
user_input(&set->val.setpoint_brew);
user_input((uint16_t*)&set->val.setpoint_brew);
if(status->temp >= status->setpoint) {
status->state = STATE_MAINTAIN;
case STATE_MAINTAIN:
@@ -384,25 +374,25 @@ void display_process(therm_settings_t* s
// [ 30 => 120 C ]
ssd1306_drawstring("Preheated!", 0, 0);
// Thermocouple error
case STATE_TC_ERROR:
// [ therm : ready to steam ]
#ifndef DISPLAY_H
#define DISPLAY_H
#include <stdlib.h>
void display_process(therm_settings_t* set, therm_status_t* status);
#include "stm32f0xx_hal_conf.h"
#include <inttypes.h>
// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow...
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) {
if(!HAL_GPIO_ReadPin(SW_UP) ) {
CHANGE_RESET;
(*to_modify)++;
#ifndef GPIO_H
#define GPIO_H
#define CHANGE_PERIOD_MS 100
#define CHANGE_ELAPSED (HAL_GetTick() - change_time_reset) > CHANGE_PERIOD_MS
#define CHANGE_RESET change_time_reset = HAL_GetTick()
void user_input(uint16_t* to_modify);
void user_input_signed(int16_t* to_modify);
void gpio_init(void);
#include "pid.h"
#ifdef MAX31855_TC_SENSOR
#include "max31855.h"
#include "spi.h"
#include "usb_device.h"
#include "usbd_cdc_if.h"
therm_settings_t set;
therm_status_t status;
@@ -251,52 +251,50 @@ 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 = -1;
unsigned char i;
const char *srcPointer = (char*)-1;
srcPointer = &fontData[(ascii-32)][0];
setStartPage(row);
setStartColumn(xPos);
for(i=0;i<5;i++)
for(uint8_t i = 0; i < 5; i++)
WriteData(*srcPointer);
srcPointer++;
void ssd1306_drawcharbig(char ascii, unsigned char row, unsigned char xPos)
setStartPage(row-1);
// Write first row
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
@@ -306,25 +304,25 @@ void ssd1306_drawcharbig(char ascii, uns
WriteData(data);
srcPointer -= 5;
// Write second row
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
@@ -3,24 +3,26 @@
#define SSD_RESET GPIOA,GPIO_PIN_3
#define SSD_A0 GPIOA,GPIO_PIN_4
#define SSD_CS GPIOA,GPIO_PIN_2
#define SSD_Reset_Low() HAL_GPIO_WritePin(SSD_RESET, 0)
#define SSD_Reset_High() HAL_GPIO_WritePin(SSD_RESET, 1)
#define SSD_A0_Low() HAL_GPIO_WritePin(SSD_A0, 0)
#define SSD_A0_High() HAL_GPIO_WritePin(SSD_A0, 1)
#define SSD_CS_Low() HAL_GPIO_WritePin(SSD_CS, 0)
#define SSD_CS_High() HAL_GPIO_WritePin(SSD_CS, 1)
// EMZ FIXME this won't really work
#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);
Status change: