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