]> git.karo-electronics.de Git - oswald.git/blob - metawatch/mw_bt.h
Add modified LPM3_EXIT_ISR to work around FLL IRQ wake-up problem
[oswald.git] / metawatch / mw_bt.h
1 #ifndef _MW_BT_H
2 #define _MW_BT_H
3
4 #define BT_RST_PIN              BIT3
5 #define BT_RST_PSEL             P10SEL
6 #define BT_RST_POUT             P10OUT
7 #define BT_RST_PDIR             P10DIR
8
9 #define BT_IO_PSEL              P1SEL
10 #define BT_IO_RTS               BIT0
11 #define BT_IO_CTS               BIT3
12 #define BT_IO_POUT              P1OUT
13 #define BT_IO_PIN               P1IN
14 #define BT_IO_PDIR              P1DIR
15 #define BT_IO_REN               P1REN
16
17 #define BT_IO_PIN1              BIT5
18 #define BT_IO_PIN2              BIT6
19 #define BT_IO_CLKREQ    BIT4
20
21 #define BT_SHUTDOWN()           { BT_RST_POUT &= ~BT_RST_PIN; }
22 #define BT_ENABLE()                     { BT_RST_POUT |= BT_RST_PIN; }
23
24 #define BT_UART_PSEL            P5SEL
25 #define BT_UART_PDIR            P5DIR
26 #define BT_UART_REN                     P5REN
27 #define BT_UART_POUT            P5OUT
28 #define BT_UART_TX_PIN          BIT6
29 #define BT_UART_RX_PIN          BIT7
30
31 #define CONFIG_BT_PINS() { \
32         BT_RST_PSEL &= ~BT_RST_PIN; \
33         BT_RST_PDIR |= BT_RST_PIN; \
34         BT_SHUTDOWN(); \
35         BT_IO_PSEL &= ~(BT_IO_RTS | BT_IO_CTS | BT_IO_PIN1 | BT_IO_PIN2 | BT_IO_CLKREQ); \
36         BT_IO_PDIR &= ~(BT_IO_RTS | BT_IO_CTS | BT_IO_PIN1 | BT_IO_PIN2 | BT_IO_CLKREQ); \
37         BT_IO_POUT &= ~(BT_IO_RTS | BT_IO_CTS | BT_IO_PIN1 | BT_IO_PIN2 | BT_IO_CLKREQ); \
38         BT_UART_PSEL &= ~(BT_UART_TX_PIN | BT_UART_RX_PIN); \
39         BT_UART_PDIR &= ~(BT_UART_TX_PIN | BT_UART_RX_PIN); \
40         BT_UART_REN |= BT_UART_TX_PIN | BT_UART_RX_PIN; \
41         BT_UART_POUT |= BT_UART_TX_PIN | BT_UART_RX_PIN; \
42 }
43
44 void mw_enable_bt(void);
45 void mw_disable_bt(void);
46
47 typedef enum {
48         BT_UART_BD19200 = 0,
49         BT_UART_BD38400,
50         BT_UART_BD57600,
51         BT_UART_BD115200,
52         BT_UART_BD234000,
53 } bt_uart_baud_t;
54
55 #define BT_MW_DEVICE_CLASS      0x842704 /* Limited discovery, Rendering, Information, Wearable, Wrist Watch */
56 #define BT_RX_MAX_SIZE          255
57
58 void mw_init_bt_uart(const bt_uart_baud_t baud);
59
60 int mw_bt_uart_tx(const void *buf, const unsigned int len);
61 // extern char BT_UART_RX_CHAR;
62
63 int mw_bt_get_rxbuf_len(void);
64 const unsigned char *mw_bt_get_rx_buf(unsigned char **rpos, unsigned char *len);
65 unsigned char bt_feed_packet_data(unsigned char pdata);
66 uint8_t mw_bt_is_enabled(void);
67 #endif