1 /*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holders nor the names of
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * 4. Any redistribution, use, or modification is done solely for
17 * personal benefit and not for any commercial purpose or for
18 * monetary gain.
19 *
20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * Please inquire about commercial licensing options at
34 * [email protected]
35 *
36 */
37
38 #define BTSTACK_FILE__ "btstack_chipset_stlc2500d.c"
39
40 /*
41 * btstack_chipset_stlc2500d.c
42 *
43 * Adapter to use stlc2500d-based chipsets with BTstack
44 *
45 */
46
47 #include "btstack_config.h"
48 #include "btstack_chipset_stlc2500d.h"
49
50 #include <stddef.h> /* NULL */
51 #include <stdio.h>
52 #include <string.h> /* memcpy */
53 #include "hci.h"
54 #include "btstack_debug.h"
55
56 // should go to some common place
57 #define OPCODE(ogf, ocf) (ocf | ogf << 10)
58
chipset_set_baudrate_command(uint32_t baudrate,uint8_t * hci_cmd_buffer)59 static void chipset_set_baudrate_command(uint32_t baudrate, uint8_t *hci_cmd_buffer){
60 // map baud rate to predefined settings
61 int preset = 0;
62 switch (baudrate){
63 case 57600:
64 preset = 0x0e;
65 break;
66 case 115200:
67 preset = 0x10;
68 break;
69 case 230400:
70 preset = 0x12;
71 break;
72 case 460800:
73 preset = 0x13;
74 break;
75 case 921600:
76 preset = 0x14;
77 break;
78 case 1843200:
79 preset = 0x16;
80 break;
81 case 2000000:
82 preset = 0x19;
83 break;
84 case 3000000:
85 preset = 0x1b;
86 break;
87 case 4000000:
88 preset = 0x1f;
89 break;
90 default:
91 log_error("stlc2500d_baudrate_cmd baudrate %u not supported", baudrate);
92 return;
93 }
94 little_endian_store_16(hci_cmd_buffer, 0, OPCODE(OGF_VENDOR, 0xfc));
95 hci_cmd_buffer[2] = 0x01;
96 hci_cmd_buffer[3] = preset;
97 }
98
chipset_set_bd_addr_command(bd_addr_t addr,uint8_t * hci_cmd_buffer)99 static void chipset_set_bd_addr_command(bd_addr_t addr, uint8_t *hci_cmd_buffer){
100 little_endian_store_16(hci_cmd_buffer, 0, OPCODE(OGF_VENDOR, 0x22));
101 hci_cmd_buffer[2] = 0x08;
102 hci_cmd_buffer[3] = 254;
103 hci_cmd_buffer[4] = 0x06;
104 reverse_bd_addr(addr, &hci_cmd_buffer[5]);
105 }
106
107 static const btstack_chipset_t btstack_chipset_stlc2500d = {
108 "BCM",
109 NULL, // chipset_init,
110 NULL, // chipset_next_command,
111 chipset_set_baudrate_command,
112 chipset_set_bd_addr_command,
113 };
114
115 // MARK: public API
btstack_chipset_stlc2500d_instance(void)116 const btstack_chipset_t * btstack_chipset_stlc2500d_instance(void){
117 return &btstack_chipset_stlc2500d;
118 }
119