📄 ddi_display_controller_ssd133x.c
字号:
////////////////////////////////////////////////////////////////////////////////
//! \addtogroup ddi_display
//! @{
//
// Copyright (c) 2004-2005 SigmaTel, Inc.
//
//! \file ddi_display_controller_ssd133x.c
//! \brief Structures and code specific to the Solomon ssd133x controllers
//! \version 0.1
//! \date 08/2005
//!
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Includes and external references
////////////////////////////////////////////////////////////////////////////////
#include <types.h>
#include <gfx.h>
#include <drivers\ddi_display.h>
#include <stdarg.h>
#include <registers\regspower.h> // need this to check for alkaline battery
#include "..\ddi_display_controller.h"
#include "..\ddi_display_controller_priv.h"
#include <drivers\ddi_gpio.h>
#include <drivers\ddi_pwm.h>
#include <drivers\ddi_lcdif.h>
#include <string.h>
#if defined(RTOS_THREADX)
#include <os\os_thi_api.h>
#else
#include <registers\regspwm.h>
#include <registers\regspinctrl.h>
#endif
#include <drivers\ddi_etm.h>
////////////////////////////////////////////////////////////////////////////////
// Externs
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
// For the 1339, parameters are send in data mode rather than command mode
#ifdef DDI_DISPLAY_CONTROLLER_SSD1339
#define PARAM_MODE DATA_MODE
#elif defined(DDI_DISPLAY_CONTROLLER_SSD1332)
#define PARAM_MODE CMD_MODE
#endif
//! Command byte to set the horizontal position register
#define DDI_DISPLAY_HORZ_REGION_CMD 0x15
//! Command byte to set the vertical position register
#define DDI_DISPLAY_VERT_REGION_CMD 0x75
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
//! Defines the frequency of the backlight PWM control signal
#define BACKLIGHT_PWM_FREQ 12000000
#else
//! Defines the CDIV value for OS independent PWM control
#define BACKLIGHT_PWM_CDIV BV_PWMn_PERIOD_CDIV__DIV_1
//! Defines the period in divided clocks for OS independent PWM control
#define BACKLIGHT_PWM_PERIOD 200
#endif
#define DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL 1
#ifdef DDI_DISPLAY_CONTROLLER_SSD1339
// Max width for the controller
#define DDI_DISPLAY_CONTROLLER_MAX_WIDTH 128
// Max height for the controller
#define DDI_DISPLAY_CONTROLLER_MAX_HEIGHT 128
#elif defined(DDI_DISPLAY_CONTROLLER_SSD1332)
// Max width for the controller
#define DDI_DISPLAY_CONTROLLER_MAX_WIDTH 96
// Max height for the controller
#define DDI_DISPLAY_CONTROLLER_MAX_HEIGHT 64
#endif
#if 0
//! Minimum contrast value set in hardware
#define MIN_CONTRAST_RED (0xa0 - 63)
//! Maximum contrast value set in hardware
#define MAX_CONTRAST_RED (0xa0 + 63)
//! Minimum contrast value set in hardware
#define MIN_CONTRAST_GREEN (0x80 - 63)
//! Maximum contrast value set in hardware
#define MAX_CONTRAST_GREEN (0x80 + 63)
//! Minimum contrast value set in hardware
#define MIN_CONTRAST_BLUE (0xc0 - 63)
//! Maximum contrast value set in hardware
#define MAX_CONTRAST_BLUE (0xc0 + 63)
#endif
//! Minimum contrast value set in hardware
#define MIN_CONTRAST_RED 0
//! Maximum contrast value set in hardware
#define MAX_CONTRAST_RED 0xff
//! Minimum contrast value set in hardware
#define MIN_CONTRAST_GREEN 0
//! Maximum contrast value set in hardware
#define MAX_CONTRAST_GREEN 0xff
//! Minimum contrast value set in hardware
#define MIN_CONTRAST_BLUE 0
//! Maximum contrast value set in hardware
#define MAX_CONTRAST_BLUE 0xff
//! Min allowed brightness setting
#define MIN_BRIGHTNESS 0
//! Max allowed brightness setting
#define MAX_BRIGHTNESS 15
//! Min allowed brightness percentage
#define MIN_BRIGHTNESS_PERCENTAGE 0
//! Alkaline batttery can't support the power needed for high brightness
#define ALKALINE_MIN_BRIGHTNESS_PERCENTAGE 10
//! Max allowed brightness percentage
#define MAX_BRIGHTNESS_PERCENTAGE 70
//! Alkaline batttery can't support the power needed for high brightness
#define ALKALINE_MAX_BRIGHTNESS_PERCENTAGE 20
#ifdef DDI_LCDIF_WORDLENGTH_16BITS
#define DDI_DISPLAY_WORD_TYPE uint16_t
#define DDI_DISPLAY_WORDLENGTH WORDLENGTH_16BITS
#define DDI_DISPLAY_DATA_SWIZZLE NO_SWAP
#else
#define DDI_DISPLAY_WORD_TYPE uint8_t
#define DDI_DISPLAY_WORDLENGTH WORDLENGTH_8BITS
#define DDI_DISPLAY_DATA_SWIZZLE HWD_BYTE_SWAP
#endif
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
static void InitPwmBacklight(void);
static void delay(uint32_t u32DelayValue);
////////////////////////////////////////////////////////////////////////////////
// Variables
////////////////////////////////////////////////////////////////////////////////
//! This variable is needed since the command contains multiple fields that
//! may be modified by various operations and we cannot read from the LCDIF
static uint8_t stc_u8RemapAndColorByte = 0x70;
// variables for alkaline mode since it can't power full brighness
static uint8_t u8MaxBrightnessPercentage;
static uint8_t u8MinBrightnessPercentage;
////////////////////////////////////////////////////////////////////////////////
// Globals
////////////////////////////////////////////////////////////////////////////////
uint16_t g_ddi_display_u16ScreenWidth = DDI_DISPLAY_DEFAULT_SIZE_HORIZONTAL;
uint16_t g_ddi_display_u16ScreenHeight = DDI_DISPLAY_DEFAULT_SIZE_VERTICAL;
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//! \brief Writes a single command or param/data byte to the controller
//!
//! \fntype Function
//!
//! \param[in] eCommMode - CMD_MODE or DATA_MODE specifier
//! \param[in] u8CommandByte - Command or param/data to send
//!
//! This function sends a single byte to the display controller
//!
////////////////////////////////////////////////////////////////////////////////
void WriteDirect(hw_lcdif_CommMode_t eCommMode, uint8_t u8CommandByte)
{
uint32_t u32Command = u8CommandByte;
RtStatus_t ret;
switch( ddi_lcdif_GetDataSwizzle() )
{
case NO_SWAP:
// Leave the data as is
break;
case HWD_BYTE_SWAP: // Swap bytes within each half-word
// Move command byte to upper half of lower 16-bit word
u32Command <<= 8;
break;
case HWD_SWAP: // Swap half-words
// Move command byte to lower half of upper 16-bit word
u32Command <<= 16;
break;
case SWAP_ALL_BYTES: // Swap bytes 0,3 and 1,2
// Move command byte to upper half of upper 16-bit word
u32Command <<= 24;
break;
default:
SystemHalt(); // Programming error
}
ret = ddi_lcdif_WriteDirect(eCommMode, (void *)&u32Command, sizeof(DDI_DISPLAY_WORD_TYPE));
assert(!ret);
}
////////////////////////////////////////////////////////////////////////////////
//! \brief Sends commands to initialize the controller from reset
//!
//! \fntype Function
//!
//! \param[in] eBitmapType - Graphics color format specifier
//! \param[in] u32ScreenWidth - Desired screen width setting
//! \param[in] u32ScreenHeight - Desired screen height setting
//!
//! This function sends commands to initialize the controller after it has
//! been taken out of reset.
//!
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED - This
//! controller does not support the given bitmap color type
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_SCREEN_SIZE - This
//! controller does not support the given screen dimensions
//!
////////////////////////////////////////////////////////////////////////////////
static RtStatus_t SendControllerInitSeq(gfx_BitmapTypeEnum_t eBitmapType,
uint32_t u32ScreenWidth, uint32_t u32ScreenHeight )
{
//Init command
WriteDirect(CMD_MODE, 0xAE); // Sleep mode on (display off)
WriteDirect(CMD_MODE, 0xA0); // Remap and color depth
WriteDirect(PARAM_MODE, stc_u8RemapAndColorByte); // 64k color, enable COM split odd even, scan from COM[N-1] to COM0
WriteDirect(CMD_MODE, 0xA1); // Display start line
WriteDirect(PARAM_MODE, 0x00);
WriteDirect(CMD_MODE, 0xA2); // Display offset
WriteDirect(PARAM_MODE, 0x00);
WriteDirect(CMD_MODE, 0xB0); // Set power saving mode
WriteDirect(PARAM_MODE, 0x00);
WriteDirect(CMD_MODE, 0xB1); // phase 1 and 2 period adjustment
WriteDirect(PARAM_MODE, 0x74);
#ifdef DDI_DISPLAY_CONTROLLER_SSD1332
WriteDirect(CMD_MODE, 0xA8); // Set multiplex ratio
WriteDirect(PARAM_MODE, 63);
WriteDirect(CMD_MODE, 0x87); // Master current control / attenuation
WriteDirect(PARAM_MODE, 0x09);
WriteDirect(CMD_MODE, 0x81); // Contrast for color A
WriteDirect(PARAM_MODE, 0xA0);
WriteDirect(CMD_MODE, 0x82); // Contrast for color B
WriteDirect(PARAM_MODE, 0x80);
WriteDirect(CMD_MODE, 0x83); // Contrast for color C
WriteDirect(PARAM_MODE, 0xC0);
WriteDirect(CMD_MODE, 0xBB); // Set pre-charge voltage of color A
WriteDirect(PARAM_MODE, 0x1F);
WriteDirect(CMD_MODE, 0xBC); // Set pre-charge voltage of color B
WriteDirect(PARAM_MODE, 0x0F);
WriteDirect(CMD_MODE, 0xBD); // Set pre-charge voltage of color C
WriteDirect(PARAM_MODE, 0x1F);
WriteDirect(CMD_MODE, 0xBE); // Set VCOMH
WriteDirect(PARAM_MODE, 0x3F);
WriteDirect(CMD_MODE, 0xB3); // Display clock divider / oscillator frequency
WriteDirect(PARAM_MODE, 0xB0);
#elif defined(DDI_DISPLAY_CONTROLLER_SSD1339)
WriteDirect(CMD_MODE, 0xCA); // Set multiplex ratio
WriteDirect(PARAM_MODE, 131);
WriteDirect(CMD_MODE, 0xc7); // Master current control / attenuation
WriteDirect(PARAM_MODE, 0x09);
WriteDirect(CMD_MODE, 0xc1); // Contrast for color A, B, and C
WriteDirect(PARAM_MODE, 0xA0);
WriteDirect(PARAM_MODE, 0x80);
WriteDirect(PARAM_MODE, 0xC0);
WriteDirect(CMD_MODE, 0xBB); // Set pre-charge voltage of color A, B, and C
WriteDirect(PARAM_MODE, 0x1F);
WriteDirect(PARAM_MODE, 0x0F);
WriteDirect(PARAM_MODE, 0x1F);
WriteDirect(CMD_MODE, 0xBE); // Set VCOMH
WriteDirect(PARAM_MODE, 0x3F);
WriteDirect(CMD_MODE, 0xB3); // Display clock divider / oscillator frequency
WriteDirect(PARAM_MODE, 0x90);
#endif
// The 32 commands after 0xB8 set the current drive pulse width of the gray scale level
WriteDirect(CMD_MODE, 0xB8);
WriteDirect(PARAM_MODE, 0x01);
WriteDirect(PARAM_MODE, 0x05);
WriteDirect(PARAM_MODE, 0x09);
WriteDirect(PARAM_MODE, 0x0D);
WriteDirect(PARAM_MODE, 0x11);
WriteDirect(PARAM_MODE, 0x15);
WriteDirect(PARAM_MODE, 0x19);
WriteDirect(PARAM_MODE, 0x1D);
WriteDirect(PARAM_MODE, 0x21);
WriteDirect(PARAM_MODE, 0x25);
WriteDirect(PARAM_MODE, 0x29);
WriteDirect(PARAM_MODE, 0x2D);
WriteDirect(PARAM_MODE, 0x31);
WriteDirect(PARAM_MODE, 0x35);
WriteDirect(PARAM_MODE, 0x39);
WriteDirect(PARAM_MODE, 0x3D);
WriteDirect(PARAM_MODE, 0x41);
WriteDirect(PARAM_MODE, 0x45);
WriteDirect(PARAM_MODE, 0x49);
WriteDirect(PARAM_MODE, 0x4D);
WriteDirect(PARAM_MODE, 0x51);
WriteDirect(PARAM_MODE, 0x55);
WriteDirect(PARAM_MODE, 0x59);
WriteDirect(PARAM_MODE, 0x5D);
WriteDirect(PARAM_MODE, 0x61);
WriteDirect(PARAM_MODE, 0x65);
WriteDirect(PARAM_MODE, 0x69);
WriteDirect(PARAM_MODE, 0x6D);
WriteDirect(PARAM_MODE, 0x71);
WriteDirect(PARAM_MODE, 0x75);
WriteDirect(PARAM_MODE, 0x79);
WriteDirect(PARAM_MODE, 0x7D);
WriteDirect(CMD_MODE, 0xA4); // Set display mode
WriteDirect(CMD_MODE, 0xAD); // Set master configuration
WriteDirect(CMD_MODE, 0x8E); // Select internal VP, internal VCOMH, external VCC supply
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -