Skip to content

Commit

Permalink
ADD: update cdc pin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
r2axz committed Nov 19, 2020
1 parent fc07934 commit 9d2a60b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cdc_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ static int cdc_shell_cmd_uart_set_output_type(int port, cdc_pin_t uart_pin, gpio
gpio_pin_t *pin = &device_config_get()->cdc_config.port_config[port_index].pins[uart_pin];
if (pin->dir == gpio_dir_output) {
pin->output = output;
usb_cdc_reconfigure_port_pin(port, uart_pin);
} else {
cdc_shell_write(cdc_shell_err_cannot_set_output_type_for_input, strlen(cdc_shell_err_cannot_set_output_type_for_input));
return -1;
Expand All @@ -193,6 +194,7 @@ static int cdc_shell_cmd_uart_set_polarity(int port, cdc_pin_t uart_pin, gpio_po
gpio_pin_t *pin = &device_config_get()->cdc_config.port_config[port_index].pins[uart_pin];
if (pin->func == gpio_func_general) {
pin->polarity = polarity;
usb_cdc_reconfigure_port_pin(port, uart_pin);
} else {
cdc_shell_write(cdc_shell_err_cannot_change_polarity, strlen(cdc_shell_err_cannot_change_polarity));
return -1;
Expand All @@ -208,6 +210,7 @@ static int cdc_shell_cmd_uart_set_pull_type(int port, cdc_pin_t uart_pin, gpio_p
gpio_pin_t *pin = &device_config_get()->cdc_config.port_config[port_index].pins[uart_pin];
if (pin->dir == gpio_dir_input) {
pin->pull = pull;
usb_cdc_reconfigure_port_pin(port, uart_pin);
} else {
cdc_shell_write(cdc_shell_err_cannot_set_pull_for_output, strlen(cdc_shell_err_cannot_set_pull_for_output));
return -1;
Expand All @@ -228,16 +231,15 @@ static void cdc_shell_cmd_uart(int argc, char *argv[]) {
}
port = port - 1;
}

argv++;
if (argc) {
if (strcmp(*argv, "show") == 0) {
cdc_shell_cmd_uart_show(port);
} else {
while(argc) {
argc--;
cdc_pin_t uart_signal = _cdc_uart_signal_by_name(*argv);
if (uart_signal == cdc_pin_unknown) {
cdc_pin_t uart_pin = _cdc_uart_signal_by_name(*argv);
if (uart_pin == cdc_pin_unknown) {
cdc_shell_write(cdc_shell_err_uart_unknown_signal, strlen(cdc_shell_err_uart_unknown_signal));
return;
}
Expand All @@ -252,7 +254,9 @@ static void cdc_shell_cmd_uart(int argc, char *argv[]) {
if (output_type != gpio_output_unknown) {
argc--;
argv++;
cdc_shell_cmd_uart_set_output_type(port, uart_signal, output_type);
if (cdc_shell_cmd_uart_set_output_type(port, uart_pin, output_type) == -1) {
return;
}
} else {
cdc_shell_write(cdc_shell_err_uart_invalid_output_type, strlen(cdc_shell_err_uart_invalid_output_type));
return;
Expand All @@ -269,7 +273,9 @@ static void cdc_shell_cmd_uart(int argc, char *argv[]) {
if (polarity != gpio_polarity_unknown) {
argc--;
argv++;
cdc_shell_cmd_uart_set_polarity(port, uart_signal, polarity);
if (cdc_shell_cmd_uart_set_polarity(port, uart_pin, polarity) == -1) {
return;
}
} else {
cdc_shell_write(cdc_shell_err_uart_invalid_polarity, strlen(cdc_shell_err_uart_invalid_polarity));
return;
Expand All @@ -286,7 +292,9 @@ static void cdc_shell_cmd_uart(int argc, char *argv[]) {
if (pull != gpio_pull_unknown) {
argc--;
argv++;
cdc_shell_cmd_uart_set_pull_type(port, uart_signal, pull);
if (cdc_shell_cmd_uart_set_pull_type(port, uart_pin, pull) == -1) {
return;
}
} else {
cdc_shell_write(cdc_shell_err_uart_invalid_pull_type, strlen(cdc_shell_err_uart_invalid_pull_type));
return;
Expand Down

0 comments on commit 9d2a60b

Please # to comment.