COSA
An Object-Oriented Platform for Arduino Programming
IOPin.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_IO_PIN_HH
22 #define COSA_IO_PIN_HH
23 
24 #include "Cosa/OutputPin.hh"
25 
29 class IOPin : public OutputPin {
30 public:
31  enum Mode {
34  } __attribute__((packed));
35 
41  IOPin(Board::DigitalPin pin, Mode mode = INPUT_MODE, bool pullup = false) :
42  OutputPin(pin)
43  {
44  synchronized {
45  if (pullup)
46  *PORT() |= m_mask;
47  }
48  this->mode(mode);
49  }
50 
56  void mode(Mode mode)
57  __attribute__((always_inline))
58  {
59  synchronized {
60  if (mode == OUTPUT_MODE)
61  *DDR() |= m_mask;
62  else
63  *DDR() &= ~m_mask;
64  }
65  }
66 
71  Mode mode() const
72  __attribute__((always_inline))
73  {
74  return ((*DDR() & m_mask) == 0 ? INPUT_MODE : OUTPUT_MODE);
75  }
76 
84  __attribute__((always_inline))
85  {
86  volatile uint8_t* ddr = DDR(pin);
87  const uint8_t mask = MASK(pin);
88  synchronized {
89  if (mode == OUTPUT_MODE)
90  *ddr |= mask;
91  else
92  *ddr &= ~mask;
93  }
94  }
95 
102  __attribute__((always_inline))
103  {
104  return ((*DDR(pin) & MASK(pin)) == 0 ? INPUT_MODE : OUTPUT_MODE);
105  }
106 };
107 
108 #endif
void mode(Mode mode)
Definition: IOPin.hh:56
uint8_t pin() const
Definition: Pin.hh:103
static uint8_t MASK(uint8_t pin)
Definition: Pin.hh:42
Mode mode() const
Definition: IOPin.hh:71
static void mode(Board::DigitalPin pin, Mode mode)
Definition: IOPin.hh:83
IOPin(Board::DigitalPin pin, Mode mode=INPUT_MODE, bool pullup=false)
Definition: IOPin.hh:41
Definition: IOPin.hh:29
Mode
Definition: IOPin.hh:31
const uint8_t m_mask
Definition: Pin.hh:227
volatile uint8_t * PORT() const
Definition: Pin.hh:254
static Mode mode(Board::DigitalPin pin)
Definition: IOPin.hh:101
volatile uint8_t * DDR() const
Definition: Pin.hh:245