Soundharrajan

Fork of mbed by mbed official

Committer:
mrsoundhar
Date:
Sun Jun 12 16:45:04 2016 +0000
Revision:
92:f7fcbaa5f1b5
Parent:
27:7110ebee3484
Child:
43:e2ed12d17f06
Soundharrajan

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rolf.meyer@arm.com 11:1c1ebd0324fa 1 /* mbed Microcontroller Library - DigitalInOut
emilmont 27:7110ebee3484 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
rolf.meyer@arm.com 11:1c1ebd0324fa 3 */
rolf.meyer@arm.com 11:1c1ebd0324fa 4
rolf.meyer@arm.com 11:1c1ebd0324fa 5 #ifndef MBED_DIGITALINOUT_H
rolf.meyer@arm.com 11:1c1ebd0324fa 6 #define MBED_DIGITALINOUT_H
rolf.meyer@arm.com 11:1c1ebd0324fa 7
rolf.meyer@arm.com 11:1c1ebd0324fa 8 #include "platform.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 9 #include "PinNames.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 10 #include "PeripheralNames.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 11 #include "Base.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 12
rolf.meyer@arm.com 11:1c1ebd0324fa 13 namespace mbed {
rolf.meyer@arm.com 11:1c1ebd0324fa 14
rolf.meyer@arm.com 11:1c1ebd0324fa 15 /* Class: DigitalInOut
rolf.meyer@arm.com 11:1c1ebd0324fa 16 * A digital input/output, used for setting or reading a bi-directional pin
rolf.meyer@arm.com 11:1c1ebd0324fa 17 */
rolf.meyer@arm.com 11:1c1ebd0324fa 18 class DigitalInOut : public Base {
rolf.meyer@arm.com 11:1c1ebd0324fa 19
rolf.meyer@arm.com 11:1c1ebd0324fa 20 public:
rolf.meyer@arm.com 11:1c1ebd0324fa 21
rolf.meyer@arm.com 11:1c1ebd0324fa 22 /* Constructor: DigitalInOut
rolf.meyer@arm.com 11:1c1ebd0324fa 23 * Create a DigitalInOut connected to the specified pin
rolf.meyer@arm.com 11:1c1ebd0324fa 24 *
rolf.meyer@arm.com 11:1c1ebd0324fa 25 * Variables:
rolf.meyer@arm.com 11:1c1ebd0324fa 26 * pin - DigitalInOut pin to connect to
rolf.meyer@arm.com 11:1c1ebd0324fa 27 */
rolf.meyer@arm.com 11:1c1ebd0324fa 28 DigitalInOut(PinName pin, const char* name = NULL);
rolf.meyer@arm.com 11:1c1ebd0324fa 29
rolf.meyer@arm.com 11:1c1ebd0324fa 30 /* Function: write
rolf.meyer@arm.com 11:1c1ebd0324fa 31 * Set the output, specified as 0 or 1 (int)
rolf.meyer@arm.com 11:1c1ebd0324fa 32 *
rolf.meyer@arm.com 11:1c1ebd0324fa 33 * Variables:
rolf.meyer@arm.com 11:1c1ebd0324fa 34 * value - An integer specifying the pin output value,
rolf.meyer@arm.com 11:1c1ebd0324fa 35 * 0 for logical 0 and 1 (or any other non-zero value) for logical 1
rolf.meyer@arm.com 11:1c1ebd0324fa 36 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 37 void write(int value) {
emilmont 27:7110ebee3484 38 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
emilmont 27:7110ebee3484 39
simon.ford@mbed.co.uk 18:b3c9f16cbb96 40 if(value) {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 41 _gpio->FIOSET = _mask;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 42 } else {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 43 _gpio->FIOCLR = _mask;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 44 }
emilmont 27:7110ebee3484 45
emilmont 27:7110ebee3484 46 #elif defined(TARGET_LPC11U24)
emilmont 27:7110ebee3484 47
emilmont 27:7110ebee3484 48 if(value) {
emilmont 27:7110ebee3484 49 LPC_GPIO->SET[_index] = _mask;
emilmont 27:7110ebee3484 50 } else {
emilmont 27:7110ebee3484 51 LPC_GPIO->CLR[_index] = _mask;
emilmont 27:7110ebee3484 52 }
emilmont 27:7110ebee3484 53 #endif
simon.ford@mbed.co.uk 18:b3c9f16cbb96 54 }
rolf.meyer@arm.com 11:1c1ebd0324fa 55
rolf.meyer@arm.com 11:1c1ebd0324fa 56 /* Function: read
rolf.meyer@arm.com 11:1c1ebd0324fa 57 * Return the output setting, represented as 0 or 1 (int)
rolf.meyer@arm.com 11:1c1ebd0324fa 58 *
rolf.meyer@arm.com 11:1c1ebd0324fa 59 * Variables:
rolf.meyer@arm.com 11:1c1ebd0324fa 60 * returns - An integer representing the output setting of the pin if it is an output,
rolf.meyer@arm.com 11:1c1ebd0324fa 61 * or read the input if set as an input
rolf.meyer@arm.com 11:1c1ebd0324fa 62 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 63 int read() {
emilmont 27:7110ebee3484 64 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
emilmont 27:7110ebee3484 65
simon.ford@mbed.co.uk 18:b3c9f16cbb96 66 return ((_gpio->FIOPIN & _mask) ? 1 : 0);
emilmont 27:7110ebee3484 67 #elif defined(TARGET_LPC11U24)
emilmont 27:7110ebee3484 68 return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0);
emilmont 27:7110ebee3484 69 #endif
simon.ford@mbed.co.uk 18:b3c9f16cbb96 70 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 71
rolf.meyer@arm.com 11:1c1ebd0324fa 72
rolf.meyer@arm.com 11:1c1ebd0324fa 73 /* Function: output
rolf.meyer@arm.com 11:1c1ebd0324fa 74 * Set as an output
rolf.meyer@arm.com 11:1c1ebd0324fa 75 */
rolf.meyer@arm.com 11:1c1ebd0324fa 76 void output();
rolf.meyer@arm.com 11:1c1ebd0324fa 77
rolf.meyer@arm.com 11:1c1ebd0324fa 78 /* Function: input
rolf.meyer@arm.com 11:1c1ebd0324fa 79 * Set as an input
rolf.meyer@arm.com 11:1c1ebd0324fa 80 */
rolf.meyer@arm.com 11:1c1ebd0324fa 81 void input();
rolf.meyer@arm.com 11:1c1ebd0324fa 82
rolf.meyer@arm.com 11:1c1ebd0324fa 83 /* Function: mode
rolf.meyer@arm.com 11:1c1ebd0324fa 84 * Set the input pin mode
rolf.meyer@arm.com 11:1c1ebd0324fa 85 *
rolf.meyer@arm.com 11:1c1ebd0324fa 86 * Variables:
simon.ford@mbed.co.uk 18:b3c9f16cbb96 87 * mode - PullUp, PullDown, PullNone, OpenDrain
rolf.meyer@arm.com 11:1c1ebd0324fa 88 */
rolf.meyer@arm.com 11:1c1ebd0324fa 89 void mode(PinMode pull);
rolf.meyer@arm.com 11:1c1ebd0324fa 90
rolf.meyer@arm.com 11:1c1ebd0324fa 91 #ifdef MBED_OPERATORS
rolf.meyer@arm.com 11:1c1ebd0324fa 92 /* Function: operator=
rolf.meyer@arm.com 11:1c1ebd0324fa 93 * A shorthand for <write>
rolf.meyer@arm.com 11:1c1ebd0324fa 94 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 95 DigitalInOut& operator= (int value) {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 96 write(value);
simon.ford@mbed.co.uk 18:b3c9f16cbb96 97 return *this;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 98 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 99
simon.ford@mbed.co.uk 18:b3c9f16cbb96 100 DigitalInOut& operator= (DigitalInOut& rhs) {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 101 write(rhs.read());
simon.ford@mbed.co.uk 18:b3c9f16cbb96 102 return *this;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 103 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 104
rolf.meyer@arm.com 11:1c1ebd0324fa 105 /* Function: operator int()
rolf.meyer@arm.com 11:1c1ebd0324fa 106 * A shorthand for <read>
rolf.meyer@arm.com 11:1c1ebd0324fa 107 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 108 operator int() {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 109 return read();
simon.ford@mbed.co.uk 18:b3c9f16cbb96 110 }
rolf.meyer@arm.com 11:1c1ebd0324fa 111 #endif
rolf.meyer@arm.com 11:1c1ebd0324fa 112
rolf.meyer@arm.com 11:1c1ebd0324fa 113 #ifdef MBED_RPC
rolf.meyer@arm.com 11:1c1ebd0324fa 114 virtual const struct rpc_method *get_rpc_methods();
rolf.meyer@arm.com 11:1c1ebd0324fa 115 static struct rpc_class *get_rpc_class();
rolf.meyer@arm.com 11:1c1ebd0324fa 116 #endif
rolf.meyer@arm.com 11:1c1ebd0324fa 117
rolf.meyer@arm.com 11:1c1ebd0324fa 118 protected:
rolf.meyer@arm.com 11:1c1ebd0324fa 119
simon.ford@mbed.co.uk 18:b3c9f16cbb96 120 PinName _pin;
emilmont 27:7110ebee3484 121
emilmont 27:7110ebee3484 122 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
simon.ford@mbed.co.uk 18:b3c9f16cbb96 123 LPC_GPIO_TypeDef *_gpio;
emilmont 27:7110ebee3484 124 #elif defined(TARGET_LPC11U24)
emilmont 27:7110ebee3484 125 int _index;
emilmont 27:7110ebee3484 126 #endif
emilmont 27:7110ebee3484 127
simon.ford@mbed.co.uk 18:b3c9f16cbb96 128 uint32_t _mask;
rolf.meyer@arm.com 11:1c1ebd0324fa 129
rolf.meyer@arm.com 11:1c1ebd0324fa 130 };
rolf.meyer@arm.com 11:1c1ebd0324fa 131
rolf.meyer@arm.com 11:1c1ebd0324fa 132 } // namespace mbed
rolf.meyer@arm.com 11:1c1ebd0324fa 133
rolf.meyer@arm.com 11:1c1ebd0324fa 134 #endif