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 - DigitalIn
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_DIGITALIN_H
lharoon 0:22612ae617a0 6 #define MBED_DIGITALIN_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: DigitalIn
lharoon 0:22612ae617a0 16 * A digital input, used for reading the state of a pin
lharoon 0:22612ae617a0 17 *
lharoon 0:22612ae617a0 18 * Example:
lharoon 0:22612ae617a0 19 * > // Flash an LED while a DigitalIn is true
lharoon 0:22612ae617a0 20 * >
lharoon 0:22612ae617a0 21 * > #include "mbed.h"
lharoon 0:22612ae617a0 22 * >
lharoon 0:22612ae617a0 23 * > DigitalIn enable(p5);
lharoon 0:22612ae617a0 24 * > DigitalOut led(LED1);
lharoon 0:22612ae617a0 25 * >
lharoon 0:22612ae617a0 26 * > int main() {
lharoon 0:22612ae617a0 27 * > while(1) {
lharoon 0:22612ae617a0 28 * > if(enable) {
lharoon 0:22612ae617a0 29 * > led = !led;
lharoon 0:22612ae617a0 30 * > }
lharoon 0:22612ae617a0 31 * > wait(0.25);
lharoon 0:22612ae617a0 32 * > }
lharoon 0:22612ae617a0 33 * > }
lharoon 0:22612ae617a0 34 */
lharoon 0:22612ae617a0 35 class DigitalIn : public Base {
lharoon 0:22612ae617a0 36
lharoon 0:22612ae617a0 37 public:
lharoon 0:22612ae617a0 38
lharoon 0:22612ae617a0 39 /* Constructor: DigitalIn
lharoon 0:22612ae617a0 40 * Create a DigitalIn connected to the specified pin
lharoon 0:22612ae617a0 41 *
lharoon 0:22612ae617a0 42 * Variables:
lharoon 0:22612ae617a0 43 * pin - DigitalIn pin to connect to
lharoon 0:22612ae617a0 44 * name - (optional) A string to identify the object
lharoon 0:22612ae617a0 45 */
lharoon 0:22612ae617a0 46 DigitalIn(PinName pin, const char *name = NULL);
lharoon 0:22612ae617a0 47
lharoon 0:22612ae617a0 48 /* Function: read
lharoon 0:22612ae617a0 49 * Read the input, represented as 0 or 1 (int)
lharoon 0:22612ae617a0 50 *
lharoon 0:22612ae617a0 51 * Variables:
lharoon 0:22612ae617a0 52 * returns - An integer representing the state of the input pin,
lharoon 0:22612ae617a0 53 * 0 for logical 0 and 1 for logical 1
lharoon 0:22612ae617a0 54 */
lharoon 0:22612ae617a0 55 int read() {
lharoon 0:22612ae617a0 56 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
lharoon 0:22612ae617a0 57 return ((_gpio->FIOPIN & _mask) ? 1 : 0);
lharoon 0:22612ae617a0 58 #elif defined(TARGET_LPC11U24)
lharoon 0:22612ae617a0 59 return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0);
lharoon 0:22612ae617a0 60 #endif
lharoon 0:22612ae617a0 61 }
lharoon 0:22612ae617a0 62
lharoon 0:22612ae617a0 63
lharoon 0:22612ae617a0 64 /* Function: mode
lharoon 0:22612ae617a0 65 * Set the input pin mode
lharoon 0:22612ae617a0 66 *
lharoon 0:22612ae617a0 67 * Variables:
lharoon 0:22612ae617a0 68 * mode - PullUp, PullDown, PullNone, OpenDrain
lharoon 0:22612ae617a0 69 */
lharoon 0:22612ae617a0 70 void mode(PinMode pull);
lharoon 0:22612ae617a0 71
lharoon 0:22612ae617a0 72 #ifdef MBED_OPERATORS
lharoon 0:22612ae617a0 73 /* Function: operator int()
lharoon 0:22612ae617a0 74 * An operator shorthand for <read()>
lharoon 0:22612ae617a0 75 */
lharoon 0:22612ae617a0 76 operator int() {
lharoon 0:22612ae617a0 77 return read();
lharoon 0:22612ae617a0 78 }
lharoon 0:22612ae617a0 79
lharoon 0:22612ae617a0 80 #endif
lharoon 0:22612ae617a0 81
lharoon 0:22612ae617a0 82 #ifdef MBED_RPC
lharoon 0:22612ae617a0 83 virtual const struct rpc_method *get_rpc_methods();
lharoon 0:22612ae617a0 84 static struct rpc_class *get_rpc_class();
lharoon 0:22612ae617a0 85 #endif
lharoon 0:22612ae617a0 86
lharoon 0:22612ae617a0 87 protected:
lharoon 0:22612ae617a0 88
lharoon 0:22612ae617a0 89 PinName _pin;
lharoon 0:22612ae617a0 90 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
lharoon 0:22612ae617a0 91 LPC_GPIO_TypeDef *_gpio;
lharoon 0:22612ae617a0 92 #elif defined(TARGET_LPC11U24)
lharoon 0:22612ae617a0 93 int _index;
lharoon 0:22612ae617a0 94 #endif
lharoon 0:22612ae617a0 95 uint32_t _mask;
lharoon 0:22612ae617a0 96
lharoon 0:22612ae617a0 97 };
lharoon 0:22612ae617a0 98
lharoon 0:22612ae617a0 99 } // namespace mbed
lharoon 0:22612ae617a0 100
lharoon 0:22612ae617a0 101 #endif
lharoon 0:22612ae617a0 102