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 * This file contains commands for DAC control. User can setup DIN pin as active or inactive, set voltage in mV units and set raw value on pin.
34 #include "cmdproc_utils.h"
39 * @brief Setup DAC pin enable or disable
41 * @param[in] cmd_io Pointer to IO stack
42 * @param[in] des Pointer to command descriptor
43 * @param[in] param Parameters of command
44 * @return 0 when OK or error code
46 int cmd_do_dac_pin_setup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
54 if (sscanf(p, "%d %d %1s", &pin, &enabled, &spareParams) != 2)
55 return -CMDERR_BADPAR;
56 ret = rpp_dac_setup(pin, enabled);
58 rpp_sci_printf("Pin out of range.\n");
59 return -CMDERR_BADPAR;
62 if (rpp_dac_update() == FAILURE) {
63 rpp_sci_printf("DAC update failed.\n");
67 return cmd_opchar_replong(cmd_io, param, enabled, 0, 10);
71 * @brief Set DAC pin raw value
73 * @param[in] cmd_io Pointer to IO stack
74 * @param[in] des Pointer to command descriptor
75 * @param[in] param Parameters of command
76 * @return 0 when OK or error code
78 int cmd_do_dac_pin_set_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
86 if (sscanf(p, "%d %d %1s", &pin, &val, &spareParams) != 2)
87 return -CMDERR_BADPAR;
88 ret = rpp_dac_set(pin, val);
90 rpp_sci_printf("Pin out of range.\n");
91 return -CMDERR_BADPAR;
94 rpp_sci_printf("Value out of range.\n");
95 return -CMDERR_BADPAR;
98 if (rpp_dac_update() == FAILURE) {
99 rpp_sci_printf("DAC update failed.\n");
102 return cmd_opchar_replong(cmd_io, param, val, 0, 10);
106 * @brief Set DAC pin voltage value in mV units
108 * @param[in] cmd_io Pointer to IO stack
109 * @param[in] des Pointer to command descriptor
110 * @param[in] param Parameters of command
111 * @return 0 when OK or error code
113 int cmd_do_dac_pin_set_voltage(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
121 if (sscanf(p, "%d %d %1s", &pin, &mV, &spareParams) != 2)
122 return -CMDERR_BADPAR;
123 ret = rpp_dac_set_voltage(pin, mV);
125 rpp_sci_printf("Pin out of range.\n");
126 return -CMDERR_BADPAR;
128 else if (ret == -2) {
129 rpp_sci_printf("Voltage out of range.\n");
130 return -CMDERR_BADPAR;
133 if (rpp_dac_update() == FAILURE) {
134 rpp_sci_printf("DAC update failed.\n");
137 return cmd_opchar_replong(cmd_io, param, mV, 0, 10);
142 /** Descriptor of command for dac pin setup */
143 cmd_des_t const cmd_des_dac_pin_setup = {
145 "dacpinenable*","Enable or disable a DAC pin",
146 "### Command syntax ###\n"
148 " dacpinenable<PIN> <VALUE>\n"
151 "- `<PIN>` is a number in range 1-4\n"
152 "- `<VALUE>` is a number 0 (disable) or 1 (enable)\n"
154 "### Description ###\n"
156 "Command for enabling or disabling of a DAC pin.\n"
158 "Command always prints the actual state of the selected pin.\n"
162 " --> dacpinenable1 1\n"
165 "Enables pin DAC1 and prints its actual state (which will be 1)\n",
166 CMD_HANDLER(cmd_do_dac_pin_setup), (void *)&cmd_list_dac
169 /** Descriptor of command for dac pin value set */
170 cmd_des_t const cmd_des_dac_pin_set_val = {
172 "dacpinval*","Set raw value of a DAC register",
173 "### Command syntax ###\n"
175 " dacpinval<PIN> <VALUE>\n"
178 "- `<PIN>` is a number in range 1-4\n"
179 "- `<VALUE>` is a number in range 0-4095\n"
181 "### Description ###\n"
183 "This command writes a raw value to DAC register that controls the DAC\n"
184 "output voltage according to the formula described in the datasheet.\n"
185 "`<PIN>` parameter selects which DAC pin to use.\n"
187 "Command always prints the written raw value of the selected pin. There\n"
188 "is no way how to read the value out of the register.\n"
192 " --> dacpinval1 4095\n"
193 " dacpinval1 =4095\n"
195 "Set pin DAC1 voltage to 12V, and prints the value (4095).\n",
196 CMD_HANDLER(cmd_do_dac_pin_set_val), (void *)&cmd_list_dac
199 /** Descriptor of command for dac pin voltage set */
200 cmd_des_t const cmd_des_dac_pin_set_voltage = {
202 "dacpinvoltage*","Set voltage in mV of a DAC pin",
203 "### Command syntax ###\n"
205 " dacpinvoltage<PIN> <VALUE>\n"
208 "- `<PIN>` is a number in range 1-4\n"
209 "- `<VALUE>` is a number in range 0-12000\n"
211 "### Description ###\n"
213 "This command sets the voltage on a DAC pin.\n"
215 "The command always prints the actually set voltage of selected pin.\n"
216 "There is no way how to read the value back out of the pin.\n"
220 " --> dacpinvoltage1 8000\n"
221 " dacpinvoltage1 =8000\n"
223 "Sets pin DAC1 to 8V, prints the actual voltage (8000)\n"
225 " --> dacpinvoltage2 500\n"
226 " dacpinvoltage2 =500\n"
228 "Sets pin DAC2 to 500mV, prints actual voltage (500)\n",
229 CMD_HANDLER(cmd_do_dac_pin_set_voltage), (void *)&cmd_list_dac
232 /** List of commands for dac, defined as external */
233 cmd_des_t const *cmd_list_dac[] = {
234 &cmd_des_dac_pin_setup,
235 &cmd_des_dac_pin_set_val,
236 &cmd_des_dac_pin_set_voltage,