move DMA utils
This commit is contained in:
Родитель
c5ecb0a6dd
Коммит
e024ecdd1a
16
stm32/dspi.c
16
stm32/dspi.c
|
@ -194,15 +194,15 @@ static void px_fill_buffer(uint16_t *dst) {
|
|||
}
|
||||
|
||||
static void px_dma(void) {
|
||||
if (dma_has_flag(DMA_FLAG_TC)) {
|
||||
dma_clear_flag(DMA_FLAG_TC);
|
||||
if (dma_has_flag(DMA_CH_TX, DMA_FLAG_TC)) {
|
||||
dma_clear_flag(DMA_CH_TX, DMA_FLAG_TC);
|
||||
px_fill_buffer(px_state.pxscratch + (PX_SCRATCH_LEN >> 2));
|
||||
}
|
||||
if (dma_has_flag(DMA_FLAG_HT)) {
|
||||
dma_clear_flag(DMA_FLAG_HT);
|
||||
if (dma_has_flag(DMA_CH_TX, DMA_FLAG_HT)) {
|
||||
dma_clear_flag(DMA_CH_TX, DMA_FLAG_HT);
|
||||
px_fill_buffer(px_state.pxscratch);
|
||||
}
|
||||
dma_clear_flag(DMA_FLAG_G);
|
||||
dma_clear_flag(DMA_CH_TX, DMA_FLAG_G);
|
||||
if (px_state.pxdata_ptr == 0) {
|
||||
stop_dma();
|
||||
}
|
||||
|
@ -214,8 +214,8 @@ void px_tx(const void *data, uint32_t numbytes, uint8_t intensity, cb_t doneHand
|
|||
px_state.pxdata_ptr = 0;
|
||||
px_state.intensity = intensity;
|
||||
|
||||
dma_clear_flag(DMA_FLAG_TC);
|
||||
dma_clear_flag(DMA_FLAG_HT);
|
||||
dma_clear_flag(DMA_CH_TX, DMA_FLAG_TC);
|
||||
dma_clear_flag(DMA_CH_TX, DMA_FLAG_HT);
|
||||
px_fill_buffer(px_state.pxscratch);
|
||||
px_fill_buffer(px_state.pxscratch + (PX_SCRATCH_LEN >> 2));
|
||||
|
||||
|
@ -248,7 +248,7 @@ void DMA_Handler(void) {
|
|||
dma_handler();
|
||||
return;
|
||||
}
|
||||
dma_clear_flag(DMA_FLAG_G);
|
||||
dma_clear_flag(DMA_CH_TX, DMA_FLAG_G);
|
||||
stop_dma();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,27 @@ void rtc_cancel_cb(void);
|
|||
#define DMA_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#endif
|
||||
|
||||
#define DMA_FLAG_G DMA_ISR_GIF1
|
||||
#define DMA_FLAG_TC DMA_ISR_TCIF1
|
||||
#define DMA_FLAG_HT DMA_ISR_HTIF1
|
||||
#define DMA_FLAG_TE DMA_ISR_TEIF1
|
||||
|
||||
#if defined(STM32G0) || defined(STM32WL)
|
||||
static inline void dma_clear_flag(int ch, int flag) {
|
||||
WRITE_REG(DMA1->IFCR, flag << (ch*4));
|
||||
}
|
||||
|
||||
static inline bool dma_has_flag(int ch, int flag) {
|
||||
return (READ_BIT(DMA1->ISR, flag << (ch*4)) != 0);
|
||||
}
|
||||
#else
|
||||
static inline void dma_clear_flag(int ch, int flag) {
|
||||
WRITE_REG(DMA1->IFCR, flag << ((ch - 1) * 4));
|
||||
}
|
||||
|
||||
static inline bool dma_has_flag(int ch, int flag) {
|
||||
return (READ_BIT(DMA1->ISR, flag << ((ch - 1) * 4)) != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,28 +119,6 @@ STATIC_ASSERT(PIN_AMISO == -1);
|
|||
|
||||
#endif
|
||||
|
||||
#define DMA_FLAG_G DMA_ISR_GIF1
|
||||
#define DMA_FLAG_TC DMA_ISR_TCIF1
|
||||
#define DMA_FLAG_HT DMA_ISR_HTIF1
|
||||
#define DMA_FLAG_TE DMA_ISR_TEIF1
|
||||
|
||||
#if defined(STM32G0) || defined(STM32WL)
|
||||
static inline void dma_clear_flag(int flag) {
|
||||
WRITE_REG(DMA1->IFCR, flag << ((DMA_CH_TX)*4));
|
||||
}
|
||||
|
||||
static inline bool dma_has_flag(int flag) {
|
||||
return (READ_BIT(DMA1->ISR, flag << ((DMA_CH_TX)*4)) != 0);
|
||||
}
|
||||
#else
|
||||
static inline void dma_clear_flag(int flag) {
|
||||
WRITE_REG(DMA1->IFCR, flag << ((DMA_CH_TX - 1) * 4));
|
||||
}
|
||||
|
||||
static inline bool dma_has_flag(int flag) {
|
||||
return (READ_BIT(DMA1->ISR, flag << ((DMA_CH_TX - 1) * 4)) != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void spi_init0(void) {
|
||||
SPI_CLK_ENABLE();
|
||||
|
|
Загрузка…
Ссылка в новой задаче