Merge pull request #1269 from pkendall64/crsf-max-output
[ExpressLRS.git] / src / lib / FHSS / FHSS.h
blob3aea3a45bf093ce758738006ccb88e58981cac5a
1 #pragma once
3 #include "targets.h"
5 #if defined(Regulatory_Domain_AU_915) || defined(Regulatory_Domain_EU_868) || defined(Regulatory_Domain_IN_866) || defined(Regulatory_Domain_FCC_915) || defined(Regulatory_Domain_AU_433) || defined(Regulatory_Domain_EU_433)
6 #include "SX127xDriver.h"
7 #elif Regulatory_Domain_ISM_2400
8 #include "SX1280Driver.h"
9 #endif
11 #include "random.h"
13 #ifdef Regulatory_Domain_AU_915
14 #define Regulatory_Domain_Index 1
15 #elif defined Regulatory_Domain_FCC_915
16 #define Regulatory_Domain_Index 2
17 #elif defined Regulatory_Domain_EU_868
18 #define Regulatory_Domain_Index 3
19 #elif defined Regulatory_Domain_AU_433
20 #define Regulatory_Domain_Index 4
21 #elif defined Regulatory_Domain_EU_433
22 #define Regulatory_Domain_Index 5
23 #elif defined Regulatory_Domain_ISM_2400
24 #define Regulatory_Domain_Index 6
25 #elif defined Regulatory_Domain_IN_866
26 #define Regulatory_Domain_Index 7
27 #else
28 #define Regulatory_Domain_Index 8
29 #endif
31 #define FreqCorrectionMax ((int32_t)(100000/FREQ_STEP))
32 #define FreqCorrectionMin ((int32_t)(-100000/FREQ_STEP))
34 #define FREQ_HZ_TO_REG_VAL(freq) ((uint32_t)((double)freq/(double)FREQ_STEP))
36 extern volatile uint8_t FHSSptr;
37 extern int32_t FreqCorrection;
38 extern uint8_t FHSSsequence[];
39 extern const uint32_t FHSSfreqs[];
40 extern uint_fast8_t sync_channel;
41 extern const uint8_t FHSS_SEQUENCE_CNT;
43 // create and randomise an FHSS sequence
44 void FHSSrandomiseFHSSsequence(uint32_t seed);
45 // The number of frequencies for this regulatory domain
46 uint32_t FHSSgetChannelCount(void);
48 // get the initial frequency, which is also the sync channel
49 static inline uint32_t GetInitialFreq()
51 return FHSSfreqs[sync_channel] - FreqCorrection;
54 // Get the current sequence pointer
55 static inline uint8_t FHSSgetCurrIndex()
57 return FHSSptr;
60 // Set the sequence pointer, used by RX on SYNC
61 static inline void FHSSsetCurrIndex(const uint8_t value)
63 FHSSptr = value % FHSS_SEQUENCE_CNT;
66 // Advance the pointer to the next hop and return the frequency of that channel
67 static inline uint32_t FHSSgetNextFreq()
69 FHSSptr = (FHSSptr + 1) % FHSS_SEQUENCE_CNT;
70 uint32_t freq = FHSSfreqs[FHSSsequence[FHSSptr]] - FreqCorrection;
71 return freq;
74 // get the number of entries in the FHSS sequence
75 static inline uint8_t FHSSgetSequenceCount()
77 return FHSS_SEQUENCE_CNT;