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
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"
231 " --> pinvalGIOB0 1\n"
234 "Sets the GIOB0 pin to 1.\n"
239 "Gets a value of the GIOB0 pin.\n",
240 CMD_HANDLER(cmd_do_pin_val), (void *)&cmd_list_pin
243 /** Command descriptor for pin get/set direction */
244 cmd_des_t const cmd_des_pin_dir = {
246 "pindir*","Set the pin direction",
247 "### Command syntax ###\n"
249 " pindir<NAME> <DIR>\n"
253 "- `<NAME>` is a string identifying the pin\n"
254 "- DIR is be either 0 (input) or 1 (output)\n"
256 "### Description ###\n"
258 "This command is used to set or get direction of the particular pin.\n"
260 "The list of valid pin names can be obtained with pinlist command.\n"
264 " --> pindirGIOB0 1\n"
267 "Sets the GIOB0 pin as output.\n"
272 "Gets the direction of the GIOB0 pin.\n",
273 CMD_HANDLER(cmd_do_pin_dir), (void *)&cmd_list_pin
276 /** List of commands for pin, defined as external */
277 cmd_des_t const *cmd_list_pin[] = {