xref: /btstack/chipset/em9301/btstack_chipset_em9301.c (revision ab2c6ae4b737d5e801d3defe4117331eb244ebb7)
1faa6c1f6SMatthias Ringwald /*
2faa6c1f6SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3faa6c1f6SMatthias Ringwald  *
4faa6c1f6SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5faa6c1f6SMatthias Ringwald  * modification, are permitted provided that the following conditions
6faa6c1f6SMatthias Ringwald  * are met:
7faa6c1f6SMatthias Ringwald  *
8faa6c1f6SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9faa6c1f6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10faa6c1f6SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11faa6c1f6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12faa6c1f6SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13faa6c1f6SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14faa6c1f6SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15faa6c1f6SMatthias Ringwald  *    from this software without specific prior written permission.
16faa6c1f6SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17faa6c1f6SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18faa6c1f6SMatthias Ringwald  *    monetary gain.
19faa6c1f6SMatthias Ringwald  *
20faa6c1f6SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21faa6c1f6SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22faa6c1f6SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23faa6c1f6SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24faa6c1f6SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25faa6c1f6SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26faa6c1f6SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27faa6c1f6SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28faa6c1f6SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29faa6c1f6SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30faa6c1f6SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31faa6c1f6SMatthias Ringwald  * SUCH DAMAGE.
32faa6c1f6SMatthias Ringwald  *
33faa6c1f6SMatthias Ringwald  * Please inquire about commercial licensing options at
34faa6c1f6SMatthias Ringwald  * [email protected]
35faa6c1f6SMatthias Ringwald  *
36faa6c1f6SMatthias Ringwald  */
37faa6c1f6SMatthias Ringwald 
38*ab2c6ae4SMatthias Ringwald #define __BTSTACK_FILE__ "btstack_chipset_em9301.c"
39*ab2c6ae4SMatthias Ringwald 
40faa6c1f6SMatthias Ringwald /*
41fb55bd0aSMatthias Ringwald  *  btstack_chipset_em9301.c
42faa6c1f6SMatthias Ringwald  *
43faa6c1f6SMatthias Ringwald  *  Adapter to use em9301-based chipsets with BTstack
44faa6c1f6SMatthias Ringwald  *
45faa6c1f6SMatthias Ringwald  *  Allows to set public BD ADDR
46faa6c1f6SMatthias Ringwald  */
47faa6c1f6SMatthias Ringwald 
48faa6c1f6SMatthias Ringwald #include "btstack_config.h"
49fb55bd0aSMatthias Ringwald #include "btstack_chipset_em9301.h"
50faa6c1f6SMatthias Ringwald 
51faa6c1f6SMatthias Ringwald #include <stddef.h>   /* NULL */
52faa6c1f6SMatthias Ringwald #include <stdio.h>
53faa6c1f6SMatthias Ringwald #include <string.h>   /* memcpy */
54faa6c1f6SMatthias Ringwald #include "hci.h"
55faa6c1f6SMatthias Ringwald 
56faa6c1f6SMatthias Ringwald // should go to some common place
57faa6c1f6SMatthias Ringwald #define OPCODE(ogf, ocf) (ocf | ogf << 10)
58faa6c1f6SMatthias Ringwald 
59faa6c1f6SMatthias Ringwald 
60faa6c1f6SMatthias Ringwald static void chipset_set_bd_addr_command(bd_addr_t addr, uint8_t *hci_cmd_buffer){
61f8fbdce0SMatthias Ringwald     little_endian_store_16(hci_cmd_buffer, 0, OPCODE(OGF_VENDOR, 0x02));
62faa6c1f6SMatthias Ringwald     hci_cmd_buffer[2] = 0x06;
63a47028edSMatthias Ringwald     reverse_bd_addr(addr, &hci_cmd_buffer[3]);
64faa6c1f6SMatthias Ringwald }
65faa6c1f6SMatthias Ringwald 
66faa6c1f6SMatthias Ringwald static const btstack_chipset_t btstack_chipset_em9301 = {
67faa6c1f6SMatthias Ringwald     "EM9301",
68faa6c1f6SMatthias Ringwald     NULL, // chipset_init not used
69faa6c1f6SMatthias Ringwald     NULL, // chipset_next_command not used
70faa6c1f6SMatthias Ringwald     NULL, // chipset_set_baudrate_command not needed as we're connected via SPI
71faa6c1f6SMatthias Ringwald     chipset_set_bd_addr_command,
72faa6c1f6SMatthias Ringwald };
73faa6c1f6SMatthias Ringwald 
74faa6c1f6SMatthias Ringwald // MARK: public API
75faa6c1f6SMatthias Ringwald const btstack_chipset_t * btstack_chipset_em9301_instance(void){
76faa6c1f6SMatthias Ringwald     return &btstack_chipset_em9301;
77faa6c1f6SMatthias Ringwald }
78