PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 18:03:02 2017 +0000
Revision:
11:02ad9c807a21
Parent:
5:7e5c566b1760
fixed 4color refreshRegion code

Who changed what in which revision?

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