You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2017/02/24 19:38:27 UTC
[32/50] incubator-mynewt-core git commit: Cleaning up
Cleaning up
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e5c20c82
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e5c20c82
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e5c20c82
Branch: refs/heads/develop
Commit: e5c20c82c53d6e2c7268e47b37b8bb9e51b8ba1a
Parents: 3559c73
Author: Vipul Rahane <vi...@apache.org>
Authored: Fri Feb 3 16:17:37 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Fri Feb 3 16:17:37 2017 -0800
----------------------------------------------------------------------
hw/drivers/sensors/tsl2561/src/tsl2561.c | 39 +++++++++------------------
1 file changed, 12 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5c20c82/hw/drivers/sensors/tsl2561/src/tsl2561.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/tsl2561/src/tsl2561.c b/hw/drivers/sensors/tsl2561/src/tsl2561.c
index c9f7531..1fbf905 100644
--- a/hw/drivers/sensors/tsl2561/src/tsl2561.c
+++ b/hw/drivers/sensors/tsl2561/src/tsl2561.c
@@ -58,12 +58,9 @@
/* ToDo: Add timer based polling in bg and data ready callback (os_event?) */
/* ToDo: Move values to struct incl. address to allow multiple instances */
-#if MYNEWT_VAL(TSL2561_CLI)
uint8_t g_tsl2561_gain;
uint8_t g_tsl2561_integration_time;
uint8_t g_tsl2561_enabled;
-#endif
-
#if MYNEWT_VAL(TSL2561_STATS)
/* Define the stats section and records */
@@ -224,7 +221,6 @@ err:
return rc;
}
-#if MYNEWT_VAL(TSL2561_CLI)
int
tsl2561_enable(uint8_t state)
{
@@ -253,14 +249,14 @@ tsl2561_set_integration_time(uint8_t int_time)
int rc;
rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
- g_tsl2561_integration_time | g_tsl2561_gain);
+ int_time | g_tsl2561_gain);
if (rc) {
- goto error;
+ goto err;
}
g_tsl2561_integration_time = int_time;
-error:
+err:
return rc;
}
@@ -278,18 +274,18 @@ tsl2561_set_gain(uint8_t gain)
if ((gain != TSL2561_LIGHT_GAIN_1X) && (gain != TSL2561_LIGHT_GAIN_16X)) {
TSL2561_ERR("Invalid gain value\n");
rc = EINVAL;
- goto error;
+ goto err;
}
rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
g_tsl2561_integration_time | gain);
if (rc) {
- goto error;
+ goto err;
}
g_tsl2561_gain = gain;
-error:
+err:
return rc;
}
@@ -298,8 +294,6 @@ tsl2561_get_gain(void)
{
return g_tsl2561_gain;
}
-#endif
-
int
tsl2561_get_data(uint16_t *broadband, uint16_t *ir, struct tsl2561 *tsl2561)
@@ -698,27 +692,18 @@ tsl2561_config(struct tsl2561 *tsl2561, struct tsl2561_cfg *cfg)
{
int rc;
- if ((cfg->gain != TSL2561_LIGHT_GAIN_1X) &&
- (cfg->gain != TSL2561_LIGHT_GAIN_16X)) {
- TSL2561_ERR("Invalid gain value\n");
- rc = SYS_EINVAL;
- goto err;
- }
-
- /* Overwrite the configuration data. */
- memcpy(&tsl2561->cfg, cfg, sizeof(*cfg));
+ rc = tsl2561_enable(1);
- /* Enable the device by setting the control bit to 0x03 */
- rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL,
- TSL2561_CONTROL_POWERON);
+ rc |= tsl2561_set_integration_time(cfg->integration_time);
- /* Set integration time and gain */
- rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
- cfg->integration_time | cfg->gain);
+ rc |= tsl2561_set_gain(cfg->gain);
if (rc) {
goto err;
}
+ /* Overwrite the configuration data. */
+ memcpy(&tsl2561->cfg, cfg, sizeof(*cfg));
+
err:
return (rc);
}