Prusa MINI Firmware overview
st7789v.c File Reference
#include "st7789v.h"
#include <guiconfig.h>
#include <string.h>
#include <stdlib.h>
#include "stm32f4xx_hal.h"
#include "gpio.h"

Macros

#define ST7789V_COLS   240
 
#define ST7789V_ROWS   320
 
#define CMD_SLPIN   0x10
 
#define CMD_SLPOUT   0x11
 
#define CMD_INVOFF   0x20
 
#define CMD_INVON   0x21
 
#define CMD_GAMMA_SET   0x26
 
#define CMD_DISPOFF   0x28
 
#define CMD_DISPON   0x29
 
#define CMD_CASET   0x2A
 
#define CMD_RASET   0x2B
 
#define CMD_RAMWR   0x2C
 
#define CMD_RAMRD   0x2E
 
#define CMD_MADCTL   0x36
 
#define CMD_COLMOD   0x3A
 
#define CMD_RAMWRC   0x3C
 
#define CMD_WRDISBV   0x51
 
#define CMD_RDDISBV   0x52
 
#define CMD_WRCTRLD   0x53
 
#define CMD_RDCTRLD   0x54
 
#define GAMMA_CURVE0   0x01
 
#define GAMMA_CURVE1   0x02
 
#define GAMMA_CURVE2   0x04
 
#define GAMMA_CURVE3   0x08
 
#define MASK_CTRLD_BCTRL   (0x01 << 5)
 
#define MASK_CTRLD_DD   (0x01 << 3)
 
#define MASK_CTRLD_BL   (0x01 << 2)
 
#define CLR565_WHITE   0xffff
 
#define CLR565_BLACK   0x0000
 
#define CLR565_RED   0xf800
 
#define CLR565_CYAN   0x0000
 
#define CLR565_MAGENTA   0x0000
 
#define CLR565_GREEN   0x07e0
 
#define CLR565_YELLOW   0xffe0
 
#define CLR565_ORANGE   0x0000
 
#define CLR565_GRAY   0x38e7
 
#define CLR565_BLUE   0x001f
 
#define _COLOR_565(clr)   color_to_565(clr)
 
#define _565_COLOR(clr)   color_from_565(clr)
 
#define FLG_CS   0x01
 
#define FLG_RS   0x02
 
#define FLG_RST   0x04
 
#define SWAPBW_TOLERANCE   64
 

Functions

void st7789v_init (void)
 
void st7789v_done (void)
 
void st7789v_clear (color_t clr)
 
void st7789v_set_pixel (point_ui16_t pt, color_t clr)
 
void st7789v_clip_rect (rect_ui16_t rc)
 
void st7789v_draw_line (point_ui16_t pt, point_ui16_t pt1, color_t clr)
 
void st7789v_draw_rect (rect_ui16_t rc, color_t clr)
 
void st7789v_fill_rect (rect_ui16_t rc, color_t clr)
 
void st7789v_draw_char (point_ui16_t pt, char chr, font_t *pf, color_t clr0, color_t clr1)
 
void st7789v_draw_text (rect_ui16_t rc, const char *str, font_t *pf, color_t clr0, color_t clr1)
 
void st7789v_draw_png (point_ui16_t pt, FILE *pf)
 
void st7789v_gamma_set_direct (uint8_t gamma_enu)
 
uint8_t st7789v_read_ctrl (void)
 
void st7789v_ctrl_set (uint8_t ctrl)
 
static void st7789v_set_cs (void)
 
static void st7789v_clr_cs (void)
 
static void st7789v_set_rs (void)
 
static void st7789v_clr_rs (void)
 
static void st7789v_set_rst (void)
 
static void st7789v_clr_rst (void)
 
static void st7789v_fill_ui16 (uint16_t *p, uint16_t v, uint16_t c)
 
static int is_interrupt (void)
 
void st7789v_delay_ms (uint32_t ms)
 
void st7789v_spi_wr_byte (uint8_t b)
 
void st7789v_spi_wr_bytes (uint8_t *pb, uint16_t size)
 
void st7789v_spi_rd_bytes (uint8_t *pb, uint16_t size)
 
void st7789v_cmd (uint8_t cmd, uint8_t *pdata, uint16_t size)
 
void st7789v_wr (uint8_t *pdata, uint16_t size)
 
void st7789v_rd (uint8_t *pdata, uint16_t size)
 
void st7789v_cmd_slpout (void)
 
void st7789v_cmd_madctl (uint8_t madctl)
 
void st7789v_cmd_colmod (uint8_t colmod)
 
void st7789v_cmd_dispon (void)
 
void st7789v_cmd_caset (uint16_t x, uint16_t cx)
 
void st7789v_cmd_raset (uint16_t y, uint16_t cy)
 
void st7789v_cmd_ramwr (uint8_t *pdata, uint16_t size)
 
void st7789v_cmd_ramrd (uint8_t *pdata, uint16_t size)
 
void st7789v_init_ctl_pins (void)
 
void st7789v_reset (void)
 
color_t st7789v_get_pixel (point_ui16_t pt)
 
void st7789v_set_pixel_directColor (point_ui16_t pt, uint16_t directColor)
 
static uint16_t set_num_of_ones (uint8_t num_of_ones)
 
static uint16_t rd18bit_to_16bit (uint8_t *buff)
 
uint16_t st7789v_get_pixel_directColor (point_ui16_t pt)
 
static void rop_rgb888_invert (uint8_t *ppx888)
 
static void rop_rgb888_swapbw (uint8_t *ppx888)
 
static void rop_rgb888_disabled (uint8_t *ppx888)
 
static void rop_rgb8888_swapbw (uint8_t *ppx)
 
