| | |
| | | #include "fpx.h" |
| | | #endif |
| | | |
| | | /* |
| | | if ((nCurTick &0xff) ==0) |
| | | { |
| | | if (freqdir) { freq+=1+freq/10;if (freq>=1500) {freq=1500;freqdir=0;}} |
| | | else {freq-=1+freq/10;if (freq<=10) {freq=10;freqdir=1;} } |
| | | } |
| | | */ |
| | | |
| | | /* |
| | | static int outputsum=0; |
| | | static int freq=10; |
| | | static int freqdir=1; |
| | | static int phase=0; |
| | | static int somb=0; |
| | | static int len=0; |
| | | static int curbb=0; |
| | | |
| | | if ((nCurTick &0x3ff) ==1) |
| | | { |
| | | curbb++; |
| | | if (curbb+1==len) |
| | | { |
| | | // freq=0; |
| | | }else if (curbb>=len) |
| | | { |
| | | somb=musictab1[cur_musicpos*2]; |
| | | len=musictab1[cur_musicpos*2+1]; |
| | | freq=freqtab[somb]; |
| | | curbb=0;cur_musicpos++; if (cur_musicpos >= Totalmusiccount) {cur_musicpos=0;} |
| | | } |
| | | } |
| | | if ((nCurTick &0x3ff) ==0x1ff) |
| | | { |
| | | if (curbb+1==len) |
| | | { |
| | | freq=0; |
| | | } |
| | | } |
| | | phase+=freq; |
| | | if (phase>=5000) {phase-=5000;} |
| | | |
| | | |
| | | if (outtype==1) |
| | | { |
| | | outputsum+=freq; |
| | | if (outputsum>=5000) |
| | | { |
| | | //LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | //LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | }else if (outtype==2) |
| | | { |
| | | const int volume = 2500; |
| | | int amp; |
| | | if (phase<1250) |
| | | { |
| | | amp=2500+sintab[(phase -0)*256/1250]*volume/256; |
| | | |
| | | }else if (phase <2500) |
| | | { |
| | | amp=2500+sintab[(2500-1-phase)*256/1250]*volume/256; |
| | | }else if (phase <3750) |
| | | { |
| | | amp=2500-sintab[(phase-2500)*256/1250]*volume/256; |
| | | }else |
| | | { |
| | | amp=2500-sintab[(5000-1-phase)*256/1250]*volume/256; |
| | | } |
| | | outputsum+=amp; |
| | | if (outputsum>=5000) |
| | | { |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | //LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | } |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * @brief System Clock Configuration |
| | | * @retval None |
| | |
| | | |
| | | } |
| | | /** |
| | | * @brief TIM1 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM1_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM1_Init 0 */ |
| | | |
| | | /* USER CODE END TIM1_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
| | | LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1); |
| | | |
| | | |
| | | /* USER CODE BEGIN TIM1_Init 1 */ |
| | | |
| | | /* USER CODE END TIM1_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 0; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 1713; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | TIM_InitStruct.RepetitionCounter = 0; |
| | | LL_TIM_Init(TIM1, &TIM_InitStruct); |
| | | LL_TIM_EnableARRPreload(TIM1); |
| | | LL_TIM_SetClockSource(TIM1, LL_TIM_CLOCKSOURCE_INTERNAL); |
| | | LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH1); |
| | | |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 857; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM1, LL_TIM_CHANNEL_CH1); |
| | | |
| | | |
| | | LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH4); |
| | | |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 856; |
| | | LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct); |
| | | |
| | | |
| | | LL_TIM_OC_DisableFast(TIM1, LL_TIM_CHANNEL_CH4); |
| | | LL_TIM_SetTriggerInput(TIM1, LL_TIM_TS_ITR0); |
| | | LL_TIM_SetSlaveMode(TIM1, LL_TIM_SLAVEMODE_RESET); |
| | | LL_TIM_DisableIT_TRIG(TIM1); |
| | | LL_TIM_DisableDMAReq_TRIG(TIM1); |
| | | LL_TIM_SetTriggerOutput(TIM1, LL_TIM_TRGO_RESET); |
| | | LL_TIM_DisableMasterSlaveMode(TIM1); |
| | | |
| | | TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
| | | TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
| | | TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
| | | TIM_BDTRInitStruct.DeadTime = 20; |
| | | TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
| | | TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
| | | TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
| | | LL_TIM_BDTR_Init(TIM1, &TIM_BDTRInitStruct); |
| | | |
| | | |
| | | /* USER CODE BEGIN TIM1_Init 2 */ |
| | | |
| | | /* USER CODE END TIM1_Init 2 */ |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
| | | /**TIM1 GPIO Configuration |
| | | PB13 ------> TIM1_CH1N |
| | | PA8 ------> TIM1_CH1 |
| | | PA11 ------> TIM1_CH4 |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_13; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_8; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_11; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | |
| | | } |
| | | /** |
| | | * @brief TIM6 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | |
| | | /* USER CODE END TIM6_Init 2 */ |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM14 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM14_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM14_Init 0 */ |
| | | |
| | | /* USER CODE END TIM14_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM14); |
| | | |
| | | /* USER CODE BEGIN TIM14_Init 1 */ |
| | | |
| | | /* USER CODE END TIM14_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 2; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 2400; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | LL_TIM_Init(TIM14, &TIM_InitStruct); |
| | | LL_TIM_EnableARRPreload(TIM14); |
| | | /* USER CODE BEGIN TIM14_Init 2 */ |
| | | |
| | | /* USER CODE END TIM14_Init 2 */ |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM15 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM15_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM15_Init 0 */ |
| | | |
| | | /* USER CODE END TIM15_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
| | | LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM15); |
| | | |
| | | /* USER CODE BEGIN TIM15_Init 1 */ |
| | | |
| | | /* USER CODE END TIM15_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 0; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 1713; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | TIM_InitStruct.RepetitionCounter = 0; |
| | | LL_TIM_Init(TIM15, &TIM_InitStruct); |
| | | LL_TIM_EnableARRPreload(TIM15); |
| | | LL_TIM_SetClockSource(TIM15, LL_TIM_CLOCKSOURCE_INTERNAL); |
| | | |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 856; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | LL_TIM_OC_Init(TIM15, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM15, LL_TIM_CHANNEL_CH1); |
| | | |
| | | LL_TIM_OC_EnablePreload(TIM15, LL_TIM_CHANNEL_CH2); |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM2; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 100; |
| | | LL_TIM_OC_Init(TIM15, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM15, LL_TIM_CHANNEL_CH2); |
| | | LL_TIM_SetTriggerOutput(TIM15, LL_TIM_TRGO_OC2REF); |
| | | LL_TIM_DisableMasterSlaveMode(TIM15); |
| | | |
| | | |
| | | TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
| | | TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
| | | TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
| | | TIM_BDTRInitStruct.DeadTime = 5; |
| | | TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
| | | TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
| | | TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
| | | LL_TIM_BDTR_Init(TIM15, &TIM_BDTRInitStruct); |
| | | /* USER CODE BEGIN TIM15_Init 2 */ |
| | | |
| | | /* USER CODE END TIM15_Init 2 */ |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**TIM15 GPIO Configuration |
| | | PB14 ------> TIM15_CH1 |
| | | PB15 ------> TIM15_CH1N |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_14; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_3; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM16 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM16_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM16_Init 0 */ |
| | | |
| | | /* USER CODE END TIM16_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
| | | LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM16); |
| | | /* TIM6 interrupt Init */ |
| | | NVIC_SetPriority(TIM16_IRQn, 0); |
| | | NVIC_EnableIRQ(TIM16_IRQn); |
| | | |
| | | /* USER CODE BEGIN TIM16_Init 1 */ |
| | | |
| | | /* USER CODE END TIM16_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 100; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 1417; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | TIM_InitStruct.RepetitionCounter = 0; |
| | | LL_TIM_Init(TIM16, &TIM_InitStruct); |
| | | LL_TIM_DisableARRPreload(TIM16); |
| | | |
| | | LL_TIM_OC_EnablePreload(TIM16, LL_TIM_CHANNEL_CH1); |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_TOGGLE; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 500; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | LL_TIM_OC_Init(TIM16, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM16, LL_TIM_CHANNEL_CH1); |
| | | TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
| | | TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
| | | TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
| | | TIM_BDTRInitStruct.DeadTime = 6; |
| | | TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
| | | TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
| | | TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
| | | LL_TIM_BDTR_Init(TIM16, &TIM_BDTRInitStruct); |
| | | |
| | | /* USER CODE BEGIN TIM16_Init 2 */ |
| | | |
| | | /* USER CODE END TIM16_Init 2 */ |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**TIM16 GPIO Configuration |
| | | PA6 ------> TIM16_CH1 |
| | | PB6 ------> TIM16_CH1N |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_5; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | LL_TIM_EnableIT_UPDATE(TIM16); |
| | | } |
| | | |
| | | |
| | | /* ADC init function */ |
| | | void MX_ADC_Init(void) |
| | | { |
| | |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | // GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_15); |
| | | |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**SPI1 GPIO Configuration |
| | | PB3 ------> SPI1_SCK |
| | |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /* |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | // GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_5); |
| | | */ |
| | | |
| | | /* |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | |
| | | // NVIC_EnableIRQ(SPI1_IRQn); |
| | | /* USER CODE BEGIN SPI1_Init 1 */ |
| | | |
| | | #if (BOARD_TYPE == 13) |
| | | #if (BOARD_TYPE == 13 || BOARD_TYPE == 9) |
| | | |
| | | NVIC_EnableIRQ(SPI1_IRQn); |
| | | SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
| | |
| | | LL_SPI_DisableNSSPulseMgt(SPI1); |
| | | LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
| | | // LL_SPI_EnableNSSPulseMgt(SPI1); |
| | | |
| | | LL_SPI_EnableIT_RXNE(SPI1); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | |
| | | SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
| | |
| | | SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_HIGH;//LL_SPI_POLARITY_LOW; |
| | | SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; //LL_SPI_PHASE_1EDGE; |
| | | SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
| | | SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2; |
| | | SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
| | | SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
| | | SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
| | | SPI_InitStruct.CRCPoly = 7; |
| | |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6 | LL_GPIO_PIN_7); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief I2C1 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_I2C1_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN I2C1_Init 0 */ |
| | | |
| | | /* USER CODE END I2C1_Init 0 */ |
| | | |
| | | LL_I2C_InitTypeDef I2C_InitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**I2C1 GPIO Configuration |
| | | PB8 ------> I2C1_SCL |
| | | PB9 ------> I2C1_SDA |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_8; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_9; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); |
| | | |
| | | /* USER CODE BEGIN I2C1_Init 1 */ |
| | | |
| | | /* USER CODE END I2C1_Init 1 */ |
| | | /** I2C Initialization |
| | | */ |
| | | LL_I2C_DisableOwnAddress2(I2C1); |
| | | LL_I2C_DisableGeneralCall(I2C1); |
| | | LL_I2C_EnableClockStretching(I2C1); |
| | | I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; |
| | | I2C_InitStruct.Timing = 0x20303E5D; |
| | | I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; |
| | | I2C_InitStruct.DigitalFilter = 0; |
| | | I2C_InitStruct.OwnAddress1 = 0; |
| | | I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; |
| | | I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; |
| | | LL_I2C_Init(I2C1, &I2C_InitStruct); |
| | | LL_I2C_EnableAutoEndMode(I2C1); |
| | | LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK); |
| | | /* USER CODE BEGIN I2C1_Init 2 */ |
| | | |
| | | /* USER CODE END I2C1_Init 2 */ |
| | | |
| | | } |
| | | |
| | |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_8|LL_GPIO_PIN_11; |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_8; //|LL_GPIO_PIN_11; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | |
| | | #endif |
| | | |
| | | } |
| | | |
| | | |
| | | /* |
| | | if ((nCurTick &0xff) ==0) |
| | | { |
| | | if (freqdir) { freq+=1+freq/10;if (freq>=1500) {freq=1500;freqdir=0;}} |
| | | else {freq-=1+freq/10;if (freq<=10) {freq=10;freqdir=1;} } |
| | | } |
| | | */ |
| | | |
| | | /* |
| | | static int outputsum=0; |
| | | static int freq=10; |
| | | static int freqdir=1; |
| | | static int phase=0; |
| | | static int somb=0; |
| | | static int len=0; |
| | | static int curbb=0; |
| | | |
| | | if ((nCurTick &0x3ff) ==1) |
| | | { |
| | | curbb++; |
| | | if (curbb+1==len) |
| | | { |
| | | // freq=0; |
| | | }else if (curbb>=len) |
| | | { |
| | | somb=musictab1[cur_musicpos*2]; |
| | | len=musictab1[cur_musicpos*2+1]; |
| | | freq=freqtab[somb]; |
| | | curbb=0;cur_musicpos++; if (cur_musicpos >= Totalmusiccount) {cur_musicpos=0;} |
| | | } |
| | | } |
| | | if ((nCurTick &0x3ff) ==0x1ff) |
| | | { |
| | | if (curbb+1==len) |
| | | { |
| | | freq=0; |
| | | } |
| | | } |
| | | phase+=freq; |
| | | if (phase>=5000) {phase-=5000;} |
| | | |
| | | |
| | | if (outtype==1) |
| | | { |
| | | outputsum+=freq; |
| | | if (outputsum>=5000) |
| | | { |
| | | //LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | //LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | }else if (outtype==2) |
| | | { |
| | | const int volume = 2500; |
| | | int amp; |
| | | if (phase<1250) |
| | | { |
| | | amp=2500+sintab[(phase -0)*256/1250]*volume/256; |
| | | |
| | | }else if (phase <2500) |
| | | { |
| | | amp=2500+sintab[(2500-1-phase)*256/1250]*volume/256; |
| | | }else if (phase <3750) |
| | | { |
| | | amp=2500-sintab[(phase-2500)*256/1250]*volume/256; |
| | | }else |
| | | { |
| | | amp=2500-sintab[(5000-1-phase)*256/1250]*volume/256; |
| | | } |
| | | outputsum+=amp; |
| | | if (outputsum>=5000) |
| | | { |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | //LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | } |
| | | */ |