2 * Copyright © 2023 Bdale Garbee <bdale@gag.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * define the FET outputs
27 struct stm_gpio * port;
32 {&stm_gpioe, 9}, /* step_0 */
33 {&stm_gpioe, 13}, /* step_1 */
34 {&stm_gpiob, 11}, /* step_2 */
35 {&stm_gpioe, 8}, /* step_3 */
36 {&stm_gpioe, 12}, /* step_4 */
37 {&stm_gpioe, 10}, /* step_5 */
38 {&stm_gpioe, 14}, /* step_6 */
39 {&stm_gpiob, 10}, /* step_7 */
40 {&stm_gpioe, 11}, /* step_8 */
41 {&stm_gpioe, 15}, /* step_9 */
42 {&stm_gpioa, 5}, /* step_10 */
43 {&stm_gpioc, 5}, /* step_11 */
44 {&stm_gpioe, 7}, /* step_12 */
45 {&stm_gpioa, 6}, /* step_13 */
46 {&stm_gpiob, 0}, /* step_14 */
47 {&stm_gpioa, 3}, /* step_15 */
48 {&stm_gpioa, 7}, /* step_16 */
49 {&stm_gpiob, 1}, /* step_17 */
50 {&stm_gpioa, 4}, /* step_18 */
51 {&stm_gpioc, 4}, /* step_19 */
52 {&stm_gpioe, 4}, /* step_20 */
53 {&stm_gpioc, 0}, /* step_21 */
54 {&stm_gpioc, 3}, /* step_22 */
55 {&stm_gpioe, 5}, /* step_23 */
56 {&stm_gpioc, 1}, /* step_24 */
57 {&stm_gpioe, 2}, /* step_25 */
58 {&stm_gpioc, 14}, /* step_26 */
59 {&stm_gpioc, 2}, /* step_27 */
60 {&stm_gpioe, 3}, /* step_28 */
61 {&stm_gpioc, 15}, /* step_29 */
62 {&stm_gpiob, 3}, /* step_30 */
63 {&stm_gpiob, 5}, /* step_31 */
64 {&stm_gpiob, 9}, /* step_32 */
65 {&stm_gpiob, 4}, /* step_33 */
66 {&stm_gpiob, 6}, /* step_34 */
67 {&stm_gpiod, 7}, /* step_35 */
68 {&stm_gpiob, 7}, /* step_36 */
69 {&stm_gpioe, 0}, /* step_37 */
70 {&stm_gpiod, 6}, /* step_38 */
71 {&stm_gpiob, 8}, /* step_39 */
72 {&stm_gpioc, 7}, /* step_40 */
73 {&stm_gpiod, 1}, /* step_41 */
74 {&stm_gpiod, 4}, /* step_42 */
75 {&stm_gpioc, 6}, /* step_43 */
76 {&stm_gpiod, 0}, /* step_44 */
77 {&stm_gpioc, 8}, /* step_45 */
78 {&stm_gpiod, 2}, /* step_46 */
79 {&stm_gpiod, 5}, /* step_47 */
80 {&stm_gpioc, 9}, /* step_48 */
81 {&stm_gpiod, 3}}; /* step_49 */
84 ao_fet_control(uint32_t output, uint8_t value)
86 /* map output 0-49 to corresponding GPIO port and pin, set to value */
87 ao_gpio_set(outputs[output].port, outputs[output].pin, value);
95 /* initialize GPIO outputs and turn them all off */
96 for (i = 0; i < 50; i++)
98 ao_enable_output(outputs[i].port, outputs[i].pin, 0);
107 output = ao_cmd_decimal();
108 if (ao_cmd_status != ao_cmd_success)
110 if (output > 49) /* can't be less than 0 since unsigned! */
111 printf ("Invalid FET selection %lu, must be 0..49\n", output);
113 ao_fet_control(output, 1);
114 ao_led_on(AO_LED_RED);
123 output = ao_cmd_decimal();
124 if (ao_cmd_status != ao_cmd_success)
126 if (output > 49) /* can't be less than 0 since unsigned! */
127 printf ("Invalid FET selection %lu, must be 0..49\n", output);
129 ao_fet_control(output, 0);
130 ao_led_off(AO_LED_RED);
134 static const struct ao_cmds ao_fet_cmds[] = {
135 { ao_fet_on, "S <output>\0Set (turn on) FET" },
136 { ao_fet_off, "R <output>\0Reset (turn off) FET" },
143 ao_fet_init(); /* turn all outputs off ASAP */
149 /* both LEDs on briefly as system test */
150 ao_led_on(LEDS_AVAILABLE);
159 ao_cmd_register(ao_fet_cmds);
161 /* turn red off, leave green on as a "power indicator" */
162 ao_led_off(AO_LED_RED);
164 ao_start_scheduler();