forked from DangerousPrototypes/BusPirate5-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bio.c
89 lines (83 loc) · 2.6 KB
/
bio.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
#include <stdio.h>
#include "pico/stdlib.h"
#include "pirate.h"
#define BUFDIR_INPUT 0
#define BUFDIR_OUTPUT 1
void bio_init(void)
{
// setup the buffer IO and DIRection pins
for(uint8_t i=0;i<BIO_MAX_PINS; i++)
{
#ifdef BP_DEBUG_ENABLED
if(i==BP_DEBUG_UART_TX || i==BP_DEBUG_UART_RX) continue;
#endif
gpio_set_drive_strength(bio2bufiopin[i], GPIO_DRIVE_STRENGTH_2MA);
gpio_set_dir(bio2bufiopin[i], GPIO_IN);
gpio_set_function(bio2bufiopin[i], GPIO_FUNC_SIO);
}
// init buffer direction (0 = input)
for(uint8_t i=0;i<BIO_MAX_PINS; i++)
{
//don't blow up our debug UART settings
#ifdef BP_DEBUG_ENABLED
if(i==BP_DEBUG_UART_TX || i==BP_DEBUG_UART_RX) continue;
#endif
gpio_put(bio2bufdirpin[i], BUFDIR_INPUT);
gpio_set_dir(bio2bufdirpin[i], GPIO_OUT);
gpio_set_function(bio2bufdirpin[i], GPIO_FUNC_SIO);
}
}
void bio_buf_pin_init(uint8_t bio)
{
gpio_put(bio2bufdirpin[bio], BUFDIR_INPUT);
gpio_set_dir(bio2bufdirpin[bio], GPIO_OUT);
gpio_set_function(bio2bufdirpin[bio], GPIO_FUNC_SIO);
}
//these are only for use with the BIO0...BIOn ordered pin format,
void bio_buf_output(uint8_t bio)
{
gpio_put(bio2bufdirpin[bio], BUFDIR_OUTPUT); //make the buffer an output
}
//these are only for use with the BIO0...BIOn ordered pin format,
void bio_buf_input(uint8_t bio)
{
gpio_put(bio2bufdirpin[bio], BUFDIR_INPUT); //make the buffer an input
}
//these are only for use with the BIO0...BIOn ordered pin format,
void bio_output(uint8_t bio)
{
//first set the buffer to output
gpio_put(bio2bufdirpin[bio], BUFDIR_OUTPUT);
//now set pin to output
gpio_set_dir(bio2bufiopin[bio], GPIO_OUT);
}
//these are only for use with the BIO0...BIOn ordered pin format,
void bio_input(uint8_t bio)
{
//first set the pin to input
gpio_set_dir(bio2bufiopin[bio], GPIO_IN);
//now set buffer to input
gpio_put(bio2bufdirpin[bio], BUFDIR_INPUT);
}
void bio_put(uint8_t bio, bool value)
{
gpio_put(bio2bufiopin[bio], value);
}
bool bio_get(uint8_t bio)
{
return gpio_get(bio2bufiopin[bio]);
}
void bio_set_function(uint8_t bio, uint8_t function)
{
gpio_set_function(bio2bufiopin[bio], function);
}
void bio_buf_test(uint8_t bufio, uint8_t bufdir)
{
gpio_put(bufdir, BUFDIR_OUTPUT);
gpio_set_dir(bufio, GPIO_OUT);
gpio_put(bufio, 1);
busy_wait_ms(2000);
gpio_put(bufio, 0);
gpio_set_dir(bufio, GPIO_IN);
gpio_put(bufdir, BUFDIR_INPUT);
}