CuVoodoo STM32F1 firmware template
busvoodoo_hiz.c
Go to the documentation of this file.
1 /* This program is free software: you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation, either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program. If not, see <http://www.gnu.org/licenses/>.
13  *
14  */
20 /* standard libraries */
21 #include <stdint.h> // standard integer types
22 #include <string.h> // string utilities
23 #include <math.h> // math utilities
24 
25 /* STM32 (including CM3) libraries */
26 #include <libopencmsis/core_cm3.h> // Cortex M3 utilities
27 #include <libopencm3/stm32/gpio.h> // general purpose input output library
28 #include <libopencm3/stm32/rcc.h> // real-time control clock library
29 #include <libopencm3/stm32/dbgmcu.h> // debug utilities
30 #include <libopencm3/stm32/desig.h> // design utilities
31 #include <libopencm3/stm32/dac.h> // DAC utilities
32 
33 /* own libraries */
34 #include "global.h" // board definitions
35 #include "print.h" // printing utilities
36 #include "menu.h" // menu definitions
37 #include "busvoodoo_global.h" // BusVoodoo definitions
38 #include "busvoodoo_oled.h" // OLED utilities
39 #include "busvoodoo_hiz.h" // own definitions
40 
41 #define BUSVOODOO_LV_DEFAULT (0.8*(1+30.0/10.0))
42 #define BUSVOODOO_LV_TEST 2.5
43 #define BUSVOODOO_HV_DEFAULT (1.25*(1+100.0/10.0))
44 #define BUSVOODOO_HV_TEST 12.0
51 static bool busvoodoo_hiz_setup(char** prefix, const char* line)
52 {
53  (void)line; // no configuration is required
54  *prefix = "HiZ"; // set command line prefix
55  busvoodoo_leds_off(); // switch off all LEDs
56  busvoodoo_led_blue_on(); // switch on blue LED
57  busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
58  const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", NULL, NULL, NULL, NULL, NULL, NULL}; // HiZ mode I/O pinout
59  for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
60  busvoodoo_global_pinout_io[i] = pinout_io[i]; // set pin names
61  }
62  if (busvoodoo_full) {
63  const char* pinout_rscan[5] = {"HV", NULL, NULL, NULL, NULL}; // HiZ mode RS/CAN pinout
64  for (uint8_t i=0; i<LENGTH(pinout_rscan) && i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
65  busvoodoo_global_pinout_rscan[i] = pinout_rscan[i]; // set pin names
66  }
67  }
68  busvoodoo_oled_text_pinout(busvoodoo_global_pinout_io, true); // set pinout on display
69  busvoodoo_oled_update(); // update display to show text and pinout
70  return true;
71 }
72 
75 static void busvoodoo_hiz_exit(void)
76 {
77  // there is nothing to do
78 }
79 
84 static bool busvoodoo_hiz_test_self(bool halt)
85 {
86  bool to_return = false; // success of the self-test
87  busvoodoo_safe_state(); // start from a safe state
88 
89  // get device information
90  // get device identifier (DEV_ID)
91  // 0x412: low-density, 16-32 kB flash
92  // 0x410: medium-density, 64-128 kB flash
93  // 0x414: high-density, 256-512 kB flash
94  // 0x430: XL-density, 768-1024 kB flash
95  // 0x418: connectivity
96  if (0==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) { // can't read IDCODE for verification
97  // this is a known issue document in STM32F10xxC/D/E Errata sheet, without workaround
98  } else if (0x414!=(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
99  printf("this (DEV_ID=%03x) is not a high-density device: a wrong micro-controller might have been used\n", (DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK));
100  }
101  // ensure flash size is ok
102  if (0xffff==DESIG_FLASH_SIZE) {
103  printf("unknown flash size: this is probably a defective micro-controller\n");
104  }
105 
106  // check 5V power rail
107  float voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
108  if (voltage<4.0) {
109  printf("5V power rail voltage is too low: %.2fV\n", voltage);
110  if (halt) { // halt on error if requested
111  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
112  while (!user_input_available); // wait for user input
113  }
114  goto error;
115  } else if (voltage>5.5) {
116  printf("5V power rail voltage is too high: %.2fV\n", voltage);
117  goto error;
118  }
119 
120  // check 3.3V power rail
121  voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
122  if (voltage<3.0) {
123  printf("3.3V power rail voltage is too low: %.2fV\n", voltage);
124  goto error;
125  } else if (voltage>3.6) {
126  printf("3.3V power rail voltage is too high: %.2fV\n", voltage);
127  goto error;
128  }
129 
130  // test 5V and 3.3V outputs
131  busvoodoo_vout_switch(true); // enable Vout
132  voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
133  if (voltage<4.0) {
134  printf("5V power rail voltage is too low when 5V output is enabled: %.2fV\n", voltage);
135  goto error;
136  } else if (voltage>5.5) {
137  printf("5V power rail voltage is too high when 5V output is enabled: %.2fV\n", voltage);
138  goto error;
139  }
140  voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
141  if (voltage<3.0) {
142  printf("3.3V power rail voltage is too low when 3V3 output is enabled: %.2fV\n", voltage);
143  goto error;
144  } else if (voltage>3.6) {
145  printf("3.3V power rail voltage is too high when 3V3 is enabled: %.2fV\n", voltage);
146  goto error;
147  }
148  busvoodoo_vout_switch(false); // disable Vout
149 
150  // check LV voltage regulator
151  voltage = busvoodoo_lv_set(0); // disable LV voltage regulator
152  if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
153  printf("LV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
154  goto error;
155  }
156  gpio_set(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // enable LV voltage regulator
157  sleep_ms(5); // let the voltage regulator start and voltage settle
158  voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get LV voltage
159  // without being driven it should be around the default voltage
160  if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
161  printf("LV voltage is lower (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_LV_DEFAULT);
162  goto error;
163  } else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
164  printf("LV voltage is higher (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_LV_DEFAULT);
165  goto error;
166  }
167 
168  // check if we can control LV
169  voltage = busvoodoo_lv_set(BUSVOODOO_LV_TEST); // get LV voltage
170  if (voltage<BUSVOODOO_LV_TEST-0.2) {
171  printf("LV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
172  goto error;
173  } else if (voltage>BUSVOODOO_LV_TEST+0.2) {
174  printf("LV voltage is highed (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
175  goto error;
176  }
177  busvoodoo_lv_set(0); // disable LV voltage regulator
178 
179  // check HV voltage regulator
180  if (busvoodoo_full) {
181  voltage = busvoodoo_hv_set(0); // disable HV voltage regulator
182  if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
183  printf("HV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
184  goto error;
185  }
186  gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
187  sleep_ms(10); // let the voltage regulator start and voltage settle
188  voltage = busvoodoo_vreg_get(BUSVOODOO_HV_CHANNEL); // get HV voltage
189  // without being driven it should be around the default voltage
190  if (voltage<BUSVOODOO_HV_DEFAULT-0.4) {
191  printf("HV voltage is lower (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
192  goto error;
193  } else if (voltage>BUSVOODOO_HV_DEFAULT+0.4) {
194  printf("HV voltage is higher (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
195  goto error;
196  }
197 
198  // check if we can control HV voltage regulator
199  voltage = busvoodoo_hv_set(BUSVOODOO_HV_TEST); // set voltage on HV voltage regulator
200  if (voltage<BUSVOODOO_HV_TEST-0.4) {
201  printf("HV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
202  goto error;
203  } else if (voltage>BUSVOODOO_HV_TEST+0.4) {
204  printf("HV voltage is higher (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
205  goto error;
206  }
207  voltage = busvoodoo_hv_set(0); // disable HV voltage regulator
208  }
209 
210  // pull all pins down and ensure they are low
211  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
212  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
213  gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down so it's not floating
214  }
215  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
216  if (gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is low
217  printf("signal %s is high although it is pulled low (internal)\n", busvoodoo_io_names[pin]); // warn user about the error
218  goto error;
219  }
220  }
221 
222  // pull all pins up and ensure they are high
223  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
224  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
225  gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull up using internal pull-up
226  }
227  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
228  if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
229  printf("signal %s is low although it is pulled up (internal)\n", busvoodoo_io_names[pin]); // warn user about the error
230  goto error;
231  }
232  }
233 
234  // set individual pin high and ensure only pins in the same group are at the same level
235  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
236  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
237  gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
238  }
239  for (uint8_t pin1=0; pin1<LENGTH(busvoodoo_io_ports) && pin1<LENGTH(busvoodoo_io_pins) && pin1<LENGTH(busvoodoo_io_groups) && pin1<LENGTH(busvoodoo_io_names); pin1++) {
240  gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin1]); // set button pin to output
241  gpio_set(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // set pin high
242  for (uint8_t pin2=0; pin2<LENGTH(busvoodoo_io_ports) && pin2<LENGTH(busvoodoo_io_pins) && pin2<LENGTH(busvoodoo_io_groups) && pin2<LENGTH(busvoodoo_io_names); pin2++) {
243  if (busvoodoo_io_groups[pin1]==busvoodoo_io_groups[pin2] && !gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
244  printf("signal %s of I/O-%u is low while it should be set high by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
245  goto error;
246  } else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
247  printf("signal %s of I/O-%u is high while it should not be set high by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
248  goto error;
249  }
250  }
251  gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin1]); // set pin back to input
252  gpio_clear(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // pull pin back down
253  }
254  // set individual pin low and ensure only pins in the same group are at the same level
255  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
256  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
257  gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull up to ensure it is not low by accident
258  }
259  for (uint8_t pin1=0; pin1<LENGTH(busvoodoo_io_ports) && pin1<LENGTH(busvoodoo_io_pins) && pin1<LENGTH(busvoodoo_io_groups) && pin1<LENGTH(busvoodoo_io_names); pin1++) {
260  gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin1]); // set button pin to output
261  gpio_clear(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // set pin low
262  for (uint8_t pin2=0; pin2<LENGTH(busvoodoo_io_ports) && pin2<LENGTH(busvoodoo_io_pins) && pin2<LENGTH(busvoodoo_io_groups) && pin2<LENGTH(busvoodoo_io_names); pin2++) {
263  if (busvoodoo_io_groups[pin1]==busvoodoo_io_groups[pin2] && gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
264  printf("signal %s of I/O-%u is high while it should be set low by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
265  goto error;
266  } else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && !gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
267  printf("signal %s of I/O-%u is low while it should not be set low by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
268  goto error;
269  }
270  }
271  gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin1]); // set pin back to input
272  gpio_set(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // pull pin back up
273  }
274 
275  // test 5V pull-up
276  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
277  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
278  gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
279  }
280  busvoodoo_lv_set(5.0); // set LV voltage regulator to use the 5.0V power rail
281  voltage = busvoodoo_embedded_pullup(true); // enable 5V pull-up
282  if (voltage<4.0) {
283  printf("5V power rail voltage is too low when used to pull up: %.2fV\n", voltage);
284  goto error;
285  } else if (voltage>5.5) {
286  printf("5V power rail voltage is too high when used to pull up: %.2fV\n", voltage);
287  goto error;
288  }
289  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
290  if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
291  printf("signal %s is low although it is pulled up by 5V (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
292  goto error;
293  }
294  }
295  busvoodoo_embedded_pullup(false); // disable pull-ups
296  voltage = busvoodoo_lv_set(0); // disable LV voltage regulator
297 
298  // test LV pull-up set to 3.3V
299  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
300  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
301  gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
302  }
303  busvoodoo_lv_set(3.3); // set LV voltage regulator
304  voltage = busvoodoo_embedded_pullup(3.3); // enable pull-up with adjustable regulator
305  if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
306  printf("LV voltage is lower (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_LV_DEFAULT);
307  goto error;
308  } else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
309  printf("LV voltage is higher (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_LV_DEFAULT);
310  goto error;
311  }
312  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
313  if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
314  printf("signal %s is low although it is pulled up by LV (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
315  goto error;
316  }
317  }
318  busvoodoo_lv_set(0); // disable LV voltage regulator
319  busvoodoo_embedded_pullup(false); // disable pull-ups
320 
321  // test RS-485 transceiver
322  if (busvoodoo_full) {
323  // configure transceiver
324  gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
325  gpio_clear(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO(BUSVOODOO_RS485_RE_PIN)); // enable receiver
326  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
327  gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_RS485_RX_PIN)); // set RX as input with pull up/down
328  // test low signal
329  gpio_set(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN)); // pull RX up
330  gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low
331  sleep_us(100); // let voltage settle
332  if (gpio_get(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN))) { // test if RX is still high
333  printf("RS-485 RX is high while TX is set low\n"); // warn user about the error
334  goto error;
335  }
336  // test high signal
337  gpio_clear(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN)); // pull RX down
338  gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high
339  sleep_us(100); // let voltage settle
340  if (0==gpio_get(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN))) { // test if RX is still low
341  printf("RS-485 RX is low while TX is set high\n"); // warn user about the error
342  goto error;
343  }
344  // release transceiver
345  gpio_set(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO(BUSVOODOO_RS485_RE_PIN)); // set high to disable receiver
346  gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
347  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
348  gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_RX_PIN)); // set pin to floating
349  }
350 
351 #if BUSVOODOO_HARDWARE_VERSION!=0
352  // test CAN transceiver
353  if (busvoodoo_full) {
354  // configure transceiver
355  gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver
356  gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX as output (there is a pull-up resistor to 5V)
357  gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_CAN_RX_PIN)); // set RX as input with pull up/down
358  // test high signal
359  gpio_clear(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN)); // pull RX down
360  gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
361  sleep_us(100); // let voltage settle
362  if (0==gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is still low
363  printf("CAN RX is low while TX is set high\n"); // warn user about the error
364  goto error;
365  }
366  // test low signal
367  gpio_set(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN)); // pull RX up
368  gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
369  sleep_us(100); // let voltage settle
370  if (gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is still high
371  printf("CAN RX is high while TX is set low\n"); // warn user about the error
372  goto error;
373  }
374  // test dominant timeout
375  sleep_ms(10); // after 5 ms the output should be switched back from dominant to recessive respite TX being low
376  if (!gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is now low
377  printf("CAN RX is low while the output should be back to recessive\n"); // warn user about the error
378  goto error;
379  }
380  // release transceiver
381  gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
382  gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
383  gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN)); // set pin to floating
384  }
385 #endif
386 
387  to_return = true; // all tests are successful
388  printf("self-test succeeded\n"); // notify user
389 error:
390  if (!to_return) {
391  if (halt) { // halt on error if requested
392  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
393  while (!user_input_available); // wait for user input
394  } else {
395  printf("the test procedure has been aborted for safety reasons\n");
396  }
397  }
398  busvoodoo_safe_state(); // set back to safe state
399 
400  return to_return;
401 }
402 
407 static bool busvoodoo_hiz_test_pins(bool halt)
408 {
409  bool to_return = false; // test result to return
410  busvoodoo_safe_state(); // start from safe state with all outputs switched off
411 
412  const char* lv_to = "connect I/O pin 4 to "; // most outputs will be tested using LV ADC
413  char* pinout[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; // pinout to display
414  pinout[3] = "O"; // set main testing pin
415  busvoodoo_oled_text_right("pins test"); // display test on display
416  busvoodoo_oled_update(); // update screen
417 
418  // test GND on pin 1 by shorting LV_CTL to ground (through 40k resistor) and measure short
419  gpio_set(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin high
420  gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
421  printf("%sI/O pin 1\n", lv_to); // ask user for action
422  busvoodoo_leds_off(); // clear LEDs
423  busvoodoo_led_red_on(); // notify user to perform action
424  pinout[0] = "O"; // set target testing pin
425  busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
426  busvoodoo_oled_update(); // update screen
427  do {
428  sleep_ms(100); // wait for user to make connection
429  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2 && !user_input_available); // wait until pin is shorted to ground
430  busvoodoo_led_red_off(); // clear red LED
431  busvoodoo_led_blue_on(); // notify user test is running
432  if (user_input_available) { // user interruption
433  goto error;
434  }
435  gpio_clear(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin low
436  gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
437  sleep_ms(100); // wait for voltage to settle an debounce
439  printf("I/O pin 4 is high while it should be low and shorted to ground\n");
440  goto error;
441  }
442  gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin back to analog input for DAC
443  pinout[0] = NULL; // clear pin to test
444 
445  // test 5V output on pin 2
446  gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
447  printf("%sI/O pin 2\n", lv_to);
448  busvoodoo_leds_off(); // clear LEDs
449  busvoodoo_led_red_on(); // notify user to perform action
450  pinout[1] = "O"; // set target testing pin
451  busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
452  busvoodoo_oled_update(); // update screen
453  do {
454  sleep_ms(100); // wait for user to make connection
455  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
456  busvoodoo_led_red_off(); // clear red LED
457  busvoodoo_led_blue_on(); // notify user test is running
458  if (user_input_available) { // user interruption
459  goto error;
460  }
461  gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
462  sleep_ms(100); // wait for voltage to settle and debounce
464  printf("5V output is high while the power output should be switched off\n");
465  goto error;
466  }
467  pinout[1] = NULL; // clear pin to test
468 
469  // test 3.3V output on pin 3
470  gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
471  printf("%sI/O pin 3\n", lv_to);
472  busvoodoo_leds_off(); // clear LEDs
473  busvoodoo_led_red_on(); // notify user to perform action
474  pinout[2] = "O"; // set target testing pin
475  busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
476  busvoodoo_oled_update(); // update screen
477  do {
478  do {
479  sleep_ms(100); // wait for user to make connection
480  } while ((busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) && !user_input_available); // wait until pin is connected
481  sleep_ms(100); // wait for stable connection
482  } while ((busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) && !user_input_available); // check to be sure it really is not on the 5V pin
483  busvoodoo_led_red_on(); // clear red LED
484  busvoodoo_led_blue_on(); // notify user test is running
485  if (user_input_available) { // user interruption
486  goto error;
487  }
488  gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
489  sleep_ms(100); // wait for voltage to settle and debounce
491  printf("3V3 output is high while the power output should be switched off\n");
492  goto error;
493  }
494  pinout[2] = NULL; // clear pin to test
495 
496  // test I/O pins
497  for (uint8_t io=1; io<=6; io++) { // test each I/O pin
498  for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_groups); pin++) { // look for a pin mapped on this I/O
499  if (busvoodoo_io_groups[pin]==io) {
500  gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin high
501  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin]); // set pin to output
502  printf("%sI/O pin %u\n", lv_to, io+4);
503  busvoodoo_leds_off(); // clear LEDs
504  busvoodoo_led_red_on(); // notify user to perform action
505  pinout[io+3] = "O"; // set target testing pin
506  busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
507  busvoodoo_oled_update(); // update screen
508  do {
509  sleep_ms(100); // wait for user to make connection
510  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
511  busvoodoo_led_red_off(); // clear red LED
512  busvoodoo_led_blue_on(); // notify user test is running
513  if (user_input_available) { // user interruption
514  goto error;
515  }
516  gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin low
517  sleep_ms(100); // wait for voltage to settle and debounce
519  printf("I/O pin %u is high while it should be low\n", io+4);
520  goto error;
521  }
522  gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input
523  pinout[io+3] = NULL; // clear pin to test
524  break; // stop looking for pin
525  }
526  }
527  }
528 
529  if (busvoodoo_full) {
530  pinout[3] = NULL; // reset testing pin
531 
532  // test HV output on RS/CAN pin 1
533  double voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
534  uint16_t dac_set = BUSVOODOO_HV_SET(5.0)/voltage*4095; // DAC value corresponding to the voltage
535  dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_HVCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
536  dac_software_trigger(BUSVOODOO_HVCTL_CHANNEL); // transfer the value to the DAC
537  dac_enable(BUSVOODOO_HVCTL_CHANNEL); // enable DAC
538  gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
539  printf("%sRS/CAN pin 1\n", lv_to);
540  busvoodoo_leds_off(); // clear LEDs
541  busvoodoo_led_red_on(); // notify user to perform action
542  pinout[0] = "O"; // set target testing pin
543  busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
544  busvoodoo_oled_update(); // update screen
545  do {
546  sleep_ms(100); // wait for user to make connection
547  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
548  busvoodoo_led_red_off(); // clear red LED
549  busvoodoo_led_blue_on(); // notify user test is running
550  if (user_input_available) { // user interruption
551  goto error;
552  }
553  gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
554  dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable HV control
555  sleep_ms(100); // wait for voltage to settle (and debounce)
557  printf("HV output is high while voltage regulator should be switched off\n");
558  goto error;
559  }
560  pinout[0] = NULL; // clear pin to test
561 
562 #if BUSVOODOO_HARDWARE_VERSION==0
563  // test RS-485 port pin B
564  gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
565  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
566  gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low -> B will be high
567  printf("%sRS/CAN pin 4\n", lv_to);
568  busvoodoo_leds_off(); // clear LEDs
569  busvoodoo_led_red_on(); // notify user to perform action
570  pinout[6] = "O"; // set target testing pin
571  busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
572  busvoodoo_oled_update(); // update screen
573  do {
574  sleep_ms(100); // wait for user to make connection
575  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
576  busvoodoo_led_red_off(); // clear red LED
577  busvoodoo_led_blue_on(); // notify user test is running
578  if (user_input_available) { // user interruption
579  goto error;
580  }
581  gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high
582  sleep_ms(100); // wait for voltage to settle (and debounce)
584  printf("RS-485 output B is high while it should be low\n");
585  goto error;
586  }
587  gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
588  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
589  pinout[6] = NULL; // clear pin to test
590 #else
591  // test RS-485 output A
592  gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
593  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
594  gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high -> A will be high
595  printf("%sRS/CAN pin 3\n", lv_to);
596  busvoodoo_leds_off(); // clear LEDs
597  busvoodoo_led_red_on(); // notify user to perform action
598  pinout[4] = "O"; // set target testing pin
599  busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
600  busvoodoo_oled_update(); // update screen
601  do {
602  sleep_ms(100); // wait for user to make connection
603  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
604  busvoodoo_led_red_off(); // clear red LED
605  busvoodoo_led_blue_on(); // notify user test is running
606  if (user_input_available) { // user interruption
607  goto error;
608  }
609  gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low
610  sleep_ms(100); // wait for voltage to settle (and debounce)
612  printf("RS-485 output A is high while it should be low\n");
613  goto error;
614  }
615  gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
616  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
617  pinout[4] = NULL; // clear pin to test
618 #endif
619 
620 #if BUSVOODOO_HARDWARE_VERSION!=0
621  // test CAN output L
622  // configure transceiver
623  gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver
624  gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX as output (there is a pull-up resistor to 5V)
625  // test recessive output
626  gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
627  sleep_us(100); // let voltage settle
628  voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
629  if (voltage<0.4) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
630  printf("CAN L output is low while it should be at recessive 2.5V\n");
631  goto error;
632  }
633  if (voltage>3.0) { // normally the upper limit is 3V
634  printf("CAN L output is high while it should be at recessive 2.5V\n");
635  goto error;
636  }
637  // test dominant output
638  gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
639  sleep_us(100); // let voltage settle
640  voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
641  if (voltage>2.5) {
642  printf("CAN L output is high while it should at dominant <2.25V\n");
643  goto error;
644  }
645  // release transceiver
646  gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
647  gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
648 #endif
649 
650 #if BUSVOODOO_HARDWARE_VERSION==0
651  // test RS-485 output A
652  gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
653  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
654  gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high -> A will be high
655  printf("%sRS/CAN pin 5\n", lv_to);
656  busvoodoo_leds_off(); // clear LEDs
657  busvoodoo_led_red_on(); // notify user to perform action
658  pinout[8] = "O"; // set target testing pin
659  busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
660  busvoodoo_oled_update(); // update screen
661  do {
662  sleep_ms(100); // wait for user to make connection
663  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
664  busvoodoo_led_red_off(); // clear red LED
665  busvoodoo_led_blue_on(); // notify user test is running
666  if (user_input_available) { // user interruption
667  goto error;
668  }
669  gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low
670  sleep_ms(100); // wait for voltage to settle (and debounce)
672  printf("RS-485 output A is high while it should be low\n");
673  goto error;
674  }
675  gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
676  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
677  pinout[8] = NULL; // clear pin to test
678 #else
679  // test RS-485 port pin B
680  gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
681  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
682  gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low -> B will be high
683  printf("%sRS/CAN pin 4\n", lv_to);
684  busvoodoo_leds_off(); // clear LEDs
685  busvoodoo_led_red_on(); // notify user to perform action
686  pinout[6] = "O"; // set target testing pin
687  busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
688  busvoodoo_oled_update(); // update screen
689  do {
690  sleep_ms(100); // wait for user to make connection
691  } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
692  busvoodoo_led_red_off(); // clear red LED
693  busvoodoo_led_blue_on(); // notify user test is running
694  if (user_input_available) { // user interruption
695  goto error;
696  }
697  gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high
698  sleep_ms(100); // wait for voltage to settle (and debounce)
700  printf("RS-485 output B is high while it should be low\n");
701  goto error;
702  }
703  gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
704  gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
705  pinout[6] = NULL; // clear pin to test
706 #endif
707 
708 #if BUSVOODOO_HARDWARE_VERSION!=0
709  // test CAN output H
710  // configure transceiver
711  gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver
712  gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX as output (there is a pull-up resistor to 5V)
713  // test recessive output
714  gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
715  sleep_us(100); // let voltage settle
716  voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
717  if (voltage<0.5) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
718  printf("CAN H output is low while it should be at recessive 2.5V\n");
719  goto error;
720  }
721  if (voltage>3.0) { // normally the upper limit is 3V
722  printf("CAN H output is high while it should be at recessive 2.5V\n");
723  goto error;
724  }
725  // test dominant output
726  gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
727  sleep_us(100); // let voltage settle
728  voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
729  if (voltage<2.5) {
730  printf("CAN H output is low while it dominant >2.75V\n");
731  printf("%.02f\n", voltage);
732  goto error;
733  }
734  // release transceiver
735  gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
736  gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
737 #endif
738 
739  // test RS-232 port (with itself)
740  rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_EN_PORT)); // enable clock for GPIO domain
741  gpio_clear(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set low to enable receiver
742  gpio_set_mode(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_RS232_EN_PIN)); // set pin as output (open-drain pulled high to disable receiver)
743  rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_SHDN_PORT)); // enable clock for GPIO domain
744  gpio_set(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set high to enable transmitter
745  gpio_set_mode(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set pin as output (push-pull pulled low to disable transmitter)
746  rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_TX_PORT)); // enable clock for GPIO
747  gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_TX_PIN)); // set pin as output (push-pull)
748  rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_RX_PORT)); // enable clock for GPIO
749  gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_RS232_RX_PIN)); // set pin as input (with pull resistors)
750  // start by setting low since unconnected (pulled to ground by 3 kO) is considered as high
751  gpio_clear(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO(BUSVOODOO_RS232_TX_PIN)); // set low
752  gpio_set(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull high to avoid false negative
753  sleep_ms(5);
754  printf("connect RS/CAN pin 2 to RS/CAN pin 3\n");
755  busvoodoo_leds_off(); // clear LEDs
756  busvoodoo_led_red_on(); // notify user to perform action
757  pinout[2] = "O"; // set target testing pin
758  pinout[4] = "O"; // set target testing pin
759  busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
760  busvoodoo_oled_update(); // update screen
761  do {
762  sleep_ms(100); // wait for user to make connection
763  } while (gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)) && !user_input_available); // wait until pin is connected
764  busvoodoo_led_red_off(); // clear red LED
765  busvoodoo_led_blue_on(); // notify user test is running
766  if (user_input_available) { // user interruption
767  goto error;
768  }
769  gpio_set(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO(BUSVOODOO_RS232_TX_PIN)); // set high
770  gpio_clear(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull low to avoid false negative
771  sleep_ms(100); // wait for voltage to settle and debounce
772  if (!gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN))) { // check if RX is set low by TX
773  printf("RS-232 RX is high while it should be set low by RS-232 TX\n");
774  goto error;
775  }
776  gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_TX_PIN)); // free pin
777  gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RX_PIN)); // free pin
778  pinout[2] = NULL; // clear pin to test
779  pinout[4] = NULL; // clear pin to test
780 
781  rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_RTS_PORT)); // enable clock for GPIO
782  gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_RTS_PIN)); // set pin as output (push-pull)
783  rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_CTS_PORT)); // enable clock for GPIO
784  gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_RS232_CTS_PIN)); // set pin as input (with pull resistors)
785  // start by setting low since unconnected (pulled to ground by 3 kO) is considered as high
786  gpio_clear(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO(BUSVOODOO_RS232_RTS_PIN)); // set low
787  gpio_set(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull high to avoid false negative
788  printf("connect RS/CAN pin 4 to RS/CAN pin 5\n");
789  busvoodoo_leds_off(); // clear LEDs
790  busvoodoo_led_red_on(); // notify user to perform action
791  pinout[6] = "O"; // set target testing pin
792  pinout[8] = "O"; // set target testing pin
793  busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user
794  busvoodoo_oled_update(); // update screen
795  do {
796  sleep_ms(100); // wait for user to make connection
797  } while (gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)) && !user_input_available); // wait until pin is connected
798  busvoodoo_led_red_off(); // clear red LED
799  busvoodoo_led_blue_on(); // notify user test is running
800  if (user_input_available) { // user interruption
801  goto error;
802  }
804  gpio_clear(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull low to avoid false negative
805  sleep_ms(100); // wait for voltage to settle an debounce
806  if (!gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN))) { // check if CTS is set high by RTS
807  printf("RS-232 CTS is high while it should be set low by RS-232 RTS\n");
808  goto error;
809  }
810  gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RTS_PIN)); // free pin
811  gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_CTS_PIN)); // free pin
812  gpio_set(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set high to disable receiver
813  gpio_clear(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set low to disable transmitter
814  pinout[6] = NULL; // clear pin to test
815  pinout[8] = NULL; // clear pin to test
816  }
817 
818  to_return = true; // all tests passed
819 error:
820  if (!to_return) {
821  if (user_input_available) {
822  printf("user interrupted the test\n");
823  to_return = true; // we don't consider this as error
824  } else if (halt) { // halt on error if requested
825  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
826  while (!user_input_available); // wait for user input
827  } else {
828  printf("the test procedure has been aborted for safety reasons\n");
829  }
830  }
831  busvoodoo_safe_state(); // go back to safe state
832 
833  return to_return;
834 }
835 
836 // command handlers
837 
843 {
844  (void)argument; // we won't use the argument
845  RCC_CSR |= RCC_CSR_RMVF; // clear reset flags
846  scb_reset_core(); // reset core (the bootloader will interpret it as starting into DFU)
847  while (true); // wait for the reset to happen
848 }
849 
854 static void busvoodoo_hiz_version(void* argument)
855 {
856  (void)argument; // we won't use the argument
857  printf("BusVoodoo flavor: %s\n", busvoodoo_full ? "full" : "light");
858  printf("hardware version: %c\n", busvoodoo_version);
859  printf("firmware date: %04u-%02u-%02u\n", BUILD_YEAR, BUILD_MONTH, BUILD_DAY);
860  printf("device ID: %08x%08x%08x\n", DESIG_UNIQUE_ID0, DESIG_UNIQUE_ID1, DESIG_UNIQUE_ID2);
861 }
862 
863 
868 {
869  bool halt = false; // if we halt on error
870  if (NULL!=argument && strlen(argument)>0) {
871  if (0==strcmp(argument, "halt")) {
872  halt = true;
873  } else {
874  printf("malformed argument\n");
875  return;
876  }
877  }
878  printf("performing self-test\n");
879  if (halt) {
880  printf("WARNING: halting on error can cause hardware damages (press any key to exit halt state)\n");
881  }
882  printf("remove all cables from connectors and press space to start (or any other key to abort)\n");
883  busvoodoo_leds_off(); // clear LEDs
884  busvoodoo_led_red_on(); // show red LED to indicate test started
885  if (' '==user_input_get()) { // space entered
886  printf("self-test running\n");
887  if (busvoodoo_hiz_test_self(halt)) { // perform self-test
888  busvoodoo_led_red_off(); // clear red LED
889  busvoodoo_led_blue_on(); // show blue to indicate test passed
890  } else {
891  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
892  printf("self-test failed\n"); // notify user
893  if (user_input_available) {
894  user_input_get(); // clear user input
895  }
896  }
897  } else {
898  printf("self-test aborted\n");
899  }
900 }
901 
906 {
907  bool halt = false; // if we halt on error
908  if (NULL!=argument && strlen(argument)>0) {
909  if (0==strcmp(argument, "halt")) {
910  halt = true;
911  } else {
912  printf("malformed argument\n");
913  return;
914  }
915  }
916  printf("performing pins test\n");
917  if (halt) {
918  printf("WARNING: halting on error can cause hardware damages (press any key to exit halt state)\n");
919  }
920  busvoodoo_leds_off(); // clear LEDs
921  busvoodoo_led_red_on(); // show red LED to indicate test started
922  char* pinout[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; // pinout to display
923  pinout[3] = "O"; // set main testing pin
924  busvoodoo_oled_text_right("pins test"); // display test on display
925  busvoodoo_oled_text_pinout((const char**)pinout, true); // reset pinout
926  busvoodoo_oled_update(); // update screen
927  printf("connect one lead of jumper wire to I/O pin 4 and press space to start (or any other key to abort)\n");
928  if (' '==user_input_get()) { // space entered
929  if (busvoodoo_hiz_test_pins(halt)) { // perform pin test
930  busvoodoo_led_red_off(); // clear red LED
931  busvoodoo_led_blue_on(); // show blue OK LED
932  printf("pins test succeeded\n"); // notify user
933  } else {
934  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
935  printf("pins test failed\n"); // notify user
936  if (user_input_available) {
937  user_input_get(); // clear user input
938  }
939  }
940  } else {
941  printf("pins test aborted\n");
942  busvoodoo_led_red_off(); // clear red LED
943  busvoodoo_led_blue_on(); // switch back to main blue LED
944  }
945  busvoodoo_oled_text_left("HiZ"); // reset mode text
947  busvoodoo_oled_update(); // update display to show text and pinout
948 }
949 
951 static const struct menu_command_t busvoodoo_hiz_commands[] = {
952  {
953  .shortcut = 'v',
954  .name = "version",
955  .command_description = "show hardware and firmware version",
956  .argument = MENU_ARGUMENT_NONE,
957  .argument_description = NULL,
958  .command_handler = &busvoodoo_hiz_version,
959  },
960  {
961  .shortcut = 'b',
962  .name = "bootloader",
963  .command_description = "reboot into DFU bootloader",
964  .argument = MENU_ARGUMENT_NONE,
965  .argument_description = NULL,
966  .command_handler = &busvoodoo_hiz_bootloader,
967  },
968  {
969  .shortcut = 's',
970  .name = "self-test [halt]",
971  .command_description = "perform board self-test (optional halt on error)",
972  .argument = MENU_ARGUMENT_STRING,
973  .argument_description = NULL,
974  .command_handler = &busvoodoo_hiz_command_test_self,
975  },
976  {
977  .shortcut = 't',
978  .name = "pins-test [halt]",
979  .command_description = "perform connector pins test (optional halt on error)",
980  .argument = MENU_ARGUMENT_STRING,
981  .argument_description = NULL,
982  .command_handler = &busvoodoo_hiz_command_test_pins,
983  },
984 };
985 
987  .name = "hiz",
988  .description = "High Impedance (Z)",
989  .full_only = false,
990  .setup = &busvoodoo_hiz_setup,
991  .commands = busvoodoo_hiz_commands,
992  .commands_nb = LENGTH(busvoodoo_hiz_commands),
993  .exit = &busvoodoo_hiz_exit,
994 };
void busvoodoo_leds_off(void)
switch off blue and red LEDs
#define BUSVOODOO_5V_CHANNEL
ADC channel to measure 3.3V rail.
float busvoodoo_hv_set(float voltage)
set voltage on high voltage adjustable voltage regulator
#define BUSVOODOO_LV_TEST
target LV output voltage to test if we can set control the LV voltage regulator
Definition: busvoodoo_hiz.c:42
static void busvoodoo_hiz_bootloader(void *argument)
switch to DFU bootloader
#define BUSVOODOO_HVCTL_CHANNEL
DAC channel to control HV output voltage.
command menu entry
Definition: menu.h:31
static const struct menu_command_t busvoodoo_hiz_commands[]
HiZ menu commands.
BusVoodoo global definitions and methods (API)
#define BUSVOODOO_HVEN_PIN
high voltage (HV) enable pin (active low)
#define RCC_GPIO(x)
get RCC for GPIO based on GPIO identifier
Definition: global.h:105
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
const char * name
name of the mode (i.e.
#define BUSVOODOO_LVCTL_PORT
pin to control LV output voltage
bool busvoodoo_vout_switch(bool on)
switch 3V3 and 5V power outputs on I/O connector
#define BUSVOODOO_RS232_EN_PORT
RS-232 pin to enable receiver (active low, pulled up)
#define BUSVOODOO_HV_SET(x)
voltage to output for the DAC to set the desired HV output voltage (based on resistor values on the H...
#define BUSVOODOO_HVEN_PORT
high voltage (HV) enable pin (active low)
#define BUSVOODOO_RS232_CTS_PORT
RS-232 Clear-To-Send input pin.
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
float busvoodoo_lv_set(float voltage)
set voltage on low voltage adjustable voltage regulator
#define BUSVOODOO_LVEN_PIN
low voltage (LV) enable pin (active high)
const char * busvoodoo_global_pinout_rscan[5]
RS/CAN connector pinout.
const uint32_t busvoodoo_io_pins[13]
pin of individual signals
#define BUSVOODOO_RS232_TX_PORT
RS-232 Transmit output pin.
global definitions and methods (API)
enum menu_argument_t argument
what kind of argument it accepts
Definition: menu.h:35
static void busvoodoo_hiz_exit(void)
exit HiZ mode
Definition: busvoodoo_hiz.c:75
#define GPIO(x)
get GPIO based on GPIO identifier
Definition: global.h:103
#define BUSVOODOO_RS485_RX_PORT
RS-485 Receive input pin.
void sleep_us(uint32_t duration)
go to sleep for some microseconds
Definition: global.c:102
static void busvoodoo_hiz_command_test_self(void *argument)
command to perform board self-test
#define BUSVOODOO_HV_DEFAULT
default (when not driven) HV voltage regulator output voltage based on R1 and R2
Definition: busvoodoo_hiz.c:43
#define BUSVOODOO_RS485_RE_PORT
RS-485 pin to enable receiver (active low, pulled up)
static bool busvoodoo_hiz_test_pins(bool halt)
test if signals are soldered correctly to the connector pins
bool busvoodoo_full
is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side)
static void busvoodoo_hiz_version(void *argument)
show BusVoodoo version
const struct busvoodoo_mode_t busvoodoo_hiz_mode
HiZ mode interface definition.
const uint32_t busvoodoo_io_ports[13]
port of individual signals
#define BUSVOODOO_RS485_TX_PORT
RS-485 Transmit output pin.
#define BUSVOODOO_RS232_CTS_PIN
RS-232 Clear-To-Send input pin.
#define BUSVOODOO_LV_CHANNEL
ADC channel to measure LV rail.
#define BUSVOODOO_RS232_TX_PIN
RS-232 Transmit output pin.
#define BUSVOODOO_RS485_DE_PORT
RS-485 pin to enable transmitter (active high, pulled low)
#define BUSVOODOO_RS232_RTS_PIN
RS-232 Request-To-Send output pin.
const uint8_t busvoodoo_io_groups[13]
which I/O pin (group) does the signal belong to
char shortcut
short command code (0 if not available)
Definition: menu.h:32
void busvoodoo_leds_blink(double period, double duty)
set LED blinking pattern
void busvoodoo_led_blue_on(void)
switch on blue LED
#define BUILD_MONTH
build month as number if known, or 0 if unknown
Definition: global.h:94
#define BUSVOODOO_HV_CHANNEL
ADC channel to measure HV rail.
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
#define BUSVOODOO_LVCTL_PIN
pin to control LV output voltage
char user_input_get(void)
get user input
Definition: global.c:145
#define BUSVOODOO_RS232_EN_PIN
RS-232 pin to enable receiver (active low, pulled up)
static bool busvoodoo_hiz_setup(char **prefix, const char *line)
setup HiZ mode
Definition: busvoodoo_hiz.c:51
float busvoodoo_vreg_get(uint8_t channel)
read voltage from power rail
const char * busvoodoo_io_names[13]
I/O individual signal names.
#define BUSVOODOO_VOUTEN_PORT
voltage output (5V and 3.3V) enable pin (active low)
void sleep_ms(uint32_t duration)
go to sleep for some milliseconds
Definition: global.c:117
#define BUSVOODOO_VOUTEN_PIN
voltage output (5V and 3.3V) enable pin (active low)
#define BUSVOODOO_RS232_RX_PORT
RS-232 Receive input pin.
#define BUSVOODOO_RS485_DE_PIN
RS-485 pin to enable transmitter (active high, pulled low)
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
#define BUSVOODOO_LVEN_PORT
low voltage (LV) enable pin (active high)
float busvoodoo_embedded_pullup(bool on)
enable embedded pull-up resistors
#define BUSVOODOO_HV_TEST
target HV output voltage to test if we can set control the HV voltage regulator
Definition: busvoodoo_hiz.c:44
void busvoodoo_led_red_off(void)
switch off red LED
#define BUSVOODOO_RS232_RTS_PORT
RS-232 Request-To-Send output pin.
static bool busvoodoo_hiz_test_self(bool halt)
perform self tests
Definition: busvoodoo_hiz.c:84
#define LENGTH(x)
get the length of an array
Definition: global.h:26
#define BUSVOODOO_RS485_RE_PIN
RS-485 pin to enable receiver (active low, pulled up)
void busvoodoo_oled_text_right(char *text)
draw mode text on top (yellow) right side in display buffer
void busvoodoo_led_red_on(void)
switch on red LED
#define BUSVOODOO_RS232_RX_PIN
RS-232 Receive input pin.
#define BUSVOODOO_LV_DEFAULT
default (when not driven) LV voltage regulator output voltage based on R1 and R2
Definition: busvoodoo_hiz.c:41
BusVoodoo high impedance (HiZ) default mode (API)
#define BUSVOODOO_RS485_RX_PIN
RS-485 Receive input pin.
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
static void busvoodoo_hiz_command_test_pins(void *argument)
command to perform pins test
volatile bool user_input_available
flag set when user input is available
Definition: global.c:36
#define BUSVOODOO_RS485_TX_PIN
RS-485 Transmit output pin.
void busvoodoo_safe_state(void)
set safe state by disabling all outputs
#define BUILD_YEAR
build year as number if known, or 0 if unknown
Definition: global.h:92
char busvoodoo_version
version of the hardware board
BusVoodoo mode interface.
#define BUSVOODOO_RS232_SHDN_PORT
RS-232 pin to enable transmitter (active high, pulled low)
#define BUSVOODOO_3V3_CHANNEL
ADC channel to measure 5V rail.
#define BUSVOODOO_RS232_SHDN_PIN
RS-232 pin to enable transmitter (active high, pulled low)
#define BUILD_DAY
build day as number if known, or 0 if unknown
Definition: global.h:96