From f7cd9b461ca33845339f4a11f49bdc142696827a Mon Sep 17 00:00:00 2001 From: Dominik Sliwa Date: Tue, 28 Jun 2016 09:51:29 +0200 Subject: Apalis_TK1_K20: SPI Communication, ADC, TSC, GPIO Support for Communication between TK1 SoC and K20 MCU This patch includes ADC, TSC and GPIO functionality. Signed-off-by: Dominik Sliwa --- board/pin_mux.c | 128 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 42 deletions(-) (limited to 'board/pin_mux.c') diff --git a/board/pin_mux.c b/board/pin_mux.c index be07825..3a538f5 100644 --- a/board/pin_mux.c +++ b/board/pin_mux.c @@ -34,6 +34,8 @@ #include "fsl_common.h" #include "fsl_port.h" #include "fsl_gpio.h" +#include "fsl_debug_console.h" +#include "gpio_ext.h" /******************************************************************************* * Code @@ -43,54 +45,96 @@ */ void BOARD_InitPins(void) { - gpio_pin_config_t gpio_out_config = { - kGPIO_DigitalOutput, 0, - }; + unsigned int i; + gpio_pin_config_t gpio_out_config = { + kGPIO_DigitalOutput, 0, + }; + gpio_pin_config_t gpio_out_hi_config = { + kGPIO_DigitalOutput, 1, + }; + gpio_pin_config_t gpio_in_config = { + kGPIO_DigitalInput, + }; + port_pin_config_t od_config; - CLOCK_EnableClock(kCLOCK_PortA); - CLOCK_EnableClock(kCLOCK_PortB); - CLOCK_EnableClock(kCLOCK_PortC); - CLOCK_EnableClock(kCLOCK_PortD); - CLOCK_EnableClock(kCLOCK_PortE); + CLOCK_EnableClock(kCLOCK_PortA); + CLOCK_EnableClock(kCLOCK_PortB); + CLOCK_EnableClock(kCLOCK_PortC); + CLOCK_EnableClock(kCLOCK_PortD); + CLOCK_EnableClock(kCLOCK_PortE); - /* Osc pins */ - PORT_SetPinMux(PORTA, 18UL, kPORT_PinDisabledOrAnalog); - PORT_SetPinMux(PORTA, 19UL, kPORT_PinDisabledOrAnalog); + /* Osc pins */ + PORT_SetPinMux(PORTA, 18UL, kPORT_PinDisabledOrAnalog); + PORT_SetPinMux(PORTA, 19UL, kPORT_PinDisabledOrAnalog); - /* CAN0 pinmux config */ - PORT_SetPinMux(PORTA, 12u, kPORT_MuxAlt2); /* CAN0 TX */ - PORT_SetPinMux(PORTA, 13u, kPORT_MuxAlt2); /* CAN0 RX */ + /* CAN0 pinmux config */ + PORT_SetPinMux(PORTA, 12u, kPORT_MuxAlt2); /* CAN0 TX */ + PORT_SetPinMux(PORTA, 13u, kPORT_MuxAlt2); /* CAN0 RX */ - /* CAN1 pinmux config */ - PORT_SetPinMux(PORTC, 17u, kPORT_MuxAlt2); /* CAN1 TX */ - PORT_SetPinMux(PORTC, 16u, kPORT_MuxAlt2); /* CAN1 RX */ + /* CAN1 pinmux config */ + PORT_SetPinMux(PORTC, 17u, kPORT_MuxAlt2); /* CAN1 TX */ + PORT_SetPinMux(PORTC, 16u, kPORT_MuxAlt2); /* CAN1 RX */ - /* Debug UART3 pinmux config */ - PORT_SetPinMux(PORTB, 11u, kPORT_MuxAlt3); /* UART3 TX */ - PORT_SetPinMux(PORTB, 10u, kPORT_MuxAlt3); /* UART3 RX */ +#ifdef SDK_DEBUGCONSOLE + /* Debug UART3 pinmux config */ + PORT_SetPinMux(PORTB, 11u, kPORT_MuxAlt3); /* UART3 TX */ + PORT_SetPinMux(PORTB, 10u, kPORT_MuxAlt3); /* UART3 RX */ +#endif - /* Resistive Touch panel pinmux config */ - PORT_SetPinMux(PORTE, 6u, kPORT_MuxAsGpio); - GPIO_PinInit(GPIOE, 6u, &gpio_out_config); - GPIO_SetPinsOutput(GPIOE, 1u << 6); /* Force X+*/ - PORT_SetPinMux(PORTB, 9u, kPORT_MuxAsGpio); - GPIO_PinInit(GPIOB, 9u, &gpio_out_config); - GPIO_ClearPinsOutput(GPIOB, 1u << 9); /* Force X-*/ - PORT_SetPinMux(PORTC, 5u, kPORT_MuxAsGpio); - GPIO_PinInit(GPIOC, 5u, &gpio_out_config); - GPIO_SetPinsOutput(GPIOC, 1u << 5); /* Force Y+*/ - PORT_SetPinMux(PORTC, 13u, kPORT_MuxAsGpio); - GPIO_PinInit(GPIOC, 13u, &gpio_out_config); - GPIO_ClearPinsOutput(GPIOC, 1u << 13); /* Force Y-*/ - PORT_SetPinMux(PORTB, 6UL, kPORT_PinDisabledOrAnalog); /* Sense X+ */ - PORT_SetPinMux(PORTB, 7UL, kPORT_PinDisabledOrAnalog); /* Sense X- */ - PORT_SetPinMux(PORTC, 8UL, kPORT_PinDisabledOrAnalog); /* Sense Y+ */ - PORT_SetPinMux(PORTC, 9UL, kPORT_PinDisabledOrAnalog); /* Sense Y- */ +#ifdef BOARD_USES_ADC + /* Resistive Touch panel pinmux config */ + PORT_SetPinMux(PORTE, 6u, kPORT_MuxAsGpio); + GPIO_PinInit(GPIOE, 6u, &gpio_out_hi_config); /* Force X+*/ + PORT_SetPinMux(PORTB, 9u, kPORT_MuxAsGpio); + GPIO_PinInit(GPIOB, 9u, &gpio_out_config); /* Force X-*/ + PORT_SetPinMux(PORTC, 5u, kPORT_MuxAsGpio); + GPIO_PinInit(GPIOC, 5u, &gpio_out_hi_config); /* Force Y+*/ + PORT_SetPinMux(PORTC, 13u, kPORT_MuxAsGpio); + GPIO_PinInit(GPIOC, 13u, &gpio_out_config); /* Force Y-*/ + PORT_SetPinMux(PORTB, 6UL, kPORT_PinDisabledOrAnalog); /* Sense X+ */ + GPIO_PinInit(GPIOB, 6u, &gpio_in_config); + PORT_SetPinMux(PORTB, 7UL, kPORT_PinDisabledOrAnalog); /* Sense X- */ + GPIO_PinInit(GPIOB, 7u, &gpio_in_config); + PORT_SetPinMux(PORTC, 8UL, kPORT_PinDisabledOrAnalog); /* Sense Y+ */ + GPIO_PinInit(GPIOC, 8u, &gpio_in_config); + PORT_SetPinMux(PORTC, 9UL, kPORT_PinDisabledOrAnalog); /* Sense Y- */ + GPIO_PinInit(GPIOC, 9u, &gpio_in_config); - /* SPI2 pinmux config */ - PORT_SetPinMux(PORTB, 21u, kPORT_MuxAlt2); /* SPI2_SCK */ - PORT_SetPinMux(PORTB, 22u, kPORT_MuxAlt2); /* SPI2_SOUT */ - PORT_SetPinMux(PORTB, 23u, kPORT_MuxAlt2); /* SPI2_SIN */ - PORT_SetPinMux(PORTB, 20u, kPORT_MuxAsGpio); /* SPI2_SS */ + /* Apalis ADC pinmux config */ + PORT_SetPinMux(PORTB, 0UL, kPORT_PinDisabledOrAnalog); /* ADC0 */ + PORT_SetPinMux(PORTB, 1UL, kPORT_PinDisabledOrAnalog); /* ADC1 */ + PORT_SetPinMux(PORTB, 2UL, kPORT_PinDisabledOrAnalog); /* ADC2 */ + PORT_SetPinMux(PORTB, 3UL, kPORT_PinDisabledOrAnalog); /* ADC3 */ +#endif + /* SPI2 pinmux config */ + PORT_SetPinMux(PORTB, 21u, kPORT_MuxAlt2); /* SPI2_SCK */ + PORT_SetPinMux(PORTB, 22u, kPORT_MuxAlt2); /* SPI2_SOUT */ + PORT_SetPinMux(PORTB, 23u, kPORT_MuxAlt2); /* SPI2_SIN */ + PORT_SetPinMux(PORTB, 20u, kPORT_MuxAlt2); /* SPI2_SS */ + + /* Open Drain INT pins config */ + od_config.mux = kPORT_MuxAsGpio; + od_config.openDrainEnable = kPORT_OpenDrainEnable; + od_config.pullSelect = kPORT_PullDisable; + od_config.slewRate = kPORT_FastSlewRate; + od_config.passiveFilterEnable = kPORT_PassiveFilterDisable; + od_config.driveStrength = kPORT_LowDriveStrength; + od_config.lockRegister = kPORT_UnlockRegister; + GPIO_PinInit(GPIOA, 16u, &gpio_out_hi_config); + PORT_SetPinConfig(PORTA, 16u, &od_config); /* MCU_INT1 */ + GPIO_PinInit(GPIOA, 29u, &gpio_out_hi_config); + PORT_SetPinConfig(PORTA, 29u, &od_config); /* MCU_INT2 */ + GPIO_PinInit(GPIOB, 8u, &gpio_out_config); + PORT_SetPinConfig(PORTB, 8u, &od_config); /* MCU_INT3 */ + GPIO_PinInit(GPIOE, 26u, &gpio_out_config); + PORT_SetPinConfig(PORTE, 26u, &od_config); /* MCU_INT4 */ + GPIO_PinInit(GPIOC, 19u, &gpio_out_hi_config); + PORT_SetPinConfig(PORTC, 19u, &od_config); /* PMIC_ONKEY */ + + /* GPIOs */ + for (i = 0; i < sizeof(gpio_list)/sizeof(struct gpio_id); i++){ + PORT_SetPinMux(gpio_list[i].port, gpio_list[i].pin, kPORT_MuxAsGpio); + GPIO_PinInit(gpio_list[i].gpio, gpio_list[i].pin, &gpio_in_config); + } } -- cgit v1.2.3