00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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);