gpio_stm32.h

Go to the documentation of this file.
00001 
00036 #ifndef GPIO_STM32_H
00037 #define GPIO_STM32_H
00038 
00039 #include <io/stm32.h>
00040 
00041 /* GPIO configuration registers structure */
00042 struct stm32_gpio
00043 {
00044     reg32_t CRL;
00045     reg32_t CRH;
00046     reg32_t IDR;
00047     reg32_t ODR;
00048     reg32_t BSRR;
00049     reg32_t BRR;
00050     reg32_t LCKR;
00051 };
00052 
00056 /*\{*/
00057 enum
00058 {
00059     GPIO_MODE_AIN = 0x0,
00060     GPIO_MODE_IN_FLOATING = 0x04,
00061     GPIO_MODE_IPD = 0x28,
00062     GPIO_MODE_IPU = 0x48,
00063     GPIO_MODE_OUT_OD = 0x14,
00064     GPIO_MODE_OUT_PP = 0x10,
00065     GPIO_MODE_AF_OD = 0x1C,
00066     GPIO_MODE_AF_PP = 0x18,
00067 };
00068 /*\}*/
00069 
00073 /*\{*/
00074 enum
00075 {
00076     GPIO_SPEED_10MHZ = 1,
00077     GPIO_SPEED_2MHZ,
00078     GPIO_SPEED_50MHZ,
00079 };
00080 /*\}*/
00081 
00082 /* Write a value to the specified pin(s) */
00083 INLINE void
00084 stm32_gpioPinWrite(struct stm32_gpio *base, uint32_t pins, uint8_t val)
00085 {
00086     if (val)
00087         base->BSRR |= pins;
00088     else
00089         base->BRR  |= pins;
00090 }
00091 
00092 /* Read a value from the specified pin(s) */
00093 INLINE uint8_t stm32_gpioPinRead(struct stm32_gpio *base, uint32_t pins)
00094 {
00095     return !!(base->IDR & pins);
00096 }
00097 
00098 /* Initialize a GPIO peripheral configuration */
00099 int stm32_gpioPinConfig(struct stm32_gpio *base,
00100             uint16_t pins, uint8_t mode, uint8_t speed);
00101 
00102 #endif /* GPIO_STM32_H */