int tsl2561_config(struct tsl2561 *tsl2561, struct tsl2561_cfg *cfg) { int rc; rc = tsl2561_enable(1); rc |= tsl2561_set_integration_time(cfg->integration_time); rc |= tsl2561_set_gain(cfg->gain); if (rc) { goto err; } /* Overwrite the configuration data. */ memcpy(&tsl2561->cfg, cfg, sizeof(*cfg)); err: return (rc); }
/** * Configure the sensor * * @param ptr to sensor driver * @param ptr to sensor driver config */ int tsl2561_config(struct tsl2561 *tsl2561, struct tsl2561_cfg *cfg) { int rc; struct sensor_itf *itf; itf = SENSOR_GET_ITF(&(tsl2561->sensor)); rc = tsl2561_enable(itf, 1); if (rc) { goto err; } rc = tsl2561_set_integration_time(itf, cfg->integration_time); if (rc) { goto err; } tsl2561->cfg.integration_time = cfg->integration_time; rc = tsl2561_set_gain(itf, cfg->gain); if (rc) { goto err; } tsl2561->cfg.gain = cfg->gain; rc = sensor_set_type_mask(&(tsl2561->sensor), cfg->mask); if (rc) { goto err; } tsl2561->cfg.mask = cfg->mask; return 0; err: return rc; }