/*----------------------------------------------------------------------------* * NAME * I2CcommsInit * * DESCRIPTION * This function initialises the I2C * * RETURNS * Nothing * *----------------------------------------------------------------------------*/ extern void I2CcommsInit(void) { /* Initialise I2C if it is not already initialised */ if(!i2c_initialised) { i2c_initialised = TRUE; PioSetModes( ((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), pio_mode_user); /* Configure the PIOs as Input */ PioSetDirs( ((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), FALSE); PioSetPullModes(((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), pio_mode_strong_pull_down); PioSetEventMask(((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), pio_event_mode_disable); /* Configure the I2C controller */ I2cInit(I2C_SDA_PIO, I2C_SCL_PIO, I2C_POWER_PIO_UNDEFINED, pio_i2c_pull_mode_strong_pull_up); /* Configure pull mode of the I2C pins */ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_up); /* Configure the I2C clock */ I2cConfigClock(I2C_SCL_100KBPS_HIGH_PERIOD, I2C_SCL_100KBPS_LOW_PERIOD); // I2cConfigClock(I2C_SCL_400KBPS_HIGH_PERIOD, I2C_SCL_400KBPS_LOW_PERIOD); /* Enable the I2C controller */ I2cEnable(TRUE); } }
void AppInit(sleep_state last_sleep_state) { /* set all PIOs to inputs and pull them down */ PioSetModes(0xFFFFFFFFUL, pio_mode_user); PioSetDirs(0xFFFFFFFFUL, FALSE); PioSetPullModes(0xFFFFFFFFUL, pio_mode_strong_pull_down); /* Set LED0 and LED1 to be controlled directly via PioSet */ PioSetModes((1UL << PIO_LED0), pio_mode_user); /* Configure LED0 and LED1 to be outputs */ PioSetDir(PIO_LED0, PIO_DIR_OUTPUT); /* Set the LED0 and LED1 to have strong internal pull ups */ PioSetPullModes((1UL << PIO_LED0), pio_mode_strong_pull_up); /* Configure button to be controlled directly */ PioSetMode(PIR_SIGNAL, pio_mode_user); /* Configure button to be input */ PioSetDir(PIR_SIGNAL, PIO_DIR_INPUT); /* Set weak pull up on button PIO, in order not to draw too much current * while button is pressed */ PioSetPullModes((1UL << PIR_SIGNAL), pio_mode_weak_pull_down); /* Set the button to generate sys_event_pio_changed when pressed as well * as released */ PioSetEventMask((1UL << PIR_SIGNAL), pio_event_mode_rising); /* disable wake up on UART RX */ SleepWakeOnUartRX(FALSE); /* pull down the I2C lines */ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down); /* Reset LED sequence */ restartLedSeq(); SleepModeChange(sleep_mode_deep); TimerInit(MAX_APP_TIMERS, (void*)app_timers); BeaconInit(); pirStatusServiceInit(); }
void AppInit(sleep_state last_sleep_state) { /* set all PIOs to inputs and pull them down */ PioSetModes(0xFFFFFFFFUL, pio_mode_user); PioSetDirs(0xFFFFFFFFUL, FALSE); PioSetPullModes(0xFFFFFFFFUL, pio_mode_strong_pull_down); /* disable wake up on UART RX */ SleepWakeOnUartRX(FALSE); /* pull down the I2C lines */ PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down); /* Start advertising */ startAdvertising(); }