Skip to content

Commit 17a1e33

Browse files
committed
Implemented a fixed size queue for delayed displaying of received packets
1 parent dee9b7c commit 17a1e33

File tree

5 files changed

+223
-100
lines changed

5 files changed

+223
-100
lines changed

lib/rapidfire_SPI/rapidFIRE_SPI.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "rapidFIRE_SPI.h"
55

66
rapidFIRE_SPI::rapidFIRE_SPI(int pin_SCK, int pin_DATA, int pin_SS, int freq) {
7-
assert(SPI_freq < RAPIDFIRE_SPI_MAX_CLOCK);
7+
assert(freq < RAPIDFIRE_SPI_MAX_CLOCK);
88

99
SPI_pin_SCK = pin_SCK;
1010
SPI_pin_DATA = pin_DATA;
@@ -68,23 +68,18 @@ RF_RESULT rapidFIRE_SPI::recvCommand(uint8_t *data, size_t len) {
6868

6969
recv_len = spi->transfer(0);
7070
recv_sum = spi->transfer(0);
71-
for (int i = 0; i < len; i++) {
71+
for (size_t i = 0; i < len; i++) {
7272
data[i] = spi->transfer(0);
7373
}
7474

7575
spi->end();
7676
spi->setHwCs(false);
7777

7878
byte csum = recv_len;
79-
for (int i = 0; i < len; ++i) {
80-
// Serial.printf("Read[%d]:0x%02x(%3d) '\%c'\n", i, data[i], data[i],
81-
// data[i]);
79+
for (size_t i = 0; i < len; ++i) {
8280
csum += data[i];
8381
}
8482

85-
Serial.printf("CSUM:recv:%02x==calc:%02x LEN:recv:%d==%d %s\n", recv_sum,
86-
csum, recv_len, len, recv_sum == csum ? "" : "NG!");
87-
8883
if (recv_sum != csum) {
8984
// return RF_RESULT_ERROR_CHECKSUM_MISSMATCH; // Checksum missmatch.
9085
}
@@ -104,6 +99,7 @@ RF_RESULT rapidFIRE_SPI::sendCommand(uint16_t command, byte *data, size_t len) {
10499
spi->begin();
105100
spi->pins(SPI_pin_SCK, SPI_pin_DATA, -1, SPI_pin_SS);
106101
#endif
102+
107103
spi->setFrequency(SPI_freq);
108104
spi->setDataMode(SPI_MODE0);
109105
spi->setBitOrder(MSBFIRST);
@@ -117,14 +113,6 @@ RF_RESULT rapidFIRE_SPI::sendCommand(uint16_t command, byte *data, size_t len) {
117113

118114
spi->setHwCs(false);
119115

120-
#if 0
121-
Serial.printf("sendCommand: '%c'(%02x) '%c'(%02x) LEN:%d SUM:%02x DATA:[", command>>8, command>>8, command&0xff, command&0xff, len, csum);
122-
for (int i = 0; i < len; ++i)
123-
{
124-
Serial.printf(" %02x", data[i]);
125-
}
126-
Serial.printf("]\n");
127-
#endif
128116
return RF_RESULT_OK;
129117
}
130118

lib/rapidfire_SPI/rapidFIRE_SPI.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class rapidFIRE_SPI {
3636
int SPI_pin_SCK = -1;
3737
int SPI_pin_DATA = -1;
3838
int SPI_pin_SS = -1;
39-
int SPI_freq;
39+
int SPI_freq = -1;
4040

4141
SPIClass *spi = NULL;
4242

@@ -71,7 +71,8 @@ class rapidFIRE_SPI {
7171
};
7272
enum RAPIDFIREMODE {
7373
RAPIDFIRE_1 = 0x00, // - RapidFIRE #1
74-
RAPIDFIRE_2 = 0x01, // - RapidFIRE #2
74+
RAPIDFIRE_2 = 0x01, // - RapidFIRE #2 # Seems to have compatibility issues
75+
// with OSD UserText
7576
LEGACY = 0x02, // - Legacy
7677
};
7778

lib/rapidfire_SPI/rapidFIRE_SPI_Protocol.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
#pragma once
77

8-
// The CS1, CS2, CS3 pins are used as the SPI interface. These are normally used as a 3-bit
9-
// binary interface to communicate the goggle selected channel to the module.
10-
// The SPI interface is configured so that the module is the slave (allowing several modules to
11-
// be connected to the same bus), with CPOL = 0, CPHA = 0, MSB first.
12-
// The speed should be limited to a clock rate of about 80kHz.
8+
// The CS1, CS2, CS3 pins are used as the SPI interface. These are normally used
9+
// as a 3-bit binary interface to communicate the goggle selected channel to the
10+
// module. The SPI interface is configured so that the module is the slave
11+
// (allowing several modules to be connected to the same bus), with CPOL = 0,
12+
// CPHA = 0, MSB first. The speed should be limited to a clock rate of about
13+
// 80kHz.
1314

1415
#define RAPIDFIRE_SPI_CS1 1
1516
#define RAPIDFIRE_SPI_CS2 2
@@ -18,20 +19,24 @@
1819
#define RAPIDFIRE_SPI_CPOL 0
1920
#define RAPIDFIRE_SPI_CPHA 0
2021

21-
#define RAPIDFIRE_SPI_BIT (SPI_MSBFIRST)
22+
#define RAPIDFIRE_SPI_BIT SPI_MSBFIRST
2223

23-
#define RAPIDFIRE_SPI_MAX_CLOCK (80000) // 80kHz
24+
#define RAPIDFIRE_SPI_MAX_CLOCK 80000 // 80kHz
2425

2526
#define RAPIDFIRE_SPI_MODE_ENABLE_DELAY 100 // ms
2627

28+
#define RAPIDFIRE_MAX_LENGTH_TEXT \
29+
25 // max length of text to display on rapidfire osd
30+
2731
// SPI Protocol
2832
// ------------
2933
//
3034
// Command Heade
3135
//
3236
// | cmd | dir | len | csum | data0 | ... | |
3337
//
34-
// Where Csum is computed as the 8 - bit checksum of all header bytes, Cmd, Dir, Len, and all(optional) data bytes.
38+
// Where Csum is computed as the 8 - bit checksum of all header bytes, Cmd, Dir,
39+
// Len, and all(optional) data bytes.
3540
//
3641
// Query Header
3742
// | len | csum | data0 | ... | |
@@ -43,9 +48,10 @@
4348
#define RAPIDFIRE_CMD(Cmd, Dir) (Cmd << 8 | Dir)
4449

4550
// Query
46-
#define RAPIDFIRE_CMD_FIRMWARE_VERSION RAPIDFIRE_CMD('F', '?') // - Firmware Version, Query
47-
#define RAPIDFIRE_CMD_VOLTAGE RAPIDFIRE_CMD('V', '?') // - Voltage, Query
48-
#define RAPIDFIRE_CMD_RSSI RAPIDFIRE_CMD('R', '?') // - RSSI, Query
51+
#define RAPIDFIRE_CMD_FIRMWARE_VERSION \
52+
RAPIDFIRE_CMD('F', '?') // - Firmware Version, Query
53+
#define RAPIDFIRE_CMD_VOLTAGE RAPIDFIRE_CMD('V', '?') // - Voltage, Query
54+
#define RAPIDFIRE_CMD_RSSI RAPIDFIRE_CMD('R', '?') // - RSSI, Query
4955

5056
// Action
5157
#define RAPIDFIRE_CMD_SOUND_BUZZER RAPIDFIRE_CMD('S', '>') // - Buzzer
@@ -57,4 +63,3 @@
5763
#define RAPIDFIRE_CMD_SET_CHANNEL RAPIDFIRE_CMD('C', '=')
5864
#define RAPIDFIRE_CMD_SET_BAND RAPIDFIRE_CMD('B', '=')
5965
#define RAPIDFIRE_CMD_SET_RAPIDFIRE_MODE RAPIDFIRE_CMD('D', '=')
60-

0 commit comments

Comments
 (0)