Fork of the official mbed C/C SDK provides the software platform and libraries to build your applications. The fork has the documentation converted to Doxygen format

Fork of mbed by -deleted-

Committer:
simon.ford@mbed.co.uk
Date:
Mon May 17 14:18:54 2010 +0000
Revision:
18:b3c9f16cbb96
Parent:
11:1c1ebd0324fa
Child:
27:7110ebee3484
* Digital I/O speed improved
* Added Port
* Added OpenDrain mode
* Fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon.ford@mbed.co.uk 0:82220227f4fa 1 /* mbed Microcontroller Library - DigitalOut
rolf.meyer@arm.com 11:1c1ebd0324fa 2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
rolf.meyer@arm.com 11:1c1ebd0324fa 3 * sford
rolf.meyer@arm.com 11:1c1ebd0324fa 4 */
simon.ford@mbed.co.uk 0:82220227f4fa 5
simon.ford@mbed.co.uk 0:82220227f4fa 6 #ifndef MBED_DIGITALOUT_H
simon.ford@mbed.co.uk 0:82220227f4fa 7 #define MBED_DIGITALOUT_H
simon.ford@mbed.co.uk 0:82220227f4fa 8
rolf.meyer@arm.com 11:1c1ebd0324fa 9 #include "platform.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 10 #include "PinNames.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 11 #include "PeripheralNames.h"
simon.ford@mbed.co.uk 0:82220227f4fa 12 #include "Base.h"
simon.ford@mbed.co.uk 0:82220227f4fa 13
simon.ford@mbed.co.uk 0:82220227f4fa 14 namespace mbed {
simon.ford@mbed.co.uk 0:82220227f4fa 15
simon.ford@mbed.co.uk 0:82220227f4fa 16 /* Class: DigitalOut
simon.ford@mbed.co.uk 0:82220227f4fa 17 * A digital output, used for setting the state of a pin
rolf.meyer@arm.com 11:1c1ebd0324fa 18 *
rolf.meyer@arm.com 11:1c1ebd0324fa 19 * Example:
rolf.meyer@arm.com 11:1c1ebd0324fa 20 * > // Toggle a LED
rolf.meyer@arm.com 11:1c1ebd0324fa 21 * > #include "mbed.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 22 * >
rolf.meyer@arm.com 11:1c1ebd0324fa 23 * > DigitalOut led(LED1);
rolf.meyer@arm.com 11:1c1ebd0324fa 24 * >
rolf.meyer@arm.com 11:1c1ebd0324fa 25 * > int main() {
rolf.meyer@arm.com 11:1c1ebd0324fa 26 * > while(1) {
rolf.meyer@arm.com 11:1c1ebd0324fa 27 * > led = !led;
rolf.meyer@arm.com 11:1c1ebd0324fa 28 * > wait(0.2);
rolf.meyer@arm.com 11:1c1ebd0324fa 29 * > }
rolf.meyer@arm.com 11:1c1ebd0324fa 30 * > }
simon.ford@mbed.co.uk 0:82220227f4fa 31 */
simon.ford@mbed.co.uk 0:82220227f4fa 32 class DigitalOut : public Base {
simon.ford@mbed.co.uk 0:82220227f4fa 33
simon.ford@mbed.co.uk 0:82220227f4fa 34 public:
simon.ford@mbed.co.uk 0:82220227f4fa 35
rolf.meyer@arm.com 11:1c1ebd0324fa 36 /* Constructor: DigitalOut
rolf.meyer@arm.com 11:1c1ebd0324fa 37 * Create a DigitalOut connected to the specified pin
rolf.meyer@arm.com 11:1c1ebd0324fa 38 *
rolf.meyer@arm.com 11:1c1ebd0324fa 39 * Variables:
rolf.meyer@arm.com 11:1c1ebd0324fa 40 * pin - DigitalOut pin to connect to
rolf.meyer@arm.com 11:1c1ebd0324fa 41 */
rolf.meyer@arm.com 11:1c1ebd0324fa 42 DigitalOut(PinName pin, const char* name = NULL);
simon.ford@mbed.co.uk 0:82220227f4fa 43
rolf.meyer@arm.com 11:1c1ebd0324fa 44 /* Function: write
rolf.meyer@arm.com 11:1c1ebd0324fa 45 * Set the output, specified as 0 or 1 (int)
rolf.meyer@arm.com 11:1c1ebd0324fa 46 *
rolf.meyer@arm.com 11:1c1ebd0324fa 47 * Variables:
rolf.meyer@arm.com 11:1c1ebd0324fa 48 * value - An integer specifying the pin output value,
rolf.meyer@arm.com 11:1c1ebd0324fa 49 * 0 for logical 0 and 1 (or any other non-zero value) for logical 1
rolf.meyer@arm.com 11:1c1ebd0324fa 50 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 51 void write(int value) {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 52 if(value) {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 53 _gpio->FIOSET = _mask;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 54 } else {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 55 _gpio->FIOCLR = _mask;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 56 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 57 }
simon.ford@mbed.co.uk 0:82220227f4fa 58
rolf.meyer@arm.com 11:1c1ebd0324fa 59 /* Function: read
rolf.meyer@arm.com 11:1c1ebd0324fa 60 * Return the output setting, represented as 0 or 1 (int)
rolf.meyer@arm.com 11:1c1ebd0324fa 61 *
rolf.meyer@arm.com 11:1c1ebd0324fa 62 * Variables:
rolf.meyer@arm.com 11:1c1ebd0324fa 63 * returns - An integer representing the output setting of the pin,
rolf.meyer@arm.com 11:1c1ebd0324fa 64 * 0 for logical 0 and 1 for logical 1
rolf.meyer@arm.com 11:1c1ebd0324fa 65 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 66 int read() {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 67 return ((_gpio->FIOPIN & _mask) ? 1 : 0);
simon.ford@mbed.co.uk 18:b3c9f16cbb96 68 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 69
simon.ford@mbed.co.uk 4:5d1359a283bc 70
rolf.meyer@arm.com 11:1c1ebd0324fa 71 #ifdef MBED_OPERATORS
rolf.meyer@arm.com 11:1c1ebd0324fa 72 /* Function: operator=
rolf.meyer@arm.com 11:1c1ebd0324fa 73 * A shorthand for <write>
rolf.meyer@arm.com 11:1c1ebd0324fa 74 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 75 DigitalOut& operator= (int value) {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 76 write(value);
simon.ford@mbed.co.uk 18:b3c9f16cbb96 77 return *this;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 78 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 79
simon.ford@mbed.co.uk 18:b3c9f16cbb96 80 DigitalOut& operator= (DigitalOut& rhs) {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 81 write(rhs.read());
simon.ford@mbed.co.uk 18:b3c9f16cbb96 82 return *this;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 83 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 84
rolf.meyer@arm.com 11:1c1ebd0324fa 85
simon.ford@mbed.co.uk 0:82220227f4fa 86 /* Function: operator int()
simon.ford@mbed.co.uk 0:82220227f4fa 87 * A shorthand for <read>
simon.ford@mbed.co.uk 0:82220227f4fa 88 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 89 operator int() {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 90 return read();
simon.ford@mbed.co.uk 18:b3c9f16cbb96 91 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 92
rolf.meyer@arm.com 11:1c1ebd0324fa 93 #endif
rolf.meyer@arm.com 11:1c1ebd0324fa 94
rolf.meyer@arm.com 11:1c1ebd0324fa 95 #ifdef MBED_RPC
rolf.meyer@arm.com 11:1c1ebd0324fa 96 virtual const struct rpc_method *get_rpc_methods();
rolf.meyer@arm.com 11:1c1ebd0324fa 97 static struct rpc_class *get_rpc_class();
rolf.meyer@arm.com 11:1c1ebd0324fa 98 #endif
simon.ford@mbed.co.uk 0:82220227f4fa 99
simon.ford@mbed.co.uk 0:82220227f4fa 100 protected:
rolf.meyer@arm.com 11:1c1ebd0324fa 101
simon.ford@mbed.co.uk 18:b3c9f16cbb96 102 PinName _pin;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 103 LPC_GPIO_TypeDef *_gpio;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 104 uint32_t _mask;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 105
rolf.meyer@arm.com 11:1c1ebd0324fa 106
simon.ford@mbed.co.uk 0:82220227f4fa 107 };
simon.ford@mbed.co.uk 0:82220227f4fa 108
rolf.meyer@arm.com 11:1c1ebd0324fa 109 } // namespace mbed
simon.ford@mbed.co.uk 0:82220227f4fa 110
rolf.meyer@arm.com 11:1c1ebd0324fa 111 #endif