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