COSA
An Object-Oriented Platform for Arduino Programming
InputPin.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_INPUT_PIN_HH
22 #define COSA_INPUT_PIN_HH
23 
24 #include "Cosa/Pin.hh"
25 
29 class InputPin : public Pin {
30 public:
31  enum Mode {
34  } __attribute__((packed));
35 
42  Pin((uint8_t) pin)
43  {
44  if (mode == PULLUP_MODE)
45  synchronized *PORT(pin) |= MASK(pin);
46  }
47 
52  Mode mode() const
53  __attribute__((always_inline))
54  {
55  return ((*PORT() & m_mask) != 0 ? PULLUP_MODE : NORMAL_MODE);
56  }
57 
65  __attribute__((always_inline))
66  {
67  synchronized {
68  if (mode == PULLUP_MODE)
69  *PORT(pin) |= MASK(pin);
70  else
71  *PORT(pin) &= ~MASK(pin);
72  }
73  }
74 
81  __attribute__((always_inline))
82  {
83  return ((*PORT(pin) & MASK(pin)) == 0 ? NORMAL_MODE : PULLUP_MODE);
84  }
85 };
86 
87 #endif
InputPin(Board::DigitalPin pin, Mode mode=NORMAL_MODE)
Definition: InputPin.hh:41
uint8_t pin() const
Definition: Pin.hh:103
Definition: Pin.hh:35
static uint8_t MASK(uint8_t pin)
Definition: Pin.hh:42
static void mode(Board::DigitalPin pin, Mode mode)
Definition: InputPin.hh:64
Mode mode() const
Definition: InputPin.hh:52
static Mode mode(Board::DigitalPin pin)
Definition: InputPin.hh:80
const uint8_t m_mask
Definition: Pin.hh:227
volatile uint8_t * PORT() const
Definition: Pin.hh:254