2 * Copyright (C) 2012-2013 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
23 #include "../cmd_pin.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 for (i = 0; i < MAX_PIN_CNT; i++) {
47 if (pin_map[i].pin_name == PIN_NAME_UNUSED) continue;
48 rpp_sci_printf(pin_map[i].pin_name);
49 rpp_sci_printf("\r\n");
55 * @brief Set or get pin value
57 * @param[in] cmd_io Pointer to IO stack
58 * @param[in] des Pointer to command descriptor
59 * @param[in] param Parameters of command
60 * @return 0 when OK or error code
62 int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
71 if (sscanf(p, "%31s ", pinName) != 1)
72 return -CMDERR_BADPAR;
74 if ((desc = hal_gpio_pin_get_dsc(pinName, -1)) == NULL) return -CMDERR_BADREG;
76 if (param[2] != NULL) { // More parameters = set values
78 if (sscanf(p, "%d %1s", &val, &spareParams) != 1)
79 return -CMDERR_BADPAR;
80 if (val != 0 && val != 1)
81 return -CMDERR_BADPAR;
82 hal_gpio_pin_set_value(*desc, (uint32_t)val);
83 return cmd_opchar_replong(cmd_io, param, val, 0, 0);
86 else { // No more parameters = get values
87 uint32_t pin_value = hal_gpio_pin_get_value(*desc);
88 rpp_sci_printf("pinval%s=%d\n", pinName, pin_value);
94 * @brief Set or get pin direction
96 * @param[in] cmd_io Pointer to IO stack
97 * @param[in] des Pointer to command descriptor
98 * @param[in] param Parameters of command
99 * @return 0 when OK or error code
101 int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
110 if (sscanf(p, "%31s ", pinName) != 1)
111 return -CMDERR_BADPAR;
113 if ((desc = hal_gpio_pin_get_dsc(pinName, -1)) == NULL) return -CMDERR_BADREG;
115 if (param[2] != NULL) { // More parameters = set values
117 if (sscanf(p, "%d %1s", &val, &spareParams) != 1)
118 return -CMDERR_BADPAR;
120 *desc |= PORT_CONF_SET_DIR;
121 *desc |= PORT_CONF_DIR_OUT;
124 *desc &= (~PORT_CONF_DIR_OUT);
125 *desc |= PORT_CONF_SET_DIR;
128 return -CMDERR_BADPAR;
130 hal_gpio_pin_conf(*desc);
131 return cmd_opchar_replong(cmd_io, param, val, 0, 0);
133 else { // No more parameters = get values
134 uint32_t pin_dir = hal_gpio_pin_get_direction(*desc);
135 rpp_sci_printf("pindir%s=%d\n", pinName, pin_dir);
142 /** Command descriptor for pin list */
143 cmd_des_t const cmd_des_pin_list = {
145 "pinlist","Print a list of all defined pins.",
146 "### Command syntax ###\n"
150 "### Description ###\n"
152 "The command prints a list of all defined pins accessible by pinval and\n"
158 " List of all defined pins. Those names can be used by pinval command.\n"
207 CMD_HANDLER(cmd_do_pin_list), (void *)&cmd_list_pin
210 /** Command descriptor for pin get/set value */
211 cmd_des_t const cmd_des_pin_val = {
213 "pinval*","Set or get the pin value",
214 "### Command syntax ###\n"
216 " pinval<NAME> <VAL>\n"
220 "- `<NAME>` is a string identifying the pin\n"
221 "- `<VAL>` can be 0 or 1\n"
223 "### Description ###\n"
225 "This command is sets or gets a value of the particular pin.\n"
227 "The list of valid pin names can be obtained with pinlist command.\n"
229 "Most of the pins are accessible indirectly via other highlevel\n"
230 "commands. HBR_EN is, for example, controlled by the hbrenable command.\n"
231 "This command serves as supplement to highlevel commands for testing\n"
236 " --> pinvalHBREN 1\n"
239 "Sets the HBR_EN pin to 1.\n"
244 "Gets a value of the HBR_EN pin.\n",
245 CMD_HANDLER(cmd_do_pin_val), (void *)&cmd_list_pin
248 /** Command descriptor for pin get/set direction */
249 cmd_des_t const cmd_des_pin_dir = {
251 "pindir*","Set the pin direction",
252 "### Command syntax ###\n"
254 " pindir<NAME> <DIR>\n"
258 "- `<NAME>` is a string identifying the pin\n"
259 "- DIR is be either 0 (input) or 1 (output)\n"
261 "### Description ###\n"
263 "This command is used to set or get direction of the particular pin.\n"
265 "The list of valid pin names can be obtained with pinlist command.\n"
267 "Most of the pins are accessible indirectly via other highlevel\n"
268 "commands HBR_EN is, for example, controlled by the hbrenable command.\n"
269 "This command serves as supplement to highlevel commands for testing\n"
274 " --> pindirHBREN 1\n"
277 "Sets the HBR_EN pin as output.\n"
282 "Gets the direction of the HBR_EN pin.\n",
283 CMD_HANDLER(cmd_do_pin_dir), (void *)&cmd_list_pin
286 /** List of commands for pin, defined as external */
287 cmd_des_t const *cmd_list_pin[] = {