Ejemplo n.º 1
0
/*********************************************************************//**
 * @brief		Set all pins used as SPIx function corresponding to
 * 				parameter specified in SPIPinCfg.
 * @param[in]	SPIx	SPI peripheral selected, should be SPI
 * @param[in]	SPIPinCfg	Pointer to a SPI_PinCFG_Type structure
*                    that contains the configuration information for the
*                    specified SPIx pin function.
* @param[in]	spiMode	SPI mode, should be:
* 				- SPI_SLAVE_MODE: SLAVE mode
* 				- SPI_MASTER_MODE: MASTER mode
 * @return 		None
 **********************************************************************/
void SPI_PinConfig(SPI_TypeDef *SPIx, SPI_PinCFG_Type *SPIPinCfg, int32_t spiMode)
{
	CHECK_PARAM(PARAM_SPIx(SPIx));
	CHECK_PARAM(PARAM_SPI_SCK(SPIPinCfg->SCK_Pin));
	CHECK_PARAM(PARAM_SPI_SSEL(SPIPinCfg->SSEL_Pin));
	CHECK_PARAM(PARAM_SPI_MISO(SPIPinCfg->MISO_Pin));
	CHECK_PARAM(PARAM_SPI_MOSI(SPIPinCfg->MOSI_Pin));

	// SCK pin
	switch (SPIPinCfg->SCK_Pin)
	{
	case SPI_SCK_P0_15:
		PINSEL_SetPinFunc (PINSEL_PORT_0, SPI_PINSEL_SCK_P0_15, SPI_PINFUNC_SCK_P0_15);
		PINSEL_SetResistorMode (PINSEL_PORT_0, SPI_PINSEL_SCK_P0_15, PINSEL_PINMODE_PULLUP);
		break;
	}


	// SSEL pin
	switch (SPIPinCfg->SSEL_Pin)
	{
	case SPI_SSEL_P0_16:
		if (spiMode == SPI_SLAVE_MODE)
		{
			PINSEL_SetPinFunc (PINSEL_PORT_0, SPI_PINSEL_SSEL_P0_16, SPI_PINFUNC_SSEL_P0_16);
			PINSEL_SetResistorMode (PINSEL_PORT_0, SPI_PINSEL_SSEL_P0_16, PINSEL_PINMODE_PULLUP);
		}
		else
		{
			// Release SSEL pin as default function
			PINSEL_SetPinFunc (PINSEL_PORT_0, SPI_PINSEL_SSEL_P0_16, PINSEL_FUNC_0);
			PINSEL_SetResistorMode (PINSEL_PORT_0, SPI_PINSEL_SSEL_P0_16, PINSEL_PINMODE_PULLUP);
		}
		break;
	}


	// MISO pin
	switch (SPIPinCfg->MISO_Pin)
	{
	case SPI_MISO_P0_17:
		PINSEL_SetPinFunc (PINSEL_PORT_0, SPI_PINSEL_MISO_P0_17, SPI_PINFUNC_MISO_P0_17);
		PINSEL_SetResistorMode (PINSEL_PORT_0, SPI_PINSEL_MISO_P0_17, PINSEL_PINMODE_PULLUP);
		break;
	}

	// MOSI pin
	switch (SPIPinCfg->MOSI_Pin)
	{
	case SPI_MOSI_P0_18:
		PINSEL_SetPinFunc (PINSEL_PORT_0, SPI_PINSEL_MOSI_P0_18, SPI_PINFUNC_MOSI_P0_18);
		PINSEL_SetResistorMode (PINSEL_PORT_0, SPI_PINSEL_MOSI_P0_18, PINSEL_PINMODE_PULLUP);
		break;
	}
}
Ejemplo n.º 2
0
/*********************************************************************//**
 * @brief 		Configure Pin corresponding to specified parameters passed
 * 				in the PinCfg
 * @param[in]	PinCfg	Pointer to a PINSEL_CFG_Type structure
 *                    that contains the configuration information for the
 *                    specified pin.
 * @return 		None
 **********************************************************************/
void PINSEL_ConfigPin(PINSEL_CFG_Type *PinCfg)
{
	PINSEL_SetPinFunc(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Funcnum);
	PINSEL_SetResistorMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Pinmode);
	PINSEL_SetOpenDrainMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->OpenDrain);
}