1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-21 07:15:18 +03:00

Merge pull request #7804 from mikeller/add_missing_timer_command

Added missing 'timer <pin>' command.
This commit is contained in:
Michael Keller 2019-03-22 13:38:57 +13:00 committed by GitHub
commit c04dcd0ff7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4695,7 +4695,7 @@ dmaoptEntry_t dmaoptEntryTable[] = {
#define DMA_OPT_UI_INDEX(i) ((i) + 1) #define DMA_OPT_UI_INDEX(i) ((i) + 1)
#define DMA_OPT_STRING_BUFSIZE 5 #define DMA_OPT_STRING_BUFSIZE 5
static void dmaoptToString(int optval, char *buf) static void optToString(int optval, char *buf)
{ {
if (optval == DMA_OPT_UNUSED) { if (optval == DMA_OPT_UNUSED) {
memcpy(buf, "NONE", DMA_OPT_STRING_BUFSIZE); memcpy(buf, "NONE", DMA_OPT_STRING_BUFSIZE);
@ -4925,17 +4925,9 @@ static void cliDmaopt(char *cmdline)
pch = strtok_r(NULL, " ", &saveptr); pch = strtok_r(NULL, " ", &saveptr);
if (!pch) { if (!pch) {
if (entry) { if (entry) {
if (orgval == DMA_OPT_UNUSED) { printPeripheralDmaoptDetails(entry, index, *optaddr, true, DUMP_MASTER, cliDumpPrintLinef);
cliPrintLinef("%s %d NONE", entry->device, index + 1);
} else {
cliPrintLinef("%s %d %d", entry->device, index + 1, *optaddr);
}
} else { } else {
if (orgval == DMA_OPT_UNUSED) { printTimerDmaoptDetails(ioTag, timer, orgval, true, DUMP_MASTER, cliDumpPrintLinef);
cliPrintLinef("pin %c%02d NONE", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag));
} else {
cliPrintLinef("pin %c%02d %d", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag), orgval);
}
} }
return; return;
@ -4955,22 +4947,30 @@ static void cliDmaopt(char *cmdline)
return; return;
} else if (pch) { } else if (pch) {
int optval; int optval;
if (strcasecmp(pch, "none") == 0) { if (strcasecmp(pch, "none") == 0) {
optval = DMA_OPT_UNUSED; optval = DMA_OPT_UNUSED;
} else { } else {
optval = atoi(pch); optval = atoi(pch);
if (optval < 0 || (entry && optval >= MAX_PERIPHERAL_DMA_OPTIONS) || (!entry && optval >= MAX_TIMER_DMA_OPTIONS)) {
cliPrintErrorLinef("BAD DMA OPTION NUMBER '%s'", pch);
return; if (entry) {
if (!dmaGetChannelSpecByPeripheral(entry->peripheral, index, optval)) {
cliPrintErrorLinef("INVALID DMA OPTION FOR %s %d: '%s'", entry->device, DMA_OPT_UI_INDEX(index), pch);
return;
}
} else {
if (!dmaGetChannelSpecByTimerValue(timer->tim, timer->channel, optval)) {
cliPrintErrorLinef("INVALID DMA OPTION FOR PIN %c%02d: '%s'", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag), pch);
return;
}
} }
} }
char optvalString[5]; char optvalString[DMA_OPT_STRING_BUFSIZE];
char orgvalString[5]; char orgvalString[DMA_OPT_STRING_BUFSIZE];
dmaoptToString(optval, optvalString); optToString(optval, optvalString);
dmaoptToString(orgval, orgvalString); optToString(orgval, orgvalString);
if (optval != orgval) { if (optval != orgval) {
if (entry) { if (entry) {
@ -4991,8 +4991,6 @@ static void cliDmaopt(char *cmdline)
cliPrintLinef("dma %c%02d: no change: %s", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag),orgvalString); cliPrintLinef("dma %c%02d: no change: %s", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag),orgvalString);
} }
} }
} else {
cliPrintLinef("bad option %s", pch);
} }
} }
#endif // USE_DMA_SPEC #endif // USE_DMA_SPEC
@ -5110,11 +5108,20 @@ static void cliResource(char *cmdline)
#endif // USE_RESOURCE_MGMT #endif // USE_RESOURCE_MGMT
#ifdef USE_TIMER_MGMT #ifdef USE_TIMER_MGMT
static void printTimerDetails(const ioTag_t ioTag, const unsigned timerIndex, const bool equalsDefault, const dumpFlags_t dumpMask, printFn *printValue)
{
const char *format = "timer %c%02d %d";
printValue(dumpMask, equalsDefault, format,
IO_GPIOPortIdxByTag(ioTag) + 'A',
IO_GPIOPinIdxByTag(ioTag),
timerIndex - 1
);
}
static void printTimer(dumpFlags_t dumpMask) static void printTimer(dumpFlags_t dumpMask)
{ {
const char *format = "timer %c%02d %d";
const pgRegistry_t* pg = pgFind(PG_TIMER_IO_CONFIG); const pgRegistry_t* pg = pgFind(PG_TIMER_IO_CONFIG);
const timerIOConfig_t *currentConfig; const timerIOConfig_t *currentConfig;
const timerIOConfig_t *defaultConfig; const timerIOConfig_t *defaultConfig;
@ -5150,21 +5157,15 @@ static void printTimer(dumpFlags_t dumpMask)
const bool equalsDefault = defaultTimerIndex == timerIndex; const bool equalsDefault = defaultTimerIndex == timerIndex;
if (defaultConfig && defaultTimerIndex) { if (defaultConfig && defaultTimerIndex) {
cliDefaultPrintLinef(dumpMask, equalsDefault, format, printTimerDetails(ioTag, defaultTimerIndex, equalsDefault, dumpMask, cliDefaultPrintLinef);
IO_GPIOPortIdxByTag(ioTag) + 'A',
IO_GPIOPinIdxByTag(ioTag),
defaultTimerIndex - 1
);
} }
cliDumpPrintLinef(dumpMask, equalsDefault, format, printTimerDetails(ioTag, timerIndex, equalsDefault, dumpMask, cliDumpPrintLinef);
IO_GPIOPortIdxByTag(ioTag) + 'A',
IO_GPIOPinIdxByTag(ioTag),
timerIndex - 1
);
} }
} }
#define TIMER_INDEX_UNDEFINED -1
static void cliTimer(char *cmdline) static void cliTimer(char *cmdline)
{ {
int len = strlen(cmdline); int len = strlen(cmdline);
@ -5185,24 +5186,31 @@ static void cliTimer(char *cmdline)
char *pch = NULL; char *pch = NULL;
char *saveptr; char *saveptr;
int timerIOIndex = -1;
ioTag_t ioTag = 0; ioTag_t ioTag = IO_TAG_NONE;
pch = strtok_r(cmdline, " ", &saveptr); pch = strtok_r(cmdline, " ", &saveptr);
if (!pch || !(strToPin(pch, &ioTag) && IOGetByTag(ioTag))) { if (!pch || !(strToPin(pch, &ioTag) && IOGetByTag(ioTag))) {
goto error; cliShowParseError();
return;
} }
int timerIOIndex = TIMER_INDEX_UNDEFINED;
bool isNewTimerOpt = false;
/* find existing entry, or go for next available */ /* find existing entry, or go for next available */
for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) { for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) {
if (timerIOConfig(i)->ioTag == ioTag) { if (timerIOConfig(i)->ioTag == ioTag) {
timerIOIndex = i; timerIOIndex = i;
break; break;
} }
/* first available empty slot */ /* first available empty slot */
if (timerIOIndex < 0 && timerIOConfig(i)->ioTag == IO_TAG_NONE) { if (timerIOConfig(i)->ioTag == IO_TAG_NONE) {
timerIOIndex = i; timerIOIndex = i;
isNewTimerOpt = true;
break;
} }
} }
@ -5212,42 +5220,58 @@ static void cliTimer(char *cmdline)
return; return;
} }
uint8_t timerIndex = 0;
pch = strtok_r(NULL, " ", &saveptr); pch = strtok_r(NULL, " ", &saveptr);
if (pch) { if (pch) {
int timerIndex;
if (strcasecmp(pch, "list") == 0) { if (strcasecmp(pch, "list") == 0) {
/* output the list of available options */ /* output the list of available options */
uint8_t index = 0; const timerHardware_t *timer;
for (unsigned i = 0; i < TIMER_CHANNEL_COUNT; i++) { for (unsigned index = 0; (timer = timerGetByTagAndIndex(ioTag, index + 1)); index++) {
if (TIMER_HARDWARE[i].tag == ioTag) { cliPrintLinef("# %d: TIM%d CH%d",
cliPrintLinef("# %d. TIM%d CH%d", index,
index, timerGetTIMNumber(timer->tim),
timerGetTIMNumber(TIMER_HARDWARE[i].tim), CC_INDEX_FROM_CHANNEL(timer->channel) + 1
CC_INDEX_FROM_CHANNEL(TIMER_HARDWARE[i].channel) + 1 );
);
index++;
}
} }
return; return;
} else if (strcasecmp(pch, "none") == 0) { } else if (strcasecmp(pch, "none") == 0) {
goto success; timerIndex = TIMER_INDEX_UNDEFINED;
} else { } else {
timerIndex = atoi(pch) + 1; timerIndex = atoi(pch);
const timerHardware_t *timer = timerGetByTagAndIndex(ioTag, timerIndex + 1);
if (!timer) {
cliPrintErrorLinef("INVALID TIMER OPTION FOR %c%02d: '%s'", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag), pch);
return;
}
} }
uint8_t oldTimerIndex = isNewTimerOpt ? 0 : timerIOConfig(timerIOIndex)->index - 1;
timerIOConfigMutable(timerIOIndex)->ioTag = timerIndex == TIMER_INDEX_UNDEFINED ? IO_TAG_NONE : ioTag;
timerIOConfigMutable(timerIOIndex)->index = timerIndex + 1;
timerIOConfigMutable(timerIOIndex)->dmaopt = DMA_OPT_UNUSED;
char optvalString[DMA_OPT_STRING_BUFSIZE];
optToString(timerIndex, optvalString);
char orgvalString[DMA_OPT_STRING_BUFSIZE];
optToString(oldTimerIndex, orgvalString);
if (timerIndex == oldTimerIndex) {
cliPrintLinef("timer %c%02d: no change: %s", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag), orgvalString);
} else {
cliPrintLinef("timer %c%02d: changed from %s to %s", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag), orgvalString, optvalString);
}
return;
} else { } else {
goto error; printTimerDetails(ioTag, timerIOConfig(timerIOIndex)->index, false, DUMP_MASTER, cliDumpPrintLinef);
}
success: return;
timerIOConfigMutable(timerIOIndex)->ioTag = timerIndex == 0 ? IO_TAG_NONE : ioTag; }
timerIOConfigMutable(timerIOIndex)->index = timerIndex;
timerIOConfigMutable(timerIOIndex)->dmaopt = DMA_OPT_UNUSED;
cliPrintLine("Success");
return;
error:
cliShowParseError();
} }
#endif #endif