mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
emilmont
Date:
Mon Feb 18 11:44:18 2013 +0000
Revision:
2:143cac498751
Parent:
0:fd0d7bdfcdc2
Update mbed sources to Rev 59

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_DIGITALOUT_H
mbed_official 0:fd0d7bdfcdc2 17 #define MBED_DIGITALOUT_H
mbed_official 0:fd0d7bdfcdc2 18
mbed_official 0:fd0d7bdfcdc2 19 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 20 #include "gpio_api.h"
mbed_official 0:fd0d7bdfcdc2 21
mbed_official 0:fd0d7bdfcdc2 22 namespace mbed {
mbed_official 0:fd0d7bdfcdc2 23
mbed_official 0:fd0d7bdfcdc2 24 /** A digital output, used for setting the state of a pin
mbed_official 0:fd0d7bdfcdc2 25 *
mbed_official 0:fd0d7bdfcdc2 26 * Example:
mbed_official 0:fd0d7bdfcdc2 27 * @code
mbed_official 0:fd0d7bdfcdc2 28 * // Toggle a LED
mbed_official 0:fd0d7bdfcdc2 29 * #include "mbed.h"
emilmont 2:143cac498751 30 *
mbed_official 0:fd0d7bdfcdc2 31 * DigitalOut led(LED1);
emilmont 2:143cac498751 32 *
mbed_official 0:fd0d7bdfcdc2 33 * int main() {
mbed_official 0:fd0d7bdfcdc2 34 * while(1) {
mbed_official 0:fd0d7bdfcdc2 35 * led = !led;
mbed_official 0:fd0d7bdfcdc2 36 * wait(0.2);
mbed_official 0:fd0d7bdfcdc2 37 * }
mbed_official 0:fd0d7bdfcdc2 38 * }
mbed_official 0:fd0d7bdfcdc2 39 * @endcode
mbed_official 0:fd0d7bdfcdc2 40 */
mbed_official 0:fd0d7bdfcdc2 41 class DigitalOut {
mbed_official 0:fd0d7bdfcdc2 42
mbed_official 0:fd0d7bdfcdc2 43 public:
mbed_official 0:fd0d7bdfcdc2 44 /** Create a DigitalOut connected to the specified pin
mbed_official 0:fd0d7bdfcdc2 45 *
mbed_official 0:fd0d7bdfcdc2 46 * @param pin DigitalOut pin to connect to
mbed_official 0:fd0d7bdfcdc2 47 */
mbed_official 0:fd0d7bdfcdc2 48 DigitalOut(PinName pin) {
mbed_official 0:fd0d7bdfcdc2 49 gpio_init(&gpio, pin, PIN_OUTPUT);
mbed_official 0:fd0d7bdfcdc2 50 }
emilmont 2:143cac498751 51
mbed_official 0:fd0d7bdfcdc2 52 /** Set the output, specified as 0 or 1 (int)
mbed_official 0:fd0d7bdfcdc2 53 *
emilmont 2:143cac498751 54 * @param value An integer specifying the pin output value,
emilmont 2:143cac498751 55 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
mbed_official 0:fd0d7bdfcdc2 56 */
mbed_official 0:fd0d7bdfcdc2 57 void write(int value) {
mbed_official 0:fd0d7bdfcdc2 58 gpio_write(&gpio, value);
mbed_official 0:fd0d7bdfcdc2 59 }
emilmont 2:143cac498751 60
mbed_official 0:fd0d7bdfcdc2 61 /** Return the output setting, represented as 0 or 1 (int)
mbed_official 0:fd0d7bdfcdc2 62 *
mbed_official 0:fd0d7bdfcdc2 63 * @returns
emilmont 2:143cac498751 64 * an integer representing the output setting of the pin,
mbed_official 0:fd0d7bdfcdc2 65 * 0 for logical 0, 1 for logical 1
mbed_official 0:fd0d7bdfcdc2 66 */
mbed_official 0:fd0d7bdfcdc2 67 int read() {
mbed_official 0:fd0d7bdfcdc2 68 return gpio_read(&gpio);
mbed_official 0:fd0d7bdfcdc2 69 }
emilmont 2:143cac498751 70
mbed_official 0:fd0d7bdfcdc2 71 #ifdef MBED_OPERATORS
mbed_official 0:fd0d7bdfcdc2 72 /** A shorthand for write()
mbed_official 0:fd0d7bdfcdc2 73 */
mbed_official 0:fd0d7bdfcdc2 74 DigitalOut& operator= (int value) {
mbed_official 0:fd0d7bdfcdc2 75 write(value);
mbed_official 0:fd0d7bdfcdc2 76 return *this;
mbed_official 0:fd0d7bdfcdc2 77 }
emilmont 2:143cac498751 78
mbed_official 0:fd0d7bdfcdc2 79 DigitalOut& operator= (DigitalOut& rhs) {
mbed_official 0:fd0d7bdfcdc2 80 write(rhs.read());
mbed_official 0:fd0d7bdfcdc2 81 return *this;
mbed_official 0:fd0d7bdfcdc2 82 }
emilmont 2:143cac498751 83
mbed_official 0:fd0d7bdfcdc2 84 /** A shorthand for read()
mbed_official 0:fd0d7bdfcdc2 85 */
mbed_official 0:fd0d7bdfcdc2 86 operator int() {
mbed_official 0:fd0d7bdfcdc2 87 return read();
mbed_official 0:fd0d7bdfcdc2 88 }
mbed_official 0:fd0d7bdfcdc2 89 #endif
mbed_official 0:fd0d7bdfcdc2 90
mbed_official 0:fd0d7bdfcdc2 91 protected:
mbed_official 0:fd0d7bdfcdc2 92 gpio_t gpio;
mbed_official 0:fd0d7bdfcdc2 93 };
mbed_official 0:fd0d7bdfcdc2 94
mbed_official 0:fd0d7bdfcdc2 95 } // namespace mbed
mbed_official 0:fd0d7bdfcdc2 96
emilmont 2:143cac498751 97 #endif