📄 lcdmem.c
字号:
/*
*********************************************************************************************************
* uC/GUI V3.98
* Universal graphic software for embedded applications
*
* (c) Copyright 2002, Micrium Inc., Weston, FL
* (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
* 礐/GUI is protected by international copyright laws. Knowledge of the
* source code may not be used to write a similar product. This file may
* only be used in accordance with a license and should not be redistributed
* in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File : LCDMem.C
Purpose : Driver for LCDs using internal memory
----------------------------------------------------------------------
Version-Date---Author-Explanation
----------------------------------------------------------------------
2.00c 030718 JE a) 1bpp bitmaps optimized
2.00b 030122 JE a) Multi display support added
2.00a 010926 JE a) Reworked to work with LCD_MIRROR_...
and LCD_SWAP_XY
2.00 010402 RS a) LCD_GetDevCaps removed from driver
(now LCD.c)
1.00.04 990930 RS Prototyp changed for LCD_Init()
1.00.03 990927 RS Config defaults added
1.00.02 990925 RS Bugfix for transparent 4 color bitmaps
1.00.01 990920 RS Bugfix for DrawHline
1.00 990823 RS Xor accelerated.
0.00 990118 RS First release.
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
None.
---------------------------END-OF-HEADER------------------------------
*/
#include <string.h> /* for memset */
#include <stddef.h> /* needed for definition of NULL */
#include "LCD_Private.h" /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"
#if ((LCD_CONTROLLER == 0) && ((LCD_FIXEDPALETTE==2) | (LCD_FIXEDPALETTE==1)) ) \
&& (!defined(WIN32) | defined(LCD_SIMCONTROLLER))
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#if defined(WIN32)
#if (LCD_DISPLAY_INDEX > 0)
#if LCD_DISPLAY_INDEX == 1
void SIMMEM_On_1(void);
void SIMMEM_Off_1(void);
#define LCD_L0_1_On SIMMEM_On_1
#define LCD_L0_1_Off SIMMEM_Off_1
#elif LCD_DISPLAY_INDEX == 2
void SIMMEM_On_2(void);
void SIMMEM_Off_2(void);
#define LCD_L0_2_On SIMMEM_On_2
#define LCD_L0_2_Off SIMMEM_Off_2
#elif LCD_DISPLAY_INDEX == 3
void SIMMEM_On_3(void);
void SIMMEM_Off_3(void);
#define LCD_L0_3_On SIMMEM_On_3
#define LCD_L0_3_Off SIMMEM_Off_3
#elif LCD_DISPLAY_INDEX == 4
void SIMMEM_On_4(void);
void SIMMEM_Off_4(void);
#define LCD_L0_4_On SIMMEM_On_4
#define LCD_L0_4_Off SIMMEM_Off_4
#else
#error Not supported yet!
#endif
#endif
#endif
#if (GUI_NUM_LAYERS > 1)
#if LCD_DISPLAY_INDEX == 1
#define LCD_VRam LCD_VRam_1
#define LCD__apVRam LCD__apVRam_1
#define LCD_L0_Off LCD_L0_1_Off
#define LCD_L0_On LCD_L0_1_On
#define LCD__aTimerReload LCD__aTimerReload_1
#define LCD__BitsPerPixel LCD__BitsPerPixel_1
#elif LCD_DISPLAY_INDEX == 2
#define LCD_VRam LCD_VRam_2
#define LCD__apVRam LCD__apVRam_2
#define LCD_L0_Off LCD_L0_2_Off
#define LCD_L0_On LCD_L0_2_On
#define LCD__aTimerReload LCD__aTimerReload_2
#define LCD__BitsPerPixel LCD__BitsPerPixel_2
#elif LCD_DISPLAY_INDEX == 3
#define LCD_VRam LCD_VRam_3
#define LCD__apVRam LCD__apVRam_3
#define LCD_L0_Off LCD_L0_3_Off
#define LCD_L0_On LCD_L0_3_On
#define LCD__aTimerReload LCD__aTimerReload_3
#define LCD__BitsPerPixel LCD__BitsPerPixel_3
#elif LCD_DISPLAY_INDEX == 4
#define LCD_VRam LCD_VRam_4
#define LCD__apVRam LCD__apVRam_4
#define LCD_L0_Off LCD_L0_4_Off
#define LCD_L0_On LCD_L0_4_On
#define LCD__aTimerReload LCD__aTimerReload_4
#define LCD__BitsPerPixel LCD__BitsPerPixel_4
#endif
#endif
#define LCD_BYTESPERLINE (((LCD_VXSIZE_PHYS)+7)/8)
#ifndef LCD_VRAMTYPE
#define LCD_VRAMTYPE
#endif
#ifdef WIN32
#undef LCD_VRAMTYPE
#define LCD_VRAMTYPE
#endif
/*********************************************************************
*
* Defaults for configuration
*
* Please be aware that not all configuration errors can be captured !
*/
#ifndef LCD_NUM_EMPTY_LINES
#define LCD_NUM_EMPTY_LINES 0
#endif
#ifndef LCD_REVERSEMODE_SUPPORT
#define LCD_REVERSEMODE_SUPPORT (1)
#endif
#ifndef LCD_VERIFY
#define LCD_VERIFY (0)
#endif
#ifndef LCD_REVERSEMODE_SUPPORT
#define LCD_REVERSEMODE_SUPPORT (0)
#endif
#ifndef LCD_SUPPORT_VERIFY
#define LCD_SUPPORT_VERIFY (0)
#endif
/* If disabled, selected drawmode is ignored.
==> XOR, REVERSE drawing not supported */
#ifndef LCD_SUPPORT_DRAWMODE
#define LCD_SUPPORT_DRAWMODE (1)
#endif
/* Switch support for the LCD_On, LCD_Off functions of the driver */
#ifndef LCD_SUPPORT_ONOFF
#define LCD_SUPPORT_ONOFF (1)
#endif
/* Switch for support of multiple pages.
Only available with certain LCD-controllers */
#ifndef LCD_SUPPORT_PAGING
#define LCD_SUPPORT_PAGING (0)
#endif
/* Switch for support of run-time inversion of display. */
#ifndef LCD_SUPPORT_REVERSEMODE
#define LCD_SUPPORT_REVERSEMODE (0)
#endif
/* Switch support for the LCD_SetOrg function of the driver */
#ifndef LCD_SUPPORT_SETORG
#define LCD_SUPPORT_SETORG (1)
#endif
#ifndef LCD_SUPPORT_PALETTE
#define LCD_SUPPORT_PALETTE (1)
#endif
/*********************************************************************
*
* Support for Segment/COMLUTs
*/
/* For compatibility with older configs, define defaults */
#ifndef LCD_SUPPORT_COMTRANS
#define LCD_SUPPORT_COMTRANS 0
#endif
#ifndef LCD_SUPPORT_SEGTRANS
#define LCD_SUPPORT_SEGTRANS 0
#endif
#if LCD_SUPPORT_COMTRANS
extern U8 LCD__aLine2Com0[LCD_LASTCOM0-LCD_FIRSTCOM0+1];
#endif
#if LCD_SUPPORT_SEGTRANS
extern U8 LCD__aRow2Seg0[LCD_LASTSEG0-LCD_FIRSTSEG0+1];
#endif
/*********************************************************************
*
* Macro calculations
*/
/* Define number of used coms/segments per controller */
#define LCD_NUM_SEGS0 (LCD_LASTSEG0-LCD_FIRSTSEG0+1)
#define LCD_NUM_COMS0 (LCD_LASTCOM0-LCD_FIRSTCOM0+1)
/* Define total number of used coms/segments */
#define LCD_NUM_SEGS LCD_NUM_SEGS0
#define LCD_NUM_COMS LCD_NUM_COMS0
#define LCD_MEMSIZE LCD_VXSIZE_PHYS*(LCD_VYSIZE_PHYS+LCD_NUM_EMPTY_LINES)
/*********************************************************************
*
* Configuration switch checking
*
* Please be aware that not all configuration errors can be captured !
*/
#if (LCD_BITSPERPIXEL != 2) & (LCD_BITSPERPIXEL != 1)
#error this value for LCD_BITSPERPIXEL not yet supported
#endif
/* Check if number of segments / coms equals resolution */
/*
#if (LCD_NUM_SEGS < LCD_XSIZE_PHYS)
#error Please check segment setup of controller 0 and X/YSIZE !!!
#endif
#if (LCD_NUM_COMS < LCD_YSIZE_PHYS)
#error Please check com setup of controller 0 and X/YSIZE !!!
#endif
*/
/*********************************************************************
*
* EXPORTs for ISR
*/
#ifndef LCD_TIMERINIT1
#define LCD_TIMERINIT1 1599
#endif
#ifndef LCD_TIMERINIT0
#define LCD_TIMERINIT0 1065
#endif
U16 LCD__BitsPerPixel = LCD_BITSPERPIXEL;
LCD_VRAMTYPE U8 LCD_VRAMTYPE* LCD__apVRam[LCD_BITSPERPIXEL];
LCD_VRAMTYPE U16 LCD__aTimerReload[LCD_BITSPERPIXEL] = {
LCD_TIMERINIT0
#if LCD_BITSPERPIXEL > 1
,LCD_TIMERINIT1
#endif
};
/*********************************************************************
*
* ID translation table
*
* This table contains 0, 1, 2, ... and serves as translation table for DDBs
*/
#define INTS(Base) Base+0,Base+1,Base+2,Base+3,Base+4,Base+5, \
Base+6,Base+7,Base+8,Base+9,Base+10,Base+11, \
Base+12,Base+13,Base+14,Base+15
static const LCD_PIXELINDEX aID[] = {
INTS(0),
#if LCD_MAX_LOG_COLORS > 0x10
INTS(0x10),
#endif
#if LCD_MAX_LOG_COLORS > 0x20
INTS(0x20),
INTS(0x30),
#endif
};
/*********************************************************************
*
* Macros for internal use
*/
#if (LCD_SUPPORT_COMTRANS)
#if (LCD_MIRROR_Y)
#error LCD_MIRROR_Y not supported with COMTrans !
#endif
#if (LCD_MIRROR_X)
#error LCD_MIRROR_X not supported with COMTrans !
#endif
#endif
#if (!LCD_SUPPORT_COMTRANS && !LCD_SUPPORT_SEGTRANS)
#if (!LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
#define SETPIXEL(x, y, c) SETPIXELPHYS((x), (y), (c))
#define SETPIXELFAST(x, y, c) SETPIXELPHYS((x), (y), (c))
#define GETPIXEL(x, y) _GetPixel ((x), (y))
#define XORPIXEL(x, y) _XorPixel ((x), (y))
#elif (!LCD_MIRROR_X && !LCD_MIRROR_Y && LCD_SWAP_XY)
#define SETPIXEL(x, y, c) SETPIXELPHYS((y), (x), (c))
#define GETPIXEL(x, y) _GetPixel ((y), (x))
#define XORPIXEL(x, y) _XorPixel ((y), (x))
#elif (!LCD_MIRROR_X && LCD_MIRROR_Y && !LCD_SWAP_XY)
#define SETPIXEL(x, y, c) SETPIXELPHYS((x), (LCD_YSIZE-1-(y)), (c))
#define SETPIXELFAST(x, y, c) SETPIXELPHYS((x), (LCD_YSIZE-1-(y)), (c))
#define GETPIXEL(x, y) _GetPixel ((x), (LCD_YSIZE-1-(y)))
#define XORPIXEL(x, y) _XorPixel ((x), (LCD_YSIZE-1-(y)))
#elif (!LCD_MIRROR_X && LCD_MIRROR_Y && LCD_SWAP_XY)
#define SETPIXEL(x, y, c) SETPIXELPHYS((y), (LCD_XSIZE-1-(x)), (c))
#define GETPIXEL(x, y) _GetPixel ((y), (LCD_XSIZE-1-(x)))
#define XORPIXEL(x, y) _XorPixel ((y), (LCD_XSIZE-1-(x)))
#elif ( LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
#define SETPIXEL(x, y, c) SETPIXELPHYS((LCD_XSIZE-1-(x)), (y), (c))
#define SETPIXELFAST(x, y, c) SETPIXELPHYS((LCD_XSIZE-1-(x)), (y), (c))
#define GETPIXEL(x, y) _GetPixel ((LCD_XSIZE-1-(x)), (y))
#define XORPIXEL(x, y) _XorPixel ((LCD_XSIZE-1-(x)), (y))
#elif ( LCD_MIRROR_X && !LCD_MIRROR_Y && LCD_SWAP_XY)
#define SETPIXEL(x, y, c) SETPIXELPHYS((LCD_YSIZE-1-(y)), (x), (c))
#define GETPIXEL(x, y) _GetPixel ((LCD_YSIZE-1-(y)), (x))
#define XORPIXEL(x, y) _XorPixel ((LCD_YSIZE-1-(y)), (x))
#elif ( LCD_MIRROR_X && LCD_MIRROR_Y && !LCD_SWAP_XY)
#define SETPIXEL(x, y, c) SETPIXELPHYS((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)), (c))
#define SETPIXELFAST(x, y, c) SETPIXELPHYS((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)), (c))
#define GETPIXEL(x, y) _GetPixel ((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)))
#define XORPIXEL(x, y) _XorPixel ((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)))
#elif ( LCD_MIRROR_X && LCD_MIRROR_Y && LCD_SWAP_XY)
#error This combination of mirroring/swapping not yet supported
#endif
#elif (LCD_SUPPORT_COMTRANS && !LCD_SUPPORT_SEGTRANS)
#if (!LCD_SWAP_XY)
#define SETPIXEL(x, y, c) _SetPixelPhys(x,LCD__aLine2Com0[y], c)
#define SETPIXELFAST(x, y, c) SETPIXELPHYS(x,LCD__aLine2Com0[y], c)
#define GETPIXEL(x, y) _GetPixel(x,LCD__aLine2Com0[y])
#define XORPIXEL(x, y) _XorPixel(x,LCD__aLine2Com0[y])
#else
#define SETPIXEL(x, y, c) _SetPixelPhys(y,LCD__aLine2Com0[x], c)
#define SETPIXELFAST(x, y, c) SETPIXELPHYS(y,LCD__aLine2Com0[x], c)
#define GETPIXEL(x, y) _GetPixel(y,LCD__aLine2Com0[x])
#define XORPIXEL(x, y) _XorPixel(y,LCD__aLine2Com0[x])
#endif
#else
#error This combination of switches not yet supported
#endif
/*********************************************************************
*
* Set pixel macros
*/
#if LCD_BITSPERPIXEL == 1
#define SETPIXELPHYS(x,y,c) \
{ \
unsigned int Off = y*LCD_BYTESPERLINE+((x)>>3); \
U8 Data = 0x80>>((x)&7); \
if (c&1) LCD_VRam[0][Off] |= Data; \
else LCD_VRam[0][Off] &= ~Data; \
}
#elif LCD_BITSPERPIXEL == 2
#define SETPIXELPHYS(x,y,c) \
{ \
unsigned int Off = y*LCD_BYTESPERLINE+((x)>>3); \
U8 Data = 0x80>>((x)&7); \
if (c&1) LCD_VRam[0][Off] |= Data; \
else LCD_VRam[0][Off] &= ~Data; \
if (c&2) LCD_VRam[1][Off] |= Data; \
else LCD_VRam[1][Off] &= ~Data; \
}
#else
#error unsupported Configuration
#endif
#define PIXELCOLOR U8
#define BKCOLOR LCD_BKCOLORINDEX
#define COLOR LCD_COLORINDEX
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
LCD_VRAMTYPE U8 LCD_VRam[LCD_BITSPERPIXEL][LCD_VYSIZE_PHYS * LCD_BYTESPERLINE];
#if (!LCD_SWAP_XY)
static const U8 aMask[] = {255,127,63,31,15,7,3,1,0};
#endif
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _SetPixelPhys
*/
static void _SetPixelPhys(int x, int y, PIXELCOLOR c) {
SETPIXELPHYS(x,y,c);
}
/*********************************************************************
*
* _GetPixel
*/
static U8 _GetPixel(int x, int y) {
#if LCD_BITSPERPIXEL == 1
unsigned int Off = y*LCD_BYTESPERLINE+(x>>3);
U8 Data = (LCD_VRam[0][Off] >> (7-(x&7))) &1;
return Data;
#elif LCD_BITSPERPIXEL == 2
unsigned int Off = y*LCD_BYTESPERLINE+(x>>3);
U8 Data = (LCD_VRam[0][Off] >> (7-(x&7))) &1;
Data |= ((LCD_VRam[1][Off] >> (7-(x&7)))<<1) &2;
return Data;
#else
#error Colordepth not supported by this driver !
#endif
}
/*********************************************************************
*
* _XorPixel
*/
static void _XorPixel (int x, int y) {
PIXELCOLOR Index = _GetPixel(x,y);
Index = LCD_NUM_COLORS-1-Index;
_SetPixelPhys(x,y,Index);
}
/*********************************************************************
*
* _DrawBitLine1BPP (optimized)
*/
#if (!LCD_MIRROR_X) && \
(!LCD_MIRROR_Y) && \
(!LCD_SWAP_XY) && \
(LCD_BITSPERPIXEL == 1)
/*********************************************************************
*
* _DrawBitMap1BPP
*/
static void _DrawBitMap1BPP(int x0, int y, U8 const GUI_UNI_PTR * p0, int Diff0, int xsize, int ysize, int BytesPerLine) {
U8 * pVRam = &LCD_VRam[0][y * LCD_BYTESPERLINE + ((x0) >> 3)];
int x1 = x0 + xsize - 1;
U8 Mask0 = 0xff >> (x0 &7);
U8 EndMask = 0xff80 >> (x1&7);
int NumBytes0 = (x1 >> 3) - (x0 >> 3);
U8 * pVRam0 = pVRam;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -