sx125x_com.c 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2019 Semtech
  8. Description:
  9. Functions used to handle LoRa concentrator SX1255/SX1257 radios.
  10. License: Revised BSD License, see LICENSE.TXT file include in the project
  11. */
  12. /* -------------------------------------------------------------------------- */
  13. /* --- DEPENDANCIES --------------------------------------------------------- */
  14. #include <stdint.h> /* C99 types */
  15. #include <stdio.h> /* printf fprintf */
  16. #include "sx125x_com.h"
  17. #include "sx125x_spi.h"
  18. /* -------------------------------------------------------------------------- */
  19. /* --- PRIVATE MACROS ------------------------------------------------------- */
  20. #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
  21. #if DEBUG_RAD == 1
  22. #define DEBUG_MSG(str) fprintf(stdout, str)
  23. #define DEBUG_PRINTF(fmt, args...) fprintf(stdout,"%s:%d: "fmt, __FUNCTION__, __LINE__, args)
  24. #define CHECK_NULL(a) if(a==NULL){fprintf(stderr,"%s:%d: ERROR: NULL POINTER AS ARGUMENT\n", __FUNCTION__, __LINE__);return -1;}
  25. #else
  26. #define DEBUG_MSG(str)
  27. #define DEBUG_PRINTF(fmt, args...)
  28. #define CHECK_NULL(a) if(a==NULL){return -1;}
  29. #endif
  30. /* -------------------------------------------------------------------------- */
  31. /* --- PRIVATE TYPES -------------------------------------------------------- */
  32. /* -------------------------------------------------------------------------- */
  33. /* --- PRIVATE CONSTANTS ---------------------------------------------------- */
  34. /* -------------------------------------------------------------------------- */
  35. /* --- PRIVATE VARIABLES ---------------------------------------------------- */
  36. /* -------------------------------------------------------------------------- */
  37. /* --- PRIVATE FUNCTIONS ---------------------------------------------------- */
  38. /* -------------------------------------------------------------------------- */
  39. /* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */
  40. int sx125x_com_r(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, uint8_t address, uint8_t *data) {
  41. int com_stat;
  42. /* Check input parameters */
  43. CHECK_NULL(com_target);
  44. CHECK_NULL(data);
  45. switch (com_type) {
  46. case LGW_COM_SPI:
  47. com_stat = sx125x_spi_r(com_target, spi_mux_target, address, data);
  48. break;
  49. case LGW_COM_USB:
  50. printf("ERROR: USB COM type is not supported for sx125x\n");
  51. return -1;
  52. default:
  53. printf("ERROR: wrong communication type (SHOULD NOT HAPPEN)\n");
  54. return -1;
  55. }
  56. return com_stat;
  57. }
  58. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  59. int sx125x_com_w(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, uint8_t address, uint8_t data) {
  60. int com_stat;
  61. /* Check input parameters */
  62. CHECK_NULL(com_target);
  63. switch (com_type) {
  64. case LGW_COM_SPI:
  65. com_stat = sx125x_spi_w(com_target, spi_mux_target, address, data);
  66. break;
  67. case LGW_COM_USB:
  68. printf("ERROR: USB COM type is not supported for sx125x\n");
  69. return -1;
  70. default:
  71. printf("ERROR: wrong communication type (SHOULD NOT HAPPEN)\n");
  72. return -1;
  73. }
  74. return com_stat;
  75. }
  76. /* --- EOF ------------------------------------------------------------------ */