Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

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