Nut/OS  5.0.5
API Reference
gpio_stm32.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 by Ulrich Prinz (uprinz2@netscape.net)
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: stm32_can2.c 3108 2010-09-15 21:11:15Z Astralix $
00038  * \endverbatim
00039  */
00040 
00041 #include <cfg/arch.h>
00042 #include <cfg/arch/gpio.h>
00043 #include <dev/irqreg.h>
00044 #include <arch/cm3/stm/stm32xxxx.h>
00045 
00046 #define NUTGPIO_PORT    GPIOA_BASE
00047 #define NUTGPIO_PORTA   GPIOA_BASE
00048 #define NUTGPIO_PORTB   GPIOB_BASE
00049 #define NUTGPIO_PORTC   GPIOC_BASE
00050 #define NUTGPIO_PORTD   GPIOD_BASE
00051 #define NUTGPIO_PORTE   GPIOE_BASE
00052 #define NUTGPIO_PORTF   GPIOF_BASE
00053 #define NUTGPIO_PORTG   GPIOG_BASE
00054 
00055 #define NUTGPIO_EXTINT0     1
00056 #define NUTGPIO_EXTINT1     2
00057 #define NUTGPIO_EXTINT2     3
00058 #define NUTGPIO_EXTINT3     4
00059 #define NUTGPIO_EXTINT4     5
00060 
00068 #define GPIO_CFG_INPUT      0x00000000
00069 
00077 #define GPIO_CFG_DISABLED   0x00000001
00078 
00086 #define GPIO_CFG_OUTPUT     0x00000002
00087 
00091 #define GPIO_CFG_PULLUP     0x00000004
00092 
00098 #define GPIO_CFG_MULTIDRIVE 0x00000008
00099 
00105 #define GPIO_CFG_DEBOUNCE   0x00000000
00106 
00113 #define GPIO_CFG_PERIPHAL   0x00000020
00114 
00126 #define GPIO_CFG_SPEED       0x000000C0
00127 #define GPIO_CFG_SPEED_SLOW  0x00000040
00128 #define GPIO_CFG_SPEED_MED   0x00000000
00129 #define GPIO_CFG_SPEED_FAST  0x00000080
00130 #define GPIO_CFG_SPEED_HIGH  0x000000C0
00131 
00132 typedef struct {
00133     void (*iov_handler) (void *);
00134     void *iov_arg;
00135 } GPIO_VECTOR;
00136 
00137 typedef struct {
00138     IRQ_HANDLER *ios_sig;
00139     void (*ios_handler) (void *);
00140     int (*ios_ctl) (int cmd, void *param, int bit);
00141     GPIO_VECTOR *ios_vector;
00142 } GPIO_SIGNAL;
00143 
00144 #if defined(PIO_ISR)
00145 extern GPIO_SIGNAL sig_GPIO;
00146 #endif
00147 #if defined(PIOA_ISR)
00148 extern GPIO_SIGNAL sig_GPIO1;
00149 #endif
00150 #if defined(PIOB_ISR)
00151 extern GPIO_SIGNAL sig_GPIO2;
00152 #endif
00153 #if defined(PIOC_ISR)
00154 extern GPIO_SIGNAL sig_GPIO3;
00155 #endif
00156 
00157 extern uint32_t GpioPinConfigGet(int bank, int bit);
00158 extern int GpioPinConfigSet(int bank, int bit, uint32_t flags);
00159 extern int GpioPortConfigSet(int bank, uint32_t mask, uint32_t flags);
00160 
00161 #define GpioPinGet(bank, bit)           CM3BBREG(bank, GPIO_TypeDef, IDR, bit)
00162 #define GpioPinSet(bank, bit, value)    CM3BBREG(bank, GPIO_TypeDef, ODR, bit) = value
00163 #if defined(MCU_STM32F1)
00164 #define GpioPinSetHigh(bank, bit)   CM3BBREG(bank, GPIO_TypeDef, BSRR, bit) = 1
00165 #define GpioPinSetLow(bank, bit)    CM3BBREG(bank, GPIO_TypeDef, BRR , bit) = 1
00166 #else
00167 #define GpioPinSetHigh(bank, bit)   CM3BBREG(bank, GPIO_TypeDef, BSRRL, bit) = 1
00168 #define GpioPinSetLow(bank, bit)    CM3BBREG(bank, GPIO_TypeDef, BSRRH, bit) = 1
00169 #endif
00170 
00171 #define GpioPortGet(bank)       CM3REG(bank, GPIO_TypeDef, IDR )
00172 #define GpioPortSet(bank, value)    CM3REG(bank, GPIO_TypeDef, ODR ) = value
00173 #define GpioPortSetHigh(bank, mask) CM3REG(bank, GPIO_TypeDef, BSRR) = mask
00174 #define GpioPortSetLow(bank, mask)  CM3REG(bank, GPIO_TypeDef, BRR ) = mask
00175 
00176 extern int GpioRegisterIrqHandler(GPIO_SIGNAL * sig, uint8_t bit, void (*handler) (void *), void *arg);
00177 extern int GpioIrqEnable(GPIO_SIGNAL * sig, uint8_t bit);
00178 extern int GpioIrqDisable(GPIO_SIGNAL * sig, uint8_t bit);