2 * Copyright (C) 2012-2013 Czech Technical University in Prague
4 * Created on: 28.2.2013
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
33 * 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.
42 #include "cmdproc_utils.h"
47 * @brief Setup DAC pin enable or disable
49 * @param[in] cmd_io Pointer to IO stack
50 * @param[in] des Pointer to command descriptor
51 * @param[in] param Parameters of command
52 * @return 0 when OK or error code
54 int cmd_do_dac_pin_setup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
62 if (sscanf(p, "%d %d %1s", &pin, &enabled, &spareParams) != 2)
63 return -CMDERR_BADPAR;
64 ret = rpp_dac_setup(pin, enabled);
66 rpp_sci_printf("Pin out of range.\n");
67 return -CMDERR_BADPAR;
70 if (rpp_dac_update() == FAILURE) {
71 rpp_sci_printf("DAC update failed.\n");
75 return cmd_opchar_replong(cmd_io, param, enabled, 0, 10);
79 * @brief Set DAC pin raw value
81 * @param[in] cmd_io Pointer to IO stack
82 * @param[in] des Pointer to command descriptor
83 * @param[in] param Parameters of command
84 * @return 0 when OK or error code
86 int cmd_do_dac_pin_set_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
94 if (sscanf(p, "%d %d %1s", &pin, &val, &spareParams) != 2)
95 return -CMDERR_BADPAR;
96 ret = rpp_dac_set(pin, val);
98 rpp_sci_printf("Pin out of range.\n");
99 return -CMDERR_BADPAR;
101 else if (ret == -2) {
102 rpp_sci_printf("Value out of range.\n");
103 return -CMDERR_BADPAR;
106 if (rpp_dac_update() == FAILURE) {
107 rpp_sci_printf("DAC update failed.\n");
110 return cmd_opchar_replong(cmd_io, param, val, 0, 10);
114 * @brief Set DAC pin voltage value in mV units
116 * @param[in] cmd_io Pointer to IO stack
117 * @param[in] des Pointer to command descriptor
118 * @param[in] param Parameters of command
119 * @return 0 when OK or error code
121 int cmd_do_dac_pin_set_voltage(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
129 if (sscanf(p, "%d %d %1s", &pin, &mV, &spareParams) != 2)
130 return -CMDERR_BADPAR;
131 ret = rpp_dac_set_voltage(pin, mV);
133 rpp_sci_printf("Pin out of range.\n");
134 return -CMDERR_BADPAR;
136 else if (ret == -2) {
137 rpp_sci_printf("Voltage out of range.\n");
138 return -CMDERR_BADPAR;
141 if (rpp_dac_update() == FAILURE) {
142 rpp_sci_printf("DAC update failed.\n");
145 return cmd_opchar_replong(cmd_io, param, mV, 0, 10);
150 /** Descriptor of command for dac pin setup */
151 cmd_des_t const cmd_des_dac_pin_setup = {
153 "dacpinenable*","Enable or disable a DAC pin",
154 "### Command syntax ###\n"
156 " dacpinenable<PIN> <VALUE>\n"
159 "- `<PIN>` is a number in range 1-4\n"
160 "- `<VALUE>` is a number 0 (disable) or 1 (enable)\n"
162 "### Description ###\n"
164 "Command for enabling or disabling of a DAC pin.\n"
166 "Command always prints the actual state of the selected pin.\n"
170 " --> dacpinenable1 1\n"
173 "Enables pin DAC1 and prints its actual state (which will be 1)\n",
174 CMD_HANDLER(cmd_do_dac_pin_setup), (void *)&cmd_list_dac
177 /** Descriptor of command for dac pin value set */
178 cmd_des_t const cmd_des_dac_pin_set_val = {
180 "dacpinval*","Set raw value of a DAC register",
181 "### Command syntax ###\n"
183 " dacpinval<PIN> <VALUE>\n"
186 "- `<PIN>` is a number in range 1-4\n"
187 "- `<VALUE>` is a number in range 0-4095\n"
189 "### Description ###\n"
191 "This command writes a raw value to DAC register that controls the DAC\n"
192 "output voltage according to the formula described in the datasheet.\n"
193 "`<PIN>` parameter selects which DAC pin to use.\n"
195 "Command always prints the written raw value of the selected pin. There\n"
196 "is no way how to read the value out of the register.\n"
200 " --> dacpinval1 4095\n"
201 " dacpinval1 =4095\n"
203 "Set pin DAC1 voltage to 12V, and prints the value (4095).\n",
204 CMD_HANDLER(cmd_do_dac_pin_set_val), (void *)&cmd_list_dac
207 /** Descriptor of command for dac pin voltage set */
208 cmd_des_t const cmd_des_dac_pin_set_voltage = {
210 "dacpinvoltage*","Set voltage in mV of a DAC pin",
211 "### Command syntax ###\n"
213 " dacpinvoltage<PIN> <VALUE>\n"
216 "- `<PIN>` is a number in range 1-4\n"
217 "- `<VALUE>` is a number in range 0-12000\n"
219 "### Description ###\n"
221 "This command sets the voltage on a DAC pin.\n"
223 "The command always prints the actually set voltage of selected pin.\n"
224 "There is no way how to read the value back out of the pin.\n"
228 " --> dacpinvoltage1 8000\n"
229 " dacpinvoltage1 =8000\n"
231 "Sets pin DAC1 to 8V, prints the actual voltage (8000)\n"
233 " --> dacpinvoltage2 500\n"
234 " dacpinvoltage2 =500\n"
236 "Sets pin DAC2 to 500mV, prints actual voltage (500)\n",
237 CMD_HANDLER(cmd_do_dac_pin_set_voltage), (void *)&cmd_list_dac
240 /** List of commands for dac, defined as external */
241 cmd_des_t const *cmd_list_dac[] = {
242 &cmd_des_dac_pin_setup,
243 &cmd_des_dac_pin_set_val,
244 &cmd_des_dac_pin_set_voltage,