loragw_sx125x.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #ifndef _LORAGW_SX125X_H
  13. #define _LORAGW_SX125X_H
  14. /* -------------------------------------------------------------------------- */
  15. /* --- DEPENDANCIES --------------------------------------------------------- */
  16. #include <stdint.h> /* C99 types */
  17. #include <stdbool.h> /* bool type */
  18. /* -------------------------------------------------------------------------- */
  19. /* --- INTERNAL SHARED TYPES ------------------------------------------------ */
  20. struct radio_reg_s
  21. {
  22. uint8_t addr; /* base address of the register */
  23. uint8_t offs; /* position of the register LSB (between 0 to 7) */
  24. uint8_t leng; /* number of bits in the register */
  25. };
  26. /* -------------------------------------------------------------------------- */
  27. /* --- PUBLIC MACROS -------------------------------------------------------- */
  28. #define SX1257_FREQ_TO_REG(f) (uint32_t)((uint64_t)f * (1 << 19) / 32000000U)
  29. #define SX1255_FREQ_TO_REG(f) (uint32_t)((uint64_t)f * (1 << 20) / 32000000U)
  30. /* -------------------------------------------------------------------------- */
  31. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  32. #define LGW_REG_SUCCESS 0
  33. #define LGW_REG_ERROR -1
  34. #define SX125x_32MHz_FRAC 15625 /* irreductible fraction for PLL register caculation */
  35. #define SX125x_TX_DAC_CLK_SEL 0 /* 0:int, 1:ext */
  36. #define SX125x_TX_DAC_GAIN 2 /* 3:0, 2:-3, 1:-6, 0:-9 dBFS (default 2) */
  37. #define SX125x_TX_MIX_GAIN 14 /* -38 + 2*TxMixGain dB (default 14) */
  38. #define SX125x_TX_PLL_BW 1 /* 0:75, 1:150, 2:225, 3:300 kHz (default 3) */
  39. #define SX125x_TX_ANA_BW 0 /* 17.5 / 2*(41-TxAnaBw) MHz (default 0) */
  40. #define SX125x_TX_DAC_BW 5 /* 24 + 8*TxDacBw Nb FIR taps (default 2) */
  41. #define SX125x_RX_LNA_GAIN 1 /* 1 to 6, 1 highest gain */
  42. #define SX125x_RX_BB_GAIN 15 /* 0 to 15 , 15 highest gain */
  43. #define SX125x_LNA_ZIN 0 /* 0:50, 1:200 Ohms (default 1) */
  44. #define SX125x_RX_ADC_BW 7 /* 0 to 7, 2:100<BW<200, 5:200<BW<400,7:400<BW kHz SSB (default 7) */
  45. #define SX125x_RX_ADC_TRIM 6 /* 0 to 7, 6 for 32MHz ref, 5 for 36MHz ref */
  46. #define SX125x_RX_BB_BW 0 /* 0:750, 1:500, 2:375; 3:250 kHz SSB (default 1, max 3) */
  47. #define SX125x_RX_PLL_BW 0 /* 0:75, 1:150, 2:225, 3:300 kHz (default 3, max 3) */
  48. #define SX125x_ADC_TEMP 0 /* ADC temperature measurement mode (default 0) */
  49. #define SX125x_XOSC_GM_STARTUP 13 /* (default 13) */
  50. #define SX125x_XOSC_DISABLE 2 /* Disable of Xtal Oscillator blocks bit0:regulator, bit1:core(gm), bit2:amplifier */
  51. typedef enum {
  52. SX125x_REG_MODE = 0,
  53. SX125x_REG_MODE__PA_DRIVER_EN = 1,
  54. SX125x_REG_MODE__TX_EN = 2,
  55. SX125x_REG_MODE__RX_EN = 3,
  56. SX125x_REG_MODE__STANDBY_EN = 4,
  57. SX125x_REG_FRF_RX_MSB = 5,
  58. SX125x_REG_FRF_RX_MID = 6,
  59. SX125x_REG_FRF_RX_LSB = 7,
  60. SX125x_REG_FRF_TX_MSB = 8,
  61. SX125x_REG_FRF_TX_MID = 9,
  62. SX125x_REG_FRF_TX_LSB = 10,
  63. SX125x_REG_VERSION = 11,
  64. SX125x_REG_TX_GAIN = 12,
  65. SX125x_REG_TX_GAIN__DAC_GAIN = 13,
  66. SX125x_REG_TX_GAIN__MIX_GAIN = 14,
  67. SX125x_REG_TX_BW = 15,
  68. SX125x_REG_TX_BW__PLL_BW = 16,
  69. SX125x_REG_TX_BW__ANA_BW = 17,
  70. SX125x_REG_TX_DAC_BW = 18,
  71. SX125x_REG_RX_ANA_GAIN = 19,
  72. SX125x_REG_RX_ANA_GAIN__LNA_GAIN = 20,
  73. SX125x_REG_RX_ANA_GAIN__BB_GAIN = 21,
  74. SX125x_REG_RX_ANA_GAIN__LNA_ZIN = 22,
  75. SX125x_REG_RX_BW = 23,
  76. SX125x_REG_RX_BW__ADC_BW = 24,
  77. SX125x_REG_RX_BW__ADC_TRIM = 25,
  78. SX125x_REG_RX_BW__BB_BW = 26,
  79. SX125x_REG_RX_PLL_BW = 27,
  80. SX125x_REG_RX_PLL_BW__PLL_BW = 28,
  81. SX125x_REG_RX_PLL_BW__ADC_TEMP_EN = 29,
  82. SX125x_REG_DIO_MAPPING = 30,
  83. SX125x_REG_DIO_MAPPING__DIO_0_MAPPING = 31,
  84. SX125x_REG_DIO_MAPPING__DIO_1_MAPPING = 32,
  85. SX125x_REG_DIO_MAPPING__DIO_2_MAPPING = 33,
  86. SX125x_REG_DIO_MAPPING__DIO_3_MAPPING = 34,
  87. SX125x_REG_CLK_SELECT = 35,
  88. SX125x_REG_CLK_SELECT__DIG_LOOPBACK_EN = 36,
  89. SX125x_REG_CLK_SELECT__RF_LOOPBACK_EN = 37,
  90. SX125x_REG_CLK_SELECT__CLK_OUT = 38,
  91. SX125x_REG_CLK_SELECT__DAC_CLK_SELECT = 39,
  92. SX125x_REG_MODE_STATUS = 40,
  93. SX125x_REG_MODE_STATUS__LOW_BAT_EN = 41,
  94. SX125x_REG_MODE_STATUS__RX_PLL_LOCKED = 42,
  95. SX125x_REG_MODE_STATUS__TX_PLL_LOCKED = 43,
  96. SX125x_REG_LOW_BAT_THRESH = 44,
  97. SX125x_REG_SX1257_XOSC_TEST = 45,
  98. SX125x_REG_SX1257_XOSC_TEST__DISABLE = 46,
  99. SX125x_REG_SX1257_XOSC_TEST__GM_STARTUP = 47,
  100. SX125x_REG_SX1255_XOSC_TEST = 48,
  101. SX125x_REG_SX1255_XOSC_TEST__DISABLE = 49,
  102. SX125x_REG_SX1255_XOSC_TEST__GM_STARTUP = 50
  103. }
  104. radio_reg_t;
  105. #define RADIO_TOTALREGS 51
  106. /* -------------------------------------------------------------------------- */
  107. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  108. /*
  109. SX1257 frequency setting :
  110. F_register(24bit) = F_rf (Hz) / F_step(Hz)
  111. = F_rf (Hz) * 2^19 / F_xtal(Hz)
  112. = F_rf (Hz) * 2^19 / 32e6
  113. = F_rf (Hz) * 256/15625
  114. SX1255 frequency setting :
  115. F_register(24bit) = F_rf (Hz) / F_step(Hz)
  116. = F_rf (Hz) * 2^20 / F_xtal(Hz)
  117. = F_rf (Hz) * 2^20 / 32e6
  118. = F_rf (Hz) * 512/15625
  119. */
  120. /* -------------------------------------------------------------------------- */
  121. /* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
  122. int sx125x_setup(uint8_t rf_chain, uint8_t rf_clkout, bool rf_enable, uint8_t rf_radio_type, uint32_t freq_hz);
  123. int sx125x_reg_w(radio_reg_t idx, uint8_t data, uint8_t rf_chain);
  124. int sx125x_reg_r(radio_reg_t idx, uint8_t *data, uint8_t rf_chain);
  125. #endif
  126. /* --- EOF ------------------------------------------------------------------ */