mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c
Dependents: Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay
Fork of mbed-dev by
drivers/BusIn.cpp@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /* mbed Microcontroller Library |
<> | 149:156823d33999 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 149:156823d33999 | 3 | * |
<> | 149:156823d33999 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 149:156823d33999 | 5 | * you may not use this file except in compliance with the License. |
<> | 149:156823d33999 | 6 | * You may obtain a copy of the License at |
<> | 149:156823d33999 | 7 | * |
<> | 149:156823d33999 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 149:156823d33999 | 9 | * |
<> | 149:156823d33999 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 149:156823d33999 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 149:156823d33999 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 149:156823d33999 | 13 | * See the License for the specific language governing permissions and |
<> | 149:156823d33999 | 14 | * limitations under the License. |
<> | 149:156823d33999 | 15 | */ |
<> | 149:156823d33999 | 16 | #include "drivers/BusIn.h" |
<> | 149:156823d33999 | 17 | #include "platform/mbed_assert.h" |
<> | 149:156823d33999 | 18 | |
<> | 149:156823d33999 | 19 | namespace mbed { |
<> | 149:156823d33999 | 20 | |
<> | 149:156823d33999 | 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) { |
<> | 149:156823d33999 | 22 | PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15}; |
<> | 149:156823d33999 | 23 | |
<> | 149:156823d33999 | 24 | // No lock needed in the constructor |
<> | 149:156823d33999 | 25 | _nc_mask = 0; |
<> | 149:156823d33999 | 26 | for (int i=0; i<16; i++) { |
<> | 149:156823d33999 | 27 | _pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0; |
<> | 149:156823d33999 | 28 | if (pins[i] != NC) { |
<> | 149:156823d33999 | 29 | _nc_mask |= (1 << i); |
<> | 149:156823d33999 | 30 | } |
<> | 149:156823d33999 | 31 | } |
<> | 149:156823d33999 | 32 | } |
<> | 149:156823d33999 | 33 | |
<> | 149:156823d33999 | 34 | BusIn::BusIn(PinName pins[16]) { |
<> | 149:156823d33999 | 35 | // No lock needed in the constructor |
<> | 149:156823d33999 | 36 | _nc_mask = 0; |
<> | 149:156823d33999 | 37 | for (int i=0; i<16; i++) { |
<> | 149:156823d33999 | 38 | _pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0; |
<> | 149:156823d33999 | 39 | if (pins[i] != NC) { |
<> | 149:156823d33999 | 40 | _nc_mask |= (1 << i); |
<> | 149:156823d33999 | 41 | } |
<> | 149:156823d33999 | 42 | } |
<> | 149:156823d33999 | 43 | } |
<> | 149:156823d33999 | 44 | |
<> | 149:156823d33999 | 45 | BusIn::~BusIn() { |
<> | 149:156823d33999 | 46 | // No lock needed in the destructor |
<> | 149:156823d33999 | 47 | for (int i=0; i<16; i++) { |
<> | 149:156823d33999 | 48 | if (_pin[i] != 0) { |
<> | 149:156823d33999 | 49 | delete _pin[i]; |
<> | 149:156823d33999 | 50 | } |
<> | 149:156823d33999 | 51 | } |
<> | 149:156823d33999 | 52 | } |
<> | 149:156823d33999 | 53 | |
<> | 149:156823d33999 | 54 | int BusIn::read() { |
<> | 149:156823d33999 | 55 | int v = 0; |
<> | 149:156823d33999 | 56 | lock(); |
<> | 149:156823d33999 | 57 | for (int i=0; i<16; i++) { |
<> | 149:156823d33999 | 58 | if (_pin[i] != 0) { |
<> | 149:156823d33999 | 59 | v |= _pin[i]->read() << i; |
<> | 149:156823d33999 | 60 | } |
<> | 149:156823d33999 | 61 | } |
<> | 149:156823d33999 | 62 | unlock(); |
<> | 149:156823d33999 | 63 | return v; |
<> | 149:156823d33999 | 64 | } |
<> | 149:156823d33999 | 65 | |
<> | 149:156823d33999 | 66 | void BusIn::mode(PinMode pull) { |
<> | 149:156823d33999 | 67 | lock(); |
<> | 149:156823d33999 | 68 | for (int i=0; i<16; i++) { |
<> | 149:156823d33999 | 69 | if (_pin[i] != 0) { |
<> | 149:156823d33999 | 70 | _pin[i]->mode(pull); |
<> | 149:156823d33999 | 71 | } |
<> | 149:156823d33999 | 72 | } |
<> | 149:156823d33999 | 73 | unlock(); |
<> | 149:156823d33999 | 74 | } |
<> | 149:156823d33999 | 75 | |
<> | 149:156823d33999 | 76 | void BusIn::lock() { |
<> | 149:156823d33999 | 77 | _mutex.lock(); |
<> | 149:156823d33999 | 78 | } |
<> | 149:156823d33999 | 79 | |
<> | 149:156823d33999 | 80 | void BusIn::unlock() { |
<> | 149:156823d33999 | 81 | _mutex.unlock(); |
<> | 149:156823d33999 | 82 | } |
<> | 149:156823d33999 | 83 | |
<> | 149:156823d33999 | 84 | BusIn::operator int() { |
<> | 149:156823d33999 | 85 | // Underlying read is thread safe |
<> | 149:156823d33999 | 86 | return read(); |
<> | 149:156823d33999 | 87 | } |
<> | 149:156823d33999 | 88 | |
<> | 149:156823d33999 | 89 | DigitalIn& BusIn::operator[] (int index) { |
<> | 149:156823d33999 | 90 | // No lock needed since _pin is not modified outside the constructor |
<> | 149:156823d33999 | 91 | MBED_ASSERT(index >= 0 && index <= 16); |
<> | 149:156823d33999 | 92 | MBED_ASSERT(_pin[index]); |
<> | 149:156823d33999 | 93 | return *_pin[index]; |
<> | 149:156823d33999 | 94 | } |
<> | 149:156823d33999 | 95 | |
<> | 149:156823d33999 | 96 | } // namespace mbed |