/
io.c
74 lines (64 loc) · 1.18 KB
/
io.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
#include "config.h"
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "io.h"
#include "timer.h"
ISR(INT0_vect)
{
if(io_get_ptt())
{
io_set_ptt();
io_set_led();
timer_start();
}
else
{
io_clear_ptt();
io_clear_led();
timer_stop_and_reset();
}
}
void io_init(void)
{
// PB0 is output to LED, PB1 is PTT output to radio
io_clear_led();
io_clear_ptt();
DDRB |= (1 << DDB0) | (1 << DDB1);
// PB2/INT0 is PTT input from raspberry pi, interrupt-driven
EICRA = 1; // Any logical change on INT0 generates IRQ
EIMSK = 1; // Enable external pin interrupt
sei();
}
void io_set_led(void)
{
// LED is active low
PORTB &= ~(1 << PORTB0);
}
void io_clear_led(void)
{
PORTB |= (1 << PORTB0);
}
void io_flash_led(uint8_t n)
{
for(uint8_t i=0; i<n; i++)
{
io_set_led();
_delay_ms(100);
io_clear_led();
_delay_ms(400);
}
}
void io_set_ptt(void)
{
// PTT is active high
PORTB |= (1 << PORTB1);
}
void io_clear_ptt(void)
{
PORTB &= ~(1 << PORTB1);
}
inline bool io_get_ptt(void)
{
return PINB & (1 << PINB2);
}