root / scout_avr / src / bom.h @ 812788aa
History | View | Annotate | Download (1.19 KB)
1 |
#ifndef _BOM_H
|
---|---|
2 |
#define _BOM_H
|
3 |
|
4 |
extern "C" { |
5 |
#include <stdint.h> |
6 |
} |
7 |
|
8 |
// constants for direction
|
9 |
#define BOM_FRONT 0 |
10 |
#define BOM_BACK 1 |
11 |
#define BOM_LEFT 2 |
12 |
#define BOM_RIGHT 3 |
13 |
|
14 |
// timing, in us, for read of valid bits
|
15 |
#define MIN_LOW_PW 600 |
16 |
#define MAX_LOW_PW 1400 |
17 |
#define MIN_HIGH_PW 1600 |
18 |
#define MAX_HIGH_PW 2400 |
19 |
|
20 |
// returned by bom_get if there is no new data since last call
|
21 |
#define BOM_NO_DATA -1 |
22 |
|
23 |
// i/o pins
|
24 |
// if these are changed, remember to change bom_init and/or ISRs
|
25 |
#define BOM_SIG PINB
|
26 |
#define BOM_SIG0 PB0
|
27 |
#define BOM_SIG1 PB1
|
28 |
#define BOM_SIG2 PB2
|
29 |
#define BOM_SIG3 PB3
|
30 |
#define BOM_EMIT PORTH
|
31 |
#define BOM_EMIT0 PH4
|
32 |
#define BOM_EMIT1 PH5
|
33 |
#define BOM_EMIT2 PH6
|
34 |
#define BOM_EMIT3 PH7
|
35 |
|
36 |
typedef uint8_t bom_msg_t;
|
37 |
|
38 |
inline char bom_msg_get_robot_id(bom_msg_t msg) { |
39 |
return msg >> 2; |
40 |
} |
41 |
inline char bom_msg_get_dir(bom_msg_t msg) { |
42 |
return msg & 3; |
43 |
} |
44 |
inline bom_msg_t bom_msg_make(char id, char dir) { |
45 |
return (id << 2) | (dir & 3); |
46 |
} |
47 |
|
48 |
void set_robot_id(char id); |
49 |
char get_robot_id(void); |
50 |
|
51 |
// NOTE: call range_init before bom_init to ensure timer 1 is set up!
|
52 |
void bom_init(void); |
53 |
void bom_send(char dir); |
54 |
int bom_get(char dir); |
55 |
|
56 |
// toggles output - should be called at around 76 kHz
|
57 |
void bom_isr();
|
58 |
|
59 |
#endif
|