LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
iocon_17xx_40xx.h
Go to the documentation of this file.
1 /*
2  * @brief LPC17xx/40xx IOCON registers and control functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __IOCON_17XX_40XX_H_
33 #define __IOCON_17XX_40XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
47 typedef struct {
48 #if defined(CHIP_LPC175X_6X)
49  __IO uint32_t PINSEL[11];
50  uint32_t RESERVED0[5];
51  __IO uint32_t PINMODE[10];
52  __IO uint32_t PINMODE_OD[5];
53  __IO uint32_t I2CPADCFG;
54 #else
55  __IO uint32_t p[5][32];
56 #endif
57 } LPC_IOCON_T;
58 
64 #define IOCON_FUNC0 0x0
65 #define IOCON_FUNC1 0x1
66 #define IOCON_FUNC2 0x2
67 #define IOCON_FUNC3 0x3
68 #if defined(CHIP_LPC175X_6X)
69 #define IOCON_MODE_INACT (0x2 << 0)
70 #define IOCON_MODE_PULLDOWN (0x3 << 0)
71 #define IOCON_MODE_PULLUP (0x0 << 0)
72 #define IOCON_MODE_REPEATER (0x1 << 0)
73 #else
74 #define IOCON_FUNC4 0x4
75 #define IOCON_FUNC5 0x5
76 #define IOCON_FUNC6 0x6
77 #define IOCON_FUNC7 0x7
78 #define IOCON_MODE_INACT (0x0 << 3)
79 #define IOCON_MODE_PULLDOWN (0x1 << 3)
80 #define IOCON_MODE_PULLUP (0x2 << 3)
81 #define IOCON_MODE_REPEATER (0x3 << 3)
82 #define IOCON_HYS_EN (0x1 << 5)
83 #define IOCON_INV_EN (0x1 << 6)
84 #define IOCON_ADMODE_EN (0x0 << 7)
85 #define IOCON_DIGMODE_EN (0x1 << 7)
86 #define IOCON_FILT_DIS (0x1 << 8)
87 #define IOCON_HS_DIS (0x1 << 8)
88 #define IOCON_HIDRIVE_EN (0x1 << 9)
89 #define IOCON_FASTSLEW_EN (0x1 << 9)
90 #define IOCON_OPENDRAIN_EN (0x1 << 10)
91 #define IOCON_DAC_EN (0x1 << 16)
92 #endif
93 
98 #define FUNC0 0x0
99 #define FUNC1 0x1
100 #define FUNC2 0x2
101 #define FUNC3 0x3
102 #if defined(CHIP_LPC175X_6X)
103 #define MD_PLN (0x2)
104 #define MD_PDN (0x3)
105 #define MD_PUP (0x0)
106 #define MD_RPT (0x1)
107 
108 #else
109 #define MD_PLN (0x0 << 3)
110 #define MD_PDN (0x1 << 3)
111 #define MD_PUP (0x2 << 3)
112 #define MD_RPT (0x3 << 3)
113 #define MD_HYS_ENA (0x1 << 5)
114 #define MD_HYS_DIS (0x0 << 5)
115 #define MD_IINV_ENA (0x1 << 6)
116 #define MD_IINV_DIS (0x0 << 6)
117 #define MD_OD_ENA (0x1 << 10)
118 #define MD_OD_DIS (0x0 << 10)
119 #define MD_HS_ENA (0x0 << 8)
120 #define MD_HS_DIS (0x1 << 8)
121 #define MD_ANA_ENA (0x0 << 7)
122 #define MD_ANA_DIS (0x1 << 7)
123 #define MD_FILT_ENA (0x0 << 8)
124 #define MD_FILT_DIS (0x1 << 8)
125 #define MD_DAC_ENA (0x1 << 16)
126 #define MD_DAC_DIS (0x0 << 16)
127 #define MD_STD_SLEW_RATE (0x0 << 9)
128 #define MD_FAST_SLEW_RATE (0x1 << 9)
129 #define MD_HD_ENA (0x1 << 9)
130 #define MD_HD_DIS (0x0 << 9)
131 #define FUNC4 0x4
132 #define FUNC5 0x5
133 #define FUNC6 0x6
134 #define FUNC7 0x7
135 #endif /* defined(CHIP_LPC175X_6X)*/
136 
143 {}
144 
145 #if defined(CHIP_LPC175X_6X)
146 /* PINSEL and PINMODE register index calculation.*/
147 #define IOCON_REG_INDEX(port, pin) (2 * port + (pin / 16))
148 /* Bit position calculation in PINSEL and PINMODE register.*/
149 #define IOCON_BIT_INDEX(pin) ((pin % 16) * 2)
150 
160 void Chip_IOCON_PinMux(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t mode, uint8_t func);
161 
169 STATIC INLINE void Chip_IOCON_EnableOD(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin)
170 {
171  pIOCON->PINMODE_OD[port] |= (0x01UL << pin);
172 }
173 
181 STATIC INLINE void Chip_IOCON_DisableOD(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin)
182 {
183  pIOCON->PINMODE_OD[port] &= ~(0x01UL << pin);
184 }
185 
189 typedef enum {
190  I2CPADCFG_STD_MODE = 0x00,
191  I2CPADCFG_FAST_MODE = I2CPADCFG_STD_MODE,
192  I2CPADCFG_FAST_MODE_PLUS = 0x05,
193  I2CPADCFG_NON_I2C = 0x0A,
194 } IOCON_I2CPINS_CONFIG;
195 
202 STATIC INLINE void Chip_IOCON_SetI2CPad(LPC_IOCON_T *pIOCON, IOCON_I2CPINS_CONFIG cfg)
203 {
204  pIOCON->I2CPADCFG = cfg;
205 }
206 
207 #else
208 
216 STATIC INLINE void Chip_IOCON_PinMuxSet(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t modefunc)
217 {
218  pIOCON->p[port][pin] = modefunc;
219 }
220 
230 STATIC INLINE void Chip_IOCON_PinMux(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t mode, uint8_t func)
231 {
232  Chip_IOCON_PinMuxSet(pIOCON, port, pin, (mode | func));
233 }
234 #endif /* defined(CHIP_LPC175X_6X) */
235 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif /* __IOCON_17XX_40XX_H_ */