Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
SRPIO.h
Go to the documentation of this file.
1
19
#ifndef SRPIO_H
20
#define SRPIO_H
21
22
#include "
GPIO.h
"
23
30
template
<u
int
8_t BITORDER, BOARD::pin_t DATA_PIN, BOARD::pin_t CLOCK_PIN>
31
class
SRPIO
{
32
public
:
39
SRPIO
()
40
{
41
m_data
.
open_drain
();
42
m_clock
.
output
();
43
}
44
50
void
write
(uint8_t value)
51
{
52
if
(BITORDER == LSBFIRST) {
53
uint8_t mask = 1;
54
do
{
55
if
(value & mask)
m_data
.
input
();
else
m_data
.
output
();
56
m_clock
.
toggle
();
57
mask <<= 1;
58
m_clock
.
toggle
();
59
}
while
(mask);
60
}
61
else
{
62
uint8_t mask = 0x80;
63
do
{
64
if
(value & mask)
m_data
.
input
();
else
m_data
.
output
();
65
m_clock
.
toggle
();
66
mask >>= 1;
67
m_clock
.
toggle
();
68
}
while
(mask);
69
}
70
m_data
.
input
();
71
}
72
77
void
operator<<
(uint8_t value)
78
{
79
write
(value);
80
}
81
88
uint8_t
read
()
89
{
90
uint8_t res = 0;
91
if
(BITORDER == LSBFIRST) {
92
uint8_t mask = 1;
93
do
{
94
m_clock
.
toggle
();
95
res |= (
m_data
? mask : 0);
96
m_clock
.
toggle
();
97
mask <<= 1;
98
}
while
(mask);
99
}
100
else
{
101
uint8_t mask = 0x80;
102
do
{
103
m_clock
.
toggle
();
104
res |= (
m_data
? mask : 0);
105
m_clock
.
toggle
();
106
mask >>= 1;
107
}
while
(mask);
108
}
109
return
(res);
110
}
111
116
void
operator>>
(uint8_t& value)
117
{
118
value =
read
();
119
}
120
121
protected
:
122
GPIO<DATA_PIN>
m_data
;
123
GPIO<CLOCK_PIN>
m_clock
;
124
};
125
126
#endif
SRPIO::operator>>
void operator>>(uint8_t &value)
Definition:
SRPIO.h:116
GPIO::input
GPIO< PIN > & input()
Definition:
GPIO.h:36
SRPIO::read
uint8_t read()
Definition:
SRPIO.h:88
GPIO.h
GPIO::toggle
void toggle()
Definition:
GPIO.h:113
GPIO::open_drain
void open_drain()
Definition:
GPIO.h:65
SRPIO::write
void write(uint8_t value)
Definition:
SRPIO.h:50
SRPIO::operator<<
void operator<<(uint8_t value)
Definition:
SRPIO.h:77
GPIO::output
void output()
Definition:
GPIO.h:56
GPIO< DATA_PIN >
SRPIO
Definition:
SRPIO.h:31
SRPIO::SRPIO
SRPIO()
Definition:
SRPIO.h:39
SRPIO::m_clock
GPIO< CLOCK_PIN > m_clock
Definition:
SRPIO.h:123
SRPIO::m_data
GPIO< DATA_PIN > m_data
Definition:
SRPIO.h:122
src
SRPIO.h
Generated on Sat Oct 14 2017 16:03:22 for Arduino-GPIO by
1.8.11