Skip to content

Commit 4cf96b8

Browse files
authored
Merge pull request #10482 from SiliconLabs/fix/allow_nc_pins
Allow NC pins to be instantiated on Silicon Labs platforms
2 parents 3e1a24b + 365f364 commit 4cf96b8

File tree

1 file changed

+8
-2
lines changed
  • targets/TARGET_Silicon_Labs/TARGET_EFM32

1 file changed

+8
-2
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/gpio_api.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
void gpio_write(gpio_t *obj, int value)
3131
{
32+
MBED_ASSERT(obj->pin != NC);
33+
3234
if (value) {
3335
GPIO_PinOutSet((GPIO_Port_TypeDef)(obj->pin >> 4 & 0xF), obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin
3436
} else {
@@ -38,6 +40,8 @@ void gpio_write(gpio_t *obj, int value)
3840

3941
int gpio_read(gpio_t *obj)
4042
{
43+
MBED_ASSERT(obj->pin != NC);
44+
4145
if (obj->dir == PIN_INPUT) {
4246
return GPIO_PinInGet((GPIO_Port_TypeDef)(obj->pin >> 4 & 0xF), obj->pin & 0xF); // Pin number encoded in first four bits of obj->pin
4347
} else {
@@ -63,15 +67,15 @@ uint32_t gpio_set(PinName pin)
6367

6468
void gpio_init(gpio_t *obj, PinName pin)
6569
{
66-
MBED_ASSERT(pin != NC);
67-
6870
CMU_ClockEnable(cmuClock_HFPER, true);
6971
CMU_ClockEnable(cmuClock_GPIO, true);
7072
obj->pin = pin;
7173
}
7274

7375
void gpio_mode(gpio_t *obj, PinMode mode)
7476
{
77+
MBED_ASSERT(obj->pin != NC);
78+
7579
uint32_t pin = 1 << (obj->pin & 0xF);
7680
uint32_t port = (obj->pin >> 4) & 0xF;
7781

@@ -129,6 +133,8 @@ void gpio_mode(gpio_t *obj, PinMode mode)
129133
// Used by DigitalInOut to set correct mode when direction is set
130134
void gpio_dir(gpio_t *obj, PinDirection direction)
131135
{
136+
MBED_ASSERT(obj->pin != NC);
137+
132138
obj->dir = direction;
133139
switch (direction) {
134140
case PIN_INPUT:

0 commit comments

Comments
 (0)