Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Wed Oct 10 00:33:53 2018 +0000
Revision:
0:8fdf9a60065b
how to make mbed librry

Who changed what in which revision?

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