diff --git a/inc/system/gpio.h b/inc/system/gpio.h --- a/inc/system/gpio.h +++ b/inc/system/gpio.h @@ -4,6 +4,12 @@ #include "stm32f3xx_hal.h" +// Helper macros +#define CHANGE_PERIOD_MS 100 +#define CHANGE_ELAPSED (HAL_GetTick() - change_time_reset) > CHANGE_PERIOD_MS +#define CHANGE_RESET change_time_reset = HAL_GetTick() + + // Define button push #define SW_D_Pin GPIO_PIN_4 #define SW_D_GPIO_Port GPIOA diff --git a/lib/ssd1306/ssd1306.c b/lib/ssd1306/ssd1306.c --- a/lib/ssd1306/ssd1306.c +++ b/lib/ssd1306/ssd1306.c @@ -1,34 +1,21 @@ +// +// ssd1306: OLED display driver +// + #include "stm32f3xx_hal.h" #include "ssd1306.h" -SPI_HandleTypeDef hspi1; - - -// SPI handle accessor -SPI_HandleTypeDef* spi_get() -{ - return &hspi1; -} +// Private variables +static SPI_HandleTypeDef hspi1; -// Write command to OLED -static void WriteCommand(unsigned char command) -{ - SSD_CS_Low(); - SSD_A0_Low(); - SPI_SendByte(command); - SSD_CS_High(); -} +// Private method prototypes +static void WriteCommand(unsigned char command); +static void WriteData(unsigned char data); +static void setStartPage(unsigned char d); +static void setStartColumn(unsigned char d); -// Write data to OLED -static void WriteData(unsigned char data) -{ - SSD_CS_Low(); - SSD_A0_High(); - SPI_SendByte(data); - SSD_CS_High(); -} // Initialize OLED void ssd1306_init(void) @@ -38,7 +25,7 @@ void ssd1306_init(void) __GPIOB_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStruct; - /*Configure GPIO pins : OLED_CS_Pin OLED_RESET_Pin OLED_DC_Pin */ + // GPIO GPIO_InitStruct.Pin = OLED_CS_Pin|OLED_RESET_Pin|OLED_DC_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -227,10 +214,27 @@ static const char fontData[][5] = {0x22,0x5d,0x22,0x00,0x00}, // (111) ez updown {0x14,0x3e,0x14,0x00,0x00}, // (112) ez updown short }; -/* -*/ +// Write command to OLED +static void WriteCommand(unsigned char command) +{ + SSD_CS_Low(); + SSD_A0_Low(); + SPI_SendByte(command); + SSD_CS_High(); +} + + +// Write data to OLED +static void WriteData(unsigned char data) +{ + SSD_CS_Low(); + SSD_A0_High(); + SPI_SendByte(data); + SSD_CS_High(); +} + // Set start page static void setStartPage(unsigned char d) @@ -248,7 +252,6 @@ static void setStartColumn(unsigned char // Default => 0x10 } - // Therm logo const uint8_t row[4][32] = { @@ -439,4 +442,10 @@ void ssd1306_drawstringbig(const unsigne } +// SPI handle accessor +SPI_HandleTypeDef* spi_get() +{ + return &hspi1; +} + // vim:softtabstop=4 shiftwidth=4 expandtab diff --git a/src/pid.c b/src/pid.c --- a/src/pid.c +++ b/src/pid.c @@ -5,7 +5,7 @@ #include "pid.h" #include "flash.h" -// PID implementation +// Private variables static pid_state_t state; diff --git a/src/pwmout.c b/src/pwmout.c --- a/src/pwmout.c +++ b/src/pwmout.c @@ -8,11 +8,13 @@ #include "flash.h" #include "error.h" -TIM_HandleTypeDef htim17; +// Private variables +static TIM_HandleTypeDef htim17; static uint32_t last_ssr_on = 0; +// Initialize hardware PWM output void pwmout_init(void) { GPIO_InitTypeDef GPIO_InitStruct; @@ -100,6 +102,8 @@ void pwmout_process(int16_t duty) htim17.Instance->CCR1 = duty; //duty; } + +// Accessor for timer handle TIM_HandleTypeDef* pwmout_get_tim(void) { return &htim17; diff --git a/src/system/flash.c b/src/system/flash.c --- a/src/system/flash.c +++ b/src/system/flash.c @@ -6,11 +6,12 @@ #include "flash.h" #include "config.h" -// Takes up 1 page (1k size) -static __attribute__((__section__(".eeprom"))) uint16_t eeprom_emulation[512]; -therm_settings_t settings; -therm_status_t status; +// Private variables +static __attribute__((__section__(".eeprom"))) uint16_t eeprom_emulation[512]; // Takes up 1 page (1k size) +static therm_settings_t settings; +static therm_status_t status; + // Initialize flash and restore settings void flash_init(void) diff --git a/src/system/gpio.c b/src/system/gpio.c --- a/src/system/gpio.c +++ b/src/system/gpio.c @@ -3,50 +3,12 @@ // #include "stm32f3xx_hal.h" - #include "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() - -// 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)++; - } - else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) { - CHANGE_RESET; - (*to_modify)--; - } - } -} - - -// Increment/decrement signed variable with up/down buttons -void user_input_signed(int32_t* to_modify) -{ - //fixme: need to cast to 16/32 bits correctly - if(CHANGE_ELAPSED) { - if(!HAL_GPIO_ReadPin(SW_UP) ) { - CHANGE_RESET; - if (*to_modify < 32768) - (*to_modify)++; - } - else if(!HAL_GPIO_ReadPin(SW_DOWN)) { - CHANGE_RESET; - if (*to_modify >= -32768) - (*to_modify)--; - } - } -} +// Private variables +// 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; // Initialize GPIOs @@ -90,3 +52,38 @@ void gpio_init(void) HAL_GPIO_WritePin(LED, 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)++; + } + else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) { + CHANGE_RESET; + (*to_modify)--; + } + } +} + + +// Increment/decrement signed variable with up/down buttons +void user_input_signed(int32_t* to_modify) +{ + //fixme: need to cast to 16/32 bits correctly + if(CHANGE_ELAPSED) { + if(!HAL_GPIO_ReadPin(SW_UP) ) { + CHANGE_RESET; + if (*to_modify < 32768) + (*to_modify)++; + } + else if(!HAL_GPIO_ReadPin(SW_DOWN)) { + CHANGE_RESET; + if (*to_modify >= -32768) + (*to_modify)--; + } + } +} diff --git a/src/tempsense.c b/src/tempsense.c --- a/src/tempsense.c +++ b/src/tempsense.c @@ -18,8 +18,6 @@ void tempsense_init(void) // Maybe don't perform temp sensor setup in here, but in readtemp? // what happens if the user changes the tempsense type while running? // we need to re-init... - - }