/* Set I2C mode to polling/interrupt */ static void i2c_set_mode(I2C_ID_T id, int polling) { if (!polling) { mode_poll &= ~(1 << id); Chip_I2C_SetMasterEventHandler(id, Chip_I2C_EventHandler); NVIC_EnableIRQ(I2C0_IRQn); } else { mode_poll |= 1 << id; NVIC_DisableIRQ(I2C0_IRQn); Chip_I2C_SetMasterEventHandler(id, Chip_I2C_EventHandlerPolling); } }
// Set I2C mode to polling/interrupt void I2C_Set_Mode(I2C_ID_T id, int polling) { if(!polling) { mode_poll &= ~(1 << id); Chip_I2C_SetMasterEventHandler(id, Chip_I2C_EventHandler); NVIC_EnableIRQ(id == I2C0 ? I2C0_IRQn : I2C1_IRQn); } else { mode_poll |= 1 << id; NVIC_DisableIRQ(id == I2C0 ? I2C0_IRQn : I2C1_IRQn); Chip_I2C_SetMasterEventHandler(id, Chip_I2C_EventHandlerPolling); } }
static void i2c_onboard_init(void) { Chip_I2C_Init(ONBOARD_I2C); Chip_I2C_SetClockRate(ONBOARD_I2C, 100000); // mode_poll &= ~(1 << id); Chip_I2C_SetMasterEventHandler(ONBOARD_I2C, Chip_I2C_EventHandler); NVIC_EnableIRQ(I2C0_IRQn); }
void Board_I2C_Init(void) { Chip_SYSCTL_PeriphReset(RESET_I2C0); Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO0_4, (IOCON_FUNC1)); Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO0_5, (IOCON_FUNC1)); Chip_SYSCTL_DeassertPeriphReset(RESET_I2C0); Chip_I2C_Init(DEFAULT_I2C); Chip_I2C_SetClockRate(DEFAULT_I2C, SPEED_100KHZ); Chip_I2C_SetMasterEventHandler(DEFAULT_I2C, Chip_I2C_EventHandler); NVIC_EnableIRQ(I2C0_IRQn); }
/* WM8904 initialize function */ int WM8904_Init(int input) { I2C_EVENTHANDLER_T old = Chip_I2C_GetMasterEventHandler(WM8904_I2C_BUS); int ret; /* Initialize I2C */ Board_I2C_Init(WM8904_I2C_BUS); Chip_I2C_Init(WM8904_I2C_BUS); Chip_I2C_SetClockRate(WM8904_I2C_BUS, 100000); Chip_I2C_SetMasterEventHandler(WM8904_I2C_BUS, Chip_I2C_EventHandlerPolling); /* Initialize the default values */ ret = Audio_Codec_SetDefaultValues((void *)&g_wm8904[0], sizeof(g_wm8904)/sizeof(WM8904_Init_Seq_t)); #if 0 if (ret) { ret = Audio_Codec_SetDefaultValues(UDA_interfil_regs_dat, sizeof(UDA_interfil_regs_dat)); } if (ret) { ret = Audio_Codec_SetDefaultValues(UDA_decimator_regs_dat, sizeof(UDA_decimator_regs_dat)); } if (ret && input) { /* Disable Power On for ADCR, PGAR, PGAL to get mic sound more clearly */ ret = UDA1380_REG_WriteVerify(UDA_POWER_CTRL, UDA1380_REG_PWRCTRL_DEFAULT_VALUE & (~(0x0B))); if (ret) { ret = UDA1380_REG_WriteVerify(UDA_ADC_CTRL, UDA1380_REG_ADC_DEFAULT_VALUE | input); } } #endif Chip_I2C_SetMasterEventHandler(WM8904_I2C_BUS, old); return ret; }
static void initHardware(void) { // 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); Board_I2C_Init(I2C1); Chip_I2C_SetClockRate(I2C1, 100000); Chip_I2C_SetMasterEventHandler(I2C1, Chip_I2C_EventHandlerPolling); }
static void initHardware(void) { #if defined (__USE_LPCOPEN) #if !defined(NO_BOARD_LIB) // 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); #endif #endif Board_I2C_Init(I2C1); /* pines del stick */ Chip_IOCON_PinMux(LPC_IOCON, 0, 0, IOCON_MODE_INACT, IOCON_FUNC3); Chip_IOCON_PinMux(LPC_IOCON, 0, 1, IOCON_MODE_INACT, IOCON_FUNC3); Chip_IOCON_EnableOD(LPC_IOCON, 0, 0); Chip_IOCON_EnableOD(LPC_IOCON, 0, 1); Chip_I2C_SetClockRate(I2C1, 100000); Chip_I2C_SetMasterEventHandler(I2C1, Chip_I2C_EventHandlerPolling); }