summaryrefslogtreecommitdiff
path: root/avr/cmd_boot.c
diff options
context:
space:
mode:
authorLeo C2014-10-15 21:20:41 +0200
committerLeo C2014-10-15 21:20:41 +0200
commit70c994914510f9db3ff71373cb96f50ee1669446 (patch)
treeb9fce17909ca3a66524a5b7f6c7fe7b118cb409c /avr/cmd_boot.c
parentcd5ee5442821f283f6661befb24b885d944e4c5e (diff)
downloadz180-stamp-70c994914510f9db3ff71373cb96f50ee1669446.zip
Add pin_alias
Diffstat (limited to 'avr/cmd_boot.c')
-rw-r--r--avr/cmd_boot.c84
1 files changed, 73 insertions, 11 deletions
diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c
index 26855f1..1213365 100644
--- a/avr/cmd_boot.c
+++ b/avr/cmd_boot.c
@@ -6,11 +6,13 @@
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
+#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "command.h"
#include "getopt-min.h"
+#include "env.h"
#include "z80-if.h"
#include "pin.h"
#include "debug.h"
@@ -268,7 +270,41 @@ command_ret_t do_clock2(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]
}
#endif
-// {INPUT, INPUT_PULLUP, OUTPUT, OUTPUT_TIMER} pinmode_t;
+
+static const int namestr = PIN_MAX;
+static char *pin_names[PIN_MAX+1];
+static uint_least8_t pin_names_width;
+
+void pinnames_get(void)
+{
+ static const FLASH char delim1[] = {":= "};
+ static const FLASH char delim2[] = {", "};
+ char *lp;
+ char *ptr;
+ uint_fast8_t i;
+
+ if (pin_names[namestr] != NULL)
+ free(pin_names[namestr]);
+ memset(pin_names, 0, sizeof(pin_names));
+ pin_names_width = 0;
+
+ if ((lp = getenv(PSTR(ENV_PINALIAS))) != NULL) {
+ pin_names[namestr] = strdup(lp);
+ ptr = strtok_P(pin_names[namestr], delim1);
+ while (ptr != NULL) {
+ if (((i = strtoul(ptr, &lp, 10)) < PIN_MAX) &&
+ lp != ptr &&
+ (ptr = strtok_P(NULL, delim2)) != NULL ) {
+ pin_names[i] = ptr;
+ ptr = strtok_P(NULL, delim1);
+ }
+ }
+
+ for (i = 0; i < PIN_MAX; i++)
+ if (strlen(pin_names[i]) > pin_names_width)
+ pin_names_width = strlen(pin_names[i]);
+ }
+}
static void print_blanks(uint_fast8_t count)
@@ -277,6 +313,14 @@ static void print_blanks(uint_fast8_t count)
putchar(' ');
}
+static int xstrlen(char *s)
+{
+ if (s == NULL)
+ return 0;
+ else
+ return strlen(s);
+}
+
static const FLASH char * const FLASH pinconf_str[] = {
FSTR("?"),
FSTR("Input"),
@@ -305,16 +349,20 @@ int print_pin(int pin, int multi)
levelp = pinlevel_str[pin_read(pin)];
if (multi) {
- printf_P(PSTR("%3d "), pin);
+ printf_P(PSTR("%3d "), pin);
+ if (pin_names_width) {
+ printf_P(PSTR("%s "), pin_names[pin]);
+ print_blanks(pin_names_width - xstrlen(pin_names[pin]));
+ }
my_puts_P(pinconf_str[pinconf]);
- print_blanks(8 - strlen_P(pinconf_str[pinconf]));
+ print_blanks(7 - strlen_P(pinconf_str[pinconf]));
my_puts_P(levelp);
- print_blanks(6 - strlen_P(levelp));
+ print_blanks(5 - strlen_P(levelp));
if (pinconf == OUTPUT_TIMER)
- printf_P(PSTR("%7ld %8ld"),
+ printf_P(PSTR("%8ld %8ld"),
div, F_CPU/div);
} else {
- printf_P(PSTR("Pin %d: "), pin);
+ printf_P(PSTR("%d: \"%s\", "), pin, pin_names[pin] ? pin_names[pin] : 0);
my_puts_P(pinconf_str[pinconf]);
printf_P(PSTR(", "));
my_puts_P(levelp);
@@ -409,11 +457,13 @@ command_ret_t do_pin(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
/* remaining arguments */
argc -= optind;
- if (argc == 0)
+ pinnames_get();
+
+ if (argc == 0) {
/* print cofig of all pins */
for (pinargc = 0; pinargc < PIN_MAX; pinargc++)
pinarg[pinargc] = pinargc;
- else {
+ } else {
/* get first arg */
pinargc = pinarg_get(argv[optind++], pinarg);
if (pinargc == 0)
@@ -427,9 +477,21 @@ command_ret_t do_pin(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
if (pinargc == 1)
print_pin(pinarg[0], 0);
else {
- if (printheader)
- printf_P(PSTR("Pin Config Level Divider Frequency/Hz\n"
- "-----------------------------------------\n"));
+ if (printheader) {
+ if (pin_names_width > 0) {
+ if ( strlen("Name") > pin_names_width)
+ pin_names_width = strlen("Name");
+ char s[pin_names_width+1];
+ memset(s, ' ', pin_names_width);
+ s[pin_names_width] = '\0';
+ strncpy_P(s, PSTR("Name"), 4);
+ printf_P(PSTR("Pin %s Config Level Divider Frequency/Hz\n"),s);
+ memset(s, '-', pin_names_width);
+ printf_P(PSTR("----%s-----------------------------------\n"), s);
+ } else
+ printf_P(PSTR("Pin Config Level Divider Frequency/Hz\n"
+ "--------------------------------------\n"));
+ }
for (int i = 0; i < pinargc; i++)
print_pin(pinarg[i], 1);
}