1 /* 2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 */ 4 #include <stdbool.h> 5 #include <stdio.h> 6 7 typedef struct _st7789_dev_t { 8 int spi_port; 9 int spi_freq; 10 int gpio_dc_id; 11 int gpio_reset_id; 12 int gpio_bgl_id; 13 14 // int screen_width; 15 // int screen_height; 16 // below user dont need to care 17 uint8_t *fb_addr; 18 int spi_fd; 19 int gpio_fd; 20 } st7789_dev_t; 21 22 #define ST7789_HEIGHT 240 23 #define ST7789_WIDTH 320 24 25 #define ST7789_NOP 0x00 26 #define ST7789_SWRESET 0x01 27 28 #define ST7789_SLPIN 0x10 29 #define ST7789_SLPOUT 0x11 30 #define ST7789_PTLON 0x12 31 #define ST7789_NORON 0x13 32 #define ST7789_INVOFF 0x20 33 #define ST7789_INVON 0x21 34 #define ST7789_DISPOFF 0x28 35 #define ST7789_DISPON 0x29 36 #define ST7789_IDMOFF 0x38 37 #define ST7789_IDMON 0x39 38 39 #define ST7789_CASET 0x2A 40 #define ST7789_RASET 0x2B 41 #define ST7789_RAMWR 0x2C 42 #define ST7789_RAMRD 0x2E 43 44 #define ST7789_COLMOD 0x3A 45 #define ST7789_MADCTL 0x36 46 47 #define ST7789_PTLAR 0x30 48 #define ST7789_VSCRDEF 0x33 49 #define ST7789_VSCRSADD 0x37 50 51 #define ST7789_WRDISBV 0x51 52 #define ST7789_WRCTRLD 0x53 53 #define ST7789_WRCACE 0x55 54 #define ST7789_WRCABCMB 0x5e 55 56 #define ST7789_POWSAVE 0xbc 57 #define ST7789_DLPOFFSAVE 0xbd 58 59 #define ST7789_MADCTL_MY 0x80 60 #define ST7789_MADCTL_MX 0x40 61 #define ST7789_MADCTL_MV 0x20 62 #define ST7789_MADCTL_ML 0x10 63 #define ST7789_MADCTL_RGB 0x08 64 65 #define ST_CMD_DELAY 0x80 66 67 int st7789_hw_init(st7789_dev_t *st7789_dev); 68 static void st7789_init_command(st7789_dev_t st7789_dev); 69 int st7789_hw_uninit(st7789_dev_t *st7789_dev); 70 void st7789_draw_pixel(st7789_dev_t st7789_dev, 71 uint16_t x, 72 uint16_t y, 73 uint16_t color); 74 void st7789_draw_area(st7789_dev_t st7789_dev, 75 uint16_t x, 76 uint16_t y, 77 uint16_t width, 78 uint16_t height, 79 uint8_t *frame); 80 void st7789_draw_rect(st7789_dev_t st7789_dev, 81 uint16_t x, 82 uint16_t y, 83 uint16_t width, 84 uint16_t height, 85 uint16_t color); 86 void st7789_draw_frame(st7789_dev_t st7789_dev, uint8_t *frame); 87 void st7789_set_rotation(st7789_dev_t st7789_dev, uint16_t rotation); 88 void st7789_set_invert(st7789_dev_t st7789_dev, uint8_t invert); 89 void st7789_enter_sleep(st7789_dev_t st7789_dev); 90 void st7789_exit_sleep(st7789_dev_t st7789_dev); 91