SH1106¶
Contents
#include <eglib/display/sh1106.h>
Types¶
- 
sh1106_segment_remap_t¶ Segment remap.
- 
SH1106_SEGMENT_REMAP_NORMAL¶ Normal direction.
- 
SH1106_SEGMENT_REMAP_REVERSE¶ reverse direction.
- 
 
- 
sh1106_common_pads_hardware_configuration_t¶ Common pads hardware configuration.
- 
SH1106_COMMON_PADS_HARDWARE_CONFIGURATION_SEQUENTIAL¶ Sequential.
- 
SH1106_COMMON_PADS_HARDWARE_CONFIGURATION_ALTERNATIVE¶ Alternative.
- 
 
- 
sh1106_common_output_scan_direction_t¶ Common output scan direction.
- 
SH1106_COMMON_OUTPUT_SCAN_DIRECTION_ASC¶ Scan from COM0 to COM[N-1] (POR).
- 
SH1106_COMMON_OUTPUT_SCAN_DIRECTION_DESC¶ Scan from COM[N-1] to COM0.
- 
 
- 
sh1106_oscillator_frequency_t¶ Oscillator frequency .
- 
SH1106_OSCILLATOR_FREQUENCY_MINUS_25_PCT¶ -25%
- 
SH1106_OSCILLATOR_FREQUENCY_MINUS_20_PCT¶ -20%
- 
SH1106_OSCILLATOR_FREQUENCY_MINUS_15_PCT¶ -15%
- 
SH1106_OSCILLATOR_FREQUENCY_MINUS_10_PCT¶ -10%
- 
SH1106_OSCILLATOR_FREQUENCY_MINUS_5_PCT¶ -5%
- 
SH1106_OSCILLATOR_FREQUENCY__0_PCT¶ fosc (POR)
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_5_PCT¶ 5%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_10_PCT¶ 10%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_15_PCT¶ 15%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_20_PCT¶ 20%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_25_PCT¶ 25%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_30_PCT¶ 30%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_35_PCT¶ 35%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_40_PCT¶ 40%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_45_PCT¶ 45%
- 
SH1106_OSCILLATOR_FREQUENCY_PLUS_50_PCT¶ 50%
- 
 
Configuration¶
- 
sh1106_config_t¶ Configuration for
sh1106_vdd1_1_65_vandsh1106_vdd1_2_4_v.- See also
 
- 
coordinate_t 
width¶ Display width
- 
coordinate_t 
height¶ Display height
- 
sh1106_segment_remap_t 
segment_remap¶ Segment remap (mirror horizontally).
- 
sh1106_common_pads_hardware_configuration_t 
common_pads_hardware_configuration¶ Common pads hardware configuration.
How rows (COM) and columns (SEG) are physically connected to the display.
- 
sh1106_common_output_scan_direction_t 
common_output_scan_direction¶ Common output scan direction (mirror vertically).
- 
uint8_t 
display_offset¶ Vertical offset.
Some displays do not start at row 0: this allows setting this offset.
- 
uint8_t 
column_offset¶ Horizontal offset.
Some displays do not start at column 0: this allows setting this offset.
- 
uint8_t 
pre_charge_period¶ Pre-change period: 1-15 DCLKs (POR = 2 DCLKs)
- 
uint8_t 
dis_charge_period¶ Dis-change period: 1-15 DCLKs (POR = 2 DCLKs)
- 
uint8_t 
vcom_deselect_level¶ VCOM Deselect level. POR=0x35 (Beta=0.770).
- 
uint8_t 
clock_divide¶ Display clock divide ratio. POR=0 (divide ratio = 1).
- 
sh1106_oscillator_frequency_t 
oscillator_frequency¶ Display oscillator frequency .
- 
_Bool 
dc_dc_enable¶ DC-DC control mode on/off.
- 
sh1106_shh1106_dc_dc_t 
dc_dc_voltage¶ Pump voltage.
- 
_Bool 
sa0¶ Least significant bit of 7-bit slave address: 011110(sa0).
Pre-baked configurations¶
- 
sh1106_config_t 
sh1106_config_sparkfun_micro_oled¶ Configuration for SparkFun Micro OLED Breakout.
Values extracted from example code.
Driver¶
- 
const display_t 
sh1106_vdd1_1_65_v¶ SH1106 display driver.
This driver supports the following data buses:
4-Wire SPI.
I2C.
This display driver does not support writing pixels directly to the display RAM and must be used in conjunction with
eglib_Init_FrameBuffer().This variant is to be used when VDD1 = 1.65 - 3.5V, TA= +25°C.
- See also
 - See also
 - See also
 
- 
const display_t 
sh1106_vdd1_2_4_v¶ SH1106 display driver.
This driver supports the following data buses:
4-Wire SPI.
I2C.
This display driver does not support writing pixels directly to the display RAM and must be used in conjunction with
eglib_Init_FrameBuffer().This variant is to be used when VDD1 = 2.4 - 3.5V, TA= +25°C
- See also
 - See also
 - See also
 
