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