You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.6 KiB
158 lines
4.6 KiB
2 years ago
|
/* USER CODE BEGIN Header */
|
||
|
/**
|
||
|
******************************************************************************
|
||
|
* File Name : SAI.c
|
||
|
* Description : This file provides code for the configuration
|
||
|
* of the SAI instances.
|
||
|
******************************************************************************
|
||
|
* @attention
|
||
|
*
|
||
|
* Copyright (c) 2022 STMicroelectronics.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||
|
* in the root directory of this software component.
|
||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||
|
*
|
||
|
******************************************************************************
|
||
|
*/
|
||
|
/* USER CODE END Header */
|
||
|
|
||
|
/* Includes ------------------------------------------------------------------*/
|
||
|
#include "sai.h"
|
||
|
|
||
|
/* USER CODE BEGIN 0 */
|
||
|
|
||
|
/* USER CODE END 0 */
|
||
|
|
||
|
SAI_HandleTypeDef hsai_BlockA1;
|
||
|
|
||
|
/* SAI1 init function */
|
||
|
void MX_SAI1_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN SAI1_Init 0 */
|
||
|
|
||
|
/* USER CODE END SAI1_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN SAI1_Init 1 */
|
||
|
|
||
|
/* USER CODE END SAI1_Init 1 */
|
||
|
|
||
|
hsai_BlockA1.Instance = SAI1_Block_A;
|
||
|
hsai_BlockA1.Init.Protocol = SAI_FREE_PROTOCOL;
|
||
|
hsai_BlockA1.Init.AudioMode = SAI_MODEMASTER_TX;
|
||
|
hsai_BlockA1.Init.DataSize = SAI_DATASIZE_8;
|
||
|
hsai_BlockA1.Init.FirstBit = SAI_FIRSTBIT_MSB;
|
||
|
hsai_BlockA1.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
|
||
|
hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS;
|
||
|
hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
|
||
|
hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
|
||
|
hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
|
||
|
hsai_BlockA1.Init.ClockSource = SAI_CLKSOURCE_PLLSAI;
|
||
|
hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_192K;
|
||
|
hsai_BlockA1.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
|
||
|
hsai_BlockA1.Init.MonoStereoMode = SAI_STEREOMODE;
|
||
|
hsai_BlockA1.Init.CompandingMode = SAI_NOCOMPANDING;
|
||
|
hsai_BlockA1.Init.TriState = SAI_OUTPUT_NOTRELEASED;
|
||
|
hsai_BlockA1.FrameInit.FrameLength = 8;
|
||
|
hsai_BlockA1.FrameInit.ActiveFrameLength = 1;
|
||
|
hsai_BlockA1.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
|
||
|
hsai_BlockA1.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
|
||
|
hsai_BlockA1.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
|
||
|
hsai_BlockA1.SlotInit.FirstBitOffset = 0;
|
||
|
hsai_BlockA1.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
|
||
|
hsai_BlockA1.SlotInit.SlotNumber = 1;
|
||
|
hsai_BlockA1.SlotInit.SlotActive = 0x00000000;
|
||
|
if (HAL_SAI_Init(&hsai_BlockA1) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
/* USER CODE BEGIN SAI1_Init 2 */
|
||
|
|
||
|
/* USER CODE END SAI1_Init 2 */
|
||
|
|
||
|
}
|
||
|
static uint32_t SAI1_client =0;
|
||
|
|
||
|
void HAL_SAI_MspInit(SAI_HandleTypeDef* saiHandle)
|
||
|
{
|
||
|
|
||
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||
|
/* SAI1 */
|
||
|
if(saiHandle->Instance==SAI1_Block_A)
|
||
|
{
|
||
|
/* SAI1 clock enable */
|
||
|
if (SAI1_client == 0)
|
||
|
{
|
||
|
__HAL_RCC_SAI1_CLK_ENABLE();
|
||
|
}
|
||
|
SAI1_client ++;
|
||
|
|
||
|
/**SAI1_A_Block_A GPIO Configuration
|
||
|
PE4 ------> SAI1_FS_A
|
||
|
PE5 ------> SAI1_SCK_A
|
||
|
PD6 ------> SAI1_SD_A
|
||
|
PG7 ------> SAI1_MCLK_A
|
||
|
*/
|
||
|
GPIO_InitStruct.Pin = SAI1_FSA_Pin|SAI1_SCKA_Pin;
|
||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||
|
GPIO_InitStruct.Alternate = GPIO_AF6_SAI1;
|
||
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||
|
|
||
|
GPIO_InitStruct.Pin = MIC_DATA_Pin;
|
||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||
|
GPIO_InitStruct.Alternate = GPIO_AF6_SAI1;
|
||
|
HAL_GPIO_Init(MIC_DATA_GPIO_Port, &GPIO_InitStruct);
|
||
|
|
||
|
GPIO_InitStruct.Pin = SAI1_MCLKA_Pin;
|
||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||
|
GPIO_InitStruct.Alternate = GPIO_AF6_SAI1;
|
||
|
HAL_GPIO_Init(SAI1_MCLKA_GPIO_Port, &GPIO_InitStruct);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void HAL_SAI_MspDeInit(SAI_HandleTypeDef* saiHandle)
|
||
|
{
|
||
|
|
||
|
/* SAI1 */
|
||
|
if(saiHandle->Instance==SAI1_Block_A)
|
||
|
{
|
||
|
SAI1_client --;
|
||
|
if (SAI1_client == 0)
|
||
|
{
|
||
|
/* Peripheral clock disable */
|
||
|
__HAL_RCC_SAI1_CLK_DISABLE();
|
||
|
}
|
||
|
|
||
|
/**SAI1_A_Block_A GPIO Configuration
|
||
|
PE4 ------> SAI1_FS_A
|
||
|
PE5 ------> SAI1_SCK_A
|
||
|
PD6 ------> SAI1_SD_A
|
||
|
PG7 ------> SAI1_MCLK_A
|
||
|
*/
|
||
|
HAL_GPIO_DeInit(GPIOE, SAI1_FSA_Pin|SAI1_SCKA_Pin);
|
||
|
|
||
|
HAL_GPIO_DeInit(MIC_DATA_GPIO_Port, MIC_DATA_Pin);
|
||
|
|
||
|
HAL_GPIO_DeInit(SAI1_MCLKA_GPIO_Port, SAI1_MCLKA_Pin);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @}
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @}
|
||
|
*/
|