【AT91SAM3S】SAM3S-EK Demo工程中,LCD驱动程序的加载(函数指针结构体)

为了调试LCD,在英倍特的板子上烧Atmel的sam3s-ek_demo_1.4_source示例代码.LCD显示正常了,却找不到LCD的驱动究竟在哪。

花了好久,追踪到了这个执行过程。

进入main函数--_SetupHardware()----DISP_Initialize() ----_aDISP_Backends[DISP_BACKEND_ILI9325]=&sDISP_Backend_ILI9325 ;

static __no_init SDISPBackend* _aDISP_Backends[DISP_BACKEND_MAX] ;

_aDISP_Backends[DISP_BACKEND_ILI9325]=&sDISP_Backend_ILI9325 ;

 

然后就是结构体:

SDISPBackend是一个函数指针结构体。其定义是这样的:

typedef struct _SDISPBackendData
{
uint32_t dwID ;
uint32_t dwOrientation ; // Portrait, Landscape
uint32_t dwMode ; // RGB, BGR
} sDISPBackendData ;

typedef struct _SDISPBackend
{
sDISPBackendData sData ;

uint32_t (*Reset)( void ) ;
uint32_t (*Initialize)( void ) ;
uint32_t (*GetPixel)( uint32_t dwX, uint32_t dwY, SGUIColor* pclrResult ) ;
uint32_t (*DrawPixel)( uint32_t dwX, uint32_t dwY, SGUIColor* pclrIn ) ;
uint32_t (*DrawLine)( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2, SGUIColor* pclrIn ) ;
uint32_t (*DrawCircle)( uint32_t dwX, uint32_t dwY, uint32_t dwRadius, SGUIColor* pclrBorder ) ;
uint32_t (*DrawFilledCircle)( uint32_t dwX, uint32_t dwY, uint32_t dwRadius, SGUIColor* pclrBorder, SGUIColor* pclrInside ) ;
uint32_t (*DrawRectangle)( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2, SGUIColor* pclrFrame ) ;
uint32_t (*DrawFilledRectangle)( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2, SGUIColor* pclrFrame, SGUIColor* pclrInside ) ;
uint32_t (*DrawBitmap)( uint32_t dwX, uint32_t dwY, uint32_t dwWidth, uint32_t dwHeight, uint8_t* pucData ) ;
uint32_t (*DrawText)( uint32_t dwX, uint32_t dwY, uint8_t* pszText, SGUIColor* pclrText, SGUIFont* pFont, uint32_t dwSize ) ;
uint32_t (*Fill)( uint32_t dwX, uint32_t dwY, SGUIColor* pclrIn ) ;
uint32_t (*IOCtl)( uint32_t dwCommand, uint32_t* pdwValue, uint32_t* pdwValueLength ) ;
} SDISPBackend ;

使用下面这个函数将后端的代码跟前端的使用映射在一起:

SDISPBackend sDISP_Backend_ILI9325=
{
    .sData=
    {
        .dwID=DISP_BACKEND_ILI9325,
    },

    .Reset=_DBE_ILI9325_Reset,
    .Initialize=_DBE_ILI9325_Initialize,
    .GetPixel=_DBE_ILI9325_GetPixel,
    .DrawPixel=_DBE_ILI9325_DrawPixel,
    .DrawLine=_DBE_ILI9325_DrawLine,
    .DrawCircle=_DBE_ILI9325_DrawCircle,
    .DrawFilledCircle=_DBE_ILI9325_DrawFilledCircle,
    .DrawRectangle=_DBE_ILI9325_DrawRectangle,
    .DrawFilledRectangle=_DBE_ILI9325_DrawFilledRectangle,
    .DrawBitmap=_DBE_ILI9325_DrawBitmap,
    .DrawText=_DBE_ILI9325_DrawText,
    .Fill=NULL,
    .IOCtl=_DBE_ILI9325_IOCtl
} ;
使用时,直接调用sDISP_Backend_ILI9325.Initialize之类的函数就可以了。

感叹:C语言用到这个地步,已远非我所能够模仿的了。

你可能感兴趣的:(demo)