| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
iocon_8xx.c
Go to the documentation of this file.
1 /*
2 * @brief LPC8xx IOCON driver
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 licenser 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 #include "chip.h"
33
34 /*****************************************************************************
35 * Private types/enumerations/variables
36 ****************************************************************************/
37
38 /* This array maps the address offsets (from 0x40044000) to the actual pin
39 * in indexed order by pin number.
40 */
41 const static uint8_t PIN_ADDRESS_OFFSETS[] = {0x44,
42 0x2C,
43 0x18,
44 0x14,
45 0x10,
46 0x0C
47 #if !defined(PKG_DIP8)
48 ,
49
50 0x40,
51 0x3C,
52 0x38,
53 0x34,
54 0x20,
55 0x1C,
56 0x08,
57 0x04
58 #if !defined(PKG_TSSOP16)
59 ,
60
61 0x48,
62 0x28,
63 0x24,
64 0x00
65 #endif
66 #endif
67 };
68
69 #define PIN_OFFSET(pin) (PIN_ADDRESS_OFFSETS[pin])
70
71 #define PIN_BASE_ADDR (0x40044000)
72
73 #define PIN_MODE_GET(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) & (3 << 3))
74 #define PIN_MODE_CLR(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) &= ~(3 << 3))
75 #define PIN_MODE_SET(pin, val) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) |= (val << 3))
76
77 #define PIN_HYS_GET(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) & ( 1 << 5))
78 #define PIN_HYS_CLR(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) &= ~(1 << 5))
79 #define PIN_HYS_SET(pin, val) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) |= (val << 5))
80
81 #define PIN_INV_GET(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) & ( 1 << 6))
82 #define PIN_INV_CLR(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) &= ~( 1 << 6))
83 #define PIN_INV_SET(pin, val) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) |= (val << 6))
84
85 #define PIN_OD_GET(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) & ( 1 << 10))
86 #define PIN_OD_CLR(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) &= ~( 1 << 10))
87 #define PIN_OD_SET(pin, val) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) |= (val << 10))
88
89 #define PIN_SMODE_GET(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) & ( 3 << 11))
90 #define PIN_SMODE_CLR(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) &= ~( 3 << 11))
91 #define PIN_SMODE_SET(pin, val) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) |= (val << 11))
92
93 #define PIN_CLKDIV_GET(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) & ( 7 << 13))
94 #define PIN_CLKDIV_CLR(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) &= ~( 7 << 13))
95 #define PIN_CLKDIV_SET(pin, val) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) |= (val << 13))
96
97 #define PIN_I2CMODE_GET(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) & ( 3 << 8))
98 #define PIN_I2CMODE_CLR(pin) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) &= ~( 3 << 8))
99 #define PIN_I2CMODE_SET(pin, val) (*(volatile uint32_t *) (PIN_BASE_ADDR + PIN_OFFSET(pin)) |= (val << 8))
100
101 /*****************************************************************************
102 * Public types/enumerations/variables
103 ****************************************************************************/
104
105 /*****************************************************************************
106 * Private functions
107 ****************************************************************************/
108
109 /*****************************************************************************
110 * Public functions
111 ****************************************************************************/
112
113 /* Set the pin mode (pull-up/pull-down). */
114 void Chip_IOCON_PinSetMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_MODE_T mode)
115 {
116 switch (pin) {
117 case PIO10: /* No mode for the I2C pins */
118 case PIO11:
119 break;
120
121 default:
122 PIN_MODE_CLR(pin);
123 PIN_MODE_SET(pin, mode);
124 break;
125 }
126 }
127
128 /* Enables/disables the pin hysteresis. */
129 void Chip_IOCON_PinSetHysteresis(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool enable)
130 {
131 switch (pin) {
132 case PIO10: /* No hysteresis for the I2C pins */
133 case PIO11:
134 break;
135
136 default:
137 PIN_HYS_CLR(pin);
138 PIN_HYS_SET(pin, enable);
139 break;
140 }
141 }
142
143 /*Inverts (or not) the input seen by a pin. */
144 void Chip_IOCON_PinSetInputInverted(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool invert)
145 {
146 PIN_INV_CLR(pin);
147 PIN_INV_SET(pin, invert);
148 }
149
150 /* Enables/disables Open-Drain mode for a pin. */
151 void Chip_IOCON_PinSetOpenDrainMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool open_drain)
152 {
153 PIN_OD_CLR(pin);
154 PIN_OD_SET(pin, open_drain);
155 }
156
157 /* Enable/configure digital filter sample mode for a pin. */
158 void Chip_IOCON_PinSetSampleMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_SMODE_T smode)
159 {
160 PIN_SMODE_CLR(pin);
161 PIN_SMODE_SET(pin, smode);
162 }
163
164 /* Set the peripheral clock divisor for a pin. */
165 void Chip_IOCON_PinSetClockDivisor(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_CLKDIV_T clkdiv)
166 {
167 PIN_CLKDIV_CLR(pin);
168 PIN_CLKDIV_SET(pin, clkdiv);
169 }
170
171 /* Set the I2C mode for a pin. */
172 void Chip_IOCON_PinSetI2CMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_I2CMODE_T mode)
173 {
174 switch (pin) {
175 case PIO10:
176 case PIO11:
177 PIN_I2CMODE_CLR(pin);
178 PIN_I2CMODE_SET(pin, mode);
179 break;
180
181 default: /* Do nothing for non-I2C specific pins */
182 break;
183 }
184 }