define led env name in dts

Signed-off-by: Jianhui Zhao <jianhui.zhao@gl-inet.com>
This commit is contained in:
Jianhui Zhao
2022-11-23 09:51:35 +08:00
parent 1a72e4144c
commit 0547e60e94
5 changed files with 51 additions and 14 deletions

View File

@@ -24,6 +24,9 @@
environment {
lu = "mtkupgrade fip uboot-gl-mt2500.bin";
lf = "mtkupgrade fw openwrt-gl-mt2500.bin";
blink_led = "blue:run";
system_led = "white:system";
gpio_usb_power = "12";
};
};

View File

@@ -24,6 +24,9 @@
environment {
lu = "mtkupgrade fip uboot-gl-mt3000.bin";
lf = "mtkupgrade fw openwrt-gl-mt3000.bin";
blink_led = "blue:run";
system_led = "white:system";
gpio_usb_power = "12";
};
};

View File

@@ -6,10 +6,35 @@
static struct poller_async led_p;
void led_control(const char *cmd, const char *name, const char *arg)
{
const char *led = env_get(name);
char buf[128];
if (!led)
return;
sprintf(buf, "%s %s %s", cmd, led, arg);
run_command(buf, 0);
}
static void usb_power_clr(void)
{
const char *num = env_get("gpio_usb_power");
char buf[128];
if (!num)
return;
sprintf(buf, "gpio clear %s", num);
run_command(buf, 0);
}
static void led_action_post(void *arg)
{
run_command("ledblink blue:run 0", 0);
run_command("led blue:run on", 0);
led_control("ledblink", "blink_led", "0");
led_control("led", "blink_led", "on");
}
static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
@@ -19,8 +44,10 @@ static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[
struct udevice *dev;
ulong ts;
run_command("ledblink blue:run 250", 0);
run_command("gpio clear 12", 0);
led_control("ledblink", "blink_led", "250");
usb_power_clr();
ret = button_get_by_label(button_label, &dev);
if (ret) {
printf("Button '%s' not found (err=%d)\n", button_label, ret);
@@ -33,7 +60,7 @@ static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[
return CMD_RET_SUCCESS;
}
run_command("ledblink blue:run 500", 0);
led_control("ledblink", "blink_led", "500");
printf("RESET button is pressed for: %2d second(s)", counter++);
@@ -50,13 +77,13 @@ static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[
printf("\n");
run_command("ledblink blue:run 0", 0);
led_control("ledblink", "blink_led", "0");
if (counter == 6) {
run_command("led white:system on", 0);
led_control("led", "system_led", "on");
run_command("httpd", 0);
} else {
run_command("led blue:run on", 0);
led_control("ledblink", "blink_led", "0");
}
return CMD_RET_SUCCESS;

View File

@@ -18,6 +18,8 @@
#include "fs.h"
void led_control(const char *cmd, const char *name, const char *arg);
enum {
FW_TYPE_GPT,
FW_TYPE_BL2,
@@ -70,7 +72,7 @@ static int write_firmware_failsafe(size_t data_addr, uint32_t data_size)
{
int r;
run_command("ledblink blue:run 100", 0);
led_control("ledblink", "blink_led", "100");
switch (fw_type) {
#ifdef CONFIG_MT7981_BOOTMENU_EMMC
@@ -94,7 +96,7 @@ static int write_firmware_failsafe(size_t data_addr, uint32_t data_size)
break;
}
run_command("ledblink blue:run 0", 0);
led_control("ledblink", "blink_led", "0");
return r;
}
@@ -293,8 +295,8 @@ static void result_handler(enum httpd_uri_handler_status status,
/* invalidate upload identifier */
upload_data_id = rand();
run_command("led blue:run on", 0);
run_command("led white:system off", 0);
led_control("led", "blink_led", "on");
led_control("led", "system_led", "off");
if (!st->ret)
response->data = "success";

View File

@@ -16,6 +16,8 @@
#include <net/httpd.h>
#include <command.h>
void led_control(const char *cmd, const char *name, const char *arg);
struct httpd_instance {
struct list_head node;
@@ -641,7 +643,7 @@ static int httpd_handle_request(struct httpd_instance *inst,
free(boundary);
}
run_command("ledblink blue:run 0", 0);
led_control("ledblink", "blink_led", "0");
/* call uri handler */
assert((size_t) req->urih->cb > CONFIG_SYS_SDRAM_BASE);
@@ -684,7 +686,7 @@ static void httpd_rx(struct httpd_instance *inst, struct tcb_cb_data *cbd)
u8 sip[4];
if (pdata->status == HTTPD_S_NEW) {
run_command("ledblink blue:run 100", 0);
led_control("ledblink", "blink_led", "100");
memcpy(sip, &cbd->sip, 4);
debug("New connection from %d.%d.%d.%d:%d\n",