This commit is contained in:
Raphael Coeffic
2022-03-20 16:22:14 +01:00
parent da59fca1bc
commit 530d395204
66 changed files with 1267 additions and 1081 deletions
+1
View File
@@ -474,6 +474,7 @@ set(SRC
timers.cpp timers.cpp
trainer.cpp trainer.cpp
model_init.cpp model_init.cpp
serial.cpp
) )
if(GUI) if(GUI)
+212 -168
View File
@@ -37,6 +37,8 @@
// CLI receive buffer size // CLI receive buffer size
#define CLI_RX_BUFFER_SIZE 256 #define CLI_RX_BUFFER_SIZE 256
#define CLI_PRINT_BUFFER_SIZE 128
RTOS_TASK_HANDLE cliTaskId; RTOS_TASK_HANDLE cliTaskId;
RTOS_DEFINE_STACK(cliStack, CLI_STACK_SIZE); RTOS_DEFINE_STACK(cliStack, CLI_STACK_SIZE);
@@ -49,6 +51,50 @@ static StreamBufferHandle_t cliRxBuffer;
// CLI receive call back // CLI receive call back
void (*cliReceiveCallBack)(uint8_t* buf, uint32_t len) = nullptr; void (*cliReceiveCallBack)(uint8_t* buf, uint32_t len) = nullptr;
// CLI send call back
static void (*cliSendCb)(void*, uint8_t) = nullptr;
static void* cliSendCtx = nullptr;
void cliSetSendCb(void* ctx, void (*cb)(void*, uint8_t))
{
cliSendCb = nullptr;
cliSendCtx = ctx;
cliSendCb = cb;
}
static void cliSerialPrintf(const char * format, ...)
{
va_list arglist;
char tmp[CLI_PRINT_BUFFER_SIZE];
// no need to do anything if we don't have an output
if (!cliSendCb) return;
va_start(arglist, format);
vsnprintf(tmp, CLI_PRINT_BUFFER_SIZE-1, format, arglist);
tmp[CLI_PRINT_BUFFER_SIZE-1] = '\0';
va_end(arglist);
const char *t = tmp;
while (*t && cliSendCb) {
cliSendCb(cliSendCtx, *t++);
}
}
#define cliSerialPrint(...) \
do { cliSerialPrintf(__VA_ARGS__); cliSerialCrlf(); } while(0)
static void cliSerialPutc(uint8_t c)
{
if (cliSendCb) cliSendCb(cliSendCtx, c);
}
static void cliSerialCrlf()
{
cliSerialPutc('\r');
cliSerialPutc('\n');
}
uint8_t cliTracesEnabled = true; uint8_t cliTracesEnabled = true;
char cliLastLine[CLI_COMMAND_MAX_LEN+1]; char cliLastLine[CLI_COMMAND_MAX_LEN+1];
@@ -73,8 +119,8 @@ struct MemArea
void cliPrompt() void cliPrompt()
{ {
serialPutc('>'); cliSerialPutc('>');
serialPutc(' '); cliSerialPutc(' ');
} }
int toLongLongInt(const char ** argv, int index, long long int * val) int toLongLongInt(const char ** argv, int index, long long int * val)
@@ -94,7 +140,7 @@ int toLongLongInt(const char ** argv, int index, long long int * val)
if (*endptr == '\0') if (*endptr == '\0')
return 1; return 1;
else { else {
serialPrint("%s: Invalid argument \"%s\"", argv[0], argv[index]); cliSerialPrint("%s: Invalid argument \"%s\"", argv[0], argv[index]);
return -1; return -1;
} }
} }
@@ -134,12 +180,12 @@ int cliLs(const char ** argv)
for (;;) { for (;;) {
res = f_readdir(&dir, &fno); /* Read a directory item */ res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
serialPrint(fno.fname); cliSerialPrint(fno.fname);
} }
f_closedir(&dir); f_closedir(&dir);
} }
else { else {
serialPrint("%s: Invalid directory \"%s\"", argv[0], argv[1]); cliSerialPrint("%s: Invalid directory \"%s\"", argv[0], argv[1]);
} }
return 0; return 0;
} }
@@ -150,20 +196,20 @@ int cliRead(const char ** argv)
uint32_t bytesRead = 0; uint32_t bytesRead = 0;
int bufferSize; int bufferSize;
if (toInt(argv, 2, &bufferSize) == 0 || bufferSize < 0 ) { if (toInt(argv, 2, &bufferSize) == 0 || bufferSize < 0 ) {
serialPrint("%s: Invalid buffer size \"%s\"", argv[0], argv[2]); cliSerialPrint("%s: Invalid buffer size \"%s\"", argv[0], argv[2]);
return 0; return 0;
} }
uint8_t * buffer = (uint8_t*) malloc(bufferSize); uint8_t * buffer = (uint8_t*) malloc(bufferSize);
if (!buffer) { if (!buffer) {
serialPrint("Not enough memory"); cliSerialPrint("Not enough memory");
return 0; return 0;
} }
FRESULT result = f_open(&file, argv[1], FA_OPEN_EXISTING | FA_READ); FRESULT result = f_open(&file, argv[1], FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) { if (result != FR_OK) {
free(buffer); free(buffer);
serialPrint("%s: File not found \"%s\"", argv[0], argv[1]); cliSerialPrint("%s: File not found \"%s\"", argv[0], argv[1]);
return 0; return 0;
} }
@@ -184,7 +230,7 @@ int cliRead(const char ** argv)
uint32_t elapsedTime = (get_tmr10ms() - start) * 10; uint32_t elapsedTime = (get_tmr10ms() - start) * 10;
if (elapsedTime == 0) elapsedTime = 1; if (elapsedTime == 0) elapsedTime = 1;
uint32_t speed = bytesRead / elapsedTime; uint32_t speed = bytesRead / elapsedTime;
serialPrint("Read %d bytes in %d ms, speed %d kB/s", bytesRead, elapsedTime, speed); cliSerialPrint("Read %d bytes in %d ms, speed %d kB/s", bytesRead, elapsedTime, speed);
free(buffer); free(buffer);
return 0; return 0;
} }
@@ -195,22 +241,22 @@ int cliReadSD(const char ** argv)
int numberOfSectors; int numberOfSectors;
int bufferSectors; int bufferSectors;
if (toInt(argv, 1, &startSector) == 0 || startSector < 0 ) { if (toInt(argv, 1, &startSector) == 0 || startSector < 0 ) {
serialPrint("%s: Invalid start sector \"%s\"", argv[0], argv[1]); cliSerialPrint("%s: Invalid start sector \"%s\"", argv[0], argv[1]);
return 0; return 0;
} }
if (toInt(argv, 2, &numberOfSectors) == 0 || numberOfSectors < 0 ) { if (toInt(argv, 2, &numberOfSectors) == 0 || numberOfSectors < 0 ) {
serialPrint("%s: Invalid number of sectors \"%s\"", argv[0], argv[2]); cliSerialPrint("%s: Invalid number of sectors \"%s\"", argv[0], argv[2]);
return 0; return 0;
} }
if (toInt(argv, 3, &bufferSectors) == 0 || bufferSectors < 0 ) { if (toInt(argv, 3, &bufferSectors) == 0 || bufferSectors < 0 ) {
serialPrint("%s: Invalid number of buffer sectors \"%s\"", argv[0], argv[3]); cliSerialPrint("%s: Invalid number of buffer sectors \"%s\"", argv[0], argv[3]);
return 0; return 0;
} }
uint8_t * buffer = (uint8_t*) malloc(512*bufferSectors); uint8_t * buffer = (uint8_t*) malloc(512*bufferSectors);
if (!buffer) { if (!buffer) {
serialPrint("Not enough memory"); cliSerialPrint("Not enough memory");
return 0; return 0;
} }
@@ -220,7 +266,7 @@ int cliReadSD(const char ** argv)
while (numberOfSectors > 0) { while (numberOfSectors > 0) {
DRESULT res = __disk_read(0, buffer, startSector, bufferSectors); DRESULT res = __disk_read(0, buffer, startSector, bufferSectors);
if (res != RES_OK) { if (res != RES_OK) {
serialPrint("disk_read error: %d, sector: %d(%d)", res, startSector, numberOfSectors); cliSerialPrint("disk_read error: %d, sector: %d(%d)", res, startSector, numberOfSectors);
} }
#if 0 #if 0
for(uint32_t n=0; n<bufferSectors; ++n) { for(uint32_t n=0; n<bufferSectors; ++n) {
@@ -233,7 +279,7 @@ int cliReadSD(const char ** argv)
for(int n=0; n<(bufferSectors*512); ++n) { for(int n=0; n<(bufferSectors*512); ++n) {
summ += buffer[n]; summ += buffer[n];
} }
serialPrint("sector %d(%d) checksumm: %u", startSector, numberOfSectors, summ); cliSerialPrint("sector %d(%d) checksumm: %u", startSector, numberOfSectors, summ);
#endif #endif
if (numberOfSectors >= bufferSectors) { if (numberOfSectors >= bufferSectors) {
numberOfSectors -= bufferSectors; numberOfSectors -= bufferSectors;
@@ -247,7 +293,7 @@ int cliReadSD(const char ** argv)
uint32_t elapsedTime = (get_tmr10ms() - start) * 10; uint32_t elapsedTime = (get_tmr10ms() - start) * 10;
if (elapsedTime == 0) elapsedTime = 1; if (elapsedTime == 0) elapsedTime = 1;
uint32_t speed = bytesRead / elapsedTime; uint32_t speed = bytesRead / elapsedTime;
serialPrint("Read %d bytes in %d ms, speed %d kB/s", bytesRead, elapsedTime, speed); cliSerialPrint("Read %d bytes in %d ms, speed %d kB/s", bytesRead, elapsedTime, speed);
free(buffer); free(buffer);
return 0; return 0;
} }
@@ -259,67 +305,67 @@ int cliTestSD(const char ** argv)
// get sector count // get sector count
uint32_t sectorCount; uint32_t sectorCount;
if (disk_ioctl(0, GET_SECTOR_COUNT, &sectorCount) != RES_OK) { if (disk_ioctl(0, GET_SECTOR_COUNT, &sectorCount) != RES_OK) {
serialPrint("Error: can't read sector count"); cliSerialPrint("Error: can't read sector count");
return 0; return 0;
} }
serialPrint("SD card has %u sectors", sectorCount); cliSerialPrint("SD card has %u sectors", sectorCount);
// read last 16 sectors one sector at the time // read last 16 sectors one sector at the time
serialPrint("Starting single sector read test, reading 16 sectors one by one"); cliSerialPrint("Starting single sector read test, reading 16 sectors one by one");
uint8_t * buffer = (uint8_t*) malloc(512); uint8_t * buffer = (uint8_t*) malloc(512);
if (!buffer) { if (!buffer) {
serialPrint("Not enough memory"); cliSerialPrint("Not enough memory");
return 0; return 0;
} }
for (uint32_t s = sectorCount - 16; s<sectorCount; ++s) { for (uint32_t s = sectorCount - 16; s<sectorCount; ++s) {
DRESULT res = __disk_read(0, buffer, s, 1); DRESULT res = __disk_read(0, buffer, s, 1);
if (res != RES_OK) { if (res != RES_OK) {
serialPrint("sector %d read FAILED, err: %d", s, res); cliSerialPrint("sector %d read FAILED, err: %d", s, res);
} }
else { else {
serialPrint("sector %d read OK", s); cliSerialPrint("sector %d read OK", s);
} }
} }
free(buffer); free(buffer);
serialCrlf(); cliSerialCrlf();
// read last 16 sectors, two sectors at the time with a multi-block read // read last 16 sectors, two sectors at the time with a multi-block read
buffer = (uint8_t *) malloc(512*2); buffer = (uint8_t *) malloc(512*2);
if (!buffer) { if (!buffer) {
serialPrint("Not enough memory"); cliSerialPrint("Not enough memory");
return 0; return 0;
} }
serialPrint("Starting multiple sector read test, reading two sectors at the time"); cliSerialPrint("Starting multiple sector read test, reading two sectors at the time");
for (uint32_t s = sectorCount - 16; s<sectorCount; s+=2) { for (uint32_t s = sectorCount - 16; s<sectorCount; s+=2) {
DRESULT res = __disk_read(0, buffer, s, 2); DRESULT res = __disk_read(0, buffer, s, 2);
if (res != RES_OK) { if (res != RES_OK) {
serialPrint("sector %d-%d read FAILED, err: %d", s, s+1, res); cliSerialPrint("sector %d-%d read FAILED, err: %d", s, s+1, res);
} }
else { else {
serialPrint("sector %d-%d read OK", s, s+1); cliSerialPrint("sector %d-%d read OK", s, s+1);
} }
} }
free(buffer); free(buffer);
serialCrlf(); cliSerialCrlf();
// read last 16 sectors, all sectors with single multi-block read // read last 16 sectors, all sectors with single multi-block read
buffer = (uint8_t*) malloc(512*16); buffer = (uint8_t*) malloc(512*16);
if (!buffer) { if (!buffer) {
serialPrint("Not enough memory"); cliSerialPrint("Not enough memory");
return 0; return 0;
} }
serialPrint("Starting multiple sector read test, reading 16 sectors at the time"); cliSerialPrint("Starting multiple sector read test, reading 16 sectors at the time");
DRESULT res = __disk_read(0, buffer, sectorCount-16, 16); DRESULT res = __disk_read(0, buffer, sectorCount-16, 16);
if (res != RES_OK) { if (res != RES_OK) {
serialPrint("sector %d-%d read FAILED, err: %d", sectorCount-16, sectorCount-1, res); cliSerialPrint("sector %d-%d read FAILED, err: %d", sectorCount-16, sectorCount-1, res);
} }
else { else {
serialPrint("sector %d-%d read OK", sectorCount-16, sectorCount-1); cliSerialPrint("sector %d-%d read OK", sectorCount-16, sectorCount-1);
} }
free(buffer); free(buffer);
serialCrlf(); cliSerialCrlf();
return 0; return 0;
} }
@@ -327,42 +373,42 @@ int cliTestSD(const char ** argv)
int cliTestNew() int cliTestNew()
{ {
char * tmp = 0; char * tmp = 0;
serialPrint("Allocating 1kB with new()"); cliSerialPrint("Allocating 1kB with new()");
RTOS_WAIT_MS(200); RTOS_WAIT_MS(200);
tmp = new char[1024]; tmp = new char[1024];
if (tmp) { if (tmp) {
serialPrint("\tsuccess"); cliSerialPrint("\tsuccess");
delete[] tmp; delete[] tmp;
tmp = 0; tmp = 0;
} }
else { else {
serialPrint("\tFAILURE"); cliSerialPrint("\tFAILURE");
} }
serialPrint("Allocating 10MB with (std::nothrow) new()"); cliSerialPrint("Allocating 10MB with (std::nothrow) new()");
RTOS_WAIT_MS(200); RTOS_WAIT_MS(200);
tmp = new (std::nothrow) char[1024*1024*10]; tmp = new (std::nothrow) char[1024*1024*10];
if (tmp) { if (tmp) {
serialPrint("\tFAILURE, tmp = %p", tmp); cliSerialPrint("\tFAILURE, tmp = %p", tmp);
delete[] tmp; delete[] tmp;
tmp = 0; tmp = 0;
} }
else { else {
serialPrint("\tsuccess, allocaton failed, tmp = 0"); cliSerialPrint("\tsuccess, allocaton failed, tmp = 0");
} }
serialPrint("Allocating 10MB with new()"); cliSerialPrint("Allocating 10MB with new()");
RTOS_WAIT_MS(200); RTOS_WAIT_MS(200);
tmp = new char[1024*1024*10]; tmp = new char[1024*1024*10];
if (tmp) { if (tmp) {
serialPrint("\tFAILURE, tmp = %p", tmp); cliSerialPrint("\tFAILURE, tmp = %p", tmp);
delete[] tmp; delete[] tmp;
tmp = 0; tmp = 0;
} }
else { else {
serialPrint("\tsuccess, allocaton failed, tmp = 0"); cliSerialPrint("\tsuccess, allocaton failed, tmp = 0");
} }
serialPrint("Test finished"); cliSerialPrint("Test finished");
return 0; return 0;
} }
@@ -444,7 +490,7 @@ float runTimedFunctionTest(timedTestFunc_t func, const char *name,
noRuns += step; noRuns += step;
} }
const float result = (noRuns * 500.0f) / (float)actualRuntime; // runs/second const float result = (noRuns * 500.0f) / (float)actualRuntime; // runs/second
serialPrint("Test %s speed: %lu.%02u, (%lu runs in %lu ms)", name, cliSerialPrint("Test %s speed: %lu.%02u, (%lu runs in %lu ms)", name,
uint32_t(result), uint16_t((result - uint32_t(result)) * 100.0f), uint32_t(result), uint16_t((result - uint32_t(result)) * 100.0f),
noRuns, actualRuntime); noRuns, actualRuntime);
RTOS_WAIT_MS(200); RTOS_WAIT_MS(200);
@@ -453,7 +499,7 @@ float runTimedFunctionTest(timedTestFunc_t func, const char *name,
int cliTestGraphics() int cliTestGraphics()
{ {
serialPrint("Starting graphics performance test..."); cliSerialPrint("Starting graphics performance test...");
RTOS_WAIT_MS(200); RTOS_WAIT_MS(200);
watchdogSuspend(6000 /*60s*/); watchdogSuspend(6000 /*60s*/);
@@ -479,7 +525,7 @@ int cliTestGraphics()
result += RUN_GRAPHICS_TEST(testDrawTextVertical, 1000); result += RUN_GRAPHICS_TEST(testDrawTextVertical, 1000);
result += RUN_GRAPHICS_TEST(testClear, 1000); result += RUN_GRAPHICS_TEST(testClear, 1000);
serialPrint("Total speed: %lu.%02u", uint32_t(result), cliSerialPrint("Total speed: %lu.%02u", uint32_t(result),
uint16_t((result - uint32_t(result)) * 100.0f)); uint16_t((result - uint32_t(result)) * 100.0f));
perMainEnabled = true; perMainEnabled = true;
@@ -586,7 +632,7 @@ void testMemoryCopyFrom_SDRAM_to_SDRAM_8bit()
int cliTestMemorySpeed() int cliTestMemorySpeed()
{ {
serialPrint("Starting memory speed test..."); cliSerialPrint("Starting memory speed test...");
RTOS_WAIT_MS(200); RTOS_WAIT_MS(200);
watchdogSuspend(6000 /*60s*/); watchdogSuspend(6000 /*60s*/);
@@ -607,7 +653,7 @@ int cliTestMemorySpeed()
result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_32bit, 200); result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_32bit, 200);
LTDC_Cmd(DISABLE); LTDC_Cmd(DISABLE);
serialPrint("Disabling LCD..."); cliSerialPrint("Disabling LCD...");
RTOS_WAIT_MS(200); RTOS_WAIT_MS(200);
result += RUN_MEMORY_TEST(testMemoryReadFrom_RAM_8bit, 200); result += RUN_MEMORY_TEST(testMemoryReadFrom_RAM_8bit, 200);
@@ -619,7 +665,7 @@ int cliTestMemorySpeed()
result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_8bit, 200); result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_8bit, 200);
result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_32bit, 200); result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_32bit, 200);
serialPrint("Total speed: %lu.%02u", uint32_t(result), cliSerialPrint("Total speed: %lu.%02u", uint32_t(result),
uint16_t((result - uint32_t(result)) * 100.0f)); uint16_t((result - uint32_t(result)) * 100.0f));
LTDC_Cmd(ENABLE); LTDC_Cmd(ENABLE);
@@ -646,7 +692,7 @@ int cliTestModelsList()
int count = 0; int count = 0;
serialPrint("Starting fetching RF data 100x..."); cliSerialPrint("Starting fetching RF data 100x...");
const uint32_t start = RTOS_GET_MS(); const uint32_t start = RTOS_GET_MS();
const list<ModelsCategory *> &cats = modList.getCategories(); const list<ModelsCategory *> &cats = modList.getCategories();
@@ -656,7 +702,7 @@ int cliTestModelsList()
for (ModelsCategory::iterator mod_it = (*cat_it)->begin(); for (ModelsCategory::iterator mod_it = (*cat_it)->begin();
mod_it != (*cat_it)->end(); mod_it++) { mod_it != (*cat_it)->end(); mod_it++) {
if (!(*mod_it)->fetchRfData()) { if (!(*mod_it)->fetchRfData()) {
serialPrint("Error while fetching RF data..."); cliSerialPrint("Error while fetching RF data...");
return 0; return 0;
} }
@@ -666,7 +712,7 @@ int cliTestModelsList()
} }
done: done:
serialPrint("Done fetching %ix RF data: %lu ms", count, cliSerialPrint("Done fetching %ix RF data: %lu ms", count,
(RTOS_GET_MS() - start)); (RTOS_GET_MS() - start));
return 0; return 0;
@@ -699,7 +745,7 @@ int cliTest(const char ** argv)
#endif #endif
#endif #endif
else { else {
serialPrint("%s: Invalid argument \"%s\"", argv[0], argv[1]); cliSerialPrint("%s: Invalid argument \"%s\"", argv[0], argv[1]);
} }
return 0; return 0;
} }
@@ -713,18 +759,18 @@ int cliTrace(const char ** argv)
cliTracesEnabled = false; cliTracesEnabled = false;
} }
else { else {
serialPrint("%s: Invalid argument \"%s\"", argv[0], argv[1]); cliSerialPrint("%s: Invalid argument \"%s\"", argv[0], argv[1]);
} }
return 0; return 0;
} }
int cliStackInfo(const char ** argv) int cliStackInfo(const char ** argv)
{ {
serialPrint("[MAIN] %d available / %d bytes", stackAvailable()*4, stackSize()*4); cliSerialPrint("[MAIN] %d available / %d bytes", stackAvailable()*4, stackSize()*4);
serialPrint("[MENUS] %d available / %d bytes", menusStack.available()*4, menusStack.size()); cliSerialPrint("[MENUS] %d available / %d bytes", menusStack.available()*4, menusStack.size());
serialPrint("[MIXER] %d available / %d bytes", mixerStack.available()*4, mixerStack.size()); cliSerialPrint("[MIXER] %d available / %d bytes", mixerStack.available()*4, mixerStack.size());
serialPrint("[AUDIO] %d available / %d bytes", audioStack.available()*4, audioStack.size()); cliSerialPrint("[AUDIO] %d available / %d bytes", audioStack.available()*4, audioStack.size());
serialPrint("[CLI] %d available / %d bytes", cliStack.available()*4, cliStack.size()); cliSerialPrint("[CLI] %d available / %d bytes", cliStack.available()*4, cliStack.size());
return 0; return 0;
} }
@@ -747,31 +793,31 @@ int cliMemoryInfo(const char ** argv)
// int keepcost; /* top-most, releasable (via malloc_trim) space */ // int keepcost; /* top-most, releasable (via malloc_trim) space */
// }; // };
struct mallinfo info = mallinfo(); struct mallinfo info = mallinfo();
serialPrint("mallinfo:"); cliSerialPrint("mallinfo:");
serialPrint("\tarena %d bytes", info.arena); cliSerialPrint("\tarena %d bytes", info.arena);
serialPrint("\tordblks %d bytes", info.ordblks); cliSerialPrint("\tordblks %d bytes", info.ordblks);
serialPrint("\tuordblks %d bytes", info.uordblks); cliSerialPrint("\tuordblks %d bytes", info.uordblks);
serialPrint("\tfordblks %d bytes", info.fordblks); cliSerialPrint("\tfordblks %d bytes", info.fordblks);
serialPrint("\tkeepcost %d bytes", info.keepcost); cliSerialPrint("\tkeepcost %d bytes", info.keepcost);
serialPrint("\nHeap:"); cliSerialPrint("\nHeap:");
serialPrint("\tstart %p", (unsigned char *)&_end); cliSerialPrint("\tstart %p", (unsigned char *)&_end);
serialPrint("\tend %p", (unsigned char *)&_heap_end); cliSerialPrint("\tend %p", (unsigned char *)&_heap_end);
serialPrint("\tcurr %p", heap); cliSerialPrint("\tcurr %p", heap);
serialPrint("\tused %d bytes", (int)(heap - (unsigned char *)&_end)); cliSerialPrint("\tused %d bytes", (int)(heap - (unsigned char *)&_end));
serialPrint("\tfree %d bytes", (int)((unsigned char *)&_heap_end - heap)); cliSerialPrint("\tfree %d bytes", (int)((unsigned char *)&_heap_end - heap));
#if defined(LUA) #if defined(LUA)
serialPrint("\nLua:"); cliSerialPrint("\nLua:");
uint32_t s = luaGetMemUsed(lsScripts); uint32_t s = luaGetMemUsed(lsScripts);
serialPrint("\tScripts %u", s); cliSerialPrint("\tScripts %u", s);
#if defined(COLORLCD) #if defined(COLORLCD)
uint32_t w = luaGetMemUsed(lsWidgets); uint32_t w = luaGetMemUsed(lsWidgets);
uint32_t e = luaExtraMemoryUsage; uint32_t e = luaExtraMemoryUsage;
serialPrint("\tWidgets %u", w); cliSerialPrint("\tWidgets %u", w);
serialPrint("\tExtra %u", e); cliSerialPrint("\tExtra %u", e);
serialPrint("------------"); cliSerialPrint("------------");
serialPrint("\tTotal %u", s + w + e); cliSerialPrint("\tTotal %u", s + w + e);
#endif #endif
#endif #endif
return 0; return 0;
@@ -825,7 +871,7 @@ int cliSet(const char **argv)
g_rtcTime = gmktime(&t); g_rtcTime = gmktime(&t);
rtcSetTime(&t); rtcSetTime(&t);
} else { } else {
serialPrint("%s: Invalid arguments \"%s\" \"%s\"", argv[0], argv[1], cliSerialPrint("%s: Invalid arguments \"%s\" \"%s\"", argv[0], argv[1],
argv[2]); argv[2]);
return -1; return -1;
} }
@@ -836,7 +882,7 @@ int cliSet(const char **argv)
if (toInt(argv, 2, &level) > 0) { if (toInt(argv, 2, &level) > 0) {
setVolume(level); setVolume(level);
} else { } else {
serialPrint("%s: Invalid argument \"%s\" \"%s\"", argv[0], argv[1], cliSerialPrint("%s: Invalid argument \"%s\" \"%s\"", argv[0], argv[1],
argv[2]); argv[2]);
return -1; return -1;
} }
@@ -845,7 +891,7 @@ int cliSet(const char **argv)
else if (!strcmp(argv[1], "rfmod")) { else if (!strcmp(argv[1], "rfmod")) {
int module = 0; int module = 0;
if (toInt(argv, 2, &module) < 0) { if (toInt(argv, 2, &module) < 0) {
serialPrint("%s: invalid module argument '%s'", argv[0], argv[2]); cliSerialPrint("%s: invalid module argument '%s'", argv[0], argv[2]);
return -1; return -1;
} }
if (!strcmp(argv[3], "power")) { if (!strcmp(argv[3], "power")) {
@@ -862,34 +908,34 @@ int cliSet(const char **argv)
EXTERNAL_MODULE_OFF(); EXTERNAL_MODULE_OFF();
} }
} else { } else {
serialPrint("%s: invalid power argument '%s'", argv[0], argv[4]); cliSerialPrint("%s: invalid power argument '%s'", argv[0], argv[4]);
return -1; return -1;
} }
serialPrint("%s: rfmod %d power %s", argv[0], module, argv[4]); cliSerialPrint("%s: rfmod %d power %s", argv[0], module, argv[4]);
} }
#if defined(INTMODULE_BOOTCMD_GPIO) #if defined(INTMODULE_BOOTCMD_GPIO)
else if (!strcmp(argv[3], "bootpin")) { else if (!strcmp(argv[3], "bootpin")) {
int level = 0; int level = 0;
if (toInt(argv, 4, &level) < 0) { if (toInt(argv, 4, &level) < 0) {
serialPrint("%s: invalid bootpin argument '%s'", argv[0], argv[4]); cliSerialPrint("%s: invalid bootpin argument '%s'", argv[0], argv[4]);
return -1; return -1;
} }
if (module == 0) { if (module == 0) {
if (level) { if (level) {
GPIO_SetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN); GPIO_SetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN);
serialPrint("%s: bootpin set", argv[0]); cliSerialPrint("%s: bootpin set", argv[0]);
} else { } else {
GPIO_ResetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN); GPIO_ResetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN);
serialPrint("%s: bootpin reset", argv[0]); cliSerialPrint("%s: bootpin reset", argv[0]);
} }
} }
} }
#endif #endif
else { else {
if (strlen(argv[2]) == 0) { if (strlen(argv[2]) == 0) {
serialPrint("%s: missing rfmod arguments", argv[0]); cliSerialPrint("%s: missing rfmod arguments", argv[0]);
} else { } else {
serialPrint("%s: invalid rfmod argument '%s'", argv[0], argv[3]); cliSerialPrint("%s: invalid rfmod argument '%s'", argv[0], argv[3]);
return -1; return -1;
} }
} }
@@ -897,15 +943,15 @@ int cliSet(const char **argv)
else if (!strcmp(argv[1], "pulses")) { else if (!strcmp(argv[1], "pulses")) {
int level = 0; int level = 0;
if (toInt(argv, 2, &level) < 0) { if (toInt(argv, 2, &level) < 0) {
serialPrint("%s: invalid level argument '%s'", argv[0], argv[2]); cliSerialPrint("%s: invalid level argument '%s'", argv[0], argv[2]);
return -1; return -1;
} }
if (level) { if (level) {
serialPrint("%s: pulses start", argv[0]); cliSerialPrint("%s: pulses start", argv[0]);
startPulses(); startPulses();
} else { } else {
serialPrint("%s: pulses stop", argv[0]); cliSerialPrint("%s: pulses stop", argv[0]);
stopPulses(); stopPulses();
} }
} }
@@ -917,7 +963,7 @@ int cliSet(const char **argv)
static void spInternalModuleTx(uint8_t* buf, uint32_t len) static void spInternalModuleTx(uint8_t* buf, uint32_t len)
{ {
while (len > 0) { while (len > 0) {
IntmoduleSerialDriver.sendByte(*(buf++)); IntmoduleSerialDriver.sendByte(nullptr, *(buf++));
len--; len--;
} }
} }
@@ -928,8 +974,6 @@ static const etx_serial_init spIntmoduleSerialInitParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleFifoReceive, .on_receive = intmoduleFifoReceive,
.on_error = intmoduleFifoError, .on_error = intmoduleFifoError,
}; };
@@ -953,7 +997,7 @@ int cliSerialPassthrough(const char **argv)
// 3rd argument (baudrate is optional) // 3rd argument (baudrate is optional)
if (!port_type || !port_num) { if (!port_type || !port_num) {
serialPrint("%s: missing argument", argv[0]); cliSerialPrint("%s: missing argument", argv[0]);
return -1; return -1;
} }
@@ -961,7 +1005,7 @@ int cliSerialPassthrough(const char **argv)
int err = toInt(argv, 2, &port_n); int err = toInt(argv, 2, &port_n);
if (err == -1) return err; if (err == -1) return err;
if (err == 0) { if (err == 0) {
serialPrint("%s: missing port #", argv[0]); cliSerialPrint("%s: missing port #", argv[0]);
return -1; return -1;
} }
@@ -973,7 +1017,7 @@ int cliSerialPassthrough(const char **argv)
if (!baudrate) { if (!baudrate) {
// default to 115200 // default to 115200
baudrate = 115200; baudrate = 115200;
serialPrint("%s: USB baudrate is 0, default to 115200", argv[0]); cliSerialPrint("%s: USB baudrate is 0, default to 115200", argv[0]);
} }
} }
@@ -982,7 +1026,7 @@ int cliSerialPassthrough(const char **argv)
if (port_n >= NUM_MODULES if (port_n >= NUM_MODULES
// only internal module supported for now // only internal module supported for now
&& port_n != INTERNAL_MODULE) { && port_n != INTERNAL_MODULE) {
serialPrint("%s: invalid port # '%s'", port_num); cliSerialPrint("%s: invalid port # '%s'", port_num);
return -1; return -1;
} }
@@ -1002,7 +1046,7 @@ int cliSerialPassthrough(const char **argv)
etx_serial_init params(spIntmoduleSerialInitParams); etx_serial_init params(spIntmoduleSerialInitParams);
params.baudrate = baudrate; params.baudrate = baudrate;
IntmoduleSerialDriver.init(&params); void* uart_ctx = IntmoduleSerialDriver.init(&params);
// backup and swap CLI input // backup and swap CLI input
auto backupCB = cliReceiveCallBack; auto backupCB = cliReceiveCallBack;
@@ -1023,7 +1067,7 @@ int cliSerialPassthrough(const char **argv)
timeout--; timeout--;
} }
usbSerialPutc(data); usbSerialPutc(nullptr, data);
} }
// keep us up & running // keep us up & running
@@ -1035,7 +1079,7 @@ int cliSerialPassthrough(const char **argv)
cliReceiveCallBack = backupCB; cliReceiveCallBack = backupCB;
// and stop module // and stop module
IntmoduleSerialDriver.deinit(); IntmoduleSerialDriver.deinit(uart_ctx);
// power off the module and wait for a bit // power off the module and wait for a bit
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
@@ -1053,7 +1097,7 @@ int cliSerialPassthrough(const char **argv)
xTaskResumeAll(); xTaskResumeAll();
} else { } else {
serialPrint("%s: invalid port type '%s'", port_type); cliSerialPrint("%s: invalid port type '%s'", port_type);
return -1; return -1;
} }
@@ -1069,9 +1113,9 @@ void printInterrupts()
memset(&interruptCounters, 0, sizeof(interruptCounters)); memset(&interruptCounters, 0, sizeof(interruptCounters));
interruptCounters.resetTime = get_tmr10ms(); interruptCounters.resetTime = get_tmr10ms();
__enable_irq(); __enable_irq();
serialPrint("Interrupts count in the last %u ms:", (get_tmr10ms() - ic.resetTime) * 10); cliSerialPrint("Interrupts count in the last %u ms:", (get_tmr10ms() - ic.resetTime) * 10);
for(int n = 0; n < INT_LAST; n++) { for(int n = 0; n < INT_LAST; n++) {
serialPrint("%s: %u", interruptNames[n], ic.cnt[n]); cliSerialPrint("%s: %u", interruptNames[n], ic.cnt[n]);
} }
} }
#endif //#if defined(DEBUG_INTERRUPTS) #endif //#if defined(DEBUG_INTERRUPTS)
@@ -1080,20 +1124,20 @@ void printInterrupts()
void printDebugTime(uint32_t time) void printDebugTime(uint32_t time)
{ {
if (time >= 30000) { if (time >= 30000) {
serialPrintf("%dms", time/1000); cliSerialPrintf("%dms", time/1000);
} }
else { else {
serialPrintf("%d.%03dms", time/1000, time%1000); cliSerialPrintf("%d.%03dms", time/1000, time%1000);
} }
} }
void printDebugTimer(const char * name, DebugTimer & timer) void printDebugTimer(const char * name, DebugTimer & timer)
{ {
serialPrintf("%s: ", name); cliSerialPrintf("%s: ", name);
printDebugTime( timer.getMin()); printDebugTime( timer.getMin());
serialPrintf(" - "); cliSerialPrintf(" - ");
printDebugTime(timer.getMax()); printDebugTime(timer.getMax());
serialCrlf(); cliSerialCrlf();
timer.reset(); timer.reset();
} }
void printDebugTimers() void printDebugTimers()
@@ -1108,28 +1152,28 @@ void printDebugTimers()
void printAudioVars() void printAudioVars()
{ {
for (int n = 0; n < AUDIO_BUFFER_COUNT; n++) { for (int n = 0; n < AUDIO_BUFFER_COUNT; n++) {
serialPrint("Audio Buffer %d: size: %u, ", n, cliSerialPrint("Audio Buffer %d: size: %u, ", n,
(uint32_t)audioBuffers[n].size); (uint32_t)audioBuffers[n].size);
dump((uint8_t *)audioBuffers[n].data, 32); dump((uint8_t *)audioBuffers[n].data, 32);
} }
serialPrint("fragments:"); cliSerialPrint("fragments:");
for (int n = 0; n < AUDIO_QUEUE_LENGTH; n++) { for (int n = 0; n < AUDIO_QUEUE_LENGTH; n++) {
serialPrint("%d: type %u: id: %u, repeat: %u, ", n, cliSerialPrint("%d: type %u: id: %u, repeat: %u, ", n,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].type, (uint32_t)audioQueue.fragmentsFifo.fragments[n].type,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].id, (uint32_t)audioQueue.fragmentsFifo.fragments[n].id,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].repeat); (uint32_t)audioQueue.fragmentsFifo.fragments[n].repeat);
if (audioQueue.fragmentsFifo.fragments[n].type == FRAGMENT_FILE) { if (audioQueue.fragmentsFifo.fragments[n].type == FRAGMENT_FILE) {
serialPrint(" file: %s", audioQueue.fragmentsFifo.fragments[n].file); cliSerialPrint(" file: %s", audioQueue.fragmentsFifo.fragments[n].file);
} }
} }
serialPrint("FragmentFifo: ridx: %d, widx: %d", cliSerialPrint("FragmentFifo: ridx: %d, widx: %d",
audioQueue.fragmentsFifo.ridx, audioQueue.fragmentsFifo.widx); audioQueue.fragmentsFifo.ridx, audioQueue.fragmentsFifo.widx);
serialPrint("audioQueue: readIdx: %d, writeIdx: %d, full: %d", cliSerialPrint("audioQueue: readIdx: %d, writeIdx: %d, full: %d",
audioQueue.buffersFifo.readIdx, audioQueue.buffersFifo.writeIdx, audioQueue.buffersFifo.readIdx, audioQueue.buffersFifo.writeIdx,
audioQueue.buffersFifo.bufferFull); audioQueue.buffersFifo.bufferFull);
serialPrint("normalContext: %u", cliSerialPrint("normalContext: %u",
(uint32_t)audioQueue.normalContext.fragment.type); (uint32_t)audioQueue.normalContext.fragment.type);
} }
#endif #endif
@@ -1152,13 +1196,13 @@ int cliDisplay(const char ** argv)
uint8_t len = STR_VKEYS[0]; uint8_t len = STR_VKEYS[0];
strncpy(name, STR_VKEYS+1+len*i, len); strncpy(name, STR_VKEYS+1+len*i, len);
name[len] = '\0'; name[len] = '\0';
serialPrint("[%s] = %s", name, keys[i].state() ? "on" : "off"); cliSerialPrint("[%s] = %s", name, keys[i].state() ? "on" : "off");
} }
#if defined(ROTARY_ENCODER_NAVIGATION) #if defined(ROTARY_ENCODER_NAVIGATION)
serialPrint("[Enc.] = %d", rotencValue / ROTARY_ENCODER_GRANULARITY); cliSerialPrint("[Enc.] = %d", rotencValue / ROTARY_ENCODER_GRANULARITY);
#endif #endif
for (int i=TRM_BASE; i<=TRM_LAST; i++) { for (int i=TRM_BASE; i<=TRM_LAST; i++) {
serialPrint("[Trim%d] = %s", i-TRM_BASE, keys[i].state() ? "on" : "off"); cliSerialPrint("[Trim%d] = %s", i-TRM_BASE, keys[i].state() ? "on" : "off");
} }
for (int i=MIXSRC_FIRST_SWITCH; i<=MIXSRC_LAST_SWITCH; i++) { for (int i=MIXSRC_FIRST_SWITCH; i<=MIXSRC_LAST_SWITCH; i++) {
mixsrc_t sw = i - MIXSRC_FIRST_SWITCH; mixsrc_t sw = i - MIXSRC_FIRST_SWITCH;
@@ -1166,34 +1210,34 @@ int cliDisplay(const char ** argv)
char swName[LEN_SWITCH_NAME + 1]; char swName[LEN_SWITCH_NAME + 1];
strAppend(swName, STR_VSWITCHES+1+sw*STR_VSWITCHES[0], STR_VSWITCHES[0]); strAppend(swName, STR_VSWITCHES+1+sw*STR_VSWITCHES[0], STR_VSWITCHES[0]);
static const char * const SWITCH_POSITIONS[] = { "down", "mid", "up" }; static const char * const SWITCH_POSITIONS[] = { "down", "mid", "up" };
serialPrint("[%s] = %s", swName, SWITCH_POSITIONS[1 + getValue(i) / 1024]); cliSerialPrint("[%s] = %s", swName, SWITCH_POSITIONS[1 + getValue(i) / 1024]);
} }
} }
} }
else if (!strcmp(argv[1], "adc")) { else if (!strcmp(argv[1], "adc")) {
for (int i=0; i<NUM_ANALOGS; i++) { for (int i=0; i<NUM_ANALOGS; i++) {
serialPrint("adc[%d] = %04X", i, (int)adcValues[i]); cliSerialPrint("adc[%d] = %04X", i, (int)adcValues[i]);
} }
} }
else if (!strcmp(argv[1], "outputs")) { else if (!strcmp(argv[1], "outputs")) {
for (int i=0; i<MAX_OUTPUT_CHANNELS; i++) { for (int i=0; i<MAX_OUTPUT_CHANNELS; i++) {
serialPrint("outputs[%d] = %04d", i, (int)channelOutputs[i]); cliSerialPrint("outputs[%d] = %04d", i, (int)channelOutputs[i]);
} }
} }
else if (!strcmp(argv[1], "rtc")) { else if (!strcmp(argv[1], "rtc")) {
struct gtm utm; struct gtm utm;
gettime(&utm); gettime(&utm);
serialPrint("rtc = %4d-%02d-%02d %02d:%02d:%02d.%02d0", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100); cliSerialPrint("rtc = %4d-%02d-%02d %02d:%02d:%02d.%02d0", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
} }
#if !defined(SOFTWARE_VOLUME) #if !defined(SOFTWARE_VOLUME)
else if (!strcmp(argv[1], "volume")) { else if (!strcmp(argv[1], "volume")) {
serialPrint("volume = %d", getVolume()); cliSerialPrint("volume = %d", getVolume());
} }
#endif #endif
else if (!strcmp(argv[1], "uid")) { else if (!strcmp(argv[1], "uid")) {
char str[LEN_CPU_UID+1]; char str[LEN_CPU_UID+1];
getCPUUniqueID(str); getCPUUniqueID(str);
serialPrint("uid = %s", str); cliSerialPrint("uid = %s", str);
} }
else if (!strcmp(argv[1], "tim")) { else if (!strcmp(argv[1], "tim")) {
int timerNumber; int timerNumber;
@@ -1215,29 +1259,29 @@ int cliDisplay(const char ** argv)
default: default:
return 0; return 0;
} }
serialPrint("TIM%d", timerNumber); cliSerialPrint("TIM%d", timerNumber);
serialPrint(" CR1 0x%x", tim->CR1); cliSerialPrint(" CR1 0x%x", tim->CR1);
serialPrint(" CR2 0x%x", tim->CR2); cliSerialPrint(" CR2 0x%x", tim->CR2);
serialPrint(" DIER 0x%x", tim->DIER); cliSerialPrint(" DIER 0x%x", tim->DIER);
serialPrint(" SR 0x%x", tim->SR); cliSerialPrint(" SR 0x%x", tim->SR);
serialPrint(" EGR 0x%x", tim->EGR); cliSerialPrint(" EGR 0x%x", tim->EGR);
serialPrint(" CCMR1 0x%x", tim->CCMR1); cliSerialPrint(" CCMR1 0x%x", tim->CCMR1);
serialPrint(" CCMR2 0x%x", tim->CCMR2); cliSerialPrint(" CCMR2 0x%x", tim->CCMR2);
serialPrint(" CNT 0x%x", tim->CNT); cliSerialPrint(" CNT 0x%x", tim->CNT);
serialPrint(" ARR 0x%x", tim->ARR); cliSerialPrint(" ARR 0x%x", tim->ARR);
serialPrint(" PSC 0x%x", tim->PSC); cliSerialPrint(" PSC 0x%x", tim->PSC);
serialPrint(" CCER 0x%x", tim->CCER); cliSerialPrint(" CCER 0x%x", tim->CCER);
serialPrint(" CCR1 0x%x", tim->CCR1); cliSerialPrint(" CCR1 0x%x", tim->CCR1);
serialPrint(" CCR2 0x%x", tim->CCR2); cliSerialPrint(" CCR2 0x%x", tim->CCR2);
serialPrint(" CCR3 0x%x", tim->CCR3); cliSerialPrint(" CCR3 0x%x", tim->CCR3);
serialPrint(" CCR4 0x%x", tim->CCR4); cliSerialPrint(" CCR4 0x%x", tim->CCR4);
} }
} }
else if (!strcmp(argv[1], "dma")) { else if (!strcmp(argv[1], "dma")) {
serialPrint("DMA1_Stream7"); cliSerialPrint("DMA1_Stream7");
serialPrint(" CR 0x%x", DMA1_Stream7->CR); cliSerialPrint(" CR 0x%x", DMA1_Stream7->CR);
} }
#if defined(DEBUG_INTERRUPTS) #if defined(DEBUG_INTERRUPTS)
else if (!strcmp(argv[1], "int")) { else if (!strcmp(argv[1], "int")) {
@@ -1258,7 +1302,7 @@ int cliDisplay(const char ** argv)
else if (!strcmp(argv[1], "dc")) { else if (!strcmp(argv[1], "dc")) {
DiskCacheStats stats = diskCache.getStats(); DiskCacheStats stats = diskCache.getStats();
uint32_t hitRate = diskCache.getHitRate(); uint32_t hitRate = diskCache.getHitRate();
serialPrint("Disk Cache stats: w:%u r: %u, h: %u(%0.1f%%), m: %u", stats.noWrites, (stats.noHits + stats.noMisses), stats.noHits, hitRate*0.1f, stats.noMisses); cliSerialPrint("Disk Cache stats: w:%u r: %u, h: %u(%0.1f%%), m: %u", stats.noWrites, (stats.noHits + stats.noMisses), stats.noHits, hitRate*0.1f, stats.noMisses);
} }
#endif #endif
else if (toLongLongInt(argv, 1, &address) > 0) { else if (toLongLongInt(argv, 1, &address) > 0) {
@@ -1275,15 +1319,15 @@ int cliDebugVars(const char ** argv)
#if defined(PCBHORUS) #if defined(PCBHORUS)
extern uint32_t ioMutexReq, ioMutexRel; extern uint32_t ioMutexReq, ioMutexRel;
extern uint32_t sdReadRetries; extern uint32_t sdReadRetries;
serialPrint("ioMutexReq=%d", ioMutexReq); cliSerialPrint("ioMutexReq=%d", ioMutexReq);
serialPrint("ioMutexRel=%d", ioMutexRel); cliSerialPrint("ioMutexRel=%d", ioMutexRel);
serialPrint("sdReadRetries=%d", sdReadRetries); cliSerialPrint("sdReadRetries=%d", sdReadRetries);
#if defined(ACCESS_DENIED) #if defined(ACCESS_DENIED)
extern volatile int32_t authenticateFrames; extern volatile int32_t authenticateFrames;
serialPrint("authenticateFrames=%d", authenticateFrames); cliSerialPrint("authenticateFrames=%d", authenticateFrames);
#endif #endif
#elif defined(PCBTARANIS) #elif defined(PCBTARANIS)
serialPrint("telemetryErrors=%d", telemetryErrors); cliSerialPrint("telemetryErrors=%d", telemetryErrors);
#endif #endif
return 0; return 0;
@@ -1311,7 +1355,7 @@ int cliRepeat(const char ** argv)
} }
} }
else { else {
serialPrint("%s: Invalid arguments", argv[0]); cliSerialPrint("%s: Invalid arguments", argv[0]);
} }
return 0; return 0;
} }
@@ -1320,13 +1364,13 @@ int cliRepeat(const char ** argv)
#if defined(JITTER_MEASURE) #if defined(JITTER_MEASURE)
int cliShowJitter(const char ** argv) int cliShowJitter(const char ** argv)
{ {
serialPrint( "# anaIn rawJ avgJ"); cliSerialPrint( "# anaIn rawJ avgJ");
for (int i=0; i<NUM_ANALOGS; i++) { for (int i=0; i<NUM_ANALOGS; i++) {
serialPrint("A%02d %04X %04X %3d %3d", i, getAnalogValue(i), anaIn(i), rawJitter[i].get(), avgJitter[i].get()); cliSerialPrint("A%02d %04X %04X %3d %3d", i, getAnalogValue(i), anaIn(i), rawJitter[i].get(), avgJitter[i].get());
if (IS_POT_MULTIPOS(i)) { if (IS_POT_MULTIPOS(i)) {
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i]; StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i];
for (int j=0; j<calib->count; j++) { for (int j=0; j<calib->count; j++) {
serialPrint(" s%d %04X", j, calib->steps[j]); cliSerialPrint(" s%d %04X", j, calib->steps[j]);
} }
} }
} }
@@ -1350,10 +1394,10 @@ int cliGps(const char ** argv)
#endif #endif
else if (toInt(argv, 1, &baudrate) > 0 && baudrate > 0) { else if (toInt(argv, 1, &baudrate) > 0 && baudrate > 0) {
gpsInit(baudrate); gpsInit(baudrate);
serialPrint("GPS baudrate set to %d", baudrate); cliSerialPrint("GPS baudrate set to %d", baudrate);
} }
else { else {
serialPrint("%s: Invalid arguments", argv[0]); cliSerialPrint("%s: Invalid arguments", argv[0]);
} }
return 0; return 0;
} }
@@ -1366,21 +1410,21 @@ int cliBlueTooth(const char ** argv)
if (!strncmp(argv[1], "AT", 2) || !strncmp(argv[1], "TTM", 3)) { if (!strncmp(argv[1], "AT", 2) || !strncmp(argv[1], "TTM", 3)) {
bluetooth.writeString(argv[1]); bluetooth.writeString(argv[1]);
char * line = bluetooth.readline(); char * line = bluetooth.readline();
serialPrint("<BT %s", line); cliSerialPrint("<BT %s", line);
} }
else if (toInt(argv, 1, &baudrate) > 0) { else if (toInt(argv, 1, &baudrate) > 0) {
if (baudrate > 0) { if (baudrate > 0) {
bluetoothInit(baudrate, true); bluetoothInit(baudrate, true);
char * line = bluetooth.readline(); char * line = bluetooth.readline();
serialPrint("<BT %s", line); cliSerialPrint("<BT %s", line);
} }
else { else {
bluetoothDisable(); bluetoothDisable();
serialPrint("BT turned off"); cliSerialPrint("BT turned off");
} }
} }
else { else {
serialPrint("%s: Invalid arguments", argv[0]); cliSerialPrint("%s: Invalid arguments", argv[0]);
} }
return 0; return 0;
} }
@@ -1407,7 +1451,7 @@ int cliCrypt(const char ** argv)
return -1; return -1;
strncpy((char*)cryptInput, argv[1], sizeof(cryptInput)); strncpy((char*)cryptInput, argv[1], sizeof(cryptInput));
serialPrint("Input:"); cliSerialPrint("Input:");
dumpBody(cryptInput, sizeof(cryptInput)); dumpBody(cryptInput, sizeof(cryptInput));
dumpEnd(); dumpEnd();
@@ -1420,9 +1464,9 @@ int cliCrypt(const char ** argv)
uint32_t startMs = RTOS_GET_MS(); uint32_t startMs = RTOS_GET_MS();
testAccessDenied(100000); testAccessDenied(100000);
serialPrintf("access_denied: %f us/run\r\n", (RTOS_GET_MS() - startMs)*1000.0f / 100000.0f); cliSerialPrintf("access_denied: %f us/run\r\n", (RTOS_GET_MS() - startMs)*1000.0f / 100000.0f);
serialPrint("Decrypted (SW):"); cliSerialPrint("Decrypted (SW):");
dumpBody(cryptOutput, sizeof(cryptOutput)); dumpBody(cryptOutput, sizeof(cryptOutput));
dumpEnd(); dumpEnd();
@@ -1479,14 +1523,14 @@ int cliHelp(const char ** argv)
{ {
for (const CliCommand * command = cliCommands; command->name != nullptr; command++) { for (const CliCommand * command = cliCommands; command->name != nullptr; command++) {
if (argv[1][0] == '\0' || !strcmp(command->name, argv[0])) { if (argv[1][0] == '\0' || !strcmp(command->name, argv[0])) {
serialPrint("%s %s", command->name, command->args); cliSerialPrint("%s %s", command->name, command->args);
if (argv[1][0] != '\0') { if (argv[1][0] != '\0') {
return 0; return 0;
} }
} }
} }
if (argv[1][0] != '\0') { if (argv[1][0] != '\0') {
serialPrint("Invalid command \"%s\"", argv[0]); cliSerialPrint("Invalid command \"%s\"", argv[0]);
} }
return -1; return -1;
} }
@@ -1501,7 +1545,7 @@ int cliExecCommand(const char ** argv)
return command->func(argv); return command->func(argv);
} }
} }
serialPrint("Invalid command \"%s\"", argv[0]); cliSerialPrint("Invalid command \"%s\"", argv[0]);
return -1; return -1;
} }
@@ -1556,14 +1600,14 @@ void cliTask(void * pdata)
switch(c) { switch(c) {
case CHAR_NEWPAGE: case CHAR_NEWPAGE:
// clear screen // clear screen
serialPrint("\033[2J\033[1;1H"); cliSerialPrint("\033[2J\033[1;1H");
cliPrompt(); cliPrompt();
break; break;
case CHAR_BACKSPACE: case CHAR_BACKSPACE:
if (pos) { if (pos) {
line[--pos] = '\0'; line[--pos] = '\0';
serialPutc(c); cliSerialPutc(c);
} }
break; break;
@@ -1573,7 +1617,7 @@ void cliTask(void * pdata)
case CHAR_LF: case CHAR_LF:
// enter // enter
serialCrlf(); cliSerialCrlf();
line[pos] = '\0'; line[pos] = '\0';
if (pos == 0 && cliLastLine[0]) { if (pos == 0 && cliLastLine[0]) {
// execute (repeat) last command // execute (repeat) last command
@@ -1592,7 +1636,7 @@ void cliTask(void * pdata)
default: default:
if (isascii(c) && pos < CLI_COMMAND_MAX_LEN) { if (isascii(c) && pos < CLI_COMMAND_MAX_LEN) {
line[pos++] = c; line[pos++] = c;
serialPutc(c); cliSerialPutc(c);
} }
break; break;
} }
+3
View File
@@ -35,4 +35,7 @@ void cliStart();
// Called from receive ISR (either USB or UART) // Called from receive ISR (either USB or UART)
void cliReceiveData(uint8_t* buf, uint32_t len); void cliReceiveData(uint8_t* buf, uint32_t len);
// Set callbacks for sending data back to serial port
void cliSetSendCb(void* ctx, void (*cb)(void*, uint8_t));
#endif // _CLI_H_ #endif // _CLI_H_
+1 -6
View File
@@ -241,9 +241,6 @@ enum TrainerMode {
enum UartModes { enum UartModes {
UART_MODE_NONE, UART_MODE_NONE,
#if defined(CLI) || defined(DEBUG)
UART_MODE_DEBUG SKIP = UART_MODE_NONE,
#endif
UART_MODE_TELEMETRY_MIRROR, UART_MODE_TELEMETRY_MIRROR,
UART_MODE_TELEMETRY, UART_MODE_TELEMETRY,
UART_MODE_SBUS_TRAINER, UART_MODE_SBUS_TRAINER,
@@ -252,9 +249,7 @@ enum UartModes {
UART_MODE_MAX SKIP = UART_MODE_COUNT-1 UART_MODE_MAX SKIP = UART_MODE_COUNT-1
}; };
#if defined(CLI) || defined(DEBUG) #define UART_MODE_DEBUG UART_MODE_NONE
#define UART_MODE_NONE UART_MODE_DEBUG
#endif
#define LEN_SWITCH_NAME 3 #define LEN_SWITCH_NAME 3
#define LEN_ANA_NAME 3 #define LEN_ANA_NAME 3
+2 -5
View File
@@ -33,9 +33,6 @@
extern volatile uint32_t g_tmr10ms; extern volatile uint32_t g_tmr10ms;
uint8_t auxSerialTracesEnabled();
uint8_t aux2SerialTracesEnabled();
#if defined(SIMU) #if defined(SIMU)
typedef void (*traceCallbackFunc)(const char * text); typedef void (*traceCallbackFunc)(const char * text);
extern traceCallbackFunc traceCallback; extern traceCallbackFunc traceCallback;
@@ -45,9 +42,9 @@ uint8_t aux2SerialTracesEnabled();
#define debugPrintf(...) printf(__VA_ARGS__) #define debugPrintf(...) printf(__VA_ARGS__)
#elif defined(DEBUG) && defined(CLI) #elif defined(DEBUG) && defined(CLI)
#include "cli_traces.h" #include "cli_traces.h"
#define debugPrintf(...) do { if (cliTracesEnabled) serialPrintf(__VA_ARGS__); } while(0) #define debugPrintf(...) do { if (cliTracesEnabled) dbgSerialPrintf(__VA_ARGS__); } while(0)
#elif defined(DEBUG) #elif defined(DEBUG)
#define debugPrintf(...) do { serialPrintf(__VA_ARGS__); } while(0) #define debugPrintf(...) do { dbgSerialPrintf(__VA_ARGS__); } while(0)
#else #else
#define debugPrintf(...) #define debugPrintf(...)
#endif #endif
+1 -1
View File
@@ -24,7 +24,7 @@
#if defined(SIMU) #if defined(SIMU)
#define dumpPrintf(...) debugPrintf(__VA_ARGS__) #define dumpPrintf(...) debugPrintf(__VA_ARGS__)
#else #else
#define dumpPrintf(...) serialPrintf(__VA_ARGS__) #define dumpPrintf(...) dbgSerialPrintf(__VA_ARGS__)
#endif #endif
#if defined(DEBUG) || defined(CLI) #if defined(DEBUG) || defined(CLI)
-12
View File
@@ -163,18 +163,6 @@ void menuStatisticsDebug(event_t event)
uint8_t y = FH + 1; uint8_t y = FH + 1;
#if defined(STM32) && !defined(SIMU) && defined(DEBUG)
lcdDrawTextAlignedLeft(y, "Usb");
lcdDrawNumber(MENU_DEBUG_COL1_OFS, y, charsWritten, LEFT);
lcdDrawText(lcdLastRightPos, y, " ");
lcdDrawNumber(lcdLastRightPos, y, APP_Rx_ptr_in, LEFT);
lcdDrawText(lcdLastRightPos, y, " ");
lcdDrawNumber(lcdLastRightPos, y, APP_Rx_ptr_out, LEFT);
lcdDrawText(lcdLastRightPos, y, " ");
lcdDrawNumber(lcdLastRightPos, y, usbWraps, LEFT);
y += FH;
#endif
#if defined(STM32) #if defined(STM32)
lcdDrawTextAlignedLeft(y, "Free Mem"); lcdDrawTextAlignedLeft(y, "Free Mem");
lcdDrawNumber(MENU_DEBUG_COL1_OFS, y, availableMemory(), LEFT); lcdDrawNumber(MENU_DEBUG_COL1_OFS, y, availableMemory(), LEFT);
+2 -2
View File
@@ -380,7 +380,7 @@ void RadioHardwarePage::build(FormWindow * window)
UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.auxSerialMode), UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.auxSerialMode),
[](int value) { [](int value) {
g_eeGeneral.auxSerialMode = value; g_eeGeneral.auxSerialMode = value;
auxSerialInit(g_eeGeneral.auxSerialMode, modelTelemetryProtocol()); serialInit(0, value);
SET_DIRTY(); SET_DIRTY();
}); });
aux->setAvailableHandler(isAuxModeAvailable); aux->setAvailableHandler(isAuxModeAvailable);
@@ -394,7 +394,7 @@ void RadioHardwarePage::build(FormWindow * window)
UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.aux2SerialMode), UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.aux2SerialMode),
[](int value) { [](int value) {
g_eeGeneral.aux2SerialMode = value; g_eeGeneral.aux2SerialMode = value;
aux2SerialInit(g_eeGeneral.aux2SerialMode, modelTelemetryProtocol()); serialInit(1, value);
SET_DIRTY(); SET_DIRTY();
}); });
aux2->setAvailableHandler(isAux2ModeAvailable); aux2->setAvailableHandler(isAux2ModeAvailable);
@@ -600,7 +600,7 @@ void menuRadioHardware(event_t event)
case ITEM_RADIO_HARDWARE_AUX_SERIAL_MODE: case ITEM_RADIO_HARDWARE_AUX_SERIAL_MODE:
g_eeGeneral.auxSerialMode = editChoice(HW_SETTINGS_COLUMN2, y, STR_AUX_SERIAL_MODE, STR_AUX_SERIAL_MODES, g_eeGeneral.auxSerialMode, 0, UART_MODE_MAX, attr, event); g_eeGeneral.auxSerialMode = editChoice(HW_SETTINGS_COLUMN2, y, STR_AUX_SERIAL_MODE, STR_AUX_SERIAL_MODES, g_eeGeneral.auxSerialMode, 0, UART_MODE_MAX, attr, event);
if (attr && checkIncDec_Ret) { if (attr && checkIncDec_Ret) {
auxSerialInit(g_eeGeneral.auxSerialMode, modelTelemetryProtocol()); serialInit(0, g_eeGeneral.auxSerialMode);
} }
break; break;
#endif #endif
+18 -17
View File
@@ -40,44 +40,45 @@ enum SerialWordLength {
ETX_WordLength_9, ETX_WordLength_9,
}; };
struct etx_serial_init { typedef struct {
uint32_t baudrate; // = 0; uint32_t baudrate; // = 0;
uint8_t parity; // = ETX_Parity_None; uint8_t parity; // = ETX_Parity_None;
uint8_t stop_bits; // = ETX_StopBits_One; uint8_t stop_bits; // = ETX_StopBits_One;
uint8_t word_length; // = ETX_WordLength_8; uint8_t word_length; // = ETX_WordLength_8;
bool rx_enable; // = false; bool rx_enable; // = false;
void* rx_dma_buf;
uint32_t rx_dma_buf_len;
void (*on_receive)(uint8_t data); // = nullptr; void (*on_receive)(uint8_t data); // = nullptr;
void (*on_error)(); // = nullptr; void (*on_error)(); // = nullptr;
}; } etx_serial_init;
struct etx_serial_callbacks_t { struct etx_serial_callbacks_t {
bool (*on_send)(uint8_t& data); bool (*on_send)(uint8_t* data);
void (*on_receive)(uint8_t data); void (*on_receive)(uint8_t data);
void (*on_error)(); void (*on_error)();
}; };
struct etx_serial_driver_t { typedef struct {
// Init module communication // Init serial communication
void (*init)(const etx_serial_init* params); void* (*init)(const etx_serial_init* params);
// De-Init module communication // De-Init serial communication
void (*deinit)(); void (*deinit)(void* ctx);
// Send a single byte // Send a single byte
void (*sendByte)(uint8_t byte); void (*sendByte)(void* ctx, uint8_t byte);
// Send a buffer // Send a buffer
void (*sendBuffer)(const uint8_t* data, uint8_t size); void (*sendBuffer)(void* ctx, const uint8_t* data, uint8_t size);
// Wait for last send operation to complete // Wait for last send operation to complete
void (*waitForTxCompleted)(); void (*waitForTxCompleted)(void* ctx);
// Fetch byte from internal buffer
int (*getByte)(void* ctx, uint8_t* data);
// Callbacks // Callbacks
void (*setReceiveCb)(void (*on_receive)(uint8_t data)); void (*setReceiveCb)(void* ctx, void (*on_receive)(uint8_t data));
void (*setOnErrorCb)(void (*on_error)()); void (*setOnErrorCb)(void* ctx, void (*on_error)());
};
} etx_serial_driver_t;
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (C) EdgeTx
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "serial_driver.h"
typedef void etx_pwr_driver;
typedef struct {
const etx_serial_driver_t* uart;
void (*set_pwr)(uint8_t on);
} etx_serial_port_t;
+13 -15
View File
@@ -175,7 +175,7 @@ const uint8_t * FrskyDeviceFirmwareUpdate::readHalfDuplexFrame(uint32_t timeout)
{ {
for (int i = timeout; i >= 0; i--) { for (int i = timeout; i >= 0; i--) {
uint8_t byte ; uint8_t byte ;
while (telemetryGetByte(&byte)) { while (sportGetByte(&byte)) {
if (pushFrskyTelemetryData(byte)) { if (pushFrskyTelemetryData(byte)) {
return telemetryRxBuffer; return telemetryRxBuffer;
} }
@@ -251,7 +251,7 @@ void FrskyDeviceFirmwareUpdate::sendFrame()
switch (module) { switch (module) {
#if defined(INTERNAL_MODULE_PXX2) #if defined(INTERNAL_MODULE_PXX2)
case INTERNAL_MODULE: case INTERNAL_MODULE:
IntmoduleSerialDriver.sendBuffer(outputTelemetryBuffer.data, IntmoduleSerialDriver.sendBuffer(uart_ctx, outputTelemetryBuffer.data,
ptr - outputTelemetryBuffer.data); ptr - outputTelemetryBuffer.data);
return; return;
#endif #endif
@@ -316,8 +316,6 @@ static const etx_serial_init serialInitParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleFifoReceive, .on_receive = intmoduleFifoReceive,
.on_error = intmoduleFifoError, .on_error = intmoduleFifoError,
}; };
@@ -354,7 +352,7 @@ const char * FrskyDeviceFirmwareUpdate::doFlashFirmware(const char * filename, P
etx_serial_init params(serialInitParams); etx_serial_init params(serialInitParams);
params.baudrate = 38400; params.baudrate = 38400;
IntmoduleSerialDriver.init(&params); uart_ctx = IntmoduleSerialDriver.init(&params);
GPIO_SetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN); GPIO_SetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN);
result = uploadFileToHorusXJT(filename, &file, progressHandler); result = uploadFileToHorusXJT(filename, &file, progressHandler);
@@ -370,7 +368,7 @@ const char * FrskyDeviceFirmwareUpdate::doFlashFirmware(const char * filename, P
case INTERNAL_MODULE: { case INTERNAL_MODULE: {
etx_serial_init params(serialInitParams); etx_serial_init params(serialInitParams);
params.baudrate = 57600; params.baudrate = 57600;
IntmoduleSerialDriver.init(&params); uart_ctx = IntmoduleSerialDriver.init(&params);
} break; } break;
#endif #endif
@@ -402,14 +400,14 @@ const char * FrskyDeviceFirmwareUpdate::uploadFileToHorusXJT(const char * filena
return STR_DEVICE_NO_RESPONSE; return STR_DEVICE_NO_RESPONSE;
} }
IntmoduleSerialDriver.sendByte(0x81); IntmoduleSerialDriver.sendByte(uart_ctx, 0x81);
readBuffer(frame, 1, 100); readBuffer(frame, 1, 100);
if (!readBuffer(frame, 8, 100) || frame[0] != 0x02) { if (!readBuffer(frame, 8, 100) || frame[0] != 0x02) {
return STR_DEVICE_NO_RESPONSE; return STR_DEVICE_NO_RESPONSE;
} }
IntmoduleSerialDriver.sendByte(0x82); IntmoduleSerialDriver.sendByte(uart_ctx, 0x82);
readBuffer(frame, 1, 100); readBuffer(frame, 1, 100);
uint8_t index = 0; uint8_t index = 0;
@@ -427,7 +425,7 @@ const char * FrskyDeviceFirmwareUpdate::uploadFileToHorusXJT(const char * filena
return STR_DEVICE_WRONG_REQUEST; return STR_DEVICE_WRONG_REQUEST;
if (count == 0) { if (count == 0) {
IntmoduleSerialDriver.sendByte(0xA1); IntmoduleSerialDriver.sendByte(uart_ctx, 0xA1);
RTOS_WAIT_MS(50); RTOS_WAIT_MS(50);
return nullptr; return nullptr;
} }
@@ -435,15 +433,15 @@ const char * FrskyDeviceFirmwareUpdate::uploadFileToHorusXJT(const char * filena
if (count < 1024) if (count < 1024)
memset(((uint8_t *)buffer) + count, 0, 1024 - count); memset(((uint8_t *)buffer) + count, 0, 1024 - count);
IntmoduleSerialDriver.sendByte(frame[0] + 0x80); IntmoduleSerialDriver.sendByte(uart_ctx, frame[0] + 0x80);
IntmoduleSerialDriver.sendByte(frame[1]); IntmoduleSerialDriver.sendByte(uart_ctx, frame[1]);
uint16_t crc_16 = crc16(CRC_1189, (uint8_t *)buffer, 1024, crc16(CRC_1189, &frame[1], 1)); uint16_t crc_16 = crc16(CRC_1189, (uint8_t *)buffer, 1024, crc16(CRC_1189, &frame[1], 1));
for (size_t i = 0; i < sizeof(buffer); i++) { for (size_t i = 0; i < sizeof(buffer); i++) {
IntmoduleSerialDriver.sendByte(((uint8_t *)buffer)[i]); IntmoduleSerialDriver.sendByte(uart_ctx, ((uint8_t *)buffer)[i]);
} }
IntmoduleSerialDriver.sendByte(crc_16 >> 8); IntmoduleSerialDriver.sendByte(uart_ctx, crc_16 >> 8);
IntmoduleSerialDriver.sendByte(crc_16); IntmoduleSerialDriver.sendByte(uart_ctx, crc_16);
index++; index++;
} }
@@ -597,7 +595,7 @@ const char * FrskyChipFirmwareUpdate::waitAnswer(uint8_t & status)
for (uint8_t i = 0; i < sizeof(buffer); i++) { for (uint8_t i = 0; i < sizeof(buffer); i++) {
uint32_t retry = 0; uint32_t retry = 0;
while (true) { while (true) {
if (telemetryGetByte(&buffer[i])) { if (sportGetByte(&buffer[i])) {
if ((i == 0 && buffer[0] != 0x7F) || if ((i == 0 && buffer[0] != 0x7F) ||
(i == 1 && buffer[1] != 0xFE) || (i == 1 && buffer[1] != 0xFE) ||
(i == 10 && buffer[10] != 0x0D) || (i == 10 && buffer[10] != 0x0D) ||
+1
View File
@@ -137,6 +137,7 @@ class FrskyDeviceFirmwareUpdate {
uint32_t address = 0; uint32_t address = 0;
ModuleIndex module; ModuleIndex module;
uint8_t frame[12]; uint8_t frame[12];
void* uart_ctx = nullptr;
void startFrame(uint8_t command); void startFrame(uint8_t command);
void sendFrame(); void sendFrame();
+34 -31
View File
@@ -28,6 +28,8 @@
#include "debug.h" #include "debug.h"
#include "timers_driver.h" #include "timers_driver.h"
#include <memory>
#if defined(LIBOPENUI) #if defined(LIBOPENUI)
#include "libopenui.h" #include "libopenui.h"
#else #else
@@ -50,24 +52,26 @@ class MultiFirmwareUpdateDriver
{ {
public: public:
MultiFirmwareUpdateDriver() {} MultiFirmwareUpdateDriver() {}
const char * flashFirmware(FIL * file, const char * label, ProgressHandler progressHandler) const; virtual ~MultiFirmwareUpdateDriver() {}
const char* flashFirmware(FIL* file, const char* label,
ProgressHandler progressHandler);
protected: protected:
virtual void moduleOn() const = 0; virtual void moduleOn() const = 0;
virtual void init(bool inverted) const = 0; virtual void init(bool inverted) = 0;
virtual bool getByte(uint8_t & byte) const = 0; virtual bool getByte(uint8_t & byte) const = 0;
virtual void sendByte(uint8_t byte) const = 0; virtual void sendByte(uint8_t byte) const = 0;
virtual void clear() const = 0; virtual void clear() const = 0;
virtual void deinit(bool inverted) const {} virtual void deinit(bool inverted) {}
private: private:
bool getRxByte(uint8_t & byte) const; bool getRxByte(uint8_t & byte) const;
bool checkRxByte(uint8_t byte) const; bool checkRxByte(uint8_t byte) const;
const char * waitForInitialSync(bool& inverted) const; const char * waitForInitialSync(bool& inverted);
const char * getDeviceSignature(uint8_t * signature) const; const char * getDeviceSignature(uint8_t * signature) const;
const char * loadAddress(uint32_t offset) const; const char * loadAddress(uint32_t offset) const;
const char * progPage(uint8_t * buffer, uint16_t size) const; const char * progPage(uint8_t * buffer, uint16_t size) const;
void leaveProgMode(bool inverted) const; void leaveProgMode(bool inverted);
}; };
#if defined(INTERNAL_MODULE_MULTI) #if defined(INTERNAL_MODULE_MULTI)
@@ -78,8 +82,6 @@ static const etx_serial_init serialInitParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleFifoReceive, .on_receive = intmoduleFifoReceive,
.on_error = intmoduleFifoError, .on_error = intmoduleFifoError,
}; };
@@ -90,16 +92,18 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
MultiInternalUpdateDriver() {} MultiInternalUpdateDriver() {}
protected: protected:
void* uart_ctx = nullptr;
void moduleOn() const override void moduleOn() const override
{ {
INTERNAL_MODULE_ON(); INTERNAL_MODULE_ON();
} }
void init(bool inverted) const override void init(bool inverted) override
{ {
etx_serial_init params(serialInitParams); etx_serial_init params(serialInitParams);
params.baudrate = 57600; params.baudrate = 57600;
IntmoduleSerialDriver.init(&params); uart_ctx = IntmoduleSerialDriver.init(&params);
} }
bool getByte(uint8_t & byte) const override bool getByte(uint8_t & byte) const override
@@ -109,7 +113,7 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
void sendByte(uint8_t byte) const override void sendByte(uint8_t byte) const override
{ {
IntmoduleSerialDriver.sendByte(byte); IntmoduleSerialDriver.sendByte(uart_ctx, byte);
} }
void clear() const override void clear() const override
@@ -117,13 +121,13 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
intmoduleFifo.clear(); intmoduleFifo.clear();
} }
void deinit(bool inverted) const override void deinit(bool inverted) override
{ {
IntmoduleSerialDriver.deinit(uart_ctx);
uart_ctx = nullptr;
clear(); clear();
} }
}; };
static const MultiInternalUpdateDriver multiInternalUpdateDriver;
#endif #endif
class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
@@ -137,7 +141,7 @@ class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
} }
void init(bool inverted) const override void init(bool inverted) override
{ {
#if !defined(EXTMODULE_USART) #if !defined(EXTMODULE_USART)
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
@@ -157,7 +161,7 @@ class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
bool getByte(uint8_t & byte) const override bool getByte(uint8_t & byte) const override
{ {
return telemetryGetByte(&byte); return sportGetByte(&byte);
} }
void sendByte(uint8_t byte) const override void sendByte(uint8_t byte) const override
@@ -172,7 +176,7 @@ class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
telemetryClearFifo(); telemetryClearFifo();
} }
void deinit(bool inverted) const override void deinit(bool inverted) override
{ {
if (inverted) if (inverted)
telemetryPortInvertedInit(0); telemetryPortInvertedInit(0);
@@ -183,8 +187,6 @@ class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
} }
}; };
static const MultiExternalUpdateDriver multiExternalUpdateDriver;
class MultiExtSportUpdateDriver: public MultiFirmwareUpdateDriver class MultiExtSportUpdateDriver: public MultiFirmwareUpdateDriver
{ {
public: public:
@@ -196,14 +198,14 @@ class MultiExtSportUpdateDriver: public MultiFirmwareUpdateDriver
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
} }
void init(bool inverted) const override void init(bool inverted) override
{ {
telemetryPortInit(57600, TELEMETRY_SERIAL_WITHOUT_DMA); telemetryPortInit(57600, TELEMETRY_SERIAL_WITHOUT_DMA);
} }
bool getByte(uint8_t & byte) const override bool getByte(uint8_t & byte) const override
{ {
return telemetryGetByte(&byte); return sportGetByte(&byte);
} }
void sendByte(uint8_t byte) const override void sendByte(uint8_t byte) const override
@@ -217,15 +219,13 @@ class MultiExtSportUpdateDriver: public MultiFirmwareUpdateDriver
telemetryClearFifo(); telemetryClearFifo();
} }
void deinit(bool inverted) const override void deinit(bool inverted) override
{ {
telemetryPortInit(0, 0); telemetryPortInit(0, 0);
clear(); clear();
} }
}; };
static const MultiExtSportUpdateDriver multiExtSportUpdateDriver;
bool MultiFirmwareUpdateDriver::getRxByte(uint8_t & byte) const bool MultiFirmwareUpdateDriver::getRxByte(uint8_t & byte) const
{ {
uint16_t time; uint16_t time;
@@ -251,7 +251,7 @@ bool MultiFirmwareUpdateDriver::checkRxByte(uint8_t byte) const
return getRxByte(rxchar) ? rxchar == byte : false; return getRxByte(rxchar) ? rxchar == byte : false;
} }
const char * MultiFirmwareUpdateDriver::waitForInitialSync(bool & inverted) const const char * MultiFirmwareUpdateDriver::waitForInitialSync(bool & inverted)
{ {
uint8_t byte; uint8_t byte;
int retries = 200; int retries = 200;
@@ -375,7 +375,7 @@ const char * MultiFirmwareUpdateDriver::progPage(uint8_t * buffer, uint16_t size
return nullptr; return nullptr;
} }
void MultiFirmwareUpdateDriver::leaveProgMode(bool inverted) const void MultiFirmwareUpdateDriver::leaveProgMode(bool inverted)
{ {
sendByte(STK_LEAVE_PROGMODE); sendByte(STK_LEAVE_PROGMODE);
sendByte(CRC_EOP); sendByte(CRC_EOP);
@@ -385,7 +385,8 @@ void MultiFirmwareUpdateDriver::leaveProgMode(bool inverted) const
deinit(inverted); deinit(inverted);
} }
const char * MultiFirmwareUpdateDriver::flashFirmware(FIL * file, const char * label, ProgressHandler progressHandler) const const char* MultiFirmwareUpdateDriver::flashFirmware(
FIL* file, const char* label, ProgressHandler progressHandler)
{ {
#if defined(SIMU) #if defined(SIMU)
for (uint16_t i = 0; i < 100; i++) { for (uint16_t i = 0; i < 100; i++) {
@@ -616,13 +617,15 @@ bool MultiDeviceFirmwareUpdate::flashFirmware(const char * filename, ProgressHan
} }
} }
const MultiFirmwareUpdateDriver * driver = &multiExternalUpdateDriver; std::unique_ptr<MultiFirmwareUpdateDriver> driver;
if (module == EXTERNAL_MODULE)
driver.reset(new MultiExternalUpdateDriver());
#if defined(INTERNAL_MODULE_MULTI) #if defined(INTERNAL_MODULE_MULTI)
if (module == INTERNAL_MODULE) else if (module == INTERNAL_MODULE)
driver = &multiInternalUpdateDriver; driver.reset(new MultiInternalUpdateDriver());
#endif #endif
if (type == MULTI_TYPE_ELRS) else if (type == MULTI_TYPE_ELRS)
driver = &multiExtSportUpdateDriver; driver.reset(new MultiExtSportUpdateDriver());
pausePulses(); pausePulses();
+84 -63
View File
@@ -91,9 +91,49 @@
{ "EVT_"#xxx"_LONG", EVT_KEY_LONG(yyy) }, \ { "EVT_"#xxx"_LONG", EVT_KEY_LONG(yyy) }, \
{ "EVT_"#xxx"_REPT", EVT_KEY_REPT(yyy) } { "EVT_"#xxx"_REPT", EVT_KEY_REPT(yyy) }
#if defined(LUA) && !defined(CLI) // Note:
Fifo<uint8_t, LUA_FIFO_SIZE> * luaRxFifo = nullptr; // - luaRxFifo & luaReceiveData are used only for USB serial
#endif // - otherwise, the AUX serial buffer is used directly
//
static Fifo<uint8_t, LUA_FIFO_SIZE>* luaRxFifo = nullptr;
static int luaRxFifoGetByte(void*, uint8_t* data)
{
if (!luaRxFifo) return -1;
return luaRxFifo->pop(*data);
}
void luaReceiveData(uint8_t* buf, uint32_t len)
{
if (!luaRxFifo) {
luaRxFifo = new Fifo<uint8_t, LUA_FIFO_SIZE>();
luaSetGetSerialByte(nullptr, luaRxFifoGetByte);
}
if (luaRxFifo) {
while(len--) luaRxFifo->push(*buf++);
}
}
static void (*luaSendDataCb)(void*, uint8_t) = nullptr;
static void* luaSendDataCtx = nullptr;
void luaSetSendCb(void* ctx, void (*cb)(void*, uint8_t))
{
luaSendDataCb = nullptr;
luaSendDataCtx = ctx;
luaSendDataCb = cb;
}
static int (*luaGetSerialByte)(void*, uint8_t*) = nullptr;
static void* luaGetSerialByteCtx = nullptr;
void luaSetGetSerialByte(void* ctx, int (*fct)(void*, uint8_t*))
{
luaGetSerialByte = nullptr;
luaGetSerialByteCtx = ctx;
luaGetSerialByte = fct;
}
/*luadoc /*luadoc
@function getVersion() @function getVersion()
@@ -1882,22 +1922,23 @@ Set baudrate for serial port(s) affected to LUA
*/ */
static int luaSetSerialBaudrate(lua_State * L) static int luaSetSerialBaudrate(lua_State * L)
{ {
#if defined(AUX_SERIAL) || defined(AUX2_SERIAL) // #if defined(AUX_SERIAL) || defined(AUX2_SERIAL)
unsigned int baudrate = luaL_checkunsigned(L, 1); // unsigned int baudrate = luaL_checkunsigned(L, 1);
#endif // #endif
#if defined(AUX_SERIAL) // TODO: add some callbacks for serial settings
if (auxSerialMode == UART_MODE_LUA) { // #if defined(AUX_SERIAL)
auxSerialStop(); // if (auxSerialMode == UART_MODE_LUA) {
auxSerialSetup(baudrate, false); // auxSerialStop();
} // auxSerialSetup(baudrate, false);
#endif // }
#if defined(AUX2_SERIAL) // #endif
if (aux2SerialMode == UART_MODE_LUA) { // #if defined(AUX2_SERIAL)
aux2SerialStop(); // if (aux2SerialMode == UART_MODE_LUA) {
aux2SerialSetup(baudrate, false); // aux2SerialStop();
} // aux2SerialSetup(baudrate, false);
#endif // }
// #endif
return 1; return 1;
} }
@@ -1917,30 +1958,15 @@ static int luaSerialWrite(lua_State * L)
if (!str || len < 1) if (!str || len < 1)
return 0; return 0;
#if defined(USB_SERIAL) auto _sendCb = luaSendDataCb;
if (getSelectedUsbMode() == USB_SERIAL_MODE) { auto _ctx = luaSendDataCtx;
if (_sendCb) {
size_t wr_len = len; size_t wr_len = len;
const char* p = str; const char* p = str;
while(wr_len--) usbSerialPutc(*p++); while(wr_len--) _sendCb(_ctx, *p++);
} }
#endif
#if defined(AUX_SERIAL)
if (auxSerialMode == UART_MODE_LUA) {
size_t wr_len = len;
const char* p = str;
while(wr_len--) auxSerialPutc(*p++);
}
#endif
#if defined(AUX2_SERIAL)
if (aux2SerialMode == UART_MODE_LUA) {
size_t wr_len = len;
const char* p = str;
while(wr_len--) aux2SerialPutc(*p++);
}
#endif
return 0; return 0;
} }
@@ -1962,34 +1988,29 @@ static int luaSerialRead(lua_State * L)
#if defined(LUA) && !defined(CLI) #if defined(LUA) && !defined(CLI)
int num = luaL_optunsigned(L, 1, 0); int num = luaL_optunsigned(L, 1, 0);
if (!luaRxFifo) {
// TODO:
// - check which serial port has been assigned this function
// - set the receive callback on that serial port
//
luaRxFifo = new Fifo<uint8_t, LUA_FIFO_SIZE>();
if (!luaRxFifo) {
lua_pushlstring(L, "", 0);
return 1;
}
}
uint8_t str[LUA_FIFO_SIZE]; uint8_t str[LUA_FIFO_SIZE];
uint8_t *p = str; uint8_t *p = str;
while (luaRxFifo->pop(*p)) {
p++; // increment only when pop was successful auto _getByte = luaGetSerialByte;
if (p - str >= LUA_FIFO_SIZE) { auto _ctx = luaGetSerialByteCtx;
// buffer full
break; if (_getByte) {
} while (_getByte(_ctx, p) > 0) {
if (num == 0) { p++; // increment only when pop was successful
if (*(p - 1) == '\n' || *(p - 1) == '\r') { if (p - str >= LUA_FIFO_SIZE) {
// found newline // buffer full
break;
}
if (num == 0) {
if (*(p - 1) == '\n' || *(p - 1) == '\r') {
// found newline
break;
}
}
else if (p - str >= num) {
// requested number of characters reached
break; break;
} }
}
else if (p - str >= num) {
// requested number of characters reached
break;
} }
} }
lua_pushlstring(L, (const char*)str, p - str); lua_pushlstring(L, (const char*)str, p - str);
+4 -3
View File
@@ -48,10 +48,11 @@ extern "C" {
#endif #endif
#endif #endif
#if !defined(CLI) || defined(AUX2_SERIAL) // LUA serial connection
#define LUA_FIFO_SIZE 256 #define LUA_FIFO_SIZE 256
extern Fifo<uint8_t, LUA_FIFO_SIZE> * luaRxFifo; void luaReceiveData(uint8_t* buf, uint32_t len);
#endif void luaSetSendCb(void* ctx, void (*cb)(void*, uint8_t));
void luaSetGetSerialByte(void* ctx, int (*fct)(void*, uint8_t*));
extern lua_State * lsScripts; extern lua_State * lsScripts;
+20
View File
@@ -26,6 +26,10 @@
#include "libopenui.h" #include "libopenui.h"
#endif #endif
#if defined(CLI)
#include "cli.h"
#endif
uint8_t currentSpeakerVolume = 255; uint8_t currentSpeakerVolume = 255;
uint8_t requiredSpeakerVolume = 255; uint8_t requiredSpeakerVolume = 255;
uint8_t currentBacklightBright = 0; uint8_t currentBacklightBright = 0;
@@ -153,6 +157,22 @@ void handleUsbConnection()
opentxClose(false); opentxClose(false);
usbPluggedIn(); usbPluggedIn();
} }
#if defined(USB_SERIAL)
else if (getSelectedUsbMode() == USB_SERIAL_MODE) {
// TODO: query USB serial mode
// -> for now, only CLI / DEBUG / LUA
#if defined(CLI)
cliSetSendCb(nullptr, usbSerialPutc);
usbSerialSetReceiveDataCb(cliReceiveData);
#elif defined(DEBUG)
dbgSerialSetSendCb(nullptr, usbSerialPutc);
usbSerialSetReceiveDataCb(nullptr);
#elif defined(LUA)
luaSetSendCb(nullptr, usbSerialPutc);
usbSerialSetReceiveDataCb(luaReceiveData);
#endif
}
#endif
usbStart(); usbStart();
TRACE("USB started"); TRACE("USB started");
+2 -8
View File
@@ -1869,14 +1869,8 @@ void opentxInit()
#endif #endif
#endif // #if !defined(EEPROM) #endif // #if !defined(EEPROM)
#if defined(AUX_SERIAL) initSerialPorts();
auxSerialInit(g_eeGeneral.auxSerialMode, modelTelemetryProtocol());
#endif
#if defined(AUX2_SERIAL)
aux2SerialInit(g_eeGeneral.aux2SerialMode, modelTelemetryProtocol());
#endif
currentSpeakerVolume = requiredSpeakerVolume = g_eeGeneral.speakerVolume + VOLUME_LEVEL_DEF; currentSpeakerVolume = requiredSpeakerVolume = g_eeGeneral.speakerVolume + VOLUME_LEVEL_DEF;
currentBacklightBright = requiredBacklightBright = g_eeGeneral.backlightBright; currentBacklightBright = requiredBacklightBright = g_eeGeneral.backlightBright;
#if !defined(SOFTWARE_VOLUME) #if !defined(SOFTWARE_VOLUME)
+2 -8
View File
@@ -45,8 +45,6 @@ const etx_serial_init afhds2SerialInitParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleFifoReceive, .on_receive = intmoduleFifoReceive,
.on_error = intmoduleFifoError, .on_error = intmoduleFifoError,
}; };
@@ -69,11 +67,9 @@ static void* afhds2Init(uint8_t module)
static void afhds2DeInit(void* context) static void afhds2DeInit(void* context)
{ {
(void)context;
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
intmoduleFifo.clear(); intmoduleFifo.clear();
IntmoduleSerialDriver.deinit(); IntmoduleSerialDriver.deinit(context);
// mixer setup // mixer setup
mixerSchedulerSetPeriod(INTERNAL_MODULE, 0); mixerSchedulerSetPeriod(INTERNAL_MODULE, 0);
@@ -97,11 +93,9 @@ static void afhds2SetupPulses(void* context, int16_t* channels, uint8_t nChannel
static void afhds2SendPulses(void* context) static void afhds2SendPulses(void* context)
{ {
(void)context;
uint8_t* data = (uint8_t*)intmodulePulsesData.flysky.pulses; uint8_t* data = (uint8_t*)intmodulePulsesData.flysky.pulses;
uint16_t size = intmodulePulsesData.flysky.ptr - data; uint16_t size = intmodulePulsesData.flysky.ptr - data;
IntmoduleSerialDriver.sendBuffer(data, size); IntmoduleSerialDriver.sendBuffer(context, data, size);
} }
const etx_module_driver_t Afhds2InternalDriver = { const etx_module_driver_t Afhds2InternalDriver = {
+1 -5
View File
@@ -134,8 +134,6 @@ static const etx_serial_init intmoduleCrossfireInitParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleCRSF_rx, .on_receive = intmoduleCRSF_rx,
.on_error = nullptr, .on_error = nullptr,
}; };
@@ -177,9 +175,7 @@ static void crossfireSetupPulsesInternal(void* context, int16_t* channels, uint8
static void crossfireSendPulsesInternal(void* context) static void crossfireSendPulsesInternal(void* context)
{ {
(void)context; IntmoduleSerialDriver.sendBuffer(context, intmodulePulsesData.crossfire.pulses,
IntmoduleSerialDriver.sendBuffer(intmodulePulsesData.crossfire.pulses,
intmodulePulsesData.crossfire.length); intmodulePulsesData.crossfire.length);
} }
+4 -9
View File
@@ -60,8 +60,6 @@ etx_serial_init multiSerialInitParams = {
.stop_bits = ETX_StopBits_Two, .stop_bits = ETX_StopBits_Two,
.word_length = ETX_WordLength_9, .word_length = ETX_WordLength_9,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleFifoReceive, .on_receive = intmoduleFifoReceive,
.on_error = intmoduleFifoError, .on_error = intmoduleFifoError,
}; };
@@ -260,7 +258,7 @@ static void* multiInit(uint8_t module)
// serial port setup // serial port setup
intmodulePulsesData.multi.initFrame(); intmodulePulsesData.multi.initFrame();
intmoduleFifo.clear(); intmoduleFifo.clear();
IntmoduleSerialDriver.init(&multiSerialInitParams); void* uart_ctx = IntmoduleSerialDriver.init(&multiSerialInitParams);
// mixer setup // mixer setup
mixerSchedulerSetPeriod(INTERNAL_MODULE, MULTIMODULE_PERIOD); mixerSchedulerSetPeriod(INTERNAL_MODULE, MULTIMODULE_PERIOD);
@@ -276,16 +274,14 @@ static void* multiInit(uint8_t module)
TRACE("counter = %d", moduleState[INTERNAL_MODULE].counter); TRACE("counter = %d", moduleState[INTERNAL_MODULE].counter);
#endif #endif
return nullptr; return uart_ctx;
} }
static void multiDeInit(void* context) static void multiDeInit(void* context)
{ {
(void)context;
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
mixerSchedulerSetPeriod(INTERNAL_MODULE, 0); mixerSchedulerSetPeriod(INTERNAL_MODULE, 0);
IntmoduleSerialDriver.deinit(); IntmoduleSerialDriver.deinit(context);
} }
static void multiSetupPulses(void* context, int16_t* channels, uint8_t nChannels) static void multiSetupPulses(void* context, int16_t* channels, uint8_t nChannels)
@@ -301,8 +297,7 @@ static void multiSetupPulses(void* context, int16_t* channels, uint8_t nChannels
static void multiSendPulses(void* context) static void multiSendPulses(void* context)
{ {
(void)context; IntmoduleSerialDriver.sendBuffer(context, intmodulePulsesData.multi.getData(),
IntmoduleSerialDriver.sendBuffer(intmodulePulsesData.multi.getData(),
intmodulePulsesData.multi.getSize()); intmodulePulsesData.multi.getSize());
} }
+3 -19
View File
@@ -476,8 +476,8 @@ void enablePulsesExternalModule(uint8_t protocol)
#if defined(PXX1) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML) #if defined(PXX1) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML)
case PROTOCOL_CHANNELS_PXX1_SERIAL: case PROTOCOL_CHANNELS_PXX1_SERIAL:
extmodulePxx1SerialStart(); externalModuleContext = Pxx1ExternalSerialDriver.init(EXTERNAL_MODULE);
mixerSchedulerSetPeriod(EXTERNAL_MODULE, EXTMODULE_PXX1_SERIAL_PERIOD); externalModuleDriver = &Pxx1ExternalSerialDriver;
break; break;
#endif #endif
@@ -522,12 +522,8 @@ void enablePulsesExternalModule(uint8_t protocol)
#if defined(MULTIMODULE) #if defined(MULTIMODULE)
case PROTOCOL_CHANNELS_MULTIMODULE: case PROTOCOL_CHANNELS_MULTIMODULE:
#if defined(PCBSKY9X)
extmoduleSerialStart(MULTIMODULE_BAUDRATE, MULTIMODULE_PERIOD * 2000, true);
#else
extmoduleSerialStart(); extmoduleSerialStart();
mixerSchedulerSetPeriod(EXTERNAL_MODULE, MULTIMODULE_PERIOD); mixerSchedulerSetPeriod(EXTERNAL_MODULE, MULTIMODULE_PERIOD);
#endif
getMultiModuleStatus(EXTERNAL_MODULE).failsafeChecked = false; getMultiModuleStatus(EXTERNAL_MODULE).failsafeChecked = false;
getMultiModuleStatus(EXTERNAL_MODULE).flags = 0; getMultiModuleStatus(EXTERNAL_MODULE).flags = 0;
#if defined(MULTI_PROTOLIST) #if defined(MULTI_PROTOLIST)
@@ -558,6 +554,7 @@ void enablePulsesExternalModule(uint8_t protocol)
#if defined(AFHDS3) #if defined(AFHDS3)
case PROTOCOL_CHANNELS_AFHDS3: case PROTOCOL_CHANNELS_AFHDS3:
// convert to serial module interface
extmodulePulsesData.afhds3.init(EXTERNAL_MODULE); extmodulePulsesData.afhds3.init(EXTERNAL_MODULE);
extmoduleSerialStart(); extmoduleSerialStart();
mixerSchedulerSetPeriod(EXTERNAL_MODULE, AFHDS3_COMMAND_TIMEOUT * 1000 /* us */); mixerSchedulerSetPeriod(EXTERNAL_MODULE, AFHDS3_COMMAND_TIMEOUT * 1000 /* us */);
@@ -591,12 +588,6 @@ bool setupPulsesExternalModule(uint8_t protocol)
return true; return true;
#endif #endif
#if defined(PXX1) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
extmodulePulsesData.pxx_uart.setupFrame(EXTERNAL_MODULE);
return true;
#endif
#if defined(SBUS) #if defined(SBUS)
case PROTOCOL_CHANNELS_SBUS: case PROTOCOL_CHANNELS_SBUS:
setupPulsesSbus(); setupPulsesSbus();
@@ -681,13 +672,6 @@ void extmoduleSendNextFrame()
break; break;
#endif #endif
#if defined(PXX1) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
ExtmoduleSerialDriver.sendBuffer(extmodulePulsesData.pxx_uart.getData(),
extmodulePulsesData.pxx_uart.getSize());
break;
#endif
#if defined(AFHDS3) #if defined(AFHDS3)
case PROTOCOL_CHANNELS_AFHDS3: case PROTOCOL_CHANNELS_AFHDS3:
#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) #if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO)
+61 -11
View File
@@ -231,17 +231,13 @@ static const etx_serial_init pxx1SerialInit = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = false, .rx_enable = false,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleFifoReceive, .on_receive = intmoduleFifoReceive,
.on_error = intmoduleFifoError, .on_error = intmoduleFifoError,
}; };
static void* pxx1InitInternal(uint8_t module) static void* pxx1InitInternal(uint8_t module)
{ {
(void)module; void* uart_ctx = IntmoduleSerialDriver.init(&pxx1SerialInit);
IntmoduleSerialDriver.init(&pxx1SerialInit);
#if defined(INTMODULE_HEARTBEAT) #if defined(INTMODULE_HEARTBEAT)
init_intmodule_heartbeat(); init_intmodule_heartbeat();
@@ -249,19 +245,17 @@ static void* pxx1InitInternal(uint8_t module)
mixerSchedulerSetPeriod(INTERNAL_MODULE, INTMODULE_PXX1_SERIAL_PERIOD); mixerSchedulerSetPeriod(INTERNAL_MODULE, INTMODULE_PXX1_SERIAL_PERIOD);
INTERNAL_MODULE_ON(); INTERNAL_MODULE_ON();
return nullptr; return uart_ctx;
} }
static void pxx1DeInitInternal(void* context) static void pxx1DeInitInternal(void* context)
{ {
(void)context;
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
mixerSchedulerSetPeriod(INTERNAL_MODULE, 0); mixerSchedulerSetPeriod(INTERNAL_MODULE, 0);
#if defined(INTMODULE_HEARTBEAT) #if defined(INTMODULE_HEARTBEAT)
stop_intmodule_heartbeat(); stop_intmodule_heartbeat();
#endif #endif
IntmoduleSerialDriver.deinit(); IntmoduleSerialDriver.deinit(context);
} }
static void pxx1SetupPulsesInternal(void* context, int16_t* channels, uint8_t nChannels) static void pxx1SetupPulsesInternal(void* context, int16_t* channels, uint8_t nChannels)
@@ -276,8 +270,7 @@ static void pxx1SetupPulsesInternal(void* context, int16_t* channels, uint8_t nC
static void pxx1SendPulsesInternal(void* context) static void pxx1SendPulsesInternal(void* context)
{ {
(void)context; IntmoduleSerialDriver.sendBuffer(context, intmodulePulsesData.pxx_uart.getData(),
IntmoduleSerialDriver.sendBuffer(intmodulePulsesData.pxx_uart.getData(),
intmodulePulsesData.pxx_uart.getSize()); intmodulePulsesData.pxx_uart.getSize());
} }
@@ -290,3 +283,60 @@ const etx_module_driver_t Pxx1InternalSerialDriver = {
}; };
#endif #endif
#if defined(EXTMODULE_USART) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML)
#include "extmodule_serial_driver.h"
static const etx_serial_init pxx1ExtSerialInit = {
.baudrate = EXTMODULE_PXX1_SERIAL_BAUDRATE,
.parity = ETX_Parity_None,
.stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8,
.rx_enable = false,
.on_receive = extmoduleFifoReceive,
.on_error = extmoduleFifoError,
};
static void* pxx1InitExternal(uint8_t module)
{
void* uart_ctx = ExtmoduleSerialDriver.init(&pxx1ExtSerialInit);
mixerSchedulerSetPeriod(EXTERNAL_MODULE, EXTMODULE_PXX1_SERIAL_PERIOD);
EXTERNAL_MODULE_ON();
return uart_ctx;
}
static void pxx1DeInitExternal(void* context)
{
EXTERNAL_MODULE_OFF();
mixerSchedulerSetPeriod(EXTERNAL_MODULE, 0);
ExtmoduleSerialDriver.deinit(context);
}
static void pxx1SetupPulsesExternal(void* context, int16_t* channels, uint8_t nChannels)
{
(void)context;
// TODO:
(void)channels;
(void)nChannels;
extmodulePulsesData.pxx_uart.setupFrame(EXTERNAL_MODULE);
}
static void pxx1SendPulsesExternal(void* context)
{
ExtmoduleSerialDriver.sendBuffer(context, extmodulePulsesData.pxx_uart.getData(),
extmodulePulsesData.pxx_uart.getSize());
}
const etx_module_driver_t Pxx1ExternalSerialDriver = {
.protocol = PROTOCOL_CHANNELS_PXX1_SERIAL,
.init = pxx1InitExternal,
.deinit = pxx1DeInitExternal,
.setupPulses = pxx1SetupPulsesExternal,
.sendPulses = pxx1SendPulsesExternal,
};
#endif
+6
View File
@@ -168,6 +168,12 @@ typedef Pxx1Pulses<UartPxx1Transport> UartPxx1Pulses;
typedef Pxx1Pulses<StandardPxx1Transport<PwmPxxBitTransport>> PwmPxx1Pulses; typedef Pxx1Pulses<StandardPxx1Transport<PwmPxxBitTransport>> PwmPxx1Pulses;
typedef Pxx1Pulses<StandardPxx1Transport<SerialPxxBitTransport>> SerialPxx1Pulses; typedef Pxx1Pulses<StandardPxx1Transport<SerialPxxBitTransport>> SerialPxx1Pulses;
#if defined(INTMODULE_USART)
extern const etx_module_driver_t Pxx1InternalSerialDriver; extern const etx_module_driver_t Pxx1InternalSerialDriver;
#endif
#if defined(EXTMODULE_USART)
extern const etx_module_driver_t Pxx1ExternalSerialDriver;
#endif
#endif #endif
+8 -17
View File
@@ -36,8 +36,6 @@ const etx_serial_init pxx2SerialInitParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = intmoduleFifoReceive, .on_receive = intmoduleFifoReceive,
.on_error = intmoduleFifoError, .on_error = intmoduleFifoError,
}; };
@@ -652,7 +650,7 @@ void Pxx2OtaUpdate::flashFirmware(const char * filename, ProgressHandler progres
static void* pxx2InitInternal(uint8_t moduleType) static void* pxx2InitInternal(uint8_t moduleType)
{ {
intmoduleFifo.clear(); intmoduleFifo.clear();
IntmoduleSerialDriver.init(&pxx2SerialInitParams); void* uart_ctx = IntmoduleSerialDriver.init(&pxx2SerialInitParams);
resetAccessAuthenticationCount(); resetAccessAuthenticationCount();
#if defined(INTMODULE_HEARTBEAT) #if defined(INTMODULE_HEARTBEAT)
@@ -662,13 +660,13 @@ static void* pxx2InitInternal(uint8_t moduleType)
mixerSchedulerSetPeriod(INTERNAL_MODULE, PXX2_PERIOD); mixerSchedulerSetPeriod(INTERNAL_MODULE, PXX2_PERIOD);
INTERNAL_MODULE_ON(); INTERNAL_MODULE_ON();
return nullptr; return uart_ctx;
} }
static void pxx2DeInitInternal(void* context) static void pxx2DeInitInternal(void* context)
{ {
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
IntmoduleSerialDriver.deinit(); IntmoduleSerialDriver.deinit(context);
#if defined(INTMODULE_HEARTBEAT) #if defined(INTMODULE_HEARTBEAT)
stop_intmodule_heartbeat(); stop_intmodule_heartbeat();
#endif #endif
@@ -694,10 +692,8 @@ static void pxx2SetupPulsesInternal(void* context, int16_t* channels, uint8_t nC
static void pxx2SendPulsesInternal(void* context) static void pxx2SendPulsesInternal(void* context)
{ {
(void)context;
if (pxx2InternalSendNextFrame) { if (pxx2InternalSendNextFrame) {
IntmoduleSerialDriver.sendBuffer(intmodulePulsesData.pxx2.getData(), IntmoduleSerialDriver.sendBuffer(context, intmodulePulsesData.pxx2.getData(),
intmodulePulsesData.pxx2.getSize()); intmodulePulsesData.pxx2.getSize());
} }
} }
@@ -721,8 +717,6 @@ static const etx_serial_init pxx2ExtSerialInitParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = extmoduleFifoReceive, .on_receive = extmoduleFifoReceive,
.on_error = extmoduleFifoError, .on_error = extmoduleFifoError,
}; };
@@ -743,21 +737,19 @@ static void* pxx2InitExternal(uint8_t module)
{ {
etx_serial_init params(pxx2ExtSerialInitParams); etx_serial_init params(pxx2ExtSerialInitParams);
params.baudrate = PXX2_HIGHSPEED_BAUDRATE; params.baudrate = PXX2_HIGHSPEED_BAUDRATE;
ExtmoduleSerialDriver.init(&params); void* uart_ctx = ExtmoduleSerialDriver.init(&params);
mixerSchedulerSetPeriod(EXTERNAL_MODULE, PXX2_NO_HEARTBEAT_PERIOD); mixerSchedulerSetPeriod(EXTERNAL_MODULE, PXX2_NO_HEARTBEAT_PERIOD);
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
return nullptr; return uart_ctx;
} }
static void pxx2DeInitExternal(void* context) static void pxx2DeInitExternal(void* context)
{ {
(void)context;
EXTERNAL_MODULE_OFF(); EXTERNAL_MODULE_OFF();
mixerSchedulerSetPeriod(EXTERNAL_MODULE, 0); mixerSchedulerSetPeriod(EXTERNAL_MODULE, 0);
ExtmoduleSerialDriver.deinit(); ExtmoduleSerialDriver.deinit(context);
} }
static void pxx2SetupPulsesExternal(void* context, int16_t* channels, uint8_t nChannels) static void pxx2SetupPulsesExternal(void* context, int16_t* channels, uint8_t nChannels)
@@ -768,8 +760,7 @@ static void pxx2SetupPulsesExternal(void* context, int16_t* channels, uint8_t nC
static void pxx2SendPulsesExternal(void* context) static void pxx2SendPulsesExternal(void* context)
{ {
(void)context; ExtmoduleSerialDriver.sendBuffer(context, extmodulePulsesData.pxx2.getData(),
ExtmoduleSerialDriver.sendBuffer(extmodulePulsesData.pxx2.getData(),
extmodulePulsesData.pxx2.getSize()); extmodulePulsesData.pxx2.getSize());
} }
+41 -12
View File
@@ -36,14 +36,45 @@
#define SBUS_CH_CENTER 0x3E0 #define SBUS_CH_CENTER 0x3E0
static int (*_sbusAuxGetByte)(void*, uint8_t*) = nullptr;
static void* _sbusAuxGetByteCtx = nullptr;
void sbusSetAuxGetByte(void* ctx, int (*fct)(void*, uint8_t*))
{
_sbusAuxGetByte = nullptr;
_sbusAuxGetByteCtx = ctx;
_sbusAuxGetByte = fct;
}
int sbusAuxGetByte(uint8_t* byte)
{
auto _getByte = _sbusAuxGetByte;
auto _ctx = _sbusAuxGetByteCtx;
if (_getByte) {
return _getByte(_ctx, byte);
}
return -1;
}
static int (*sbusGetByte)(uint8_t*) = nullptr;
void sbusSetGetByte(int (*fct)(uint8_t*))
{
sbusGetByte = fct;
}
// Range for pulses (ppm input) is [-512:+512] // Range for pulses (ppm input) is [-512:+512]
void processSbusFrame(uint8_t * sbus, int16_t * pulses, uint32_t size) void processSbusFrame(uint8_t * sbus, int16_t * pulses, uint32_t size)
{ {
if (size != SBUS_FRAME_SIZE || sbus[0] != SBUS_START_BYTE || sbus[SBUS_FRAME_SIZE-1] != SBUS_END_BYTE) { if (size != SBUS_FRAME_SIZE || sbus[0] != SBUS_START_BYTE ||
return; // not a valid SBUS frame sbus[SBUS_FRAME_SIZE - 1] != SBUS_END_BYTE) {
return; // not a valid SBUS frame
} }
if ((sbus[SBUS_FLAGS_IDX] & (1<<SBUS_FAILSAFE_BIT)) || (sbus[SBUS_FLAGS_IDX] & (1<<SBUS_FRAMELOST_BIT))) { if ((sbus[SBUS_FLAGS_IDX] & (1 << SBUS_FAILSAFE_BIT)) ||
return; // SBUS invalid frame or failsafe mode (sbus[SBUS_FLAGS_IDX] & (1 << SBUS_FRAMELOST_BIT))) {
return; // SBUS invalid frame or failsafe mode
} }
sbus++; // skip start byte sbus++; // skip start byte
@@ -65,31 +96,29 @@ void processSbusFrame(uint8_t * sbus, int16_t * pulses, uint32_t size)
void processSbusInput() void processSbusInput()
{ {
#if !defined(SIMU)
uint8_t rxchar; uint8_t rxchar;
uint32_t active = 0; uint32_t active = 0;
static uint8_t SbusIndex = 0; static uint8_t SbusIndex = 0;
static uint16_t SbusTimer; static uint16_t SbusTimer;
static uint8_t SbusFrame[SBUS_FRAME_SIZE]; static uint8_t SbusFrame[SBUS_FRAME_SIZE];
while (sbusGetByte(&rxchar)) { auto _getByte = sbusGetByte;
while (_getByte && (_getByte(&rxchar) > 0)) {
active = 1; active = 1;
if (SbusIndex > SBUS_FRAME_SIZE-1) { if (SbusIndex > SBUS_FRAME_SIZE - 1) {
SbusIndex = SBUS_FRAME_SIZE-1; SbusIndex = SBUS_FRAME_SIZE - 1;
} }
SbusFrame[SbusIndex++] = rxchar; SbusFrame[SbusIndex++] = rxchar;
} }
if (active) { if (active) {
SbusTimer = getTmr2MHz(); SbusTimer = getTmr2MHz();
return; return;
} } else {
else {
if (SbusIndex) { if (SbusIndex) {
if ((uint16_t) (getTmr2MHz() - SbusTimer) > SBUS_FRAME_GAP_DELAY) { if ((uint16_t)(getTmr2MHz() - SbusTimer) > SBUS_FRAME_GAP_DELAY) {
processSbusFrame(SbusFrame, ppmInput, SbusIndex); processSbusFrame(SbusFrame, ppmInput, SbusIndex);
SbusIndex = 0; SbusIndex = 0;
} }
} }
} }
#endif
} }
+11
View File
@@ -25,6 +25,17 @@
#define SBUS_BAUDRATE 100000 #define SBUS_BAUDRATE 100000
#define SBUS_FRAME_SIZE 25 #define SBUS_FRAME_SIZE 25
// Setup SBUS AUX serial input
void sbusSetAuxGetByte(void* ctx, int (*fct)(void*, uint8_t*));
// SBUS AUX serial getter:
// if set, it will fetch data from the handler set
// with sbusSetAuxGetByte()
int sbusAuxGetByte(uint8_t* byte);
// Setup general SBUS input source
void sbusSetGetByte(int (*fct)(uint8_t*));
void processSbusInput(); void processSbusInput();
#endif // _SBUS_H_ #endif // _SBUS_H_
+256 -19
View File
@@ -24,42 +24,279 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include "aux_serial_driver.h" #include "aux_serial_driver.h"
#include "hal/serial_port.h"
#define PRINTF_BUFFER_SIZE 128 #define PRINTF_BUFFER_SIZE 128
void serialPutc(char c) { static void (*dbg_serial_putc)(void*, uint8_t) = nullptr;
#if !defined(BOOT) && defined(USB_SERIAL) static void* dbg_serial_ctx = nullptr;
if (getSelectedUsbMode() == USB_SERIAL_MODE)
usbSerialPutc(c); void dbgSerialSetSendCb(void* ctx, void (*cb)(void*, uint8_t))
#endif {
#if defined(AUX_SERIAL) dbg_serial_putc = nullptr;
if (auxSerialTracesEnabled()) dbg_serial_ctx = ctx;
auxSerialPutc(c); dbg_serial_putc = cb;
#endif
#if defined(AUX2_SERIAL)
if (aux2SerialTracesEnabled())
aux2SerialPutc(c);
#endif
} }
void serialPrintf(const char * format, ...) extern "C" void dbgSerialPutc(char c)
{
auto _putc = dbg_serial_putc;
auto _ctx = dbg_serial_ctx;
if (_putc) _putc(_ctx, c);
}
extern "C" void dbgSerialPrintf(const char * format, ...)
{ {
va_list arglist; va_list arglist;
char tmp[PRINTF_BUFFER_SIZE+1]; char tmp[PRINTF_BUFFER_SIZE+1];
// no need to do anything if we don't have an output
if (!dbg_serial_putc) return;
va_start(arglist, format); va_start(arglist, format);
vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist); vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist);
tmp[PRINTF_BUFFER_SIZE] = '\0'; tmp[PRINTF_BUFFER_SIZE] = '\0';
va_end(arglist); va_end(arglist);
const char *t = tmp; const char *t = tmp;
while (*t) { while (*t && dbg_serial_putc) {
serialPutc(*t++); dbg_serial_putc(dbg_serial_ctx, *t++);
} }
} }
void serialCrlf() extern "C" void dbgSerialCrlf()
{ {
serialPutc('\r'); dbgSerialPutc('\r');
serialPutc('\n'); dbgSerialPutc('\n');
}
static int getAuxSerialMode(uint8_t port_nr)
{
#if !defined(BOOT)
if (port_nr == 0) {
return g_eeGeneral.auxSerialMode;
}
// TODO: change in datastruct_private.h
#if defined(PCBHORUS) || defined(PCBNV14)
if (port_nr == 1) {
return g_eeGeneral.aux2SerialMode;
}
#endif
#endif
return UART_MODE_NONE;
}
struct AuxSerialPortState
{
uint8_t mode;
const etx_serial_port_t* port;
void* usart_ctx;
};
static AuxSerialPortState auxSerialPortStates[MAX_AUX_SERIAL];
static AuxSerialPortState* auxGetPortState(int port_nr)
{
if (port_nr >= MAX_AUX_SERIAL) return nullptr;
return &auxSerialPortStates[port_nr];
}
// TODO: replace serialSetupCallBacks & serialSetupPort
// with usage based handlers.
//
static void serialSetCallBacks(int mode, void* ctx, const etx_serial_port_t* port)
{
void (*sendByte)(void*, uint8_t) = nullptr;
int (*getByte)(void*, uint8_t*) = nullptr;
if (port) {
sendByte = port->uart->sendByte;
getByte = port->uart->getByte;
}
switch(mode) {
#if defined(DEBUG)
case UART_MODE_DEBUG:
// TODO: should we handle 2 outputs?
dbgSerialSetSendCb(ctx, sendByte);
(void)getByte;
break;
#endif
#if !defined(BOOT)
#if defined(LUA)
case UART_MODE_LUA:
luaSetSendCb(ctx, sendByte);
luaSetGetSerialByte(ctx, getByte);
break;
#endif
#if defined(SBUS_TRAINER)
case UART_MODE_SBUS_TRAINER:
sbusSetAuxGetByte(ctx, getByte);
break;
#endif
case UART_MODE_TELEMETRY:
telemetrySetGetByte(ctx, getByte);
break;
case UART_MODE_TELEMETRY_MIRROR:
telemetrySetMirrorCb(ctx, sendByte);
break;
#endif
}
}
static void serialSetupPort(int mode, etx_serial_init& params, bool& power_required)
{
switch (mode) {
#if defined(DEBUG) || defined(CLI)
case UART_MODE_DEBUG:
params.baudrate = DEBUG_BAUDRATE;
break;
#endif
#if !defined(BOOT)
case UART_MODE_TELEMETRY_MIRROR:
// TODO: query telemetry baudrate / add setting for module
power_required = true;
#if defined(CROSSFIRE)
if (modelTelemetryProtocol() == PROTOCOL_TELEMETRY_CROSSFIRE) {
params.baudrate = CROSSFIRE_TELEM_MIRROR_BAUDRATE;
break;
}
#endif
params.baudrate = FRSKY_TELEM_MIRROR_BAUDRATE;
break;
case UART_MODE_TELEMETRY:
if (modelTelemetryProtocol() == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
params.baudrate = FRSKY_D_BAUDRATE;
params.rx_enable = true;
power_required = true;
}
break;
case UART_MODE_SBUS_TRAINER:
params.baudrate = SBUS_BAUDRATE;
params.word_length = ETX_WordLength_9;
params.parity = ETX_Parity_Even;
params.stop_bits = ETX_StopBits_Two;
params.rx_enable = true;
power_required = true;
break;
#if defined(LUA)
case UART_MODE_LUA:
params.baudrate = LUA_DEFAULT_BAUDRATE;
params.rx_enable = true;
power_required = true;
break;
#endif
#endif
}
}
void serialInit(int port_nr, int mode)
{
if (port_nr >= MAX_AUX_SERIAL) return;
auto state = auxGetPortState(port_nr);
if (!state) return;
auto port = auxSerialGetPort(port_nr);
if (!port) return;
if (state->port) {
auto drv = state->port->uart;
if (drv->deinit) {
drv->deinit(state->usart_ctx);
}
if (state->mode != 0) {
// Clear callbacks
serialSetCallBacks(mode, nullptr, nullptr);
}
memset(state, 0, sizeof(AuxSerialPortState));
}
etx_serial_init params = {
.baudrate = 0,
.parity = ETX_Parity_None,
.stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8,
.rx_enable = false,
.on_receive = nullptr,
.on_error = nullptr,
};
bool power_required = false;
serialSetupPort(mode, params, power_required);
if (params.baudrate != 0) {
state->mode = mode;
state->port = port;
state->usart_ctx = port->uart->init(&params);
// Set power on/off
if (port->set_pwr) {
port->set_pwr(power_required);
}
// Update callbacks once the port is setup
serialSetCallBacks(mode, state->usart_ctx, state->port);
}
}
void initSerialPorts()
{
memset(auxSerialPortStates, 0, sizeof(auxSerialPortStates));
for (int port_nr = 0; port_nr < MAX_AUX_SERIAL; port_nr++) {
auto mode = getAuxSerialMode(port_nr);
serialInit(port_nr, mode);
}
}
uint8_t serialGetMode(int port_nr)
{
auto state = auxGetPortState(port_nr);
if (!state) return UART_MODE_NONE;
return state->mode;
}
uint8_t serialTracesEnabled(int port_nr)
{
#if defined(DEBUG)
return serialGetMode(port_nr) == UART_MODE_DEBUG;
#else
return false;
#endif
}
void serialStop(int port_nr)
{
auto state = auxGetPortState(port_nr);
if (!state) return;
if (state->port) {
auto drv = state->port->uart;
if (drv && drv->deinit) {
drv->deinit(state->usart_ctx);
}
memset(state, 0, sizeof(AuxSerialPortState));
}
}
void serialPutc(int port_nr, uint8_t c)
{
auto state = auxGetPortState(port_nr);
if (!state) return;
if (state->port) {
state->port->uart->sendByte(state->usart_ctx, c);
}
} }
+37 -4
View File
@@ -22,19 +22,52 @@
#ifndef _SERIAL_H_ #ifndef _SERIAL_H_
#define _SERIAL_H_ #define _SERIAL_H_
#include <stdint.h>
#define MAX_AUX_SERIAL 2
void initSerialPorts();
uint8_t serialGetMode(int port_nr);
uint8_t serialTracesEnabled(int port_nr);
void serialInit(int port_nr, int mode);
void serialStop(int port_nr);
void serialPutc(int port_nr, uint8_t c);
#if defined(AUX_SERIAL)
#define auxSerialSbusInit() serialInit(0, UART_MODE_SBUS_TRAINER)
#define auxSerialGetMode() serialGetMode(0)
#define auxSerialTracesEnabled() serialTracesEnabled(0)
#define auxSerialStop() serialStop(0)
#define auxSerialPutc(c) serialPutc(0, (c))
#endif
#if defined(AUX2_SERIAL)
#define aux2SerialSbusInit() serialInit(1, UART_MODE_SBUS_TRAINER)
#define aux2SerialGetMode() serialGetMode(1)
#define aux2SerialTracesEnabled() serialTracesEnabled(1)
#define aux2SerialStop() serialStop(1)
#define aux2SerialPutc(c) serialPutc(1, (c))
#endif
//
// Functions used by debug.h
//
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void serialPutc(char c); void dbgSerialPutc(char c);
void serialPrintf(const char *format, ...); void dbgSerialPrintf(const char *format, ...);
void serialCrlf(); void dbgSerialCrlf();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#define serialPrint(...) do { serialPrintf(__VA_ARGS__); serialCrlf(); } while(0) #define dbgSerialPrint(...) do { dbgSerialPrintf(__VA_ARGS__); dbgSerialCrlf(); } while(0)
// Debug serial callback
void dbgSerialSetSendCb(void* ctx, void (*cb)(void*, uint8_t));
#endif // _SERIAL_H_ #endif // _SERIAL_H_
@@ -29,7 +29,6 @@ set(STM32USB_SRC
set(FIRMWARE_TARGET_SRC set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC} ${FIRMWARE_TARGET_SRC}
../common/arm/stm32/rtc_driver.cpp ../common/arm/stm32/rtc_driver.cpp
${AUX_SERIAL_DRIVER}
../common/arm/stm32/delays_driver.cpp ../common/arm/stm32/delays_driver.cpp
../common/arm/stm32/usb_bsp.c ../common/arm/stm32/usb_bsp.c
../common/arm/stm32/usbd_desc.c ../common/arm/stm32/usbd_desc.c
@@ -40,6 +39,18 @@ set(FIRMWARE_TARGET_SRC
../common/arm/stm32/usbd_hid_joystick.c ../common/arm/stm32/usbd_hid_joystick.c
) )
if(AUX_SERIAL OR AUX2_SERIAL)
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
../common/arm/stm32/aux_serial_driver.cpp
)
if(AUX_SERIAL)
add_definitions(-DAUX_SERIAL)
endif()
if(AUX2_SERIAL)
add_definitions(-DAUX2_SERIAL)
endif()
endif()
if(DEBUG OR CLI OR USB_SERIAL) if(DEBUG OR CLI OR USB_SERIAL)
set(STM32USB_SRC set(STM32USB_SRC
${STM32USB_SRC} ${STM32USB_SRC}
@@ -70,7 +81,6 @@ endif()
set(FIRMWARE_SRC set(FIRMWARE_SRC
${FIRMWARE_SRC} ${FIRMWARE_SRC}
serial.cpp
syscalls.c syscalls.c
) )
@@ -26,8 +26,71 @@
#include "targets/horus/board.h" #include "targets/horus/board.h"
#include "aux_serial_driver.h" #include "aux_serial_driver.h"
#include "fifo.h"
#include "dmafifo.h"
typedef DMAFifo<32> AuxSerialRxFifo;
struct AuxSerialState
{
Fifo<uint8_t, 512>* txFifo;
AuxSerialRxFifo* rxFifo;
const stm32_usart_t* usart;
};
static void* aux_serial_init(struct AuxSerialState* st, const etx_serial_init* params)
{
stm32_usart_init(st->usart, params);
if (params->rx_enable && st->usart->rxDMA && !params->on_receive) {
st->rxFifo->clear();
stm32_usart_init_rx_dma(st->usart, st->rxFifo->buffer(), st->rxFifo->size());
}
return st;
}
static void aux_serial_putc(void* ctx, uint8_t c)
{
AuxSerialState* st = (AuxSerialState*)ctx;
if (st->txFifo->isFull()) return;
st->txFifo->push(c);
// Send is based on IRQ, so that this
// only enables the corresponding IRQ
stm32_usart_send_buffer(st->usart, &c, 1);
}
static void aux_serial_send_buffer(void* ctx, const uint8_t* data, uint8_t size)
{
while(size > 0) {
aux_serial_putc(ctx, *data++);
size--;
}
}
static void aux_wait_tx_completed(void* ctx)
{
// TODO
(void)ctx;
}
static int aux_get_byte(void* ctx, uint8_t* data)
{
AuxSerialState* st = (AuxSerialState*)ctx;
if (!st->rxFifo) return -1;
return st->rxFifo->pop(*data);
}
void aux_serial_deinit(void* ctx)
{
AuxSerialState* st = (AuxSerialState*)ctx;
stm32_usart_deinit(st->usart);
}
#if defined(AUX_SERIAL) #if defined(AUX_SERIAL)
uint8_t auxSerialMode = UART_MODE_COUNT; // Prevent debug output before port is setup
Fifo<uint8_t, 512> auxSerialTxFifo; Fifo<uint8_t, 512> auxSerialTxFifo;
#if defined(AUX_SERIAL_DMA_Stream_RX) #if defined(AUX_SERIAL_DMA_Stream_RX)
@@ -65,166 +128,53 @@ const stm32_usart_t auxUSART = {
#endif #endif
}; };
static bool auxSerialOnSend(uint8_t& data) AuxSerialState auxSerialState = {
.txFifo = &auxSerialTxFifo,
.rxFifo = &auxSerialRxFifo,
.usart = &auxUSART,
};
// TODO: grab context to get buffer
static bool auxSerialOnSend(uint8_t* data)
{ {
return auxSerialTxFifo.pop(data); return auxSerialTxFifo.pop(*data);
} }
// TODO: add to state
static etx_serial_callbacks_t auxSerialCb = { static etx_serial_callbacks_t auxSerialCb = {
.on_send = auxSerialOnSend, .on_send = auxSerialOnSend,
.on_receive = nullptr, .on_receive = nullptr,
.on_error = nullptr, .on_error = nullptr,
}; };
void auxSerialSetup(unsigned int baudrate, bool rx_enable, uint8_t word_length, static void* auxSerialInit(const etx_serial_init* params)
uint8_t parity, uint8_t stop_bits)
{ {
#if defined(AUX_SERIAL_PWR_GPIO) return aux_serial_init(&auxSerialState, params);
LL_GPIO_InitTypeDef pinInit;
LL_GPIO_StructInit(&pinInit);
pinInit.Pin = AUX_SERIAL_PWR_GPIO_PIN;
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
pinInit.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(AUX_SERIAL_PWR_GPIO, &pinInit);
#endif
#if defined(AUX_SERIAL_TX_INVERT_GPIO_PIN) // NV14
// TODO
GPIO_InitStructure.GPIO_Pin = AUX_SERIAL_TX_INVERT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(AUX_SERIAL_TX_INVERT_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(AUX_SERIAL_TX_INVERT_GPIO, AUX_SERIAL_TX_INVERT_GPIO_PIN);
#endif
#if defined(AUX_SERIAL_RX_INVERT_GPIO_PIN) // NV14
// TODO
GPIO_InitStructure.GPIO_Pin = AUX_SERIAL_RX_INVERT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(AUX_SERIAL_RX_INVERT_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(AUX_SERIAL_RX_INVERT_GPIO, AUX_SERIAL_RX_INVERT_GPIO_PIN);
#endif
etx_serial_init serialInit = {
.baudrate = baudrate,
.parity = parity,
.stop_bits = stop_bits,
.word_length = word_length,
.rx_enable = rx_enable,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = nullptr, // TODO
.on_error = nullptr, // TODO
};
#if defined(AUX_SERIAL_DMA_Stream_RX)
if (rx_enable) {
auxSerialRxFifo.clear();
serialInit.rx_dma_buf = auxSerialRxFifo.buffer();
serialInit.rx_dma_buf_len = auxSerialRxFifo.size();
}
#endif
stm32_usart_init(&auxUSART, &serialInit);
} }
const etx_serial_driver_t AuxSerialDriver = {
.init = auxSerialInit,
.deinit = aux_serial_deinit,
.sendByte = aux_serial_putc,
.sendBuffer = aux_serial_send_buffer,
.waitForTxCompleted = aux_wait_tx_completed,
.getByte = aux_get_byte,
.setReceiveCb = nullptr,
.setOnErrorCb = nullptr,
};
extern "C" void AUX_SERIAL_USART_IRQHandler(void) extern "C" void AUX_SERIAL_USART_IRQHandler(void)
{ {
DEBUG_INTERRUPT(INT_SER2); DEBUG_INTERRUPT(INT_SER2);
stm32_usart_isr(&auxUSART, &auxSerialCb); stm32_usart_isr(&auxUSART, &auxSerialCb);
} }
void auxSerialPutc(uint8_t c)
{
if (auxSerialTxFifo.isFull()) return;
auxSerialTxFifo.push(c);
stm32_usart_send_buffer(&auxUSART, &c, 1);
}
void auxSerialStop()
{
stm32_usart_deinit(&auxUSART);
}
static void serialPushLua(uint8_t data)
{
// TODO: this should be set by LUA instead of
// including some LUA header here.
//
// if (luaRxFifo)
// luaRxFifo->push(data);
}
void auxSerialInit(unsigned int mode, unsigned int protocol)
{
auxSerialStop();
auxSerialMode = mode;
auxSerialCb.on_receive = nullptr;
switch (mode) {
case UART_MODE_TELEMETRY_MIRROR:
// TODO: add a setting for the telemetry protocol ???
// -> how do we know the baudrate?
#if defined(CROSSFIRE)
if (protocol == PROTOCOL_TELEMETRY_CROSSFIRE) {
auxSerialSetup(CROSSFIRE_TELEM_MIRROR_BAUDRATE, false);
AUX_SERIAL_POWER_ON();
break;
}
#endif
auxSerialSetup(FRSKY_TELEM_MIRROR_BAUDRATE, false);
AUX_SERIAL_POWER_ON();
break;
#if defined(DEBUG) || defined(CLI)
case UART_MODE_DEBUG:
auxSerialSetup(DEBUG_BAUDRATE, false);
AUX_SERIAL_POWER_OFF();
break;
#endif
case UART_MODE_TELEMETRY:
if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
auxSerialSetup(FRSKY_D_BAUDRATE, true);
AUX_SERIAL_POWER_ON();
}
break;
case UART_MODE_SBUS_TRAINER:
auxSerialSetup(
SBUS_BAUDRATE, true, ETX_WordLength_9, ETX_Parity_Even,
ETX_StopBits_Two); // USART_WordLength_9b due to parity bit
AUX_SERIAL_POWER_ON();
break;
#if defined(LUA)
case UART_MODE_LUA:
auxSerialSetup(LUA_DEFAULT_BAUDRATE, false);
auxSerialCb.on_receive = serialPushLua;
AUX_SERIAL_POWER_ON();
break;
#endif
}
}
void auxSerialSbusInit()
{
auxSerialInit(UART_MODE_SBUS_TRAINER, 0);
}
uint8_t auxSerialTracesEnabled()
{
#if defined(DEBUG)
return (auxSerialMode == UART_MODE_DEBUG);
#else
return false;
#endif
}
#endif // AUX_SERIAL #endif // AUX_SERIAL
#if defined(AUX2_SERIAL) #if defined(AUX2_SERIAL)
uint8_t aux2SerialMode = UART_MODE_COUNT; // Prevent debug output before port is setup
Fifo<uint8_t, 512> aux2SerialTxFifo; Fifo<uint8_t, 512> aux2SerialTxFifo;
AuxSerialRxFifo aux2SerialRxFifo __DMA (AUX2_SERIAL_DMA_Stream_RX); AuxSerialRxFifo aux2SerialRxFifo __DMA (AUX2_SERIAL_DMA_Stream_RX);
const LL_GPIO_InitTypeDef aux2USARTPinInit = { const LL_GPIO_InitTypeDef aux2USARTPinInit = {
@@ -250,9 +200,15 @@ const stm32_usart_t aux2USART = {
.rxDMA_Channel = AUX2_SERIAL_DMA_Channel_RX, .rxDMA_Channel = AUX2_SERIAL_DMA_Channel_RX,
}; };
static bool aux2SerialOnSend(uint8_t& data) AuxSerialState aux2SerialState = {
.txFifo = &aux2SerialTxFifo,
.rxFifo = &aux2SerialRxFifo,
.usart = &aux2USART,
};
static bool aux2SerialOnSend(uint8_t* data)
{ {
return aux2SerialTxFifo.pop(data); return aux2SerialTxFifo.pop(*data);
} }
static etx_serial_callbacks_t aux2SerialCb = { static etx_serial_callbacks_t aux2SerialCb = {
@@ -261,35 +217,9 @@ static etx_serial_callbacks_t aux2SerialCb = {
.on_error = nullptr, .on_error = nullptr,
}; };
void aux2SerialSetup(unsigned int baudrate, bool rx_enable, uint8_t word_length, void* aux2SerialInit(const etx_serial_init* params)
uint8_t parity, uint8_t stop_bits)
{ {
etx_serial_init serialInit = { return aux_serial_init(&aux2SerialState, params);
.baudrate = baudrate,
.parity = parity,
.stop_bits = stop_bits,
.word_length = word_length,
.rx_enable = rx_enable,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = nullptr, // TODO
.on_error = nullptr, // TODO
};
if (rx_enable) {
aux2SerialRxFifo.clear();
serialInit.rx_dma_buf = aux2SerialRxFifo.buffer();
serialInit.rx_dma_buf_len = aux2SerialRxFifo.size();
}
stm32_usart_init(&aux2USART, &serialInit);
// #if defined(AUX2_SERIAL_PWR_GPIO)
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
// GPIO_InitStructure.GPIO_Pin = AUX2_SERIAL_PWR_GPIO_PIN;
// GPIO_Init(AUX2_SERIAL_PWR_GPIO, &GPIO_InitStructure);
// #endif
} }
extern "C" void AUX2_SERIAL_USART_IRQHandler(void) extern "C" void AUX2_SERIAL_USART_IRQHandler(void)
@@ -298,81 +228,15 @@ extern "C" void AUX2_SERIAL_USART_IRQHandler(void)
stm32_usart_isr(&aux2USART, &aux2SerialCb); stm32_usart_isr(&aux2USART, &aux2SerialCb);
} }
void aux2SerialPutc(uint8_t c) const etx_serial_driver_t Aux2SerialDriver = {
{ .init = aux2SerialInit,
if (aux2SerialTxFifo.isFull()) return; .deinit = aux_serial_deinit,
aux2SerialTxFifo.push(c); .sendByte = aux_serial_putc,
stm32_usart_send_buffer(&aux2USART, &c, 1); .sendBuffer = aux_serial_send_buffer,
} .waitForTxCompleted = aux_wait_tx_completed,
.getByte = aux_get_byte,
void aux2SerialStop() .setReceiveCb = nullptr,
{ .setOnErrorCb = nullptr,
stm32_usart_deinit(&aux2USART); };
}
void aux2SerialInit(unsigned int mode, unsigned int protocol)
{
aux2SerialStop();
aux2SerialMode = mode;
aux2SerialCb.on_receive = nullptr;
switch (mode) {
case UART_MODE_TELEMETRY_MIRROR:
#if defined(CROSSFIRE)
if (protocol == PROTOCOL_TELEMETRY_CROSSFIRE) {
aux2SerialSetup(CROSSFIRE_TELEM_MIRROR_BAUDRATE, false);
AUX2_SERIAL_POWER_ON();
break;
}
#endif
aux2SerialSetup(FRSKY_TELEM_MIRROR_BAUDRATE, false);
AUX2_SERIAL_POWER_ON();
break;
#if defined(DEBUG) || defined(CLI)
case UART_MODE_DEBUG:
aux2SerialSetup(DEBUG_BAUDRATE, false);
AUX2_SERIAL_POWER_OFF();
break;
#endif
case UART_MODE_TELEMETRY:
if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
aux2SerialSetup(FRSKY_D_BAUDRATE, true);
AUX2_SERIAL_POWER_ON();
}
break;
case UART_MODE_SBUS_TRAINER:
aux2SerialSetup(
SBUS_BAUDRATE, true, ETX_WordLength_9, ETX_Parity_Even,
ETX_StopBits_Two); // 2 stop bits requires USART_WordLength_9b
AUX2_SERIAL_POWER_ON();
break;
#if defined(LUA)
case UART_MODE_LUA:
aux2SerialSetup(LUA_DEFAULT_BAUDRATE, false);
aux2SerialCb.on_receive = serialPushLua;
AUX2_SERIAL_POWER_ON();
break;
#endif
}
}
void aux2SerialSbusInit()
{
aux2SerialInit(UART_MODE_SBUS_TRAINER, 0);
}
uint8_t aux2SerialTracesEnabled()
{
#if defined(DEBUG)
return (aux2SerialMode == UART_MODE_DEBUG);
#else
return false;
#endif
}
#endif // AUX2_SERIAL #endif // AUX2_SERIAL
@@ -24,28 +24,12 @@
#include "hal/serial_driver.h" #include "hal/serial_driver.h"
#if defined(AUX_SERIAL) #if defined(AUX_SERIAL)
extern uint8_t auxSerialMode;
void auxSerialSetup(unsigned int baudrate, bool rx_enable, extern const etx_serial_driver_t AuxSerialDriver;
uint8_t word_length = ETX_WordLength_8,
uint8_t parity = ETX_Parity_None,
uint8_t stop_bits = ETX_StopBits_One);
void auxSerialInit(unsigned int mode, unsigned int protocol);
void auxSerialPutc(uint8_t c);
void auxSerialSbusInit();
void auxSerialStop();
uint8_t auxSerialTracesEnabled();
#endif #endif
#if defined(AUX2_SERIAL) #if defined(AUX2_SERIAL)
extern uint8_t aux2SerialMode;
void aux2SerialSetup(unsigned int baudrate, bool rx_enable, extern const etx_serial_driver_t Aux2SerialDriver;
uint8_t word_length = ETX_WordLength_8,
uint8_t parity = ETX_Parity_None,
uint8_t stop_bits = ETX_StopBits_One);
void aux2SerialInit(unsigned int mode, unsigned int protocol);
void aux2SerialPutc(uint8_t c);
void aux2SerialSbusInit();
void aux2SerialStop();
uint8_t aux2SerialTracesEnabled();
#endif #endif
@@ -144,6 +144,7 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c ../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
../../../../../serial.cpp ../../../../../serial.cpp
../../../../../targets/common/arm/stm32/aux_serial_driver.cpp ../../../../../targets/common/arm/stm32/aux_serial_driver.cpp
../../../../../targets/common/arm/stm32/stm32_usart_driver.cpp
) )
endif() endif()
else() else()
@@ -244,12 +244,9 @@ int main()
#endif #endif
delaysInit(); // needed for lcdInit() delaysInit(); // needed for lcdInit()
#if defined(DEBUG) && defined(AUX_SERIAL) #if defined(DEBUG)
auxSerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined) initSerialPorts();
#endif
#if defined(DEBUG) && defined(AUX2_SERIAL)
aux2SerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined)
#endif #endif
__enable_irq(); __enable_irq();
@@ -49,8 +49,6 @@ static const etx_serial_init extmoduleSerialParams = {
.stop_bits = ETX_StopBits_One, .stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8, .word_length = ETX_WordLength_8,
.rx_enable = true, .rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = extmoduleFifoReceive, .on_receive = extmoduleFifoReceive,
.on_error = extmoduleFifoError, .on_error = extmoduleFifoError,
}; };
@@ -78,9 +76,9 @@ static const stm32_usart_t extmoduleUSART = {
.rxDMA_Channel = 0, .rxDMA_Channel = 0,
}; };
static void extmoduleSerialStart(const etx_serial_init* params) static void* extmoduleSerialStart(const etx_serial_init* params)
{ {
if (!params) return; if (!params) return nullptr;
extmodule_driver.on_receive = params->on_receive; extmodule_driver.on_receive = params->on_receive;
extmodule_driver.on_error = params->on_error; extmodule_driver.on_error = params->on_error;
@@ -88,6 +86,8 @@ static void extmoduleSerialStart(const etx_serial_init* params)
// UART config // UART config
stm32_usart_init(&extmoduleUSART, params); stm32_usart_init(&extmoduleUSART, params);
extmoduleFifo.clear(); extmoduleFifo.clear();
return nullptr;
} }
void extmoduleInvertedSerialStart(uint32_t baudrate) void extmoduleInvertedSerialStart(uint32_t baudrate)
@@ -108,7 +108,7 @@ void extmodulePxx1SerialStart()
} }
#endif #endif
void extmoduleSerialStop() void extmoduleSerialStop(void*)
{ {
stm32_usart_deinit(&extmoduleUSART); stm32_usart_deinit(&extmoduleUSART);
@@ -117,18 +117,18 @@ void extmoduleSerialStop()
extmodule_driver.on_error = nullptr; extmodule_driver.on_error = nullptr;
} }
static void extmoduleSendByte(uint8_t byte) static void extmoduleSendByte(void*, uint8_t byte)
{ {
stm32_usart_send_byte(&extmoduleUSART, byte); stm32_usart_send_byte(&extmoduleUSART, byte);
} }
static void extmoduleSendBuffer(const uint8_t * data, uint8_t size) static void extmoduleSendBuffer(void*, const uint8_t * data, uint8_t size)
{ {
if (size == 0) return; if (size == 0) return;
stm32_usart_send_buffer(&extmoduleUSART, data, size); stm32_usart_send_buffer(&extmoduleUSART, data, size);
} }
static void extmoduleWaitForTxCompleted() static void extmoduleWaitForTxCompleted(void*)
{ {
stm32_usart_wait_for_tx_dma(&extmoduleUSART); stm32_usart_wait_for_tx_dma(&extmoduleUSART);
} }
@@ -20,6 +20,7 @@ target_include_directories(stm32cube_ll PRIVATE
${THIRDPARTY_DIR}/CMSIS/Include) ${THIRDPARTY_DIR}/CMSIS/Include)
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32cube_ll>) set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
# StdPeriph library # StdPeriph library
set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries) set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries)
@@ -28,13 +28,13 @@
ModuleFifo intmoduleFifo; ModuleFifo intmoduleFifo;
#if !defined(INTMODULE_DMA_STREAM) #if !defined(INTMODULE_DMA_STREAM)
uint8_t * intmoduleTxBufferData; static uint8_t * intmoduleTxBufferData;
volatile uint8_t intmoduleTxBufferRemaining; static volatile uint8_t intmoduleTxBufferRemaining;
bool intmoduleTxBufferSend(uint8_t& data) bool intmoduleTxBufferSend(uint8_t* data)
{ {
if (intmoduleTxBufferRemaining) { if (intmoduleTxBufferRemaining) {
data = *(intmoduleTxBufferData++); *data = *(intmoduleTxBufferData++);
intmoduleTxBufferRemaining--; intmoduleTxBufferRemaining--;
return true; return true;
} }
@@ -96,9 +96,15 @@ void intmoduleStop()
intmodule_driver.on_error = nullptr; intmodule_driver.on_error = nullptr;
} }
void intmoduleSerialStart(const etx_serial_init* params) static void intmoduleStop(void* ctx)
{ {
if (!params) return; (void)ctx;
intmoduleStop();
}
void* intmoduleSerialStart(const etx_serial_init* params)
{
if (!params) return nullptr;
// TODO: sanity check parameters // TODO: sanity check parameters
// - the UART seems to block when initialised with baudrate = 0 // - the UART seems to block when initialised with baudrate = 0
@@ -108,6 +114,7 @@ void intmoduleSerialStart(const etx_serial_init* params)
intmodule_driver.on_error = params->on_error; intmodule_driver.on_error = params->on_error;
stm32_usart_init(&intmoduleUSART, params); stm32_usart_init(&intmoduleUSART, params);
return nullptr;
} }
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE) #define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
@@ -116,13 +123,15 @@ extern "C" void INTMODULE_USART_IRQHandler(void)
stm32_usart_isr(&intmoduleUSART, &intmodule_driver); stm32_usart_isr(&intmoduleUSART, &intmodule_driver);
} }
void intmoduleSendByte(uint8_t byte) void intmoduleSendByte(void* ctx, uint8_t byte)
{ {
(void)ctx;
stm32_usart_send_byte(&intmoduleUSART, byte); stm32_usart_send_byte(&intmoduleUSART, byte);
} }
void intmoduleSendBuffer(const uint8_t * data, uint8_t size) void intmoduleSendBuffer(void* ctx, const uint8_t * data, uint8_t size)
{ {
(void)ctx;
if (size == 0) if (size == 0)
return; return;
@@ -133,8 +142,9 @@ void intmoduleSendBuffer(const uint8_t * data, uint8_t size)
stm32_usart_send_buffer(&intmoduleUSART, data, size); stm32_usart_send_buffer(&intmoduleUSART, data, size);
} }
void intmoduleWaitForTxCompleted() void intmoduleWaitForTxCompleted(void* ctx)
{ {
(void)ctx;
#if defined(INTMODULE_DMA_STREAM) #if defined(INTMODULE_DMA_STREAM)
stm32_usart_wait_for_tx_dma(&intmoduleUSART); stm32_usart_wait_for_tx_dma(&intmoduleUSART);
#else #else
@@ -22,8 +22,16 @@
#include "stm32_usart_driver.h" #include "stm32_usart_driver.h"
#include <string.h> #include <string.h>
static void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length) void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length)
{ {
// Disable IRQ based RX
LL_USART_DisableIT_RXNE(usart->USARTx);
// In case TX DMA is used, disable the ISR completely
if (usart->txDMA) {
NVIC_DisableIRQ(usart->IRQn);
}
LL_DMA_InitTypeDef dmaInit; LL_DMA_InitTypeDef dmaInit;
LL_DMA_StructInit(&dmaInit); LL_DMA_StructInit(&dmaInit);
dmaInit.Channel = usart->rxDMA_Channel; dmaInit.Channel = usart->rxDMA_Channel;
@@ -47,6 +55,8 @@ void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
LL_GPIO_Init(usart->GPIOx, (LL_GPIO_InitTypeDef*)usart->pinInit); LL_GPIO_Init(usart->GPIOx, (LL_GPIO_InitTypeDef*)usart->pinInit);
LL_USART_InitTypeDef usartInit; LL_USART_InitTypeDef usartInit;
LL_USART_StructInit(&usartInit);
usartInit.BaudRate = params->baudrate; usartInit.BaudRate = params->baudrate;
uint32_t parity = LL_USART_PARITY_NONE; uint32_t parity = LL_USART_PARITY_NONE;
@@ -96,14 +106,8 @@ void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
// Enable RX IRQ // Enable RX IRQ
if (params->rx_enable) { if (params->rx_enable) {
if (usart->rxDMA) { // IRQ based RX
// RX DMA LL_USART_EnableIT_RXNE(usart->USARTx);
stm32_usart_init_rx_dma(usart, params->rx_dma_buf,
params->rx_dma_buf_len);
} else {
// IRQ based RX
LL_USART_EnableIT_RXNE(usart->USARTx);
}
} }
if (!usart->txDMA || (params->rx_enable && !usart->rxDMA)) { if (!usart->txDMA || (params->rx_enable && !usart->rxDMA)) {
@@ -159,7 +163,7 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
return; return;
} else { } else {
// Please note that we don't use the buffer: // Please note that we don't use the buffer:
// it should set internally by the driver user // it should be set internally by the driver user
// and each byte is returned individually by on_send() // and each byte is returned individually by on_send()
LL_USART_EnableIT_TXE(usart->USARTx); LL_USART_EnableIT_TXE(usart->USARTx);
} }
@@ -204,7 +208,7 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
uint32_t status = LL_USART_ReadReg(usart->USARTx, SR); uint32_t status = LL_USART_ReadReg(usart->USARTx, SR);
// Receive: do it first as it is more time critical // Receive: do it first as it is more time critical
if (LL_USART_IsEnabledIT_TXE(usart->USARTx)) { if (LL_USART_IsEnabledIT_RXNE(usart->USARTx)) {
// Drain RX // Drain RX
while (status & (LL_USART_SR_RXNE | USART_FLAG_ERRORS)) { while (status & (LL_USART_SR_RXNE | USART_FLAG_ERRORS)) {
@@ -229,7 +233,7 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
if (LL_USART_IsEnabledIT_TXE(usart->USARTx) && (status & LL_USART_SR_TXE)) { if (LL_USART_IsEnabledIT_TXE(usart->USARTx) && (status & LL_USART_SR_TXE)) {
uint8_t data; uint8_t data;
if (cb->on_send && cb->on_send(data)) { if (cb->on_send && cb->on_send(&data)) {
LL_USART_TransmitData8(usart->USARTx, data); LL_USART_TransmitData8(usart->USARTx, data);
} else { } else {
LL_USART_DisableIT_TXE(usart->USARTx); LL_USART_DisableIT_TXE(usart->USARTx);
@@ -48,10 +48,10 @@ struct stm32_usart_t {
}; };
void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params); void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params);
void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length);
void stm32_usart_deinit(const stm32_usart_t* usart); void stm32_usart_deinit(const stm32_usart_t* usart);
void stm32_usart_send_byte(const stm32_usart_t* usart, uint8_t byte); void stm32_usart_send_byte(const stm32_usart_t* usart, uint8_t byte);
void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, uint32_t size); void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, uint32_t size);
void stm32_usart_wait_for_tx_dma(const stm32_usart_t* usart); void stm32_usart_wait_for_tx_dma(const stm32_usart_t* usart);
void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb); void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb);
@@ -51,7 +51,7 @@ int getSelectedUsbMode();
void setSelectedUsbMode(int mode); void setSelectedUsbMode(int mode);
uint32_t usbSerialFreeSpace(); uint32_t usbSerialFreeSpace();
void usbSerialPutc(uint8_t c); void usbSerialPutc(void*, uint8_t c);
uint32_t usbSerialBaudRate(void); uint32_t usbSerialBaudRate(void);
@@ -94,6 +94,7 @@ static uint16_t VCP_Init(void)
cdcConnected = true; cdcConnected = true;
ctrlLineStateCb = NULL; ctrlLineStateCb = NULL;
baudRateCb = NULL; baudRateCb = NULL;
return USBD_OK; return USBD_OK;
} }
@@ -205,7 +206,7 @@ uint32_t usbSerialFreeSpace()
1; 1;
} }
void usbSerialPutc(uint8_t c) void usbSerialPutc(void*, uint8_t c)
{ {
/* /*
Apparently there is no reliable way to tell if the Apparently there is no reliable way to tell if the
@@ -253,21 +254,8 @@ void usbSerialPutc(uint8_t c)
*/ */
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len) static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{ {
if (receiveDataCb) auto _rxCb = receiveDataCb;
receiveDataCb(Buf, Len); if (_rxCb) _rxCb(Buf, Len);
// #if defined(CLI)
// // pass data to CLI
// cliReceiveData(Buf, Len);
// #elif defined(LUA)
// // copy data to the LUA FIFO
// if (luaRxFifo) {
// for (uint32_t i = 0; i < Len; i++) {
// luaRxFifo->push(Buf[i]);
// }
// }
// #endif
return USBD_OK; return USBD_OK;
} }
-11
View File
@@ -245,16 +245,6 @@ if(BLUETOOTH)
add_definitions(-DHARDWARE_TRAINER_BLUETOOTH) add_definitions(-DHARDWARE_TRAINER_BLUETOOTH)
endif() endif()
if (AUX_SERIAL)
add_definitions(-DAUX_SERIAL)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
endif()
if (AUX2_SERIAL)
add_definitions(-DAUX2_SERIAL)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
endif()
if (SBUS_TRAINER) if (SBUS_TRAINER)
add_definitions(-DSBUS_TRAINER) add_definitions(-DSBUS_TRAINER)
set(SRC set(SRC
@@ -266,7 +256,6 @@ endif()
set(FIRMWARE_TARGET_SRC set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC} ${FIRMWARE_TARGET_SRC}
${LCD_DRIVER} ${LCD_DRIVER}
${AUX_SERIAL_DRIVER}
${FLYSKY_HALL_STICKS_DRIVER} ${FLYSKY_HALL_STICKS_DRIVER}
${IMU_LSM6DS33_DRIVER} ${IMU_LSM6DS33_DRIVER}
${TOUCH_DRIVER} ${TOUCH_DRIVER}
+72 -32
View File
@@ -19,13 +19,21 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include "stm32_hal_ll.h"
#include "opentx.h" #include "opentx.h"
#include "hal/adc_driver.h" #include "hal/adc_driver.h"
#include "../common/arm/stm32/timers_driver.h" #include "hal/serial_driver.h"
#include "hal/serial_port.h"
#include "timers_driver.h"
#if defined(AUX_SERIAL) || defined(AUX2_SERIAL)
#include "aux_serial_driver.h"
#endif
#if !defined(PCBX12S) #if !defined(PCBX12S)
#include "../common/arm/stm32/stm32_hal_adc.h" #include "stm32_hal_adc.h"
#define ADC_DRIVER stm32_hal_adc_driver #define ADC_DRIVER stm32_hal_adc_driver
#else #else
#include "x12s_adc_driver.h" #include "x12s_adc_driver.h"
@@ -58,30 +66,6 @@ void watchdogInit(unsigned int duration)
IWDG->KR = 0xCCCC; // start IWDG->KR = 0xCCCC; // start
} }
#if defined(AUX_SERIAL_PWR_GPIO)
void auxSerialPowerOn()
{
GPIO_SetBits(AUX_SERIAL_PWR_GPIO, AUX_SERIAL_PWR_GPIO_PIN);
}
void auxSerialPowerOff()
{
GPIO_ResetBits(AUX_SERIAL_PWR_GPIO, AUX_SERIAL_PWR_GPIO_PIN);
}
#endif
#if defined(AUX2_SERIAL_PWR_GPIO)
void aux2SerialPowerOn()
{
GPIO_SetBits(AUX2_SERIAL_PWR_GPIO, AUX2_SERIAL_PWR_GPIO_PIN);
}
void aux2SerialPowerOff()
{
GPIO_ResetBits(AUX2_SERIAL_PWR_GPIO, AUX2_SERIAL_PWR_GPIO_PIN);
}
#endif
#if HAS_SPORT_UPDATE_CONNECTOR() #if HAS_SPORT_UPDATE_CONNECTOR()
void sportUpdateInit() void sportUpdateInit()
{ {
@@ -193,12 +177,7 @@ void boardInit()
__enable_irq(); __enable_irq();
#if defined(DEBUG) && defined(AUX_SERIAL) initSerialPorts();
auxSerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined)
#endif
#if defined(DEBUG) && defined(AUX2_SERIAL)
aux2SerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined)
#endif
TRACE("\nHorus board started :)"); TRACE("\nHorus board started :)");
TRACE("RCC->CSR = %08x", RCC->CSR); TRACE("RCC->CSR = %08x", RCC->CSR);
@@ -359,3 +338,64 @@ bool isBacklightEnabled()
return true; return true;
return boardBacklightOn; return boardBacklightOn;
} }
static void _aux_pwr(GPIO_TypeDef *GPIOx, uint32_t pin, uint8_t on)
{
LL_GPIO_InitTypeDef pinInit;
LL_GPIO_StructInit(&pinInit);
pinInit.Pin = pin;
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
pinInit.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(GPIOx, &pinInit);
if (on) {
LL_GPIO_SetOutputPin(GPIOx, pin);
} else {
LL_GPIO_ResetOutputPin(GPIOx, pin);
}
}
#if defined(AUX_SERIAL)
void set_aux_pwr(uint8_t on)
{
#if defined(AUX_SERIAL_PWR_GPIO)
_aux_pwr(AUX_SERIAL_PWR_GPIO, AUX_SERIAL_PWR_GPIO_PIN, on);
#endif
}
const etx_serial_port_t auxSerialPort = {
&AuxSerialDriver,
set_aux_pwr,
};
#define AUX_SERIAL_PORT &auxSerialPort
#else
#define AUX_SERIAL_PORT nullptr
#endif
#if defined(AUX2_SERIAL)
void set_aux2_pwr(uint8_t on)
{
#if defined(AUX2_SERIAL_PWR_GPIO)
_aux_pwr(AUX2_SERIAL_PWR_GPIO, AUX2_SERIAL_PWR_GPIO_PIN, on);
#endif
}
const etx_serial_port_t aux2SerialPort = {
&Aux2SerialDriver,
set_aux2_pwr,
};
#define AUX2_SERIAL_PORT &aux2SerialPort
#else
#define AUX2_SERIAL_PORT nullptr
#endif // AUX2_SERIAL
static const etx_serial_port_t* serialPorts[MAX_AUX_SERIAL] = {
AUX_SERIAL_PORT,
AUX2_SERIAL_PORT,
};
const etx_serial_port_t* auxSerialGetPort(int port_nr)
{
if (port_nr >= MAX_AUX_SERIAL) return nullptr;
return serialPorts[port_nr];
}
+3 -39
View File
@@ -26,6 +26,7 @@
#include "opentx_constants.h" #include "opentx_constants.h"
#include "board_common.h" #include "board_common.h"
#include "hal.h" #include "hal.h"
#include "hal/serial_port.h"
#include "watchdog_driver.h" #include "watchdog_driver.h"
@@ -198,9 +199,6 @@ void stop_trainer_ppm();
void init_trainer_capture(); void init_trainer_capture();
void stop_trainer_capture(); void stop_trainer_capture();
// SBUS
int sbusGetByte(uint8_t * byte);
// Keys driver // Keys driver
enum EnumKeys enum EnumKeys
{ {
@@ -623,7 +621,7 @@ void telemetryPortSetDirectionInput();
void telemetryPortSetDirectionOutput(); void telemetryPortSetDirectionOutput();
void sportSendByte(uint8_t byte); void sportSendByte(uint8_t byte);
void sportSendBuffer(const uint8_t * buffer, uint32_t count); void sportSendBuffer(const uint8_t * buffer, uint32_t count);
bool telemetryGetByte(uint8_t * byte); bool sportGetByte(uint8_t * byte);
void telemetryClearFifo(); void telemetryClearFifo();
extern uint32_t telemetryErrors; extern uint32_t telemetryErrors;
@@ -654,32 +652,8 @@ void sportUpdatePowerInit();
#define DEBUG_BAUDRATE 115200 #define DEBUG_BAUDRATE 115200
#define LUA_DEFAULT_BAUDRATE 115200 #define LUA_DEFAULT_BAUDRATE 115200
#endif #endif
#if defined(AUX_SERIAL)
#define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
void auxSerialPowerOn();
void auxSerialPowerOff();
#if defined(AUX_SERIAL_PWR_GPIO)
#define AUX_SERIAL_POWER_ON() auxSerialPowerOn()
#define AUX_SERIAL_POWER_OFF() auxSerialPowerOff()
#else
#define AUX_SERIAL_POWER_ON()
#define AUX_SERIAL_POWER_OFF()
#endif
#endif
// Aux2 serial port driver const etx_serial_port_t* auxSerialGetPort(int port_nr);
#if defined(AUX2_SERIAL)
#define aux2SerialTelemetryInit(protocol) aux2SerialInit(UART_MODE_TELEMETRY, protocol)
void aux2SerialPowerOn();
void aux2SerialPowerOff();
#if defined(AUX2_SERIAL_PWR_GPIO)
#define AUX2_SERIAL_POWER_ON() aux2SerialPowerOn()
#define AUX2_SERIAL_POWER_OFF() aux2SerialPowerOff()
#else
#define AUX2_SERIAL_POWER_ON()
#define AUX2_SERIAL_POWER_OFF()
#endif
#endif
// Haptic driver // Haptic driver
void hapticInit(); void hapticInit();
@@ -711,14 +685,4 @@ void bluetoothWriteWakeup();
uint8_t bluetoothIsWriting(); uint8_t bluetoothIsWriting();
void bluetoothDisable(); void bluetoothDisable();
#if defined(__cplusplus)
#include "fifo.h"
#include "dmafifo.h"
extern DMAFifo<512> telemetryFifo;
typedef DMAFifo<32> AuxSerialRxFifo;
extern AuxSerialRxFifo auxSerialRxFifo;
extern AuxSerialRxFifo aux2SerialRxFifo;
extern volatile uint32_t externalModulePort;
#endif
#endif // _BOARD_H_ #endif // _BOARD_H_
@@ -22,6 +22,9 @@
#include "opentx.h" #include "opentx.h"
#include "flyskyHallStick_driver.h" #include "flyskyHallStick_driver.h"
#include "fifo.h"
#include "dmafifo.h"
DMAFifo<HALLSTICK_BUFF_SIZE> hallDMAFifo __DMA (FLYSKY_HALL_DMA_Stream_RX); DMAFifo<HALLSTICK_BUFF_SIZE> hallDMAFifo __DMA (FLYSKY_HALL_DMA_Stream_RX);
Fifo<uint8_t, HALLSTICK_BUFF_SIZE> hallStickTxFifo; Fifo<uint8_t, HALLSTICK_BUFF_SIZE> hallStickTxFifo;
unsigned char HallCmd[264] __DMA; unsigned char HallCmd[264] __DMA;
+4 -1
View File
@@ -21,6 +21,9 @@
#include "opentx.h" #include "opentx.h"
#include "fifo.h"
#include "dmafifo.h"
Fifo<uint8_t, TELEMETRY_FIFO_SIZE> telemetryNoDMAFifo; Fifo<uint8_t, TELEMETRY_FIFO_SIZE> telemetryNoDMAFifo;
uint32_t telemetryErrors = 0; uint32_t telemetryErrors = 0;
@@ -415,7 +418,7 @@ extern "C" void TELEMETRY_TIMER_IRQHandler()
} }
// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp // TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
bool telemetryGetByte(uint8_t * byte) bool sportGetByte(uint8_t * byte)
{ {
#if defined(PCBX12S) #if defined(PCBX12S)
if (telemetryFifoMode & TELEMETRY_SERIAL_WITHOUT_DMA) if (telemetryFifoMode & TELEMETRY_SERIAL_WITHOUT_DMA)
@@ -142,22 +142,3 @@ extern "C" void TRAINER_TIMER_IRQHandler()
} }
} }
} }
int sbusGetByte(uint8_t * byte)
{
switch (currentTrainerMode) {
#if defined(AUX_SERIAL) || defined(AUX2_SERIAL)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
#if defined(AUX_SERIAL)
if (auxSerialMode == UART_MODE_SBUS_TRAINER)
return auxSerialRxFifo.pop(*byte);
#endif
#if defined(AUX2_SERIAL)
if (aux2SerialMode == UART_MODE_SBUS_TRAINER)
return aux2SerialRxFifo.pop(*byte);
#endif
#endif
default:
return false;
}
}
+7 -2
View File
@@ -23,8 +23,8 @@
#include "touch.h" #include "touch.h"
#include "hal/adc_driver.h" #include "hal/adc_driver.h"
#include "../common/arm/stm32/stm32_hal_adc.h" #include "stm32_hal_adc.h"
#include "../common/arm/stm32/timers_driver.h" #include "timers_driver.h"
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
extern "C" { extern "C" {
@@ -242,3 +242,8 @@ void boardOff()
} }
} }
const etx_serial_port_t* auxSerialGetPort(int port_nr)
{
return nullptr;
}
+4 -21
View File
@@ -26,6 +26,7 @@
#include "opentx_constants.h" #include "opentx_constants.h"
#include "board_common.h" #include "board_common.h"
#include "hal.h" #include "hal.h"
#include "hal/serial_port.h"
#if !defined(LUA_EXPORT_GENERATION) #if !defined(LUA_EXPORT_GENERATION)
#include "stm32f4xx_sdio.h" #include "stm32f4xx_sdio.h"
@@ -390,9 +391,8 @@ bool pwrPressed();
#endif #endif
uint32_t pwrPressedDuration();; uint32_t pwrPressedDuration();;
#define AUX_SERIAL_POWER_ON() const etx_serial_port_t* auxSerialGetPort(int port_nr);
#define AUX_SERIAL_POWER_OFF()
// LCD driver // LCD driver
#define LCD_W 320 #define LCD_W 320
#define LCD_H 480 #define LCD_H 480
@@ -483,7 +483,7 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode);
void telemetryPortSetDirectionOutput(); void telemetryPortSetDirectionOutput();
void telemetryPortSetDirectionInput(); void telemetryPortSetDirectionInput();
void sportSendBuffer(const uint8_t * buffer, uint32_t count); void sportSendBuffer(const uint8_t * buffer, uint32_t count);
bool telemetryGetByte(uint8_t * byte); bool sportGetByte(uint8_t * byte);
void telemetryClearFifo(); void telemetryClearFifo();
void sportSendByte(uint8_t byte); void sportSendByte(uint8_t byte);
extern uint32_t telemetryErrors; extern uint32_t telemetryErrors;
@@ -507,27 +507,10 @@ void hapticOn(uint32_t pwmPercent);
//#define AUX_SERIAL //#define AUX_SERIAL
#define DEBUG_BAUDRATE 115200 #define DEBUG_BAUDRATE 115200
#define LUA_DEFAULT_BAUDRATE 115200 #define LUA_DEFAULT_BAUDRATE 115200
#define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
#if defined(AUX_SERIAL_PWR_GPIO)
#define AUX_SERIAL_POWER_ON() auxSerialPowerOn()
#define AUX_SERIAL__POWER_OFF() auxSerialPowerOff()
#else
#define AUX_SERIAL_POWER_ON()
#define AUX_SERIAL__POWER_OFF()
#endif
extern uint8_t currentTrainerMode; extern uint8_t currentTrainerMode;
void checkTrainerSettings(); void checkTrainerSettings();
#if defined(__cplusplus)
#include "fifo.h"
#include "dmafifo.h"
extern DMAFifo<512> telemetryFifo;
typedef Fifo<uint8_t, 32> AuxSerialRxFifo;
extern AuxSerialRxFifo auxSerialRxFifo;
#endif
// Touch panel driver // Touch panel driver
bool touchPanelEventOccured(); bool touchPanelEventOccured();
struct TouchState touchPanelRead(); struct TouchState touchPanelRead();
+1 -1
View File
@@ -215,7 +215,7 @@ extern "C" void TELEMETRY_USART_IRQHandler(void)
} }
// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp // TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
bool telemetryGetByte(uint8_t * byte) bool sportGetByte(uint8_t * byte)
{ {
#if defined(PCBX12S) #if defined(PCBX12S)
if (telemetryFifoMode & TELEMETRY_SERIAL_WITHOUT_DMA) if (telemetryFifoMode & TELEMETRY_SERIAL_WITHOUT_DMA)
+8 -5
View File
@@ -63,11 +63,12 @@ void stop_trainer_module_sbus() {}
void init_intmodule_heartbeat() {} void init_intmodule_heartbeat() {}
void stop_intmodule_heartbeat() {} void stop_intmodule_heartbeat() {}
static void init(const etx_serial_init*) {} static void* init(const etx_serial_init*) { return nullptr; }
static void deinit() {} static void deinit(void*) {}
static void sendByte(uint8_t) {} static void sendByte(void*, uint8_t) {}
static void sendBuffer(const uint8_t*, uint8_t) {} static void sendBuffer(void*, const uint8_t*, uint8_t) {}
static void waitForTxCompleted() {} static void waitForTxCompleted(void*) {}
static int getByte(void*,uint8_t*) { return -1; }
const etx_serial_driver_t IntmoduleSerialDriver = { const etx_serial_driver_t IntmoduleSerialDriver = {
.init = init, .init = init,
@@ -75,6 +76,7 @@ const etx_serial_driver_t IntmoduleSerialDriver = {
.sendByte = sendByte, .sendByte = sendByte,
.sendBuffer = sendBuffer, .sendBuffer = sendBuffer,
.waitForTxCompleted = waitForTxCompleted, .waitForTxCompleted = waitForTxCompleted,
.getByte = getByte,
.setReceiveCb = nullptr, .setReceiveCb = nullptr,
.setOnErrorCb = nullptr, .setOnErrorCb = nullptr,
}; };
@@ -85,6 +87,7 @@ const etx_serial_driver_t ExtmoduleSerialDriver = {
.sendByte = sendByte, .sendByte = sendByte,
.sendBuffer = sendBuffer, .sendBuffer = sendBuffer,
.waitForTxCompleted = waitForTxCompleted, .waitForTxCompleted = waitForTxCompleted,
.getByte = getByte,
.setReceiveCb = nullptr, .setReceiveCb = nullptr,
.setOnErrorCb = nullptr, .setOnErrorCb = nullptr,
}; };
+3 -55
View File
@@ -429,7 +429,7 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode)
{ {
} }
bool telemetryGetByte(uint8_t * byte) bool sportGetByte(uint8_t * byte)
{ {
return false; return false;
} }
@@ -732,6 +732,7 @@ void disableSpeaker()
} }
#endif #endif
int trainerModuleSbusGetByte(unsigned char*) { return 0; }
void rtcInit() void rtcInit()
{ {
@@ -751,60 +752,7 @@ void usbSerialPutc(uint8_t c)
} }
#endif #endif
#if defined(AUX_SERIAL) const etx_serial_port_t* auxSerialGetPort(int port_nr) { return nullptr; }
#if defined(AUX_SERIAL_DMA_Stream_RX)
AuxSerialRxFifo auxSerialRxFifo(nullptr);
#else
AuxSerialRxFifo auxSerialRxFifo;
#endif
uint8_t auxSerialMode;
void auxSerialSetup(unsigned int baudrate, bool dma, uint8_t length, uint8_t parity, uint8_t stop)
{
}
void auxSerialInit(unsigned int mode, unsigned int protocol)
{
}
void auxSerialPutc(uint8_t c)
{
}
void auxSerialSbusInit()
{
}
void auxSerialStop()
{
}
#endif
#if defined(AUX2_SERIAL)
AuxSerialRxFifo aux2SerialRxFifo(nullptr);
uint8_t aux2SerialMode;
void aux2SerialSetup(unsigned int baudrate, bool dma, uint8_t length, uint8_t parity, uint8_t stop)
{
}
void aux2SerialInit(unsigned int mode, unsigned int protocol)
{
}
void aux2SerialPutc(uint8_t c)
{
}
void aux2SerialSbusInit()
{
}
void aux2SerialStop()
{
}
#endif
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
struct TouchState simTouchState = {}; struct TouchState simTouchState = {};
+4 -4
View File
@@ -31,7 +31,7 @@ if(PCB STREQUAL X9E)
top_lcd_driver.cpp top_lcd_driver.cpp
startup_stm32f40_41xxx.s startup_stm32f40_41xxx.s
) )
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp) set(AUX_SERIAL ON)
if(STICKS STREQUAL HORUS) if(STICKS STREQUAL HORUS)
add_definitions(-DHORUS_STICKS) add_definitions(-DHORUS_STICKS)
endif() endif()
@@ -90,7 +90,7 @@ elseif(PCB STREQUAL X9D+)
set(CPU_TYPE_FULL STM32F205xE) # for size report set(CPU_TYPE_FULL STM32F205xE) # for size report
add_definitions(-DSTM32F205xx) add_definitions(-DSTM32F205xx)
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld) set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp) set(AUX_SERIAL ON)
set(STATUS_LEDS NO) set(STATUS_LEDS NO)
endif() endif()
elseif(PCB STREQUAL X9D) elseif(PCB STREQUAL X9D)
@@ -110,7 +110,7 @@ elseif(PCB STREQUAL X9D)
set(BITMAPS_TARGET taranis_bitmaps) set(BITMAPS_TARGET taranis_bitmaps)
set(FONTS_TARGET taranis_fonts) set(FONTS_TARGET taranis_fonts)
set(LCD_DRIVER lcd_driver_aspi.cpp) set(LCD_DRIVER lcd_driver_aspi.cpp)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp) set(AUX_SERIAL ON)
set(GVAR_SCREEN model_gvars.cpp) set(GVAR_SCREEN model_gvars.cpp)
set(STATUS_LEDS NO) set(STATUS_LEDS NO)
add_definitions(-DMANUFACTURER_FRSKY) add_definitions(-DMANUFACTURER_FRSKY)
@@ -207,7 +207,7 @@ elseif(PCB STREQUAL X7)
set(LUA_EXPORT lua_export_zorro) set(LUA_EXPORT lua_export_zorro)
set(BLUETOOTH NO) set(BLUETOOTH NO)
set(USB_CHARGER YES) set(USB_CHARGER YES)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp) set(AUX_SERIAL ON)
add_definitions(-DRADIO_ZORRO) add_definitions(-DRADIO_ZORRO)
add_definitions(-DEEPROM_VARIANT=0x4006) add_definitions(-DEEPROM_VARIANT=0x4006)
add_definitions(-DMANUFACTURER_RADIOMASTER) add_definitions(-DMANUFACTURER_RADIOMASTER)
+28 -4
View File
@@ -26,6 +26,10 @@
#include "../common/arm/stm32/timers_driver.h" #include "../common/arm/stm32/timers_driver.h"
#if defined(AUX_SERIAL)
#include "aux_serial_driver.h"
#endif
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
@@ -223,10 +227,7 @@ void boardInit()
i2cInit(); i2cInit();
usbInit(); usbInit();
#if defined(DEBUG) && defined(AUX_SERIAL_GPIO) initSerialPorts();
auxSerialInit(0, 0); // default serial mode (None if DEBUG not defined)
TRACE("\nTaranis board started :)");
#endif
#if defined(HAPTIC) #if defined(HAPTIC)
hapticInit(); hapticInit();
@@ -415,3 +416,26 @@ void initJackDetect(void)
GPIO_Init(JACK_DETECT_GPIO, &GPIO_InitStructure); GPIO_Init(JACK_DETECT_GPIO, &GPIO_InitStructure);
} }
#endif #endif
#if defined(AUX_SERIAL)
const etx_serial_port_t auxSerialPort = {
&AuxSerialDriver,
nullptr
};
#define AUX_SERIAL_PORT &auxSerialPort
#else
#define AUX_SERIAL_PORT nullptr
#endif
#define AUX2_SERIAL_PORT nullptr
static const etx_serial_port_t* serialPorts[MAX_AUX_SERIAL] = {
AUX_SERIAL_PORT,
AUX2_SERIAL_PORT,
};
const etx_serial_port_t* auxSerialGetPort(int port_nr)
{
if (port_nr >= MAX_AUX_SERIAL) return nullptr;
return serialPorts[port_nr];
}
+7 -17
View File
@@ -27,6 +27,7 @@
#include "opentx_constants.h" #include "opentx_constants.h"
#include "board_common.h" #include "board_common.h"
#include "hal.h" #include "hal.h"
#include "hal/serial_port.h"
#include "watchdog_driver.h" #include "watchdog_driver.h"
@@ -164,26 +165,20 @@ uint32_t isBootloaderStart(const uint8_t * buffer);
#define init_trainer_capture() #define init_trainer_capture()
#define stop_trainer_capture() #define stop_trainer_capture()
#endif #endif
#if defined(TRAINER_MODULE_CPPM) #if defined(TRAINER_MODULE_CPPM)
void init_trainer_module_cppm(); void init_trainer_module_cppm();
void stop_trainer_module_cppm(); void stop_trainer_module_cppm();
#else
#define init_trainer_module_cppm()
#define stop_trainer_module_cppm()
#endif #endif
#if defined(TRAINER_MODULE_SBUS) #if defined(TRAINER_MODULE_SBUS)
void init_trainer_module_sbus(); void init_trainer_module_sbus();
void stop_trainer_module_sbus(); void stop_trainer_module_sbus();
#else int trainerModuleSbusGetByte(uint8_t* byte);
#define init_trainer_module_sbus()
#define stop_trainer_module_sbus()
#endif #endif
void check_telemetry_exti(); void check_telemetry_exti();
// SBUS
int sbusGetByte(uint8_t * byte);
// Keys driver // Keys driver
enum EnumKeys enum EnumKeys
{ {
@@ -775,7 +770,7 @@ void sportSendByte(uint8_t byte);
void sportSendByteLoop(uint8_t byte); void sportSendByteLoop(uint8_t byte);
void sportStopSendByteLoop(); void sportStopSendByteLoop();
void sportSendBuffer(const uint8_t * buffer, uint32_t count); void sportSendBuffer(const uint8_t * buffer, uint32_t count);
bool telemetryGetByte(uint8_t * byte); bool sportGetByte(uint8_t * byte);
void telemetryClearFifo(); void telemetryClearFifo();
extern uint32_t telemetryErrors; extern uint32_t telemetryErrors;
@@ -860,15 +855,10 @@ void hapticOff();
void hapticOn(); void hapticOn();
#endif #endif
// Aux serial port driver
#if defined(AUX_SERIAL_GPIO)
#define DEBUG_BAUDRATE 115200 #define DEBUG_BAUDRATE 115200
#define LUA_DEFAULT_BAUDRATE 115200 #define LUA_DEFAULT_BAUDRATE 115200
#define AUX_SERIAL
#define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol) const etx_serial_port_t* auxSerialGetPort(int port_nr);
#define AUX_SERIAL_POWER_ON()
#define AUX_SERIAL_POWER_OFF()
#endif
// BT driver // BT driver
#define BLUETOOTH_BOOTLOADER_BAUDRATE 230400 #define BLUETOOTH_BOOTLOADER_BAUDRATE 230400
+8 -8
View File
@@ -1929,14 +1929,14 @@
#define TRAINER_MODULE_CPPM_TIMER_IRQn TRAINER_TIMER_IRQn #define TRAINER_MODULE_CPPM_TIMER_IRQn TRAINER_TIMER_IRQn
#define TRAINER_MODULE_CPPM_GPIO_AF GPIO_AF_TIM3 #define TRAINER_MODULE_CPPM_GPIO_AF GPIO_AF_TIM3
// Trainer SBUS input on heartbeat pin // Trainer SBUS input on heartbeat pin
#define TRAINER_MODULE_SBUS // #define TRAINER_MODULE_SBUS
#define TRAINER_MODULE_SBUS_GPIO_AF GPIO_AF_USART6 // #define TRAINER_MODULE_SBUS_GPIO_AF GPIO_AF_USART6
#define TRAINER_MODULE_SBUS_USART USART6 // #define TRAINER_MODULE_SBUS_USART USART6
#define TRAINER_MODULE_SBUS_GPIO INTMODULE_HEARTBEAT_GPIO // #define TRAINER_MODULE_SBUS_GPIO INTMODULE_HEARTBEAT_GPIO
#define TRAINER_MODULE_SBUS_GPIO_PIN INTMODULE_HEARTBEAT_GPIO_PIN // #define TRAINER_MODULE_SBUS_GPIO_PIN INTMODULE_HEARTBEAT_GPIO_PIN
#define TRAINER_MODULE_SBUS_GPIO_PinSource INTMODULE_HEARTBEAT_EXTI_PinSource // #define TRAINER_MODULE_SBUS_GPIO_PinSource INTMODULE_HEARTBEAT_EXTI_PinSource
#define TRAINER_MODULE_SBUS_DMA_STREAM DMA2_Stream1 // #define TRAINER_MODULE_SBUS_DMA_STREAM DMA2_Stream1
#define TRAINER_MODULE_SBUS_DMA_CHANNEL DMA_Channel_5 // #define TRAINER_MODULE_SBUS_DMA_CHANNEL DMA_Channel_5
#else #else
// TODO: replace SBUS trainer with S.PORT pin // TODO: replace SBUS trainer with S.PORT pin
#define TRAINER_MODULE_RCC_AHB1Periph 0 #define TRAINER_MODULE_RCC_AHB1Periph 0
+4 -14
View File
@@ -393,22 +393,12 @@ extern "C" void TELEMETRY_TIMER_IRQHandler()
telemetryPortInvertedRxBit(); telemetryPortInvertedRxBit();
} }
// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp // TODO: we should have telemetry in an higher layer,
bool telemetryGetByte(uint8_t * byte) // functions above should move to a sport_driver.cpp
//
bool sportGetByte(uint8_t * byte)
{ {
#if defined(AUX_SERIAL)
if (telemetryProtocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
if (auxSerialMode == UART_MODE_TELEMETRY)
return auxSerialRxFifo.pop(*byte);
else
return false;
}
else {
return telemetryFifo.pop(*byte);
}
#else
return telemetryFifo.pop(*byte); return telemetryFifo.pop(*byte);
#endif
} }
void telemetryClearFifo() void telemetryClearFifo()
+6 -19
View File
@@ -21,10 +21,6 @@
#include "opentx.h" #include "opentx.h"
#if defined(TRAINER_MODULE_SBUS_USART)
DMAFifo<32> trainerSbusFifo __DMA (TRAINER_MODULE_SBUS_DMA_STREAM);
#endif
void trainerSendNextFrame(); void trainerSendNextFrame();
#if defined(TRAINER_GPIO) #if defined(TRAINER_GPIO)
@@ -267,7 +263,11 @@ void stop_trainer_module_cppm()
} }
#endif #endif
// TODO: use external module serial driver
#if defined(TRAINER_MODULE_SBUS) #if defined(TRAINER_MODULE_SBUS)
static DMAFifo<32> trainerSbusFifo __DMA (TRAINER_MODULE_SBUS_DMA_STREAM);
void init_trainer_module_sbus() void init_trainer_module_sbus()
{ {
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
@@ -328,22 +328,9 @@ void stop_trainer_module_sbus()
EXTERNAL_MODULE_OFF(); EXTERNAL_MODULE_OFF();
} }
} }
#endif
#if defined(SBUS_TRAINER) int trainerModuleSbusGetByte(uint8_t* byte)
int sbusGetByte(uint8_t * byte)
{ {
switch (currentTrainerMode) { return trainerSbusFifo.pop(*byte);
#if defined(TRAINER_MODULE_SBUS_USART)
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
return trainerSbusFifo.pop(*byte);
#endif
#if defined(AUX_SERIAL_USART)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
return auxSerialRxFifo.pop(*byte);
#endif
default:
return false;
}
} }
#endif #endif
+1 -11
View File
@@ -293,17 +293,7 @@ void processCrossfireTelemetryData(uint8_t data, uint8_t module)
uint8_t * rxBuffer = getTelemetryRxBuffer(module); uint8_t * rxBuffer = getTelemetryRxBuffer(module);
uint8_t &rxBufferCount = getTelemetryRxBufferCount(module); uint8_t &rxBufferCount = getTelemetryRxBufferCount(module);
#if defined(AUX_SERIAL) telemetryMirrorSend(data);
if (g_eeGeneral.auxSerialMode == UART_MODE_TELEMETRY_MIRROR) {
auxSerialPutc(data);
}
#endif
#if defined(AUX2_SERIAL)
if (g_eeGeneral.aux2SerialMode == UART_MODE_TELEMETRY_MIRROR) {
aux2SerialPutc(data);
}
#endif
if (rxBufferCount == 0 && data != RADIO_ADDRESS && data != UART_SYNC) { if (rxBufferCount == 0 && data != RADIO_ADDRESS && data != UART_SYNC) {
TRACE("[XF] address 0x%02X error", data); TRACE("[XF] address 0x%02X error", data);
+1
View File
@@ -116,6 +116,7 @@ const uint8_t CROSSFIRE_FRAME_PERIODS[] = {
4, 4,
4, 4,
4, 4,
4,
}; };
#if SPORT_MAX_BAUDRATE < 400000 #if SPORT_MAX_BAUDRATE < 400000
// index 0 (115200) is the default 0 value // index 0 (115200) is the default 0 value
+1 -11
View File
@@ -24,17 +24,7 @@
void processFrskyTelemetryData(uint8_t data) void processFrskyTelemetryData(uint8_t data)
{ {
telemetryMirrorSend(data);
#if defined(AUX_SERIAL)
if (g_eeGeneral.auxSerialMode == UART_MODE_TELEMETRY_MIRROR) {
auxSerialPutc(data);
}
#endif
#if defined(AUX2_SERIAL)
if (g_eeGeneral.aux2SerialMode == UART_MODE_TELEMETRY_MIRROR) {
aux2SerialPutc(data);
}
#endif
if (pushFrskyTelemetryData(data)) { if (pushFrskyTelemetryData(data)) {
if (IS_FRSKY_SPORT_PROTOCOL()) { if (IS_FRSKY_SPORT_PROTOCOL()) {
+1 -11
View File
@@ -322,17 +322,7 @@ void processGhostTelemetryFrame()
void processGhostTelemetryData(uint8_t data) void processGhostTelemetryData(uint8_t data)
{ {
#if defined(AUX_SERIAL) telemetryMirrorSend(data);
if (g_eeGeneral.auxSerialMode == UART_MODE_TELEMETRY_MIRROR) {
auxSerialPutc(data);
}
#endif
#if defined(AUX2_SERIAL)
if (g_eeGeneral.aux2SerialMode == UART_MODE_TELEMETRY_MIRROR) {
aux2SerialPutc(data);
}
#endif
if (telemetryRxBufferCount == 0 && data != GHST_ADDR_RADIO) { if (telemetryRxBufferCount == 0 && data != GHST_ADDR_RADIO) {
TRACE("[GH] address 0x%02X error", data); TRACE("[GH] address 0x%02X error", data);
+3 -13
View File
@@ -257,7 +257,7 @@ static void processMultiSyncPacket(const uint8_t * data, uint8_t module)
status.update(refreshRate, inputLag); status.update(refreshRate, inputLag);
#if defined(DEBUG) #if defined(DEBUG)
serialPrint("MP ADJ: R %d, L %04d", refreshRate, inputLag); dbgSerialPrint("MP ADJ: R %d, L %04d", refreshRate, inputLag);
#endif #endif
} }
@@ -351,18 +351,8 @@ static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
uint8_t len = packet[1]; uint8_t len = packet[1];
const uint8_t * data = packet + 2; const uint8_t * data = packet + 2;
#if defined(AUX_SERIAL) for (uint8_t c = 0; c < len + 2; c++)
if (g_eeGeneral.auxSerialMode == UART_MODE_TELEMETRY_MIRROR) { telemetryMirrorSend(packet[c]);
for (uint8_t c = 0; c < len + 2; c++)
auxSerialPutc(packet[c]);
}
#endif
#if defined(AUX2_SERIAL)
if (g_eeGeneral.aux2SerialMode == UART_MODE_TELEMETRY_MIRROR) {
for (uint8_t c = 0; c < len + 2; c++)
aux2SerialPutc(packet[c]);
}
#endif
// Switch type // Switch type
switch (type) { switch (type) {
+46 -3
View File
@@ -42,8 +42,8 @@ TelemetryData telemetryData;
uint8_t telemetryProtocol = 255; uint8_t telemetryProtocol = 255;
#if defined(INTERNAL_MODULE_SERIAL_TELEMETRY) #if defined(INTERNAL_MODULE_SERIAL_TELEMETRY)
uint8_t intTelemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE]; static uint8_t intTelemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE];
uint8_t intTelemetryRxBufferCount; static uint8_t intTelemetryRxBufferCount;
#endif #endif
uint8_t * getTelemetryRxBuffer(uint8_t moduleIdx) uint8_t * getTelemetryRxBuffer(uint8_t moduleIdx)
@@ -64,6 +64,48 @@ uint8_t &getTelemetryRxBufferCount(uint8_t moduleIdx)
return telemetryRxBufferCount; return telemetryRxBufferCount;
} }
static int (*_telemetryGetByte)(void*, uint8_t*) = nullptr;
static void* _telemetryGetByteCtx = nullptr;
void telemetrySetGetByte(void* ctx, int (*fct)(void*, uint8_t*))
{
_telemetryGetByte = nullptr;
_telemetryGetByteCtx = ctx;
_telemetryGetByte = fct;
}
static bool telemetryGetByte(uint8_t* data)
{
auto _getByte = _telemetryGetByte;
auto _ctx = _telemetryGetByteCtx;
if (_getByte) {
return _getByte(_ctx, data);
}
return sportGetByte(data);
}
static void (*telemetryMirrorSendByte)(void*, uint8_t) = nullptr;
static void* telemetryMirrorSendByteCtx = nullptr;
void telemetrySetMirrorCb(void* ctx, void (*fct)(void*, uint8_t))
{
telemetryMirrorSendByte = nullptr;
telemetryMirrorSendByteCtx = ctx;
telemetryMirrorSendByte = fct;
}
void telemetryMirrorSend(uint8_t data)
{
auto _sendByte = telemetryMirrorSendByte;
auto _ctx = telemetryMirrorSendByteCtx;
if (_sendByte) {
_sendByte(_ctx, data);
}
}
void processTelemetryData(uint8_t data) void processTelemetryData(uint8_t data)
{ {
#if defined(CROSSFIRE) #if defined(CROSSFIRE)
@@ -427,7 +469,8 @@ void telemetryInit(uint8_t protocol)
#if defined(AUX_SERIAL) #if defined(AUX_SERIAL)
else if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) { else if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
telemetryPortInit(0, TELEMETRY_SERIAL_DEFAULT); telemetryPortInit(0, TELEMETRY_SERIAL_DEFAULT);
auxSerialTelemetryInit(PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY); // Note: this is done in initSerialPorts()
//auxSerialTelemetryInit(PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY);
} }
#endif #endif
+8 -1
View File
@@ -75,10 +75,17 @@ constexpr uint8_t TELEMETRY_TIMEOUT10ms = 100; // 1 second
extern uint8_t telemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE]; extern uint8_t telemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE];
extern uint8_t telemetryRxBufferCount; extern uint8_t telemetryRxBufferCount;
//TODO: use module scoped buffers instead
uint8_t* getTelemetryRxBuffer(uint8_t moduleIdx); uint8_t* getTelemetryRxBuffer(uint8_t moduleIdx);
uint8_t& getTelemetryRxBufferCount(uint8_t moduleIdx); uint8_t& getTelemetryRxBufferCount(uint8_t moduleIdx);
// Set alternative telemetry input
void telemetrySetGetByte(void* ctx, int (*fct)(void*, uint8_t*));
// Set telemetry mirror callback
void telemetrySetMirrorCb(void* ctx, void (*fct)(void*, uint8_t));
// Mirror telemetry byte
void telemetryMirrorSend(uint8_t data);
#define TELEMETRY_AVERAGE_COUNT 3 #define TELEMETRY_AVERAGE_COUNT 3
+5 -23
View File
@@ -69,20 +69,14 @@ void stopTrainer()
#if defined(TRAINER_MODULE_SBUS) #if defined(TRAINER_MODULE_SBUS)
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE: case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
sbusSetGetByte(nullptr);
stop_trainer_module_sbus(); stop_trainer_module_sbus();
break; break;
#endif #endif
#if defined(TRAINER_BATTERY_COMPARTMENT) #if defined(TRAINER_BATTERY_COMPARTMENT)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT: case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
#if defined(AUX_SERIAL) sbusSetGetByte(nullptr);
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER)
auxSerialStop();
#endif
#if defined(AUX2_SERIAL)
if (g_eeGeneral.aux2SerialMode == UART_MODE_SBUS_TRAINER)
aux2SerialStop();
#endif
break; break;
#endif #endif
} }
@@ -115,26 +109,14 @@ void checkTrainerSettings()
#if defined(TRAINER_MODULE_SBUS) #if defined(TRAINER_MODULE_SBUS)
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE: case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
init_trainer_module_sbus(); init_trainer_module_sbus();
sbusSetGetByte(trainerModuleSbusGetByte);
break; break;
#endif #endif
#if defined(TRAINER_BATTERY_COMPARTMENT) #if defined(TRAINER_BATTERY_COMPARTMENT)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT: case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
#if defined(AUX_SERIAL) sbusSetGetByte(sbusAuxGetByte);
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER) { break;
auxSerialSbusInit();
break;
}
#endif
#if defined(AUX2_SERIAL)
if (g_eeGeneral.aux2SerialMode == UART_MODE_SBUS_TRAINER) {
aux2SerialSbusInit();
break;
}
#endif
// no break
#endif #endif
case TRAINER_MODE_MASTER_TRAINER_JACK: case TRAINER_MODE_MASTER_TRAINER_JACK: