1 /*! 2 * \file spi-board.h 3 * 4 * \brief SPI driver implementation 5 * 6 * \copyright Revised BSD License, see section \ref LICENSE. 7 * 8 * \code 9 * ______ _ 10 * / _____) _ | | 11 * ( (____ _____ ____ _| |_ _____ ____| |__ 12 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 13 * _____) ) ____| | | || |_| ____( (___| | | | 14 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 15 * (C)2013-2017 Semtech 16 * 17 * \endcode 18 * 19 * \author Miguel Luis ( Semtech ) 20 * 21 * \author Gregory Cristian ( Semtech ) 22 */ 23 #ifndef __SPI_H__ 24 #define __SPI_H__ 25 26 #ifdef __cplusplus 27 extern "C" 28 { 29 #endif 30 31 #include "gpio.h" 32 33 /*! 34 * SPI peripheral ID 35 */ 36 typedef enum 37 { 38 SPI_1, 39 SPI_2, 40 }SpiId_t; 41 42 /*! 43 * SPI object type definition 44 */ 45 typedef struct Spi_s 46 { 47 SpiId_t SpiId; 48 Gpio_t Mosi; 49 Gpio_t Miso; 50 Gpio_t Sclk; 51 Gpio_t Nss; 52 }Spi_t; 53 54 /*! 55 * \brief Initializes the SPI object and MCU peripheral 56 * 57 * \remark When NSS pin is software controlled set the pin name to NC otherwise 58 * set the pin name to be used. 59 * 60 * \param [IN] obj SPI object 61 * \param [IN] mosi SPI MOSI pin name to be used 62 * \param [IN] miso SPI MISO pin name to be used 63 * \param [IN] sclk SPI SCLK pin name to be used 64 * \param [IN] nss SPI NSS pin name to be used 65 */ 66 void SpiInit( Spi_t *obj, SpiId_t spiId, PinNames mosi, PinNames miso, PinNames sclk, PinNames nss ); 67 68 /*! 69 * \brief De-initializes the SPI object and MCU peripheral 70 * 71 * \param [IN] obj SPI object 72 */ 73 void SpiDeInit( Spi_t *obj ); 74 75 /*! 76 * \brief Configures the SPI peripheral 77 * 78 * \remark Slave mode isn't currently handled 79 * 80 * \param [IN] obj SPI object 81 * \param [IN] bits Number of bits to be used. [8 or 16] 82 * \param [IN] cpol Clock polarity 83 * \param [IN] cpha Clock phase 84 * \param [IN] slave When set the peripheral acts in slave mode 85 */ 86 void SpiFormat( Spi_t *obj, int8_t bits, int8_t cpol, int8_t cpha, int8_t slave ); 87 88 /*! 89 * \brief Sets the SPI speed 90 * 91 * \param [IN] obj SPI object 92 * \param [IN] hz SPI clock frequency in hz 93 */ 94 void SpiFrequency( Spi_t *obj, uint32_t hz ); 95 96 /*! 97 * \brief Sends outData and receives inData 98 * 99 * \param [IN] obj SPI object 100 * \param [IN] outData Byte to be sent 101 * \retval inData Received byte. 102 */ 103 uint16_t SpiInOut( Spi_t *obj, uint16_t outData ); 104 105 #ifdef __cplusplus 106 } 107 #endif 108 109 #endif // __SPI_H__ 110