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/BusIn.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 BusIn::BusIn(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 DigitalIn(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 BusIn::BusIn(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 DigitalIn(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 BusIn::~BusIn() {
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 int BusIn::read() {
thedo 167:1657b442184c 55 int v = 0;
thedo 167:1657b442184c 56 lock();
thedo 167:1657b442184c 57 for (int i=0; i<16; i++) {
thedo 167:1657b442184c 58 if (_pin[i] != 0) {
thedo 167:1657b442184c 59 v |= _pin[i]->read() << i;
thedo 167:1657b442184c 60 }
thedo 167:1657b442184c 61 }
thedo 167:1657b442184c 62 unlock();
thedo 167:1657b442184c 63 return v;
thedo 167:1657b442184c 64 }
thedo 167:1657b442184c 65
thedo 167:1657b442184c 66 void BusIn::mode(PinMode pull) {
thedo 167:1657b442184c 67 lock();
thedo 167:1657b442184c 68 for (int i=0; i<16; i++) {
thedo 167:1657b442184c 69 if (_pin[i] != 0) {
thedo 167:1657b442184c 70 _pin[i]->mode(pull);
thedo 167:1657b442184c 71 }
thedo 167:1657b442184c 72 }
thedo 167:1657b442184c 73 unlock();
thedo 167:1657b442184c 74 }
thedo 167:1657b442184c 75
thedo 167:1657b442184c 76 void BusIn::lock() {
thedo 167:1657b442184c 77 _mutex.lock();
thedo 167:1657b442184c 78 }
thedo 167:1657b442184c 79
thedo 167:1657b442184c 80 void BusIn::unlock() {
thedo 167:1657b442184c 81 _mutex.unlock();
thedo 167:1657b442184c 82 }
thedo 167:1657b442184c 83
thedo 167:1657b442184c 84 BusIn::operator int() {
thedo 167:1657b442184c 85 // Underlying read is thread safe
thedo 167:1657b442184c 86 return read();
thedo 167:1657b442184c 87 }
thedo 167:1657b442184c 88
thedo 167:1657b442184c 89 DigitalIn& BusIn::operator[] (int index) {
thedo 167:1657b442184c 90 // No lock needed since _pin is not modified outside the constructor
thedo 167:1657b442184c 91 MBED_ASSERT(index >= 0 && index <= 16);
thedo 167:1657b442184c 92 MBED_ASSERT(_pin[index]);
thedo 167:1657b442184c 93 return *_pin[index];
thedo 167:1657b442184c 94 }
thedo 167:1657b442184c 95
thedo 167:1657b442184c 96 } // namespace mbed
thedo 167:1657b442184c 97