error_t pn532_bus_HWInit(void) { #ifdef PN532_DEBUGMODE PN532_DEBUG("Initialising I2C%s", CFG_PRINTF_NEWLINE); #endif i2cInit(I2CMASTER); // Set reset pin as output and reset device GPIOSetDir(CFG_PN532_RSTPD_PORT, CFG_PN532_RSTPD_PIN, 1); #ifdef PN532_DEBUGMODE PN532_DEBUG("Resetting the PN532%s", CFG_PRINTF_NEWLINE); #endif LPC_GPIO->CLR[CFG_PN532_RSTPD_PORT] = (1 << CFG_PN532_RSTPD_PIN); systickDelay(400); LPC_GPIO->SET[CFG_PN532_RSTPD_PORT] = (1 << CFG_PN532_RSTPD_PIN); // Wait for the PN532 to finish booting systickDelay(100); // Ping the I2C device first to see if it exists! if (i2cCheckAddress(PN532_I2C_ADDRESS) == false) { #ifdef PN532_DEBUGMODE PN532_DEBUG("Can't find PN532 on the I2C bus%s", CFG_PRINTF_NEWLINE); #endif return ERROR_I2C_DEVICENOTFOUND; } // Set IRQ pin to input GPIOSetDir(CFG_PN532_I2C_IRQPORT, CFG_PN532_I2C_IRQPIN, 0); return ERROR_NONE; }
error_t tcs34725Init(void) { uint8_t id = 0; /* Initialise I2C */ i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(i2cCheckAddress(TCS34725_ADDRESS), ERROR_I2C_DEVICENOTFOUND); /* Make sure we have the right IC (0x44 = TCS34725 and TCS34721) */ ASSERT_STATUS(tcs34725Read8(TCS34725_ID, &id)); ASSERT(id == 0x44, ERROR_DEVICENOTINITIALISED); /* Enable the device */ ASSERT_STATUS(tcs34725Enable()); /* Ready to go ... set the initialised flag */ _tcs34725Initialised = true; /* This needs to take place after the initialisation flag! */ ASSERT_STATUS(tcs34725SetIntegrationTime(TCS34725_INTEGRATIONTIME_2_4MS)); ASSERT_STATUS(tcs34725SetGain(TCS34725_GAIN_60X)); return ERROR_NONE; }
error_t pca9685Init(uint8_t address) { // Initialise I2C i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(!(i2cCheckAddress(_pca9685Address)), ERROR_I2C_DEVICENOTFOUND); ASSERT_STATUS(pca9685Write8(PCA9685_REG_MODE1, 0x00)); _pca9685Initialised = true; return ERROR_NONE; }
error_t mpl115a2Init(void) { /* Initialise I2C */ i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(i2cCheckAddress(MPL115A2_ADDRESS), ERROR_I2C_DEVICENOTFOUND); /* Coefficients need to be read once */ ASSERT_STATUS(mpl115a2ReadCoefficients()); _mpl115a2Initialised = true; return ERROR_NONE; }
error_t lm75bInit(void) { /* Initialise I2C */ i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(i2cCheckAddress(LM75B_ADDRESS), ERROR_I2C_DEVICENOTFOUND); _lm75bInitialised = true; /* Set device to shutdown mode by default (saves power) */ ASSERT_STATUS(lm75bConfigWrite (LM75B_CONFIG_SHUTDOWN_SHUTDOWN)); return ERROR_NONE; }
err_t tsl2561Init(void) { /* Initialise I2C */ i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(i2cCheckAddress(TSL2561_ADDRESS), ERROR_I2C_DEVICENOTFOUND); /* Note: by default, the device is in power down mode on bootup */ _tsl2561Initialised = true; /* Set default integration time and gain */ ASSERT_STATUS(tsl2561SetIntegrationTime(_tsl2561IntegrationTime)); ASSERT_STATUS(tsl2561SetGain(_tsl2561Gain)); return ERROR_NONE; }
error_t lsm303accelInit(void) { // Initialise I2C i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(i2cCheckAddress(LSM303_ADDRESS_ACCEL), ERROR_I2C_DEVICENOTFOUND); /* Enable the accelerometer (10Hz) */ // ASSERT_STATUS(lsm303accelWrite8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A, 0x27)); /* Enable the accelerometer (100Hz) */ ASSERT_STATUS(lsm303accelWrite8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A, 0x57)); _lsm303accelInitialised = true; return ERROR_NONE; }
err_t lsm303magInit(void) { // Initialise I2C i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(i2cCheckAddress(LSM303_ADDRESS_MAG), ERROR_I2C_DEVICENOTFOUND); /* Enable the magnetometer (continuous conversion) */ ASSERT_STATUS(lsm303magWrite8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_MR_REG_M, 0x00)); _lsm303magInitialised = true; /* Set default gain */ ASSERT_STATUS(lsm303magSetGain(_lsm303magGain)); return ERROR_NONE; }
err_t adxl345Init(void) { uint8_t devid = 0x00; /* Initialise I2C */ i2cInit(I2CMASTER); /* Ping the I2C device first to see if it exists! */ ASSERT(i2cCheckAddress(ADXL345_ADDRESS), ERROR_I2C_DEVICENOTFOUND); /* Check device ID register to see if everything is properly connected */ ASSERT_STATUS(adxl345Read8(ADXL345_REG_DEVID, &devid)); if (devid != 0xE5) { return ERROR_I2C_DEVICENOTFOUND; } /* Enable measurements */ ASSERT_STATUS(adxl345Write8(ADXL345_REG_POWER_CTL, 0x08)); _adxl345Initialised = true; return ERROR_NONE; }