projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
USB: coding style fixes (structure naming)
[bertos.git]
/
bertos
/
drv
/
sipo.c
diff --git
a/bertos/drv/sipo.c
b/bertos/drv/sipo.c
index cb821692727b4989a57227b77ae87565a39435f8..58830bbbbc95907b9385070f4360dfd6a9f14a4f 100644
(file)
--- a/
bertos/drv/sipo.c
+++ b/
bertos/drv/sipo.c
@@
-26,18
+26,17
@@
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
- * Copyright 200
8
Develer S.r.l. (http://www.develer.com/)
+ * Copyright 200
9
Develer S.r.l. (http://www.develer.com/)
*
* -->
*
*
* -->
*
- * \version $Id$
*
* \brief SIPO Module
*
*
* \brief SIPO Module
*
- * The SIPO module trasform a serial input in
- * a parallel output. Please check hw_sipo.h
- * file to customize hardware relative parameters.
+ * The SIPO module transforms a serial input in a parallel output. Please check hw_sipo.h
+ * file to customize hardware related parameters.
*
*
+ * \author Andrea Grandi <andrea@develer.com>
* \author Daniele Basile <asterix@develer.com>
*/
* \author Daniele Basile <asterix@develer.com>
*/
@@
-46,43
+45,57
@@
#include "hw/hw_sipo.h"
#include <cfg/compiler.h>
#include "hw/hw_sipo.h"
#include <cfg/compiler.h>
+#include <cfg/log.h>
-#include <
kern
/kfile.h>
+#include <
io
/kfile.h>
#include <string.h>
#include <string.h>
+
+#define SIPO_DATAORDER_START(order) (order ? SIPO_DATAORDER_START_LSB : SIPO_DATAORDER_START_MSB)
+#define SIPO_DATAORDER_SHIFT(shift, order) (order ? ((shift) <<= 1) : ((shift) >>= 1))
+
/**
* Write a char in sipo shift register
*/
/**
* Write a char in sipo shift register
*/
-INLINE void sipo_putchar(uint8_t c)
+INLINE void sipo_putchar(uint8_t c
, uint8_t bit_order, uint8_t clock_pol
)
{
{
+ uint8_t shift = SIPO_DATAORDER_START(bit_order);
+
for(int i = 0; i < 8; i++)
{
for(int i = 0; i < 8; i++)
{
- if((c &
BV(i)
) == 0)
+ if((c &
shift
) == 0)
SIPO_SI_LOW();
else
SIPO_SI_HIGH();
SIPO_SI_LOW();
else
SIPO_SI_HIGH();
- SIPO_SI_CLOCK();
+ SIPO_SI_CLOCK(clock_pol);
+
+ SIPO_DATAORDER_SHIFT(shift, bit_order);
}
}
/**
}
}
/**
- * Write a buffer into sipo register and when finish to
- * we load it.
+ * Write a buffer into the sipo register and, when finished, give a load pulse.
*/
*/
-
static size_t sipo_write(UNUSED_ARG(struct KFile *, fd)
, const void *_buf, size_t size)
+
static size_t sipo_write(struct KFile *_fd
, const void *_buf, size_t size)
{
const uint8_t *buf = (const uint8_t *)_buf;
{
const uint8_t *buf = (const uint8_t *)_buf;
+ Sipo *fd = SIPO_CAST(_fd);
size_t write_len = size;
size_t write_len = size;
+
ASSERT(buf);
ASSERT(buf);
- // Load into shift register all byte in buffer
+ SIPO_SET_SI_LEVEL();
+ SIPO_SET_CLK_LEVEL(fd->clock_pol);
+ SIPO_SET_LD_LEVEL(fd->load_device, fd->load_pol);
+
+ // Load into the shift register all the buffer bytes
while(size--)
while(size--)
- sipo_putchar(*buf++);
+ sipo_putchar(*buf++
, fd->bit_order, fd->clock_pol
);
- // We finsh to load bytes
into shift register,
load it.
- SIPO_LOAD();
+ // We finsh to load bytes
, so
load it.
+ SIPO_LOAD(
fd->load_device, fd->load_pol
);
return write_len;
}
return write_len;
}
@@
-99,9
+112,11
@@
void sipo_init(Sipo *fd)
//Set kfile struct type as a generic kfile structure.
DB(fd->fd._type = KFT_SIPO);
//Set kfile struct type as a generic kfile structure.
DB(fd->fd._type = KFT_SIPO);
- // Set up
data flash programm
ing functions.
+ // Set up
SIPO writ
ing functions.
fd->fd.write = sipo_write;
SIPO_INIT_PIN();
fd->fd.write = sipo_write;
SIPO_INIT_PIN();
+ /* Enable sipo output */
+ SIPO_ENABLE();
}
}