48 #define ISL29020_ADDR_0 (0x44)
50 #define ISL29020_ADDR_1 (0x45)
52 #define _ISL29020_EN (0x80)
53 #define _ISL29020_MODE (0x40)
54 #define _ISL29020_LIGHT (0x20)
55 #define _ISL29020_RES (0x1c)
56 #define _ISL29020_RANGE (0x03)
58 #define ISL29020_SET_ENABLE(c) do{ (c) |= _ISL29020_EN;}while(0)
59 #define ISL29020_SET_DISABLE(c) do{ (c) &= ~_ISL29020_EN;}while(0)
61 #define ISL29020_SET_MODE_SINGLE(c) do{ (c) &= ~_ISL29020_MODE;}while(0)
62 #define ISL29020_SET_MODE_CONT(c) do{ (c) |= _ISL29020_MODE;}while(0)
64 #define ISL29020_SET_IR(c) do{ (c) |= _ISL29020_LIGHT;}while(0)
65 #define ISL29020_SET_LIGHT(c) do{ (c) &= ~_ISL29020_LIGHT;}while(0)
67 #define ISL29020_SET_RESOLUTION(c,r) do{ (c) &= ~_ISL29020_RES;\
68 (c) |= (r<<2)&_ISL29020_RES; }while(0)
69 #define ISL29020_SET_RANGE(c,r) do{ (c) &= ~_ISL29020_RANGE;\
70 (c) |= (r)&_ISL29020_RANGE; }while(0)
73 #define ISL29020_GET_ENABLE(c) (((c) & _ISL29020_EN)>>7)
74 #define ISL29020_GET_MODE_CONT(c) (((c) & _ISL29020_MODE)>>6)
75 #define ISL29020_GET_IR(c) (((c) & _ISL29020_LIGHT)>>5)
76 #define ISL29020_GET_RES(c) (((c) & _ISL29020_RES)>>2)
77 #define ISL29020_GET_RANGE(c) (((c) & _ISL29020_RANGE))
90 static inline uint8_t isl29020_init(isl29020_ctx_t *pctx, uint8_t addr)
104 static inline void isl29020_set_command(isl29020_ctx_t *pctx, uint8_t cmd)
106 uint8_t buf[3] = {0,};
113 static inline uint8_t isl29020_get_command(isl29020_ctx_t *pctx)
115 uint8_t buf[3] = {0,};
121 static inline uint16_t isl29020_get(isl29020_ctx_t *pctx)
123 uint8_t buf[3] = {1,};
125 return buf[0] | buf[1] * 256;
128 static inline float isl29020_scale(isl29020_ctx_t *pctx, uint16_t val)
133 res = ISL29020_GET_RES(pctx->cmd);
134 range = ISL29020_GET_RANGE(pctx->cmd);
135 cnt_max = (1L << (16 - (res * 4))) - 1;
139 rv = (float)(1000.0 / cnt_max) * (float)val;
142 rv = (float)(4000.0 / cnt_max) * (float)val;
145 rv = (float)(16000.0 / cnt_max) * (float)val;
148 rv = (float)(64000.0 / cnt_max) * (float)val;
159 uint8_t sensor_isl29020_trigger(
void)
163 uint8_t sensor_isl29020_get_raw(
void)
167 uint8_t sensor_isl29020_get_float(
void)
uint8_t i2c_probe(uint8_t devaddr)
uint8_t i2c_master_writeread(uint8_t devaddr, uint8_t *writebuf, uint8_t bytestowrite, uint8_t *readbuf, uint8_t bytestoread)