COSA
An Object-Oriented Platform for Arduino Programming
OutputPin.cpp
Go to the documentation of this file.
1 
21 #include "Cosa/OutputPin.hh"
22 
23 void
24 OutputPin::write(uint8_t value, OutputPin& clk, Direction order) const
25 {
26  uint8_t bits = CHARBITS;
27  if (order == MSB_FIRST) {
28  do {
29  _write(value & 0x80);
30  clk._toggle();
31  value <<= 1;
32  clk._toggle();
33  } while (--bits);
34  }
35  else {
36  do {
37  _write(value & 0x01);
38  clk._toggle();
39  value >>= 1;
40  clk._toggle();
41  } while (--bits);
42  }
43 }
44 
45 void
46 OutputPin::write(uint16_t value, uint8_t bits, uint16_t us) const
47 {
48  if (UNLIKELY(bits == 0)) return;
49  synchronized {
50  do {
51  _write(value & 0x01);
52  DELAY(us);
53  value >>= 1;
54  } while (--bits);
55  }
56 }
57 
#define DELAY(us)
Definition: Types.h:280
Direction
Definition: Pin.hh:84
void write(int value) const
Definition: OutputPin.hh:236
#define CHARBITS
Definition: Types.h:57
void _toggle() const
Definition: OutputPin.hh:153
void _write(int value) const
Definition: OutputPin.hh:219
#define UNLIKELY(x)
Definition: Types.h:153