Loading...
Searching...
No Matches
tsl4531x_internals.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Inria
3 * Copyright (C) 2018 Freie Universität Berlin
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
9
25#ifndef TSL4531X_INTERNALS_H
26#define TSL4531X_INTERNALS_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
36#define TSL4531X_CONTROL_REG (0x0)
37#define TSL4531X_CONFIGURATION_REG (0x01)
38#define TSL4531X_ALSDATA1_REG (0x04)
39#define TSL4531X_ALSDATA2_REG (0x05)
40#define TSL4531X_ID_REG (0x0A)
47#define TSL4531X_MODE_POWER_DOWN (0x00)
48#define TSL4531X_MODE_RESERVED (0x01)
49#define TSL4531X_MODE_SINGLE_ADC_CYCLE (0x02)
51#define TSL4531X_MODE_NORMAL (0x03)
52
53/* PowerSave saves some power in full power mode. PowerSave skip turns this off.
54 * Currently PowerSave skip is hard-coded to be on for simplicity, as it's just
55 * an intermediate between normal mode and low-power mode. */
56#define TSL4531X_PSAVESKIP_OFF (0)
57#define TSL4531X_PSAVESKIP_ON (1)
64/* Assemble the Command register */
65#define TSL4531X_COMMAND(addr) ((1 << 7) | (addr))
66
67/* Assemble the Configuration register */
68#define TSL4531X_CONFIG(psaveskip, tcntrl) (((!!(psaveskip)) << 3) | (tcntrl))
69
70/* Assemble the Control register */
71#define TSL4531X_CONTROL(mode) (mode)
72
73#define TSL4531X_GET_PARTNO(id_reg) ((id_reg) >> 4)
74
75/* Data multiplier according to integration time.
76 *
77 * From the manual:
78 * MULTIPLIER = 1 for TCNTRL = 00 (Tint = 400 ms)
79 * MULTIPLIER = 2 for TCNTRL = 01 (Tint = 200 ms)
80 * MULTIPLIER = 4 for TCNTRL = 10 (Tint = 100 ms)
81 */
82#define MULTIPLY_DATA(data_raw, integration_time) ((data_raw) << (integration_time))
83
84/* This allows either full power mode or power down mode. */
85#define TSL4531X_POWER_MODE(mode) ((!mode) * (0x03))
86
87/* The full integration time is a sum of:
88 * 1. A worst-case time for each of the integration times, which according to
89 * the datasheet is 5% more than the nominal time
90 * 2. 60, 30 or 15 ms, according to the integration time, if PowerSave is on;
91 * which is the power down period in between integration cycles in this mode.
92 * Note that in the current implementation, the "PowerSave skip" option is
93 * hard-coded to be on, as PowerSave only gives slightly less power
94 * consumption than normal mode.
95 */
96#define TSL4531X_GET_INTEGRATION_TIME_USEC(int_time_setting, psaveskip) \
97 (uint32_t)1000 * (((0x04 >> int_time_setting) * 105) + ((!psaveskip) * (60 >> int_time_setting)))
100#ifdef __cplusplus
101}
102#endif
103
104#endif /* TSL4531X_INTERNALS_H */