Skip to content

Commit ecff775

Browse files
committed
Don't pull KSDK FSL libraries into apps
Freescale KSDK2 gpio_object.h pulled in Freescale libraries to inline some GPIO operations. The resulting namespace pollution (status_t) doesn't seem to be worth the function call overhead. Hopefully making the base address array non-automatic will offset that loss.
1 parent d1ec4be commit ecff775

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/api/gpio_api.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "gpio_api.h"
1818
#include "pinmap.h"
1919
#include "fsl_port.h"
20+
#include "fsl_gpio.h"
21+
22+
static GPIO_Type * const gpio_addrs[] = GPIO_BASE_PTRS;
2023

2124
uint32_t gpio_set(PinName pin) {
2225
MBED_ASSERT(pin != (PinName)NC);
@@ -41,7 +44,6 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
4144
void gpio_dir(gpio_t *obj, PinDirection direction) {
4245
MBED_ASSERT(obj->pin != (PinName)NC);
4346
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
44-
GPIO_Type *gpio_addrs[] = GPIO_BASE_PTRS;
4547
uint32_t pin_num = obj->pin & 0xFF;
4648
GPIO_Type *base = gpio_addrs[port];
4749

@@ -54,3 +56,19 @@ void gpio_dir(gpio_t *obj, PinDirection direction) {
5456
break;
5557
}
5658
}
59+
60+
void gpio_write(gpio_t *obj, int value) {
61+
MBED_ASSERT(obj->pin != (PinName)NC);
62+
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
63+
uint32_t pin = obj->pin & 0xFF;
64+
65+
GPIO_WritePinOutput(gpio_addrs[port], pin, value);
66+
}
67+
68+
int gpio_read(gpio_t *obj) {
69+
MBED_ASSERT(obj->pin != (PinName)NC);
70+
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
71+
uint32_t pin = obj->pin & 0xFF;
72+
73+
return (int)GPIO_ReadPinInput(gpio_addrs[port], pin);
74+
}

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/api/gpio_object.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#ifndef MBED_GPIO_OBJECT_H
1717
#define MBED_GPIO_OBJECT_H
1818

19-
#include "mbed_assert.h"
20-
#include "fsl_gpio.h"
21-
2219
#ifdef __cplusplus
2320
extern "C" {
2421
#endif
@@ -27,24 +24,6 @@ typedef struct {
2724
PinName pin;
2825
} gpio_t;
2926

30-
static inline void gpio_write(gpio_t *obj, int value) {
31-
MBED_ASSERT(obj->pin != (PinName)NC);
32-
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
33-
uint32_t pin = obj->pin & 0xFF;
34-
GPIO_Type *gpio_addrs[] = GPIO_BASE_PTRS;
35-
36-
GPIO_WritePinOutput(gpio_addrs[port], pin, value);
37-
}
38-
39-
static inline int gpio_read(gpio_t *obj) {
40-
MBED_ASSERT(obj->pin != (PinName)NC);
41-
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
42-
uint32_t pin = obj->pin & 0xFF;
43-
GPIO_Type *gpio_addrs[] = GPIO_BASE_PTRS;
44-
45-
return (int)GPIO_ReadPinInput(gpio_addrs[port], pin);
46-
}
47-
4827
static inline int gpio_is_connected(const gpio_t *obj) {
4928
return obj->pin != (PinName)NC;
5029
}

0 commit comments

Comments
 (0)