display.c

Go to the documentation of this file.
00001 /***************************************************************************/
00018 #include <stdint.h>
00019 #include <stdbool.h>
00020 #include <string.h>
00021 
00022 #include "displayconfigall.h"
00023 #include "display.h"
00024 #include "displaybackend.h"
00025 
00026 
00029 /*******************************************************************************
00030  ********************************  STATICS  ************************************
00031  ******************************************************************************/
00032 
00033 /* Table of display devices. */
00034 static DISPLAY_Device_t deviceTable[DISPLAY_DEVICES_MAX];
00035 
00036 /* This variable keeps track of whether the DISPLAY module is initialized
00037    or not. */
00038 static bool moduleInitialized = false;
00039 
00040 /* This variable keeps track of the number of devices that have been
00041     registered. */
00042 static int devicesRegistered=0;
00043 
00044 /*
00045  * Table of display device driver initialization functions to be called in
00046  * DISPLAY_Init, the DISPLAY module init function.
00047  */
00048 static pDisplayDeviceDriverInitFunction_t pDisplayDeviceDriverInitFunctions[] =
00049   DISPLAY_DEVICE_DRIVER_INIT_FUNCTIONS;
00050 
00054 /*******************************************************************************
00055  **************************     GLOBAL FUNCTIONS      **************************
00056  ******************************************************************************/
00057 
00058 /***************************************************************************/
00064 EMSTATUS DISPLAY_Init (void)
00065 {
00066   EMSTATUS status;
00067 
00068   pDisplayDeviceDriverInitFunction_t* pDisplayDeviceDriverInitFunction =
00069     pDisplayDeviceDriverInitFunctions;
00070 
00071   if (false == moduleInitialized)
00072   {
00073     moduleInitialized = true;
00074     for (; *pDisplayDeviceDriverInitFunction; pDisplayDeviceDriverInitFunction++)
00075     {
00076       status = (*pDisplayDeviceDriverInitFunction)();
00077       if (DISPLAY_EMSTATUS_OK != status)
00078         return status;
00079     }
00080   }
00081 
00082   return DISPLAY_EMSTATUS_OK;
00083 }
00084 
00085 
00086 /***************************************************************************/
00097 EMSTATUS DISPLAY_DriverRefresh (void)
00098 {
00099   int        i;
00100   EMSTATUS status = DISPLAY_EMSTATUS_OK;
00101 
00102   if (false == moduleInitialized)
00103   {
00104     status = DISPLAY_EMSTATUS_NOT_INITIALIZED;
00105   }
00106   else
00107   {
00108     for (i=0; i<devicesRegistered; i++)
00109     {
00110       if (deviceTable[i].pDriverRefresh)
00111       {
00112         status = (*deviceTable[i].pDriverRefresh)(&deviceTable[i]);
00113         if (DISPLAY_EMSTATUS_OK != status)
00114         {
00115           return status;
00116         }
00117       }
00118     }
00119   }
00120 
00121   return status;
00122 }
00123 
00124 
00125 /***************************************************************************/
00139 EMSTATUS DISPLAY_DeviceGet(int                displayDeviceNo,
00140                            DISPLAY_Device_t*  device)
00141 {
00142   EMSTATUS status;
00143 
00144   if (false == moduleInitialized)
00145   {
00146     status = DISPLAY_EMSTATUS_NOT_INITIALIZED;
00147   }
00148   else
00149   {
00150     if (displayDeviceNo < DISPLAY_DEVICES_MAX)
00151     {
00152       memcpy(device, &deviceTable[displayDeviceNo], sizeof(DISPLAY_Device_t));
00153       status = DISPLAY_EMSTATUS_OK;
00154     }
00155     else
00156     {
00157       status = DISPLAY_EMSTATUS_OUT_OF_RANGE;
00158     }
00159   }
00160   return status;
00161 }
00162 
00163 
00164 /**************************************************************************/
00172 EMSTATUS DISPLAY_DeviceRegister(DISPLAY_Device_t *device)
00173 {
00174   EMSTATUS status;
00175 
00176   if (false == moduleInitialized)
00177   {
00178     status = DISPLAY_EMSTATUS_NOT_INITIALIZED;
00179   }
00180   else
00181   {
00182     if (devicesRegistered < DISPLAY_DEVICES_MAX)
00183     {
00184       memcpy(&deviceTable[devicesRegistered++], device, sizeof(DISPLAY_Device_t));
00185       status = DISPLAY_EMSTATUS_OK;
00186     }
00187     else
00188     {
00189       status = DISPLAY_EMSTATUS_NOT_ENOUGH_MEMORY;
00190     }
00191   }
00192   return status;
00193 }
00194 
00195 
00196 /***************  THE REST OF THE FILE IS DOCUMENTATION ONLY !  ***************/
00197 
00198 /*******************************************************************************
00199  **************************       DOCUMENTATION       **************************
00200  ******************************************************************************/
00201 
00202 /***************************************************************************/