Basic_Frame_TypeC_2023_Omni
Loading...
Searching...
No Matches
ssd1306_driver.h
1/*
2 * ssd1306_driver.h
3 *
4 * Created on: Apr 19, 2025
5 * Author: johnm
6 *
7 * This and related files contains driver code displaying simple scrollable text
8 * messages onto 128x64 OLED screens controlled by SSD1306 drivers (e.g. DFR0650).
9 */
10
11#ifndef SRC_DEVICE_OLED_SSD1306_DRIVER_H_
12#define SRC_DEVICE_OLED_SSD1306_DRIVER_H_
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include "cmsis_os.h"
19#include "i2c.h"
20#include "stdint.h"
21#include "stdlib.h"
22#include "stm32f4xx_hal.h"
23#include "string.h"
24
25#define OLED_ADDRESS 0x78
26#define OLED_WIDTH 128
27#define OLED_HEIGHT 64
28#define CHAR_WIDTH 6 // 5x7 + 1 spacing
29#define CHAR_HEIGHT 8 // 8 pixels per page
30#define MAX_ROWS (OLED_HEIGHT / CHAR_HEIGHT)
31#define MAX_COLS (OLED_WIDTH / CHAR_WIDTH)
32
33extern I2C_HandleTypeDef hi2c2;
34
35#define I2C_DEVICE hi2c2
36
37typedef struct {
38 uint8_t buffer[MAX_ROWS][OLED_WIDTH];
39} Display_t;
40
41// Message_t data type for outputting messages onto the OLED display.
42// newline characters in title field will be replaced with spaces.
43// title and body fields will "scroll" horizontally and vertically respectively
44// if they are too long for their display areas.
45typedef struct {
46 const char* title;
47 const char* body;
48} Message_t;
49
50int get_line_start_index(const char* msg, uint8_t line);
51uint8_t get_line_count(const char* msg);
52
53void ssd1306_send_command(uint8_t command);
54void ssd1306_send_data(uint8_t* data, size_t size);
55
56void ssd1306_init();
57void ssd1306_clear(void);
58void ssd1306_write_char_to_buffer(Display_t* display, char c,
59 uint8_t cursor_row, uint8_t cursor_col);
60void ssd1306_write_title(Display_t* display, Message_t message, uint8_t offset);
61void ssd1306_write_body(Display_t* display, Message_t message,
62 uint8_t line_start);
63void ssd1306_write_buffer_to_gddram(Display_t* display);
64
65#ifdef __cplusplus
66}
67#endif
68
69#endif /* SRC_DEVICE_OLED_SSD1306_DRIVER_H_ */
Definition ssd1306_driver.h:37
Definition ssd1306_driver.h:45