mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 03:20:00 +03:00
Optimize timer index lookup and fix CLI DMA option boundaries
This commit is contained in:
parent
80fdbc17fc
commit
4e9fd6550b
5 changed files with 12 additions and 32 deletions
|
@ -5418,29 +5418,29 @@ static void optToString(int optval, char *buf)
|
||||||
static int getDmaOptDisplayNumber(dmaoptEntry_t *entry, int index)
|
static int getDmaOptDisplayNumber(dmaoptEntry_t *entry, int index)
|
||||||
{
|
{
|
||||||
if (entry->peripheral == DMA_PERIPH_TIMUP) {
|
if (entry->peripheral == DMA_PERIPH_TIMUP) {
|
||||||
int uiIndex = timerGetNumberByIndex(index);
|
const int dispNum = timerGetNumberByIndex(index);
|
||||||
if (!(TIM_N(uiIndex) & entry->presenceMask)) {
|
if (!(TIM_N(dispNum) & entry->presenceMask)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return uiIndex;
|
return dispNum;
|
||||||
}
|
}
|
||||||
return DMA_OPT_UI_INDEX(index);
|
return DMA_OPT_UI_INDEX(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int displayNumberToDmaOptIndex(dmaoptEntry_t *entry, int index)
|
static int displayNumberToDmaOptIndex(dmaoptEntry_t *entry, int dispNum)
|
||||||
{
|
{
|
||||||
if (index <= 0) {
|
if (dispNum < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry->peripheral == DMA_PERIPH_TIMUP) {
|
if (entry->peripheral == DMA_PERIPH_TIMUP) {
|
||||||
if (!(entry->presenceMask & TIM_N(index))) {
|
if (!(entry->presenceMask & TIM_N(dispNum))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return timerGetIndexByNumber(index);
|
return timerGetIndexByNumber(dispNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
return index > entry->maxIndex ? -1 : index - 1;
|
return dispNum > entry->maxIndex ? -1 : dispNum - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dmaOptIndexToPeripheralMappingIndex(dmaoptEntry_t *entry, int index)
|
static int dmaOptIndexToPeripheralMappingIndex(dmaoptEntry_t *entry, int index)
|
||||||
|
|
|
@ -286,12 +286,7 @@ int8_t timerGetNumberByIndex(uint8_t index)
|
||||||
|
|
||||||
int8_t timerGetIndexByNumber(uint8_t number)
|
int8_t timerGetIndexByNumber(uint8_t number)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < USED_TIMER_COUNT; i++) {
|
return TIM_N(number) & USED_TIMERS ? popcount((TIM_N(number) - 1) & USED_TIMERS) : -1;
|
||||||
if (timerNumbers[i] == number) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t timerGetTIMNumber(const TMR_TypeDef *tim)
|
int8_t timerGetTIMNumber(const TMR_TypeDef *tim)
|
||||||
|
|
|
@ -285,12 +285,7 @@ int8_t timerGetNumberByIndex(uint8_t index)
|
||||||
|
|
||||||
int8_t timerGetIndexByNumber(uint8_t number)
|
int8_t timerGetIndexByNumber(uint8_t number)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < USED_TIMER_COUNT; i++) {
|
return TIM_N(number) & USED_TIMERS ? popcount((TIM_N(number) - 1) & USED_TIMERS) : -1;
|
||||||
if (timerNumbers[i] == number) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t timerGetTIMNumber(const tmr_type *tim)
|
int8_t timerGetTIMNumber(const tmr_type *tim)
|
||||||
|
|
|
@ -294,12 +294,7 @@ int8_t timerGetNumberByIndex(uint8_t index)
|
||||||
|
|
||||||
int8_t timerGetIndexByNumber(uint8_t number)
|
int8_t timerGetIndexByNumber(uint8_t number)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < USED_TIMER_COUNT; i++) {
|
return TIM_N(number) & USED_TIMERS ? popcount((TIM_N(number) - 1) & USED_TIMERS) : -1;
|
||||||
if (timerNumbers[i] == number) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t timerGetTIMNumber(const TIM_TypeDef *tim)
|
int8_t timerGetTIMNumber(const TIM_TypeDef *tim)
|
||||||
|
|
|
@ -276,12 +276,7 @@ int8_t timerGetNumberByIndex(uint8_t index)
|
||||||
|
|
||||||
int8_t timerGetIndexByNumber(uint8_t number)
|
int8_t timerGetIndexByNumber(uint8_t number)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < USED_TIMER_COUNT; i++) {
|
return TIM_N(number) & USED_TIMERS ? popcount((TIM_N(number) - 1) & USED_TIMERS) : -1;
|
||||||
if (timerNumbers[i] == number) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t timerGetTIMNumber(const TIM_TypeDef *tim)
|
int8_t timerGetTIMNumber(const TIM_TypeDef *tim)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue