Make pinmap and port API use the correct memory region for the GPIOs.

pull/8/head
Joe Turner 2013-05-14 11:00:18 +01:00
parent 3a0c872df4
commit 4e68eaef57
2 changed files with 4 additions and 4 deletions

View File

@ -27,7 +27,7 @@ void pin_function(PinName pin, int function) {
int pin_index = (pin_number & 0xF);
int offset = pin_index << 1;
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6));
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)));
gpio->MODER &= ~(0x3 << offset);
gpio->MODER |= function << offset;
}
@ -40,7 +40,7 @@ void pin_alternate_function(PinName pin, int function) {
int pin_index = (pin_number & 0xF);
int offset = (pin_index & 0x7) << 2;
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6));
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)));
// Bottom seven pins are in AFR[0], top seven in AFR[1]
if (pin_index <= 0x7) {
@ -61,7 +61,7 @@ void pin_mode(PinName pin, PinMode mode) {
int pin_index = (pin_number & 0xF);
int offset = pin_index << 1;
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6));
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)));
if (mode == OpenDrain) {
gpio->OTYPER |= 1 << pin_index;
}

View File

@ -29,7 +29,7 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
uint32_t port_index = (uint32_t) port;
GPIO_TypeDef *port_reg = (GPIO_TypeDef *)(GPIOA_BASE + (port_index << 6));
GPIO_TypeDef *port_reg = (GPIO_TypeDef *)(GPIOA_BASE + (port_index << 10));
obj->reg_mode = &port_reg->MODER;
obj->reg_set = &port_reg->BSRRH;