diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index e23a24f2a4..e3af676cec 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -5440,15 +5440,8 @@ static int displayNumberToDmaOptIndex(dmaoptEntry_t *entry, int dispNum) return timerGetIndexByNumber(dispNum); } - return dispNum > entry->maxIndex ? -1 : dispNum - 1; -} - -static int dmaOptIndexToPeripheralMappingIndex(dmaoptEntry_t *entry, int index) -{ - if (entry->peripheral == DMA_PERIPH_TIMUP) { - return timerGetNumberByIndex(index) - 1; // TIM1 = 0, TIM20 = 19 - } - return index; + const int index = dispNum - 1; + return (index < 0 || index >= entry->maxIndex) ? -1 : index; } static void printPeripheralDmaoptDetails(dmaoptEntry_t *entry, int index, const dmaoptValue_t dmaopt, const bool equalsDefault, const dumpFlags_t dumpMask, printFn *printValue) @@ -5468,7 +5461,7 @@ static void printPeripheralDmaoptDetails(dmaoptEntry_t *entry, int index, const "dma %s %d %d", entry->device, uiIndex, dmaopt); - const dmaChannelSpec_t *dmaChannelSpec = dmaGetChannelSpecByPeripheral(entry->peripheral, dmaOptIndexToPeripheralMappingIndex(entry, index), dmaopt); + const dmaChannelSpec_t *dmaChannelSpec = dmaGetChannelSpecByPeripheral(entry->peripheral, index, dmaopt); dmaCode_t dmaCode = 0; if (dmaChannelSpec) { dmaCode = dmaChannelSpec->code; @@ -5717,7 +5710,7 @@ static void cliDmaopt(const char *cmdName, char *cmdline) // Show possible opts const dmaChannelSpec_t *dmaChannelSpec; if (entry) { - for (int opt = 0; (dmaChannelSpec = dmaGetChannelSpecByPeripheral(entry->peripheral, dmaOptIndexToPeripheralMappingIndex(entry, index), opt)); opt++) { + for (int opt = 0; (dmaChannelSpec = dmaGetChannelSpecByPeripheral(entry->peripheral, index, opt)); opt++) { cliPrintLinef("# %d: " DMASPEC_FORMAT_STRING, opt, DMA_CODE_CONTROLLER(dmaChannelSpec->code), DMA_CODE_STREAM(dmaChannelSpec->code), DMA_CODE_CHANNEL(dmaChannelSpec->code)); } } else { @@ -5735,7 +5728,7 @@ static void cliDmaopt(const char *cmdName, char *cmdline) optval = atoi(pch); if (entry) { - if (!dmaGetChannelSpecByPeripheral(entry->peripheral, dmaOptIndexToPeripheralMappingIndex(entry, index), optval)) { + if (!dmaGetChannelSpecByPeripheral(entry->peripheral, index, optval)) { cliPrintErrorLinef(cmdName, "INVALID DMA OPTION FOR %s %d: '%s'", entry->device, getDmaOptDisplayNumber(entry, index), pch); return; diff --git a/src/platform/AT32/dma_reqmap_mcu.c b/src/platform/AT32/dma_reqmap_mcu.c index 653efd3c3f..96ef5551c7 100644 --- a/src/platform/AT32/dma_reqmap_mcu.c +++ b/src/platform/AT32/dma_reqmap_mcu.c @@ -49,7 +49,7 @@ typedef struct dmaTimerMapping_s { #define REQMAP_SGL(periph) { DMA_PERIPH_ ## periph, 0, DMA_REQUEST_ ## periph } #define REQMAP(periph, device) { DMA_PERIPH_ ## periph, periph ## DEV_ ## device, DMA_REQUEST_ ## periph ## device } #define REQMAP_DIR(periph, device, dir) { DMA_PERIPH_ ## periph ## _ ## dir, periph ## DEV_ ## device, DMA_REQUEST_ ## periph ## device ## _ ## dir } -#define REQMAP_TIMUP(periph, timno) { DMA_PERIPH_TIMUP, timno - 1, DMAMUX_DMAREQ_ID_ ## TMR ## timno ## _OVERFLOW } +#define REQMAP_TIMUP(periph, timno) { DMA_PERIPH_TIMUP, TIMER_INDEX(timno), DMAMUX_DMAREQ_ID_ ## TMR ## timno ## _OVERFLOW } #define DMA_REQUEST_UART1_RX DMAMUX_DMAREQ_ID_USART1_RX #define DMA_REQUEST_UART1_TX DMAMUX_DMAREQ_ID_USART1_TX diff --git a/src/platform/STM32/dma_reqmap_mcu.c b/src/platform/STM32/dma_reqmap_mcu.c index 57001a1919..e2862119e9 100644 --- a/src/platform/STM32/dma_reqmap_mcu.c +++ b/src/platform/STM32/dma_reqmap_mcu.c @@ -59,7 +59,7 @@ typedef struct dmaTimerMapping_s { #define REQMAP_SGL(periph) { DMA_PERIPH_ ## periph, 0, DMA_REQUEST_ ## periph } #define REQMAP(periph, device) { DMA_PERIPH_ ## periph, periph ## DEV_ ## device, DMA_REQUEST_ ## periph ## device } #define REQMAP_DIR(periph, device, dir) { DMA_PERIPH_ ## periph ## _ ## dir, periph ## DEV_ ## device, DMA_REQUEST_ ## periph ## device ## _ ## dir } -#define REQMAP_TIMUP(periph, timno) { DMA_PERIPH_TIMUP, timno - 1, DMA_REQUEST_ ## TIM ## timno ## _UP } +#define REQMAP_TIMUP(periph, timno) { DMA_PERIPH_TIMUP, TIMER_INDEX(timno), DMA_REQUEST_ ## TIM ## timno ## _UP } // Resolve UART/USART mess #define DMA_REQUEST_UART1_RX DMA_REQUEST_USART1_RX @@ -215,7 +215,7 @@ static dmaChannelSpec_t dmaChannelSpec[MAX_PERIPHERAL_DMA_OPTIONS] = { #define REQMAP_SGL(periph) { DMA_PERIPH_ ## periph, 0, DMA_REQUEST_ ## periph } #define REQMAP(periph, device) { DMA_PERIPH_ ## periph, periph ## DEV_ ## device, DMA_REQUEST_ ## periph ## device } #define REQMAP_DIR(periph, device, dir) { DMA_PERIPH_ ## periph ## _ ## dir, periph ## DEV_ ## device, DMA_REQUEST_ ## periph ## device ## _ ## dir } -#define REQMAP_TIMUP(periph, timno) { DMA_PERIPH_TIMUP, timno - 1, DMA_REQUEST_ ## TIM ## timno ## _UP } +#define REQMAP_TIMUP(periph, timno) { DMA_PERIPH_TIMUP, TIMER_INDEX(timno), DMA_REQUEST_ ## TIM ## timno ## _UP } // Resolve UART/USART mess #define DMA_REQUEST_UART1_RX DMA_REQUEST_USART1_RX