Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/input/als.h
1476 views
1
/*
2
* Ambient light sensor driver for Nintendo Switch's Rohm BH1730
3
*
4
* Copyright (c) 2018 CTCaer
5
*
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms and conditions of the GNU General Public License,
8
* version 2, as published by the Free Software Foundation.
9
*
10
* This program is distributed in the hope it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
* more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef __ALS_H_
20
#define __ALS_H_
21
22
#include <utils/types.h>
23
24
#define BH1730_I2C_ADDR 0x29
25
26
#define BH1730_CMD_MAGIC 0x80
27
#define BH1730_CMD_SETADDR 0x00
28
#define BH1730_CMD_SPECCMD 0x60
29
#define BH1730_SPECCMD_RESET 0x4
30
31
#define BH1730_CONTROL_REG 0x00
32
#define BH1730_CTL_ADC_VALID 0x10
33
#define BH1730_CTL_ONE_TIME 0x08
34
#define BH1730_CTL_DAT0_ONLY 0x04
35
#define BH1730_CTL_ADC_EN 0x02
36
#define BH1730_CTL_POWER_ON 0x01
37
#define BH1730_TIMING_REG 0x01
38
#define BH1730_GAIN_REG 0x07
39
#define BH1730_GAIN_1X 0x00
40
#define BH1730_GAIN_2X 0x01
41
#define BH1730_GAIN_64X 0x02
42
#define BH1730_GAIN_128X 0x03
43
#define BH1730_DATA0LOW_REG 0x14
44
#define BH1730_DATA0HIGH_REG 0x15
45
#define BH1730_DATA1LOW_REG 0x16
46
#define BH1730_DATA1HIGH_REG 0x17
47
48
#define BH1730_ADDR(reg) (BH1730_CMD_MAGIC | BH1730_CMD_SETADDR | (reg))
49
#define BH1730_SPEC(cmd) (BH1730_CMD_MAGIC | BH1730_CMD_SPECCMD | (cmd))
50
51
typedef struct _als_ctxt_t
52
{
53
u32 lux;
54
bool over_limit;
55
u32 vi_light;
56
u32 ir_light;
57
u8 gain;
58
u8 cycle;
59
} als_ctxt_t;
60
61
void set_als_cfg(als_ctxt_t *als_ctxt, u8 gain, u8 cycle);
62
void get_als_lux(als_ctxt_t *als_ctxt);
63
u8 als_power_on(als_ctxt_t *als_ctxt);
64
65
#endif /* __ALS_H_ */
66
67