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.
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
mbed/DigitalInOut.h@3:5dc0023e6284, 2014-01-31 (annotated)
- Committer:
- wyunreal
- Date:
- Fri Jan 31 23:19:28 2014 +0000
- Revision:
- 3:5dc0023e6284
First approach of EthernetService class
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wyunreal | 3:5dc0023e6284 | 1 | /* mbed Microcontroller Library - DigitalInOut |
| wyunreal | 3:5dc0023e6284 | 2 | * Copyright (c) 2006-2009 ARM Limited. All rights reserved. |
| wyunreal | 3:5dc0023e6284 | 3 | * sford |
| wyunreal | 3:5dc0023e6284 | 4 | */ |
| wyunreal | 3:5dc0023e6284 | 5 | |
| wyunreal | 3:5dc0023e6284 | 6 | #ifndef MBED_DIGITALINOUT_H |
| wyunreal | 3:5dc0023e6284 | 7 | #define MBED_DIGITALINOUT_H |
| wyunreal | 3:5dc0023e6284 | 8 | |
| wyunreal | 3:5dc0023e6284 | 9 | #include "platform.h" |
| wyunreal | 3:5dc0023e6284 | 10 | #include "PinNames.h" |
| wyunreal | 3:5dc0023e6284 | 11 | #include "PeripheralNames.h" |
| wyunreal | 3:5dc0023e6284 | 12 | #include "Base.h" |
| wyunreal | 3:5dc0023e6284 | 13 | |
| wyunreal | 3:5dc0023e6284 | 14 | namespace mbed { |
| wyunreal | 3:5dc0023e6284 | 15 | |
| wyunreal | 3:5dc0023e6284 | 16 | /* Class: DigitalInOut |
| wyunreal | 3:5dc0023e6284 | 17 | * A digital input/output, used for setting or reading a bi-directional pin |
| wyunreal | 3:5dc0023e6284 | 18 | */ |
| wyunreal | 3:5dc0023e6284 | 19 | class DigitalInOut : public Base { |
| wyunreal | 3:5dc0023e6284 | 20 | |
| wyunreal | 3:5dc0023e6284 | 21 | public: |
| wyunreal | 3:5dc0023e6284 | 22 | |
| wyunreal | 3:5dc0023e6284 | 23 | /* Constructor: DigitalInOut |
| wyunreal | 3:5dc0023e6284 | 24 | * Create a DigitalInOut connected to the specified pin |
| wyunreal | 3:5dc0023e6284 | 25 | * |
| wyunreal | 3:5dc0023e6284 | 26 | * Variables: |
| wyunreal | 3:5dc0023e6284 | 27 | * pin - DigitalInOut pin to connect to |
| wyunreal | 3:5dc0023e6284 | 28 | */ |
| wyunreal | 3:5dc0023e6284 | 29 | DigitalInOut(PinName pin, const char* name = NULL); |
| wyunreal | 3:5dc0023e6284 | 30 | |
| wyunreal | 3:5dc0023e6284 | 31 | /* Function: write |
| wyunreal | 3:5dc0023e6284 | 32 | * Set the output, specified as 0 or 1 (int) |
| wyunreal | 3:5dc0023e6284 | 33 | * |
| wyunreal | 3:5dc0023e6284 | 34 | * Variables: |
| wyunreal | 3:5dc0023e6284 | 35 | * value - An integer specifying the pin output value, |
| wyunreal | 3:5dc0023e6284 | 36 | * 0 for logical 0 and 1 (or any other non-zero value) for logical 1 |
| wyunreal | 3:5dc0023e6284 | 37 | */ |
| wyunreal | 3:5dc0023e6284 | 38 | void write(int value) { |
| wyunreal | 3:5dc0023e6284 | 39 | if(value) { |
| wyunreal | 3:5dc0023e6284 | 40 | _gpio->FIOSET = _mask; |
| wyunreal | 3:5dc0023e6284 | 41 | } else { |
| wyunreal | 3:5dc0023e6284 | 42 | _gpio->FIOCLR = _mask; |
| wyunreal | 3:5dc0023e6284 | 43 | } |
| wyunreal | 3:5dc0023e6284 | 44 | } |
| wyunreal | 3:5dc0023e6284 | 45 | |
| wyunreal | 3:5dc0023e6284 | 46 | /* Function: read |
| wyunreal | 3:5dc0023e6284 | 47 | * Return the output setting, represented as 0 or 1 (int) |
| wyunreal | 3:5dc0023e6284 | 48 | * |
| wyunreal | 3:5dc0023e6284 | 49 | * Variables: |
| wyunreal | 3:5dc0023e6284 | 50 | * returns - An integer representing the output setting of the pin if it is an output, |
| wyunreal | 3:5dc0023e6284 | 51 | * or read the input if set as an input |
| wyunreal | 3:5dc0023e6284 | 52 | */ |
| wyunreal | 3:5dc0023e6284 | 53 | int read() { |
| wyunreal | 3:5dc0023e6284 | 54 | return ((_gpio->FIOPIN & _mask) ? 1 : 0); |
| wyunreal | 3:5dc0023e6284 | 55 | } |
| wyunreal | 3:5dc0023e6284 | 56 | |
| wyunreal | 3:5dc0023e6284 | 57 | |
| wyunreal | 3:5dc0023e6284 | 58 | /* Function: output |
| wyunreal | 3:5dc0023e6284 | 59 | * Set as an output |
| wyunreal | 3:5dc0023e6284 | 60 | */ |
| wyunreal | 3:5dc0023e6284 | 61 | void output(); |
| wyunreal | 3:5dc0023e6284 | 62 | |
| wyunreal | 3:5dc0023e6284 | 63 | /* Function: input |
| wyunreal | 3:5dc0023e6284 | 64 | * Set as an input |
| wyunreal | 3:5dc0023e6284 | 65 | */ |
| wyunreal | 3:5dc0023e6284 | 66 | void input(); |
| wyunreal | 3:5dc0023e6284 | 67 | |
| wyunreal | 3:5dc0023e6284 | 68 | /* Function: mode |
| wyunreal | 3:5dc0023e6284 | 69 | * Set the input pin mode |
| wyunreal | 3:5dc0023e6284 | 70 | * |
| wyunreal | 3:5dc0023e6284 | 71 | * Variables: |
| wyunreal | 3:5dc0023e6284 | 72 | * mode - PullUp, PullDown, PullNone, OpenDrain |
| wyunreal | 3:5dc0023e6284 | 73 | */ |
| wyunreal | 3:5dc0023e6284 | 74 | void mode(PinMode pull); |
| wyunreal | 3:5dc0023e6284 | 75 | |
| wyunreal | 3:5dc0023e6284 | 76 | #ifdef MBED_OPERATORS |
| wyunreal | 3:5dc0023e6284 | 77 | /* Function: operator= |
| wyunreal | 3:5dc0023e6284 | 78 | * A shorthand for <write> |
| wyunreal | 3:5dc0023e6284 | 79 | */ |
| wyunreal | 3:5dc0023e6284 | 80 | DigitalInOut& operator= (int value) { |
| wyunreal | 3:5dc0023e6284 | 81 | write(value); |
| wyunreal | 3:5dc0023e6284 | 82 | return *this; |
| wyunreal | 3:5dc0023e6284 | 83 | } |
| wyunreal | 3:5dc0023e6284 | 84 | |
| wyunreal | 3:5dc0023e6284 | 85 | DigitalInOut& operator= (DigitalInOut& rhs) { |
| wyunreal | 3:5dc0023e6284 | 86 | write(rhs.read()); |
| wyunreal | 3:5dc0023e6284 | 87 | return *this; |
| wyunreal | 3:5dc0023e6284 | 88 | } |
| wyunreal | 3:5dc0023e6284 | 89 | |
| wyunreal | 3:5dc0023e6284 | 90 | /* Function: operator int() |
| wyunreal | 3:5dc0023e6284 | 91 | * A shorthand for <read> |
| wyunreal | 3:5dc0023e6284 | 92 | */ |
| wyunreal | 3:5dc0023e6284 | 93 | operator int() { |
| wyunreal | 3:5dc0023e6284 | 94 | return read(); |
| wyunreal | 3:5dc0023e6284 | 95 | } |
| wyunreal | 3:5dc0023e6284 | 96 | #endif |
| wyunreal | 3:5dc0023e6284 | 97 | |
| wyunreal | 3:5dc0023e6284 | 98 | #ifdef MBED_RPC |
| wyunreal | 3:5dc0023e6284 | 99 | virtual const struct rpc_method *get_rpc_methods(); |
| wyunreal | 3:5dc0023e6284 | 100 | static struct rpc_class *get_rpc_class(); |
| wyunreal | 3:5dc0023e6284 | 101 | #endif |
| wyunreal | 3:5dc0023e6284 | 102 | |
| wyunreal | 3:5dc0023e6284 | 103 | protected: |
| wyunreal | 3:5dc0023e6284 | 104 | |
| wyunreal | 3:5dc0023e6284 | 105 | PinName _pin; |
| wyunreal | 3:5dc0023e6284 | 106 | LPC_GPIO_TypeDef *_gpio; |
| wyunreal | 3:5dc0023e6284 | 107 | uint32_t _mask; |
| wyunreal | 3:5dc0023e6284 | 108 | |
| wyunreal | 3:5dc0023e6284 | 109 | }; |
| wyunreal | 3:5dc0023e6284 | 110 | |
| wyunreal | 3:5dc0023e6284 | 111 | } // namespace mbed |
| wyunreal | 3:5dc0023e6284 | 112 | |
| wyunreal | 3:5dc0023e6284 | 113 | #endif |
