Rename tools to ao-<foo>
[fw/altos] / ao-tools / lib / cc-bitbang.h
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _CC_BITBANG_H_
20 #define _CC_BITBANG_H_
21
22 #include <stdint.h>
23
24 #define CC_CLOCK        0x1
25 #define CC_DATA         0x2
26 #define CC_RESET_N      0x4
27 #define CC_CLOCK_US     (2)
28
29 /* Telemetrum has a 10k pull-up to 3.3v, a 0.001uF cap to ground
30  * and a 2.7k resistor to the reset line. This takes about 6us
31  * to settle, so we'll wait longer than that after changing the reset line
32  */
33 #define CC_RESET_US     (12)
34
35 struct cc_bitbang;
36
37 void
38 cc_bitbang_set_clock(uint32_t us);
39
40 void
41 cc_bitbang_half_clock(struct cc_bitbang *bb);
42
43 void
44 cc_bitbang_wait_reset(struct cc_bitbang *bb);
45
46 struct cc_bitbang *
47 cc_bitbang_open(void);
48
49 void
50 cc_bitbang_close(struct cc_bitbang *bb);
51
52 void
53 cc_bitbang_debug_mode(struct cc_bitbang *bb);
54
55 void
56 cc_bitbang_reset(struct cc_bitbang *bb);
57
58 int
59 cc_bitbang_write(struct cc_bitbang *bb, uint8_t mask, uint8_t value);
60
61 void
62 cc_bitbang_read(struct cc_bitbang *bb, uint8_t *valuep);
63
64 void
65 cc_bitbang_sync(struct cc_bitbang *bb);
66
67 void
68 cc_bitbang_print(char *format, uint8_t mask, uint8_t set);
69
70 void
71 cc_bitbang_print(char *format, uint8_t mask, uint8_t set);
72
73 void
74 cc_bitbang_send(struct cc_bitbang *bb, uint8_t mask, uint8_t set);
75
76 void
77 cc_bitbang_send_bit(struct cc_bitbang *bb, uint8_t bit);
78
79 void
80 cc_bitbang_send_byte(struct cc_bitbang *bb, uint8_t byte);
81
82 void
83 cc_bitbang_send_bytes(struct cc_bitbang *bb, uint8_t *bytes, int nbytes);
84
85 void
86 cc_bitbang_recv_bit(struct cc_bitbang *bb, int first, uint8_t *bit);
87
88 void
89 cc_bitbang_recv_byte(struct cc_bitbang *bb, int first, uint8_t *bytep);
90
91 void
92 cc_bitbang_recv_bytes(struct cc_bitbang *bb, uint8_t *bytes, int nbytes);
93
94 #endif /* _CC_BITBANG_H_ */