aboutsummaryrefslogtreecommitdiffstats
path: root/src/gdriver
diff options
context:
space:
mode:
Diffstat (limited to 'src/gdriver')
-rw-r--r--src/gdriver/gdriver_gdriver.c178
-rw-r--r--src/gdriver/sys_defs.h135
-rw-r--r--src/gdriver/sys_make.mk1
-rw-r--r--src/gdriver/sys_options.h32
-rw-r--r--src/gdriver/sys_rules.h23
5 files changed, 369 insertions, 0 deletions
diff --git a/src/gdriver/gdriver_gdriver.c b/src/gdriver/gdriver_gdriver.c
new file mode 100644
index 00000000..2c73719e
--- /dev/null
+++ b/src/gdriver/gdriver_gdriver.c
@@ -0,0 +1,178 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDRIVER
+
+#include "sys_defs.h"
+
+// Define the tables to hold the driver instances.
+static GDriver *dhead;
+
+// Definition that allows getting addresses of structures
+typedef const struct GDriverVMT const VMT_EL[1];
+
+// The system initialization.
+void _gdriverInit(void) {
+ #if GFX_USE_GDISP
+ {
+ // Both GDISP_CONTROLLER_LIST and GDISP_CONTROLLER_DISPLAYS are defined - create the required numbers of each controller
+ #if defined(GDISP_CONTROLLER_LIST) && defined(GDISP_CONTROLLER_DISPLAYS)
+ int i, cnt;
+
+
+ extern VMT_EL GDISP_CONTROLLER_LIST;
+ static const struct GDriverVMT const * dclist[GDISP_TOTAL_CONTROLLERS] = {GDISP_CONTROLLER_LIST};
+ static const unsigned dnlist[GDISP_TOTAL_CONTROLLERS] = {GDISP_CONTROLLER_DISPLAYS};
+ for(i = 0; i < GDISP_TOTAL_CONTROLLERS; i++) {
+ for(cnt = dnlist[i]; cnt; cnt--)
+ gdriverRegister(dclist[i]);
+ }
+
+ // Only GDISP_CONTROLLER_LIST is defined - create one of each controller
+ #elif defined(GDISP_CONTROLLER_LIST)
+ int i;
+
+
+ extern VMT_EL GDISP_CONTROLLER_LIST;
+ static const struct GDriverVMT const * dclist[GDISP_TOTAL_CONTROLLERS] = {GDISP_CONTROLLER_LIST};
+ for(i = 0; i < GDISP_TOTAL_CONTROLLERS; i++)
+ gdriverRegister(dclist[i]);
+
+ // Only GDISP_TOTAL_DISPLAYS is defined - create the required number of the one controller
+ #elif GDISP_TOTAL_DISPLAYS > 1
+ int cnt;
+
+ extern VMT_EL GDISPVMT_OnlyOne;
+ for(cnt = 0; cnt < GDISP_TOTAL_DISPLAYS; cnt++)
+ gdriverRegister(GDISPVMT_OnlyOne);
+
+ // One and only one display
+ #else
+ extern VMT_EL GDISPVMT_OnlyOne;
+ gdriverRegister(GDISPVMT_OnlyOne);
+ #endif
+ }
+ #endif
+
+ // Drivers not loaded yet
+ // GINPUT_NEED_MOUSE
+ // GINPUT_NEED_DIAL
+ // GINPUT_NEED_TOGGLE
+ // GINPUT_NEED_KEYBOARD
+ // GINPUT_NEED_STRING
+ // GFX_USE_GBLOCK
+}
+
+// The system de-initialization.
+void _gdriverDeinit(void) {
+ while(dhead)
+ gdriverUnRegister(dhead);
+}
+
+
+GDriver *gdriverRegister(const GDriverVMT *vmt) {
+ GDriver *pd;
+ GDriver *dtail;
+ int dinstance, sinstance;
+
+ // Loop to find the driver instance and the system instance numbers
+ dinstance = sinstance = 0;
+ for(pd = dhead; pd; dtail = pd, pd = pd->driverchain) {
+ if (pd->vmt == vmt)
+ dinstance++;
+ if (pd->vmt->type == vmt->type)
+ sinstance++;
+ }
+
+ // Get a new driver instance of the correct size and initialize it
+ pd = gfxAlloc(vmt->objsize);
+ if (!pd)
+ return 0;
+ pd->driverchain = 0;
+ pd->vmt = vmt;
+ if (vmt->init && !vmt->init(pd, dinstance, sinstance)) {
+ gfxFree(pd);
+ return 0;
+ }
+
+ // Add it to the driver chain
+ if (dhead)
+ dtail->driverchain = pd;
+ else
+ dhead = pd;
+
+ return pd;
+}
+
+void gdriverUnRegister(GDriver *driver) {
+ GDriver *pd;
+
+ // Safety
+ if (!driver)
+ return;
+
+ // Remove it from the list of drivers
+ if (dhead == driver)
+ dhead = driver->driverchain;
+ else {
+ for(pd = dhead; pd->driverchain; pd = pd->driverchain) {
+ if (pd->driverchain == driver) {
+ pd->driverchain = driver->driverchain;
+ break;
+ }
+ }
+ }
+
+ // Call the deinit()
+ if (driver->vmt->deinit)
+ driver->vmt->deinit(driver);
+
+ // Cleanup
+ gfxFree(driver);
+}
+
+GDriver *gdriverGetInstance(uint16_t type, int instance) {
+ GDriver *pd;
+ int sinstance;
+
+ // Loop to find the system instance
+ sinstance = 0;
+ for(pd = dhead; pd; pd = pd->driverchain) {
+ if (pd->vmt->type == type) {
+ if (sinstance == instance)
+ return pd;
+ sinstance++;
+ }
+ }
+ return 0;
+}
+
+int gdriverInstanceCount(uint16_t type) {
+ GDriver *pd;
+ int sinstance;
+
+ // Loop to count the system instances
+ sinstance = 0;
+ for(pd = dhead; pd; pd = pd->driverchain) {
+ if (pd->vmt->type == type)
+ sinstance++;
+ }
+ return sinstance;
+}
+
+GDriver *gdriverGetNext(uint16_t type, GDriver *driver) {
+ driver = driver ? driver->driverchain : dhead;
+
+ while(driver && driver->vmt->type != type)
+ driver = driver->driverchain;
+
+ return driver;
+}
+
+#endif /* GFX_USE_GDRIVER */
diff --git a/src/gdriver/sys_defs.h b/src/gdriver/sys_defs.h
new file mode 100644
index 00000000..c5ab9862
--- /dev/null
+++ b/src/gdriver/sys_defs.h
@@ -0,0 +1,135 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gdriver/sys_defs.h
+ *
+ * @addtogroup GINPUT
+ *
+ * @brief Module to support registering and unregistering of drivers
+ *
+ * @details GDRIVER provides a generalized way of defining and registering drivers.
+ *
+ * @note There are many different types of drivers and GDRIVER can handle any
+ * type of driver defined by the uGFX system.
+ *
+ * @note GDRIVER supports multiple drivers for one type of device. eg a SSD1289 LCD
+ * driver simultaneously with a framebuffer driver.
+ * @note GDRIVER supports multiple instances of a single driver. eg 2 SSD1289 LCD's.
+ * @note If there is only a single device of a particular type it will automatically
+ * register that device (it only needs to be included in the build, no special
+ * configuration is required)
+ * @note This module sys_defs.h file is NOT included in the general gfx.h file.
+ * Instead it is included in each driver type's driver API.
+ *
+ * @pre GFX_USE_GDRIVER must be set to TRUE in your gfxconf.h
+ *
+ * @{
+ */
+
+#ifndef _GDRIVER_H
+#define _GDRIVER_H
+
+#if GFX_USE_GDRIVER || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+#define GDRIVER_TYPE_DISPLAY 'g' // @< A graphics display
+#define GDRIVER_TYPE_MOUSE 'm' // @< A mouse
+#define GDRIVER_TYPE_TOUCH 'm' // @< A touch display (equivalent to a mouse)
+#define GDRIVER_TYPE_TOGGLE 't' // @< A toggle device eg GPIO pins, switches etc
+#define GDRIVER_TYPE_DIAL 'd' // @< A analog or digit dial (ranges in value from a minimum to a maximum)
+#define GDRIVER_TYPE_KEYBOARD 'k' // @< A keyboard
+#define GDRIVER_TYPE_BLOCK 'b' // @< A block device
+#define GDRIVER_TYPE_STRING 's' // @< A device that returns strings of data
+
+/**
+ * @brief All runtime driver structures start with this structure
+ *
+ * @note This structure (and any additional structure memory) is allocated
+ * dynamically by the system for each driver instance.
+ */
+typedef struct GDriver {
+ struct GDriver * driverchain;
+ const struct GDriverVMT * vmt;
+} GDriver;
+
+/**
+ * @brief All driver VMT's start with this structure.
+ */
+typedef struct GDriverVMT {
+ uint16_t type; // @< What type of driver this is
+ uint16_t flags; // @< Flags for the driver. Meaning is specific to each driver type.
+ uint32_t objsize; // @< How big the runtime driver structure is
+ bool_t (*init)(GDriver *driver, int driverinstance, int systeminstance); // @< Initialise the driver.
+ // driverinstance is the instance 0..n of this driver.
+ // systeminstance is the instance 0..n of this type of device.
+ void (*deinit)(GDriver *driver); // @< De-initialise the driver
+} GDriverVMT;
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /**
+ * @brief Register a new driver instance.
+ * @return The runtime driver structure or NULL if it fails.
+ *
+ * @param[in] vmt The driver's vmt
+ */
+ GDriver *gdriverRegister(const GDriverVMT *vmt);
+
+ /**
+ * @brief UnRegister a driver instance.
+ *
+ * @param[in] driver The driver instance's runtime structure
+ */
+ void gdriverUnRegister(GDriver *driver);
+
+ /**
+ * @brief Get the driver for a particular instance of a type of device
+ * @return The runtime driver structure or NULL if it fails.
+ *
+ * @param[in] type The type of driver to find
+ * @param[in] instance The instance (0..n) to find
+ */
+ GDriver *gdriverGetInstance(uint16_t type, int instance);
+
+ /**
+ * @brief Get the count of instances of a type of device
+ * @return The instance count.
+ *
+ * @note Valid instance numbers are then 0 .. count-1
+ *
+ * @param[in] type The type of driver to find
+ */
+ int gdriverInstanceCount(uint16_t type);
+
+ /**
+ * @brief Get the next driver for a type of device
+ * @return The runtime driver structure or NULL if there are no more.
+ *
+ * @param[in] type The type of driver to find
+ * @param[in] driver The last driver returned or NULL to start again
+ */
+ GDriver *gdriverGetNext(uint16_t type, GDriver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_GDRIVER */
+
+#endif /* _GDRIVER_H */
+/** @} */
+
diff --git a/src/gdriver/sys_make.mk b/src/gdriver/sys_make.mk
new file mode 100644
index 00000000..93810aa9
--- /dev/null
+++ b/src/gdriver/sys_make.mk
@@ -0,0 +1 @@
+GFXSRC += $(GFXLIB)/src/gdriver/gdriver_gdriver.c
diff --git a/src/gdriver/sys_options.h b/src/gdriver/sys_options.h
new file mode 100644
index 00000000..bef0a95a
--- /dev/null
+++ b/src/gdriver/sys_options.h
@@ -0,0 +1,32 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gdriver/sys_options.h
+ * @brief GDRIVER - Driver options header file.
+ *
+ * @addtogroup GDRIVER
+ * @{
+ */
+
+#ifndef _GDRIVER_OPTIONS_H
+#define _GDRIVER_OPTIONS_H
+
+/**
+ * @name GDRIVER Functionality to be included
+ * @{
+ */
+/**
+ * @}
+ *
+ * @name GDRIVER Optional Parameters
+ * @{
+ */
+/** @} */
+
+#endif /* _GDRIVER_OPTIONS_H */
+/** @} */
diff --git a/src/gdriver/sys_rules.h b/src/gdriver/sys_rules.h
new file mode 100644
index 00000000..596babba
--- /dev/null
+++ b/src/gdriver/sys_rules.h
@@ -0,0 +1,23 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gdriver/sys_rules.h
+ * @brief GDRIVER safety rules header file.
+ *
+ * @addtogroup GFILE
+ * @{
+ */
+
+#ifndef _GDRIVER_RULES_H
+#define _GDRIVER_RULES_H
+
+#if GFX_USE_GDRIVER
+#endif
+
+#endif /* _GDRIVER_RULES_H */
+/** @} */