Library

Dependents:   OSCTest_2

Fork of mbed by gokmen ascioglu

Committer:
itotaka
Date:
Fri Oct 04 12:17:02 2013 +0000
Revision:
1:b749145a7bb1
Parent:
0:a8fa94490a0a
changed Max_Arg to 80

Who changed what in which revision?

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