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
10#pragma once
11
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
35#define TSL4531X_CONTROL_REG (0x0)
36#define TSL4531X_CONFIGURATION_REG (0x01)
37#define TSL4531X_ALSDATA1_REG (0x04)
38#define TSL4531X_ALSDATA2_REG (0x05)
39#define TSL4531X_ID_REG (0x0A)
41
46#define TSL4531X_MODE_POWER_DOWN (0x00)
47#define TSL4531X_MODE_RESERVED (0x01)
48#define TSL4531X_MODE_SINGLE_ADC_CYCLE (0x02)
50#define TSL4531X_MODE_NORMAL (0x03)
51
52/* PowerSave saves some power in full power mode. PowerSave skip turns this off.
53 * Currently PowerSave skip is hard-coded to be on for simplicity, as it's just
54 * an intermediate between normal mode and low-power mode. */
55#define TSL4531X_PSAVESKIP_OFF (0)
56#define TSL4531X_PSAVESKIP_ON (1)
58
63/* Assemble the Command register */
64#define TSL4531X_COMMAND(addr) ((1 << 7) | (addr))
65
66/* Assemble the Configuration register */
67#define TSL4531X_CONFIG(psaveskip, tcntrl) (((!!(psaveskip)) << 3) | (tcntrl))
68
69/* Assemble the Control register */
70#define TSL4531X_CONTROL(mode) (mode)
71
72#define TSL4531X_GET_PARTNO(id_reg) ((id_reg) >> 4)
73
74/* Data multiplier according to integration time.
75 *
76 * From the manual:
77 * MULTIPLIER = 1 for TCNTRL = 00 (Tint = 400 ms)
78 * MULTIPLIER = 2 for TCNTRL = 01 (Tint = 200 ms)
79 * MULTIPLIER = 4 for TCNTRL = 10 (Tint = 100 ms)
80 */
81#define MULTIPLY_DATA(data_raw, integration_time) ((data_raw) << (integration_time))
82
83/* This allows either full power mode or power down mode. */
84#define TSL4531X_POWER_MODE(mode) ((!mode) * (0x03))
85
86/* The full integration time is a sum of:
87 * 1. A worst-case time for each of the integration times, which according to
88 * the datasheet is 5% more than the nominal time
89 * 2. 60, 30 or 15 ms, according to the integration time, if PowerSave is on;
90 * which is the power down period in between integration cycles in this mode.
91 * Note that in the current implementation, the "PowerSave skip" option is
92 * hard-coded to be on, as PowerSave only gives slightly less power
93 * consumption than normal mode.
94 */
95#define TSL4531X_GET_INTEGRATION_TIME_USEC(int_time_setting, psaveskip) \
96 (uint32_t)1000 * (((0x04 >> int_time_setting) * 105) + ((!psaveskip) * (60 >> int_time_setting)))
98
99#ifdef __cplusplus
100}
101#endif
102