monoZ docs
MZ_i2c_example.h
Go to the documentation of this file.
1/*
2 * MZ_i2c_example.h
3 *
4 * Created on: Jul 14, 2021
5 * Author: Mahendra & Kafeel
6 */
7
8#ifndef MZ_I2C_EXAMPLE_H_
9#define MZ_I2C_EXAMPLE_H_
10
11//SENSOR I2C Register Map
12#define SI_REG_RD 0x01
13#define SI_REG_WR 0x00
14
15#define SI_REG_RA(x) (x)
16#define SI_ID_REG_PART_ID 0X00
17#define SI_ID_REG_HW_ID 0X01
18#define SI_ID_REG_REV_ID 0X02
19#define SI_SL_ADD (SLAVE_ADD)
20
21#define ENMASK_UV_INDEX (1u << 6)
22#define RETRY_MAX 2
23#define TIMEOUT_5_SECS 5000UL
24#define TIMEOUT_15_SECS 15000UL
25#define TIMEOUT_25_SECS 25000UL
26#define TIMEOUT_35_SECS 35000UL
27#define TIMEOUT_90_SECS 90000UL
28#define TIMEOUT_120_SECS 120000UL
29#define TIMEOUT_180_SECS 180000UL
30#define TIMEOUT_360_SECS 360000UL
31//SENSOR Direct Register Map
32#define SENSOR_REG_IRQ_ENABLE 0x0F
33#define SENSOR_REG_IRQ_STATUS 0x12
34#define SENSOR_REG_HOSTOUT0 0x13
35#define SENSOR_REG_HOSTOUT1 0x14
36#define SENSOR_REG_HOSTOUT2 0x15
37#define SENSOR_REG_HOSTOUT3 0x16
38#define SENSOR_REG_HOSTOUT4 0x17
39#define SENSOR_REG_HOSTOUT5 0x18
40#define SENSOR_REG_HOSTOUT6 0x19
41#define SENSOR_REG_HOSTOUT7 0x1A
42#define SENSOR_REG_HOSTOUT8 0x1B
43#define SENSOR_REG_HOSTOUT9 0x1C
44#define SENSOR_REG_HOSTOUT10 0x1D
45#define SENSOR_REG_HOSTOUT11 0x1E
46#define SENSOR_REG_HOSTOUT12 0x1F
47#define SENSOR_REG_HOSTOUT13 0x20
48#define SENSOR_REG_HOSTOUT14 0x21
49#define SENSOR_REG_HOSTOUT15 0x22
50#define SENSOR_REG_HOSTOUT16 0x23
51#define SENSOR_REG_HOSTOUT17 0x24
52#define SENSOR_REG_HOSTOUT18 0x25
53#define SENSOR_REG_HOSTOUT19 0x26
54#define SENSOR_REG_HOSTOUT20 0x27
55#define SENSOR_REG_HOSTOUT21 0x28
56#define SENSOR_REG_HOSTOUT22 0x29
57#define SENSOR_REG_HOSTOUT23 0x2A
58#define SENSOR_REG_HOSTOUT24 0x2B
59#define SENSOR_REG_HOSTOUT25 0x2C
60
61#define UV_INPUT_FRACTION 15
62#define UV_OUTPUT_FRACTION 12
63#define UV_NUMCOEFF 2
64#define ADC_THRESHOLD 16000
65#define INPUT_FRACTION_HIGH 7
66#define INPUT_FRACTION_LOW 15
67#define LUX_OUTPUT_FRACTION 12
68#define NUMCOEFF_LOW 9
69#define NUMCOEFF_HIGH 4
70
71#define X_ORDER_MASK 0x0070
72#define Y_ORDER_MASK 0x0007
73#define SIGN_MASK 0x0080
74#define get_x_order(m) ( (m & X_ORDER_MASK) >> 4)
75#define get_y_order(m) ( (m & Y_ORDER_MASK) )
76#define get_sign(m) ( (m & SIGN_MASK) >> 7)
77
78//SENSOR Parameter Register Map
79#define SENSOR_PARAM_I2C_ADDR 0x00
80#define SENSOR_PARAM_CH_LIST 0x01
81#define SENSOR_PARAM_ADCCONFIG0 0x02
82#define SENSOR_PARAM_ADCSENS0 0x03
83#define SENSOR_PARAM_ADCPOST0 0x04
84#define SENSOR_PARAM_MEASCONFIG0 0x05
85#define SENSOR_PARAM_ADCCONFIG1 0x06
86#define SENSOR_PARAM_ADCSENS1 0x07
87#define SENSOR_PARAM_ADCPOST1 0x08
88#define SENSOR_PARAM_MEASCONFIG1 0x09
89#define SENSOR_PARAM_ADCCONFIG2 0x0A
90#define SENSOR_PARAM_ADCSENS2 0x0B
91#define SENSOR_PARAM_ADCPOST2 0x0C
92#define SENSOR_PARAM_MEASCONFIG2 0x0D
93#define SENSOR_PARAM_ADCCONFIG3 0x0E
94#define SENSOR_PARAM_ADCSENS3 0x0F
95#define SENSOR_PARAM_ADCPOST3 0x10
96#define SENSOR_PARAM_MEASCONFIG3 0x11
97#define SENSOR_PARAM_ADCCONFIG4 0x12
98#define SENSOR_PARAM_ADCSENS4 0x13
99#define SENSOR_PARAM_ADCPOST4 0x14
100#define SENSOR_PARAM_MEASCONFIG4 0x15
101#define SENSOR_REG_HOSTIN0 0x0A
102#define SENSOR_REG_COMMAND 0x0B
103#define SENSOR_REG_IRQ_ENABLE 0x0F
104#define SENSOR_REG_RESPONSE1 0x10
105#define SENSOR_REG_RESPONSE0 0x11
106#define SENSOR_REG_IRQ_STATUS 0x12
107#define SENSOR_REG_BURST 0x2B
108// command register code
109#define RESET_CMD_CTR 0x00
110#define FORCE_CMD 0x11
111#define SENSOR_RSP0_COUNTER_MASK 0x1F
112#define SENSOR_OK 0000
113
114typedef enum{
120
121typedef enum{
128
129typedef enum{
134
135typedef struct{
138}SI_CMD;
139typedef struct
140 {
141 int16_t info;
142 uint16_t mag;
144
145
146typedef struct
147 {
148 SENSOR_Coeff_TypeDef coeff_high[4];
151
153{ { 0, 209 },
154 { 1665, 93 },
155 { 2064, 65 },
156 { -2671, 234 } },
157 { { 0, 0 },
158 { 1921, 29053 },
159 { -1022, 36363 },
160 { 2320, 20789 },
161 { -367, 57909 },
162 { -1774, 38240 },
163 { -608, 46775 },
164 { -1503, 51831 },
165 { -1886, 58928 } }
166 };
167
169
170 { 1281, 30902 },
171 { -638, 46301 }
172 };
173typedef struct{
174 uint8_t UV_Data[50];
175
178
179void SENSOR_Init();
181int32_t SENSOR_getUv( int32_t uv, SENSOR_Coeff_TypeDef *uk );
182int32_t SENSOR_calcEvalPoly( int32_t x, int32_t y, uint8_t input_fraction, uint8_t output_fraction, uint8_t num_coeff, SENSOR_Coeff_TypeDef *kp );
183int32_t SENSOR_calcPolyInner( int32_t input, int8_t fraction, uint16_t mag, int8_t shift );
185mz_error_t Sensor_cmd_data_conf(uint8_t addr, uint8_t data);
187mz_error_t I2C_Read_Reg(uint8_t addr, uint32_t *buf);
188mz_error_t I2C_Write_Reg(uint8_t addr, uint8_t data);
189uint8_t N;
192mz_error_t param_table_write(uint8_t addr, uint8_t data);
195void reset_resp_counter(void);
196void int8buf_to_asciibuf(uint8_t *destbuf,uint8_t *srcbuf,uint16_t len);
197uint16_t Get_String_len(uint8_t *buf);
198uint8_t string_append(uint8_t *srcstr,uint8_t *apstr);
199uint16_t string_copy(uint8_t *dststr,uint8_t *srcstr);
200void calib_uv_index(float uv_raw_data);
201
202
203#endif /* MZ_I2C_EXAMPLE_H_ */
mz_error_t
Enumeration of monoZ Error Flags.
mzUint8 buf[10]
static SENSOR_LuxCoeff_TypeDef lk
mz_error_t I2C_Read_Reg(uint8_t addr, uint32_t *buf)
Function to read from the specific register.
void int8buf_to_asciibuf(uint8_t *destbuf, uint8_t *srcbuf, uint16_t len)
Function to Conversion of Int to ascii data.
uint16_t string_copy(uint8_t *dststr, uint8_t *srcstr)
Function to Copy the data from source to destination.
mz_error_t I2C_ReadID_Reg(uint8_t *buf)
int32_t SENSOR_calcEvalPoly(int32_t x, int32_t y, uint8_t input_fraction, uint8_t output_fraction, uint8_t num_coeff, SENSOR_Coeff_TypeDef *kp)
Function to Conversion of Raw Data.
uint8_t * Get_SenPayload_UV_DataStr(void)
uint16_t Get_String_len(uint8_t *buf)
Function to get string length.
SICMD_REQ
@ SI_CMD_READ_ALS
@ SI_CMD_NONE
@ SI_CMD_READ_UV
mz_error_t Sensor_cmd_data_conf(uint8_t addr, uint8_t data)
Function to write data for Sensor Configuration.
SISER_RCVD
@ SISER_NONE_RCVD
@ SISER_INVALID_RESP_RCVD
@ SISER_VALID_RESP_RCVD
@ SISER_TIMEOUT_RCVD
PAYLOAD_ST SENSOR_payload
SICMD_RESP
@ SICMD_DONE
@ SICMD_TIMEOUT
@ SICMD_NG
@ SICMD_NOT_DONE
@ SICMD_ERROR
mz_error_t param_table_write(uint8_t addr, uint8_t data)
Function to read from the specific register.
static SENSOR_Coeff_TypeDef uk[2]
int32_t SENSOR_calcPolyInner(int32_t input, int8_t fraction, uint16_t mag, int8_t shift)
Function to Conversion of Raw Data.
uint8_t N
uint8_t string_append(uint8_t *srcstr, uint8_t *apstr)
Function to append the string.
mz_error_t I2C_Write_Reg(uint8_t addr, uint8_t data)
Function to write into the specific register.
mz_error_t Sensor_ReadID(uint8_t *buf)
Function to read the content from ID register of SENSOR.
void calib_uv_index(float uv_raw_data)
Function to calibrate the raw data.
SISER_RCVD SI_Read_UV(void)
Function to read the data from SENSOR.
mz_error_t i2c_app_init(void)
SISER_RCVD send_SI_cmd_and_wait_resp(SICMD_REQ req, uint32_t timeout)
void SENSOR_Init()
Function Sensor Initialisation.
int32_t SENSOR_getUv(int32_t uv, SENSOR_Coeff_TypeDef *uk)
Function to Conversion of Raw Data.
mz_error_t SENSOR_Config()
Function to config the sensor.
void reset_resp_counter(void)
Reset register.
SICMD_REQ cmd_request
SICMD_RESP cmd_response