altos: Add RN4678 Bluetooth module driver
[fw/altos] / src / drivers / ao_rn4678.h
1 /*
2  * Copyright © 2017 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
15 #ifndef _AO_RN4678_H_
16 #define _AO_RN4678_H_
17
18 /* From the rn4678 pictail board
19
20     1   SW_BTN  0-off/1-on       2      P2_0    1-app/0-test (boot time)
21     3   P2_4    1-app/0-WF       4      EAN     0-app/1-WF (reboots)
22     5                            6      RTS     0
23     7                            8      P3_2    1 (NC)
24     9   TXD                     10      P3_3    1 (NC)
25    11   RXD                     12      P3_4    1 (NC)
26    13                           14
27    15                           16      P3_7    1 (NC)
28    17   P0_5    1 (NC)          18      RST_N   1 run/0 reset
29    19   WAKE_UP 1 run/0 btn     20
30    21   P0_4    0 (NC)          22
31    23   P1_5    1 (NC)          24      P3_1    1 (NC)
32    25   CTS     0               26      3.3V
33    27                           28      GND
34
35
36    Interesting pins:
37
38    Not connected to microcontroller:
39
40    SW_BTN       0-off           1-on
41    P2_4         0 write-flash   1-app
42    WAKE_UP      0-stop          1-run
43    P2_0         0 test          1-run
44    EAN          1-WF (reboots)  0-run
45    RST_N        0 reset         1 run
46
47    Connected to microcontroller:
48
49    CTS          mostly 0
50    RTS          mostly 1
51
52    TXD
53    RXD
54
55    Other connections -- LDO33_O to VDD_IO
56
57 */
58
59 #define AO_RN_REBOOT_MSG        "%REBOOT%"
60
61 #define AO_RN_CMD_TIMEOUT       AO_MS_TO_TICKS(200)
62
63 #define AO_RN_REBOOT_TIMEOUT    AO_MS_TO_TICKS(2000)
64
65 #define AO_RN_MAX_REPLY_LEN     10
66
67 #define AO_RN_SET_NAME_CMD              "SN,"
68 #define AO_RN_GET_NAME_CMD              "GN"
69
70 #define AO_RN_SET_STATUS_STRING "SO,"
71 #define AO_RN_STATUS_STRING_DISABLE     " "
72
73 #define AO_RN_REBOOT_CMD                "R,1"
74
75 #define AO_RN_TIMEOUT   -1
76 #define AO_RN_ERROR     0
77 #define AO_RN_OK        1
78
79 #define AO_RN_SET_COMMAND_PIN   "SX,07,0B"
80
81 #define AO_RN_SET_AUTH_JUST_WORKS       "SA,2"
82 #define AO_RN_SET_FAST_MODE             "SQ,9000"
83
84 /* This pin is configured to control cmd/data mode */
85 #define AO_RN_CMD_PORT  AO_RN_P3_7_PORT
86 #define AO_RN_CMD_PIN   AO_RN_P3_7_PIN
87
88 #define AO_RN_CMD_CMD   0
89 #define AO_RN_CMD_DATA  1
90
91 /* This pin indicates BT connection status */
92 #define AO_RN_CONNECTED_PORT    AO_RN_P1_5_PORT
93 #define AO_RN_CONNECTED_PIN     AO_RN_P1_5_PIN
94
95 void
96 ao_rn4678_init(void);
97
98 #endif /* _AO_RN_H_ */