//================================================================== // // Filename: mapp_gpio.c // Description: System driver. // //------------------------------------------------------------------ // // version: // date: 17:53, 05.Seb.2019, written by dwd // Description: // //------------------------------------------------------------------ //================================================================== /*------------------------------------------------------------------------------ * I N C L U D E *------------------------------------------------------------------------------*/ #include "stm32f0xx.h" #include "general.h" #include "mapp_gpio.h" #include "mapp_arm.h" #include "mapp_msg.h" #include "mapp_ami.h" #include "main.h" /*------------------------------------------------------------------------------ * D E F I N E *------------------------------------------------------------------------------*/ /*--- ADC1 DMA base address ---*/ /*------------------------------------------------------------------------------ * S T R U C T *------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ * S T A T I C - V A R I A B L E S *------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ * G L O B A L *------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ * P R O T O T Y P E *------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------- // Function uses : GpioCfgInit // Input parameter : // Output parameter : // Use Function : Configuration all GPIOs for system. // Reserve date : 17:53, 05.Seb.2019, written by dwd ----------------------------------------------------------------------*/ void GpioCfgInit(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOC, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); //GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0); //uart1——tx stm32f030C8 GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0); /* Configure pins as AF pushpull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;//TXRX GPIO_Pin_6| GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1); //uart2 stm32f030C8 GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1); /* Configure pins as AF pushpull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;//TXRX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /************PA0:VOICERSW******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /************PA1:mute*******/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /************PA4:HADLE KEY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /************PA5:CHANGE KEY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /************PA6.PA7:PWM******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_0);//GPIO_AF_1 // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // 设置为输出模式 // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // GPIO_Init(GPIOA, &GPIO_InitStructure); // // 设置引脚为低电平 // GPIO_ResetBits(GPIOA, GPIO_Pin_6); /************PA8:BUS_IN ******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Connect TIM pin to TIM1_CH1 */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2); /************PA15:NURSE KEY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /************PF7:VOIVCE SPEAK CONTROL******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOF,&GPIO_InitStructure); #if 0 /************PB0,PB1:BUS_IN ******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Connect TIM pin to TIM3_CH4 */ // GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_1); /* Connect TIM pin to TIM14_CH1 */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_0); #endif /************PB3:REINFORCE KEY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); /************PB4:CANCEL KEY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); /************PB5:CALL KEY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); VOICE_PB15_ON; /************PB11:RALAY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); /************PB15:D0*****************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); /************PC13:LEDY******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); LED_Y_OFF; /************Pc14:sw_spk******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_SetBits(GPIOC, GPIO_Pin_14); //原来是用来切换二三线制,现在改为默认高电平,支持切换喇叭 /************Pc15:GPIO_MIC_SW******************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); } void GpioLedInit(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /************PA****************** PA13---------------- KEY_LED USB_BATTER_LED PA14---------------- BK-LED ****************************************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); } /*---------------------------------------------------------------------- // Function uses : GpioCfgReset // Input parameter : // Output parameter : // Use Function : Reset all IO except specified usage. // Reserve date : 17:53, 05.Seb.2019, written by dwd ----------------------------------------------------------------------*/ void GpioCfgReset(void) { } void GpioSpiCSCfg(FlagStatus flag){ if (flag == SET) { GPIO_SetBits(GPIOA, GPIO_Pin_1); } else { GPIO_ResetBits(GPIOA, GPIO_Pin_1); } } void GpioSpiSclCfg(FlagStatus flag){ if (flag == SET) { GPIO_SetBits(GPIOA, GPIO_Pin_7); } else { GPIO_ResetBits(GPIOA, GPIO_Pin_7); } } void GpioMOSICfg(FlagStatus flag) { if (flag == SET) { GPIO_SetBits(GPIOA, GPIO_Pin_9); } else { GPIO_ResetBits(GPIOA, GPIO_Pin_9); } } /*------------------------------- E O F ----------------------------------------*/