From e380431860a0d4e90b0b06aa628099637a572101 Mon Sep 17 00:00:00 2001 From: Daniele Basile Date: Wed, 25 Jan 2012 14:12:23 +0100 Subject: [PATCH] Update sipo api. --- bertos/cfg/cfg_sipo.h | 66 +++++++++++++++++++ bertos/drv/sipo.c | 60 +++++++++++++++-- bertos/drv/sipo.h | 64 ++++++++++++++++-- .../triface/examples/triface/cfg/cfg_sipo.h | 66 +++++++++++++++++++ boards/triface/hw/hw_sipo.h | 1 - 5 files changed, 245 insertions(+), 12 deletions(-) create mode 100644 bertos/cfg/cfg_sipo.h create mode 100644 boards/triface/examples/triface/cfg/cfg_sipo.h diff --git a/bertos/cfg/cfg_sipo.h b/bertos/cfg/cfg_sipo.h new file mode 100644 index 00000000..76b05c43 --- /dev/null +++ b/bertos/cfg/cfg_sipo.h @@ -0,0 +1,66 @@ +/** + * \file + * + * + * \brief Configuration file for SIPO module. + * + * \author Daniele Basile + */ + +#ifndef CFG_SIPO_H +#define CFG_SIPO_H + +/** + * Check this to disable SIPO deprecated API support. + * + * $WIZ$ type = "boolean" + */ +#define CONFIG_SIPO_DISABLE_OLD_API 0 + +/** + * Module logging level. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define SIPO_LOG_LEVEL LOG_LVL_INFO + +/** + * module logging format. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define SIPO_LOG_FORMAT LOG_FMT_TERSE + +#endif /* CFG_SIPO_H */ + + diff --git a/bertos/drv/sipo.c b/bertos/drv/sipo.c index 58830bbb..046cf72a 100644 --- a/bertos/drv/sipo.c +++ b/bertos/drv/sipo.c @@ -43,9 +43,12 @@ #include "sipo.h" #include "hw/hw_sipo.h" +#include "cfg/cfg_sipo.h" -#include +#define LOG_LEVEL SIPO_LOG_LEVEL +#define LOG_FORMAT SIPO_LOG_FORMAT #include +#include #include @@ -75,6 +78,8 @@ INLINE void sipo_putchar(uint8_t c, uint8_t bit_order, uint8_t clock_pol) } } + +#if !CONFIG_SIPO_DISABLE_OLD_API /** * Write a buffer into the sipo register and, when finished, give a load pulse. */ @@ -100,14 +105,39 @@ static size_t sipo_write(struct KFile *_fd, const void *_buf, size_t size) return write_len; } +#else /* New api */ + /** - * Initialize the SIPO + * Write a buffer into the sipo register and, when finished, give a load pulse. */ -void sipo_init(Sipo *fd) +static size_t sipo_write(struct KFile *_fd, const void *_buf, size_t size) { - ASSERT(fd); + const uint8_t *buf = (const uint8_t *)_buf; + Sipo *fd = SIPO_CAST(_fd); + size_t write_len = size; + + ASSERT(buf); + + SIPO_SET_SI_LEVEL(); + SIPO_SET_CLK_LEVEL(fd->settings & SIPO_CLOCK_POL); + SIPO_SET_LD_LEVEL(fd->device, fd->settings & SIPO_LOAD_LEV); + + // Load into the shift register all the buffer bytes + while(size--) + sipo_putchar(*buf++, fd->settings & SIPO_DATAORDER, + fd->settings & SIPO_CLOCK_POL); + + // We finsh to load bytes, so load it. + SIPO_LOAD(fd->device, fd->settings & SIPO_LOAD_LEV); + + return write_len; +} +#endif - memset(fd, 0, sizeof(Sipo)); + +INLINE void init(Sipo *fd) +{ + ASSERT(fd); //Set kfile struct type as a generic kfile structure. DB(fd->fd._type = KFT_SIPO); @@ -120,3 +150,23 @@ void sipo_init(Sipo *fd) /* Enable sipo output */ SIPO_ENABLE(); } + +/** + * Initialize the SIPO + */ +#if !CONFIG_SIPO_DISABLE_OLD_API + +void sipo_init_1(Sipo *fd) +{ + init(fd); +} +#else /* New api */ + +void sipo_init_3(Sipo *fd, SipoMap dev, uint8_t settings) +{ + memset(fd, 0, sizeof(fd)); + fd->settings = settings; + fd->device = dev; + init(fd); +} +#endif diff --git a/bertos/drv/sipo.h b/bertos/drv/sipo.h index a527d6e4..10918cd7 100644 --- a/bertos/drv/sipo.h +++ b/bertos/drv/sipo.h @@ -42,20 +42,46 @@ * $WIZ$ module_hw = "bertos/hw/hw_sipo.h" */ - - - - #ifndef DRV_SIPO_H #define DRV_SIPO_H #include "hw/hw_sipo.h" +#include "cfg/cfg_sipo.h" #include + +/* + * The following macros are needed to maintain compatibility with older sipo API. + * They can be safely removed once the old API is removed. + */ + + /** + * \addtogroup sipo_api + * \{ + */ +#if COMPILER_C99 + #define sipo_init(...) PP_CAT(sipo_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__) +#else + /** + * Initialize SIPO module. + * + * To initialize the module you can write this code: + * \code + * Sipo ctx; + * sipo_init(&ctx, settings); + * \endcode + */ + #define sipo_init(args...) PP_CAT(sipo_init ## _, COUNT_PARMS(args)) (args) + +#endif +/**\}*/ + + #define SIPO_DATAORDER_START_LSB 1 #define SIPO_DATAORDER_START_MSB 0x80 +#if !CONFIG_SIPO_DISABLE_OLD_API /** * Define enum to set sipo data order. */ @@ -97,6 +123,31 @@ typedef struct Sipo SipoBitOrder bit_order; ///< Set the order of pushed bits in sipo. } Sipo; +#else /* New api */ + +#define SIPO_DATAORDER BV(0) +#define SIPO_DATAORDER_MSB BV(0) ///< MSB sipo data order setting +#define SIPO_DATAORDER_LSB 0 ///< LSB sipo data order setting + +#define SIPO_CLOCK_POL BV(1) +#define SIPO_START_LOW BV(1) ///< sipo clock start level high setting +#define SIPO_START_HIGH 0 ///< sipo clock start level low setting + +#define SIPO_LOAD_LEV BV(2) +#define SIPO_LOW_TO_HIGH BV(2) ///< sipo load high signal level setting. +#define SIPO_HIGH_TO_LOW 0 ///< sipo load low signal level setting. + +/** + * Sipo KFile context structure. + */ +typedef struct Sipo +{ + KFile fd; ///< File descriptor. + SipoMap device; ///< Descriptor of the device that we want drive. + uint8_t settings; +} Sipo; + +#endif /** * ID for sipo. @@ -112,7 +163,8 @@ INLINE Sipo * SIPO_CAST(KFile *fd) return (Sipo *)fd; } -void sipo_init(Sipo *fd); +void sipo_init_1(Sipo *fd); +void sipo_init_3(Sipo *fd, SipoMap dev, uint8_t settings); -#endif // DRV_SIPO_H +#endif /* DRV_SIPO_H */ diff --git a/boards/triface/examples/triface/cfg/cfg_sipo.h b/boards/triface/examples/triface/cfg/cfg_sipo.h new file mode 100644 index 00000000..80e7a42c --- /dev/null +++ b/boards/triface/examples/triface/cfg/cfg_sipo.h @@ -0,0 +1,66 @@ +/** + * \file + * + * + * \brief Configuration file for SIPO module. + * + * \author Daniele Basile + */ + +#ifndef CFG_SIPO_H +#define CFG_SIPO_H + +/** + * Check this to disable SIPO deprecated API support. + * + * $WIZ$ type = "boolean" + */ +#define CONFIG_SIPO_DISABLE_OLD_API 1 + +/** + * Module logging level. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define SIPO_LOG_LEVEL LOG_LVL_INFO + +/** + * module logging format. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define SIPO_LOG_FORMAT LOG_FMT_TERSE + +#endif /* CFG_SIPO_H */ + + diff --git a/boards/triface/hw/hw_sipo.h b/boards/triface/hw/hw_sipo.h index 9922c052..8415d9c4 100644 --- a/boards/triface/hw/hw_sipo.h +++ b/boards/triface/hw/hw_sipo.h @@ -97,7 +97,6 @@ typedef enum SipoMap #define SIPO_LOAD(device, load_pol) \ do { \ (void)device; \ - (void)load_pol; \ SLOAD_OUT_HIGH; \ SLOAD_OUT_LOW; \ }while(0) -- 2.25.1