SSD2119: backlight control
- Backlight uses PWM on TIM4 CH2. - Updated readme. - Updated gdisp_lld.c: moved from lld_gdisp_* to gdisp_lld_* functions names format. - One forgotten GDISP_LLD() macro removal. - General code cleanup (make diff with -w parameter ;))
This commit is contained in:
parent
d9a92aa30c
commit
cec4628a97
6 changed files with 1123 additions and 1096 deletions
|
@ -80,22 +80,22 @@ static __inline void set_cursor(coord_t x, coord_t y) {
|
||||||
* Use a bit mask to make sure they are not set too high
|
* Use a bit mask to make sure they are not set too high
|
||||||
*/
|
*/
|
||||||
switch(GDISP.Orientation) {
|
switch(GDISP.Orientation) {
|
||||||
case GDISP_ROTATE_180:
|
|
||||||
write_reg(SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH - 1 - x) & 0x01FF);
|
|
||||||
write_reg(SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT - 1 - y) & 0x00FF);
|
|
||||||
break;
|
|
||||||
case GDISP_ROTATE_0:
|
case GDISP_ROTATE_0:
|
||||||
write_reg(SSD2119_REG_X_RAM_ADDR, x & 0x01FF);
|
write_reg(SSD2119_REG_X_RAM_ADDR, x & 0x01FF);
|
||||||
write_reg(SSD2119_REG_Y_RAM_ADDR, y & 0x00FF);
|
write_reg(SSD2119_REG_Y_RAM_ADDR, y & 0x00FF);
|
||||||
break;
|
break;
|
||||||
case GDISP_ROTATE_270:
|
|
||||||
write_reg(SSD2119_REG_X_RAM_ADDR, y & 0x01FF);
|
|
||||||
write_reg(SSD2119_REG_Y_RAM_ADDR, x & 0x00FF);
|
|
||||||
break;
|
|
||||||
case GDISP_ROTATE_90:
|
case GDISP_ROTATE_90:
|
||||||
write_reg(SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
|
write_reg(SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
|
||||||
write_reg(SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT - x - 1) & 0x00FF);
|
write_reg(SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT - x - 1) & 0x00FF);
|
||||||
break;
|
break;
|
||||||
|
case GDISP_ROTATE_180:
|
||||||
|
write_reg(SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH - 1 - x) & 0x01FF);
|
||||||
|
write_reg(SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT - 1 - y) & 0x00FF);
|
||||||
|
break;
|
||||||
|
case GDISP_ROTATE_270:
|
||||||
|
write_reg(SSD2119_REG_X_RAM_ADDR, y & 0x01FF);
|
||||||
|
write_reg(SSD2119_REG_Y_RAM_ADDR, x & 0x00FF);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,20 +117,20 @@ static void set_viewport(coord_t x, coord_t y, coord_t cx, coord_t cy) {
|
||||||
write_reg(SSD2119_REG_H_RAM_START, (x & 0x01FF));
|
write_reg(SSD2119_REG_H_RAM_START, (x & 0x01FF));
|
||||||
write_reg(SSD2119_REG_H_RAM_END, (x + cx - 1) & 0x01FF);
|
write_reg(SSD2119_REG_H_RAM_END, (x + cx - 1) & 0x01FF);
|
||||||
break;
|
break;
|
||||||
case GDISP_ROTATE_270:
|
case GDISP_ROTATE_90:
|
||||||
write_reg(SSD2119_REG_V_RAM_POS, (((y + cy - 1) << 8) & 0xFF00 ) | (x & 0x00FF));
|
write_reg(SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT - x - 1) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (x + cx)) & 0x00FF));
|
||||||
write_reg(SSD2119_REG_H_RAM_START, (y & 0x01FF));
|
write_reg(SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (y + cy)) & 0x01FF);
|
||||||
write_reg(SSD2119_REG_H_RAM_END, (y + cy - 1) & 0x01FF);
|
write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
|
||||||
break;
|
break;
|
||||||
case GDISP_ROTATE_180:
|
case GDISP_ROTATE_180:
|
||||||
write_reg(SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT - y - 1) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (y + cy)) & 0x00FF));
|
write_reg(SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT - y - 1) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (y + cy)) & 0x00FF));
|
||||||
write_reg(SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (x + cx)) & 0x01FF);
|
write_reg(SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (x + cx)) & 0x01FF);
|
||||||
write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - x - 1) & 0x01FF);
|
write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - x - 1) & 0x01FF);
|
||||||
break;
|
break;
|
||||||
case GDISP_ROTATE_90:
|
case GDISP_ROTATE_270:
|
||||||
write_reg(SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT - x - 1) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (x + cx)) & 0x00FF));
|
write_reg(SSD2119_REG_V_RAM_POS, (((y + cy - 1) << 8) & 0xFF00 ) | (x & 0x00FF));
|
||||||
write_reg(SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (y + cy)) & 0x01FF);
|
write_reg(SSD2119_REG_H_RAM_START, (y & 0x01FF));
|
||||||
write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
|
write_reg(SSD2119_REG_H_RAM_END, (y + cy - 1) & 0x01FF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ static __inline void reset_viewport(void) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
bool_t lld_gdisp_init(void) {
|
bool_t gdisp_lld_init(void) {
|
||||||
/* Initialise your display */
|
/* Initialise your display */
|
||||||
init_board();
|
init_board();
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ bool_t lld_gdisp_init(void) {
|
||||||
// Release the bus
|
// Release the bus
|
||||||
release_bus();
|
release_bus();
|
||||||
|
|
||||||
/* Turn on the back-light */
|
/* Turn on the backlight */
|
||||||
set_backlight(GDISP_INITIAL_BACKLIGHT);
|
set_backlight(GDISP_INITIAL_BACKLIGHT);
|
||||||
|
|
||||||
/* Initialise the GDISP structure */
|
/* Initialise the GDISP structure */
|
||||||
|
@ -287,7 +287,7 @@ bool_t lld_gdisp_init(void) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
||||||
if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
|
if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
|
||||||
#endif
|
#endif
|
||||||
|
@ -324,7 +324,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void lld_gdisp_clear(color_t color) {
|
void gdisp_lld_clear(color_t color) {
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
acquire_bus();
|
acquire_bus();
|
||||||
|
@ -349,7 +349,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void lld_gdisp_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
|
void gdisp_lld_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
|
||||||
unsigned i, area;
|
unsigned i, area;
|
||||||
|
|
||||||
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
||||||
|
@ -385,7 +385,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void lld_gdisp_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
|
void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
|
||||||
coord_t endx, endy;
|
coord_t endx, endy;
|
||||||
unsigned lg;
|
unsigned lg;
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
color_t lld_gdisp_get_pixel_color(coord_t x, coord_t y) {
|
color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
|
||||||
color_t color;
|
color_t color;
|
||||||
|
|
||||||
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
||||||
|
@ -521,7 +521,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
* @note There are some predefined and some specific to the low level driver.
|
* @note There are some predefined and some specific to the low level driver.
|
||||||
* @note GDISP_CONTROL_POWER - Takes a gdisp_powermode_t
|
* @note GDISP_CONTROL_POWER - Takes a gdisp_powermode_t
|
||||||
* GDISP_CONTROL_ORIENTATION - Takes a gdisp_orientation_t
|
* GDISP_CONTROL_ORIENTATION - Takes a gdisp_orientation_t
|
||||||
* GDISP_CONTROL_BACKLIGHT - Takes an int from 0 to 100. For a driver
|
* GDISP_CONTROL_BACKLIGHT - Takes an int from 0 to 100. For a driver
|
||||||
* that only supports off/on anything other
|
* that only supports off/on anything other
|
||||||
* than zero is on.
|
* than zero is on.
|
||||||
* GDISP_CONTROL_CONTRAST - Takes an int from 0 to 100.
|
* GDISP_CONTROL_CONTRAST - Takes an int from 0 to 100.
|
||||||
|
@ -533,7 +533,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void lld_gdisp_control(unsigned what, void *value) {
|
void gdisp_lld_control(unsigned what, void *value) {
|
||||||
switch(what) {
|
switch(what) {
|
||||||
case GDISP_CONTROL_POWER:
|
case GDISP_CONTROL_POWER:
|
||||||
if (GDISP.Powermode == (gdisp_powermode_t)value)
|
if (GDISP.Powermode == (gdisp_powermode_t)value)
|
||||||
|
@ -541,10 +541,11 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
switch((gdisp_powermode_t)value) {
|
switch((gdisp_powermode_t)value) {
|
||||||
case powerOff:
|
case powerOff:
|
||||||
acquire_bus();
|
acquire_bus();
|
||||||
write_reg(0x0010, 0x0000); // leave sleep mode
|
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // enter sleep mode
|
||||||
write_reg(0x0007, 0x0000); // halt operation
|
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // halt operation
|
||||||
write_reg(0x0000, 0x0000); // turn off oszillator
|
write_reg(SSD2119_REG_OSC_START, 0x0000); // turn off oszcillator
|
||||||
write_reg(0x0010, 0x0001); // enter sleepmode
|
set_backlight(0);
|
||||||
|
delayms(500);
|
||||||
release_bus();
|
release_bus();
|
||||||
break;
|
break;
|
||||||
case powerOn:
|
case powerOn:
|
||||||
|
@ -552,7 +553,8 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
write_reg(0x0010, 0x0000); // leave sleep mode
|
write_reg(0x0010, 0x0000); // leave sleep mode
|
||||||
release_bus();
|
release_bus();
|
||||||
if (GDISP.Powermode != powerSleep)
|
if (GDISP.Powermode != powerSleep)
|
||||||
GDISP_LLD(init)();
|
gdisp_lld_init();
|
||||||
|
set_backlight(100);
|
||||||
break;
|
break;
|
||||||
case powerSleep:
|
case powerSleep:
|
||||||
acquire_bus();
|
acquire_bus();
|
||||||
|
@ -608,15 +610,21 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
|
#if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
|
||||||
GDISP.clipx0 = 0;
|
GDISP.clipx0 = 0;
|
||||||
GDISP.clipy0 = 0;
|
GDISP.clipy0 = 0;
|
||||||
GDISP.clipx1 = GDISP.Width;
|
GDISP.clipx1 = GDISP.Width;
|
||||||
GDISP.clipy1 = GDISP.Height;
|
GDISP.clipy1 = GDISP.Height;
|
||||||
#endif
|
#endif
|
||||||
GDISP.Orientation = (gdisp_orientation_t)value;
|
GDISP.Orientation = (gdisp_orientation_t)value;
|
||||||
return;
|
return;
|
||||||
/*
|
|
||||||
case GDISP_CONTROL_BACKLIGHT:
|
case GDISP_CONTROL_BACKLIGHT:
|
||||||
|
if ((unsigned)value > 100) {
|
||||||
|
value = (void *) 100;
|
||||||
|
}
|
||||||
|
set_backlight((unsigned)value);
|
||||||
|
GDISP.Backlight = (unsigned)value;
|
||||||
|
break;
|
||||||
|
/*
|
||||||
case GDISP_CONTROL_CONTRAST:
|
case GDISP_CONTROL_CONTRAST:
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,9 +84,11 @@ static __inline void init_board(void) {
|
||||||
CLR_CS;
|
CLR_CS;
|
||||||
//SET_RST;
|
//SET_RST;
|
||||||
|
|
||||||
/* Display backlight always on */
|
/* Display backlight control */
|
||||||
palSetPadMode(GPIOD, 13, PAL_MODE_OUTPUT_PUSHPULL);
|
/* TIM4 is an alternate function 2 (AF2) */
|
||||||
palSetPad(GPIOD, 13);
|
pwmStart(&PWMD4, &pwmcfg);
|
||||||
|
palSetPadMode(GPIOD, 13, PAL_MODE_ALTERNATE(2));
|
||||||
|
pwmEnableChannel(&PWMD4, 1, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,8 +114,7 @@ static __inline void setpin_reset(bool_t state) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static __inline void set_backlight(uint8_t percent) {
|
static __inline void set_backlight(uint8_t percent) {
|
||||||
(void) percent;
|
pwmEnableChannel(&PWMD4, 1, percent);
|
||||||
/* Nothing to do here - Backlight always on */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,6 +36,21 @@
|
||||||
#define SET_RST palSetPad(GPIOD, 3);
|
#define SET_RST palSetPad(GPIOD, 3);
|
||||||
#define CLR_RST palClearPad(GPIOD, 3);
|
#define CLR_RST palClearPad(GPIOD, 3);
|
||||||
|
|
||||||
|
/* PWM configuration structure. We use timer 4 channel 2 (orange LED on board). */
|
||||||
|
static const PWMConfig pwmcfg = {
|
||||||
|
100000, /* 100kHz PWM clock frequency. */
|
||||||
|
100, /* PWM period is 128 cycles. */
|
||||||
|
NULL,
|
||||||
|
{
|
||||||
|
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
|
||||||
|
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
|
||||||
|
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
|
||||||
|
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
|
||||||
|
},
|
||||||
|
/* HW dependent part.*/
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise the board for the display.
|
* @brief Initialise the board for the display.
|
||||||
* @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
|
* @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
|
||||||
|
@ -70,12 +85,11 @@ static __inline void init_board(void) {
|
||||||
* This is actually not needed as already set by default after reset */
|
* This is actually not needed as already set by default after reset */
|
||||||
FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
|
FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
|
||||||
|
|
||||||
/* Display backlight always on */
|
/* Display backlight control */
|
||||||
palSetPadMode(GPIOD, 13, PAL_MODE_OUTPUT_PUSHPULL);
|
|
||||||
palSetPad(GPIOD, 13);
|
|
||||||
|
|
||||||
/* TIM4 is an alternate function 2 (AF2) */
|
/* TIM4 is an alternate function 2 (AF2) */
|
||||||
//palSetPadMode(GPIOD, 13, PAL_MODE_ALTERNATE(2));
|
pwmStart(&PWMD4, &pwmcfg);
|
||||||
|
palSetPadMode(GPIOD, 13, PAL_MODE_ALTERNATE(2));
|
||||||
|
pwmEnableChannel(&PWMD4, 1, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,8 +115,7 @@ static __inline void setpin_reset(bool_t state) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static __inline void set_backlight(uint8_t percent) {
|
static __inline void set_backlight(uint8_t percent) {
|
||||||
(void) percent;
|
pwmEnableChannel(&PWMD4, 1, percent);
|
||||||
/* Nothing to do here - Backlight always on */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
Description:
|
||||||
|
|
||||||
|
Driver for LCD with 16-bit interface in 8080 mode (65k colors).
|
||||||
|
|
||||||
To use this driver:
|
To use this driver:
|
||||||
|
|
||||||
1. Add in your halconf.h:
|
1. Add in your halconf.h:
|
||||||
|
@ -11,6 +15,7 @@ To use this driver:
|
||||||
Currently known boards are:
|
Currently known boards are:
|
||||||
BOARD_EMBEST_DMSTF4BB - GPIO interface
|
BOARD_EMBEST_DMSTF4BB - GPIO interface
|
||||||
BOARD_EMBEST_DMSTF4BB_FSMC - FSMC interface
|
BOARD_EMBEST_DMSTF4BB_FSMC - FSMC interface
|
||||||
|
Both board configurations assume you have STM32_PWM_USE_TIM4 set to TRUE in your mcuconf.h.
|
||||||
|
|
||||||
d) The following are optional - define them if you are not using the defaults below:
|
d) The following are optional - define them if you are not using the defaults below:
|
||||||
#define GDISP_SCREEN_WIDTH 320
|
#define GDISP_SCREEN_WIDTH 320
|
||||||
|
|
Loading…
Add table
Reference in a new issue