xref: /btstack/platform/embedded/hal_em9304_spi.h (revision 2fca4dad957cd7b88f4657ed51e89c12615dda72)
15e2dc9e8SMatthias Ringwald /*
2161a5569SMatthias Ringwald  * Copyright (C) 2017 BlueKitchen GmbH
35e2dc9e8SMatthias Ringwald  *
45e2dc9e8SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
55e2dc9e8SMatthias Ringwald  * modification, are permitted provided that the following conditions
65e2dc9e8SMatthias Ringwald  * are met:
75e2dc9e8SMatthias Ringwald  *
85e2dc9e8SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
95e2dc9e8SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
105e2dc9e8SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
115e2dc9e8SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
125e2dc9e8SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
135e2dc9e8SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
145e2dc9e8SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
155e2dc9e8SMatthias Ringwald  *    from this software without specific prior written permission.
165e2dc9e8SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
175e2dc9e8SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
185e2dc9e8SMatthias Ringwald  *    monetary gain.
195e2dc9e8SMatthias Ringwald  *
205e2dc9e8SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
215e2dc9e8SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
225e2dc9e8SMatthias 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,
255e2dc9e8SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
265e2dc9e8SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
275e2dc9e8SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
285e2dc9e8SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
295e2dc9e8SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
305e2dc9e8SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
315e2dc9e8SMatthias Ringwald  * SUCH DAMAGE.
325e2dc9e8SMatthias Ringwald  *
335e2dc9e8SMatthias Ringwald  * Please inquire about commercial licensing options at
345e2dc9e8SMatthias Ringwald  * [email protected]
355e2dc9e8SMatthias Ringwald  *
365e2dc9e8SMatthias Ringwald  */
375e2dc9e8SMatthias Ringwald 
385e2dc9e8SMatthias Ringwald /*
395e2dc9e8SMatthias Ringwald  *  hal_em9304_spi.h
405e2dc9e8SMatthias Ringwald  *
415e2dc9e8SMatthias Ringwald  *  Hardware Abstraction Layer for EM9304 connected via SPI with additional RDY Interrupt line
425e2dc9e8SMatthias Ringwald  *
435e2dc9e8SMatthias Ringwald  */
4480e33422SMatthias Ringwald #ifndef HAL_EM9304_SPI_H
4580e33422SMatthias Ringwald #define HAL_EM9304_SPI_H
465e2dc9e8SMatthias Ringwald 
475e2dc9e8SMatthias Ringwald #include <stdint.h>
485e2dc9e8SMatthias Ringwald 
495e2dc9e8SMatthias Ringwald #if defined __cplusplus
505e2dc9e8SMatthias Ringwald extern "C" {
515e2dc9e8SMatthias Ringwald #endif
525e2dc9e8SMatthias Ringwald 
535e2dc9e8SMatthias Ringwald /* API_START */
545e2dc9e8SMatthias Ringwald 
555e2dc9e8SMatthias Ringwald /**
565e2dc9e8SMatthias Ringwald  * @brief Initialize SPI
575e2dc9e8SMatthias Ringwald  */
585e2dc9e8SMatthias Ringwald void hal_em9304_spi_init(void);
595e2dc9e8SMatthias Ringwald 
605e2dc9e8SMatthias Ringwald /**
61161a5569SMatthias Ringwald  * @brief Deinitialize SPI
62161a5569SMatthias Ringwald  */
63161a5569SMatthias Ringwald void hal_em9304_spi_deinit(void);
64161a5569SMatthias Ringwald 
65161a5569SMatthias Ringwald /**
665e2dc9e8SMatthias Ringwald  * @brief Set callback for RDY - can be called from ISR context
675e2dc9e8SMatthias Ringwald  * @param callback
685e2dc9e8SMatthias Ringwald  */
695e2dc9e8SMatthias Ringwald void hal_em9304_spi_set_ready_callback(void (*callback)(void));
705e2dc9e8SMatthias Ringwald 
715e2dc9e8SMatthias Ringwald /**
725e2dc9e8SMatthias Ringwald  * @brief Set callback for transfer complete - can be called from ISR context
735e2dc9e8SMatthias Ringwald  * @param callback
745e2dc9e8SMatthias Ringwald  */
755e2dc9e8SMatthias Ringwald void hal_em9304_spi_set_transfer_done_callback(void (*callback)(void));
765e2dc9e8SMatthias Ringwald 
775e2dc9e8SMatthias Ringwald /**
785e2dc9e8SMatthias Ringwald  * @brief Enable READY IRQ
795e2dc9e8SMatthias Ringwald  */
805e2dc9e8SMatthias Ringwald void hal_em9304_spi_enable_ready_interrupt(void);
815e2dc9e8SMatthias Ringwald 
825e2dc9e8SMatthias Ringwald /**
835e2dc9e8SMatthias Ringwald  * @brief Disable READY IRQ
845e2dc9e8SMatthias Ringwald  */
855e2dc9e8SMatthias Ringwald void hal_em9304_spi_disable_ready_interrupt(void);
865e2dc9e8SMatthias Ringwald 
875e2dc9e8SMatthias Ringwald /**
885e2dc9e8SMatthias Ringwald  * @brief Poll READY state
895e2dc9e8SMatthias Ringwald  */
905e2dc9e8SMatthias Ringwald int hal_em9304_spi_get_ready();
915e2dc9e8SMatthias Ringwald 
925e2dc9e8SMatthias Ringwald /**
935e2dc9e8SMatthias Ringwald  * @brief Set Chip Selet
945e2dc9e8SMatthias Ringwald  * @param enable
955e2dc9e8SMatthias Ringwald  */
965e2dc9e8SMatthias Ringwald void hal_em9304_spi_set_chip_select(int enable);
975e2dc9e8SMatthias Ringwald 
985e2dc9e8SMatthias Ringwald /**
995e2dc9e8SMatthias Ringwald  * @brief Check if full duplex operation via hal_em9304_spi_transceive is supported
1005e2dc9e8SMatthias Ringwald  */
101161a5569SMatthias Ringwald int  hal_em9304_spi_get_fullduplex_support(void);
1025e2dc9e8SMatthias Ringwald 
1035e2dc9e8SMatthias Ringwald /**
1045e2dc9e8SMatthias Ringwald  * @brief Transmit and Receive bytes via SPI
1055e2dc9e8SMatthias Ringwald  * @param tx_data buffer to transmit
1065e2dc9e8SMatthias Ringwald  * @param rx_data buffer to receive into
1075e2dc9e8SMatthias Ringwald  * @param len
1085e2dc9e8SMatthias Ringwald  */
1095e2dc9e8SMatthias Ringwald void hal_em9304_spi_transceive(const uint8_t * tx_data, uint8_t * rx_data, uint16_t len);
1105e2dc9e8SMatthias Ringwald 
1115e2dc9e8SMatthias Ringwald /**
1125e2dc9e8SMatthias Ringwald  * @brief Transmit bytes via SPI
1135e2dc9e8SMatthias Ringwald  * @param tx_data buffer to transmit
1145e2dc9e8SMatthias Ringwald  * @param len
1155e2dc9e8SMatthias Ringwald  */
1165e2dc9e8SMatthias Ringwald void hal_em9304_spi_transmit(const uint8_t * tx_data, uint16_t len);
1175e2dc9e8SMatthias Ringwald 
1185e2dc9e8SMatthias Ringwald /**
1195e2dc9e8SMatthias Ringwald  * @brief Receive bytes via SPI
1205e2dc9e8SMatthias Ringwald  * @param rx_data buffer to receive into
1215e2dc9e8SMatthias Ringwald  * @param len
1225e2dc9e8SMatthias Ringwald  */
1235e2dc9e8SMatthias Ringwald void hal_em9304_spi_receive(uint8_t * rx_data, uint16_t len);
1245e2dc9e8SMatthias Ringwald 
1255e2dc9e8SMatthias Ringwald /* API_END */
1265e2dc9e8SMatthias Ringwald 
1275e2dc9e8SMatthias Ringwald #if defined __cplusplus
1285e2dc9e8SMatthias Ringwald }
1295e2dc9e8SMatthias Ringwald #endif
1305e2dc9e8SMatthias Ringwald 
13180e33422SMatthias Ringwald #endif // HAL_EM9304_SPI_H
132