xref: /btstack/src/btstack_em9304_spi.h (revision 161a556908bc40ab3ce9e008590628b4a7c5b114)
1*161a5569SMatthias Ringwald /*
2*161a5569SMatthias Ringwald  * Copyright (C) 2017 BlueKitchen GmbH
3*161a5569SMatthias Ringwald  *
4*161a5569SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5*161a5569SMatthias Ringwald  * modification, are permitted provided that the following conditions
6*161a5569SMatthias Ringwald  * are met:
7*161a5569SMatthias Ringwald  *
8*161a5569SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9*161a5569SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10*161a5569SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*161a5569SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*161a5569SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13*161a5569SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*161a5569SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15*161a5569SMatthias Ringwald  *    from this software without specific prior written permission.
16*161a5569SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17*161a5569SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18*161a5569SMatthias Ringwald  *    monetary gain.
19*161a5569SMatthias Ringwald  *
20*161a5569SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21*161a5569SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*161a5569SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*161a5569SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24*161a5569SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*161a5569SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*161a5569SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27*161a5569SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*161a5569SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*161a5569SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30*161a5569SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*161a5569SMatthias Ringwald  * SUCH DAMAGE.
32*161a5569SMatthias Ringwald  *
33*161a5569SMatthias Ringwald  * Please inquire about commercial licensing options at
34*161a5569SMatthias Ringwald  * [email protected]
35*161a5569SMatthias Ringwald  *
36*161a5569SMatthias Ringwald  */
37*161a5569SMatthias Ringwald 
38*161a5569SMatthias Ringwald /*
39*161a5569SMatthias Ringwald  *  btstack_em9304_spi.h
40*161a5569SMatthias Ringwald  *
41*161a5569SMatthias Ringwald  *  BTstack's Hardware Abstraction Layer for EM9304 connected via SPI with additional RDY Interrupt line
42*161a5569SMatthias Ringwald 
43*161a5569SMatthias Ringwald  */
44*161a5569SMatthias Ringwald #ifndef __BTSTACK_EM9304_SPI_H
45*161a5569SMatthias Ringwald #define __BTSTACK_EM9304_SPI_H
46*161a5569SMatthias Ringwald 
47*161a5569SMatthias Ringwald #include <stdint.h>
48*161a5569SMatthias Ringwald 
49*161a5569SMatthias Ringwald #if defined __cplusplus
50*161a5569SMatthias Ringwald extern "C" {
51*161a5569SMatthias Ringwald #endif
52*161a5569SMatthias Ringwald 
53*161a5569SMatthias Ringwald /* API_START */
54*161a5569SMatthias Ringwald 
55*161a5569SMatthias Ringwald #include <stdint.h>
56*161a5569SMatthias Ringwald typedef struct {
57*161a5569SMatthias Ringwald 
58*161a5569SMatthias Ringwald     /* API_START */
59*161a5569SMatthias Ringwald 
60*161a5569SMatthias Ringwald     /**
61*161a5569SMatthias Ringwald      * @brief Open SPI
62*161a5569SMatthias Ringwald      */
63*161a5569SMatthias Ringwald     int (*open)(void);
64*161a5569SMatthias Ringwald 
65*161a5569SMatthias Ringwald     /**
66*161a5569SMatthias Ringwald      * @brief Close SPI
67*161a5569SMatthias Ringwald      */
68*161a5569SMatthias Ringwald     int (*close)(void);
69*161a5569SMatthias Ringwald 
70*161a5569SMatthias Ringwald     /**
71*161a5569SMatthias Ringwald      * @brief Check if full duplex operation via transceive is supported
72*161a5569SMatthias Ringwald      * @return 1 if supported
73*161a5569SMatthias Ringwald      */
74*161a5569SMatthias Ringwald     int  (*get_fullduplex_support)(void);
75*161a5569SMatthias Ringwald 
76*161a5569SMatthias Ringwald     /**
77*161a5569SMatthias Ringwald      * @brief Set callback for RDY
78*161a5569SMatthias Ringwald      * @param callback or NULL to disable callback
79*161a5569SMatthias Ringwald      */
80*161a5569SMatthias Ringwald     void (*set_ready_callback)(void (*callback)(void));
81*161a5569SMatthias Ringwald 
82*161a5569SMatthias Ringwald     /**
83*161a5569SMatthias Ringwald      * @brief Set callback for transfer complete
84*161a5569SMatthias Ringwald      * @param callback
85*161a5569SMatthias Ringwald      */
86*161a5569SMatthias Ringwald     void (*set_transfer_done_callback)(void (*callback)(void));
87*161a5569SMatthias Ringwald 
88*161a5569SMatthias Ringwald     /**
89*161a5569SMatthias Ringwald      * @brief Set Chip Selet
90*161a5569SMatthias Ringwald      * @param enable
91*161a5569SMatthias Ringwald      */
92*161a5569SMatthias Ringwald     void (*set_chip_select)(int enable);
93*161a5569SMatthias Ringwald 
94*161a5569SMatthias Ringwald     /**
95*161a5569SMatthias Ringwald      * @brief Poll READY state
96*161a5569SMatthias Ringwald      */
97*161a5569SMatthias Ringwald     int (*get_ready)();
98*161a5569SMatthias Ringwald 
99*161a5569SMatthias Ringwald     /**
100*161a5569SMatthias Ringwald      * @brief Transmit and Receive bytes via SPI
101*161a5569SMatthias Ringwald      * @param tx_data buffer to transmit
102*161a5569SMatthias Ringwald      * @param rx_data buffer to receive into
103*161a5569SMatthias Ringwald      * @param len
104*161a5569SMatthias Ringwald      */
105*161a5569SMatthias Ringwald     void (*transceive)(const uint8_t * tx_data, uint8_t * rx_data, uint16_t len);
106*161a5569SMatthias Ringwald 
107*161a5569SMatthias Ringwald     /**
108*161a5569SMatthias Ringwald      * @brief Transmit bytes via SPI
109*161a5569SMatthias Ringwald      * @param tx_data buffer to transmit
110*161a5569SMatthias Ringwald      * @param len
111*161a5569SMatthias Ringwald      */
112*161a5569SMatthias Ringwald     void (*transmit)(const uint8_t * tx_data, uint16_t len);
113*161a5569SMatthias Ringwald 
114*161a5569SMatthias Ringwald     /**
115*161a5569SMatthias Ringwald      * @brief Receive bytes via SPI
116*161a5569SMatthias Ringwald      * @param rx_data buffer to receive into
117*161a5569SMatthias Ringwald      * @param len
118*161a5569SMatthias Ringwald      */
119*161a5569SMatthias Ringwald     void (*receive)(uint8_t * rx_data, uint16_t len);
120*161a5569SMatthias Ringwald 
121*161a5569SMatthias Ringwald } btstack_em9304_spi_t;
122*161a5569SMatthias Ringwald 
123*161a5569SMatthias Ringwald /**
124*161a5569SMatthias Ringwald  *
125*161a5569SMatthias Ringwald  */
126*161a5569SMatthias Ringwald const btstack_em9304_spi_t * btstack_em9304_spi_embedded_instance(void);
127*161a5569SMatthias Ringwald 
128*161a5569SMatthias Ringwald #if defined __cplusplus
129*161a5569SMatthias Ringwald }
130*161a5569SMatthias Ringwald #endif
131*161a5569SMatthias Ringwald 
132*161a5569SMatthias Ringwald #endif // __BTSTACK_EM9304_SPI_H
133