Nut/OS  5.0.5
API Reference
gpio_lpc17xx.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
00003  *
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the copyright holders nor the names of
00016  *    contributors may be used to endorse or promote products derived
00017  *    from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00026  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00027  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00028  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00029  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  * For additional information see http://www.ethernut.de/
00033  */
00034 
00035 /*
00036  * \verbatim
00037  * $Id: gpio_lpc17xx.h $
00038  * \endverbatim
00039  */
00040 
00041 #include <cfg/arch.h>
00042 #include <cfg/arch/gpio.h>
00043 #include <dev/irqreg.h>
00044 #if defined(MCU_LPC176x)
00045 #include <arch/cm3/nxp/lpc176x.h>
00046 #elif defined(MCU_LPC177x_8x)
00047 #include <arch/cm3/nxp/lpc177x_8x.h>
00048 #else
00049 #warning "Unknown LPC family"
00050 #endif
00051 
00052 #define NUTGPIO_PORT    0
00053 #define NUTGPIO_PORT0   0
00054 #define NUTGPIO_PORT1   1
00055 #define NUTGPIO_PORT2   2
00056 #define NUTGPIO_PORT3   3
00057 #define NUTGPIO_PORT4   4
00058 #define NUTGPIO_PORT5   5
00059 
00060 #define NUTGPIO_PORTA   NUTGPIO_PORT0
00061 #define NUTGPIO_PORTB   NUTGPIO_PORT1
00062 #define NUTGPIO_PORTC   NUTGPIO_PORT2
00063 #define NUTGPIO_PORTD   NUTGPIO_PORT3
00064 #define NUTGPIO_PORTE   NUTGPIO_PORT4
00065 #define NUTGPIO_PORTF   NUTGPIO_PORT5
00066 
00067 #define NUTGPIO_EXTINT0     1
00068 #define NUTGPIO_EXTINT1     2
00069 #define NUTGPIO_EXTINT2     3
00070 #define NUTGPIO_EXTINT3     4
00071 #define NUTGPIO_EXTINT4     5
00072 
00073 
00081 #define GPIO_CFG_INPUT      0x00000000
00082 
00083 
00090 #define GPIO_CFG_DISABLED   0x00000001
00091 
00098 #define GPIO_CFG_OUTPUT     0x00000002
00099 
00103 #define GPIO_CFG_PULLUP     0x00000004
00104 
00108 #define GPIO_CFG_PULLDOWN   0x00000008
00109 
00113 #define GPIO_CFG_REPEATER   0x00000010
00114 
00120 #define GPIO_CFG_MULTIDRIVE 0x00000020
00121 
00126 #if defined(MCU_LPC176x)
00127 /*Not supported with the LPC177x family */
00128 #define GPIO_CFG_DEBOUNCE   0x00000000
00129 #elif defined(MCU_LPC177x_8x)
00130 #define GPIO_CFG_DEBOUNCE   0x00000040
00131 #endif
00132 
00133 #if defined(MCU_LPC177x_8x)
00134 #define GPIO_CFG_HYSTERESIS 0x00000080
00135 #define GPIO_CFG_INVERT     0x00000100
00136 #define GPIO_CFG_SLEWCTRL   0x00000200
00137 #define GPIO_CFG_ADMODE     0x00000400
00138 #define GPIO_CFG_DAC_ENABLE 0x00000800
00139 #endif
00140 
00141 
00142 
00151 #define GPIO_CFG_PERIPHERAL_MASK 0x07000000
00152 #define GPIO_CFG_PERIPHERAL_POS  24
00153 #define GPIO_CFG_PERIPHERAL0  0x00000000
00154 #define GPIO_CFG_PERIPHERAL1  0x01000000
00155 #define GPIO_CFG_PERIPHERAL2  0x02000000
00156 #define GPIO_CFG_PERIPHERAL3  0x03000000
00157 #if defined(MCU_LPC177x_8x)
00158 #define GPIO_CFG_PERIPHERAL4  0x04000000
00159 #define GPIO_CFG_PERIPHERAL5  0x05000000
00160 #define GPIO_CFG_PERIPHERAL6  0x06000000
00161 #define GPIO_CFG_PERIPHERAL7  0x07000000
00162 #endif
00163 
00164 #define GPIO_BANKID2BASE(bank) (LPC_GPIO0_BASE + (bank << 5))
00165 
00166 typedef struct {
00167     void (*iov_handler) (void *);
00168     void *iov_arg;
00169 } GPIO_VECTOR;
00170 
00171 typedef struct _gpio_signal GPIO_SIGNAL;
00172 
00173 struct _gpio_signal {
00174     int   ios_port;
00175     void (*ios_handler) (void *);
00176     int (*ios_ctl) (GPIO_SIGNAL * sig, int cmd, void *param, int bit);
00177     GPIO_VECTOR *ios_vector;
00178     uint32_t enabled;
00179     uint32_t mode_rising_enabled;
00180     uint32_t mode_falling_enabled;
00181 };
00182 
00183 
00184 extern GPIO_SIGNAL sig_GPIO0;
00185 extern GPIO_SIGNAL sig_GPIO2;
00186 
00187 extern uint32_t GpioPinConfigGet(int bank, int bit);
00188 extern int GpioPinConfigSet(int bank, int bit, uint32_t flags);
00189 extern int GpioPortConfigSet(int bank, uint32_t mask, uint32_t flags);
00190 
00191 #define GpioPinGet(bank, bit)            CM3BBREG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOPIN, bit)
00192 //#define GpioPinSet(bank, bit, value)   CM3BBREG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOPIN, bit) = (value)
00193 #define GpioPinSet(bank, bit, value)     if (value) CM3BBREG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOSET, bit) = 1; else \
00194                                                     CM3BBREG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOCLR, bit) = 1;
00195 #define GpioPinMaskSet(bank, bit, value) CM3BBREG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOMASK, bit) = (value)
00196 
00197 #define GpioPinSetHigh(bank, bit)        CM3BBREG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOSET, bit) = 1
00198 #define GpioPinSetLow(bank, bit)         CM3BBREG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOCLR, bit) = 1
00199 
00200 #define GpioPortGet(bank)                CM3REG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOPIN )
00201 #define GpioPortSet(bank, value)         CM3REG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOPIN ) = (value)
00202 #define GpioPortSetHigh(bank, mask)      CM3REG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOSET)  = (mask)
00203 #define GpioPortSetLow(bank, mask)       CM3REG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOCLR)  = (mask)
00204 #define GpioPortMaskSet(bank, mask)      CM3REG(GPIO_BANKID2BASE(bank), LPC_GPIO_TypeDef, FIOMASK) = (mask)
00205 
00206 extern int GpioRegisterIrqHandler(GPIO_SIGNAL * sig, int bit, void (*handler) (void *), void *arg);
00207 extern int GpioIrqEnable(GPIO_SIGNAL * sig, int bit);
00208 extern int GpioIrqStatus(GPIO_SIGNAL * sig, int bit);
00209 extern int GpioIrqDisable(GPIO_SIGNAL * sig, int bit);
00210 extern int GpioIrqSetMode(GPIO_SIGNAL * sig, int bit, int mode);