SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

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