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 23c0cdcfe7SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24c0cdcfe7SMatthias Ringwald * RINGWALD 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 38c0cdcfe7SMatthias Ringwald /* 39c0cdcfe7SMatthias Ringwald * btstack_chipset_tc3566x.c 40c0cdcfe7SMatthias Ringwald * 41c0cdcfe7SMatthias Ringwald * Adapter to use Toshiba TC3566x-based chipsets with BTstack 42c0cdcfe7SMatthias Ringwald * 43c0cdcfe7SMatthias Ringwald * Supports: 44c0cdcfe7SMatthias Ringwald * - Set BD ADDR 45c0cdcfe7SMatthias Ringwald * - Set baud rate 46c0cdcfe7SMatthias Ringwald */ 47c0cdcfe7SMatthias Ringwald 48c0cdcfe7SMatthias Ringwald #include "btstack_config.h" 49c0cdcfe7SMatthias Ringwald #include "btstack_chipset_tc3566x.h" 50c0cdcfe7SMatthias Ringwald 51c0cdcfe7SMatthias Ringwald #include <stddef.h> /* NULL */ 52c0cdcfe7SMatthias Ringwald #include <stdio.h> 53c0cdcfe7SMatthias Ringwald #include <string.h> /* memcpy */ 54c0cdcfe7SMatthias Ringwald #include "hci.h" 55c0cdcfe7SMatthias Ringwald #include "btstack_debug.h" 56c0cdcfe7SMatthias Ringwald 57c0cdcfe7SMatthias Ringwald // should go to some common place 58c0cdcfe7SMatthias Ringwald #define OPCODE(ogf, ocf) (ocf | ogf << 10) 59c0cdcfe7SMatthias Ringwald 60c0cdcfe7SMatthias 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}; 61c0cdcfe7SMatthias Ringwald 62c0cdcfe7SMatthias Ringwald static void chipset_set_baudrate_command(uint32_t baudrate, uint8_t *hci_cmd_buffer){ 63c0cdcfe7SMatthias Ringwald uint16_t div1 = 0; 64c0cdcfe7SMatthias Ringwald uint8_t div2 = 0; 65c0cdcfe7SMatthias Ringwald switch (baudrate) { 66c0cdcfe7SMatthias Ringwald case 115200: 67c0cdcfe7SMatthias Ringwald div1 = 0x001A; 68c0cdcfe7SMatthias Ringwald div2 = 0x60; 69c0cdcfe7SMatthias Ringwald break; 70c0cdcfe7SMatthias Ringwald case 230400: 71c0cdcfe7SMatthias Ringwald div1 = 0x000D; 72c0cdcfe7SMatthias Ringwald div2 = 0x60; 73c0cdcfe7SMatthias Ringwald break; 74c0cdcfe7SMatthias Ringwald case 460800: 75c0cdcfe7SMatthias Ringwald div1 = 0x0005; 76c0cdcfe7SMatthias Ringwald div2 = 0xA0; 77c0cdcfe7SMatthias Ringwald break; 78c0cdcfe7SMatthias Ringwald case 921600: 79c0cdcfe7SMatthias Ringwald div1 = 0x0003; 80c0cdcfe7SMatthias Ringwald div2 = 0x70; 81c0cdcfe7SMatthias Ringwald break; 82c0cdcfe7SMatthias Ringwald default: 83c0cdcfe7SMatthias Ringwald log_error("tc3566x_baudrate_cmd baudrate %u not supported", baudrate); 84c0cdcfe7SMatthias Ringwald return; 85c0cdcfe7SMatthias Ringwald } 86c0cdcfe7SMatthias Ringwald 87c0cdcfe7SMatthias Ringwald memcpy(hci_cmd_buffer, baudrate_command, sizeof(baudrate_command)); 88*f8fbdce0SMatthias Ringwald little_endian_store_16(hci_cmd_buffer, 13, div1); 89c0cdcfe7SMatthias Ringwald hci_cmd_buffer[15] = div2; 90c0cdcfe7SMatthias Ringwald } 91c0cdcfe7SMatthias Ringwald 92c0cdcfe7SMatthias Ringwald static void chipset_set_bd_addr_command(bd_addr_t addr, uint8_t *hci_cmd_buffer){ 93c0cdcfe7SMatthias Ringwald // OGF 0x04 - Informational Parameters, OCF 0x10 94c0cdcfe7SMatthias Ringwald hci_cmd_buffer[0] = 0x13; 95c0cdcfe7SMatthias Ringwald hci_cmd_buffer[1] = 0x10; 96c0cdcfe7SMatthias Ringwald hci_cmd_buffer[2] = 0x06; 97c0cdcfe7SMatthias Ringwald bt_flip_addr(&hci_cmd_buffer[3], addr); 98c0cdcfe7SMatthias Ringwald } 99c0cdcfe7SMatthias Ringwald 100c0cdcfe7SMatthias Ringwald static const btstack_chipset_t btstack_chipset_tc3566x = { 101c0cdcfe7SMatthias Ringwald "tc3566x", 102c0cdcfe7SMatthias Ringwald NULL, // chipset_init, 103c0cdcfe7SMatthias Ringwald NULL, // chipset_next_command, 104c0cdcfe7SMatthias Ringwald chipset_set_baudrate_command, 105c0cdcfe7SMatthias Ringwald chipset_set_bd_addr_command, 106c0cdcfe7SMatthias Ringwald }; 107c0cdcfe7SMatthias Ringwald 108c0cdcfe7SMatthias Ringwald // MARK: public API 109c0cdcfe7SMatthias Ringwald const btstack_chipset_t * btstack_chipset_tc3566x_instance(void){ 110c0cdcfe7SMatthias Ringwald return &btstack_chipset_tc3566x; 111c0cdcfe7SMatthias Ringwald } 112