From fa8167b94d13e94a6cb953e7f549a89f155f77c6 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 21 Jan 2015 17:26:24 +1000 Subject: Big file rename to reduce problems with brain-dead IDE's that don't handle project file hierarchies well. Naming is more consistent with the new scheme. May affect some third party drivers (header file renames). --- src/gdriver/gdriver.c | 148 +++++++++++++++++++++++++++++++++++++++ src/gdriver/gdriver.h | 159 ++++++++++++++++++++++++++++++++++++++++++ src/gdriver/gdriver.mk | 1 + src/gdriver/gdriver_gdriver.c | 148 --------------------------------------- src/gdriver/gdriver_options.h | 32 +++++++++ src/gdriver/gdriver_rules.h | 23 ++++++ src/gdriver/sys_defs.h | 159 ------------------------------------------ src/gdriver/sys_make.mk | 1 - src/gdriver/sys_options.h | 32 --------- src/gdriver/sys_rules.h | 23 ------ 10 files changed, 363 insertions(+), 363 deletions(-) create mode 100644 src/gdriver/gdriver.c create mode 100644 src/gdriver/gdriver.h create mode 100644 src/gdriver/gdriver.mk delete mode 100644 src/gdriver/gdriver_gdriver.c create mode 100644 src/gdriver/gdriver_options.h create mode 100644 src/gdriver/gdriver_rules.h delete mode 100644 src/gdriver/sys_defs.h delete mode 100644 src/gdriver/sys_make.mk delete mode 100644 src/gdriver/sys_options.h delete mode 100644 src/gdriver/sys_rules.h (limited to 'src/gdriver') diff --git a/src/gdriver/gdriver.c b/src/gdriver/gdriver.c new file mode 100644 index 00000000..d0324639 --- /dev/null +++ b/src/gdriver/gdriver.c @@ -0,0 +1,148 @@ +/* + * 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 "gdriver.h" + +#include // For memset + +// Define the tables to hold the driver instances. +static GDriver *dhead; +static GDriver *dtail; + +// The system initialization. +void _gdriverInit(void) { +} + +// The system de-initialization. +void _gdriverDeinit(void) { + while(dhead) + gdriverUnRegister(dhead); +} + + +GDriver *gdriverRegister(const GDriverVMT *vmt, void *param) { + GDriver * pd; + unsigned dinstance, sinstance; + + // Loop to find the driver instance and the system instance numbers + dinstance = sinstance = 0; + for(pd = dhead; 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; + memset(pd, 0, vmt->objsize); + pd->vmt = vmt; + if (vmt->init && !vmt->init(pd, param, dinstance, sinstance)) { + gfxFree(pd); + return 0; + } + + // Add it to the driver chain + if (dhead) + dtail->driverchain = pd; + else + dhead = dtail = pd; + + // Do the post init + if (vmt->postinit) + vmt->postinit(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, unsigned instance) { + GDriver *pd; + unsigned 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; +} + +unsigned gdriverInstanceCount(uint16_t type) { + GDriver *pd; + unsigned 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; +} + +unsigned gdriverGetDriverInstanceNumber(GDriver *driver) { + GDriver *pd; + unsigned instance; + + // Loop to find the system instance + instance = 0; + for(pd = dhead; pd; pd = pd->driverchain) { + if (pd == driver) + return instance; + if (pd->vmt->type == driver->vmt->type) + instance++; + } + return (unsigned)-1; +} + +#endif /* GFX_USE_GDRIVER */ diff --git a/src/gdriver/gdriver.h b/src/gdriver/gdriver.h new file mode 100644 index 00000000..6f245ef1 --- /dev/null +++ b/src/gdriver/gdriver.h @@ -0,0 +1,159 @@ +/* + * 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/gdriver.h + * + * @addtogroup GDRIVER + * + * @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 gdriver.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, void *param, unsigned driverinstance, unsigned systeminstance); // @< Initialise the driver. Returns TRUE if OK. + // driverinstance is the instance 0..n of this driver. + // systeminstance is the instance 0..n of this type of device. + // The memory allocated is cleared before this call. + void (*postinit)(GDriver *driver); // @< Called once the driver is registered. + void (*deinit)(GDriver *driver); // @< De-initialise the driver +} GDriverVMT; + +/** + * @brief A definition that allows getting addresses of GDriverVMT structures to put into a list. + * @note eg. + * const MyDriverVMTtype a[1] = {{...}}; + * const MyDriverVMTtype b[1] = {{...}}; + * ... + * \#define DRIVER_LIST a, b + * extern GDriverVMTList DRIVER_LIST; // Now treated as single element arrays of GDriverVMT + * const GDriverVMT const * mylist = { DRIVER_LIST }; + * + * + */ +typedef const struct GDriverVMT const GDriverVMTList[1]; + +/*===========================================================================*/ +/* 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 + * @param[in] param An arbitrary paramater passed to the driver init routine. + */ + GDriver *gdriverRegister(const GDriverVMT *vmt, void *param); + + /** + * @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, unsigned 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 + */ + unsigned gdriverInstanceCount(uint16_t type); + + /** + * @brief Get the instance number for a device + * @return The instance number or (unsigned)-1 if it fails. + * + * @param[in] driver The driver to find the instance number for + */ + unsigned gdriverGetDriverInstanceNumber(GDriver *driver); + + /** + * @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/gdriver.mk b/src/gdriver/gdriver.mk new file mode 100644 index 00000000..663042af --- /dev/null +++ b/src/gdriver/gdriver.mk @@ -0,0 +1 @@ +GFXSRC += $(GFXLIB)/src/gdriver/gdriver.c diff --git a/src/gdriver/gdriver_gdriver.c b/src/gdriver/gdriver_gdriver.c deleted file mode 100644 index 210840b1..00000000 --- a/src/gdriver/gdriver_gdriver.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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" - -#include // For memset - -// Define the tables to hold the driver instances. -static GDriver *dhead; -static GDriver *dtail; - -// The system initialization. -void _gdriverInit(void) { -} - -// The system de-initialization. -void _gdriverDeinit(void) { - while(dhead) - gdriverUnRegister(dhead); -} - - -GDriver *gdriverRegister(const GDriverVMT *vmt, void *param) { - GDriver * pd; - unsigned dinstance, sinstance; - - // Loop to find the driver instance and the system instance numbers - dinstance = sinstance = 0; - for(pd = dhead; 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; - memset(pd, 0, vmt->objsize); - pd->vmt = vmt; - if (vmt->init && !vmt->init(pd, param, dinstance, sinstance)) { - gfxFree(pd); - return 0; - } - - // Add it to the driver chain - if (dhead) - dtail->driverchain = pd; - else - dhead = dtail = pd; - - // Do the post init - if (vmt->postinit) - vmt->postinit(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, unsigned instance) { - GDriver *pd; - unsigned 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; -} - -unsigned gdriverInstanceCount(uint16_t type) { - GDriver *pd; - unsigned 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; -} - -unsigned gdriverGetDriverInstanceNumber(GDriver *driver) { - GDriver *pd; - unsigned instance; - - // Loop to find the system instance - instance = 0; - for(pd = dhead; pd; pd = pd->driverchain) { - if (pd == driver) - return instance; - if (pd->vmt->type == driver->vmt->type) - instance++; - } - return (unsigned)-1; -} - -#endif /* GFX_USE_GDRIVER */ diff --git a/src/gdriver/gdriver_options.h b/src/gdriver/gdriver_options.h new file mode 100644 index 00000000..ca3fe1f1 --- /dev/null +++ b/src/gdriver/gdriver_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/gdriver_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/gdriver_rules.h b/src/gdriver/gdriver_rules.h new file mode 100644 index 00000000..2aaffa1b --- /dev/null +++ b/src/gdriver/gdriver_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/gdriver_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 */ +/** @} */ diff --git a/src/gdriver/sys_defs.h b/src/gdriver/sys_defs.h deleted file mode 100644 index 4ac20b19..00000000 --- a/src/gdriver/sys_defs.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 GDRIVER - * - * @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, void *param, unsigned driverinstance, unsigned systeminstance); // @< Initialise the driver. Returns TRUE if OK. - // driverinstance is the instance 0..n of this driver. - // systeminstance is the instance 0..n of this type of device. - // The memory allocated is cleared before this call. - void (*postinit)(GDriver *driver); // @< Called once the driver is registered. - void (*deinit)(GDriver *driver); // @< De-initialise the driver -} GDriverVMT; - -/** - * @brief A definition that allows getting addresses of GDriverVMT structures to put into a list. - * @note eg. - * const MyDriverVMTtype a[1] = {{...}}; - * const MyDriverVMTtype b[1] = {{...}}; - * ... - * \#define DRIVER_LIST a, b - * extern GDriverVMTList DRIVER_LIST; // Now treated as single element arrays of GDriverVMT - * const GDriverVMT const * mylist = { DRIVER_LIST }; - * - * - */ -typedef const struct GDriverVMT const GDriverVMTList[1]; - -/*===========================================================================*/ -/* 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 - * @param[in] param An arbitrary paramater passed to the driver init routine. - */ - GDriver *gdriverRegister(const GDriverVMT *vmt, void *param); - - /** - * @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, unsigned 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 - */ - unsigned gdriverInstanceCount(uint16_t type); - - /** - * @brief Get the instance number for a device - * @return The instance number or (unsigned)-1 if it fails. - * - * @param[in] driver The driver to find the instance number for - */ - unsigned gdriverGetDriverInstanceNumber(GDriver *driver); - - /** - * @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 deleted file mode 100644 index 93810aa9..00000000 --- a/src/gdriver/sys_make.mk +++ /dev/null @@ -1 +0,0 @@ -GFXSRC += $(GFXLIB)/src/gdriver/gdriver_gdriver.c diff --git a/src/gdriver/sys_options.h b/src/gdriver/sys_options.h deleted file mode 100644 index bef0a95a..00000000 --- a/src/gdriver/sys_options.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 deleted file mode 100644 index 596babba..00000000 --- a/src/gdriver/sys_rules.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 */ -/** @} */ -- cgit v1.2.3