// Initialize the I2C bus void I2C_Init(I2C_ID_T id, int speed) { Board_I2C_Init(id); // Initialize board I2C Chip_I2C_Init(id); // Initialize I2C1 Chip_I2C_SetClockRate(id, speed); // Set clock speed I2C_Set_Mode(id, 0); // Set default mode interrupt }
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); }
/* Initialize the I2C bus */ static void i2c_app_init(I2C_ID_T id, int speed) { Board_I2C_Init(id); /* Initialize I2C */ Chip_I2C_Init(id); Chip_I2C_SetClockRate(id, speed); }
void vI2CInit( I2C_ID_T i2c_id, I2C_Mode mode ) { char pcI2C_Tag[4]; uint8_t sla_addr; sprintf( pcI2C_Tag, "I2C%u", i2c_id ); /*! @todo Maybe wrap these functions, or use some board-specific defines * so this code is generic enough to be applied on other hardware. * Example: (if using LPC17xx and LPCOpen library) * @code * #define PIN_FUNC_CFG( port, pin, func ) Chip_IOCON_PinMux(...) * @endcode */ Chip_IOCON_PinMux( LPC_IOCON, i2c_cfg[i2c_id].pins.sda_port, i2c_cfg[i2c_id].pins.sda_pin, IOCON_MODE_INACT, i2c_cfg[i2c_id].pins.pin_func ); Chip_IOCON_PinMux( LPC_IOCON, i2c_cfg[i2c_id].pins.scl_port, i2c_cfg[i2c_id].pins.scl_pin, IOCON_MODE_INACT, i2c_cfg[i2c_id].pins.pin_func ); Chip_IOCON_EnableOD( LPC_IOCON, i2c_cfg[i2c_id].pins.sda_port, i2c_cfg[i2c_id].pins.sda_pin ); Chip_IOCON_EnableOD( LPC_IOCON, i2c_cfg[i2c_id].pins.scl_port, i2c_cfg[i2c_id].pins.scl_pin ); NVIC_SetPriority(i2c_cfg[i2c_id].irq, configMAX_SYSCALL_INTERRUPT_PRIORITY); NVIC_EnableIRQ( i2c_cfg[i2c_id].irq ); /* Create mutex for accessing the shared memory (i2c_cfg) */ I2C_mutex[i2c_id] = xSemaphoreCreateMutex(); /* Make sure that the mutex is freed */ xSemaphoreGive( I2C_mutex[i2c_id] ); /* Set I2C operating mode */ if( xSemaphoreTake( I2C_mutex[i2c_id], 0 ) ) { i2c_cfg[i2c_id].mode = mode; xSemaphoreGive( I2C_mutex[i2c_id] ); } /* Enable and configure I2C clock */ Chip_I2C_Init( i2c_id ); Chip_I2C_SetClockRate( i2c_id, 100000 ); /* Enable I2C interface (Master Mode only) */ I2CCONSET( i2c_id, I2C_I2EN ); if ( mode == I2C_Mode_IPMB ) { /* Configure Slave Address */ sla_addr = get_ipmb_addr( ); I2CADDR_WRITE( i2c_id, sla_addr ); /* Configure Slave Address Mask */ I2CMASK( i2c_id, 0xFE); /* Enable slave mode */ I2CCONSET( i2c_id, I2C_AA ); } /* Clear I2C0 interrupt (just in case) */ I2CCONCLR( i2c_id, I2C_SI ); } /* End of vI2C_Init */
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); }
/* void i2C0_IRQHandler (void) { if (Chip_I2C_IsMasterActive(I2C0)) { Chip_I2C_MasterStateHandler(I2C0); } else { Chip_I2C_SlaveStateHandler(I2C0); } } */ void Board_I2C_Master_Init(void) { Board_I2C_Init(I2C0); /* Initialize I2C */ Chip_I2C_Init(I2C0); Chip_I2C_SetClockRate(I2C0, 100000); /* Set default mode to poll */ i2c_set_mode(I2C0, 1); }
/* Initialize the I2C bus */ static void i2c_app_init(I2C_ID_T id, int speed) { Init_I2C_PinMux(); /* Initialize I2C */ Chip_I2C_Init(id); Chip_I2C_SetClockRate(id, speed); /* Set default mode to interrupt */ i2c_set_mode(id, 0); }
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); }
/* 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) { #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); }
void Board_I2C_Master_SetSpeed(uint32_t speed) { Chip_I2C_SetClockRate(I2C0, speed); }