/*FUNCTION*---------------------------------------------------------------- * * Function Name : GPIO_Init * Returned Value : none * Comments : * Init LEDs and Buttons * *END*--------------------------------------------------------------------*/ void GPIO_Init() { /* Body */ //#if defined(MCU_MK60N512VMD100) // wenxue #if defined(MCU_MK64F12) SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK; /* Enable clock gating to PORTA */ SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; /* Enable clock gating to PORTE */ // wenxue /* Enable LEDs Port B pin 21 & 22 wenxue */ PORTB_PCR21|= PORT_PCR_SRE_MASK /* Slow slew rate */ | PORT_PCR_ODE_MASK /* Open Drain Enable */ | PORT_PCR_DSE_MASK /* High drive strength */ ; PORTB_PCR21 = PORT_PCR_MUX(1); PORTB_PCR22|= PORT_PCR_SRE_MASK /* Slow slew rate */ | PORT_PCR_ODE_MASK /* Open Drain Enable */ | PORT_PCR_DSE_MASK /* High drive strength */ ; PORTB_PCR22 = PORT_PCR_MUX(1); GPIOB_PSOR |= 1 << 21 | 1 << 22; GPIOB_PDDR |= 1 << 21 | 1 << 22; /* set in put PORTC pin 6 */ // wenxue PTC6:SW2 PORTC_PCR6 = PORT_PCR_MUX(1); GPIOC_PDDR &= ~((uint_32)1 << 6); PORTC_PCR6 |= PORT_PCR_PE_MASK|PORT_PCR_PS_MASK; /* pull up*/ #endif /* End MCU_MK64F12 */ #ifdef _MCF51JM128_H /* init buttons on port G */ PTGDD &= 0xF0; /* set PTG0-3 to input */ PTGPE |= 0x0F; /* enable PTG0-3 pull-up resistor */ /* Enable LEDs Port E pin 2 & 3 */ PTEDD_PTEDD2 = 1; PTEDD_PTEDD3 = 1; PTED_PTED2 = 1; PTED_PTED3 = 1; #endif /* End _MCF51JM128_H */ #if (defined __MCF52259_H__) MCF_GPIO_DDRTC = MCF_GPIO_DDRTC_DDRTC0 | MCF_GPIO_DDRTC_DDRTC1; /* Assign PORTC[0-3] as GPIO */ MCF_GPIO_PTCPAR = MCF_GPIO_PTCPAR_PTCPAR0(MCF_GPIO_PTCPAR_DTIN0_GPIO) | MCF_GPIO_PTCPAR_PTCPAR3(MCF_GPIO_PTCPAR_DTIN1_GPIO); #endif } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : GPIO_Init * Returned Value : none * Comments : * Init LEDs and Buttons * *END*--------------------------------------------------------------------*/ void GPIO_Init() { /* Body */ #if defined(MCU_MK60N512VMD100) SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; /* Enable clock gating to PORTA */ SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK; /* Enable clock gating to PORTE */ // wenxue /* Enable LEDs Port A pin 28 & 29 */ PORTA_PCR28|= PORT_PCR_SRE_MASK /* Slow slew rate */ | PORT_PCR_ODE_MASK /* Open Drain Enable */ | PORT_PCR_DSE_MASK /* High drive strength */ ; PORTA_PCR28 = PORT_PCR_MUX(1); PORTA_PCR29|= PORT_PCR_SRE_MASK /* Slow slew rate */ | PORT_PCR_ODE_MASK /* Open Drain Enable */ | PORT_PCR_DSE_MASK /* High drive strength */ ; PORTA_PCR29 = PORT_PCR_MUX(1); GPIOA_PSOR |= 1 << 28 | 1 << 29; GPIOA_PDDR |= 1 << 28 | 1 << 29; /* set in put PORTA pin 19 */ // wenxue changed PTA19->PTE26 // PORTA_PCR19 = PORT_PCR_MUX(1); // GPIOA_PDDR &= ~((uint_32)1 << 19); // // PORTA_PCR19 |= PORT_PCR_PE_MASK|PORT_PCR_PS_MASK; /* pull up*/ /* set in put PORTE pin 26 */ // wenxue PORTE_PCR26 = PORT_PCR_MUX(1); GPIOE_PDDR &= ~((uint_32)1 << 26); PORTE_PCR26 |= PORT_PCR_PE_MASK|PORT_PCR_PS_MASK; /* pull up*/ #endif /* End MCU_MK60N512VMD100 */ #ifdef _MCF51JM128_H /* init buttons on port G */ PTGDD &= 0xF0; /* set PTG0-3 to input */ PTGPE |= 0x0F; /* enable PTG0-3 pull-up resistor */ /* Enable LEDs Port E pin 2 & 3 */ PTEDD_PTEDD2 = 1; PTEDD_PTEDD3 = 1; PTED_PTED2 = 1; PTED_PTED3 = 1; #endif /* End _MCF51JM128_H */ #if (defined __MCF52259_H__) MCF_GPIO_DDRTC = MCF_GPIO_DDRTC_DDRTC0 | MCF_GPIO_DDRTC_DDRTC1; /* Assign PORTC[0-3] as GPIO */ MCF_GPIO_PTCPAR = MCF_GPIO_PTCPAR_PTCPAR0(MCF_GPIO_PTCPAR_DTIN0_GPIO) | MCF_GPIO_PTCPAR_PTCPAR3(MCF_GPIO_PTCPAR_DTIN1_GPIO); #endif } /* EndBody */
/** * Configures PTCPAR and DDRTC so port TC is in GPIO function and the pin data direction is output. */ void gpio_port_tc_init() { // Program Port TC Pin Assignment Register (PTCPAR) so pins 0, 1, 2, and 3 are configured for the general-purpose I/O (GPIO) function. MCF_GPIO_PTCPAR = MCF_GPIO_PTCPAR_PTCPAR0(MCF_GPIO_PTCPAR_DTIN0_GPIO) | MCF_GPIO_PTCPAR_PTCPAR1(MCF_GPIO_PTCPAR_DTIN1_GPIO) | MCF_GPIO_PTCPAR_PTCPAR2(MCF_GPIO_PTCPAR_DTIN2_GPIO) | MCF_GPIO_PTCPAR_PTCPAR3(MCF_GPIO_PTCPAR_DTIN3_GPIO); // Program Port TC Data Direction Register (DDRTC) so pins 0, 1, 2, and 3 are configured as output pins MCF_GPIO_DDRTC = MCF_GPIO_DDRTC_DDRTC0 | MCF_GPIO_DDRTC_DDRTC1 | MCF_GPIO_DDRTC_DDRTC2 | MCF_GPIO_DDRTC_DDRTC3; }
void gpio_port_tc_init(){ /*Configures PTCPAR and DDRTC so port TC is in GPIO * function and the pin data direction is output.*/ MCF_GPIO_PTCPAR = MCF_GPIO_PTCPAR_PTCPAR0(MCF_GPIO_PTCPAR_DTIN0_GPIO)| MCF_GPIO_PTCPAR_PTCPAR1(MCF_GPIO_PTCPAR_DTIN1_GPIO) | MCF_GPIO_PTCPAR_PTCPAR2(MCF_GPIO_PTCPAR_DTIN2_GPIO) | MCF_GPIO_PTCPAR_PTCPAR3(MCF_GPIO_PTCPAR_DTIN3_GPIO); MCF_GPIO_PORTTC &= ~(MCF_GPIO_DDRTC_DDRTC0 | MCF_GPIO_DDRTC_DDRTC1 | MCF_GPIO_DDRTC_DDRTC2 | MCF_GPIO_DDRTC_DDRTC3); MCF_GPIO_DDRTC = MCF_GPIO_DDRTC_DDRTC0 | MCF_GPIO_DDRTC_DDRTC1 | MCF_GPIO_DDRTC_DDRTC2 | MCF_GPIO_DDRTC_DDRTC3; }
/***************************************************************************** * @name GPIO_Init * * @brief: Initialization of the GPIO. * * @param : None * * @return : None ***************************************************************************** * * ****************************************************************************/ void GPIO_Init(void) { /*************************************************************************** * GPIO Init for LED * ****************************************************************************/ /* Configure LED io pins to be outputs. * M52221DEMO: LED to port mapping * LED1 LED2 LED3 LED4 * | | | | * ^ ^ ^ ^ * PTC0 PTC1 PTC2 PTC3 */ MCF_GPIO_DDRTC = (MCF_GPIO_DDRTC_DDRTC0 | MCF_GPIO_DDRTC_DDRTC1 | MCF_GPIO_DDRTC_DDRTC2 | MCF_GPIO_DDRTC_DDRTC3); /* Assign PORTC[0-3] as GPIO */ MCF_GPIO_PTCPAR = MCF_GPIO_PTCPAR_PTCPAR0(MCF_GPIO_PTCPAR_DTIN0_GPIO) | MCF_GPIO_PTCPAR_PTCPAR1(MCF_GPIO_PTCPAR_DTIN1_GPIO) | MCF_GPIO_PTCPAR_PTCPAR2(MCF_GPIO_PTCPAR_DTIN2_GPIO) | MCF_GPIO_PTCPAR_PTCPAR3(MCF_GPIO_PTCPAR_DTIN3_GPIO); /*************************************************************************** * GPIO Init for USB * ****************************************************************************/ /* setup gpio state, func and dirrections */ MCF_GPIO_PUAPAR &= 0x3f; MCF_GPIO_PORTUA |= MCF_GPIO_PORTUA_PORTUA3; /* turn Vbus off */ MCF_GPIO_DDRUA |= MCF_GPIO_DDRUA_DDRUA3; /* CTS0 as output */ MCF_GPIO_PUAPAR &= 0xcf; MCF_GPIO_DDRUA &= ~MCF_GPIO_DDRUA_DDRUA2; /* RTS0 as input */ MCF_GPIO_PORTUA &= ~MCF_GPIO_PORTUA_PORTUA3; /* turn Vbus on */ MCF_GPIO_PQSPAR |= MCF_GPIO_PQSPAR_PQSPAR5(3) | MCF_GPIO_PQSPAR_PQSPAR6(3); /*************************************************************************** * GPIO Init for KBI * ****************************************************************************/ /* Configure switch buttons */ /* M52221DEMO: SW1 & SW2 connected to PNQ[1] & PNQ[7] */ /* Pin assignement registers: IRQ */ /* Assure that PDDPAR[5-7] are configured to GPIO regardless of the reset state */ MCF_GPIO_PNQPAR &= ~(MCF_GPIO_PNQPAR_PNQPAR1(3) | MCF_GPIO_PNQPAR_PNQPAR7(3)); MCF_GPIO_PNQPAR |= (MCF_GPIO_PNQPAR_IRQ1_IRQ1 | MCF_GPIO_PNQPAR_IRQ7_IRQ7); /* Configure IRQ[1] & IRQ[7] as input */ MCF_EPORT_EPDDR &= ~(MCF_EPORT_EPDDR_EPDD1 | MCF_EPORT_EPDDR_EPDD7); /* Configure IRQ1 & IRQ7 as falling-edge sense */ MCF_EPORT_EPPAR = MCF_EPORT_EPPAR_EPPA1_FALLING | MCF_EPORT_EPPAR_EPPA7_FALLING; /* Enable Interrupt for IRQ1 & IRQ7 */ MCF_EPORT_EPIER = MCF_EPORT_EPIER_EPIE1 | MCF_EPORT_EPIER_EPIE7; /*************************************************************************** * GPIO Init for QSPI * ****************************************************************************/ /* Configure the pins for QSPI for specialized purpose */ /* QSPI_CLK, QSPI_DOUT, QSPI_DIN, QSPI_CS0 */ MCF_GPIO_PQSPAR &= ~(MCF_GPIO_PQSPAR_PQSPAR0(3) | MCF_GPIO_PQSPAR_PQSPAR1(3) | MCF_GPIO_PQSPAR_PQSPAR2(3) | MCF_GPIO_PQSPAR_PQSPAR3(3)); MCF_GPIO_PQSPAR |= (MCF_GPIO_PQSPAR_QSPI_DOUT_DOUT | MCF_GPIO_PQSPAR_QSPI_DIN_DIN | MCF_GPIO_PQSPAR_QSPI_CLK_CLK | MCF_GPIO_PQSPAR_QSPI_CS0_CS0); }