Merge with latest 2.3

This commit is contained in:
Bertrand Songis
2020-05-30 11:57:03 +02:00
240 changed files with 16050 additions and 14404 deletions
+116 -1
View File
@@ -24,6 +24,7 @@
/*
* Documentation of the Spektrum protocol is available under
* https://www.spektrumrc.com/ProdInfo/Files/SPM_Telemetry_Developers_Specs.pdf
* https://github.com/SpektrumRC/SpektrumDocumentation/blob/master/Telemetry/spektrumTelemetrySensors.h
*
* Multi module adds two byte header of 0xAA [RSSI of telemetry packet] [16 byte message]
*/
@@ -49,7 +50,18 @@
#define I2C_TEXTGEN 0x0c
#define I2C_GPS 0x17
#define I2C_GPS2 0x17
#define I2C_ESC 0x20
#define I2C_CELLS 0x3a
// SMART_BAT is using fake I2C adresses compared to official Spektrum address because of subtype used only for this I2C address
#define I2C_SMART_BAT_BASE_ADDRESS 0x42
#define I2C_SMART_BAT_REALTIME 0x42
#define I2C_SMART_BAT_CELLS_1_6 0x43
#define I2C_SMART_BAT_CELLS_7_12 0x44
#define I2C_SMART_BAT_CELLS_13_18 0x45
#define I2C_SMART_BAT_ID 0x4A
#define I2C_SMART_BAT_LIMITS 0x4B
#define I2C_QOS 0x7f
enum SpektrumDataType : uint8_t {
@@ -62,6 +74,8 @@ enum SpektrumDataType : uint8_t {
uint8bcd,
uint16bcd,
uint32bcd,
uint16le,
uint32le,
custom
};
@@ -151,7 +165,16 @@ const SpektrumSensor spektrumSensors[] = {
{0x1b, 2, int16, STR_SENSOR_PITCH, UNIT_DEGREE, 1},
{0x1b, 4, int16, STR_SENSOR_YAW, UNIT_DEGREE, 1},
// {0x20, esc}, does not exist in the wild?
// {0x20, esc}, Smart ESC telemetry
{I2C_ESC, 0, uint16, ZSTR_ESC_RPM, UNIT_RPMS, 0},
{I2C_ESC, 2, uint16, ZSTR_ESC_VIN, UNIT_VOLTS, 2},
{I2C_ESC, 4, uint16, ZSTR_ESC_TFET, UNIT_CELSIUS, 1},
{I2C_ESC, 6, uint16, ZSTR_ESC_CUR, UNIT_MAH, 1},
{I2C_ESC, 8, uint16, ZSTR_ESC_TBEC, UNIT_CELSIUS, 1},
{I2C_ESC, 10, uint8, ZSTR_ESC_BCUR, UNIT_AMPS, 1},
{I2C_ESC, 11, uint8, ZSTR_ESC_VBEC, UNIT_VOLTS, 2},
{I2C_ESC, 12, uint8, ZSTR_ESC_THR, UNIT_PERCENT, 1},
{I2C_ESC, 13, uint8, ZSTR_ESC_POUT, UNIT_PERCENT, 1},
// Dual Cell monitor (0x34)
{0x34, 0, int16, STR_SENSOR_BATT1_CURRENT, UNIT_AMPS, 1},
@@ -178,6 +201,53 @@ const SpektrumSensor spektrumSensors[] = {
{0x40, 0, int16, STR_SENSOR_ALT, UNIT_METERS, 1},
{0x40, 2, int16, STR_SENSOR_VSPD, UNIT_METERS_PER_SECOND, 1},
// Smartbat
//{I2C_SMART_BAT_REALTIME, 1, int8, ZSTR_SMART_BAT_BTMP, UNIT_CELSIUS, 0}, // disabled because sensor is a duplicate of cells sensors ones
{I2C_SMART_BAT_REALTIME, 2, uint32le, ZSTR_SMART_BAT_BCUR, UNIT_MAH, 0},
{I2C_SMART_BAT_REALTIME, 6, uint16le, ZSTR_SMART_BAT_BCAP, UNIT_MAH, 0},
{I2C_SMART_BAT_REALTIME, 8, uint16le, ZSTR_SMART_BAT_MIN_CEL, UNIT_VOLTS, 2},
{I2C_SMART_BAT_REALTIME, 10, uint16le, ZSTR_SMART_BAT_MAX_CEL, UNIT_VOLTS, 2},
//{I2C_SMART_BAT_REALTIME, 12, uint16le, "RFU[2]", UNIT_RAW, 0}, // disabled to save sensors slots
{I2C_SMART_BAT_CELLS_1_6, 1, int8, ZSTR_SMART_BAT_BTMP, UNIT_CELSIUS, 0},
{I2C_SMART_BAT_CELLS_1_6, 2, uint16le, ZSTR_CL01, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_1_6, 4, uint16le, ZSTR_CL02, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_1_6, 6, uint16le, ZSTR_CL03, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_1_6, 8, uint16le, ZSTR_CL04, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_1_6, 10, uint16le, ZSTR_CL05, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_1_6, 12, uint16le, ZSTR_CL06, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_7_12, 1, int8, ZSTR_SMART_BAT_BTMP, UNIT_CELSIUS, 0},
{I2C_SMART_BAT_CELLS_7_12, 2, uint16le, ZSTR_CL07, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_7_12, 4, uint16le, ZSTR_CL08, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_7_12, 6, uint16le, ZSTR_CL09, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_7_12, 8, uint16le, ZSTR_CL10, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_7_12, 10, uint16le, ZSTR_CL11, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_7_12, 12, uint16le, ZSTR_CL12, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_13_18, 1, int8, ZSTR_SMART_BAT_BTMP, UNIT_CELSIUS, 0},
{I2C_SMART_BAT_CELLS_13_18, 2, uint16le, ZSTR_CL13, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_13_18, 4, uint16le, ZSTR_CL14, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_13_18, 6, uint16le, ZSTR_CL15, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_13_18, 8, uint16le, ZSTR_CL16, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_13_18, 10, uint16le, ZSTR_CL17, UNIT_VOLTS, 2},
{I2C_SMART_BAT_CELLS_13_18, 12, uint16le, ZSTR_CL18, UNIT_VOLTS, 2},
//{I2C_SMART_BAT_ID, 1, uint8, "chemistery", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_ID, 2, uint8, "number of cells", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_ID, 3, uint8, "manufacturer code", UNIT_RAW, 0}, // disabled to save sensors slots
{I2C_SMART_BAT_ID, 4, uint16le, ZSTR_SMART_BAT_CYCLES, UNIT_RAW, 0},
//{I2C_SMART_BAT_ID, 6, uint8, "uniqueID[8]", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_LIMITS, 1, uint8, "rfu", UNIT_RAW, 0}, // disabled to save sensors slots
{I2C_SMART_BAT_LIMITS, 2, uint16le, ZSTR_SMART_BAT_CAPACITY,UNIT_MAH, 0},
//{I2C_SMART_BAT_LIMITS, 4, uint16le, "dischargeCurrentRating", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_LIMITS, 6, uint16le, "overDischarge_mV", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_LIMITS, 8, uint16le, "zeroCapacity_mV", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_LIMITS, 10, uint16le, "fullyCharged_mV", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_LIMITS, 12, uint8, "minWorkingTemp", UNIT_RAW, 0}, // disabled to save sensors slots
//{I2C_SMART_BAT_LIMITS, 13, uint8, "maxWorkingTemp", UNIT_RAW, 0}, // disabled to save sensors slots
// 0x50-0x56 custom 3rd party sensors
//{0x50, 0, int16, STR_SENSOR_}
@@ -248,6 +318,10 @@ static int32_t spektrumGetValue(const uint8_t *packet, int startByte, SpektrumDa
return bcdToInt8(*(uint8_t *)data);
case uint32bcd:
return bcdToInt32(*(uint32_t *)data);
case uint16le:
return (int16_t) ((uint16_t) (data[0] + (data[1] << 8)));
case uint32le:
return ((uint32_t) (data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24)));
default:
return -1;
}
@@ -274,6 +348,12 @@ void processSpektrumPacket(const uint8_t *packet)
setTelemetryValue(PROTOCOL_TELEMETRY_SPEKTRUM, (I2C_PSEUDO_TX << 8) + 0, 0, 0, packet[1], UNIT_RAW, 0);
// highest bit indicates that TM1100 is in use, ignore it
uint8_t i2cAddress = (packet[2] & 0x7f);
//SmartBat Hack
if (i2cAddress == I2C_SMART_BAT_BASE_ADDRESS) {
i2cAddress = i2cAddress + (packet[4] >> 4); // use type to create virtual I2CAddresses
}
uint8_t instance = packet[3];
if (i2cAddress == I2C_TEXTGEN) {
@@ -303,6 +383,41 @@ void processSpektrumPacket(const uint8_t *packet)
if (!isSpektrumValidValue(value, sensor->dataType))
continue;
// mV to VOLT PREC2 for Smart Batteries
if ((i2cAddress >= I2C_SMART_BAT_REALTIME && i2cAddress <= I2C_SMART_BAT_LIMITS) && sensor->unit == UNIT_VOLTS) {
if (value == -1) {
continue; // discard unavailable sensors
}
else {
value = value / 10;
}
}
// RPM, 10RPM (0-655340 RPM)
if (i2cAddress == I2C_ESC && sensor->unit == UNIT_RPMS) {
value = value / 10;
}
// Current, 10mA (0-655.34A)
if (i2cAddress == I2C_ESC && sensor->startByte == 6) {
value = value / 10;
}
// BEC Current, 100mA (0-25.4A)
if (i2cAddress == I2C_ESC && sensor->startByte == 10) {
value = value / 10;
}
// Throttle 0.5% (0-127%)
if (i2cAddress == I2C_ESC && sensor->startByte == 12) {
value = value / 2;
}
// Power 0.5% (0-127%)
if (i2cAddress == I2C_ESC && sensor->startByte == 13) {
value = value / 2;
}
if (i2cAddress == I2C_CELLS && sensor->unit == UNIT_VOLTS) {
// Map to FrSky style cell values
int cellIndex = (sensor->startByte / 2) << 16;