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