a

Fork of mbed by -deleted-

Committer:
TUATBM
Date:
Sun Sep 09 14:57:10 2018 +0000
Revision:
44:8d22cce05b9a
Parent:
43:aff670d0d510
a

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