Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
SRPI.h
Go to the documentation of this file.
1 
19 #ifndef SRPI_H
20 #define SRPI_H
21 
22 #include "GPIO.h"
23 
30 template<uint8_t BITORDER, BOARD::pin_t DATA_PIN, BOARD::pin_t CLOCK_PIN>
31 class SRPI {
32 public:
38  SRPI()
39  {
40  m_data.input();
41  m_clock.output();
42  }
43 
50  uint8_t read()
51  {
52  uint8_t res = 0;
53  if (BITORDER == LSBFIRST) {
54  uint8_t mask = 1;
55  do {
56  m_clock.toggle();
57  res |= (m_data ? mask : 0);
58  m_clock.toggle();
59  mask <<= 1;
60  } while (mask);
61  }
62  else {
63  uint8_t mask = 0x80;
64  do {
65  m_clock.toggle();
66  res |= (m_data ? mask : 0);
67  m_clock.toggle();
68  mask >>= 1;
69  } while (mask);
70  }
71  return (res);
72  }
73 
78  void operator>>(uint8_t& value)
79  {
80  value = read();
81  }
82 
83 protected:
86 };
87 
88 #endif
Definition: SRPI.h:31
GPIO< DATA_PIN > m_data
Definition: SRPI.h:84
void operator>>(uint8_t &value)
Definition: SRPI.h:78
GPIO< CLOCK_PIN > m_clock
Definition: SRPI.h:85
SRPI()
Definition: SRPI.h:38
GPIO< PIN > & input()
Definition: GPIO.h:36
uint8_t read()
Definition: SRPI.h:50
void toggle()
Definition: GPIO.h:113
void output()
Definition: GPIO.h:56