SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phungductung 0:8ede47d38d10 1 /* mbed Microcontroller Library
phungductung 0:8ede47d38d10 2 * Copyright (c) 2006-2013 ARM Limited
phungductung 0:8ede47d38d10 3 *
phungductung 0:8ede47d38d10 4 * Licensed under the Apache License, Version 2.0 (the "License");
phungductung 0:8ede47d38d10 5 * you may not use this file except in compliance with the License.
phungductung 0:8ede47d38d10 6 * You may obtain a copy of the License at
phungductung 0:8ede47d38d10 7 *
phungductung 0:8ede47d38d10 8 * http://www.apache.org/licenses/LICENSE-2.0
phungductung 0:8ede47d38d10 9 *
phungductung 0:8ede47d38d10 10 * Unless required by applicable law or agreed to in writing, software
phungductung 0:8ede47d38d10 11 * distributed under the License is distributed on an "AS IS" BASIS,
phungductung 0:8ede47d38d10 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
phungductung 0:8ede47d38d10 13 * See the License for the specific language governing permissions and
phungductung 0:8ede47d38d10 14 * limitations under the License.
phungductung 0:8ede47d38d10 15 */
phungductung 0:8ede47d38d10 16 #include "BusInOut.h"
phungductung 0:8ede47d38d10 17 #include "mbed_assert.h"
phungductung 0:8ede47d38d10 18
phungductung 0:8ede47d38d10 19 namespace mbed {
phungductung 0:8ede47d38d10 20
phungductung 0:8ede47d38d10 21 BusInOut::BusInOut(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) {
phungductung 0:8ede47d38d10 22 PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
phungductung 0:8ede47d38d10 23
phungductung 0:8ede47d38d10 24 _nc_mask = 0;
phungductung 0:8ede47d38d10 25 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 26 _pin[i] = (pins[i] != NC) ? new DigitalInOut(pins[i]) : 0;
phungductung 0:8ede47d38d10 27 if (pins[i] != NC) {
phungductung 0:8ede47d38d10 28 _nc_mask |= (1 << i);
phungductung 0:8ede47d38d10 29 }
phungductung 0:8ede47d38d10 30 }
phungductung 0:8ede47d38d10 31 }
phungductung 0:8ede47d38d10 32
phungductung 0:8ede47d38d10 33 BusInOut::BusInOut(PinName pins[16]) {
phungductung 0:8ede47d38d10 34 _nc_mask = 0;
phungductung 0:8ede47d38d10 35 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 36 _pin[i] = (pins[i] != NC) ? new DigitalInOut(pins[i]) : 0;
phungductung 0:8ede47d38d10 37 if (pins[i] != NC) {
phungductung 0:8ede47d38d10 38 _nc_mask |= (1 << i);
phungductung 0:8ede47d38d10 39 }
phungductung 0:8ede47d38d10 40 }
phungductung 0:8ede47d38d10 41 }
phungductung 0:8ede47d38d10 42
phungductung 0:8ede47d38d10 43 BusInOut::~BusInOut() {
phungductung 0:8ede47d38d10 44 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 45 if (_pin[i] != 0) {
phungductung 0:8ede47d38d10 46 delete _pin[i];
phungductung 0:8ede47d38d10 47 }
phungductung 0:8ede47d38d10 48 }
phungductung 0:8ede47d38d10 49 }
phungductung 0:8ede47d38d10 50
phungductung 0:8ede47d38d10 51 void BusInOut::write(int value) {
phungductung 0:8ede47d38d10 52 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 53 if (_pin[i] != 0) {
phungductung 0:8ede47d38d10 54 _pin[i]->write((value >> i) & 1);
phungductung 0:8ede47d38d10 55 }
phungductung 0:8ede47d38d10 56 }
phungductung 0:8ede47d38d10 57 }
phungductung 0:8ede47d38d10 58
phungductung 0:8ede47d38d10 59 int BusInOut::read() {
phungductung 0:8ede47d38d10 60 int v = 0;
phungductung 0:8ede47d38d10 61 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 62 if (_pin[i] != 0) {
phungductung 0:8ede47d38d10 63 v |= _pin[i]->read() << i;
phungductung 0:8ede47d38d10 64 }
phungductung 0:8ede47d38d10 65 }
phungductung 0:8ede47d38d10 66 return v;
phungductung 0:8ede47d38d10 67 }
phungductung 0:8ede47d38d10 68
phungductung 0:8ede47d38d10 69 void BusInOut::output() {
phungductung 0:8ede47d38d10 70 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 71 if (_pin[i] != 0) {
phungductung 0:8ede47d38d10 72 _pin[i]->output();
phungductung 0:8ede47d38d10 73 }
phungductung 0:8ede47d38d10 74 }
phungductung 0:8ede47d38d10 75 }
phungductung 0:8ede47d38d10 76
phungductung 0:8ede47d38d10 77 void BusInOut::input() {
phungductung 0:8ede47d38d10 78 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 79 if (_pin[i] != 0) {
phungductung 0:8ede47d38d10 80 _pin[i]->input();
phungductung 0:8ede47d38d10 81 }
phungductung 0:8ede47d38d10 82 }
phungductung 0:8ede47d38d10 83 }
phungductung 0:8ede47d38d10 84
phungductung 0:8ede47d38d10 85 void BusInOut::mode(PinMode pull) {
phungductung 0:8ede47d38d10 86 for (int i=0; i<16; i++) {
phungductung 0:8ede47d38d10 87 if (_pin[i] != 0) {
phungductung 0:8ede47d38d10 88 _pin[i]->mode(pull);
phungductung 0:8ede47d38d10 89 }
phungductung 0:8ede47d38d10 90 }
phungductung 0:8ede47d38d10 91 }
phungductung 0:8ede47d38d10 92
phungductung 0:8ede47d38d10 93 #ifdef MBED_OPERATORS
phungductung 0:8ede47d38d10 94 BusInOut& BusInOut::operator= (int v) {
phungductung 0:8ede47d38d10 95 write(v);
phungductung 0:8ede47d38d10 96 return *this;
phungductung 0:8ede47d38d10 97 }
phungductung 0:8ede47d38d10 98
phungductung 0:8ede47d38d10 99 BusInOut& BusInOut::operator= (BusInOut& rhs) {
phungductung 0:8ede47d38d10 100 write(rhs.read());
phungductung 0:8ede47d38d10 101 return *this;
phungductung 0:8ede47d38d10 102 }
phungductung 0:8ede47d38d10 103
phungductung 0:8ede47d38d10 104 DigitalInOut& BusInOut::operator[] (int index) {
phungductung 0:8ede47d38d10 105 MBED_ASSERT(index >= 0 && index <= 16);
phungductung 0:8ede47d38d10 106 MBED_ASSERT(_pin[index]);
phungductung 0:8ede47d38d10 107 return *_pin[index];
phungductung 0:8ede47d38d10 108 }
phungductung 0:8ede47d38d10 109
phungductung 0:8ede47d38d10 110 BusInOut::operator int() {
phungductung 0:8ede47d38d10 111 return read();
phungductung 0:8ede47d38d10 112 }
phungductung 0:8ede47d38d10 113 #endif
phungductung 0:8ede47d38d10 114
phungductung 0:8ede47d38d10 115 } // namespace mbed