Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

110 lines
2.4 KiB

  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. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. #include "gpio.h"
  30. /*!
  31. * SPI peripheral ID
  32. */
  33. typedef enum
  34. {
  35. SPI_1,
  36. SPI_2,
  37. }SpiId_t;
  38. /*!
  39. * SPI object type definition
  40. */
  41. typedef struct Spi_s
  42. {
  43. SpiId_t SpiId;
  44. Gpio_t Mosi;
  45. Gpio_t Miso;
  46. Gpio_t Sclk;
  47. Gpio_t Nss;
  48. }Spi_t;
  49. /*!
  50. * \brief Initializes the SPI object and MCU peripheral
  51. *
  52. * \remark When NSS pin is software controlled set the pin name to NC otherwise
  53. * set the pin name to be used.
  54. *
  55. * \param [IN] obj SPI object
  56. * \param [IN] mosi SPI MOSI pin name to be used
  57. * \param [IN] miso SPI MISO pin name to be used
  58. * \param [IN] sclk SPI SCLK pin name to be used
  59. * \param [IN] nss SPI NSS pin name to be used
  60. */
  61. void SpiInit( Spi_t *obj, SpiId_t spiId, PinNames mosi, PinNames miso, PinNames sclk, PinNames nss );
  62. /*!
  63. * \brief De-initializes the SPI object and MCU peripheral
  64. *
  65. * \param [IN] obj SPI object
  66. */
  67. void SpiDeInit( Spi_t *obj );
  68. /*!
  69. * \brief Configures the SPI peripheral
  70. *
  71. * \remark Slave mode isn't currently handled
  72. *
  73. * \param [IN] obj SPI object
  74. * \param [IN] bits Number of bits to be used. [8 or 16]
  75. * \param [IN] cpol Clock polarity
  76. * \param [IN] cpha Clock phase
  77. * \param [IN] slave When set the peripheral acts in slave mode
  78. */
  79. void SpiFormat( Spi_t *obj, int8_t bits, int8_t cpol, int8_t cpha, int8_t slave );
  80. /*!
  81. * \brief Sets the SPI speed
  82. *
  83. * \param [IN] obj SPI object
  84. * \param [IN] hz SPI clock frequency in hz
  85. */
  86. void SpiFrequency( Spi_t *obj, uint32_t hz );
  87. /*!
  88. * \brief Sends outData and receives inData
  89. *
  90. * \param [IN] obj SPI object
  91. * \param [IN] outData Byte to be sent
  92. * \retval inData Received byte.
  93. */
  94. uint16_t SpiInOut( Spi_t *obj, uint16_t outData );
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif // __SPI_H__