/*
 * pin_config.c
 *
 *  Created on: Oct 31, 2016
 *      Author: B52932
 */

#include "pin_config.h"

#include "S32K144.h"

void UART_pin_settings(void){
	PCC->PCCn[PCC_PORTD_INDEX ]|=PCC_PCCn_CGC_MASK; /* Enable clock for PORTC */

	/* enable the UART port of S32K144 */
	PORTD->PCR[7]|=PORT_PCR_MUX(2);           /* Port C3: MUX = ALT4,UART0 TX */
	PORTD->PCR[6]|=PORT_PCR_MUX(2);           /* Port C2: MUX = ALT4,UART0 RX */
}

void UART_pin_settings_reset(void){
	PCC->PCCn[PCC_PORTD_INDEX ]|=PCC_PCCn_CGC_MASK; /* Enable clock for PORTC */

	PORTD->PCR[7]|=PORT_PCR_MUX(1);           /* Port C3: MUX = ALT1,UART0 TX */
	PORTD->PCR[6]|=PORT_PCR_MUX(1);           /* Port C2: MUX = ALT1,UART0 RX */

}

void RS485_GPIO_Init(void) {
    /* Enable clock for PORTC (for PTC6 and PTC7) */
    PCC->PCCn[PCC_PORTC_INDEX] |= PCC_PCCn_CGC_MASK;

    /* Configure PTC6 (DE) as GPIO output */
    PORTC->PCR[6] = PORT_PCR_MUX(1);  // Set PTC6 as GPIO
    PTC->PDDR |= (1 << 6);            // Set PTC6 as output
    PTC->PCOR |= (1 << 6);            // Initialize DE (PTC6) to LOW

    /* Configure PTC7 (RE) as GPIO output */
    PORTC->PCR[7] = PORT_PCR_MUX(1);  // Set PTC7 as GPIO
    PTC->PDDR |= (1 << 7);            // Set PTC7 as output
    PTC->PCOR |= (1 << 7);            // Initialize RE (PTC7) to LOW
}



