SSD2119: power control

All modes are working: powerOff, powerOn, powerSleep and powerDeepSleep.
ugfx_release_2.6
Mateusz Tomaszkiewicz 2013-02-25 00:35:13 +01:00
parent 51b292d3b9
commit bbdd57d9c1
1 changed files with 127 additions and 92 deletions

View File

@ -515,7 +515,7 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__) #if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
/** /**
* @brief Driver Control * @brief Driver Control
* @details Unsupported control codes are ignored. * @details Unsupported control codes are ignored.
* @note The value parameter should always be typecast to (void *). * @note The value parameter should always be typecast to (void *).
* @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.
@ -525,8 +525,6 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
* 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.
* GDISP_CONTROL_LLD - Low level driver control constants start at
* this value.
* *
* @param[in] what What to do. * @param[in] what What to do.
* @param[in] value The value to use (always cast to a void *). * @param[in] value The value to use (always cast to a void *).
@ -535,98 +533,135 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
*/ */
void gdisp_lld_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)
return;
switch((gdisp_powermode_t)value) {
case powerOff:
acquire_bus();
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
write_reg(SSD2119_REG_OSC_START, 0x0000); // Turn off oscillator
release_bus();
set_backlight(0);
break;
case powerOn:
if (GDISP.Powermode == powerSleep) {
acquire_bus();
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0000); // Leave sleep mode
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0033); // Display on
release_bus();
delayms(170);
} else if (GDISP.Powermode == powerDeepSleep) {
acquire_bus();
write_reg(SSD2119_REG_SLEEP_MODE_2, 0x0999); // Disable deep sleep function
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0000); // Leave sleep mode
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0033); // Display on
release_bus();
delayms(170);
} else {
acquire_bus();
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0000); // Leave sleep mode
release_bus();
gdisp_lld_init();
}
set_backlight(100);
break;
case powerSleep:
acquire_bus();
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
release_bus();
set_backlight(0);
delayms(25);
break;
case powerDeepSleep:
acquire_bus();
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
write_reg(SSD2119_REG_SLEEP_MODE_2, 0x2999); // Enable deep sleep function
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
release_bus();
set_backlight(0);
delayms(25);
break;
default:
return;
}
GDISP.Powermode = (gdisp_powermode_t)value;
return; return;
switch((gdisp_powermode_t)value) {
case powerOff: case GDISP_CONTROL_ORIENTATION:
acquire_bus(); if (GDISP.Orientation == (gdisp_orientation_t)value)
write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // enter sleep mode return;
write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // halt operation switch((gdisp_orientation_t)value) {
write_reg(SSD2119_REG_OSC_START, 0x0000); // turn off oszcillator case GDISP_ROTATE_0:
set_backlight(0); acquire_bus();
delayms(500); write_reg(0x0001, 0x2B3F);
release_bus(); /* ID = 11 AM = 0 */
break; write_reg(0x0011, 0x6070);
case powerOn: release_bus();
acquire_bus(); GDISP.Height = GDISP_SCREEN_HEIGHT;
write_reg(0x0010, 0x0000); // leave sleep mode GDISP.Width = GDISP_SCREEN_WIDTH;
release_bus(); break;
if (GDISP.Powermode != powerSleep)
gdisp_lld_init(); case GDISP_ROTATE_90:
set_backlight(100); acquire_bus();
break; write_reg(0x0001, 0x293F);
case powerSleep: /* ID = 11 AM = 1 */
acquire_bus(); write_reg(0x0011, 0x6078);
write_reg(0x0010, 0x0001); // enter sleep mode release_bus();
release_bus(); GDISP.Height = GDISP_SCREEN_WIDTH;
break; GDISP.Width = GDISP_SCREEN_HEIGHT;
break;
case GDISP_ROTATE_180:
acquire_bus();
write_reg(0x0001, 0x2B3F);
/* ID = 01 AM = 0 */
write_reg(0x0011, 0x6040);
release_bus();
GDISP.Height = GDISP_SCREEN_HEIGHT;
GDISP.Width = GDISP_SCREEN_WIDTH;
break;
case GDISP_ROTATE_270:
acquire_bus();
write_reg(0x0001, 0x293F);
/* ID = 01 AM = 1 */
write_reg(0x0011, 0x6048);
release_bus();
GDISP.Height = GDISP_SCREEN_WIDTH;
GDISP.Width = GDISP_SCREEN_HEIGHT;
break;
default:
return;
}
#if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
GDISP.clipx0 = 0;
GDISP.clipy0 = 0;
GDISP.clipx1 = GDISP.Width;
GDISP.clipy1 = GDISP.Height;
#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;
return;
case GDISP_CONTROL_CONTRAST:
default: default:
return; return;
}
GDISP.Powermode = (gdisp_powermode_t)value;
return;
case GDISP_CONTROL_ORIENTATION:
if (GDISP.Orientation == (gdisp_orientation_t)value)
return;
switch((gdisp_orientation_t)value) {
case GDISP_ROTATE_0:
acquire_bus();
write_reg(0x0001, 0x2B3F);
/* ID = 11 AM = 0 */
write_reg(0x0011, 0x6070);
release_bus();
GDISP.Height = GDISP_SCREEN_HEIGHT;
GDISP.Width = GDISP_SCREEN_WIDTH;
break;
case GDISP_ROTATE_90:
acquire_bus();
write_reg(0x0001, 0x293F);
/* ID = 11 AM = 1 */
write_reg(0x0011, 0x6078);
release_bus();
GDISP.Height = GDISP_SCREEN_WIDTH;
GDISP.Width = GDISP_SCREEN_HEIGHT;
break;
case GDISP_ROTATE_180:
acquire_bus();
write_reg(0x0001, 0x2B3F);
/* ID = 01 AM = 0 */
write_reg(0x0011, 0x6040);
release_bus();
GDISP.Height = GDISP_SCREEN_HEIGHT;
GDISP.Width = GDISP_SCREEN_WIDTH;
break;
case GDISP_ROTATE_270:
acquire_bus();
write_reg(0x0001, 0x293F);
/* ID = 01 AM = 1 */
write_reg(0x0011, 0x6048);
release_bus();
GDISP.Height = GDISP_SCREEN_WIDTH;
GDISP.Width = GDISP_SCREEN_HEIGHT;
break;
default:
return;
}
#if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
GDISP.clipx0 = 0;
GDISP.clipy0 = 0;
GDISP.clipx1 = GDISP.Width;
GDISP.clipy1 = GDISP.Height;
#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:
*/
} }
} }
#endif #endif