Skip to content

Commit afcc1a1

Browse files
committed
app: status LED: create module for ERS board status LED. Remove ad hoc
status LED code from `main.c`.
1 parent 3936199 commit afcc1a1

7 files changed

Lines changed: 119 additions & 38 deletions

File tree

controlSystem/RecoveryBoard/firmware-zephyr/apps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ project(ers_drogue_board)
1818

1919
target_include_directories(app PRIVATE
2020
include
21-
# ${ERS_REPO_ROOT}/shell-module/include
2221
shell-module/include
2322
)
2423

@@ -34,4 +33,5 @@ target_sources(app PRIVATE
3433
src/pwm.c
3534
src/settings-ers.c
3635
src/shell-support.c
36+
src/status-led.c
3737
)

controlSystem/RecoveryBoard/firmware-zephyr/apps/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ module = ERS_SETTINGS
8383
module-str = ERS settings module
8484
source "subsys/logging/Kconfig.template.log_config"
8585

86+
module = STATUS_LED
87+
module-str = ERS status led
88+
source "subsys/logging/Kconfig.template.log_config"
89+
8690
# Following Kconfig inclusion needed to support Zephyr logging template macros
8791
source "Kconfig.zephyr"
8892

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef ERS_STATUS_LED
2+
#define ERS_STATUS_LED
3+
4+
int32_t status_led_init(void);
5+
6+
#endif // ERS_STATUS_LED

controlSystem/RecoveryBoard/firmware-zephyr/apps/src/main.c

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <ers-pwm.h>
2020
#include <settings-ers.h>
2121
#include <shell-support.h>
22+
#include <status-led.h>
2223

2324
LOG_MODULE_REGISTER(ers_main, LOG_LEVEL_INF);
2425

@@ -32,35 +33,6 @@ LOG_MODULE_REGISTER(ers_main, LOG_LEVEL_INF);
3233
// - SECTION - routines
3334
//----------------------------------------------------------------------
3435

35-
#include <zephyr/drivers/gpio.h>
36-
// static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
37-
#define LED0_NODE DT_ALIAS(led0)
38-
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
39-
40-
int32_t dev_configure_led(void)
41-
{
42-
int32_t rc = 0;
43-
44-
if (!gpio_is_ready_dt(&led)) {
45-
return -ENODEV;
46-
}
47-
48-
rc = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
49-
return rc;
50-
}
51-
52-
int32_t dev_toggle_led(void)
53-
{
54-
static bool led_state = true;
55-
56-
int32_t rc = gpio_pin_toggle_dt(&led);
57-
if (rc < 0) {
58-
return rc;
59-
}
60-
led_state = !led_state;
61-
return rc;
62-
}
63-
6436
int main(void)
6537
{
6638
static uint32_t loop_count = 0;
@@ -99,7 +71,7 @@ int main(void)
9971
rc = pwm_init();
10072
LOG_INF("ERS PWM module init returns %d", rc);
10173

102-
rc = dev_configure_led();
74+
rc = status_led_init();
10375
LOG_INF("- DEV 0108 - routine to configure led0 returns %d", rc);
10476

10577
LOG_INF("main() entering 'while (1)' loop . . .");
@@ -128,7 +100,6 @@ int main(void)
128100
rc = pwm_play_melody();
129101
// TODO [ ] . . . do something with rc.
130102

131-
rc = dev_toggle_led();
132103
k_msleep(ERS_MAIN_LOOP_PERIOD_MS);
133104
}
134105

controlSystem/RecoveryBoard/firmware-zephyr/apps/src/shell-support.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int cmd_wrapper_read_adc_in1(const struct shell *shell, size_t argc, char
5353
}
5454

5555
//----------------------------------------------------------------------
56-
// - SECTION - ERS diagnotics
56+
// - COMMAND SET - diagnotics
5757
//----------------------------------------------------------------------
5858

5959
static int cmd_diag_periodic_on(const struct shell *shell, size_t argc, char *argv[])
@@ -90,7 +90,34 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
9090
SHELL_CMD_REGISTER(diag, &ers_cmds_diag, "- ERS - diagnostics", NULL);
9191

9292
//----------------------------------------------------------------------
93-
// - SECTION - ERS ADC commands
93+
// - COMMAND SET - status LED
94+
//----------------------------------------------------------------------
95+
96+
static int cmd_status_led_on(const struct shell *shell, size_t argc, char *argv[])
97+
{
98+
shell_fprintf(shell, SHELL_NORMAL, "- STUB - enable ERS status LED\n\r");
99+
return 0;
100+
}
101+
102+
static int cmd_status_led_off(const struct shell *shell, size_t argc, char *argv[])
103+
{
104+
shell_fprintf(shell, SHELL_NORMAL, "- STUB - disable ERS status LED\n\r");
105+
return 0;
106+
}
107+
108+
SHELL_STATIC_SUBCMD_SET_CREATE(
109+
cmds_status_led,
110+
SHELL_CMD_ARG(on, NULL, "enable ERS status LED",
111+
cmd_status_led_on, 0, 0),
112+
SHELL_CMD_ARG(off, NULL, "disable ERS status LED",
113+
cmd_status_led_off, 0, 0),
114+
SHELL_SUBCMD_SET_END
115+
);
116+
117+
SHELL_CMD_REGISTER(led, &cmds_status_led, "- ERS - status LED", NULL);
118+
119+
//----------------------------------------------------------------------
120+
// - COMMAND SET - ADC commands
94121
//----------------------------------------------------------------------
95122

