📄 hal_misc.c
字号:
x2 = width - y1_save - 1;
y1 = x1_save / (32 / bpp);
y2 = x2_save / (32 / bpp) - 1;
break;
}
seWriteRegDword(REG_SUB_WIN_X_START_POS0, x1);
seWriteRegDword(REG_SUB_WIN_Y_START_POS0, y1);
seWriteRegDword(REG_SUB_WIN_X_END_POS0, x2);
seWriteRegDword(REG_SUB_WIN_Y_END_POS0, y2);
}
/*-------------------------------------------------------------------------*/
void seSetSubWinCoordinates(DWORD x1, DWORD y1, DWORD x2, DWORD y2)
{
if ((long) x1 < 0)
x1 = 0;
if ((long) x2 < 0)
x2 = 0;
if ((long) y1 < 0)
y1 = 0;
if ((long) y2 < 0)
y2 = 0;
_SubWin.x1 = x1;
_SubWin.y1 = y1;
_SubWin.x2 = x2;
_SubWin.y2 = y2;
_SetSubWinCoordinates(x1, y1, x2, y2);
}
/*-------------------------------------------------------------------------*/
void seGetSubWinCoordinates(DWORD *x1, DWORD *y1, DWORD *x2, DWORD *y2)
{
unsigned bpp;
DWORD tmp_x1, tmp_y1;
DWORD tmp_x2, tmp_y2;
int SwivelViewMode;
unsigned width, height;
seGetMainWinResolution(&width, &height);
SwivelViewMode = seGetSwivelViewMode();
bpp = seGetBitsPerPixel();
tmp_x1 = seReadRegDword(REG_SUB_WIN_X_START_POS0);
tmp_y1 = seReadRegDword(REG_SUB_WIN_Y_START_POS0);
tmp_x2 = seReadRegDword(REG_SUB_WIN_X_END_POS0) + 1;
tmp_y2 = seReadRegDword(REG_SUB_WIN_Y_END_POS0) + 1;
switch (SwivelViewMode)
{
case LANDSCAPE:
*x1 = tmp_x1 * 32 / bpp;
*y1 = tmp_y1;
*x2 = (tmp_x2 * 32 / bpp) - 1;
*y2 = tmp_y2 - 1;
break;
case ROTATE90:
*x1 = width - (tmp_y2 * 32 / bpp);
*y1 = tmp_x1;
*x2 = width - (tmp_y1 * 32 / bpp) - 1;
*y2 = tmp_x2 - 1;
break;
case ROTATE180:
*x1 = width - (tmp_x2 * 32 / bpp);
*y1 = height - tmp_y2;
*x2 = width - (tmp_x1 * 32 / bpp) - 1;
*y2 = height - tmp_y1 - 1;
break;
case ROTATE270:
*x1 = tmp_y1 * 32 / bpp;
*y1 = height - tmp_x2;
*x2 = (tmp_y2 * 32 / bpp) - 1;
*y2 = height - tmp_x1 - 1;
break;
}
}
/*-------------------------------------------------------------------------*/
int seGetResolution( unsigned *width, unsigned *height )
{
int DisplayMode;
DisplayMode = _ActiveImageSurface->DisplayMode;
if (DisplayMode & MAIN_WIN)
seGetMainWinResolution(width, height);
else if (DisplayMode & SUB_WIN)
seGetSubWinResolution(width, height);
else
{
*width = 0;
*height = 0;
return ERR_FAILED;
}
return ERR_OK;
}
/*-------------------------------------------------------------------------*/
//
// WARNING!!! _SetDtfdPowerSaveMode() delays by counting VNDP cycles. There must
// be a valid VNDP; otherwise this function will freeze the system.
//
static void _SetDtfdPowerSaveMode(BOOL enable)
{
unsigned regPwrSaveConfig;
DWORD time;
time = 0;
regPwrSaveConfig = seReadRegByte(REG_POWER_SAVE_CONFIG);
if (enable)
{
// Set GPIO5 low
seWriteRegByte(REG_GPIO_STATUS_CONTROL0, seReadRegByte(REG_GPIO_STATUS_CONTROL0) & ~0x20);
// Delay 4 frames
if (_HalInfo->wPanelFrameRate < 1)
_HalInfo->wPanelFrameRate = 1;
LcdPowerDelay(4000 / _HalInfo->wPanelFrameRate);
// Enable Power Save Mode
regPwrSaveConfig |= 0x01;
seWriteRegByte(REG_POWER_SAVE_CONFIG, regPwrSaveConfig);
// Set GPO low (GPO isn't actually power for the D-TFD)
LcdPower(FALSE);
}
else
{
// Set GPO high (GPO isn't actually power for the D-TFD)
LcdPower(TRUE);
// Clear Power Save Mode
seWriteRegByte(REG_POWER_SAVE_CONFIG, (BYTE) (regPwrSaveConfig & ~0x01));
// Delay 2 frames
if (_HalInfo->wPanelFrameRate < 1)
_HalInfo->wPanelFrameRate = 1;
LcdPowerDelay(2000 / _HalInfo->wPanelFrameRate);
// Set GPIO5 high
seWriteRegByte(REG_GPIO_STATUS_CONTROL0, seReadRegByte(REG_GPIO_STATUS_CONTROL0) | 0x20);
}
}
/*-------------------------------------------------------------------------*/
//
// WARNING!!! seSetPowerSaveMode() delays by counting VNDP cycles. There must
// be a valid VNDP; otherwise this function will freeze the system.
//
void seSetPowerSaveMode(BOOL enable)
{
unsigned regPwrSaveConfig;
DWORD time;
time = 0;
regPwrSaveConfig = seReadRegByte(REG_POWER_SAVE_CONFIG);
if ((seReadRegByte(REG_PANEL_TYPE) & 0x03) == 0x03) // D-TFD panel
{
_SetDtfdPowerSaveMode(enable);
}
else
{
if (enable)
{
//
// If the LCD is enabled, go through the power down sequence.
//
if (seReadRegByte(REG_GPIO_STATUS_CONTROL1) & 0x80) // Check if LCD power on
{
time = _HalInfo->wLcdPowerdownTime;
LcdPower(FALSE);
LcdPowerDelay(time);
}
regPwrSaveConfig |= 0x01;
seWriteRegByte(REG_POWER_SAVE_CONFIG, regPwrSaveConfig);
}
else
{
// Disable Power Save Mode
seWriteRegByte(REG_POWER_SAVE_CONFIG, (BYTE) (regPwrSaveConfig & ~0x01));
//
// If the LCD is enabled, go through the power up sequence.
//
if (!(seReadRegByte(REG_GPIO_STATUS_CONTROL1) & 0x80)) // Check if LCD power off
{
time = _HalInfo->wLcdPowerupTime;
LcdPowerDelay(time);
LcdPower(TRUE);
}
}
}
//
// Callback function to show when LcdPowerDelay() is called
//
if (pLcdPowersaveDelayMsg != NULL)
(*pLcdPowersaveDelayMsg)(enable, time);
}
/*-------------------------------------------------------------------------*/
BOOL seGetPowerSaveMode(void)
{
if (seReadRegByte(REG_POWER_SAVE_CONFIG) & 0x01)
return TRUE;
else
return FALSE;
}
/*-------------------------------------------------------------------------*/
void seCheckEndian(BOOL *ReverseBytes)
{
BYTE str[2];
WORD w = ENDIAN;
str[0] = ((BYTE *) &w)[0];
str[1] = ((BYTE *) &w)[1];
if ((str[0] == (REV_ENDIAN & 0xff)) &&
(str[1] == (REV_ENDIAN >> 8)))
*ReverseBytes = TRUE;
else
*ReverseBytes = FALSE;
}
/*-------------------------------------------------------------------------*/
// Time is in milliseconds
void seSetPowerUpDelay(WORD wLcdPowerupTime)
{
_HalInfo->wLcdPowerupTime = wLcdPowerupTime;
}
/*-------------------------------------------------------------------------*/
// Time is in milliseconds
void seSetPowerDownDelay(WORD wLcdPowerdownTime)
{
_HalInfo->wLcdPowerdownTime = wLcdPowerdownTime;
}
/*-------------------------------------------------------------------------*/
void _GetMclkAndPclk(DWORD *mclk, DWORD *pclk)
{
DWORD clki, clki2, bclk;
//
// In 90 and 270 degree SwivelView, MCLK must be >= 2 PCLK
//
clki = _HalInfo->dwClkI;
clki2 = _HalInfo->dwClkI2;
bclk = _HalInfo->dwBusClk;
*mclk = bclk / (((seReadRegByte(REG_BUSCLK_MEMCLK_CONFIG) >> 4) & 0x03) + 1);
switch (seReadRegByte(REG_PCLK_CONFIG) & 0x03)
{
case 0:
default:
*pclk = *mclk;
break;
case 1:
*pclk = bclk;
break;
case 2:
*pclk = clki;
break;
case 3:
*pclk = clki2;
break;
}
switch ((seReadRegByte(REG_PCLK_CONFIG) >> 4) & 0x07)
{
case 0:
break;
case 1:
*pclk /= 2;
break;
case 2:
*pclk /= 3;
break;
case 3:
*pclk /= 4;
break;
default:
*pclk /= 8;
}
}
/*-------------------------------------------------------------------------*/
int seCheckSwivelViewClocks(unsigned BitsPerPixel, unsigned SwivelViewMode)
{
DWORD mclk, pclk;
_GetMclkAndPclk(&mclk, &pclk);
switch (SwivelViewMode)
{
case LANDSCAPE:
case ROTATE180:
default:
switch (BitsPerPixel)
{
case 1:
if (mclk * 16 < pclk)
return ERR_SWIVELVIEW_CLOCK;
break;
case 2:
if (mclk * 8 < pclk)
return ERR_SWIVELVIEW_CLOCK;
break;
case 4:
if (mclk * 4 < pclk)
return ERR_SWIVELVIEW_CLOCK;
break;
case 8:
if (mclk * 2 < pclk)
return ERR_SWIVELVIEW_CLOCK;
break;
case 16:
default:
if (mclk < pclk)
return ERR_SWIVELVIEW_CLOCK;
break;
}
return ERR_OK;
break;
case ROTATE90:
case ROTATE270:
if (mclk < 2 * pclk)
return ERR_SWIVELVIEW_CLOCK;
else
return ERR_OK;
break;
}
}
/*-------------------------------------------------------------------------*/
int seSetSwivelViewMode(int rotate)
{
unsigned reg;
unsigned width, height;
unsigned offset;
unsigned nBitsPerPixel;
unsigned nPelsPerWord;
DWORD lLength;
//
// Change SwivelView mode
//
reg = seReadRegByte(REG_SPECIAL_EFFECTS) & ~0x03;
switch (rotate)
{
default:
case LANDSCAPE:
break;
case ROTATE90:
reg |= 0x01;
break;
case ROTATE180:
reg |= 0x02;
break;
case ROTATE270:
reg |= 0x03;
break;
}
seWriteRegByte(REG_SPECIAL_EFFECTS, reg);
seSetMainWinAsActiveSurface();
nBitsPerPixel = seGetBitsPerPixel();
seGetMainWinResolution(&width, &height);
width = _FixWidthForOffsetRegisters(width, nBitsPerPixel, &_MainWinSurface);
//
// Free Main Window memory
//
#ifdef LINEAR_ADDRESSES_SUPPORTED
if (_MainWinSurface.LinearAddress > 0)
seVmemFree(_MainWinSurface.LinearAddress);
#else
seVmemFree(_MainWinSurface.LinearAddress);
#endif
_MainWinSurface.OffsetAddress = 0;
_MainWinSurface.DisplayMemorySize = 0;
//
// Free Sub-Window memory
//
#ifdef LINEAR_ADDRESSES_SUPPORTED
if (_SubWinSurface.LinearAddress > 0)
seVmemFree(_SubWinSurface.LinearAddress);
#else
seVmemFree(_SubWinSurface.LinearAddress);
#endif
_SubWinSurface.LinearAddress = 0;
_SubWinSurface.OffsetAddress = 0;
_SubWinSurface.DisplayMemorySize = 0;
/*
** Allocate memory for the new mode.
*/
nPelsPerWord = 16 / nBitsPerPixel;
lLength = width * height / nPelsPerWord * 2; /* length in bytes */
_MainWinSurface.LinearAddress = seVmemAlloc(lLength);
#ifdef LINEAR_ADDRESSES_SUPPORTED
if (_MainWinSurface.LinearAddress == 0)
return ERR_NOT_ENOUGH_MEMORY;
#else
if (_MainWinSurface.LinearAddress == -1)
return ERR_NOT_ENOUGH_MEMORY;
#endif
_MainWinSurface.OffsetAddress = _MainWinSurface.LinearAddress - _DispLinearAddress;
_MainWinSurface.DisplayMemorySize = lLength;
/*--------------------------------------*/
/*
** Turn off the sub-window
*/
seWriteRegByte(REG_SPECIAL_EFFECTS, seReadRegByte(REG_SPECIAL_EFFECTS) & ~0x10);
/*--------------------------------------*/
//
// Update address offset registers
//
offset = width / (32 / nBitsPerPixel);
seWriteRegWord(REG_MAIN_WIN_ADDR_OFFSET0, offset);
/*--------------------------------------*/
//
// Update start address
//
seVirtPanScroll(0, 0);
/*--------------------------------------*/
#ifdef LINEAR_ADDRESSES_SUPPORTED
if (_ActiveImageSurface->LinearAddress == 0)
return ERR_NOT_ENOUGH_MEMORY;
#else
if (_ActiveImageSurface->LinearAddress == -1)
return ERR_NOT_ENOUGH_MEMORY;
#endif
return ERR_OK;
}
/*-------------------------------------------------------------------------*/
int seGetSwivelViewMode(void)
{
switch (seReadRegByte(REG_SPECIAL_EFFECTS) & 0x03)
{
case 0x00:
default:
return LANDSCAPE;
case 0x01:
return ROTATE90;
case 0x02:
return ROTATE180;
case 0x03:
return ROTATE270;
}
}
/*-------------------------------------------------------------------------*/
int seGetLcdOrientation(void)
{
return seGetSwivelViewMode();
}
/*-------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -