ST7789

#include <eglib/display/st7789.h>

Types

st7789_color_t

Display color depth. Higher color depths require more data to be transfered, meaning slower refresh rates and more memory required when using a frame buffer.

ST7789_COLOR_12_BIT

12 bit

ST7789_COLOR_16_BIT

16 bit

ST7789_COLOR_18_BIT

18 bit (encoded as 24 bit in memory)

st7789_page_address_t

Memory data access control: page address order.

ST7789_PAGE_ADDRESS_TOP_TO_BOTTOM

Top to bottom.

ST7789_PAGE_ADDRESS_BOTTOM_TO_TOP

Bottom to top.

st7789_colum_address_t

Memory data access control: column address order.

ST7789_COLUMN_ADDRESS_LEFT_TO_RIGHT

Left to right.

ST7789_COLUMN_ADDRESS_RIGHT_TO_LEFT

Right to left.

st7789_page_colum_order_t

Memory data access control: page/column order.

ST7789_PAGE_COLUMN_ORDER_NORMAL

Normal mode

ST7789_PAGE_COLUMN_ORDER_REVERSE

Reverse mode

st7789_vertical_refresh_t

Memory data access control: line address order.

ST7789_VERTICAL_REFRESH_TOP_TO_BOTTOM

LCD refresh top to bottom.

ST7789_VERTICAL_REFRESH_BOTTOM_TO_TOP

LCD refresh bottom to top.

st7789_horizontal_refresh_t

Memory data access control: display data latch data order.

ST7789_HORIZONTAL_REFRESH_LEFT_TO_RIGHT

LCD refresh left to right.

ST7789_HORIZONTAL_REFRESH_RIGHT_TO_LEFT

LCD refresh right to left.

Configuration

st7789_config_t

Configuration for st7789.

See also

eglib_Init().

coordinate_t width

Display width.

coordinate_t height

Display height.

st7789_color_t color

Display color depth.

st7789_page_address_t page_address

Page address order.

st7789_colum_address_t colum_address

Column address order.

st7789_page_colum_order_t page_column_order

Page/column order.

st7789_vertical_refresh_t vertical_refresh

Vertical refresh direction.

st7789_horizontal_refresh_t horizontal_refresh

Horizontal refresh direction.

Driver

const display_t st7789

ST7789 display driver.

This driver supports the following data buses:

  • 4-Wire SPI.

See also

eglib_Init().

See also

Datasheet.

Functions

These functions can be used exclusively with eglib_t initialized with st7789.

void st7789_SetDisplayInversion(eglib_t * eglib, _Bool inversion)

Set display inversion on/off.

void st7789_SetIdleMode(eglib_t * eglib, _Bool idle)

Set display idle mode on/off.

When in idle on mode, colors are reduced to 8.

Example

#include <eglib.h>
#include <eglib/display/frame_buffer.h>
#include <eglib/display/st7789.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_st7789;

	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,
	};

	st7789_config_t st7789_config = {
		.width = 240,
		.height = 240,
		.color = ST7789_COLOR_16_BIT,
		.page_address = ST7789_PAGE_ADDRESS_TOP_TO_BOTTOM,
		.colum_address = ST7789_COLUMN_ADDRESS_LEFT_TO_RIGHT,
		.page_column_order = ST7789_PAGE_COLUMN_ORDER_NORMAL,
		.vertical_refresh = ST7789_VERTICAL_REFRESH_TOP_TO_BOTTOM,
		.horizontal_refresh = ST7789_HORIZONTAL_REFRESH_LEFT_TO_RIGHT,
	};

	rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_84MHZ]);

	frame_buffer_config_t frame_buffer_config;
	eglib_st7789 = eglib_Init_FrameBuffer(
		&eglib, &frame_buffer_config,
		&four_wire_spi_libopencm3_stm32f4, &four_wire_spi_libopencm3_stm32f4_config,
		&st7789, &st7789_config
	);

	for(uint16_t y=0;y<st7789_config.width;y++) {
		uint8_t v;
		v = y / (float)st7789_config.width * 255;
		eglib_SetIndexColor(&eglib, 0, v, v, v);
		eglib_DrawLine(&eglib,0, y, st7789_config.width, y);
	}

	eglib_SetIndexColor(&eglib, 0, 255, 0, 0);
	eglib_DrawLine(&eglib,0, 0, st7789_config.width-1, st7789_config.height/2);

	eglib_SetIndexColor(&eglib, 0, 0, 255, 0);
	eglib_DrawLine(&eglib,0, 0, st7789_config.width-1, st7789_config.height-1);

	eglib_SetIndexColor(&eglib, 0, 0, 0, 255);
	eglib_DrawLine(&eglib,0, 0, st7789_config.width/2, st7789_config.height-1);

	eglib_FrameBuffer_SendPartial(
		&eglib,
		st7789_config.width / 8, st7789_config.height / 8,
		3 * st7789_config.width / 4, 3 * st7789_config.height / 4
	);
	
	st7789_SetDisplayInversion(eglib_st7789, true);
}