drivers/linuxgpiod: add led 70/5770/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 4 Apr 2020 17:46:38 +0000 (19:46 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 26 Jul 2020 19:15:34 +0000 (20:15 +0100)
Bitbang interface allows having a LED on one of the GPIO.

Let also linuxgpiod driver to specify and use the LED connection.

Change-Id: Id3d8772ee1808b92354fd073ba3947bacd8253ef
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5770
Tested-by: jenkins
src/jtag/drivers/linuxgpiod.c
tcl/interface/dln-2-gpiod.cfg

index 661a926f502b9956bc24990ca4689c5601402b5a..99422a1168313811b448dcbdd2c98f41a10d8d55 100644 (file)
@@ -27,6 +27,7 @@ static int trst_gpio = -1;
 static int srst_gpio = -1;
 static int swclk_gpio = -1;
 static int swdio_gpio = -1;
+static int led_gpio = -1;
 static int gpiochip = -1;
 
 static struct gpiod_chip *gpiod_chip;
@@ -38,6 +39,7 @@ static struct gpiod_line *gpiod_trst;
 static struct gpiod_line *gpiod_swclk;
 static struct gpiod_line *gpiod_swdio;
 static struct gpiod_line *gpiod_srst;
+static struct gpiod_line *gpiod_led;
 
 static int last_swclk;
 static int last_swdio;
@@ -171,13 +173,26 @@ static int linuxgpiod_swd_write(int swclk, int swdio)
        return ERROR_OK;
 }
 
+static int linuxgpiod_blink(int on)
+{
+       int retval;
+
+       if (!gpiod_led)
+               return ERROR_OK;
+
+       retval = gpiod_line_set_value(gpiod_led, on);
+       if (retval < 0)
+               LOG_WARNING("Fail set led");
+       return retval;
+}
+
 static struct bitbang_interface linuxgpiod_bitbang = {
        .read = linuxgpiod_read,
        .write = linuxgpiod_write,
        .swdio_read = linuxgpiod_swdio_read,
        .swdio_drive = linuxgpiod_swdio_drive,
        .swd_write = linuxgpiod_swd_write,
-       .blink = NULL,
+       .blink = linuxgpiod_blink,
 };
 
 /*
@@ -248,6 +263,7 @@ static inline void helper_release(struct gpiod_line *line)
 
 static int linuxgpiod_quit(void)
 {
+       helper_release(gpiod_led);
        helper_release(gpiod_srst);
        helper_release(gpiod_swdio);
        helper_release(gpiod_swclk);
@@ -370,6 +386,12 @@ static int linuxgpiod_init(void)
                        goto out_error;
        }
 
+       if (is_gpio_valid(led_gpio)) {
+               gpiod_led = helper_get_output_line("led", led_gpio, 0);
+               if (gpiod_led == NULL)
+                       goto out_error;
+       }
+
        return ERROR_OK;
 
 out_error:
@@ -484,6 +506,15 @@ COMMAND_HANDLER(linuxgpiod_handle_swd_gpionum_swdio)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(linuxgpiod_handle_gpionum_led)
+{
+       if (CMD_ARGC == 1)
+               COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], led_gpio);
+
+       command_print(CMD, "LinuxGPIOD num: led = %d", led_gpio);
+       return ERROR_OK;
+}
+
 COMMAND_HANDLER(linuxgpiod_handle_gpiochip)
 {
        if (CMD_ARGC == 1)
@@ -564,6 +595,13 @@ static const struct command_registration linuxgpiod_command_handlers[] = {
                .help = "gpio number for swdio.",
                .usage = "swdio",
        },
+       {
+               .name = "linuxgpiod_led_num",
+               .handler = linuxgpiod_handle_gpionum_led,
+               .mode = COMMAND_CONFIG,
+               .help = "gpio number for LED.",
+               .usage = "led",
+       },
        {
                .name = "linuxgpiod_gpiochip",
                .handler = linuxgpiod_handle_gpiochip,
index 1859688be3e2d729bad1f139e4590883c4b36717..5407a244e897989a00f262c199d76bb4dc94be7d 100644 (file)
@@ -11,6 +11,7 @@
 # | TMS/SWDIO | J3.4  (PA3) | 3           |
 # | TDI       | J3.5  (PA4) | 4           |
 # | nTRST     | J3.6  (PA5) | 5           |
+# | LED       | J3.7  (PA6) | 6           |
 # | GND       | J3.12 (GND) |             |
 # +-----------+-------------+-------------+
 
@@ -21,5 +22,6 @@ linuxgpiod_jtag_nums 2 3 4 1
 linuxgpiod_trst_num 5
 linuxgpiod_swd_nums 2 3
 linuxgpiod_srst_num 0
+linuxgpiod_led_num 6
 
 reset_config trst_and_srst separate srst_push_pull

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)