mirror of https://github.com/ARMmbed/mbed-os.git
Make pinmap and port API use the correct memory region for the GPIOs.
parent
3a0c872df4
commit
4e68eaef57
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue