mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Wed Oct 10 14:14:12 2012 +0000
Revision:
2:e9a661555b58
Parent:
0:8024c367e29f
Child:
7:73c5efe92a6c
Add PWM and I2C implementation;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 2:e9a661555b58 1 /* mbed Microcontroller Library - PortInOut
emilmont 2:e9a661555b58 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
emilmont 2:e9a661555b58 3 */
emilmont 2:e9a661555b58 4
emilmont 2:e9a661555b58 5 #ifndef MBED_PORTIN_H
emilmont 2:e9a661555b58 6 #define MBED_PORTIN_H
emilmont 2:e9a661555b58 7
emilmont 2:e9a661555b58 8 #include "device.h"
emilmont 2:e9a661555b58 9
emilmont 2:e9a661555b58 10 #if DEVICE_PORTIN
emilmont 2:e9a661555b58 11
emilmont 2:e9a661555b58 12 #include "PortNames.h"
emilmont 2:e9a661555b58 13 #include "PinNames.h"
emilmont 2:e9a661555b58 14
emilmont 2:e9a661555b58 15 namespace mbed {
emilmont 2:e9a661555b58 16
emilmont 2:e9a661555b58 17 /* Class: PortIn
emilmont 2:e9a661555b58 18 * A multiple pin digital input
emilmont 2:e9a661555b58 19 *
emilmont 2:e9a661555b58 20 * Example:
emilmont 2:e9a661555b58 21 * > // Switch on an LED if any of mbed pins 21-26 is high
emilmont 2:e9a661555b58 22 * >
emilmont 2:e9a661555b58 23 * > #include "mbed.h"
emilmont 2:e9a661555b58 24 * >
emilmont 2:e9a661555b58 25 * > PortIn p(Port2, 0x0000003F); // p21-p26
emilmont 2:e9a661555b58 26 * > DigitalOut ind(LED4);
emilmont 2:e9a661555b58 27 * >
emilmont 2:e9a661555b58 28 * > int main() {
emilmont 2:e9a661555b58 29 * > while(1) {
emilmont 2:e9a661555b58 30 * > int pins = p.read();
emilmont 2:e9a661555b58 31 * > if(pins) {
emilmont 2:e9a661555b58 32 * > ind = 1;
emilmont 2:e9a661555b58 33 * > } else {
emilmont 2:e9a661555b58 34 * > ind = 0;
emilmont 2:e9a661555b58 35 * > }
emilmont 2:e9a661555b58 36 * > }
emilmont 2:e9a661555b58 37 * > }
emilmont 2:e9a661555b58 38 */
emilmont 2:e9a661555b58 39 class PortIn {
emilmont 2:e9a661555b58 40 public:
emilmont 2:e9a661555b58 41
emilmont 2:e9a661555b58 42 /* Constructor: PortIn
emilmont 2:e9a661555b58 43 * Create an PortIn, connected to the specified port
emilmont 2:e9a661555b58 44 *
emilmont 2:e9a661555b58 45 * Variables:
emilmont 2:e9a661555b58 46 * port - Port to connect to (Port0-Port5)
emilmont 2:e9a661555b58 47 * mask - A bitmask to identify which bits in the port should be included (0 - ignore)
emilmont 2:e9a661555b58 48 */
emilmont 2:e9a661555b58 49 PortIn(PortName port, int mask = 0xFFFFFFFF);
emilmont 2:e9a661555b58 50
emilmont 2:e9a661555b58 51 /* Function: read
emilmont 2:e9a661555b58 52 * Read the value currently output on the port
emilmont 2:e9a661555b58 53 *
emilmont 2:e9a661555b58 54 * Variables:
emilmont 2:e9a661555b58 55 * returns - An integer with each bit corresponding to associated port pin setting
emilmont 2:e9a661555b58 56 */
emilmont 2:e9a661555b58 57 int read();
emilmont 2:e9a661555b58 58
emilmont 2:e9a661555b58 59 /* Function: mode
emilmont 2:e9a661555b58 60 * Set the input pin mode
emilmont 2:e9a661555b58 61 *
emilmont 2:e9a661555b58 62 * Variables:
emilmont 2:e9a661555b58 63 * mode - PullUp, PullDown, PullNone, OpenDrain
emilmont 2:e9a661555b58 64 */
emilmont 2:e9a661555b58 65 void mode(PinMode mode);
emilmont 2:e9a661555b58 66
emilmont 2:e9a661555b58 67 /* Function: operator int()
emilmont 2:e9a661555b58 68 * A shorthand for <read>
emilmont 2:e9a661555b58 69 */
emilmont 2:e9a661555b58 70 operator int() {
emilmont 2:e9a661555b58 71 return read();
emilmont 2:e9a661555b58 72 }
emilmont 2:e9a661555b58 73
emilmont 2:e9a661555b58 74 private:
emilmont 2:e9a661555b58 75 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
emilmont 2:e9a661555b58 76 LPC_GPIO_TypeDef *_gpio;
emilmont 2:e9a661555b58 77 #endif
emilmont 2:e9a661555b58 78 PortName _port;
emilmont 2:e9a661555b58 79 uint32_t _mask;
emilmont 2:e9a661555b58 80 };
emilmont 2:e9a661555b58 81
emilmont 2:e9a661555b58 82 } // namespace mbed
emilmont 2:e9a661555b58 83
emilmont 2:e9a661555b58 84 #endif
emilmont 2:e9a661555b58 85
emilmont 2:e9a661555b58 86 #endif