altos: Remove ao_led_toggle API from general code
[fw/altos] / src / attiny / ao_arch_funcs.h
1 /*
2  * Copyright © 2012 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 /*
20  * ao_spi.c
21  */
22
23 #define ao_spi_get_mask(reg,mask,bus,speed) do {        \
24                 (reg) &= ~(mask);                       \
25         } while (0)
26
27 #define ao_spi_put_mask(reg,mask,bus) do {      \
28                 (reg) |= (mask);                \
29         } while (0)
30
31 #define ao_spi_get_bit(reg,bit,bus,speed) ao_spi_get_mask(reg,(1<<(bit)),bus,speed)
32
33 #define ao_spi_put_bit(reg,bit,bus) ao_spi_put_mask(reg,(1<<(bit)),bus)
34
35 #define ao_gpio_token_paster(x,y)               x ## y
36 #define ao_gpio_token_evaluator(x,y)    ao_gpio_token_paster(x,y)
37
38 #define ao_gpio_set(port, bit, v) do {  \
39                 if (v)                          \
40                         PORTB |= (1 << bit);    \
41                 else                            \
42                         PORTB &= ~(1 << bit);   \
43         } while (0)
44
45 #define ao_gpio_get(port, bit)  ((PORTB >> (bit)) & 1)
46
47 /*
48  * The SPI mutex must be held to call either of these
49  * functions -- this mutex covers the entire SPI operation,
50  * from chip select low to chip select high
51  */
52
53 #define ao_enable_output(port, bit, v) do {                     \
54                 ao_gpio_set(port, bit, v);                              \
55                 ao_gpio_token_evaluator(DDR,port) |= (1 << bit);        \
56         } while (0)
57
58
59 void
60 ao_spi_send_bus(void *block, uint16_t len);
61
62 void
63 ao_spi_recv_bus(void *block, uint16_t len);
64
65 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
66 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
67
68 void
69 ao_spi_init(void);
70
71 #define ao_spi_get(bus, speed)
72 #define ao_spi_put(bus)
73
74 #define ao_spi_init_cs(port, mask) do {         \
75                 PORTB |= (mask);                \
76                 DDRB |= (mask);         \
77         } while (0)
78
79 /* I2C */
80
81 void
82 ao_i2c_get(uint8_t i2c_index);
83
84 uint8_t
85 ao_i2c_start_bus(uint8_t address);
86
87 #define ao_i2c_start(i,a)       ao_i2c_start_bus(a)
88
89 void
90 ao_i2c_put(uint8_t i2c_index);
91
92 uint8_t
93 ao_i2c_send_bus(void *block, uint16_t len, uint8_t stop);
94
95 #define ao_i2c_send(b,l,i,s) ao_i2c_send_bus(b,l.s)
96
97 uint8_t
98 ao_i2c_send_fixed_bus(uint8_t value, uint16_t len, uint8_t stop);
99
100 #define ao_i2c_send_fixed(v,l,i,s) ao_i2c_send_fixed_bus(v,l.s)
101
102 uint8_t
103 ao_i2c_recv_bus(void *block, uint16_t len, uint8_t stop);
104
105 #define ao_i2c_recv(b,l,i,s) ao_i2c_recv_bus(b,l.s)
106
107 void
108 ao_i2c_init(void);
109
110 /* notask.c */
111
112 uint8_t
113 ao_sleep(void *wchan);
114
115 void
116 ao_wakeup(void *wchan);
117
118 extern alt_t    ao_max_height;
119
120 extern void ao_report_altitude(void);
121
122 void ao_delay_us(uint16_t us);
123
124 void
125 ao_led_toggle(uint8_t colors);