Skip to content

Commit be794a0

Browse files
committed
LP-585 Add comments + typo
1 parent 131a6b0 commit be794a0

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

flight/pios/common/pios_rfm22b.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -339,26 +339,26 @@ static const uint32_t data_rate[] = {
339339

340340
static const uint8_t channel_spacing[] = {
341341
1, /* 9.6kbps */
342-
2, /* 19.2kps */
343-
2, /* 32kps */
344-
2, /* 57.6kps */
345-
2, /* 64kps */
346-
3, /* 100kps */
347-
4, /* 128kps */
348-
4, /* 192kps */
349-
4, /* 256kps */
342+
2, /* 19.2kbps */
343+
2, /* 32kbps */
344+
2, /* 57.6kbps */
345+
2, /* 64kbps */
346+
3, /* 100kbps */
347+
4, /* 128kbps */
348+
4, /* 192kbps */
349+
4, /* 256kbps */
350350
};
351351

352352
static const uint8_t channel_limits[] = {
353353
1, /* 9.6kbps */
354-
1, /* 19.2kps */
355-
1, /* 32kps */
356-
1, /* 57.6kps */
357-
1, /* 64kps */
358-
1, /* 100kps */
359-
2, /* 128kps */
360-
2, /* 192kps */
361-
2, /* 256kps */
354+
1, /* 19.2kbps */
355+
1, /* 32kbps */
356+
1, /* 57.6kbps */
357+
1, /* 64kbps */
358+
1, /* 100kbps */
359+
2, /* 128kbps */
360+
2, /* 192kbps */
361+
2, /* 256kbps */
362362
};
363363

364364
static const uint8_t reg_1C[] = { 0x01, 0x05, 0x06, 0x95, 0x95, 0x81, 0x88, 0x8B, 0x8D }; // rfm22_if_filter_bandwidth
@@ -2681,11 +2681,16 @@ static void rfm22_hmac_sha1(const uint8_t *data, size_t len,
26812681
static bool rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint8_t min,
26822682
uint8_t max, uint8_t channels[MAX_CHANNELS], uint8_t *clen)
26832683
{
2684-
uint32_t data = 0;
2685-
uint8_t cpos = 0;
2684+
// Define first and last channel to be used within min/max values
2685+
// according to the frequency deviation, without up/down overflow.
26862686
uint8_t chan_min_limit = min + channel_limits[rate];
26872687
uint8_t chan_max_limit = max - channel_limits[rate];
2688+
2689+
// Define how many channels we can use according to the spacing.
26882690
uint8_t chan_count = ((chan_max_limit - chan_min_limit) / channel_spacing[rate]) + 1;
2691+
2692+
uint32_t data = 0;
2693+
uint8_t cpos = 0;
26892694
uint8_t key[SHA1_DIGEST_LENGTH] = { 0 };
26902695
uint8_t digest[SHA1_DIGEST_LENGTH];
26912696
uint8_t *all_channels;
@@ -2694,6 +2699,7 @@ static bool rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint
26942699

26952700
memcpy(key, &coordid, sizeof(coordid));
26962701

2702+
// Fill all_channels[] with usable channels
26972703
for (int i = 0; i < chan_count; i++) {
26982704
all_channels[i] = chan_min_limit + (i * channel_spacing[rate]);
26992705
}

0 commit comments

Comments
 (0)