/****************************************************************************** * Set_Pins * * Set a PIN with Direction Out, this PIN can be used as a LED. *******************************************************************************/ void Set_Pins( LED_t LEDNr ) { if (LEDNr & LED1){ Gpio_SetPinFunction(LED1_PIN, gGpioNormalMode_c); Gpio_SetPinReadSource(LED1_PIN, gGpioPinReadReg_c); Gpio_SetPinDir(LED1_PIN, gGpioDirOut_c); Gpio_SetPinData(LED1_PIN, LED_RESET); } if (LEDNr & LED2){ Gpio_SetPinFunction(LED2_PIN, gGpioNormalMode_c); Gpio_SetPinReadSource(LED2_PIN, gGpioPinReadReg_c); Gpio_SetPinDir(LED2_PIN, gGpioDirOut_c); Gpio_SetPinData(LED2_PIN, LED_RESET); } if (LEDNr & LED3){ Gpio_SetPinFunction(LED3_PIN, gGpioNormalMode_c); Gpio_SetPinReadSource(LED3_PIN, gGpioPinReadReg_c); Gpio_SetPinDir(LED3_PIN, gGpioDirOut_c); Gpio_SetPinData(LED3_PIN, LED_RESET); } if (LEDNr & LED4){ Gpio_SetPinFunction(LED4_PIN, gGpioNormalMode_c); Gpio_SetPinReadSource(LED4_PIN, gGpioPinReadReg_c); Gpio_SetPinDir(LED4_PIN, gGpioDirOut_c); Gpio_SetPinData(LED4_PIN, LED_RESET); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// // Name I2C_EEPROM_Init // Author Dorin Muica // Brief Init I2C Module // Param none // none // Return none //////////////////////////////////////////////////////////////////////////////////////////////////// void I2C_EEPROM_Init (void) { Gpio_SetPinFunction(GPIO_EEPROM_WP , gGpioNormalMode_c); Gpio_SetPinDir( GPIO_EEPROM_WP, gGpioDirOut_c ); EEPROM_WRITE_DISABLE(); Gpio_SetPinFunction( gGpioPin12_c, gGpioAlternate1Mode_c ); // Peripheral Control Mode of pin #22 SCL Gpio_SetPinFunction( gGpioPin13_c, gGpioAlternate1Mode_c ); // Peripheral Control Mode of pin #21 SDA I2c_Init(); I2c_Enable(); I2c_SetConfig(&stI2cConfig); }
/***************************************************************************** * IIC_ModuleInit * * Initialize the IIC module ******************************************************************************/ void IIC_ModuleInit() { #if gIIC_Enabled_d /* Configure the pin to be used for signaling the master host that data for read is available. Default configuration is 'No Data for Read', meaning GPIO is set to high */ Gpio_EnPinPullup(gTxDataAvailablePin_c, TRUE); Gpio_SetPinDir(gTxDataAvailablePin_c, gGpioDirOut_c); Gpio_SetPinData(gTxDataAvailablePin_c, gGpioPinStateHigh_c); mI2cModuleEx.Rxi2cCallback = NULL; mI2cModuleEx.Txi2cCallback = NULL; mI2cModuleEx.i2cStatus = I2C_DEFAULT_STATUS; mI2cModuleEx.sendBuff = 0; mI2cModuleEx.sentBytesNo = 0; mI2cModuleEx.sendBuffLength = 0; mI2cModuleEx.recvBuffLength = 0; I2C.ClockEn = CLOCK_ENABLE; I2C.Address = I2C.Address & ~I2C_ADR_MASK; I2C.FreqDiv = I2C.FreqDiv & ~I2C_FDIV_MASK; I2C.Control = I2C.Control & ~I2C_CTRL_MASK; I2C.Status = 0x00; I2C.Data = 0x00; I2C.DigitalFilter = I2C.DigitalFilter & ~I2C_DFILT_MASK; I2C.ClockEn = I2C.ClockEn & ~I2C_CKER_MASK; Gpio_SetPinFunction(gGpioPin12_c, gGpioAlternate1Mode_c); Gpio_SetPinFunction(gGpioPin13_c, gGpioAlternate1Mode_c); /* Register our own interrupt handler for the I2C peripheral */ IntAssignHandler(gI2cInt_c, (IntHandlerFunc_t)&IIC_IsrEx); ITC_SetPriority(gI2cInt_c, gItcFastPriority_c); ITC_EnableInterrupt(gI2cInt_c); IntEnableFIQ(); /* Enable I2C module */ IIC_EnableEx(); /* Configure I2C hardware peripheral */ IIC_SetSlaveAddress(gI2CDefaultSlaveAddress_c); /* Prepare the Rx module of the I2C to receive a maximum length packet */ IIC_InitQueue(&mI2cModuleEx.recvQueue); IIC_ReceiveDataEx(0x00, &internalRxBuffer[0], gIIC_QueueSz_c - 1, gI2cSlvTransfer_c); #endif }