96123
static int cmd_wrapper_read_adc_all(const struct shell *shell, size_t argc, char *argv[])
@@ -136,7 +163,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
136163
SHELL_CMD_REGISTER(ers, &ers_cmds, "- ERS - development commands", NULL);
137164

138165
//----------------------------------------------------------------------
139-
// - SECTION - ERS Hall sensor commands
166+
// - COMMAND SET - Hall sensor commands
140167
//----------------------------------------------------------------------
141168

142169
/**
@@ -289,7 +316,7 @@ SHELL_CMD_REGISTER(ring, &sub_section_ring, "- ERS - lock ring commands", NULL);
289316
// clang-format on
290317

291318
//----------------------------------------------------------------------
292-
// - SECTION - DAC commands
319+
// - COMMAND SET - DAC commands
293320
//----------------------------------------------------------------------
294321

295322
static int cmd_dac_show_range(const struct shell *shell, size_t argc, char *argv[])
@@ -394,6 +421,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
394421
cmd_dac_get_setting_for_lock_unlock, 0, 0),
395422
SHELL_SUBCMD_SET_END
396423
);
424+
// TODO [ ] consider renaming `cmd_dac_get_setting_for_lock_unlock` to `cmd_dac_retrieve...`
425+
// to match the settings' module API names 'store' and 'retrieve'.
397426

398427
SHELL_CMD_REGISTER(dac, &cmds_dac, "- ERS - DAC info and set commands", NULL);
399428

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* ERS Zephyr firmware - status LED module
3+
*/
4+
5+
#include <zephyr/drivers/gpio.h>
6+
#include <zephyr/logging/log.h>
7+
LOG_MODULE_REGISTER(status_led, CONFIG_STATUS_LED_LOG_LEVEL);
8+
9+
//----------------------------------------------------------------------
10+
// - SECTION - defines
11+
//----------------------------------------------------------------------
12+
13+
#define LED_START_DURATION_MS 1000
14+
#define LED_PERIOD_MS 500
15+
16+
//----------------------------------------------------------------------
17+
// - SECTION - file scoped
18+
//----------------------------------------------------------------------
19+
20+
#define LED0_NODE DT_ALIAS(led0)
21+
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
22+
23+
//----------------------------------------------------------------------
24+
// - SECTION - routines
25+
//----------------------------------------------------------------------
26+
27+
int32_t configure_led(void)
28+
{
29+
int32_t rc = 0;
30+
31+
if (!gpio_is_ready_dt(&led)) {
32+
return -ENODEV;
33+
}
34+
35+
rc = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
36+
return rc;
37+
}
38+
39+
#if 1
40+
// int32_t dev_toggle_led(void)
41+
void status_led_timer_handler(struct k_timer *dummy)
42+
{
43+
static bool led_state = true;
44+
45+
int32_t rc = gpio_pin_toggle_dt(&led);
46+
if (rc < 0) {
47+
// return rc;
48+
}
49+
led_state = !led_state;
50+
// return rc;
51+
}
52+
#endif
53+
54+
K_TIMER_DEFINE(status_led_timer, status_led_timer_handler, NULL);
55+
56+
int32_t status_led_init(void)
57+
{
58+
int32_t rc = 0;
59+
if (configure_led() != 0)
60+
{
61+
LOG_ERR("Failed to init GPIO for status LED, err %d", rc);
62+
return rc;
63+
}
64+
65+
// LOG_INF("- DEV 0214 - RETURNING EARLY . . .");
66+
// return rc;
67+
68+
LOG_INF("- DEV 0214 - STARTING TIMER FOR STATUS LED . . .");
69+
k_timer_start(&status_led_timer, K_MSEC(LED_START_DURATION_MS), K_MSEC(LED_PERIOD_MS));
70+
return rc;
71+
}

controlSystem/RecoveryBoard/firmware-zephyr/boards/psas/ers-v3p1.dts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@
241241
pinctrl-0 = <&adc_in0_pa0>;
242242
pinctrl-names = "default";
243243
// for Zephyr 3.7.0 the symbol SYNC requires arrow brackets:
244-
st,adc-clock-source = <SYNC>;
244+
// st,adc-clock-source = <SYNC>;
245245
// for Zephyr 4.3.0 the symbol SYNC requires double quotes:
246-
// st,adc-clock-source = "SYNC";
246+
st,adc-clock-source = "SYNC";
247247
st,adc-prescaler = <4>;
248248
status = "okay";
249249
};

0 commit comments

Comments
 (0)