#include #include #include #include "zap.h" void cli_dragonzap_test(void); void cli_dragonzap_test(void) { // TODO: test: // * ADC0,1,2 input // -> ADC0,1: OK // -> ADC2: ≃0xB80 is 5.04V; not ≃0xC38? // 2.48V measured at ADC2 pin... // * DAC control // * MAX4619 control (enable, switch) // * crowbar 1,2 control // * NXS0108 functionality zap_init_default(); zap_dac_set_enable(zap_dac_a | zap_dac_b); zap_dac_set_mulx2(zap_dac_a | zap_dac_b); 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[3]; for (int i = 0; i < 3; ++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_togl = 0x80; busy_wait_ms(1000); zap_crowbar_a_hiz(); zap_crowbar_b_hiz(); zap_max_put(false); sio_hw->gpio_togl = 0x80; busy_wait_ms(1000); } }