This is a low level driver for the SSD1306 OLED controller through 4-wire SPI.
It provides basic functions for initializing and writing to the OLED controller. In addition to hardware control and use of the OLED controller internal functions.
Before writing data to the display call ssd1306_init() which will set up the physical interface and the OLED. A file named conf_ssd1306.h is needed to define which interface to use. For more information see the Interface selection section. In addition one also need to define the pins SSD1306_DC_PIN, SSD1306_CS_PIN and SSD1306_RES_PIN and the display SSD1306_CLOCK_SPEED.
- Warning
- This driver is not reentrant and can not be used in interrupt\ service routines without extra care.
An example conf_ssd1306.h file could look like
#define SSD1306_SPI SERCOM2
#define SSD1306_CLOCK_SPEED 1000000
#define SSD1306_DC_PIN PIN_PB24
#define SSD1306_CS_PIN PIN_PB27
#define SSD1306_RES_PIN PIN_PA17
Dependencies
This driver depends on the following modules:
#define SSD1306_CMD_ACTIVATE_SCROLL 0x2F |
#define SSD1306_CMD_COL_ADD_SET_LSB |
( |
|
column | ) |
(0x00 | (column)) |
#define SSD1306_CMD_COL_ADD_SET_MSB |
( |
|
column | ) |
(0x10 | (column)) |
#define SSD1306_CMD_CONTINUOUS_SCROLL_V_AND_H_LEFT 0x2A |
#define SSD1306_CMD_CONTINUOUS_SCROLL_V_AND_H_RIGHT 0x29 |
#define SSD1306_CMD_DEACTIVATE_SCROLL 0x2E |
#define SSD1306_CMD_ENTIRE_DISPLAY_AND_GDDRAM_ON 0xA4 |
#define SSD1306_CMD_ENTIRE_DISPLAY_ON 0xA5 |
#define SSD1306_CMD_NOP 0xE3 |
#define SSD1306_CMD_SCROLL_H_LEFT 0x27 |
#define SSD1306_CMD_SCROLL_H_RIGHT 0x26 |
#define SSD1306_CMD_SET_CHARGE_PUMP_SETTING 0x8D |
#define SSD1306_CMD_SET_COLUMN_ADDRESS 0x21 |
#define SSD1306_CMD_SET_COM_OUTPUT_SCAN_DOWN 0xC8 |
#define SSD1306_CMD_SET_COM_OUTPUT_SCAN_UP 0xC0 |
#define SSD1306_CMD_SET_COM_PINS 0xDA |
#define SSD1306_CMD_SET_CONTRAST_CONTROL_FOR_BANK0 0x81 |
#define SSD1306_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO 0xD5 |
#define SSD1306_CMD_SET_DISPLAY_OFF 0xAE |
#define SSD1306_CMD_SET_DISPLAY_OFFSET 0xD3 |
#define SSD1306_CMD_SET_DISPLAY_ON 0xAF |
#define SSD1306_CMD_SET_DISPLAY_START_LINE |
( |
|
line | ) |
(0x40 | (line)) |
#define SSD1306_CMD_SET_INVERSE_DISPLAY 0xA7 |
#define SSD1306_CMD_SET_MEMORY_ADDRESSING_MODE 0x20 |
#define SSD1306_CMD_SET_MULTIPLEX_RATIO 0xA8 |
#define SSD1306_CMD_SET_NORMAL_DISPLAY 0xA6 |
#define SSD1306_CMD_SET_PAGE_ADDRESS 0x22 |
#define SSD1306_CMD_SET_PAGE_START_ADDRESS |
( |
|
page | ) |
(0xB0 | (page)) |
#define SSD1306_CMD_SET_PRE_CHARGE_PERIOD 0xD9 |
#define SSD1306_CMD_SET_SEGMENT_RE_MAP_COL0_SEG0 0xA0 |
#define SSD1306_CMD_SET_SEGMENT_RE_MAP_COL127_SEG0 0xA1 |
#define SSD1306_CMD_SET_VCOMH_DESELECT_LEVEL 0xDB |
#define SSD1306_CMD_SET_VERTICAL_SCROLL_AREA 0xA3 |
static void ssd1306_display_invert_disable |
( |
void |
| ) |
|
|
inlinestatic |
static void ssd1306_display_invert_enable |
( |
void |
| ) |
|
|
inlinestatic |
static void ssd1306_display_off |
( |
void |
| ) |
|
|
inlinestatic |
static void ssd1306_display_on |
( |
void |
| ) |
|
|
inlinestatic |
static uint8_t ssd1306_get_status |
( |
void |
| ) |
|
|
inlinestatic |
Read status from the controller.
- Note
- The controller does not support read in serial mode.
- Return values
-
8 | bit status read from the controller |
static void ssd1306_hard_reset |
( |
void |
| ) |
|
|
inlinestatic |
void ssd1306_init |
( |
void |
| ) |
|
Initialize the OLED controller.
Call this function to initialize the hardware interface and the OLED controller. When initialization is done the display is turned on and ready to receive data.
References delay_init(), port_pin_set_output_level(), SSD1306_CMD_ENTIRE_DISPLAY_AND_GDDRAM_ON, SSD1306_CMD_SET_CHARGE_PUMP_SETTING, SSD1306_CMD_SET_COM_OUTPUT_SCAN_DOWN, SSD1306_CMD_SET_COM_PINS, SSD1306_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO, SSD1306_CMD_SET_DISPLAY_OFFSET, SSD1306_CMD_SET_DISPLAY_START_LINE, SSD1306_CMD_SET_MULTIPLEX_RATIO, SSD1306_CMD_SET_PRE_CHARGE_PERIOD, SSD1306_CMD_SET_SEGMENT_RE_MAP_COL127_SEG0, SSD1306_CMD_SET_VCOMH_DESELECT_LEVEL, ssd1306_display_invert_disable(), ssd1306_display_on(), ssd1306_hard_reset(), ssd1306_interface_init(), SSD1306_RES_PIN, ssd1306_set_contrast(), and ssd1306_write_command().
Referenced by main().
static uint8_t ssd1306_read_data |
( |
void |
| ) |
|
|
inlinestatic |
Read data from the controller.
- Note
- The controller does not support read in serial mode.
- Return values
-
8 | bit data read from the controller |
static void ssd1306_set_column_address |
( |
uint8_t |
address | ) |
|
|
inlinestatic |
static uint8_t ssd1306_set_contrast |
( |
uint8_t |
contrast | ) |
|
|
inlinestatic |
static void ssd1306_set_display_start_line_address |
( |
uint8_t |
address | ) |
|
|
inlinestatic |
static void ssd1306_set_page_address |
( |
uint8_t |
address | ) |
|
|
inlinestatic |
static void ssd1306_sleep_disable |
( |
void |
| ) |
|
|
inlinestatic |
static void ssd1306_sleep_enable |
( |
void |
| ) |
|
|
inlinestatic |
void ssd1306_write_command |
( |
uint8_t |
command | ) |
|
Writes a command to the display controller.
This functions pull pin D/C# low before writing to the controller. Different data write function is called based on the selected interface.
- Parameters
-
command | the command to write |
References port_pin_set_output_level(), spi_select_slave(), spi_write_buffer_wait(), SSD1306_DC_PIN, ssd1306_master, and ssd1306_slave.
Referenced by ssd1306_display_invert_disable(), ssd1306_display_invert_enable(), ssd1306_display_off(), ssd1306_display_on(), ssd1306_init(), ssd1306_set_column_address(), ssd1306_set_contrast(), ssd1306_set_display_start_line_address(), ssd1306_set_page_address(), ssd1306_sleep_disable(), and ssd1306_sleep_enable().
void ssd1306_write_data |
( |
uint8_t |
data | ) |
|