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; either version 2 of the License, or
7 * (at your option) any later version.
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.
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.
23 #define ao_spi_get_mask(reg,mask,bus,speed) do { \
27 #define ao_spi_put_mask(reg,mask,bus) do { \
31 #define ao_spi_get_bit(reg,bit,bus,speed) ao_spi_get_mask(reg,(1<<(bit)),bus,speed)
33 #define ao_spi_put_bit(reg,bit,bus) ao_spi_put_mask(reg,(1<<(bit)),bus)
35 #define ao_gpio_token_paster(x,y) x ## y
36 #define ao_gpio_token_evaluator(x,y) ao_gpio_token_paster(x,y)
38 #define ao_gpio_set(port, bit, v) do { \
40 PORTB |= (1 << bit); \
42 PORTB &= ~(1 << bit); \
45 #define ao_gpio_get(port, bit) ((PORTB >> (bit)) & 1)
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
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); \
60 ao_spi_send_bus(void *block, uint16_t len);
63 ao_spi_recv_bus(void *block, uint16_t len);
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)
71 #define ao_spi_get(bus, speed)
72 #define ao_spi_put(bus)
74 #define ao_spi_init_cs(port, mask) do { \
82 ao_i2c_get(uint8_t i2c_index);
85 ao_i2c_start_bus(uint8_t address);
87 #define ao_i2c_start(i,a) ao_i2c_start_bus(a)
90 ao_i2c_put(uint8_t i2c_index);
93 ao_i2c_send_bus(void *block, uint16_t len, uint8_t stop);
95 #define ao_i2c_send(b,l,i,s) ao_i2c_send_bus(b,l.s)
98 ao_i2c_send_fixed_bus(uint8_t value, uint16_t len, uint8_t stop);
100 #define ao_i2c_send_fixed(v,l,i,s) ao_i2c_send_fixed_bus(v,l.s)
103 ao_i2c_recv_bus(void *block, uint16_t len, uint8_t stop);
105 #define ao_i2c_recv(b,l,i,s) ao_i2c_recv_bus(b,l.s)
113 ao_sleep(void *wchan);
116 ao_wakeup(void *wchan);
118 extern alt_t ao_max_height;
120 extern void ao_report_altitude(void);
122 void ao_delay_us(uint16_t us);
125 ao_led_toggle(uint8_t colors);