|
看了下这个例子,整的还挺麻烦,不过MDMA的确是功能强不少,但是用起来不顺手。
配置:
- /**
- * @brief Initialize the MDMA For repeat block transfer in linked list circular
- with trigger set to DMA2D Transfer complete flag and trigger mode set to
- repeat block transfer.
- * @param None
- * @retval None
- */
- static void MDMA_Config(void)
- {
- uint32_t hal_status = HAL_OK;
- MDMA_LinkNodeConfTypeDef mdmaLinkNodeConfig;
-
- /*##-1- Enable the MDMA clock ###############################################*/
- __HAL_RCC_MDMA_CLK_ENABLE();
-
- /*##-2- Select the MDMA instance to be used : MDMA_Channel0 #################*/
- MDMA_Handle.Instance = MDMA_Channel0;
-
- /*##-3- Configure the MDMA for block transfer in HW request mode ############*/
- /*
- Config the MDMA to copy the source image to the LCD frame buffer at the center
- position with 180?rotation and mirror effect.
- Each block corresponds to a line of the source/destination image.
- The number of blocks corresponds to the number of lines of the image.
-
- The MDMA Request is set to DMA2D Transfer complete flag and the MDMA trigger Mode
- is set to Repeat block mode. As consequence each DMA2D transfer complete event
- (DMA2D has end copying an image to the Top-center of the LCD frame buffer ),
- the MDMA will start a repeat block transfer which correspond of copying the DMA2D
- image with 180?and rotation effect to the bottom-center of the LCD frame buffer.
- */
-
- MDMA_Handle.Init.Request = MDMA_REQUEST_DMA2D_TC;
- MDMA_Handle.Init.TransferTriggerMode = MDMA_REPEAT_BLOCK_TRANSFER;
- MDMA_Handle.Init.Priority = MDMA_PRIORITY_HIGH;
- MDMA_Handle.Init.Endianness = MDMA_LITTLE_ENDIANNESS_PRESERVE;
- MDMA_Handle.Init.DataAlignment = MDMA_DATAALIGN_PACKENABLE;
- MDMA_Handle.Init.SourceBurst = MDMA_SOURCE_BURST_SINGLE;
- MDMA_Handle.Init.DestBurst = MDMA_DEST_BURST_SINGLE;
- MDMA_Handle.Init.BufferTransferLength = 128;
-
- /* Source and Destination data size are word , 4 bytes that correspond to an ARGB8888 pixel 32 bpp */
- MDMA_Handle.Init.SourceDataSize = MDMA_SRC_DATASIZE_WORD;
- MDMA_Handle.Init.DestDataSize = MDMA_DEST_DATASIZE_WORD;
-
- /* Source and Destination Increment is word , 4 bytes that correspond to an ARGB8888 pixel 32 bpp */
- MDMA_Handle.Init.SourceInc = MDMA_SRC_INC_WORD;
- MDMA_Handle.Init.DestinationInc = MDMA_DEST_INC_WORD;
- /*Source Block address offset is set to LCD Offset as the source image is in the center of the LCD */
- MDMA_Handle.Init.SourceBlockAddressOffset = (int32_t)LCD_Offset;
-
- /* Destination Block address offset is set in order to place the image in the center of the LCD frame buffer
- the destination blocks are not contiguous. The LCD_Offset is = to LCD X size - image width
- Knowing that the destination address is set to the first pixel address of the last line
- in the destination image, the destination block offset allows to decrement the destination address
- after each block in order to start the next block at previous line */
- MDMA_Handle.Init.DestBlockAddressOffset = ((-2) * ((int32_t)(ARGB8888_BYTES_PER_PIXEL * IMAGE_WIDTH))) - ((int32_t)LCD_Offset);
-
- /*##-4- Initialize the MDMA channel ##########################################*/
- hal_status = HAL_MDMA_Init(&MDMA_Handle);
-
- if(hal_status != HAL_OK)
- {
- /* Initialization Error */
- Error_Handler();
- }
- HAL_MDMA_ConfigPostRequestMask(&MDMA_Handle, 0, 0);
-
- /*##-5- Create Linked list Node ############################################*/
-
- /*
- Create and add a linked list node that have the same parameters as the
- initial transfer.
- The purpose of the linked list node is to create a circular list. the MDMA
- transfer will then loop infinitely. Each DMA2D Transfer complete flag will trig
- a Node transfer ( a repeat block transfer) that correspond to a new image transfer
- */
- mdmaLinkNodeConfig.Init.Request = MDMA_Handle.Init.Request;
- mdmaLinkNodeConfig.Init.TransferTriggerMode = MDMA_Handle.Init.TransferTriggerMode;
- mdmaLinkNodeConfig.Init.Priority = MDMA_Handle.Init.Priority;
- mdmaLinkNodeConfig.Init.Endianness = MDMA_Handle.Init.Endianness;
-
- mdmaLinkNodeConfig.Init.SourceInc = MDMA_Handle.Init.SourceInc;
- mdmaLinkNodeConfig.Init.DestinationInc = MDMA_Handle.Init.DestinationInc;
-
- mdmaLinkNodeConfig.Init.SourceDataSize = MDMA_Handle.Init.SourceDataSize;
- mdmaLinkNodeConfig.Init.DestDataSize = MDMA_Handle.Init.DestDataSize;
- mdmaLinkNodeConfig.Init.DataAlignment = MDMA_Handle.Init.DataAlignment;
- mdmaLinkNodeConfig.Init.SourceBurst = MDMA_Handle.Init.SourceBurst;
- mdmaLinkNodeConfig.Init.DestBurst = MDMA_Handle.Init.DestBurst;
- mdmaLinkNodeConfig.Init.BufferTransferLength = MDMA_Handle.Init.BufferTransferLength;
-
- mdmaLinkNodeConfig.Init.SourceBlockAddressOffset = MDMA_Handle.Init.SourceBlockAddressOffset;
- mdmaLinkNodeConfig.Init.DestBlockAddressOffset = MDMA_Handle.Init.DestBlockAddressOffset;
-
- mdmaLinkNodeConfig.PostRequestMaskAddress = 0;
- mdmaLinkNodeConfig.PostRequestMaskData = 0;
-
- /* Create Node*/
- mdmaLinkNodeConfig.SrcAddress = dma2d_destination;
- mdmaLinkNodeConfig.DstAddress = mdma_destination;
- mdmaLinkNodeConfig.BlockDataLength = IMAGE_WIDTH * ARGB8888_BYTES_PER_PIXEL;
- mdmaLinkNodeConfig.BlockCount = IMAGE_HEIGHT;
- HAL_MDMA_LinkedList_CreateNode(&Xfer_Node, &mdmaLinkNodeConfig);
-
- /*Add created Node to the linkedlist */
- HAL_MDMA_LinkedList_AddNode(&MDMA_Handle, &Xfer_Node, 0);
-
- /* Make the linked list circular */
- HAL_MDMA_LinkedList_EnableCircularMode(&MDMA_Handle);
-
- /*
- As the MDMA Node descriptor "Xfer_Node" is located in the D1 AXI-SRAM which
- is cacheable, it is necessary to clean the data cache after creating the node
- in order to make sure that the MDMA will load up to date data from the linked list node
- */
- SCB_CleanDCache_by_Addr((uint32_t *)&(Xfer_Node), sizeof(MDMA_LinkNodeTypeDef));
-
- /*##-6- Select Callbacks functions called after MDMA Repeat block Transfer complete and Transfer error */
- HAL_MDMA_RegisterCallback(&MDMA_Handle, HAL_MDMA_XFER_REPBLOCKCPLT_CB_ID, MDMA_RepeatBlockTransferCompleteCallback);
- HAL_MDMA_RegisterCallback(&MDMA_Handle, HAL_MDMA_XFER_ERROR_CB_ID, MDMA_TransferErrorCallback);
-
- /*##-7- Configure NVIC for MDMA transfer complete/error interrupts ##########*/
- /* Set Interrupt Group Priority */
- HAL_NVIC_SetPriority(MDMA_IRQn, 0, 0);
-
- /* Enable the MDMA channel global Interrupt */
- HAL_NVIC_EnableIRQ(MDMA_IRQn);
-
-
- }
复制代码
|
|