Browse Source

lowl-spi: Move bit order reverse to bitflip8 function in util

Luke Dashjr 11 years ago
parent
commit
76a7438987
2 changed files with 10 additions and 5 deletions
  1. 1 5
      lowl-spi.c
  2. 9 0
      util.h

+ 1 - 5
lowl-spi.c

@@ -265,11 +265,7 @@ void *spi_emit_buf_reverse(struct spi_port *port, const void *p, size_t sz)
 	for (size_t i = 0; i < sz; ++i)
 	{
 		// Reverse bit order in each byte!
-		unsigned char p = str[i];
-		p = ((p & 0xaa)>>1) | ((p & 0x55) << 1);
-		p = ((p & 0xcc)>>2) | ((p & 0x33) << 2);
-		p = ((p & 0xf0)>>4) | ((p & 0x0f) << 4);
-		port->spibuf[port->spibufsz++] = p;
+		port->spibuf[port->spibufsz++] = bitflip8(str[i]);
 	}
 	return rv;
 }

+ 9 - 0
util.h

@@ -264,6 +264,15 @@ static inline void align_len(size_t *len)
 }
 
 
+static inline
+uint8_t bitflip8(uint8_t p)
+{
+	p = ((p & 0xaa) >> 1) | ((p & 0x55) << 1);
+	p = ((p & 0xcc) >> 2) | ((p & 0x33) << 2);
+	p = ((p & 0xf0) >> 4) | ((p & 0x0f) << 4);
+	return p;
+}
+
 static inline
 uint8_t upk_u8(const void * const bufp, const int offset)
 {