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/BusOut.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 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) {
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 DigitalOut(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 BusOut::BusOut(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 DigitalOut(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 BusOut::~BusOut() {
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 BusOut::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 BusOut::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 BusOut& BusOut::operator= (int v) {
thedo 167:1657b442184c 77 // Underlying write is thread safe
thedo 167:1657b442184c 78 write(v);
thedo 167:1657b442184c 79 return *this;
thedo 167:1657b442184c 80 }
thedo 167:1657b442184c 81
thedo 167:1657b442184c 82 BusOut& BusOut::operator= (BusOut& rhs) {
thedo 167:1657b442184c 83 // Underlying write is thread safe
thedo 167:1657b442184c 84 write(rhs.read());
thedo 167:1657b442184c 85 return *this;
thedo 167:1657b442184c 86 }
thedo 167:1657b442184c 87
thedo 167:1657b442184c 88 DigitalOut& BusOut::operator[] (int index) {
thedo 167:1657b442184c 89 // No lock needed since _pin is not modified outside the constructor
thedo 167:1657b442184c 90 MBED_ASSERT(index >= 0 && index <= 16);
thedo 167:1657b442184c 91 MBED_ASSERT(_pin[index]);
thedo 167:1657b442184c 92 return *_pin[index];
thedo 167:1657b442184c 93 }
thedo 167:1657b442184c 94
thedo 167:1657b442184c 95 BusOut::operator int() {
thedo 167:1657b442184c 96 // Underlying read is thread safe
thedo 167:1657b442184c 97 return read();
thedo 167:1657b442184c 98 }
thedo 167:1657b442184c 99
thedo 167:1657b442184c 100 void BusOut::lock() {
thedo 167:1657b442184c 101 _mutex.lock();
thedo 167:1657b442184c 102 }
thedo 167:1657b442184c 103
thedo 167:1657b442184c 104 void BusOut::unlock() {
thedo 167:1657b442184c 105 _mutex.unlock();
thedo 167:1657b442184c 106 }
thedo 167:1657b442184c 107
thedo 167:1657b442184c 108 } // namespace mbed
thedo 167:1657b442184c 109