--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2012 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Configuration file for SIPO module.
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#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 */
+
+
#include "sipo.h"
#include "hw/hw_sipo.h"
+#include "cfg/cfg_sipo.h"
-#include <cfg/compiler.h>
+#define LOG_LEVEL SIPO_LOG_LEVEL
+#define LOG_FORMAT SIPO_LOG_FORMAT
#include <cfg/log.h>
+#include <cfg/compiler.h>
#include <io/kfile.h>
}
}
+
+#if !CONFIG_SIPO_DISABLE_OLD_API
/**
* Write a buffer into the sipo register and, when finished, give a load pulse.
*/
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);
/* 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
* $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 <io/kfile.h>
+
+/*
+ * 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.
*/
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.
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 */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2012 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Configuration file for SIPO module.
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#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 */
+
+
#define SIPO_LOAD(device, load_pol) \
do { \
(void)device; \
- (void)load_pol; \
SLOAD_OUT_HIGH; \
SLOAD_OUT_LOW; \
}while(0)