diff options
author | blmorris <bryan.morrissey@gmail.com> | 2015-06-22 09:24:59 -0400 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-06-24 17:48:52 +0100 |
commit | c5175526dda06d278dd569dd7bfce0c65cbbe5fc (patch) | |
tree | 004a5e65a9fa3d1e8672b587f7b329edf517ba33 /stmhal/dma.c | |
parent | 3299f687f5b3b328008b568473c31dc8796a43c4 (diff) |
stmhal/dma.c: Modify dma_init() to accept init struct as an argument
This removes hard-coded DMA init params from dma_init(), instead defining
these parameters in a DMA_InitTypeDef struct that gets passed as an
argument to dma_init()
This makes dma_init more generic so it can be used for I2S and SD Card,
which require different initialization parameters.
Diffstat (limited to 'stmhal/dma.c')
-rw-r--r-- | stmhal/dma.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/stmhal/dma.c b/stmhal/dma.c index 93c35d61d..77474b767 100644 --- a/stmhal/dma.c +++ b/stmhal/dma.c @@ -52,6 +52,23 @@ static const uint8_t dma_irqn[NSTREAM] = { DMA2_Stream7_IRQn, }; +// Default parameters to dma_init() shared by spi and i2c; Channel and Direction +// vary depending on the peripheral instance so they get passed separately +const DMA_InitTypeDef dma_init_struct_spi_i2c = { + .Channel = 0, + .Direction = 0, + .PeriphInc = DMA_PINC_DISABLE, + .MemInc = DMA_MINC_ENABLE, + .PeriphDataAlignment = DMA_PDATAALIGN_BYTE, + .MemDataAlignment = DMA_MDATAALIGN_BYTE, + .Mode = DMA_NORMAL, + .Priority = DMA_PRIORITY_LOW, + .FIFOMode = DMA_FIFOMODE_DISABLE, + .FIFOThreshold = DMA_FIFO_THRESHOLD_FULL, + .MemBurst = DMA_MBURST_INC4, + .PeriphBurst = DMA_PBURST_INC4 +}; + static DMA_HandleTypeDef *dma_handle[NSTREAM] = {NULL}; static uint32_t dma_last_channel[NSTREAM]; @@ -80,7 +97,7 @@ static int get_dma_id(DMA_Stream_TypeDef *dma_stream) { } } -void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, uint32_t dma_channel, uint32_t direction, void *data) { +void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, const DMA_InitTypeDef *dma_init, uint32_t dma_channel, uint32_t direction, void *data) { int dma_id = get_dma_id(dma_stream); //printf("dma_init(%p, %p(%d), 0x%x, 0x%x, %p)\n", dma, dma_stream, dma_id, (uint)dma_channel, (uint)direction, data); @@ -90,9 +107,11 @@ void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, uint32_t d // set global pointer for IRQ handler dma_handle[dma_id] = dma; - // initialise critical parameters + // initialise parameters dma->Instance = dma_stream; + dma->Init = *dma_init; dma->Init.Direction = direction; + dma->Init.Channel = dma_channel; // half of __HAL_LINKDMA(data, xxx, *dma) // caller must implement other half by doing: data->xxx = dma @@ -105,19 +124,6 @@ void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, uint32_t d } dma_last_channel[dma_id] = dma_channel; - // set DMA parameters (these are only used by HAL_DMA_Init) - dma->Init.Channel = dma_channel; - dma->Init.PeriphInc = DMA_PINC_DISABLE; - dma->Init.MemInc = DMA_MINC_ENABLE; - dma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - dma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - dma->Init.Mode = DMA_NORMAL; - dma->Init.Priority = DMA_PRIORITY_LOW; - dma->Init.FIFOMode = DMA_FIFOMODE_DISABLE; - dma->Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; - dma->Init.MemBurst = DMA_MBURST_INC4; - dma->Init.PeriphBurst = DMA_PBURST_INC4; - // enable clock for needed DMA peripheral if (dma_id <= 7) { __DMA1_CLK_ENABLE(); |