mirror of https://github.com/ARMmbed/mbed-os.git
[GPIO] optimize memory usage: get rid of 8 bytes of RAM allocation per GPIO object.
parent
204e716417
commit
4b020f80e7
|
@ -42,8 +42,6 @@ void gpio_init(gpio_t *obj, PinName pin)
|
|||
CMU_ClockEnable(cmuClock_HFPER, true);
|
||||
CMU_ClockEnable(cmuClock_GPIO, true);
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->port = pin >> 4;
|
||||
}
|
||||
|
||||
void gpio_pin_enable(gpio_t *obj, uint8_t enable)
|
||||
|
@ -63,7 +61,7 @@ void gpio_mode(gpio_t *obj, PinMode mode)
|
|||
//Handle pullup for input
|
||||
if(mode == InputPullUp) {
|
||||
//Set DOUT
|
||||
GPIO->P[obj->port & 0xF].DOUTSET = 1 << (obj->pin & 0xF);
|
||||
GPIO->P[(obj->pin >> 4) & 0xF].DOUTSET = 1 << (obj->pin & 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,27 +25,25 @@ extern "C" {
|
|||
|
||||
typedef struct {
|
||||
PinName pin;
|
||||
uint32_t mask;
|
||||
GPIO_Port_TypeDef port;
|
||||
PinMode mode;
|
||||
uint32_t dir;
|
||||
PinDirection dir;
|
||||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value)
|
||||
{
|
||||
if (value) {
|
||||
GPIO_PinOutSet(obj->port, obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin
|
||||
GPIO_PinOutSet((GPIO_Port_TypeDef)((obj->pin >> 4) & 0xF), obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin
|
||||
} else {
|
||||
GPIO_PinOutClear(obj->port, obj->pin & 0xF);
|
||||
GPIO_PinOutClear((GPIO_Port_TypeDef)((obj->pin >> 4) & 0xF), obj->pin & 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj)
|
||||
{
|
||||
if (obj->dir == PIN_INPUT) {
|
||||
return GPIO_PinInGet(obj->port, obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin
|
||||
return GPIO_PinInGet((GPIO_Port_TypeDef)((obj->pin >> 4) & 0xF), obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin
|
||||
} else {
|
||||
return GPIO_PinOutGet(obj->port, obj->pin & 0xF);
|
||||
return GPIO_PinOutGet((GPIO_Port_TypeDef)((obj->pin >> 4) & 0xF), obj->pin & 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue