Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of CRAC-Strat_2017_homologation_gros_rob by
DigitalInOut.h
00001 /* mbed Microcontroller Library - DigitalInOut 00002 * Copyright (c) 2006-2011 ARM Limited. All rights reserved. 00003 */ 00004 00005 #ifndef MBED_DIGITALINOUT_H 00006 #define MBED_DIGITALINOUT_H 00007 00008 #include "platform.h" 00009 #include "PinNames.h" 00010 #include "PeripheralNames.h" 00011 #include "Base.h" 00012 00013 namespace mbed { 00014 00015 /* Class: DigitalInOut 00016 * A digital input/output, used for setting or reading a bi-directional pin 00017 */ 00018 class DigitalInOut : public Base { 00019 00020 public: 00021 00022 /* Constructor: DigitalInOut 00023 * Create a DigitalInOut connected to the specified pin 00024 * 00025 * Variables: 00026 * pin - DigitalInOut pin to connect to 00027 */ 00028 DigitalInOut(PinName pin, const char* name = NULL); 00029 00030 /* Function: write 00031 * Set the output, specified as 0 or 1 (int) 00032 * 00033 * Variables: 00034 * value - An integer specifying the pin output value, 00035 * 0 for logical 0 and 1 (or any other non-zero value) for logical 1 00036 */ 00037 void write(int value) { 00038 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) 00039 00040 if(value) { 00041 _gpio->FIOSET = _mask; 00042 } else { 00043 _gpio->FIOCLR = _mask; 00044 } 00045 00046 #elif defined(TARGET_LPC11U24) 00047 00048 if(value) { 00049 LPC_GPIO->SET[_index] = _mask; 00050 } else { 00051 LPC_GPIO->CLR[_index] = _mask; 00052 } 00053 #endif 00054 } 00055 00056 /* Function: read 00057 * Return the output setting, represented as 0 or 1 (int) 00058 * 00059 * Variables: 00060 * returns - An integer representing the output setting of the pin if it is an output, 00061 * or read the input if set as an input 00062 */ 00063 int read() { 00064 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) 00065 00066 return ((_gpio->FIOPIN & _mask) ? 1 : 0); 00067 #elif defined(TARGET_LPC11U24) 00068 return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0); 00069 #endif 00070 } 00071 00072 00073 /* Function: output 00074 * Set as an output 00075 */ 00076 void output(); 00077 00078 /* Function: input 00079 * Set as an input 00080 */ 00081 void input(); 00082 00083 /* Function: mode 00084 * Set the input pin mode 00085 * 00086 * Variables: 00087 * mode - PullUp, PullDown, PullNone, OpenDrain 00088 */ 00089 void mode(PinMode pull); 00090 00091 #ifdef MBED_OPERATORS 00092 /* Function: operator= 00093 * A shorthand for <write> 00094 */ 00095 DigitalInOut& operator= (int value) { 00096 write(value); 00097 return *this; 00098 } 00099 00100 DigitalInOut& operator= (DigitalInOut& rhs) { 00101 write(rhs.read()); 00102 return *this; 00103 } 00104 00105 /* Function: operator int() 00106 * A shorthand for <read> 00107 */ 00108 operator int() { 00109 return read(); 00110 } 00111 #endif 00112 00113 #ifdef MBED_RPC 00114 virtual const struct rpc_method *get_rpc_methods(); 00115 static struct rpc_class *get_rpc_class(); 00116 #endif 00117 00118 protected: 00119 00120 PinName _pin; 00121 00122 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) 00123 LPC_GPIO_TypeDef *_gpio; 00124 #elif defined(TARGET_LPC11U24) 00125 int _index; 00126 #endif 00127 00128 uint32_t _mask; 00129 00130 }; 00131 00132 } // namespace mbed 00133 00134 #endif
Generated on Tue Jul 12 2022 19:28:47 by
