xref: /btstack/src/btstack_em9304_spi.h (revision 2fca4dad957cd7b88f4657ed51e89c12615dda72)
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
23*2fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24*2fca4dadSMilanka Ringwald  * GMBH 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 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title EM9304 SPI
40161a5569SMatthias Ringwald  *
41fe5a6c4eSMilanka Ringwald  * BTstack's Hardware Abstraction Layer for EM9304 connected via SPI with additional RDY Interrupt line.
42fe5a6c4eSMilanka Ringwald  *
43161a5569SMatthias Ringwald  */
44fe5a6c4eSMilanka Ringwald 
4580e33422SMatthias Ringwald #ifndef BTSTACK_EM9304_SPI_H
4680e33422SMatthias Ringwald #define BTSTACK_EM9304_SPI_H
47161a5569SMatthias Ringwald 
48161a5569SMatthias Ringwald #include <stdint.h>
49161a5569SMatthias Ringwald 
50161a5569SMatthias Ringwald #if defined __cplusplus
51161a5569SMatthias Ringwald extern "C" {
52161a5569SMatthias Ringwald #endif
53161a5569SMatthias Ringwald 
54161a5569SMatthias Ringwald /* API_START */
55161a5569SMatthias Ringwald 
56161a5569SMatthias Ringwald #include <stdint.h>
57161a5569SMatthias Ringwald typedef struct {
58161a5569SMatthias Ringwald 
59161a5569SMatthias Ringwald     /**
60161a5569SMatthias Ringwald      * @brief Open SPI
61161a5569SMatthias Ringwald      */
62161a5569SMatthias Ringwald     int (*open)(void);
63161a5569SMatthias Ringwald 
64161a5569SMatthias Ringwald     /**
65161a5569SMatthias Ringwald      * @brief Close SPI
66161a5569SMatthias Ringwald      */
67161a5569SMatthias Ringwald     int (*close)(void);
68161a5569SMatthias Ringwald 
69161a5569SMatthias Ringwald     /**
70161a5569SMatthias Ringwald      * @brief Check if full duplex operation via transceive is supported
71161a5569SMatthias Ringwald      * @return 1 if supported
72161a5569SMatthias Ringwald      */
73161a5569SMatthias Ringwald     int  (*get_fullduplex_support)(void);
74161a5569SMatthias Ringwald 
75161a5569SMatthias Ringwald     /**
76161a5569SMatthias Ringwald      * @brief Set callback for RDY
77161a5569SMatthias Ringwald      * @param callback or NULL to disable callback
78161a5569SMatthias Ringwald      */
79161a5569SMatthias Ringwald     void (*set_ready_callback)(void (*callback)(void));
80161a5569SMatthias Ringwald 
81161a5569SMatthias Ringwald     /**
82161a5569SMatthias Ringwald      * @brief Set callback for transfer complete
83161a5569SMatthias Ringwald      * @param callback
84161a5569SMatthias Ringwald      */
85161a5569SMatthias Ringwald     void (*set_transfer_done_callback)(void (*callback)(void));
86161a5569SMatthias Ringwald 
87161a5569SMatthias Ringwald     /**
88161a5569SMatthias Ringwald      * @brief Set Chip Selet
89161a5569SMatthias Ringwald      * @param enable
90161a5569SMatthias Ringwald      */
91161a5569SMatthias Ringwald     void (*set_chip_select)(int enable);
92161a5569SMatthias Ringwald 
93161a5569SMatthias Ringwald     /**
94161a5569SMatthias Ringwald      * @brief Poll READY state
95161a5569SMatthias Ringwald      */
96bc5322e7SMatthias Ringwald     int (*get_ready)(void);
97161a5569SMatthias Ringwald 
98161a5569SMatthias Ringwald     /**
99161a5569SMatthias Ringwald      * @brief Transmit and Receive bytes via SPI
100161a5569SMatthias Ringwald      * @param tx_data buffer to transmit
101161a5569SMatthias Ringwald      * @param rx_data buffer to receive into
102161a5569SMatthias Ringwald      * @param len
103161a5569SMatthias Ringwald      */
104161a5569SMatthias Ringwald     void (*transceive)(const uint8_t * tx_data, uint8_t * rx_data, uint16_t len);
105161a5569SMatthias Ringwald 
106161a5569SMatthias Ringwald     /**
107161a5569SMatthias Ringwald      * @brief Transmit bytes via SPI
108161a5569SMatthias Ringwald      * @param tx_data buffer to transmit
109161a5569SMatthias Ringwald      * @param len
110161a5569SMatthias Ringwald      */
111161a5569SMatthias Ringwald     void (*transmit)(const uint8_t * tx_data, uint16_t len);
112161a5569SMatthias Ringwald 
113161a5569SMatthias Ringwald     /**
114161a5569SMatthias Ringwald      * @brief Receive bytes via SPI
115161a5569SMatthias Ringwald      * @param rx_data buffer to receive into
116161a5569SMatthias Ringwald      * @param len
117161a5569SMatthias Ringwald      */
118161a5569SMatthias Ringwald     void (*receive)(uint8_t * rx_data, uint16_t len);
119161a5569SMatthias Ringwald 
120161a5569SMatthias Ringwald } btstack_em9304_spi_t;
121161a5569SMatthias Ringwald 
122161a5569SMatthias Ringwald /**
123fe5a6c4eSMilanka Ringwald  * @brief Get EM9304 SPI instance
124161a5569SMatthias Ringwald  */
125161a5569SMatthias Ringwald const btstack_em9304_spi_t * btstack_em9304_spi_embedded_instance(void);
126161a5569SMatthias Ringwald 
127fe5a6c4eSMilanka Ringwald /* API_END */
128fe5a6c4eSMilanka Ringwald 
129161a5569SMatthias Ringwald #if defined __cplusplus
130161a5569SMatthias Ringwald }
131161a5569SMatthias Ringwald #endif
132161a5569SMatthias Ringwald 
13380e33422SMatthias Ringwald #endif // BTSTACK_EM9304_SPI_H
134