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 extern __xdata uint8_t ao_spi_mutex;
24 #define AO_SPI_SPEED_FAST 17
25 #define AO_SPI_SPEED_200kHz 13
27 #define ao_spi_set_speed(speed) (U0GCR = (UxGCR_CPOL_NEGATIVE | \
28 UxGCR_CPHA_FIRST_EDGE | \
30 ((speed) << UxGCR_BAUD_E_SHIFT)))
32 #define ao_spi_get_mask(reg,mask,bus,speed) do { \
33 ao_mutex_get(&ao_spi_mutex); \
34 ao_spi_set_speed(speed); \
38 #define ao_spi_put_mask(reg,mask,bus) do { \
40 ao_mutex_put(&ao_spi_mutex); \
44 #define ao_spi_get_bit(reg,bit,pin,bus,speed) do { \
45 ao_mutex_get(&ao_spi_mutex); \
46 ao_spi_set_speed(speed); \
50 #define ao_spi_put_bit(reg,bit,pin,bus) do { \
52 ao_mutex_put(&ao_spi_mutex); \
57 * The SPI mutex must be held to call either of these
58 * functions -- this mutex covers the entire SPI operation,
59 * from chip select low to chip select high
63 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
66 ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant;
68 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
69 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
74 #define ao_spi_init_cs(port, mask) do { \
75 SPI_CS_PORT |= mask; \
77 SPI_CS_SEL &= ~mask; \
80 #define cc1111_enable_output(port,dir,sel,mask,v) do { \
81 port = port & ~(mask) | v; \
86 #define disable_unreachable _Pragma("disable_warning 126")
88 #define token_paster(x,y) x ## y
89 #define token_evaluator(x,y) token_paster(x,y)
90 #define ao_enable_output(port,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), 1 << pin, 1 << v)