gpio_stm32.c
Go to the documentation of this file.00001
00038 #include <cfg/compiler.h>
00039 #include <cfg/debug.h>
00040 #include <io/stm32.h>
00041 #include "gpio_stm32.h"
00042
00053 int stm32_gpioPinConfig(struct stm32_gpio *base,
00054 uint16_t pins, uint8_t mode, uint8_t speed)
00055 {
00056 uint32_t reg_mode = mode & 0x0f;
00057 int i;
00058
00059 if (mode & 0x10)
00060 reg_mode |= speed;
00061
00062 if (pins & 0xff)
00063 {
00064 uint32_t reg = base->CRL;
00065
00066 for (i = 0; i < 8; i++)
00067 {
00068 uint32_t pos = 1 << i;
00069
00070 if (pins & pos)
00071 {
00072 pos = i << 2;
00073 reg &= ~(0x0f << pos);
00074 reg |= reg_mode << pos;
00075
00076 if (mode == GPIO_MODE_IPD)
00077 base->BRR = 0x01 << i;
00078 if (mode == GPIO_MODE_IPU)
00079 base->BSRR = 0x01 << i;
00080 }
00081 }
00082 base->CRL = reg;
00083 }
00084 if (pins > 0xff)
00085 {
00086 uint32_t reg = base->CRH;
00087
00088 for (i = 0; i < 8; i++)
00089 {
00090 uint32_t pos = 1 << (i + 8);
00091
00092 if (pins & pos)
00093 {
00094 pos = i << 2;
00095 reg &= ~(0x0f << pos);
00096 reg |= reg_mode << pos;
00097
00098 if (mode == GPIO_MODE_IPD)
00099 base->BRR = 0x01 << (i + 8);
00100 if (mode == GPIO_MODE_IPU)
00101 base->BSRR = 0x01 << (i + 8);
00102 }
00103 }
00104 base->CRH = reg;
00105 }
00106 return 0;
00107 }