Update sipo api.
[bertos.git] / bertos / drv / sipo.c
index 58830bbbbc95907b9385070f4360dfd6a9f14a4f..046cf72a762ba34a9d5413e01ba663d401be2a9a 100644 (file)
 #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>
 
@@ -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