2 * Copyright (C) 2012-2013 Czech Technical University in Prague
4 * Created on: 28.2.2013
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * Commands for pin controlling
26 * - Printing list of available pins
27 * - Setting and getting value to pins
28 * - Setting and getting pins direction
39 #include "cmdproc_utils.h"
42 * @brief Print list of pins
44 * @param[in] cmd_io Pointer to IO stack
45 * @param[in] des Pointer to command descriptor
46 * @param[in] param Parameters of command
47 * @return 0 when OK or error code
49 int cmd_do_pin_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
51 rpp_sci_printf("List of all defined pins. Those names can be used by pinval command.\r\n");
52 for (i = 0; i < MAX_PIN_CNT; i++) {
53 if (pin_map[i].pin_name == PIN_NAME_UNUSED) continue;
54 rpp_sci_printf(pin_map[i].pin_name);
55 rpp_sci_printf("\r\n");
61 * @brief Set or get pin value
63 * @param[in] cmd_io Pointer to IO stack
64 * @param[in] des Pointer to command descriptor
65 * @param[in] param Parameters of command
66 * @return 0 when OK or error code
68 int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
76 if (sscanf(p, "%31s ", pinName) != 1) {
77 return -CMDERR_BADPAR;
80 if((desc = hal_gpio_pin_get_dsc(pinName, -1))==NULL) return -CMDERR_BADREG;
82 if(param[2] != NULL){ // More parameters = set values
84 if (sscanf(p, "%d %1s", &val, &spareParams) != 1) {
85 return -CMDERR_BADPAR;
87 if (val != 0 && val != 1)
88 return -CMDERR_BADPAR;
89 hal_gpio_pin_set_value(*desc, (uint32_t) val);
90 return cmd_opchar_replong(cmd_io, param, val, 0, 0);;
92 else{ // No more parameters = get values
93 uint32_t pin_value = hal_gpio_pin_get_value(*desc);
94 rpp_sci_printf("pinval%s=%d\n", pinName, pin_value);
100 * @brief Set or get pin direction
102 * @param[in] cmd_io Pointer to IO stack
103 * @param[in] des Pointer to command descriptor
104 * @param[in] param Parameters of command
105 * @return 0 when OK or error code
107 int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
115 if (sscanf(p, "%31s ", pinName) != 1) {
116 return -CMDERR_BADPAR;
119 if((desc = hal_gpio_pin_get_dsc(pinName, -1))==NULL) return -CMDERR_BADREG;
121 if(param[2] != NULL){ // More parameters = set values
123 if (sscanf(p, "%d %1s", &val, &spareParams) != 1) {
124 return -CMDERR_BADPAR;
127 *desc |= PORT_CONF_SET_DIR;
128 *desc |= PORT_CONF_DIR_OUT;
131 *desc &= (~PORT_CONF_DIR_OUT);
132 *desc |= PORT_CONF_SET_DIR;
135 return -CMDERR_BADPAR;
138 hal_gpio_pin_conf(*desc);
139 return cmd_opchar_replong(cmd_io, param, val, 0, 0);
141 else{ // No more parameters = get values
142 uint32_t pin_dir = hal_gpio_pin_get_direction(*desc);
143 rpp_sci_printf("pindir%s=%d\n", pinName, pin_dir);
150 /** Command descriptor for pin list */
151 cmd_des_t const cmd_des_pin_list = {
153 "pinlist","Print a list of all defined pins.",
154 "### Command syntax ###\n"
158 "### Description ###\n"
160 "The command prints a list of all defined pins accessible by pinval and\n"
166 " List of all defined pins. Those names can be used by pinval command.\n"
215 CMD_HANDLER(cmd_do_pin_list), (void *)&cmd_list_pin
218 /** Command descriptor for pin get/set value */
219 cmd_des_t const cmd_des_pin_val={
221 "pinval*","Set or get the pin value",
222 "### Command syntax ###\n"
224 " pinval<NAME> <VAL>\n"
228 "- `<NAME>` is a string identifying the pin\n"
229 "- `<VAL>` can be 0 or 1\n"
231 "### Description ###\n"
233 "This command is sets or gets a value of the particular pin.\n"
235 "The list of valid pin names can be obtained with pinlist command.\n"
237 "Most of the pins are accessible indirectly via other highlevel\n"
238 "commands. HBR_EN is, for example, controlled by the hbrenable command.\n"
239 "This command serves as supplement to highlevel commands for testing\n"
244 " --> pinvalHBREN 1\n"
247 "Sets the HBR_EN pin to 1.\n"
252 "Gets a value of the HBR_EN pin.\n",
253 CMD_HANDLER(cmd_do_pin_val), (void *)&cmd_list_pin
256 /** Command descriptor for pin get/set direction */
257 cmd_des_t const cmd_des_pin_dir={
259 "pindir*","Set the pin direction",
260 "### Command syntax ###\n"
262 " pindir<NAME> <DIR>\n"
266 "- `<NAME>` is a string identifying the pin\n"
267 "- DIR is be either 0 (input) or 1 (output)\n"
269 "### Description ###\n"
271 "This command is used to set or get direction of the particular pin.\n"
273 "The list of valid pin names can be obtained with pinlist command.\n"
275 "Most of the pins are accessible indirectly via other highlevel\n"
276 "commands HBR_EN is, for example, controlled by the hbrenable command.\n"
277 "This command serves as supplement to highlevel commands for testing\n"
282 " --> pindirHBREN 1\n"
285 "Sets the HBR_EN pin as output.\n"
290 "Gets the direction of the HBR_EN pin.\n",
291 CMD_HANDLER(cmd_do_pin_dir), (void *)&cmd_list_pin
294 /** List of commands for pin, defined as external */
295 cmd_des_t const *cmd_list_pin[]={