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