forked from DangerousPrototypes/BusPirate5-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadc.c
93 lines (78 loc) · 2.28 KB
/
adc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/adc.h"
#include "pirate.h"
#include "opt_args.h"
#include "bio.h"
#include "ui/ui_prompt.h"
#include "ui/ui_const.h"
#include "ui/ui_term.h"
#include "ui/ui_info.h"
#include "system_config.h"
#include "freq.h"
#include "usb_rx.h"
#include "amux.h"
void adc_measure(opt_args (*args), struct command_result *res, bool refresh);
uint32_t adc_print(uint8_t bio_pin, bool refresh)
{
//sweep adc
amux_sweep();
printf("%s%s IO%d:%s %s%d.%d%sV\r%s",
ui_term_color_info(), t[T_MODE_ADC_VOLTAGE], bio_pin, ui_term_color_reset(), ui_term_color_num_float(),
((*hw_pin_voltage_ordered[bio_pin+1])/1000), (((*hw_pin_voltage_ordered[bio_pin+1])%1000)/100),
ui_term_color_reset(), (refresh?"":"\n")
);
return 1;
}
void adc_measure_single(opt_args (*args), struct command_result *res)
{
adc_measure(args, res, false);
}
void adc_measure_cont(opt_args (*args), struct command_result *res)
{
adc_measure(args, res, true);
}
void adc_measure(opt_args (*args), struct command_result *res, bool refresh)
{
if(args[0].no_value) //show voltage on all pins
{
if(refresh)
{
//TODO: use the ui_prompt_continue function, but how to deal with the names and labels????
printf("%s%s%s\r\n%s", ui_term_color_notice(), t[T_PRESS_ANY_KEY_TO_EXIT], ui_term_color_reset(), ui_term_cursor_hide());
}
ui_info_print_pin_names();
ui_info_print_pin_labels();
if(refresh)
{
char c;
do
{
ui_info_print_pin_voltage(true);
delayms(250);
}while(!rx_fifo_try_get(&c));
printf("%s", ui_term_cursor_show()); //show cursor
}
//for single measurement, also adds final \n for continuous
ui_info_print_pin_voltage(false);
}
else //single pin measurement
{
//pin bounds check
if(args[0].i>=count_of(bio2bufiopin))
{
printf("Error: Pin IO%d is invalid", args[0].i);
res->error=true;
return;
}
if(refresh)
{
//continuous measurement on this pin
// press any key to continue
prompt_result result;
ui_prompt_any_key_continue(&result, 250, &adc_print, args[0].i, true);
}
//single measurement, also adds final \n for cont mode
adc_print(args[0].i,false);
}
}