From 9aed5d7e7b3c7bf09da712e9c272ece401a7acc9 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期一, 25 十一月 2024 14:51:23 +0800 Subject: [PATCH] add UltraSonic and MultiWireLess --- ComLib/Src/BSP.c | 588 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 477 insertions(+), 111 deletions(-) diff --git a/ComLib/Src/BSP.c b/ComLib/Src/BSP.c index 665273d..f53040c 100644 --- a/ComLib/Src/BSP.c +++ b/ComLib/Src/BSP.c @@ -16,94 +16,6 @@ #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 @@ -257,6 +169,117 @@ } /** + * @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 @@ -290,6 +313,212 @@ /* 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) { @@ -395,20 +624,42 @@ // GPIO_InitStruct.Alternate = LL_GPIO_AF_0; // LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + 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(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 PB4 ------> SPI1_MISO PB5 ------> SPI1_MOSI */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Pin = LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5; 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.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; GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; @@ -424,13 +675,13 @@ GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; GPIO_InitStruct.Alternate = LL_GPIO_AF_0; LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - +*/ /* SPI1 interrupt Init */ NVIC_SetPriority(SPI1_IRQn, 0); // 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; @@ -469,7 +720,8 @@ 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; @@ -574,7 +826,7 @@ 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; @@ -586,6 +838,24 @@ /* USER CODE END SPI2_Init 2 */ } +void Soft_I2C1_Init(void) +{ + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); + /**I2C1 GPIO Configuration + PB6 ------> I2C1_SCL + PB7 ------> I2C1_SDA + */ + LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6|LL_GPIO_PIN_7); + GPIO_InitStruct.Pin = LL_GPIO_PIN_6 | LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; + 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); + +} /* USART1 init function */ void MX_USART1_UART_Init(void) @@ -648,9 +918,13 @@ // LL_USART_SetDEAssertionTime(USART1, 1); // LL_USART_SetDEDeassertionTime(USART1, 1); // LL_USART_EnableOneBitSamp(USART1); + +#if (USART1_AUTO_BAUDRATE == 1) LL_USART_EnableAutoBaudRate(USART1); LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); - LL_USART_DisableOverrunDetect(USART1); +#endif + + LL_USART_DisableOverrunDetect(USART1); LL_USART_ConfigAsyncMode(USART1); LL_USART_Enable(USART1); } @@ -800,7 +1074,7 @@ 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; @@ -821,34 +1095,38 @@ GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - if (GetBoardType()==2) - { +#if (BOARD_TYPE==2) + GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; - } - else if (GetBoardType()==9 || GetBoardType()==10 || GetBoardType()==15 || BOARD_TYPE == 16 ) - { + +#elif (BOARD_TYPE==9 || BOARD_TYPE==10) + GPIO_InitStruct.Pin = LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| + LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; + +#elif (BOARD_TYPE==15 || BOARD_TYPE == 16 ) + GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; - } - else if ( GetBoardType() == 11 ) - { +#elif ( BOARD_TYPE == 11 ) + GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| LL_GPIO_PIN_2|LL_GPIO_PIN_10|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; - } else if (BOARD_TYPE == 14) - { +#elif (BOARD_TYPE == 14) + GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7| LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15; - } else - { +#else + GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; - } - - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + +#endif + + 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_NO; @@ -951,3 +1229,91 @@ #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); + } + } +*/ -- Gitblit v1.9.1