COSA
An Object-Oriented Platform for Arduino Programming
Pin.cpp
Go to the documentation of this file.
1 
21 #include "Cosa/Pin.hh"
22 #include "Cosa/OutputPin.hh"
23 
24 uint8_t
25 Pin::read(OutputPin& clk, Direction order) const
26 {
27  uint8_t value = 0;
28  uint8_t bits = CHARBITS;
29  if (order == MSB_FIRST) {
30  do {
31  value <<= 1;
32  if (is_set()) value |= 0x01;
33  clk.toggle();
34  clk.toggle();
35  } while (--bits);
36  }
37  else {
38  do {
39  value >>= 1;
40  if (is_set()) value |= 0x80;
41  clk.toggle();
42  clk.toggle();
43  } while (--bits);
44  }
45  return (value);
46 }
Direction
Definition: Pin.hh:84
#define CHARBITS
Definition: Types.h:57
bool is_set() const
Definition: Pin.hh:112
void toggle() const
Definition: OutputPin.hh:163
bool read() const
Definition: Pin.hh:172