Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GC9A01 driver to work with release v8.2 lvgl #209

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 47 additions & 29 deletions display/GC9A01.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,53 @@
/*********************
* DEFINES
*********************/
#define GC9A01_BAUD 2000000 /*< 2,5 MHz (400 ns)*/
#ifndef GC9A01_XSTART
#define GC9A01_XSTART 0
#endif
#ifndef GC9A01_YSTART
#define GC9A01_YSTART 0
#endif

#define GC9A01_CMD_MODE 0
#define GC9A01_DATA_MODE 1
#define GC9A01_CMD_MODE 0
#define GC9A01_DATA_MODE 1

#define GC9A01_HOR_RES 240
#define GC9A01_VER_RES 240
#define GC9A01_HOR_RES 240
#define GC9A01_VER_RES 240

/* GC9A01 Commands that we know of. Limited documentation */
#define GC9A01_INVOFF 0x20
#define GC9A01_INVON 0x21
#define GC9A01_DISPON 0x29
#define GC9A01_CASET 0x2A
#define GC9A01_RASET 0x2B
#define GC9A01_RAMWR 0x2C
#define GC9A01_COLMOD 0x3A
#define GC9A01_MADCTL 0x36
#define GC9A01_MADCTL_MY 0x80
#define GC9A01_MADCTL_MX 0x40
#define GC9A01_MADCTL_MV 0x20
#define GC9A01_MADCTL_RGB 0x00
#define GC9A01_INVOFF 0x20
#define GC9A01_INVON 0x21
#define GC9A01_DISPON 0x29
#define GC9A01_CASET 0x2A
#define GC9A01_RASET 0x2B
#define GC9A01_RAMWR 0x2C
#define GC9A01_COLMOD 0x3A
#define GC9A01_MADCTL 0x36
#define GC9A01_MADCTL_MY 0x80
#define GC9A01_MADCTL_MX 0x40
#define GC9A01_MADCTL_MV 0x20
#define GC9A01_MADCTL_RGB 0x00
#define GC9A01_DISFNCTRL 0xB6

/**********************
* TYPEDEFS
**********************/

/* Init script function */
struct GC9A01_function {
uint16_t cmd;
uint16_t data;
};

/* Init script commands */
enum GC9A01_cmd {
GC9A01_START,
GC9A01_END,
GC9A01_CMD,
GC9A01_DATA,
GC9A01_DELAY
};

/**********************
* STATIC PROTOTYPES
**********************/
Expand Down Expand Up @@ -143,10 +163,10 @@ static struct GC9A01_function GC9A01_cfg_script[] = {
{ GC9A01_CMD, 0xC9}, // Power Control 4
{ GC9A01_DATA, 0x22},

{ GC9A01_CMD, 0xBE},
{ GC9A01_CMD, 0xBE},
{ GC9A01_DATA, 0x11},

{ GC9A01_CMD, 0xE1},
{ GC9A01_CMD, 0xE1},
{ GC9A01_DATA, 0x10},
{ GC9A01_DATA, 0x0E},

Expand Down Expand Up @@ -330,7 +350,7 @@ static int GC9A01_data_array(uint8_t *buf, uint32_t len)
for (uint32_t lp = 0; lp < len; lp++, pt++)
{
LV_DRV_DISP_SPI_WR_BYTE(*pt);
}
}
return 0;
}

Expand Down Expand Up @@ -409,7 +429,7 @@ void GC9A01_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
GC9A01_set_addr_win(x, y, x, y + h - 1);

uint8_t hi = color >> 8, lo = color;

while (h--) {
GC9A01_data(hi);
GC9A01_data(lo);
Expand Down Expand Up @@ -510,7 +530,7 @@ void GC9A01_setRotation(uint8_t m) {
break;
case 2:
GC9A01_data(GC9A01_MADCTL_RGB);

// _xstart = _colstart;
// _ystart = _rowstart;
break;
Expand All @@ -529,9 +549,6 @@ void GC9A01_setRotation(uint8_t m) {
*/
int GC9A01_init(void)
{
LV_DRV_DISP_SPI_FREQ(GC9A01_SPI_BAUD);
LV_DRV_DISP_SPI_MODE(GC9A01_SPI_BITS, GC9A01_SPI_MODE);

GC9A01_hard_reset();
GC9A01_run_cfg_script();

Expand All @@ -549,7 +566,7 @@ static void GC9A01_set_addr_win(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t

GC9A01_command(GC9A01_CASET); // Column addr set
GC9A01_data(x_start >> 8);
GC9A01_data(x_start & 0xFF); // XSTART
GC9A01_data(x_start & 0xFF); // XSTART
GC9A01_data(x_end >> 8);
GC9A01_data(x_end & 0xFF); // XEND

Expand All @@ -562,18 +579,19 @@ static void GC9A01_set_addr_win(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t
GC9A01_command(GC9A01_RAMWR);
}

void GC9A01_flush(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t *color_p)
void GC9A01_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t *color_p)
{
LV_DRV_DISP_SPI_CS(0); // Listen to us

GC9A01_set_addr_win(area->x1, area->y1, area->x2, area->y2);
int32_t len = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1) * 2;

LV_DRV_DISP_CMD_DATA(GC9A01_DATA_MODE);
LV_DRV_DISP_CMD_DATA(GC9A01_DATA_MODE);
LV_DRV_DISP_SPI_WR_ARRAY((char*)color_p, len);

LV_DRV_DISP_SPI_CS(1);
lv_disp_flush_ready(disp_drv); /* Indicate you are ready with the flushing*/
}

#endif
#endif

30 changes: 9 additions & 21 deletions display/GC9A01.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ extern "C" {
#include "lvgl/lvgl.h"
#endif

// #include "../../lv_drv_conf.h"
// #if USE_GC9A01 != 0
#if LV_COLOR_DEPTH != 16
#error "GC9A01 currently supports 'LV_COLOR_DEPTH == 16'. Set it in lv_conf.h"
#endif

// #include <stdint.h>
// #include "lvgl/lv_misc/lv_color.h"
#if LV_COLOR_16_SWAP != 1
#error "GC9A01 SPI requires LV_COLOR_16_SWAP == 1. Set it in lv_conf.h"
#endif

/*********************
* DEFINES
Expand All @@ -43,27 +45,12 @@ extern "C" {
* TYPEDEFS
**********************/

/* Init script function */
struct GC9A01_function {
uint16_t cmd;
uint16_t data;
};

/* Init script commands */
enum GC9A01_cmd {
GC9A01_START,
GC9A01_END,
GC9A01_CMD,
GC9A01_DATA,
GC9A01_DELAY
};

/**********************
* GLOBAL PROTOTYPES
**********************/

int GC9A01_init(void);
void GC9A01_flush(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
void GC9A01_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
void GC9A01_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
void GC9A01_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t * color_p);
void GC9A01_setRotation(uint8_t m);
Expand All @@ -85,4 +72,5 @@ void GC9A01_drawFastVLine(int16_t x, int16_t y, int16_t w, uint16_t color);
} /* extern "C" */
#endif

#endif /* GC9A01_H */
#endif /* GC9A01_H */