Modified version of the official mbed-src lib. Provides some tiny but rather intrusive addons in the i2c-api.h for the mbed-RtosI2cDriver lib.

Fork of mbed-src by mbed official

Committer:
humlet
Date:
Tue Apr 30 19:12:46 2013 +0000
Revision:
9:49923059ddc8
Parent:
2:143cac498751
alpha2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
emilmont 2:143cac498751 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
emilmont 2:143cac498751 4 * Licensed under the Apache License, Version 2.0 (the "License");
emilmont 2:143cac498751 5 * you may not use this file except in compliance with the License.
emilmont 2:143cac498751 6 * You may obtain a copy of the License at
mbed_official 0:fd0d7bdfcdc2 7 *
emilmont 2:143cac498751 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:fd0d7bdfcdc2 9 *
emilmont 2:143cac498751 10 * Unless required by applicable law or agreed to in writing, software
emilmont 2:143cac498751 11 * distributed under the License is distributed on an "AS IS" BASIS,
emilmont 2:143cac498751 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
emilmont 2:143cac498751 13 * See the License for the specific language governing permissions and
emilmont 2:143cac498751 14 * limitations under the License.
mbed_official 0:fd0d7bdfcdc2 15 */
mbed_official 0:fd0d7bdfcdc2 16 #ifndef MBED_DIGITALINOUT_H
mbed_official 0:fd0d7bdfcdc2 17 #define MBED_DIGITALINOUT_H
mbed_official 0:fd0d7bdfcdc2 18
mbed_official 0:fd0d7bdfcdc2 19 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 20
mbed_official 0:fd0d7bdfcdc2 21 #include "gpio_api.h"
mbed_official 0:fd0d7bdfcdc2 22
mbed_official 0:fd0d7bdfcdc2 23 namespace mbed {
mbed_official 0:fd0d7bdfcdc2 24
mbed_official 0:fd0d7bdfcdc2 25 /** A digital input/output, used for setting or reading a bi-directional pin
mbed_official 0:fd0d7bdfcdc2 26 */
mbed_official 0:fd0d7bdfcdc2 27 class DigitalInOut {
mbed_official 0:fd0d7bdfcdc2 28
mbed_official 0:fd0d7bdfcdc2 29 public:
mbed_official 0:fd0d7bdfcdc2 30 /** Create a DigitalInOut connected to the specified pin
mbed_official 0:fd0d7bdfcdc2 31 *
mbed_official 0:fd0d7bdfcdc2 32 * @param pin DigitalInOut pin to connect to
mbed_official 0:fd0d7bdfcdc2 33 */
mbed_official 0:fd0d7bdfcdc2 34 DigitalInOut(PinName pin) {
mbed_official 0:fd0d7bdfcdc2 35 gpio_init(&gpio, pin, PIN_INPUT);
mbed_official 0:fd0d7bdfcdc2 36 }
emilmont 2:143cac498751 37
mbed_official 0:fd0d7bdfcdc2 38 /** Set the output, specified as 0 or 1 (int)
mbed_official 0:fd0d7bdfcdc2 39 *
emilmont 2:143cac498751 40 * @param value An integer specifying the pin output value,
emilmont 2:143cac498751 41 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
mbed_official 0:fd0d7bdfcdc2 42 */
mbed_official 0:fd0d7bdfcdc2 43 void write(int value) {
mbed_official 0:fd0d7bdfcdc2 44 gpio_write(&gpio, value);
mbed_official 0:fd0d7bdfcdc2 45 }
emilmont 2:143cac498751 46
mbed_official 0:fd0d7bdfcdc2 47 /** Return the output setting, represented as 0 or 1 (int)
mbed_official 0:fd0d7bdfcdc2 48 *
mbed_official 0:fd0d7bdfcdc2 49 * @returns
emilmont 2:143cac498751 50 * an integer representing the output setting of the pin if it is an output,
mbed_official 0:fd0d7bdfcdc2 51 * or read the input if set as an input
mbed_official 0:fd0d7bdfcdc2 52 */
mbed_official 0:fd0d7bdfcdc2 53 int read() {
mbed_official 0:fd0d7bdfcdc2 54 return gpio_read(&gpio);
mbed_official 0:fd0d7bdfcdc2 55 }
emilmont 2:143cac498751 56
mbed_official 0:fd0d7bdfcdc2 57 /** Set as an output
mbed_official 0:fd0d7bdfcdc2 58 */
mbed_official 0:fd0d7bdfcdc2 59 void output() {
mbed_official 0:fd0d7bdfcdc2 60 gpio_dir(&gpio, PIN_OUTPUT);
mbed_official 0:fd0d7bdfcdc2 61 }
emilmont 2:143cac498751 62
mbed_official 0:fd0d7bdfcdc2 63 /** Set as an input
mbed_official 0:fd0d7bdfcdc2 64 */
mbed_official 0:fd0d7bdfcdc2 65 void input() {
mbed_official 0:fd0d7bdfcdc2 66 gpio_dir(&gpio, PIN_INPUT);
mbed_official 0:fd0d7bdfcdc2 67 }
emilmont 2:143cac498751 68
mbed_official 0:fd0d7bdfcdc2 69 /** Set the input pin mode
mbed_official 0:fd0d7bdfcdc2 70 *
mbed_official 0:fd0d7bdfcdc2 71 * @param mode PullUp, PullDown, PullNone, OpenDrain
mbed_official 0:fd0d7bdfcdc2 72 */
mbed_official 0:fd0d7bdfcdc2 73 void mode(PinMode pull) {
mbed_official 0:fd0d7bdfcdc2 74 gpio_mode(&gpio, pull);
mbed_official 0:fd0d7bdfcdc2 75 }
emilmont 2:143cac498751 76
mbed_official 0:fd0d7bdfcdc2 77 #ifdef MBED_OPERATORS
mbed_official 0:fd0d7bdfcdc2 78 /** A shorthand for write()
mbed_official 0:fd0d7bdfcdc2 79 */
mbed_official 0:fd0d7bdfcdc2 80 DigitalInOut& operator= (int value) {
mbed_official 0:fd0d7bdfcdc2 81 write(value);
mbed_official 0:fd0d7bdfcdc2 82 return *this;
mbed_official 0:fd0d7bdfcdc2 83 }
emilmont 2:143cac498751 84
mbed_official 0:fd0d7bdfcdc2 85 DigitalInOut& operator= (DigitalInOut& rhs) {
mbed_official 0:fd0d7bdfcdc2 86 write(rhs.read());
mbed_official 0:fd0d7bdfcdc2 87 return *this;
mbed_official 0:fd0d7bdfcdc2 88 }
emilmont 2:143cac498751 89
mbed_official 0:fd0d7bdfcdc2 90 /** A shorthand for read()
mbed_official 0:fd0d7bdfcdc2 91 */
mbed_official 0:fd0d7bdfcdc2 92 operator int() {
mbed_official 0:fd0d7bdfcdc2 93 return read();
mbed_official 0:fd0d7bdfcdc2 94 }
mbed_official 0:fd0d7bdfcdc2 95 #endif
mbed_official 0:fd0d7bdfcdc2 96
mbed_official 0:fd0d7bdfcdc2 97 protected:
mbed_official 0:fd0d7bdfcdc2 98 gpio_t gpio;
mbed_official 0:fd0d7bdfcdc2 99 };
mbed_official 0:fd0d7bdfcdc2 100
mbed_official 0:fd0d7bdfcdc2 101 } // namespace mbed
mbed_official 0:fd0d7bdfcdc2 102
mbed_official 0:fd0d7bdfcdc2 103 #endif