forked from DangerousPrototypes/BusPirate5-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auxpinfunc.c
77 lines (65 loc) · 2.46 KB
/
auxpinfunc.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
#include <stdint.h>
#include "pico/stdlib.h"
#include "pirate.h"
#include "auxpinfunc.h"
#include "bio.h"
#include "system_config.h"
#include "ui/ui_term.h"
void auxpinfunc_write(struct command_attributes *attributes, struct command_response *response, bool output, bool level);
static const char labels[][5]={"AUXL","AUXH"};
void auxpinfunc_high(struct command_attributes *attributes, struct command_response *response)
{
auxpinfunc_write(attributes, response, true, 1);
}
void auxpinfunc_low(struct command_attributes *attributes, struct command_response *response)
{
auxpinfunc_write(attributes, response, true, 0);
}
void auxpinfunc_input(struct command_attributes *attributes, struct command_response *response)
{
auxpinfunc_write(attributes, response, false, 0);
}
void auxpinfunc_write(struct command_attributes *attributes, struct command_response *response, bool output, bool level)
{
if(!attributes->has_dot)
{
printf("%sError:%s specify an IO pin (a.1, A.5, @.0)", ui_term_color_error(), ui_term_color_reset());
response->error=true;
return;
}
uint32_t pin=attributes->dot;
// first make sure the pin is present and available
if(pin>=count_of(bio2bufiopin))
{
printf("%sError:%s pin IO%d is invalid", ui_term_color_error(), ui_term_color_reset(), pin);
response->error=true;
return;
}
// pin is in use for any purposes
if(system_config.pin_labels[pin+1]!=0 && !(system_config.aux_active & (0x01<<((uint8_t)pin))))
{
printf("%sError:%s IO%d is in use by %s", ui_term_color_error(), ui_term_color_reset(), pin, system_config.pin_labels[pin+1]);
response->error=true;
return;
}
if(output) // output
{
bio_output(pin);
bio_put(pin,level);
printf("IO%s%d%s set to%s OUTPUT: %s%d%s\r\n",
ui_term_color_num_float(), pin, ui_term_color_notice(),ui_term_color_reset(),
ui_term_color_num_float(), level, ui_term_color_reset());
system_bio_claim(true, pin, BP_PIN_IO, labels[level]);
system_set_active(true, pin, &system_config.aux_active);
}
else // input
{
bio_input(pin);
printf("IO%s%d%s set to%s INPUT: %s%d%s\r\n",
ui_term_color_num_float(), pin, ui_term_color_notice(),ui_term_color_reset(),
ui_term_color_num_float(), bio_get(pin), ui_term_color_reset());
system_bio_claim(false, pin, BP_PIN_IO, 0);
system_set_active(false, pin, &system_config.aux_active);
}
return;
}