fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
aria19970520
Date:
Fri Mar 06 06:52:14 2020 +0000
Revision:
3:6f7e05dd8d15
Parent:
0:3e46577dc273
fft

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 "BusOut.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 BusOut::BusOut(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 DigitalOut(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 BusOut::BusOut(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 DigitalOut(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 BusOut::~BusOut() {
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 BusOut::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 BusOut::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 #ifdef MBED_OPERATORS
MikamiUitOpen 0:3e46577dc273 70 BusOut& BusOut::operator= (int v) {
MikamiUitOpen 0:3e46577dc273 71 write(v);
MikamiUitOpen 0:3e46577dc273 72 return *this;
MikamiUitOpen 0:3e46577dc273 73 }
MikamiUitOpen 0:3e46577dc273 74
MikamiUitOpen 0:3e46577dc273 75 BusOut& BusOut::operator= (BusOut& rhs) {
MikamiUitOpen 0:3e46577dc273 76 write(rhs.read());
MikamiUitOpen 0:3e46577dc273 77 return *this;
MikamiUitOpen 0:3e46577dc273 78 }
MikamiUitOpen 0:3e46577dc273 79
MikamiUitOpen 0:3e46577dc273 80 DigitalOut& BusOut::operator[] (int index) {
MikamiUitOpen 0:3e46577dc273 81 MBED_ASSERT(index >= 0 && index <= 16);
MikamiUitOpen 0:3e46577dc273 82 MBED_ASSERT(_pin[index]);
MikamiUitOpen 0:3e46577dc273 83 return *_pin[index];
MikamiUitOpen 0:3e46577dc273 84 }
MikamiUitOpen 0:3e46577dc273 85
MikamiUitOpen 0:3e46577dc273 86 BusOut::operator int() {
MikamiUitOpen 0:3e46577dc273 87 return read();
MikamiUitOpen 0:3e46577dc273 88 }
MikamiUitOpen 0:3e46577dc273 89 #endif
MikamiUitOpen 0:3e46577dc273 90
MikamiUitOpen 0:3e46577dc273 91 } // namespace mbed