gpio.hpp
Go to the documentation of this file.
1 /*
2  * SocialLedge.com - Copyright (C) 2013
3  *
4  * This file is part of free software framework for embedded processors.
5  * You can use it and/or distribute it as long as this copyright header
6  * remains unmodified. The code is free for personal use and requires
7  * permission to use in a commercial product.
8  *
9  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
10  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
12  * I SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
13  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
14  *
15  * You can reach the author of this software at :
16  * p r e e t . w i k i @ g m a i l . c o m
17  */
18 
24 #ifndef LPC_GPIO_H__
25 #define LPC_GPIO_H__
26 
27 #include <stdint.h>
28 #include "LPC17xx.h"
29 
30 
32 #define __PNSB 5
33 
40 typedef enum
41 {
42  P0_0 = (0 << __PNSB) | 0,
43  P0_1 = (0 << __PNSB) | 1,
44  P0_26 = (0 << __PNSB) | 26,
45  P0_29 = (0 << __PNSB) | 29,
46  P0_30 = (0 << __PNSB) | 30,
48  P1_19 = (1 << __PNSB) | 19,
49  P1_20 = (1 << __PNSB) | 20,
50  P1_22 = (1 << __PNSB) | 22,
51  P1_23 = (1 << __PNSB) | 23,
52  P1_28 = (1 << __PNSB) | 28,
53  P1_29 = (1 << __PNSB) | 29,
54  P1_30 = (1 << __PNSB) | 30,
55  P1_31 = (1 << __PNSB) | 31,
57  P2_0 = (2 << __PNSB) | 0,
58  P2_1 = (2 << __PNSB) | 1,
59  P2_2 = (2 << __PNSB) | 2,
60  P2_3 = (2 << __PNSB) | 3,
61  P2_4 = (2 << __PNSB) | 4,
62  P2_5 = (2 << __PNSB) | 5,
63  P2_6 = (2 << __PNSB) | 6,
64  P2_7 = (2 << __PNSB) | 7,
65  P2_8 = (2 << __PNSB) | 8,
66  P2_9 = (2 << __PNSB) | 9,
68  P4_28 = (4 << __PNSB) | 28,
69  P4_29 = (4 << __PNSB) | 29,
71 
95 class GPIO
96 {
97  public:
98  GPIO(LPC1758_GPIO_Type gpioId);
99  ~GPIO();
100 
101  void setAsInput(void);
102  void setAsOutput(void);
103 
104  bool read(void) const;
105  void setHigh(void);
106  void setLow(void);
107  void set(bool on);
108  void toggle(void);
109 
110  void enablePullUp();
111  void enablePullDown();
112  void disablePullUpPullDown();
113  void enableOpenDrainMode(bool openDrain=true);
114 
115  protected:
116  private:
117  GPIO();
118 
119  const uint8_t mPortNum;
120  const uint8_t mPinNum;
121  volatile LPC_GPIO_TypeDef *mpOurGpio;
122 };
123 
124 
125 
126 #endif /* GPIO_H__ */
127 
Definition: gpio.hpp:49
void toggle(void)
Toggles the state of the GPIO.
Definition: gpio.cpp:50
Definition: gpio.hpp:53
bool read(void) const
Reads logical value of the pin.
Definition: gpio.cpp:46
LPC1758_GPIO_Type
Definition: gpio.hpp:40
Definition: gpio.hpp:42
void setLow(void)
Sets the pin to logical LOW (0.0v)
Definition: gpio.cpp:48
Definition: gpio.hpp:48
void enablePullDown()
Enables pull-down resistor.
Definition: gpio.cpp:59
#define __PNSB
The "Port Number Start Bit" which is used to get value of port number from LPC1758_GPIO_Type.
Definition: gpio.hpp:32
Definition: gpio.hpp:68
Definition: gpio.hpp:44
Definition: gpio.hpp:58
Definition: gpio.hpp:61
Definition: gpio.hpp:55
Definition: gpio.hpp:50
Definition: gpio.hpp:64
Definition: gpio.hpp:57
void setHigh(void)
Sets the pin to logical HIGH (3.3v)
Definition: gpio.cpp:47
Definition: gpio.hpp:51
~GPIO()
Destructor that will destroy the pin configuration.
Definition: gpio.cpp:36
CMSIS Cortex-M3 Core Peripheral Access Layer Header File for NXP LPC17xx Device Series.
void setAsOutput(void)
Sets pin as output pin.
Definition: gpio.cpp:45
Definition: gpio.hpp:69
Definition: gpio.hpp:45
Definition: gpio.hpp:66
void enableOpenDrainMode(bool openDrain=true)
Enables open drain mode.
Definition: gpio.cpp:72
Definition: gpio.hpp:62
Definition: gpio.hpp:46
Definition: gpio.hpp:95
void enablePullUp()
Enables pull-up resistor.
Definition: gpio.cpp:53
void setAsInput(void)
Sets pin as input pin.
Definition: gpio.cpp:44
Definition: gpio.hpp:60
Definition: gpio.hpp:65
Definition: LPC17xx.h:203
Definition: gpio.hpp:54
void disablePullUpPullDown()
Disables pull-up/down resistor.
Definition: gpio.cpp:65
Definition: gpio.hpp:52
Definition: gpio.hpp:63
Definition: gpio.hpp:59
Definition: gpio.hpp:43