Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

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