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/BusInOut.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 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) {
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 DigitalInOut(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 BusInOut::BusInOut(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 DigitalInOut(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 BusInOut::~BusInOut() {
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 BusInOut::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 BusInOut::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 void BusInOut::output() {
switches 0:5c4d7b2438d3 77 lock();
switches 0:5c4d7b2438d3 78 for (int i=0; i<16; i++) {
switches 0:5c4d7b2438d3 79 if (_pin[i] != 0) {
switches 0:5c4d7b2438d3 80 _pin[i]->output();
switches 0:5c4d7b2438d3 81 }
switches 0:5c4d7b2438d3 82 }
switches 0:5c4d7b2438d3 83 unlock();
switches 0:5c4d7b2438d3 84 }
switches 0:5c4d7b2438d3 85
switches 0:5c4d7b2438d3 86 void BusInOut::input() {
switches 0:5c4d7b2438d3 87 lock();
switches 0:5c4d7b2438d3 88 for (int i=0; i<16; i++) {
switches 0:5c4d7b2438d3 89 if (_pin[i] != 0) {
switches 0:5c4d7b2438d3 90 _pin[i]->input();
switches 0:5c4d7b2438d3 91 }
switches 0:5c4d7b2438d3 92 }
switches 0:5c4d7b2438d3 93 unlock();
switches 0:5c4d7b2438d3 94 }
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96 void BusInOut::mode(PinMode pull) {
switches 0:5c4d7b2438d3 97 lock();
switches 0:5c4d7b2438d3 98 for (int i=0; i<16; i++) {
switches 0:5c4d7b2438d3 99 if (_pin[i] != 0) {
switches 0:5c4d7b2438d3 100 _pin[i]->mode(pull);
switches 0:5c4d7b2438d3 101 }
switches 0:5c4d7b2438d3 102 }
switches 0:5c4d7b2438d3 103 unlock();
switches 0:5c4d7b2438d3 104 }
switches 0:5c4d7b2438d3 105
switches 0:5c4d7b2438d3 106 BusInOut& BusInOut::operator= (int v) {
switches 0:5c4d7b2438d3 107 // Underlying write is thread safe
switches 0:5c4d7b2438d3 108 write(v);
switches 0:5c4d7b2438d3 109 return *this;
switches 0:5c4d7b2438d3 110 }
switches 0:5c4d7b2438d3 111
switches 0:5c4d7b2438d3 112 BusInOut& BusInOut::operator= (BusInOut& rhs) {
switches 0:5c4d7b2438d3 113 // Underlying read is thread safe
switches 0:5c4d7b2438d3 114 write(rhs.read());
switches 0:5c4d7b2438d3 115 return *this;
switches 0:5c4d7b2438d3 116 }
switches 0:5c4d7b2438d3 117
switches 0:5c4d7b2438d3 118 DigitalInOut& BusInOut::operator[] (int index) {
switches 0:5c4d7b2438d3 119 // No lock needed since _pin is not modified outside the constructor
switches 0:5c4d7b2438d3 120 MBED_ASSERT(index >= 0 && index <= 16);
switches 0:5c4d7b2438d3 121 MBED_ASSERT(_pin[index]);
switches 0:5c4d7b2438d3 122 return *_pin[index];
switches 0:5c4d7b2438d3 123 }
switches 0:5c4d7b2438d3 124
switches 0:5c4d7b2438d3 125 BusInOut::operator int() {
switches 0:5c4d7b2438d3 126 // Underlying read is thread safe
switches 0:5c4d7b2438d3 127 return read();
switches 0:5c4d7b2438d3 128 }
switches 0:5c4d7b2438d3 129
switches 0:5c4d7b2438d3 130 void BusInOut::lock() {
switches 0:5c4d7b2438d3 131 _mutex.lock();
switches 0:5c4d7b2438d3 132 }
switches 0:5c4d7b2438d3 133
switches 0:5c4d7b2438d3 134 void BusInOut::unlock() {
switches 0:5c4d7b2438d3 135 _mutex.unlock();
switches 0:5c4d7b2438d3 136 }
switches 0:5c4d7b2438d3 137
switches 0:5c4d7b2438d3 138 } // namespace mbed