xref: /btstack/src/btstack_em9304_spi.h (revision 80e33422a96c028b3a9c308fc4b9b874712dafb4)
1161a5569SMatthias Ringwald /*
2161a5569SMatthias Ringwald  * Copyright (C) 2017 BlueKitchen GmbH
3161a5569SMatthias Ringwald  *
4161a5569SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5161a5569SMatthias Ringwald  * modification, are permitted provided that the following conditions
6161a5569SMatthias Ringwald  * are met:
7161a5569SMatthias Ringwald  *
8161a5569SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9161a5569SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10161a5569SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11161a5569SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12161a5569SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13161a5569SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14161a5569SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15161a5569SMatthias Ringwald  *    from this software without specific prior written permission.
16161a5569SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17161a5569SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18161a5569SMatthias Ringwald  *    monetary gain.
19161a5569SMatthias Ringwald  *
20161a5569SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21161a5569SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22161a5569SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23161a5569SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24161a5569SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25161a5569SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26161a5569SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27161a5569SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28161a5569SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29161a5569SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30161a5569SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31161a5569SMatthias Ringwald  * SUCH DAMAGE.
32161a5569SMatthias Ringwald  *
33161a5569SMatthias Ringwald  * Please inquire about commercial licensing options at
34161a5569SMatthias Ringwald  * [email protected]
35161a5569SMatthias Ringwald  *
36161a5569SMatthias Ringwald  */
37161a5569SMatthias Ringwald 
38161a5569SMatthias Ringwald /*
39161a5569SMatthias Ringwald  *  btstack_em9304_spi.h
40161a5569SMatthias Ringwald  *
41161a5569SMatthias Ringwald  *  BTstack's Hardware Abstraction Layer for EM9304 connected via SPI with additional RDY Interrupt line
42161a5569SMatthias Ringwald 
43161a5569SMatthias Ringwald  */
44*80e33422SMatthias Ringwald #ifndef BTSTACK_EM9304_SPI_H
45*80e33422SMatthias Ringwald #define BTSTACK_EM9304_SPI_H
46161a5569SMatthias Ringwald 
47161a5569SMatthias Ringwald #include <stdint.h>
48161a5569SMatthias Ringwald 
49161a5569SMatthias Ringwald #if defined __cplusplus
50161a5569SMatthias Ringwald extern "C" {
51161a5569SMatthias Ringwald #endif
52161a5569SMatthias Ringwald 
53161a5569SMatthias Ringwald /* API_START */
54161a5569SMatthias Ringwald 
55161a5569SMatthias Ringwald #include <stdint.h>
56161a5569SMatthias Ringwald typedef struct {
57161a5569SMatthias Ringwald 
58161a5569SMatthias Ringwald     /* API_START */
59161a5569SMatthias Ringwald 
60161a5569SMatthias Ringwald     /**
61161a5569SMatthias Ringwald      * @brief Open SPI
62161a5569SMatthias Ringwald      */
63161a5569SMatthias Ringwald     int (*open)(void);
64161a5569SMatthias Ringwald 
65161a5569SMatthias Ringwald     /**
66161a5569SMatthias Ringwald      * @brief Close SPI
67161a5569SMatthias Ringwald      */
68161a5569SMatthias Ringwald     int (*close)(void);
69161a5569SMatthias Ringwald 
70161a5569SMatthias Ringwald     /**
71161a5569SMatthias Ringwald      * @brief Check if full duplex operation via transceive is supported
72161a5569SMatthias Ringwald      * @return 1 if supported
73161a5569SMatthias Ringwald      */
74161a5569SMatthias Ringwald     int  (*get_fullduplex_support)(void);
75161a5569SMatthias Ringwald 
76161a5569SMatthias Ringwald     /**
77161a5569SMatthias Ringwald      * @brief Set callback for RDY
78161a5569SMatthias Ringwald      * @param callback or NULL to disable callback
79161a5569SMatthias Ringwald      */
80161a5569SMatthias Ringwald     void (*set_ready_callback)(void (*callback)(void));
81161a5569SMatthias Ringwald 
82161a5569SMatthias Ringwald     /**
83161a5569SMatthias Ringwald      * @brief Set callback for transfer complete
84161a5569SMatthias Ringwald      * @param callback
85161a5569SMatthias Ringwald      */
86161a5569SMatthias Ringwald     void (*set_transfer_done_callback)(void (*callback)(void));
87161a5569SMatthias Ringwald 
88161a5569SMatthias Ringwald     /**
89161a5569SMatthias Ringwald      * @brief Set Chip Selet
90161a5569SMatthias Ringwald      * @param enable
91161a5569SMatthias Ringwald      */
92161a5569SMatthias Ringwald     void (*set_chip_select)(int enable);
93161a5569SMatthias Ringwald 
94161a5569SMatthias Ringwald     /**
95161a5569SMatthias Ringwald      * @brief Poll READY state
96161a5569SMatthias Ringwald      */
97bc5322e7SMatthias Ringwald     int (*get_ready)(void);
98161a5569SMatthias Ringwald 
99161a5569SMatthias Ringwald     /**
100161a5569SMatthias Ringwald      * @brief Transmit and Receive bytes via SPI
101161a5569SMatthias Ringwald      * @param tx_data buffer to transmit
102161a5569SMatthias Ringwald      * @param rx_data buffer to receive into
103161a5569SMatthias Ringwald      * @param len
104161a5569SMatthias Ringwald      */
105161a5569SMatthias Ringwald     void (*transceive)(const uint8_t * tx_data, uint8_t * rx_data, uint16_t len);
106161a5569SMatthias Ringwald 
107161a5569SMatthias Ringwald     /**
108161a5569SMatthias Ringwald      * @brief Transmit bytes via SPI
109161a5569SMatthias Ringwald      * @param tx_data buffer to transmit
110161a5569SMatthias Ringwald      * @param len
111161a5569SMatthias Ringwald      */
112161a5569SMatthias Ringwald     void (*transmit)(const uint8_t * tx_data, uint16_t len);
113161a5569SMatthias Ringwald 
114161a5569SMatthias Ringwald     /**
115161a5569SMatthias Ringwald      * @brief Receive bytes via SPI
116161a5569SMatthias Ringwald      * @param rx_data buffer to receive into
117161a5569SMatthias Ringwald      * @param len
118161a5569SMatthias Ringwald      */
119161a5569SMatthias Ringwald     void (*receive)(uint8_t * rx_data, uint16_t len);
120161a5569SMatthias Ringwald 
121161a5569SMatthias Ringwald } btstack_em9304_spi_t;
122161a5569SMatthias Ringwald 
123161a5569SMatthias Ringwald /**
124161a5569SMatthias Ringwald  *
125161a5569SMatthias Ringwald  */
126161a5569SMatthias Ringwald const btstack_em9304_spi_t * btstack_em9304_spi_embedded_instance(void);
127161a5569SMatthias Ringwald 
128161a5569SMatthias Ringwald #if defined __cplusplus
129161a5569SMatthias Ringwald }
130161a5569SMatthias Ringwald #endif
131161a5569SMatthias Ringwald 
132*80e33422SMatthias Ringwald #endif // BTSTACK_EM9304_SPI_H
133