Digital IO
Arduino/libraries/DigitalIO/PinIO.cpp
Go to the documentation of this file.
00001 /* Arduino DigitalIO Library
00002  * Copyright (C) 2013 by William Greiman
00003  *
00004  * This file is part of the Arduino DigitalIO Library
00005  *
00006  * This Library is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with the Arduino DigitalIO Library.  If not, see
00018  * <http://www.gnu.org/licenses/>.
00019  */
00028 #include <PinIO.h>
00029 #include <util/atomic.h>
00030 #include <Arduino.h>
00031 //==============================================================================
00035 PinIO::PinIO(uint8_t pin) {
00036   begin(pin);
00037 }
00038 //------------------------------------------------------------------------------
00043 bool PinIO::begin(uint8_t pin) {
00044   if (pin >= NUM_DIGITAL_PINS) return false;
00045   uint8_t port = digitalPinToPort(pin);
00046   pinReg_ = portInputRegister(port);
00047   bit_ = digitalPinToBitMask(pin);
00048   mask_ = ~bit_;
00049   portReg_ = pinReg_ + 2;
00050   return true;
00051 }
00052 //------------------------------------------------------------------------------
00062 void PinIO::config(bool mode, bool data) {
00063   ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
00064     modeI(mode);
00065     writeI(data);
00066   }
00067 }
 All Classes Files Functions Variables Defines