fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
MikamiUitOpen
Date:
Sun Oct 09 10:11:14 2016 +0000
Revision:
0:3e46577dc273
1

Who changed what in which revision?

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