SSD1331¶
#include <eglib/display/ssd1331.h>
-
SSD1331_WIDTH
¶ Display width
-
SSD1331_HEIGHT
¶ Display height
Types¶
-
enum
ssd1331_column_address_mapping
¶ Column address mapping.
-
SSD1331_RAM_COLUMN_0_TO_95_MAPS_TO_PIN_SEG_0_TO_95
¶ RAM Column 0 to 95 maps to Pin Seg (SA,SB,SC) 0 to 95.
-
SSD1331_RAM_COLUMN_0_TO_95_MAPS_TO_PIN_SEG_95_TO_0
¶ RAM Column 0 to 95 maps to Pin Seg (SA,SB,SC) 95 to 0.
-
-
enum
ssd1331_com_scan
¶ COM scan (where N is the multiplex ratio).
-
SSD1331_SCAN_FROM_COM0_TO_COM_N_1
¶ Scan from COM0 to COM[N-1].
-
SSD1331_SCAN_FROM_COM_N_1_TO_COM0
¶ Scan from COM[N-1] to COM0.
-
-
enum
ssd1331_color_format
¶ Color format.
-
SSD1331_256_COLORS
¶ 256 color.
-
SSD1331_65k_COLORS
¶ 65k color.
-
-
enum
ssd1331_display_mode
¶ Display mode.
-
SSD1331_DISPLAY_MODE_NORMAL
¶ Normal display
-
SSD1331_DISPLAY_MODE_ENTIRE_DISPLAY_ON
¶ Entire display ON, all pixels turn ON at GS63.
-
SSD1331_DISPLAY_MODE_ENTIRE_DISPLAY_OFF
¶ Entire display OFF, all pixels turn OFF.
-
SSD1331_DISPLAY_MODE_INVERSE
¶ Inverse display.
-
Configuration¶
-
ssd1331_config_t
¶ Configuration for
ssd1331
.- See also
-
uint8_t
color_a_contrast
¶ Contrast for color “A” segment (Pins: SA0-SA95). RESET=128.
-
uint8_t
color_b_contrast
¶ Contrast for color “B” segment (Pins: SA0-SA95). RESET=128.
-
uint8_t
color_c_contrast
¶ Contrast for color “C” segment (Pins: SA0-SA95). RESET=128.
-
uint8_t
second_pre_charge_speed_for_color_a
¶ Second pre-charge speed for color A. Default value equals to
color_a_contrast
.
-
uint8_t
second_pre_charge_speed_for_color_b
¶ Second pre-charge speed for color B. Default value equals to
color_b_contrast
.
-
uint8_t
second_pre_charge_speed_for_color_c
¶ Second pre-charge speed for color C. Default value equals to
color_c_contrast
.
-
enum ssd1331_column_address_mapping
column_address_mapping
¶ Column address mapping (mirror horizontally).
-
_Bool
left_right_swapping_on_com
¶ Left-right swapping on COM.
-
enum ssd1331_com_scan
com_scan
¶ COM scan (mirror vertically).
-
_Bool
com_split_odd_even
¶ COM split odd even.
-
enum ssd1331_color_format
color_format
¶ Color format. If 9/18bit mode is selected, color depth will be fixed to 65k.
-
uint8_t
display_offset
¶ Mapping of display start line to one of COM0-63.
-
uint8_t
phase1_period
¶ Phase 1 period in N DCLK (1-15). RESET=7.
-
uint8_t
phase2_period
¶ Phase 2 period in N DCLK (1-15). RESET=4.
-
uint8_t
clock_divider
¶ Divide ratio (D) of the display clocks (DCLK (1-16)). RESET=0.
-
uint8_t
oscillator_frequency
¶ Fosc frequency. RESET=13.
-
uint8_t *
grayscale_table
¶ When set to NULL, use linear gray scale table.
When set to not NULL, uses this gray scale table from GS1 to GS63.
-
uint8_t
pre_charge_level
¶ Set pre-charge voltage level from 0.10*Vcc (0) to 0x50*Vcc (31). RESET=31.
-
uint8_t
v_comh
¶ COM deselect voltage level (V COMH) from 0.44*Vcc (0) to 0.83*Vcc (31). RESET=3.
Pre-baked configurations¶
-
ssd1331_config_t
ssd1331_config_adafruit_65k_colors
¶ Configuration for Adafruit OLED Breakout Board - 16-bit Color 0.96” w/microSD holder.
Values extracted from Adafruit’s example code.
- Note
this configuration should work just fine with “generic” SSD1331 boards that can be easily found on eBay or Aliexpress.
-
ssd1331_config_t
ssd1331_config_adafruit_256_colors
¶ Variant of
ssd1331_config_adafruit_65k_colors
with only 256 colors instead of 65k.
-
ssd1331_config_t
ssd1331_config_buydisplay_65k_colors
¶ Configuration for Buy Display module.
Values extracted from Buy Display’s example code.
-
ssd1331_config_t
ssd1331_config_buydisplay_256_colors
¶ Variant of
ssd1331_config_buydisplay_65k_colors
with only 256 colors instead of 65k.
Driver¶
Functions¶
These functions can be used exclusively with eglib_t
initialized
with ssd1331
or ssd1331_overclock.
-
void
ssd1331_SetMasterCurrent
(eglib_t * eglib, uint8_t value)¶ Set master current attenuation factor from 0 (1/16) to 15 (16/16).
This effectively controls the how dim / bright the display is.
-
void
ssd1331_SetDisplayStartLine
(eglib_t * eglib, uint8_t line)¶ Set the display start line from 0 to 63.
This controls vertical scrolling.
-
void
ssd1331_SetDisplayMode
(eglib_t * eglib, enum ssd1331_display_mode mode)¶ Set display mode
-
void
ssd1331_SetDimMode
(eglib_t * eglib, uint8_t color_a_contrast, uint8_t color_b_contrast, uint8_t color_c_contrast, uint8_t pre_charge_voltage)¶ Set Dim mode.
- Parameters
color_a_contrast – Contrast setting for color A.
color_b_contrast – Contrast setting for color B.
color_c_contrast – Contrast setting for color C.
pre_charge_voltge – Precharge voltage setting (0-31). Setting this to~15 should keep contrast tame with for low contrast values.
-
void
ssd1331_DrawLine
(eglib_t * eglib, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)¶ Similar to
eglib_DrawLine()
, draw a line using color from index 0. It draws directly to display memory using a graphic accelerated command. Coordinates must be inside the display area.
-
void
ssd1331_DrawFrame
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height)¶ Similar to
eglib_DrawFrame()
, draw a frame using color from index 0. It draws directly to display memory using a graphic accelerated command. Coordinates must be inside the display area.
-
void
ssd1331_DrawBox
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height)¶ Similar to
eglib_DrawBox()
, draw a box using color from index 0. It draws directly to display memory using a graphic accelerated command. Coordinates must be inside the display area.
Examples¶
4-Wire SPI¶
#include <eglib.h>
#include <eglib/display/frame_buffer.h>
#include <eglib/display/ssd1331.h>
#include <eglib/hal/four_wire_spi/libopencm3_stm32f4.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/spi.h>
#include <stdio.h>
int main(void) {
eglib_t eglib;
eglib_t *eglib_ssd1331;
four_wire_spi_libopencm3_stm32f4_config_t four_wire_spi_libopencm3_stm32f4_config = {
// rst
.rcc_rst = RCC_GPIOA,
.port_rst = GPIOA,
.gpio_rst = GPIO4,
// cd
.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_Init(
&eglib,
&four_wire_spi_libopencm3_stm32f4, &four_wire_spi_libopencm3_stm32f4_config,
&ssd1331, &ssd1331_config_buydisplay_65k_colors
);
for(uint16_t y=0;y<SSD1331_HEIGHT;y++) {
uint8_t v;
v = y / ((float)SSD1331_HEIGHT-1) * 255;
eglib_SetIndexColor(&eglib, 0, v, v, v);
eglib_DrawLine(&eglib,0, y, SSD1331_WIDTH, y);
}
eglib_SetIndexColor(&eglib, 0, 255, 255, 255);
eglib_DrawVLine(&eglib, SSD1331_WIDTH/2, 0, SSD1331_HEIGHT);
eglib_SetIndexColor(&eglib, 0, 255, 0, 0);
eglib_DrawLine(&eglib, 0, 0, SSD1331_WIDTH-1, SSD1331_HEIGHT/2);
eglib_SetIndexColor(&eglib, 0, 0, 255, 0);
eglib_DrawLine(&eglib,0, 0, SSD1331_WIDTH-1, SSD1331_HEIGHT-1);
eglib_SetIndexColor(&eglib, 0, 0, 0, 255);
eglib_DrawLine(&eglib,0, 0, SSD1331_WIDTH/2, SSD1331_HEIGHT-1);
// Accelerated versions
eglib_SetIndexColor(&eglib, 0, 0, 255, 255);
ssd1331_DrawLine(&eglib, 0, 63, 95, 0);
eglib_SetIndexColor(&eglib, 0, 255, 255, 0);
ssd1331_DrawFrame(&eglib, 10, 20, 10, 20);
eglib_SetIndexColor(&eglib, 0, 255, 0, 255);
ssd1331_DrawFrame(&eglib, 0, 16, 95, 32);
eglib_SetIndexColor(&eglib, 0, 255, 255, 255);
ssd1331_DrawBox(&eglib, 40, 20, 40, 20);
eglib_SetIndexColor(&eglib, 0, 0, 0, 0);
ssd1331_DrawFrame(&eglib, 22, 20, 10, 20);
}