mbed library sources
Fork of mbed-src by
Embed:
(wiki syntax)
Show/hide line numbers
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_out(&gpio, pin); 00050 } 00051 00052 /** Create a DigitalOut connected to the specified pin 00053 * 00054 * @param pin DigitalOut pin to connect to 00055 * @param value the initial pin value 00056 */ 00057 DigitalOut(PinName pin, int value){ 00058 gpio_init_out_ex(&gpio, pin, value); 00059 } 00060 00061 /** Set the output, specified as 0 or 1 (int) 00062 * 00063 * @param value An integer specifying the pin output value, 00064 * 0 for logical 0, 1 (or any other non-zero value) for logical 1 00065 */ 00066 void write(int value) { 00067 gpio_write(&gpio, value); 00068 } 00069 00070 /** Return the output setting, represented as 0 or 1 (int) 00071 * 00072 * @returns 00073 * an integer representing the output setting of the pin, 00074 * 0 for logical 0, 1 for logical 1 00075 */ 00076 int read() { 00077 return gpio_read(&gpio); 00078 } 00079 00080 #ifdef MBED_OPERATORS 00081 /** A shorthand for write() 00082 */ 00083 DigitalOut& operator= (int value) { 00084 write(value); 00085 return *this; 00086 } 00087 00088 DigitalOut& operator= (DigitalOut& rhs) { 00089 write(rhs.read()); 00090 return *this; 00091 } 00092 00093 /** A shorthand for read() 00094 */ 00095 operator int() { 00096 return read(); 00097 } 00098 #endif 00099 00100 protected: 00101 gpio_t gpio; 00102 }; 00103 00104 } // namespace mbed 00105 00106 #endif
Generated on Tue Jul 12 2022 21:21:33 by 1.7.2