Skip to content

Commit ce1c2c7

Browse files
committed
[BEETLE] Add LED Emulation
The current version of MBED test environment requires LEDs to be present in the platform. Beetle HW does not provide any user programmable LEDs. This patch provides an emulation of the feature by using dummy PINs. Signed-off-by: Vincenzo Frascino <[email protected]>
1 parent 4f61cfd commit ce1c2c7

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

hal/targets/hal/TARGET_ARM_SSG/TARGET_BEETLE/PinNames.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ typedef enum {
126126
SENSOR_SDA = 506,
127127
SENSOR_SCL = 507,
128128

129+
// Emulated LEDS
130+
LED1 = 1001,
131+
LED2 = 1002,
132+
LED3 = 1003,
133+
LED4 = 1004,
134+
129135
// Not connected
130136
NC = (int)0xFFFFFFFF,
131-
// LEDS not connected
132-
LED1 = NC,
133-
LED2 = NC,
134-
LED3 = NC,
135-
LED4 = NC,
136137
} PinName;
137138

138139
typedef enum {

hal/targets/hal/TARGET_ARM_SSG/TARGET_BEETLE/gpio_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ uint32_t gpio_set(PinName pin) {
2424
pin_value = pin;
2525
} else if (pin >= 16 && pin <= 31) {
2626
pin_value = pin-16;
27+
} else if (pin >= 1001 && pin <= 1004) {
28+
/* Emulated LEDs */
29+
return (1);
2730
}
2831

2932
pin_function(pin, 0);
@@ -44,6 +47,9 @@ void gpio_init(gpio_t *obj, PinName pin) {
4447
pin_value = pin;
4548
} else if (pin >= 16 && pin <= 31) {
4649
pin_value = pin-16;
50+
} else if (pin >= 1001 && pin <= 1004) {
51+
/* Emulated LEDs */
52+
return;
4753
}
4854

4955
obj->mask = 0x1 << pin_value;

hal/targets/hal/TARGET_ARM_SSG/TARGET_BEETLE/gpio_object.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,25 @@ typedef struct {
3737
} gpio_t;
3838

3939
static inline void gpio_write(gpio_t *obj, int value) {
40-
if (value == 1){
41-
*obj->reg_data |= (obj->mask);
42-
} else if (value == 0){
43-
*obj->reg_data &= ~(obj->mask);
40+
if (obj->pin < LED1 || obj->pin > LED4) {
41+
if (value == 1) {
42+
*obj->reg_data |= (obj->mask);
43+
} else if (value == 0){
44+
*obj->reg_data &= ~(obj->mask);
45+
}
46+
} else {
47+
/* Emulated LEDs return without taking any action */
48+
return;
4449
}
4550
}
4651

4752
static inline int gpio_read(gpio_t *obj) {
48-
return ((*obj->reg_in & obj->mask) ? 1 : 0);
53+
if (obj->pin < LED1 || obj->pin > LED4) {
54+
return ((*obj->reg_in & obj->mask) ? 1 : 0);
55+
} else {
56+
/* Emulated LEDs return OFF always */
57+
return 0;
58+
}
4959
}
5060

5161
#ifdef __cplusplus

0 commit comments

Comments
 (0)