2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 #define ao_spi_get_mask(reg,mask,bus,speed) do { \
26 #define ao_spi_put_mask(reg,mask,bus) do { \
30 #define ao_spi_get_bit(reg,bit,pin,bus,speed) ao_spi_get_mask(reg,(1<<(bit)),bus,speed)
32 #define ao_spi_put_bit(reg,bit,pin,bus) ao_spi_put_mask(reg,(1<<(bit)),bus)
34 #define ao_gpio_token_paster(x,y) x ## y
35 #define ao_gpio_token_evaluator(x,y) ao_gpio_token_paster(x,y)
37 #define ao_gpio_set(port, bit, pin, v) do { \
39 PORTB |= (1 << bit); \
41 PORTB &= ~(1 << bit); \
44 #define ao_gpio_get(port, bit, pin) ((PORTB >> (bit)) & 1)
47 * The SPI mutex must be held to call either of these
48 * functions -- this mutex covers the entire SPI operation,
49 * from chip select low to chip select high
52 #define ao_enable_output(port, bit, pin, v) do { \
53 ao_gpio_set(port, bit, pin, v); \
54 ao_gpio_token_evaluator(DDR,port) |= (1 << bit); \
59 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
62 ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant;
64 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
65 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
70 #define ao_spi_get(bus, speed)
71 #define ao_spi_put(bus)
73 #define ao_spi_init_cs(port, mask) do { \
81 ao_i2c_get(uint8_t i2c_index);
84 ao_i2c_start_bus(uint8_t address);
86 #define ao_i2c_start(i,a) ao_i2c_start_bus(a)
89 ao_i2c_put(uint8_t i2c_index);
92 ao_i2c_send_bus(void *block, uint16_t len, uint8_t stop);
94 #define ao_i2c_send(b,l,i,s) ao_i2c_send_bus(b,l.s)
97 ao_i2c_send_fixed_bus(uint8_t value, uint16_t len, uint8_t stop);
99 #define ao_i2c_send_fixed(v,l,i,s) ao_i2c_send_fixed_bus(v,l.s)
102 ao_i2c_recv_bus(void *block, uint16_t len, uint8_t stop);
104 #define ao_i2c_recv(b,l,i,s) ao_i2c_recv_bus(b,l.s)
112 ao_sleep(__xdata void *wchan);
115 ao_wakeup(__xdata void *wchan);
117 extern alt_t ao_max_height;
119 extern void ao_report_altitude(void);
121 void ao_delay_us(uint16_t us);