The official mbed C/C SDK provides the software platform and libraries to build your applications.
Fork of mbed by
DigitalOut.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_DIGITALOUT_H 00017 #define MBED_DIGITALOUT_H 00018 00019 #include "platform.h" 00020 #include "gpio_api.h" 00021 00022 namespace mbed { 00023 00024 /** A digital output, used for setting the state of a pin 00025 * 00026 * Example: 00027 * @code 00028 * // Toggle a LED 00029 * #include "mbed.h" 00030 * 00031 * DigitalOut led(LED1); 00032 * 00033 * int main() { 00034 * while(1) { 00035 * led = !led; 00036 * wait(0.2); 00037 * } 00038 * } 00039 * @endcode 00040 */ 00041 class DigitalOut { 00042 00043 public: 00044 /** Create a DigitalOut connected to the specified pin 00045 * 00046 * @param pin DigitalOut pin to connect to 00047 */ 00048 DigitalOut(PinName pin) { 00049 gpio_init(&gpio, pin, PIN_OUTPUT); 00050 } 00051 00052 /** Set the output, specified as 0 or 1 (int) 00053 * 00054 * @param value An integer specifying the pin output value, 00055 * 0 for logical 0, 1 (or any other non-zero value) for logical 1 00056 */ 00057 void write(int value) { 00058 gpio_write(&gpio, value); 00059 } 00060 00061 /** Return the output setting, represented as 0 or 1 (int) 00062 * 00063 * @returns 00064 * an integer representing the output setting of the pin, 00065 * 0 for logical 0, 1 for logical 1 00066 */ 00067 int read() { 00068 return gpio_read(&gpio); 00069 } 00070 00071 #ifdef MBED_OPERATORS 00072 /** A shorthand for write() 00073 */ 00074 DigitalOut& operator= (int value) { 00075 write(value); 00076 return *this; 00077 } 00078 00079 DigitalOut& operator= (DigitalOut& rhs) { 00080 write(rhs.read()); 00081 return *this; 00082 } 00083 00084 /** A shorthand for read() 00085 */ 00086 operator int() { 00087 return read(); 00088 } 00089 #endif 00090 00091 protected: 00092 gpio_t gpio; 00093 }; 00094 00095 } // namespace mbed 00096 00097 #endif
Generated on Sat Jul 16 2022 06:59:32 by 1.7.2