@@ -9,24 +9,26 @@
// TODO: Grab buttonpresses with interrupts
#define SW_BTN GPIOB, GPIO_Pin_3
#define SW_UP GPIOB, GPIO_Pin_7
#define SW_DOWN GPIOB, GPIO_Pin_6
#define SW_LEFT GPIOB, GPIO_Pin_5
#define SW_RIGHT GPIOB, GPIO_Pin_4
static __IO uint32_t TimingDelay;
void init_gpio();
void init_spi();
void process();
void machine();
int main(void)
{
// Init clocks
SystemInit();
RCC_ClocksTypeDef RCC_Clocks;
// SysTick end of count event each 1ms
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
@@ -41,45 +43,239 @@ int main(void)
GPIO_SetBits(LED_POWER);
Delay(500);
GPIO_ResetBits(LED_POWER);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
init_spi();
while(1)
// Process sensor inputs [TODO: 5hz?]
process();
// Run state machine [TODO: 50hz?]
machine(); // this argument is sooo wrong
// probably just passed the actual port
uint8_t sw_btn = GPIO_ReadInputDataBit(SW_BTN);
uint8_t sw_up = GPIO_ReadInputDataBit(SW_UP);
uint8_t sw_down = GPIO_ReadInputDataBit(SW_DOWN);
uint8_t sw_left = GPIO_ReadInputDataBit(SW_LEFT);
uint8_t sw_right = GPIO_ReadInputDataBit(SW_RIGHT);
SPI_I2S_SendData(SPI2,0xFA);
SPI_I2S_SendData(SPI1,0xFA);
if(!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_3)) {
GPIO_ToggleBits(LED_STAT);
}
// ssd1306_DrawPoint(5,5,0);
Delay(150);
int32_t temp = 0;
int32_t setpoint = 0;
int32_t p = 1;
int32_t i = 1;
int32_t d = 1;
// Process things
void process()
// Read MAX temp sensor
temp = 0;
// Perform PID calculations
// Write output to SSR
enum state {
STATE_IDLE = 0,
STATE_SETP,
STATE_SETI,
STATE_SETD,
STATE_PREHEAT_BREW,
STATE_MAINTAIN_BREW,
STATE_PREHEAT_STEAM,
STATE_MAINTAIN_STEAM,
};
uint8_t state = STATE_IDLE;
// State machine
void machine()
switch(state)
// Idle state
case STATE_IDLE:
// Write text to OLED
// [ therm :: idle ]
// Button handler
if(GPIO_ReadInputDataBit(SW_BTN)) {
state = STATE_SETP;
// Event Handler
// N/A
} break;
case STATE_SETP:
// [ therm :: set p ]
// [ p = 12 ]
state = STATE_IDLE;
case STATE_SETI:
// [ therm :: set i ]
// [ i = 12 ]
case STATE_SETD:
// [ therm :: set d ]
// [ d = 12 ]
case STATE_PREHEAT_BREW:
// [ therm : preheating brew ]
// [ 30 => 120 C ]
if(temp >= setpoint) {
state = STATE_MAINTAIN_BREW;
case STATE_MAINTAIN_BREW:
// [ therm : ready to brew ]
case STATE_PREHEAT_STEAM:
// [ therm : preheating steam ]
state = STATE_MAINTAIN_STEAM;
case STATE_MAINTAIN_STEAM:
// [ therm : ready to steam ]
// Something is terribly wrong
deault:
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 1 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
TimingDelay = nTime;
while(TimingDelay != 0);
Status change: