mbed library sources

Fork of mbed-src by mbed official

Committer:
bogdanm
Date:
Mon Aug 05 14:12:34 2013 +0300
Revision:
13:0645d8841f51
Parent:
10:3bc89ef62ce7
Child:
160:6870f452afa4
Update mbed sources to revision 64

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 13:0645d8841f51 1 /* mbed Microcontroller Library
bogdanm 13:0645d8841f51 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 13:0645d8841f51 3 *
bogdanm 13:0645d8841f51 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 13:0645d8841f51 5 * you may not use this file except in compliance with the License.
bogdanm 13:0645d8841f51 6 * You may obtain a copy of the License at
bogdanm 13:0645d8841f51 7 *
bogdanm 13:0645d8841f51 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 13:0645d8841f51 9 *
bogdanm 13:0645d8841f51 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 13:0645d8841f51 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 13:0645d8841f51 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 13:0645d8841f51 13 * See the License for the specific language governing permissions and
bogdanm 13:0645d8841f51 14 * limitations under the License.
bogdanm 13:0645d8841f51 15 */
bogdanm 13:0645d8841f51 16 #include "BusIn.h"
bogdanm 13:0645d8841f51 17
bogdanm 13:0645d8841f51 18 namespace mbed {
bogdanm 13:0645d8841f51 19
bogdanm 13:0645d8841f51 20 BusIn::BusIn(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
bogdanm 13:0645d8841f51 21 PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
bogdanm 13:0645d8841f51 22
bogdanm 13:0645d8841f51 23 for (int i=0; i<16; i++) {
bogdanm 13:0645d8841f51 24 _pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
bogdanm 13:0645d8841f51 25 }
bogdanm 13:0645d8841f51 26 }
bogdanm 13:0645d8841f51 27
bogdanm 13:0645d8841f51 28 BusIn::BusIn(PinName pins[16]) {
bogdanm 13:0645d8841f51 29 for (int i=0; i<16; i++) {
bogdanm 13:0645d8841f51 30 _pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
bogdanm 13:0645d8841f51 31 }
bogdanm 13:0645d8841f51 32 }
bogdanm 13:0645d8841f51 33
bogdanm 13:0645d8841f51 34 BusIn::~BusIn() {
bogdanm 13:0645d8841f51 35 for (int i=0; i<16; i++) {
bogdanm 13:0645d8841f51 36 if (_pin[i] != 0) {
bogdanm 13:0645d8841f51 37 delete _pin[i];
bogdanm 13:0645d8841f51 38 }
bogdanm 13:0645d8841f51 39 }
bogdanm 13:0645d8841f51 40 }
bogdanm 13:0645d8841f51 41
bogdanm 13:0645d8841f51 42 int BusIn::read() {
bogdanm 13:0645d8841f51 43 int v = 0;
bogdanm 13:0645d8841f51 44 for (int i=0; i<16; i++) {
bogdanm 13:0645d8841f51 45 if (_pin[i] != 0) {
bogdanm 13:0645d8841f51 46 v |= _pin[i]->read() << i;
bogdanm 13:0645d8841f51 47 }
bogdanm 13:0645d8841f51 48 }
bogdanm 13:0645d8841f51 49 return v;
bogdanm 13:0645d8841f51 50 }
bogdanm 13:0645d8841f51 51
bogdanm 13:0645d8841f51 52 #ifdef MBED_OPERATORS
bogdanm 13:0645d8841f51 53 BusIn::operator int() {
bogdanm 13:0645d8841f51 54 return read();
bogdanm 13:0645d8841f51 55 }
bogdanm 13:0645d8841f51 56 #endif
bogdanm 13:0645d8841f51 57
bogdanm 13:0645d8841f51 58 } // namespace mbed