#ifdef __USE_LPCOPEN // Read clock settings and update SystemCoreClock variable SystemCoreClockUpdate(); // Set up and initialize all required blocks and functions // related to the board hardware Board_Init(); // Set the LED to the state of "Off" Board_LED_Set(0, false); /* Setup I2C pin muxing */ Init_I2C_PinMux(); /* Allocate I2C handle, setup I2C rate, and initialize I2C clocking */ setupI2CMaster(); /* Enable SysTick Timer */ SysTick_Config(SystemCoreClock / TICKRATE_HZ); #endif |
/* Initializes pin muxing for I2C interface - note that SystemInit() may already setup your pin muxing at system startup */ static void Init_I2C_PinMux(void) { #if defined(BOARD_NXP_XPRESSO_812) /* Enable the clock to the Switch Matrix */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); /* Connect the I2C_SDA and I2C_SCL signals to port pins(P0.10, P0.11) */ Chip_SWM_MovablePinAssign(SWM_I2C_SDA_IO, 10); Chip_SWM_MovablePinAssign(SWM_I2C_SCL_IO, 11); #if (I2C_BITRATE > 400000) /* Enable Fast Mode Plus for I2C pins */ Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO10, PIN_I2CMODE_FASTPLUS); Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO11, PIN_I2CMODE_FASTPLUS); #endif /* Disable the clock to the Switch Matrix to save power */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); #else /* Configure your own I2C pin muxing here if needed */ #warning No I2C pin muxing defined #endif } /* Setup I2C handle and parameters */ void setupI2CMaster() { /* Enable I2C clock and reset I2C peripheral - the boot ROM does not do this */ Chip_I2C_Init(); /* Perform a sanity check on the storage allocation */ if (LPC_I2CD_API->i2c_get_mem_size() > sizeof(i2cMasterHandleMEM)) { /* Example only: this should never happen and probably isn't needed for most I2C code. */ errorI2C(); } /* Setup the I2C handle */ i2cHandleMaster = LPC_I2CD_API->i2c_setup(LPC_I2C_BASE, i2cMasterHandleMEM); if (i2cHandleMaster == NULL) { errorI2C(); } /* Set I2C bit rate */ if (LPC_I2CD_API->i2c_set_bitrate(i2cHandleMaster, Chip_Clock_GetSystemClockRate(), I2C_BITRATE) != LPC_OK) { errorI2C(); } /* Enable the interrupt for the I2C */ NVIC_EnableIRQ(I2C_IRQn); } |