ShiftReg library (74HC595, NUJ3711)

Revision:
1:3741bc0fbba8
Parent:
0:5f1670338bef
diff -r 5f1670338bef -r 3741bc0fbba8 ShiftReg.cpp
--- a/ShiftReg.cpp	Sat Oct 24 16:30:11 2015 +0000
+++ b/ShiftReg.cpp	Sat Oct 24 17:44:30 2015 +0000
@@ -1,7 +1,8 @@
 #include "ShiftReg.h"
 #include "mbed.h"
- 
-ShiftReg::ShiftReg(PinName dataPin, PinName stbPin, 
+
+template <class T_bit>
+ShiftReg<T_bit>::ShiftReg(PinName dataPin, PinName stbPin, 
                    PinName clkPin, PinName clrPin)
 : 
     DATA(dataPin),
@@ -14,9 +15,10 @@
     CLK  = 1;
     CLR  = 1;
 }
- 
-void ShiftReg::send_data(uint8_t data) {
-    shiftOut(data);
+
+template <class T_bit>
+void ShiftReg<T_bit>::send_data(T_bit data, uint8_t size) {
+    shiftOut(data, size);
     wait_us(1);
 #ifdef HC595
     STB = 0;
@@ -32,10 +34,14 @@
     wait_us(1);
 }
 
-void ShiftReg::shiftOut(uint8_t data) {
-    for(int i = 0; i < 8; i++) {
+template <class T_bit>
+void ShiftReg<T_bit>::shiftOut(T_bit data, uint8_t size) {
+    for(int i = 0; i < size; i++) {
         DATA = (data & (1 << i));
         CLK = 0;
         CLK = 1;
     }
-}
\ No newline at end of file
+}
+template class ShiftReg<uint8_t>;
+template class ShiftReg<uint16_t>;
+template class ShiftReg<uint32_t>;
\ No newline at end of file