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
|
||||
*/
|
||||
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:
|
||||
write_reg(SSD2119_REG_X_RAM_ADDR, x & 0x01FF);
|
||||
write_reg(SSD2119_REG_Y_RAM_ADDR, 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;
|
||||
case GDISP_ROTATE_90:
|
||||
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);
|
||||
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_END, (x + cx - 1) & 0x01FF);
|
||||
break;
|
||||
case GDISP_ROTATE_270:
|
||||
write_reg(SSD2119_REG_V_RAM_POS, (((y + cy - 1) << 8) & 0xFF00 ) | (x & 0x00FF));
|
||||
write_reg(SSD2119_REG_H_RAM_START, (y & 0x01FF));
|
||||
write_reg(SSD2119_REG_H_RAM_END, (y + cy - 1) & 0x01FF);
|
||||
case GDISP_ROTATE_90:
|
||||
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, (GDISP_SCREEN_WIDTH - (y + cy)) & 0x01FF);
|
||||
write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
|
||||
break;
|
||||
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_H_RAM_START, (GDISP_SCREEN_WIDTH - (x + cx)) & 0x01FF);
|
||||
write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - x - 1) & 0x01FF);
|
||||
break;
|
||||
case GDISP_ROTATE_90:
|
||||
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, (GDISP_SCREEN_WIDTH - (y + cy)) & 0x01FF);
|
||||
write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
|
||||
case GDISP_ROTATE_270:
|
||||
write_reg(SSD2119_REG_V_RAM_POS, (((y + cy - 1) << 8) & 0xFF00 ) | (x & 0x00FF));
|
||||
write_reg(SSD2119_REG_H_RAM_START, (y & 0x01FF));
|
||||
write_reg(SSD2119_REG_H_RAM_END, (y + cy - 1) & 0x01FF);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ static __inline void reset_viewport(void) {
|
|||
*
|
||||
* @notapi
|
||||
*/
|
||||
bool_t lld_gdisp_init(void) {
|
||||
bool_t gdisp_lld_init(void) {
|
||||
/* Initialise your display */
|
||||
init_board();
|
||||
|
||||
|
@ -259,7 +259,7 @@ bool_t lld_gdisp_init(void) {
|
|||
// Release the bus
|
||||
release_bus();
|
||||
|
||||
/* Turn on the back-light */
|
||||
/* Turn on the backlight */
|
||||
set_backlight(GDISP_INITIAL_BACKLIGHT);
|
||||
|
||||
/* Initialise the GDISP structure */
|
||||
|
@ -287,7 +287,7 @@ bool_t lld_gdisp_init(void) {
|
|||
*
|
||||
* @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 (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
|
||||
#endif
|
||||
|
@ -324,7 +324,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
|||
*
|
||||
* @notapi
|
||||
*/
|
||||
void lld_gdisp_clear(color_t color) {
|
||||
void gdisp_lld_clear(color_t color) {
|
||||
unsigned i;
|
||||
|
||||
acquire_bus();
|
||||
|
@ -349,7 +349,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
|||
*
|
||||
* @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;
|
||||
|
||||
#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
|
||||
*/
|
||||
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;
|
||||
unsigned lg;
|
||||
|
||||
|
@ -424,7 +424,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
|||
*
|
||||
* @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;
|
||||
|
||||
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
||||
|
@ -533,7 +533,7 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
|||
*
|
||||
* @notapi
|
||||
*/
|
||||
void lld_gdisp_control(unsigned what, void *value) {
|
||||
void gdisp_lld_control(unsigned what, void *value) {
|
||||
switch(what) {
|
||||
case GDISP_CONTROL_POWER:
|
||||
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) {
|
||||
case powerOff:
|
||||
acquire_bus();
|
||||
write_reg(0x0010, 0x0000); // leave sleep mode
|
||||
write_reg(0x0007, 0x0000); // halt operation
|
||||
write_reg(0x0000, 0x0000); // turn off oszillator
|
||||
write_reg(0x0010, 0x0001); // enter sleepmode
|
||||
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // enter sleep mode
|
||||
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // halt operation
|
||||
write_reg(SSD2119_REG_OSC_START, 0x0000); // turn off oszcillator
|
||||
set_backlight(0);
|
||||
delayms(500);
|
||||
release_bus();
|
||||
break;
|
||||
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
|
||||
release_bus();
|
||||
if (GDISP.Powermode != powerSleep)
|
||||
GDISP_LLD(init)();
|
||||
gdisp_lld_init();
|
||||
set_backlight(100);
|
||||
break;
|
||||
case powerSleep:
|
||||
acquire_bus();
|
||||
|
@ -615,8 +617,14 @@ void lld_gdisp_draw_pixel(coord_t x, coord_t y, color_t color) {
|
|||
#endif
|
||||
GDISP.Orientation = (gdisp_orientation_t)value;
|
||||
return;
|
||||
/*
|
||||
case GDISP_CONTROL_BACKLIGHT:
|
||||
if ((unsigned)value > 100) {
|
||||
value = (void *) 100;
|
||||
}
|
||||
set_backlight((unsigned)value);
|
||||
GDISP.Backlight = (unsigned)value;
|
||||
break;
|
||||
/*
|
||||
case GDISP_CONTROL_CONTRAST:
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -84,9 +84,11 @@ static __inline void init_board(void) {
|
|||
CLR_CS;
|
||||
//SET_RST;
|
||||
|
||||
/* Display backlight always on */
|
||||
palSetPadMode(GPIOD, 13, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPad(GPIOD, 13);
|
||||
/* Display backlight control */
|
||||
/* TIM4 is an alternate function 2 (AF2) */
|
||||
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
|
||||
*/
|
||||
static __inline void set_backlight(uint8_t percent) {
|
||||
(void) percent;
|
||||
/* Nothing to do here - Backlight always on */
|
||||
pwmEnableChannel(&PWMD4, 1, percent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,6 +36,21 @@
|
|||
#define SET_RST palSetPad(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.
|
||||
* @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 */
|
||||
FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
|
||||
|
||||
/* Display backlight always on */
|
||||
palSetPadMode(GPIOD, 13, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPad(GPIOD, 13);
|
||||
|
||||
/* Display backlight control */
|
||||
/* 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
|
||||
*/
|
||||
static __inline void set_backlight(uint8_t percent) {
|
||||
(void) percent;
|
||||
/* Nothing to do here - Backlight always on */
|
||||
pwmEnableChannel(&PWMD4, 1, percent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
Description:
|
||||
|
||||
Driver for LCD with 16-bit interface in 8080 mode (65k colors).
|
||||
|
||||
To use this driver:
|
||||
|
||||
1. Add in your halconf.h:
|
||||
|
@ -11,6 +15,7 @@ To use this driver:
|
|||
Currently known boards are:
|
||||
BOARD_EMBEST_DMSTF4BB - GPIO 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:
|
||||
#define GDISP_SCREEN_WIDTH 320
|
||||
|
|
Loading…
Add table
Reference in a new issue