nbhw16: shield: cleanup indent, don't show specific erros, show usage instead
This commit is contained in:
parent
1fe2efa399
commit
4c8d1c8447
|
|
@ -34,32 +34,31 @@ int shield_gpio_request_as_input(unsigned int gpio, const char *label)
|
|||
|
||||
void shield_register(struct shield_t *shield)
|
||||
{
|
||||
if (shield_count >= MAX_SHIELDS) {
|
||||
printf("Max shield count reached (%d), please increment MAX_SHIELDS\n", MAX_SHIELDS);
|
||||
return;
|
||||
}
|
||||
shields[shield_count++] = shield;
|
||||
if (shield_count >= MAX_SHIELDS) {
|
||||
printf("Max shield count reached (%d), please increment MAX_SHIELDS\n", MAX_SHIELDS);
|
||||
return;
|
||||
}
|
||||
shields[shield_count++] = shield;
|
||||
}
|
||||
|
||||
int shield_set_mode(const char* shield_type, int argc, char * const argv[])
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < shield_count; i++) {
|
||||
if (strcmp(shield_type, shields[i]->name) == 0) {
|
||||
return shields[i]->setmode(argv, argc);
|
||||
}
|
||||
}
|
||||
printf("Shield %s is unknown\n", shield_type);
|
||||
return -1;
|
||||
for (i = 0; i < shield_count; i++) {
|
||||
if (strcmp(shield_type, shields[i]->name) == 0) {
|
||||
return shields[i]->setmode(argv, argc);
|
||||
}
|
||||
}
|
||||
printf("Shield %s is unknown\n", shield_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int do_shieldmode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||
{
|
||||
if (argc < 3) {
|
||||
puts("Invalid command (see help)\n");
|
||||
if (argc < 3) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return shield_set_mode(argv[1], argc - 2, &argv[2]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ static int request_gpios(void)
|
|||
{
|
||||
int ret;
|
||||
|
||||
debug("Shiled configure gpios\n");
|
||||
debug("Shield configure gpios\n");
|
||||
ret = shield_gpio_request_as_input(NETBIRD_GPIO_RST_SHIELD_N, "shield-rst");
|
||||
if ((ret < 0))
|
||||
return -1;
|
||||
|
|
@ -57,12 +57,12 @@ static int request_gpios(void)
|
|||
|
||||
static int configure_shieldmode(int mode)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
if (mode < 0 || mode > 3) {
|
||||
printf("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
if (mode < 0 || mode > 3) {
|
||||
debug("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
debug("Shield type dualcan\n");
|
||||
debug ("Set shield mode to %d\n", mode);
|
||||
|
|
@ -144,8 +144,8 @@ static int get_termination(const char* termination)
|
|||
return 0;
|
||||
}
|
||||
|
||||
printf ("Invalid termination mode %s (falling back to off)", termination);
|
||||
return 0;
|
||||
debug ("Invalid termination mode %s (falling back to off)", termination);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int get_mode_from_args(char * const argv[], int argc)
|
||||
|
|
@ -157,12 +157,15 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
assert(argc == (CAN_PORTS + 1));
|
||||
|
||||
if (strcmp ("termination", argv[0])) {
|
||||
puts("The only option for dualcan is terminations\n");
|
||||
debug("The only option for dualcan is terminations\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < CAN_PORTS; i ++) {
|
||||
terminations[i] = get_termination(argv[i + 1]);
|
||||
if (terminations[i] < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Termination is inverse */
|
||||
|
|
@ -172,12 +175,11 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
static int set_shieldmode(char * const argv[], int argc)
|
||||
{
|
||||
if (argc != 3) {
|
||||
puts("Too few arguments for dualcan\n");
|
||||
debug("Too few arguments for dualcan\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
configure_shieldmode(get_mode_from_args(argv, argc));
|
||||
return 0;
|
||||
return configure_shieldmode(get_mode_from_args(argv, argc));
|
||||
}
|
||||
|
||||
struct shield_t can_shield = {
|
||||
|
|
|
|||
|
|
@ -55,12 +55,12 @@ static int request_gpios(void)
|
|||
|
||||
static int configure_shieldmode(int mode)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
if (mode < 0 || mode > 3) {
|
||||
printf("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
if (mode < 0 || mode > 3) {
|
||||
printf("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
debug("Shield type comio\n");
|
||||
debug ("Set shield mode to %d\n", mode);
|
||||
|
|
@ -169,7 +169,7 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
int termination = 0;
|
||||
int rs232 = 0;
|
||||
|
||||
assert(argc >= 2);
|
||||
assert(argc >= 2);
|
||||
|
||||
if (strcmp ("mode", argv[0])) {
|
||||
puts("Invalid arguments (see help)\n");
|
||||
|
|
@ -200,7 +200,7 @@ int set_shieldmode(char * const argv[], int argc)
|
|||
|
||||
configure_shieldmode(get_mode_from_args(argv, argc));
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct shield_t comio_shield = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue