2 * Copyright (C) 2012-2015 Czech Technical University in Prague
4 * Created on: 28.2.2013
9 * This document contains proprietary information belonging to Czech
10 * Technical University in Prague. Passing on and copying of this
11 * document, and communication of its contents is not permitted
12 * without prior written authorization.
17 * Commands for pin controlling
18 * - Printing list of available pins
19 * - Setting and getting value to pins
20 * - Setting and getting pins direction
30 #include "drv/digital_io_def.h"
31 #include "cmdproc_utils.h"
34 * @brief Print list of pins
36 * @param[in] cmd_io Pointer to IO stack
37 * @param[in] des Pointer to command descriptor
38 * @param[in] param Parameters of command
39 * @return 0 when OK or error code
41 int cmd_do_pin_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
45 rpp_sci_printf("List of all defined pins. Those names can be used by pinval command.\r\n");
46 uint32_t pin_cnt = rpp_gio_get_pin_cnt();
47 const char* pin_names[128];
48 rpp_gio_get_pin_names(pin_names, pin_cnt);
49 for (i = 0; i < pin_cnt; i++) {
50 if (strcmp(pin_names[i], DIO_PIN_NAME_UNUSED) == 0) continue;
51 rpp_sci_printf(pin_names[i]);
52 rpp_sci_printf("\r\n");
58 * @brief Set or get pin value
60 * @param[in] cmd_io Pointer to IO stack
61 * @param[in] des Pointer to command descriptor
62 * @param[in] param Parameters of command
63 * @return 0 when OK or error code
65 int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
73 if (sscanf(p, "%31s ", pinName) != 1)
74 return -CMDERR_BADPAR;
77 if (param[2] != NULL) { // More parameters = set values
79 if (sscanf(p, "%d %1s", &val, &spareParams) != 1)
80 return -CMDERR_BADPAR;
81 if (val != 0 && val != 1)
82 return -CMDERR_BADPAR;
83 if (rpp_gio_set_val(pinName, val) == FAILURE) {
84 return -CMDERR_BADPAR;;
86 return cmd_opchar_replong(cmd_io, param, val, 0, 0);
88 else { // No more parameters = get values
89 int32_t pin_value = rpp_gio_get_val(pinName);
90 if (pin_value == FAILURE) {
91 return -CMDERR_BADPAR;
93 rpp_sci_printf("pinval%s=%d\n", pinName, pin_value);
99 * @brief Set or get pin direction
101 * @param[in] cmd_io Pointer to IO stack
102 * @param[in] des Pointer to command descriptor
103 * @param[in] param Parameters of command
104 * @return 0 when OK or error code
106 int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
114 if (sscanf(p, "%31s ", pinName) != 1)
115 return -CMDERR_BADPAR;
117 if (param[2] != NULL) { // More parameters = set values
119 if (sscanf(p, "%u %1s", &val, &spareParams) != 1)
120 return -CMDERR_BADPAR;
122 if (rpp_gio_set_input(pinName) == FAILURE) {
123 return -CMDERR_BADPAR;
127 if (rpp_gio_set_output(pinName, 0) == FAILURE) {
128 return -CMDERR_BADPAR;
132 return -CMDERR_BADPAR;
135 return cmd_opchar_replong(cmd_io, param, val, 0, 0);
137 else { // No more parameters = get values
138 int32_t pin_dir = rpp_gio_is_dir_output(pinName);
139 if (pin_dir == FAILURE) {
140 return -CMDERR_BADPAR;
142 rpp_sci_printf("pindir%s=%d\n", pinName, pin_dir);
149 /** Command descriptor for pin list */
150 cmd_des_t const cmd_des_pin_list = {
152 "pinlist","Print a list of all defined pins.",
153 "### Command syntax ###\n"
157 "### Description ###\n"
159 "The command prints a list of all defined pins accessible by pinval and\n"
165 " List of all defined pins. Those names can be used by pinval command.\n"
214 CMD_HANDLER(cmd_do_pin_list), (void *)&cmd_list_pin
217 /** Command descriptor for pin get/set value */
218 cmd_des_t const cmd_des_pin_val = {
220 "pinval*","Set or get the pin value",
221 "### Command syntax ###\n"
223 " pinval<NAME> <VAL>\n"
227 "- `<NAME>` is a string identifying the pin\n"
228 "- `<VAL>` can be 0 or 1\n"
230 "### Description ###\n"
232 "This command is sets or gets a value of the particular pin.\n"
234 "The list of valid pin names can be obtained with pinlist command.\n"
238 " --> pinvalGIOB0 1\n"
241 "Sets the GIOB0 pin to 1.\n"
246 "Gets a value of the GIOB0 pin.\n",
247 CMD_HANDLER(cmd_do_pin_val), (void *)&cmd_list_pin
250 /** Command descriptor for pin get/set direction */
251 cmd_des_t const cmd_des_pin_dir = {
253 "pindir*","Set the pin direction",
254 "### Command syntax ###\n"
256 " pindir<NAME> <DIR>\n"
260 "- `<NAME>` is a string identifying the pin\n"
261 "- DIR is be either 0 (input) or 1 (output)\n"
263 "### Description ###\n"
265 "This command is used to set or get direction of the particular pin.\n"
267 "The list of valid pin names can be obtained with pinlist command.\n"
271 " --> pindirGIOB0 1\n"
274 "Sets the GIOB0 pin as output.\n"
279 "Gets the direction of the GIOB0 pin.\n",
280 CMD_HANDLER(cmd_do_pin_dir), (void *)&cmd_list_pin
283 /** List of commands for pin, defined as external */
284 cmd_des_t const *cmd_list_pin[] = {