void st7789v_draw_png_ex (point_ui16_t pt, FILE *pf, color_t clr0, uint8_t rop)
 
void st7789v_draw_icon (point_ui16_t pt, uint16_t id_res, color_t clr0, uint8_t rop)
 
void st7789v_enable_safe_mode (void)
 enable safe mode (direct acces + safe delay) More...
 
void st7789v_spi_tx_complete (void)
 

Variables

uint8_t st7789v_flg = 0
 
uint16_t st7789v_x = 0
 
uint16_t st7789v_y = 0
 
uint16_t st7789v_cx = 0
 
uint16_t st7789v_cy = 0
 
uint8_t st7789v_buff [ST7789V_COLS *2 *16]
 
rect_ui16_t st7789v_clip = { 0, 0, ST7789V_COLS, ST7789V_ROWS }
 
const display_t st7789v_display
 
st7789v_config_t st7789v_config
 
uint16_t st7789v_reset_delay = 0
 

Macro Definition Documentation

◆ ST7789V_COLS

#define ST7789V_COLS   240

◆ ST7789V_ROWS

#define ST7789V_ROWS   320

◆ CMD_SLPIN

#define CMD_SLPIN   0x10

◆ CMD_SLPOUT

#define CMD_SLPOUT   0x11

◆ CMD_INVOFF

#define CMD_INVOFF   0x20

◆ CMD_INVON

#define CMD_INVON   0x21

◆ CMD_GAMMA_SET

#define CMD_GAMMA_SET   0x26

◆ CMD_DISPOFF

#define CMD_DISPOFF   0x28

◆ CMD_DISPON

#define CMD_DISPON   0x29

◆ CMD_CASET

#define CMD_CASET   0x2A

◆ CMD_RASET

#define CMD_RASET   0x2B

◆ CMD_RAMWR

#define CMD_RAMWR   0x2C

◆ CMD_RAMRD

#define CMD_RAMRD   0x2E

◆ CMD_MADCTL

#define CMD_MADCTL   0x36

◆ CMD_COLMOD

#define CMD_COLMOD   0x3A

◆ CMD_RAMWRC

#define CMD_RAMWRC   0x3C

◆ CMD_WRDISBV

#define CMD_WRDISBV   0x51

◆ CMD_RDDISBV

#define CMD_RDDISBV   0x52

◆ CMD_WRCTRLD

#define CMD_WRCTRLD   0x53

◆ CMD_RDCTRLD

#define CMD_RDCTRLD   0x54

◆ GAMMA_CURVE0

#define GAMMA_CURVE0   0x01

◆ GAMMA_CURVE1

#define GAMMA_CURVE1   0x02

◆ GAMMA_CURVE2

#define GAMMA_CURVE2   0x04

◆ GAMMA_CURVE3

#define GAMMA_CURVE3   0x08

◆ MASK_CTRLD_BCTRL

#define MASK_CTRLD_BCTRL   (0x01 << 5)

◆ MASK_CTRLD_DD

#define MASK_CTRLD_DD   (0x01 << 3)

◆ MASK_CTRLD_BL

#define MASK_CTRLD_BL   (0x01 << 2)

◆ CLR565_WHITE

#define CLR565_WHITE   0xffff

◆ CLR565_BLACK

#define CLR565_BLACK   0x0000

◆ CLR565_RED

#define CLR565_RED   0xf800

◆ CLR565_CYAN

#define CLR565_CYAN   0x0000

◆ CLR565_MAGENTA

#define CLR565_MAGENTA   0x0000

◆ CLR565_GREEN

#define CLR565_GREEN   0x07e0

◆ CLR565_YELLOW

#define CLR565_YELLOW   0xffe0

◆ CLR565_ORANGE

#define CLR565_ORANGE   0x0000

◆ CLR565_GRAY

#define CLR565_GRAY   0x38e7

◆ CLR565_BLUE

#define CLR565_BLUE   0x001f

◆ _COLOR_565

#define _COLOR_565 (   clr)    color_to_565(clr)

◆ _565_COLOR

#define _565_COLOR (   clr)    color_from_565(clr)

◆ FLG_CS

#define FLG_CS   0x01

◆ FLG_RS

#define FLG_RS   0x02

◆ FLG_RST

#define FLG_RST   0x04

◆ SWAPBW_TOLERANCE

#define SWAPBW_TOLERANCE   64

Function Documentation

◆ st7789v_init()

void st7789v_init ( void  )
327  {
328 #ifdef ST7789V_USE_RTOS
329  st7789v_task_handle = osThreadGetId();
330 #endif //ST7789V_USE_RTOS
333  else
335  st7789v_init_ctl_pins(); // CS=H, RS=H, RST=H
336  st7789v_reset(); // 15ms reset pulse
337  st7789v_delay_ms(120); // 120ms wait
338  st7789v_cmd_slpout(); // wakeup
339  st7789v_delay_ms(120); // 120ms wait
340  st7789v_cmd_madctl(st7789v_config.madctl); // interface pixel format
341  st7789v_cmd_colmod(st7789v_config.colmod); // memory data access control
342  st7789v_cmd_dispon(); // display on
343  st7789v_delay_ms(10); // 10ms wait
344 }
Here is the call graph for this function:

◆ st7789v_done()

void st7789v_done ( void  )
346  {
347 }

◆ st7789v_clear()

void st7789v_clear ( color_t  clr)
349  {
350  int i;
351  uint16_t clr565 = _COLOR_565(clr);
352  for (i = 0; i < ST7789V_COLS * 16; i++)
353  ((uint16_t *)st7789v_buff)[i] = clr565;
354  st7789v_clr_cs();
357  st7789v_cmd_ramwr(0, 0);
358  for (i = 0; i < ST7789V_ROWS / 16; i++)
360  st7789v_set_cs();
361  // st7789v_test_miso();
362 }
Here is the call graph for this function:

