Digital IO
PinIO.cpp
Go to the documentation of this file.
1 /* Arduino DigitalIO Library
2  * Copyright (C) 2013 by William Greiman
3  *
4  * This file is part of the Arduino DigitalIO Library
5  *
6  * This Library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This Library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with the Arduino DigitalIO Library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
28 #if defined(__AVR__) || defined(DOXYGEN) // AVR only
29 #include "PinIO.h"
30 #include <util/atomic.h>
31 #include <Arduino.h>
32 //==============================================================================
36 PinIO::PinIO(uint8_t pin) {
37  begin(pin);
38 }
39 //------------------------------------------------------------------------------
44 bool PinIO::begin(uint8_t pin) {
45  if (pin >= NUM_DIGITAL_PINS) return false;
46  uint8_t port = digitalPinToPort(pin);
47  pinReg_ = portInputRegister(port);
48  bit_ = digitalPinToBitMask(pin);
49  mask_ = ~bit_;
50  portReg_ = pinReg_ + 2;
51  return true;
52 }
53 //------------------------------------------------------------------------------
63 void PinIO::config(uint8_t mode, bool level) {
64  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
65  modeI(mode);
66  writeI(level);
67  }
68 }
69 #endif // __AVR__
70 
Digital AVR port I/O with runtime pin number.
PinIO()
Definition: PinIO.h:42
void modeI(uint8_t mode)
Definition: PinIO.h:86
bool begin(uint8_t pin)
Definition: PinIO.cpp:44
void writeI(bool level)
Definition: PinIO.h:103
void config(uint8_t mode, bool data)
Definition: PinIO.cpp:63