📄 main.c
字号:
*/
void RCC_Configuration(void)
{
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1); // 72M for APB2, 4M max reqirement for LCD IF, so divide 32 = 2.25M for SPI CLK
RCC_PCLK1Config(RCC_HCLK_Div2); // For TIM3 of SIG_IN
/* Enable peripheral clocks --------------------------------------------------*/
/* Enable LCD SPI DMA clock */
RCC_AHBPeriphClockCmd(LCD_MASTER_DMA_CLK, ENABLE);
/* Enable clock for LCD SPI_MASTER GPIO, SIG Out TIM1, Temperature ADC and other controls on APB2 */
RCC_APB2PeriphClockCmd(LCD_MASTER_GPIO_CLK | LCD_MASTER_CLK | RCC_APB2Periph_AFIO |
RCC_APB2Periph_GPIOB | SIG_GEN_TIMER_CLK | TEMPER_ADC_CLK, ENABLE);
#ifdef DEBUG
RCC_APB1PeriphClockCmd(DEBUG_UART_CLK, ENABLE);
#endif
/* Enable clock for TIM4 of SIG_IN, ... */
RCC_APB1PeriphClockCmd(SIG_RECV_TIMER_CLK | SIG_DETECT_TIMER_CLK | GLB_FREERUN_TIMER_CLK, ENABLE);
}
/**
* @brief Configures the different GPIO ports.
* @param None
* @retval None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Port B General
GPIO_InitStructure.GPIO_Pin = LCD_BACKLIGHT_PIN | SIG_GEN_PULSE_SD_PIN | SIG_RECV_SW_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LCD_BACKLIGHT_PORT, &GPIO_InitStructure);
MOSFET_DRIVER_OFF; // Pull down IR2104's SD to disable MOSFET
LCD_BACKLIGHT_OFF; // Close LCD's backlight
RECV_RELAY_RELEASE; // Release signa, in control switch
// Port A General
GPIO_InitStructure.GPIO_Pin = LCD_DC_PIN | LCD_RST_PIN | SIG_OUT_SW_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LCD_DC_PORT, &GPIO_InitStructure);
GPIO_ResetBits(LCD_DC_PORT, LCD_DC_PIN); // Low for command
GPIO_ResetBits(LCD_RST_PORT, LCD_RST_PIN); // Reset LCD
OUTPUT_RELAY_RELEASE; // Release relay
FLAG_HMI_PWRON_RESET = SET;
/* Configure LCD SPI_MASTER pins: SCK, MOSI and NSS */
GPIO_InitStructure.GPIO_Pin = LCD_MASTER_SCK_PIN | LCD_MASTER_MOSI_PIN; // | LCD_MASTER_NSS_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(LCD_MASTER_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LCD_MASTER_NSS_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LCD_MASTER_PORT, &GPIO_InitStructure);
GPIO_SetBits(LCD_MASTER_PORT, LCD_MASTER_NSS_PIN);
/* PULSE_A and PULSE_B is in TIM charge */
GPIO_InitStructure.GPIO_Pin = SIG_GEN_PULSE_A_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SIG_GEN_PULSE_A_PORT, &GPIO_InitStructure);
GPIO_ResetBits(SIG_GEN_PULSE_A_PORT, SIG_GEN_PULSE_A_PIN);
GPIO_InitStructure.GPIO_Pin = SIG_GEN_PULSE_B_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SIG_GEN_PULSE_B_PORT, &GPIO_InitStructure);
GPIO_ResetBits(SIG_GEN_PULSE_B_PORT, SIG_GEN_PULSE_B_PIN);
/* SIG IN is managered by external interrupt */
GPIO_InitStructure.GPIO_Pin = SIG_RECV_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(SIG_RECV_PORT, &GPIO_InitStructure);
/* ADC for Temperature */
GPIO_InitStructure.GPIO_Pin = TEMPER_ADC_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(TEMPER_ADC_PORT, &GPIO_InitStructure);
//#ifdef TESTPIN_ENABLE
// /* Configure Other Control pins */
// GPIO_InitStructure.GPIO_Pin = TEST_PIN_1 | TEST_PIN_2 | TEST_PIN_3;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_Init(TESTPIN_PORT_B, &GPIO_InitStructure);
// TEST_PIN_1_LOW;
// TEST_PIN_2_LOW;
// TEST_PIN_3_LOW;
//#endif
#ifdef DEBUG
/* UART2 for Communication */
GPIO_InitStructure.GPIO_Pin = UART2_TX_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(UART2_TX_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = UART2_RX_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(UART2_RX_PORT, &GPIO_InitStructure);
#else
/* UART2 for GPIO */
GPIO_InitStructure.GPIO_Pin = UART2_TX_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(UART2_TX_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = UART2_RX_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(UART2_RX_PORT, &GPIO_InitStructure);
#endif
}
void NVIC_Configuration(void)
{
// local variables
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* Configure the preemption priority and subpriority:
- 1 bits for pre-emption priority: possible value are 0 or 1
- 3 bits for subpriority: possible value are 0..7
- Lower values gives higher priority
*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the USART1_IRQn Interrupt */
// NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = LCD_MASTER_DMA_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the TIM1_IRQn global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = SIG_GEN_TIMER_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the TIM2_IRQn Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = SIG_DETECT_TIMER_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable and set EXTI0 Interrupt to receive SIG */
NVIC_InitStructure.NVIC_IRQChannel = SIG_RECV_EXTI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#ifdef DEBUG
NVIC_InitStructure.NVIC_IRQChannel = UART_DEBUG_DMA_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
/* Enable the TIM2_IRQn Interrupt */
// NVIC_InitStructure.NVIC_IRQChannel = TIMER_USER_0_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
/* Enable and set EXTI0 Interrupt to the lowest priority */
// NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
/* Enable and set EXTI1 Interrupt to the lowest priority */
// NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
} // end NVIC_Configuration
void GLB_FreerunTIM_Initial(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = GLB_FREERUN_TIMER_PRESCAL;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = GLB_FREERUN_TIMER_PERIOD;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(GLB_FREERUN_TIMER, &TIM_TimeBaseStructure);
TIM_Cmd(GLB_FREERUN_TIMER, ENABLE);
}
void memor(void *dest, const void *src, uint32_t size)
{
register uint32_t temp_i = size;
while (temp_i)
{
*((uint8_t *)dest) = *((uint8_t *)dest) | *((uint8_t *)src);
temp_i--;
}
}
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2013 Zulolo *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -