pico430prog/src/cli/dragonzap.c

58 lines
1.1 KiB
C

#include <stdio.h>
#include <string.h>
#include <pico/time.h>
#include "zap.h"
void cli_dragonzap_test(void);
void cli_dragonzap_test(void) {
zap_init_default();
zap_dac_set_enable(zap_dac_a | zap_dac_b);
#if 1 /* MCP48x2 */
zap_dac_set_mulx2(zap_dac_a | zap_dac_b);
#else
zap_dac_set_mulx2(0);
zap_dac_set_shutdown(false);
#endif
zap_max_use_vhi_jp300(true);
zap_max_set_inhibit(false);
sio_hw->gpio_oe_set = ZAP_GPIO_MASK;
sio_hw->gpio_clr = ZAP_GPIO_MASK;
for (int i = ZAP_GPIO_BASE; i <= ZAP_GPIO_END; ++i) {
gpio_set_function(i, GPIO_FUNC_SIO);
}
while (true) {
uint16_t adcv[2];
for (int i = 0; i < 2; ++i) {
adcv[i] = zap_adc_read(i);
}
/*uint32_t vbus = zap_adc_get_vbus();
float vbusf = vbus / (float)0x10000;*/
printf("ADC: 0x%04x, 0x%04x"/*", 0x%04x = %.2f"*/"\n", adcv[0], adcv[1]/*, adcv[2], vbusf*/);
zap_dac_set_a(adcv[0]);
zap_dac_set_b(adcv[1]);
zap_dac_latch();
zap_crowbar_a_act();
zap_crowbar_b_act();
zap_max_put(true);
sio_hw->gpio_set = 0x80;
busy_wait_ms(1000);
zap_crowbar_a_hiz();
zap_crowbar_b_hiz();
zap_max_put(false);
sio_hw->gpio_set = 0x80;
busy_wait_ms(1000);
}
}