◆ st7789v_set_pixel()

void st7789v_set_pixel ( point_ui16_t  pt,
color_t  clr 
)
364  {
366  return;
367  uint16_t clr565 = _COLOR_565(clr);
368  st7789v_cmd_caset(pt.x, 1);
369  st7789v_cmd_raset(pt.y, 1);
370  st7789v_cmd_ramwr((uint8_t *)(&clr565), 2);
371 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_clip_rect()

void st7789v_clip_rect ( rect_ui16_t  rc)
434  {
435  st7789v_clip = rc;
436 }

◆ st7789v_draw_line()

void st7789v_draw_line ( point_ui16_t  pt,
point_ui16_t  pt1,
color_t  clr 
)
438  {
439  int n;
440  int dx = pt1.x - pt.x;
441  int dy = pt1.y - pt.y;
442  int sx = (dx >= 0) ? 1 : -1;
443  int sy = (dy >= 0) ? 1 : -1;
444  int cx = (sx > 0) ? dx : -dx;
445  int cy = (sy > 0) ? dy : -dy;
446  dx = cx;
447  dy = cy;
448  if ((dx == 0) || (dy == 0)) { // orthogonal line
449  if (dx) // dy == 0
450  st7789v_fill_rect(rect_ui16((sx > 0) ? pt.x : pt1.x, pt.y, dx, 1), clr);
451  else // dx == 0
452  st7789v_fill_rect(rect_ui16(pt.x, (sy > 0) ? pt.y : pt1.y, 1, dy), clr);
453  } else if (dx > dy)
454  for (n = dx; n > 0; n--) {
455  st7789v_set_pixel(pt, clr);
456  if ((cx -= cy) <= 0) {
457  pt.y += sy;
458  cx += dx;
459  }
460  pt.x += sx;
461  }
462  else if (dx < dy)
463  for (n = dy; n > 0; n--) {
464  st7789v_set_pixel(pt, clr);
465  if ((cy -= cx) <= 0) {
466  pt.x += sx;
467  cy += dy;
468  }
469  pt.y += sy;
470  }
471  else //dx == dy
472  for (n = dx; n > 0; n--) {
473  st7789v_set_pixel(pt, clr);
474  pt.x += sx;
475  pt.y += sy;
476  }
477 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_draw_rect()

void st7789v_draw_rect ( rect_ui16_t  rc,
color_t  clr 
)
479  {
480  point_ui16_t pt = { rc.x, rc.y };
481  point_ui16_t pt1 = { rc.x + rc.w - 1, rc.y };
482  point_ui16_t pt2 = { rc.x + rc.w - 1, rc.y + rc.h - 1 };
483  point_ui16_t pt3 = { rc.x, rc.y + rc.h - 1 };
484  st7789v_draw_line(pt, pt1, clr);
485  st7789v_draw_line(pt1, pt2, clr);
486  st7789v_draw_line(pt2, pt3, clr);
487  st7789v_draw_line(pt3, pt, clr);
488 }
Here is the call graph for this function:

◆ st7789v_fill_rect()

void st7789v_fill_rect ( rect_ui16_t  rc,
color_t  clr 
)
490  {
492  if (rect_empty_ui16(rc))
493  return;
494  int i;
495  uint16_t clr565 = _COLOR_565(clr);
496  uint32_t size = (uint32_t)rc.w * rc.h * 2;
497  int n = size / sizeof(st7789v_buff);
498  int s = size % sizeof(st7789v_buff);
499  if (n)
500  st7789v_fill_ui16((uint16_t *)st7789v_buff, clr565, sizeof(st7789v_buff) / 2);
501  else
502  st7789v_fill_ui16((uint16_t *)st7789v_buff, clr565, size / 2);
503  st7789v_clr_cs();
504  st7789v_cmd_caset(rc.x, rc.x + rc.w - 1);
505  st7789v_cmd_raset(rc.y, rc.y + rc.h - 1);
506  st7789v_cmd_ramwr(0, 0);
507  for (i = 0; i < n; i++)
509  if (s)
511  st7789v_set_cs();
512 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_draw_char()

void st7789v_draw_char ( point_ui16_t  pt,
char  chr,
font_t pf,
color_t  clr0,
color_t  clr1 
)
514  {
515  int i;
516  int j;
517  uint8_t *pch; //character data pointer
518  uint8_t crd = 0; //current row byte data
519  uint8_t rb; //row byte
520  uint16_t w = pf->w; //cache width
521  uint16_t h = pf->h; //..
522  uint8_t bpr = pf->bpr; //bytes per row
523  uint16_t bpc = bpr * h; //bytes per char
524  uint8_t bpp = 8 * bpr / w; //bits per pixel
525  uint8_t ppb = 8 / bpp; //pixels per byte
526  uint8_t pms = (1 << bpp) - 1; //pixel mask
527  uint16_t *p = (uint16_t *)st7789v_buff;
528  uint8_t *pc;
529  if ((chr >= pf->asc_min) && (chr <= pf->asc_max)) {
530  pch = (pf->pcs) + ((chr - pf->asc_min) * bpc);
531  uint16_t clr565[16];
532  for (i = 0; i <= pms; i++)
533  clr565[i] = _COLOR_565(color_alpha(clr0, clr1, 255 * i / pms));
534  for (j = 0; j < h; j++) {
535  pc = pch + j * bpr;
536  for (i = 0; i < w; i++) {
537  if ((i % ppb) == 0) {
538  if (pf->flg & FONT_FLG_SWAP) {
539  rb = (i / ppb) ^ 1;
540  crd = pch[rb + j * bpr];
541  } else
542  crd = *(pc++);
543  }
544  if (pf->flg & FONT_FLG_LSBF) {
545  *(p++) = clr565[crd & pms];
546  crd >>= bpp;
547  } else {
548  *(p++) = clr565[crd >> (8 - bpp)];
549  crd <<= bpp;
550  }
551  }
552  }
553  st7789v_clr_cs();
554  st7789v_cmd_caset(pt.x, pt.x + w - 1);
555  st7789v_cmd_raset(pt.y, pt.y + h - 1);
556  st7789v_cmd_ramwr(st7789v_buff, 2 * w * h);
557  st7789v_set_cs();
558  } else
559  display->fill_rect(rect_ui16(pt.x, pt.y, w, h), clr0);
560 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_draw_text()

void st7789v_draw_text ( rect_ui16_t  rc,
const char *  str,
font_t pf,
color_t  clr0,
color_t  clr1 
)
562  {
563  int i;
564  int len = strlen(str);
565  int x = rc.x;
566  int y = rc.y;
567  for (i = 0; i < len; i++) {
568  char c = str[i];
569  if (c == '\n') {
570  y += pf->h;
571  x = rc.x;
572  if ((y + pf->h) > (rc.y + rc.h))
573  break;
574  } else {
575  st7789v_draw_char(point_ui16(x, y), c, pf, clr0, clr1);
576  x += pf->w;
577  if ((x + pf->w) > (rc.x + rc.w))
578  break;
579  }
580  }
581 }
Here is the call graph for this function:

◆ st7789v_draw_png()

void st7789v_draw_png ( point_ui16_t  pt,
FILE *  pf 
)
883 {}

◆ st7789v_gamma_set_direct()

void st7789v_gamma_set_direct ( uint8_t  gamma_enu)

◆ st7789v_read_ctrl()

uint8_t st7789v_read_ctrl ( void  )

◆ st7789v_ctrl_set()

void st7789v_ctrl_set ( uint8_t  ctrl)

◆ st7789v_set_cs()

static void st7789v_set_cs ( void  )
static
107  {
109  st7789v_flg |= FLG_CS;
110 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_clr_cs()

static void st7789v_clr_cs ( void  )
static
112  {
114  st7789v_flg &= ~FLG_CS;
115 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_set_rs()

static void st7789v_set_rs ( void  )
static
117  {
119  st7789v_flg |= FLG_RS;
120 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_clr_rs()

static void st7789v_clr_rs ( void  )
static
122  {
124  st7789v_flg &= ~FLG_RS;
125 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_set_rst()

static void st7789v_set_rst ( void  )
static
127  {
129  st7789v_flg |= FLG_RST;
130 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_clr_rst()

static void st7789v_clr_rst ( void  )
static
132  {
134  st7789v_flg &= ~FLG_RST;
135 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_fill_ui16()

static void st7789v_fill_ui16 ( uint16_t *  p,
uint16_t  v,
uint16_t  c 
)
static
137  {
138  while (c--)
139  *(p++) = v;
140 }
Here is the caller graph for this function:

◆ is_interrupt()

static int is_interrupt ( void  )
static
142  {
143  return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
144 }
Here is the caller graph for this function:

◆ st7789v_delay_ms()

void st7789v_delay_ms ( uint32_t  ms)
146  {
148  volatile uint32_t temp;
149  while (ms--) {
150  do {
151  temp = SysTick->CTRL;
152  } while ((temp & 0x01) && !(temp & (1 << 16)));
153  }
154  } else {
155 #ifdef ST7789V_USE_RTOS
156  osDelay(ms);
157 #else
158  HAL_Delay(ms);
159 #endif
160  }
161 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_spi_wr_byte()

void st7789v_spi_wr_byte ( uint8_t  b)
163  {
165 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_spi_wr_bytes()

void st7789v_spi_wr_bytes ( uint8_t pb,
uint16_t  size 
)
167  {
168  if ((st7789v_flg & ST7789V_FLG_DMA) && !(st7789v_flg & ST7789V_FLG_SAFE) && (size > 4)) {
169 #ifdef ST7789V_USE_RTOS
170  osSignalSet(st7789v_task_handle, ST7789V_SIG_SPI_TX);
172 #endif //ST7789V_USE_RTOS
174 #ifdef ST7789V_USE_RTOS
176 #else //ST7789V_USE_RTOS
177 //TODO:
178 #endif //ST7789V_USE_RTOS
179  } else
181 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_spi_rd_bytes()

void st7789v_spi_rd_bytes ( uint8_t pb,
uint16_t  size 
)
183  {
184  HAL_StatusTypeDef ret;
185 #if 0
186 //#ifdef ST7789V_DMA
187  if (size <= 4)
189  else
190  {
191  #ifdef ST7789V_USE_RTOS
194  #endif //ST7789V_USE_RTOS
196  #ifdef ST7789V_USE_RTOS
198  #endif //ST7789V_USE_RTOS
199  }
200 #else //ST7789V_DMA
202 #endif //ST7789V_DMA
203  ret = ret; //prevent warning
204 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd()

void st7789v_cmd ( uint8_t  cmd,
uint8_t pdata,
uint16_t  size 
)
206  {
207  uint16_t tmp_flg = st7789v_flg; // save flags
208  if (st7789v_flg & FLG_CS)
209  st7789v_clr_cs(); // CS = L
210  if (st7789v_flg & FLG_RS)
211  st7789v_clr_rs(); // RS = L
212  st7789v_spi_wr_byte(cmd); // write command byte
213  if (pdata && size) {
214  st7789v_set_rs(); // RS = H
215  st7789v_spi_wr_bytes(pdata, size); // write data bytes
216  }
217  if (tmp_flg & FLG_CS)
218  st7789v_set_cs(); // CS = H
219 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_wr()

void st7789v_wr ( uint8_t pdata,
uint16_t  size 
)
221  {
222  if (!(pdata && size))
223  return; // null or empty data - return
224  uint16_t tmp_flg = st7789v_flg; // save flags
225  if (st7789v_flg & FLG_CS)
226  st7789v_clr_cs(); // CS = L
227  if (!(st7789v_flg & FLG_RS))
228  st7789v_set_rs(); // RS = H
229  st7789v_spi_wr_bytes(pdata, size); // write data bytes
230  if (tmp_flg & FLG_CS)
231  st7789v_set_cs(); // CS = H
232 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_rd()

void st7789v_rd ( uint8_t pdata,
uint16_t  size 
)
234  {
235  if (!(pdata && size))
236  return; // null or empty data - return
237  uint16_t tmp_flg = st7789v_flg; // save flags
238  if (st7789v_flg & FLG_CS)
239  st7789v_clr_cs(); // CS = L
240  if (!(st7789v_flg & FLG_RS))
241  st7789v_set_rs(); // RS = H
242  st7789v_spi_rd_bytes(pdata, size); // read data bytes
243  if (tmp_flg & FLG_CS)
244  st7789v_set_cs(); // CS = H
245 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_slpout()

void st7789v_cmd_slpout ( void  )
247  {
248  st7789v_cmd(CMD_SLPOUT, 0, 0);
249 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_madctl()

void st7789v_cmd_madctl ( uint8_t  madctl)
251  {
252  st7789v_cmd(CMD_MADCTL, &madctl, 1);
253 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_colmod()

void st7789v_cmd_colmod ( uint8_t  colmod)
255  {
256  st7789v_cmd(CMD_COLMOD, &colmod, 1);
257 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_dispon()

void st7789v_cmd_dispon ( void  )
259  {
260  st7789v_cmd(CMD_DISPON, 0, 0);
261 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_caset()

void st7789v_cmd_caset ( uint16_t  x,
uint16_t  cx 
)
263  {
264  uint8_t data[4] = { x >> 8, x & 0xff, cx >> 8, cx & 0xff };
266 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_raset()

void st7789v_cmd_raset ( uint16_t  y,
uint16_t  cy 
)
268  {
269  uint8_t data[4] = { y >> 8, y & 0xff, cy >> 8, cy & 0xff };
271 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_ramwr()

void st7789v_cmd_ramwr ( uint8_t pdata,
uint16_t  size 
)
273  {
274  st7789v_cmd(CMD_RAMWR, pdata, size);
275 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_cmd_ramrd()

void st7789v_cmd_ramrd ( uint8_t pdata,
uint16_t  size 
)
277  {
278  st7789v_cmd(CMD_RAMRD, 0, 0);
279  st7789v_rd(pdata, size);
280 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_init_ctl_pins()

void st7789v_init_ctl_pins ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_reset()

void st7789v_reset ( void  )
312  {
313  st7789v_clr_rst();
314  st7789v_delay_ms(15);
316  volatile uint16_t delay = 0;
317  int irq = __get_PRIMASK() & 1;
318  if (irq) __disable_irq();
319  while (!gpio_get(st7789v_config.pinRST))
320  delay++;
321  if (irq) __enable_irq();
323  st7789v_set_rst();
325 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_get_pixel()

color_t st7789v_get_pixel ( point_ui16_t  pt)
373  {
375  return 0;
376  uint16_t clr565;
377  st7789v_cmd_caset(pt.x, 1);
378  st7789v_cmd_raset(pt.y, 1);
379  st7789v_cmd_ramrd((uint8_t *)(&clr565), 2);
380  return _565_COLOR(clr565);
381 }
Here is the call graph for this function:

◆ st7789v_set_pixel_directColor()

void st7789v_set_pixel_directColor ( point_ui16_t  pt,
uint16_t  directColor 
)
383  {
385  return;
386  st7789v_cmd_caset(pt.x, 1);
387  st7789v_cmd_raset(pt.y, 1);
388  st7789v_cmd_ramwr((uint8_t *)(&directColor), 2);
389 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_num_of_ones()

static uint16_t set_num_of_ones ( uint8_t  num_of_ones)
static
392  {
393  return ~((uint16_t)(-1) << num_of_ones);
394 }
Here is the caller graph for this function:

◆ rd18bit_to_16bit()

static uint16_t rd18bit_to_16bit ( uint8_t buff)
static
418  {
419  return ((uint16_t)(buff[0] >> 5) & set_num_of_ones(3)) | (((uint16_t)(buff[2] >> 3) & set_num_of_ones(5)) << 3) | (((uint16_t)(buff[1] >> 3) & set_num_of_ones(5)) << 8) | (((uint16_t)(buff[0] >> 2) & set_num_of_ones(3)) << 13);
420 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ st7789v_get_pixel_directColor()

uint16_t st7789v_get_pixel_directColor ( point_ui16_t  pt)
422  {
424  return 0;
425  enum { buff_sz = 5 };
426  uint8_t buff[buff_sz];
427  st7789v_cmd_caset(pt.x, 1);
428  st7789v_cmd_raset(pt.y, 1);
429  st7789v_cmd_ramrd(buff, buff_sz);
430  uint16_t ret = rd18bit_to_16bit(buff + 2);
431  return ret; //directColor;
432 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rop_rgb888_invert()

static void rop_rgb888_invert ( uint8_t ppx888)
static
583  {
584  uint8_t r = ppx888[0];
585  uint8_t g = ppx888[1];
586  uint8_t b = ppx888[2];
587  ppx888[0] = 255 - r;
588  ppx888[1] = 255 - g;
589  ppx888[2] = 255 - b;
590 }

◆ rop_rgb888_swapbw()

static void rop_rgb888_swapbw ( uint8_t ppx888)
static
593  {
594  uint8_t r = ppx888[0];
595  uint8_t g = ppx888[1];
596  uint8_t b = ppx888[2];
597  uint8_t l = (r + g + b) / 3;
598  uint8_t l0 = (l >= SWAPBW_TOLERANCE) ? (l - SWAPBW_TOLERANCE) : 0;
599  uint8_t l1 = (l <= (255 - SWAPBW_TOLERANCE)) ? (l + SWAPBW_TOLERANCE) : 255;
600  if ((l0 <= r) && (r <= l1) && (l0 <= g) && (g <= l1) && (l0 <= b) && (b <= l1)) {
601  ppx888[0] = 255 - r;
602  ppx888[1] = 255 - g;
603  ppx888[2] = 255 - b;
604  }
605 }

◆ rop_rgb888_disabled()

static void rop_rgb888_disabled ( uint8_t ppx888)
static
607  {
608  uint8_t r = ppx888[0];
609  uint8_t g = ppx888[1];
610  uint8_t b = ppx888[2];
611  uint8_t l = (r + g + b) / 3;
612  uint8_t l0 = (l >= SWAPBW_TOLERANCE) ? (l - SWAPBW_TOLERANCE) : 0;
613  uint8_t l1 = (l <= (255 - SWAPBW_TOLERANCE)) ? (l + SWAPBW_TOLERANCE) : 255;
614  if ((l0 <= r) && (r <= l1) && (l0 <= g) && (g <= l1) && (l0 <= b) && (b <= l1)) {
615  ppx888[0] = r / 2;
616  ppx888[1] = g / 2;
617  ppx888[2] = b / 2;
618  }
619 }

◆ rop_rgb8888_swapbw()

static void rop_rgb8888_swapbw ( uint8_t ppx)
static
621  {
622  uint8_t r = ppx[0];
623  uint8_t g = ppx[1];
624  uint8_t b = ppx[2];
625  uint8_t a = ppx[3];
626  if ((r == g) && (g == b)) {
627  ppx[0] = 255 - r;
628  ppx[1] = 255 - g;
629  ppx[2] = 255 - b;
630  if (/*(r < 32) && */ (a < 128)) {
631  ppx[0] = 0;
632  ppx[1] = 0;
633  ppx[2] = 255;
634  ppx[3] = 255;
635  }
636  } else if ((a < 128)) {
637  ppx[0] = 0;
638  ppx[1] = 255;
639  ppx[2] = 0;
640  ppx[3] = 255;
641  }
642 }

◆ st7789v_draw_png_ex()

void st7789v_draw_png_ex ( point_ui16_t  pt,
FILE *  pf,
color_t  clr0,
uint8_t  rop 
)
885 {}
Here is the caller graph for this function:

◆ st7789v_draw_icon()

void st7789v_draw_icon ( point_ui16_t  pt,
uint16_t  id_res,
color_t  clr0,
uint8_t  rop 
)
646  {
647  FILE *pf = resource_fopen(id_res, "rb");
648  st7789v_draw_png_ex(pt, pf, clr0, rop);
649  fclose(pf);
650 }
Here is the call graph for this function:

◆ st7789v_enable_safe_mode()

void st7789v_enable_safe_mode ( void  )

enable safe mode (direct acces + safe delay)

923  {
925 }
Here is the caller graph for this function:

◆ st7789v_spi_tx_complete()

void st7789v_spi_tx_complete ( void  )
927  {
928 #ifdef ST7789V_USE_RTOS
929  osSignalSet(st7789v_task_handle, ST7789V_SIG_SPI_TX);
930 #endif //ST7789V_USE_RTOS
931 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ st7789v_flg

uint8_t st7789v_flg = 0

◆ st7789v_x

uint16_t st7789v_x = 0

◆ st7789v_y

uint16_t st7789v_y = 0

◆ st7789v_cx

uint16_t st7789v_cx = 0

◆ st7789v_cy

uint16_t st7789v_cy = 0

◆ st7789v_buff

uint8_t st7789v_buff[ST7789V_COLS *2 *16]

◆ st7789v_clip

rect_ui16_t st7789v_clip = { 0, 0, ST7789V_COLS, ST7789V_ROWS }

◆ st7789v_display

◆ st7789v_config

st7789v_config_t st7789v_config
Initial value:
= {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
}

◆ st7789v_reset_delay

uint16_t st7789v_reset_delay = 0
FLG_RST
#define FLG_RST
Definition: st7789v.c:73
st7789v_set_rs
static void st7789v_set_rs(void)
Definition: st7789v.c:117
st7789v_config
st7789v_config_t st7789v_config
Definition: st7789v.c:905
st7789v_wr
void st7789v_wr(uint8_t *pdata, uint16_t size)
Definition: st7789v.c:221
CMD_DISPON
#define CMD_DISPON
Definition: st7789v.c:24
st7789v_cmd_madctl
void st7789v_cmd_madctl(uint8_t madctl)
Definition: st7789v.c:251
_rect_ui16_t::y
uint16_t y
Definition: guitypes.h:71
_font_t::h
uint8_t h
Definition: guitypes.h:78
FONT_FLG_SWAP
#define FONT_FLG_SWAP
Definition: guitypes.h:36
_rect_ui16_t::w
uint16_t w
Definition: guitypes.h:72
CMD_RAMWR
#define CMD_RAMWR
Definition: st7789v.c:27
GPIO_MODE_OUTPUT_PP
#define GPIO_MODE_OUTPUT_PP
Definition: stm32f4xx_hal_gpio.h:136
color_alpha
static color_t color_alpha(color_t clr0, color_t clr1, uint8_t alpha)
Definition: guitypes.h:141
st7789v_cmd_dispon
void st7789v_cmd_dispon(void)
Definition: st7789v.c:259
GPIO_SPEED_FREQ_HIGH
#define GPIO_SPEED_FREQ_HIGH
Definition: stm32f4xx_hal_gpio.h:160
st7789v_clip
rect_ui16_t st7789v_clip
Definition: st7789v.c:84
is_interrupt
static int is_interrupt(void)
Definition: st7789v.c:142
st7789v_reset
void st7789v_reset(void)
Definition: st7789v.c:312
st7789v_delay_ms
void st7789v_delay_ms(uint32_t ms)
Definition: st7789v.c:146
st7789v_draw_text
void st7789v_draw_text(rect_ui16_t rc, const char *str, font_t *pf, color_t clr0, color_t clr1)
Definition: st7789v.c:562
st7789v_rd
void st7789v_rd(uint8_t *pdata, uint16_t size)
Definition: st7789v.c:234
CMD_SLPOUT
#define CMD_SLPOUT
Definition: st7789v.c:19
GAMMA_CURVE0
#define GAMMA_CURVE0
Definition: st7789v.c:43
st7789v_clear
void st7789v_clear(color_t clr)
Definition: st7789v.c:349
_font_t::pcs
void * pcs
Definition: guitypes.h:81
_st7789v_config_t::phspi
SPI_HandleTypeDef * phspi
Definition: st7789v.h:20
FLG_RS
#define FLG_RS
Definition: st7789v.c:72
st7789v_flg
uint8_t st7789v_flg
Definition: st7789v.c:75
st7789v_set_pixel
void st7789v_set_pixel(point_ui16_t pt, color_t clr)
Definition: st7789v.c:364
resource_fopen
FILE * resource_fopen(uint16_t id, const char *opentype)
Definition: guitypes.c:180
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
st7789v_spi_rd_bytes
void st7789v_spi_rd_bytes(uint8_t *pb, uint16_t size)
Definition: st7789v.c:183
_point_ui16_t::x
uint16_t x
Definition: guitypes.h:65
data
uint8_t data[8]
Definition: masstorage.h:49
i
uint8_t i
Definition: screen_test_graph.c:72
st7789v_fill_rect
void st7789v_fill_rect(rect_ui16_t rc, color_t clr)
Definition: st7789v.c:490
st7789v_done
void st7789v_done(void)
Definition: st7789v.c:346
osSignalSet
int32_t osSignalSet(osThreadId thread_id, int32_t signal)
Set the specified Signal Flags of an active thread.
Definition: cmsis_os.c:545
st7789v_draw_char
void st7789v_draw_char(point_ui16_t pt, char chr, font_t *pf, color_t clr0, color_t clr1)
Definition: st7789v.c:514
_st7789v_config_t::colmod
uint8_t colmod
Definition: st7789v.h:25
_st7789v_config_t::pinCS
uint8_t pinCS
Definition: st7789v.h:21
ST7789V_COLS
#define ST7789V_COLS
Definition: st7789v.c:14
_st7789v_config_t::pinRS
uint8_t pinRS
Definition: st7789v.h:22
osThreadGetId
osThreadId osThreadGetId(void)
Return the thread ID of the current running thread.
Definition: cmsis_os.c:283
st7789v_cmd_caset
void st7789v_cmd_caset(uint16_t x, uint16_t cx)
Definition: st7789v.c:263
CMD_CASET
#define CMD_CASET
Definition: st7789v.c:25
st7789v_cmd_slpout
void st7789v_cmd_slpout(void)
Definition: st7789v.c:247
st7789v_draw_png_ex
void st7789v_draw_png_ex(point_ui16_t pt, FILE *pf, color_t clr0, uint8_t rop)
Definition: st7789v.c:885
_point_ui16_t
Definition: guitypes.h:64
st7789v_draw_line
void st7789v_draw_line(point_ui16_t pt, point_ui16_t pt1, color_t clr)
Definition: st7789v.c:438
GPIO_PULLUP
#define GPIO_PULLUP
Definition: stm32f4xx_hal_gpio.h:171
osDelay
osStatus osDelay(uint32_t millisec)
Wait for Timeout (Time Delay)
Definition: cmsis_os.c:365
_display_t::fill_rect
display_fill_rect_t * fill_rect
Definition: display.h:33
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32f4xx_hal_def.h:55
gpio_get
static int gpio_get(uint8_t pin8)
Definition: gpio.h:94
st7789v_spi_wr_byte
void st7789v_spi_wr_byte(uint8_t b)
Definition: st7789v.c:163
osSignalWait
osEvent osSignalWait(int32_t signals, uint32_t millisec)
Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
Definition: cmsis_os.c:586
st7789v_cmd_raset
void st7789v_cmd_raset(uint16_t y, uint16_t cy)
Definition: st7789v.c:268
CMD_MADCTL
#define CMD_MADCTL
Definition: st7789v.c:29
_point_ui16_t::y
uint16_t y
Definition: guitypes.h:66
rect_empty_ui16
static int rect_empty_ui16(rect_ui16_t rc)
Definition: guitypes.h:177
rect_intersect_ui16
rect_ui16_t rect_intersect_ui16(rect_ui16_t rc, rect_ui16_t rc1)
Definition: guitypes.c:37
gpio_init
static void gpio_init(uint8_t pin8, uint32_t mode, uint32_t pull, uint32_t speed)
Definition: gpio.h:102
st7789v_set_cs
static void st7789v_set_cs(void)
Definition: st7789v.c:107
_font_t::asc_max
char asc_max
Definition: guitypes.h:83
_font_t::bpr
uint8_t bpr
Definition: guitypes.h:79
st7789v_cmd_colmod
void st7789v_cmd_colmod(uint8_t colmod)
Definition: st7789v.c:255
st7789v_buff
uint8_t st7789v_buff[ST7789V_COLS *2 *16]
Definition: st7789v.c:82
_font_t::w
uint8_t w
Definition: guitypes.h:77
_st7789v_config_t::madctl
uint8_t madctl
Definition: st7789v.h:26
HAL_SPI_Receive_DMA
HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
st7789v_init
void st7789v_init(void)
Definition: st7789v.c:327
GPIO_NOPULL
#define GPIO_NOPULL
Definition: stm32f4xx_hal_gpio.h:170
_st7789v_config_t::pinRST
uint8_t pinRST
Definition: st7789v.h:23
st7789v_draw_png
void st7789v_draw_png(point_ui16_t pt, FILE *pf)
Definition: st7789v.c:883
osWaitForever
#define osWaitForever
wait forever timeout value
Definition: cmsis_os.h:230
createSpeedLookupTable.a
list a
Definition: createSpeedLookupTable.py:29
st7789v_clr_rs
static void st7789v_clr_rs(void)
Definition: st7789v.c:122
uint8_t
const uint8_t[]
Definition: 404_html.c:3
st7789v_draw_icon
void st7789v_draw_icon(point_ui16_t pt, uint16_t id_res, color_t clr0, uint8_t rop)
Definition: st7789v.c:646
display
display_t * display
Definition: display.c:6
_rect_ui16_t::h
uint16_t h
Definition: guitypes.h:73
delay
void delay(uint32_t ms)
Definition: wiring_time.c:42
CMD_RASET
#define CMD_RASET
Definition: st7789v.c:26
st7789v_spi_wr_bytes
void st7789v_spi_wr_bytes(uint8_t *pb, uint16_t size)
Definition: st7789v.c:167
_565_COLOR
#define _565_COLOR(clr)
Definition: st7789v.c:68
ST7789V_FLG_DMA
#define ST7789V_FLG_DMA
Definition: st7789v.h:9
CMD_COLMOD
#define CMD_COLMOD
Definition: st7789v.c:32
ST7789V_ROWS
#define ST7789V_ROWS
Definition: st7789v.c:15
ST7789V_FLG_SAFE
#define ST7789V_FLG_SAFE
Definition: st7789v.h:11
_font_t::flg
uint32_t flg
Definition: guitypes.h:80
gpio_set
static void gpio_set(uint8_t pin8, int state)
Definition: gpio.h:98
ST7789V_SIG_SPI_TX
#define ST7789V_SIG_SPI_TX
Definition: guiconfig.h:18
st7789v_init_ctl_pins
void st7789v_init_ctl_pins(void)
Definition: st7789v.c:300
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
st7789v_cmd_ramrd
void st7789v_cmd_ramrd(uint8_t *pdata, uint16_t size)
Definition: st7789v.c:277
set_num_of_ones
static uint16_t set_num_of_ones(uint8_t num_of_ones)
Definition: st7789v.c:392
st7789v_clr_rst
static void st7789v_clr_rst(void)
Definition: st7789v.c:132
SWAPBW_TOLERANCE
#define SWAPBW_TOLERANCE
Definition: st7789v.c:592
st7789v_reset_delay
uint16_t st7789v_reset_delay
Definition: st7789v.c:920
st7789v_cmd
void st7789v_cmd(uint8_t cmd, uint8_t *pdata, uint16_t size)
Definition: st7789v.c:206
HAL_SPI_Transmit
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_Delay
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
Definition: stm32f4xx_hal.c:393
HAL_MAX_DELAY
#define HAL_MAX_DELAY
Definition: stm32f4xx_hal_def.h:76
GPIO_MODE_INPUT
#define GPIO_MODE_INPUT
Definition: stm32f4xx_hal_gpio.h:135
_COLOR_565
#define _COLOR_565(clr)
Definition: st7789v.c:66
_font_t::asc_min
char asc_min
Definition: guitypes.h:82
HAL_SPI_Receive
HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
FLG_CS
#define FLG_CS
Definition: st7789v.c:71
point_in_rect_ui16
static int point_in_rect_ui16(point_ui16_t pt, rect_ui16_t rc)
Definition: guitypes.h:169
FONT_FLG_LSBF
#define FONT_FLG_LSBF
Definition: guitypes.h:37
_st7789v_config_t::flg
uint8_t flg
Definition: st7789v.h:24
st7789v_draw_rect
void st7789v_draw_rect(rect_ui16_t rc, color_t clr)
Definition: st7789v.c:479
CMD_RAMRD
#define CMD_RAMRD
Definition: st7789v.c:28
rd18bit_to_16bit
static uint16_t rd18bit_to_16bit(uint8_t *buff)
Definition: st7789v.c:418
st7789v_cmd_ramwr
void st7789v_cmd_ramwr(uint8_t *pdata, uint16_t size)
Definition: st7789v.c:273
createSpeedLookupTable.b
list b
Definition: createSpeedLookupTable.py:30
HAL_SPI_Transmit_DMA
HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
st7789v_set_rst
static void st7789v_set_rst(void)
Definition: st7789v.c:127
GPIO_SPEED_FREQ_LOW
#define GPIO_SPEED_FREQ_LOW
Definition: stm32f4xx_hal_gpio.h:158
st7789v_clr_cs
static void st7789v_clr_cs(void)
Definition: st7789v.c:112
st7789v_fill_ui16
static void st7789v_fill_ui16(uint16_t *p, uint16_t v, uint16_t c)
Definition: st7789v.c:137
point_ui16
static point_ui16_t point_ui16(uint16_t x, uint16_t y)
Definition: guitypes.h:154
size
static png_bytep size_t size
Definition: pngwrite.c:2170