Functions¶
These functions can be used exclusively with eglib_t initialized
with sh1106_vdd1_1_65_v or sh1106_vdd1_2_4_v.
Examples¶
4-Wire SPI¶
#include <eglib.h>
#include <eglib/hal/four_wire_spi/libopencm3_stm32f4.h>
#include <eglib/display/frame_buffer.h>
#include <eglib/display/sh1106.h>
#include <stdio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/spi.h>
int main(void) {
	eglib_t eglib;
	eglib_t *eglib_sh1106;
	sh1106_config_t sh1106_config = {
		// Display physical construction
		.width = 128,
		.height = 64,
		.segment_remap = SH1106_SEGMENT_REMAP_REVERSE,
		.common_pads_hardware_configuration = SH1106_COMMON_PADS_HARDWARE_CONFIGURATION_ALTERNATIVE,
		.common_output_scan_direction = SH1106_COMMON_OUTPUT_SCAN_DIRECTION_DESC,
		.display_offset = 0,
		.column_offset = 2,
		// Change period
		.pre_charge_period = 2,
		.dis_charge_period = 2,
		// VCOM deselect
		.vcom_deselect_level = 0x35,
		// Internal display clocks
		.clock_divide = 0,
		.oscillator_frequency = SH1106_OSCILLATOR_FREQUENCY_PLUS_50_PCT,
		// Charge Pump Regulator
		.dc_dc_enable = true,
		.dc_dc_voltage = SHH1106_DC_DC_8_0_V,
	};
	frame_buffer_config_t frame_buffer_config;
	four_wire_spi_libopencm3_stm32f4_config_t  four_wire_spi_libopencm3_stm32f4_config = {
		// rst
		.rcc_rst = RCC_GPIOA,
		.port_rst = GPIOA,
		.gpio_rst = GPIO4,
		// dc
		.rcc_dc = RCC_GPIOA,
		.port_dc = GPIOA,
		.gpio_dc = GPIO3,
		// cs
		.rcc_cs = RCC_GPIOA,
		.port_cs = GPIOA,
		.gpio_cs = GPIO2,
		// spi
		.rcc_spi = RCC_SPI1,
		.spi = SPI1,
		// sck
		.rcc_sck = RCC_GPIOA,
		.port_sck = GPIOA,
		.gpio_sck = GPIO5,
		// mosi
		.rcc_mosi = RCC_GPIOA,
		.port_mosi = GPIOA,
		.gpio_mosi = GPIO7,
	};
	rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_84MHZ]);
	eglib_sh1106 = eglib_Init_FrameBuffer(
		&eglib, &frame_buffer_config,
		&four_wire_spi_libopencm3_stm32f4, &four_wire_spi_libopencm3_stm32f4_config,
		&sh1106_vdd1_2_4_v, &sh1106_config
	);
	eglib_SetIndexColor(&eglib, 0, 0xFF, 0xFF, 0xFF);
	eglib_DrawLine(&eglib,0, 0, sh1106_config.width-1, sh1106_config.height-1);
	eglib_DrawLine(&eglib,0, sh1106_config.height-1, sh1106_config.width-1, 0);
	eglib_FrameBuffer_Send(&eglib);
	sh1106_Reverse(eglib_sh1106, true);
}
I2C¶
#include <eglib.h>
#include <eglib/hal/i2c/libopencm3_stm32f4.h>
#include <eglib/display/frame_buffer.h>
#include <eglib/display/sh1106.h>
#include <stdio.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/i2c.h>
int main(void) {
	eglib_t eglib;
	eglib_t *eglib_sh1106;
	frame_buffer_config_t frame_buffer_config;
	rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_84MHZ]);
	i2c_libopencm3_stm32f4_config_t  i2c_libopencm3_stm32f4_config = {
		.rcc_rst = RCC_GPIOA,
		.port_rst = GPIOA,
		.gpio_rst = GPIO4,
		.rcc_gpio_i2c = RCC_GPIOB,
		.port_i2c = GPIOB,
		.gpio_scl = GPIO8,
		.gpio_sda = GPIO9,
		.rcc_i2c = RCC_I2C1,
		.i2c = I2C1,
		.i2c_peripheral_clock_mhz = rcc_apb1_frequency / 1e6,
	};
	sh1106_config_t sh1106_config = {
		// Display physical construction
		.width = 128,
		.height = 64,
		.segment_remap = SH1106_SEGMENT_REMAP_REVERSE,
		.common_pads_hardware_configuration = SH1106_COMMON_PADS_HARDWARE_CONFIGURATION_ALTERNATIVE,
		.common_output_scan_direction = SH1106_COMMON_OUTPUT_SCAN_DIRECTION_DESC,
		.display_offset = 0,
		.column_offset = 2,
		// Change period
		.pre_charge_period = 2,
		.dis_charge_period = 2,
		// VCOM deselect
		.vcom_deselect_level = 0x35,
		// Internal display clocks
		.clock_divide = 0,
		.oscillator_frequency = SH1106_OSCILLATOR_FREQUENCY_PLUS_50_PCT,
		// Charge Pump Regulator
		.dc_dc_enable = true,
		.dc_dc_voltage = SHH1106_DC_DC_8_0_V,
		// I2C
		.sa0 = 0,
	};
	eglib_sh1106 = eglib_Init_FrameBuffer(
		&eglib, &frame_buffer_config,
		&i2c_libopencm3_stm32f4, &i2c_libopencm3_stm32f4_config,
		&sh1106_vdd1_2_4_v, &sh1106_config
	);
	eglib_SetIndexColor(&eglib, 0, 0xFF, 0xFF, 0xFF);
	eglib_DrawLine(&eglib,0, 0, sh1106_config.width-1, sh1106_config.height-1);
	eglib_DrawLine(&eglib,0, sh1106_config.height-1, sh1106_config.width-1, 0);
	eglib_FrameBuffer_Send(&eglib);
	sh1106_Reverse(eglib_sh1106, true);
}