114114// return Status;
115115// }
116116
117- // calls the i2c write to multiplexer function
118- static int (* i2c_multi_func )(uint8_t address , uint16_t reg ) = NULL ;
119-
120- // calls read_i2c_block_data(address, reg, length)
121- static int (* i2c_read_func )(uint8_t address , uint16_t reg ,
122- uint8_t * list , uint8_t length ) = NULL ;
123-
124- // calls write_i2c_block_data(address, reg, list)
125- static int (* i2c_write_func )(uint8_t address , uint16_t reg ,
126- uint8_t * list , uint8_t length ) = NULL ;
127-
128117static pthread_mutex_t i2c_mutex = PTHREAD_MUTEX_INITIALIZER ;
129118
130- void VL53L1_set_i2c (void * multi_func , void * read_func , void * write_func )
119+ void VL53L1_set_i2c (VL53L1_DEV Dev , void * multi_func , void * read_func , void * write_func )
131120{
132- i2c_multi_func = multi_func ;
133- i2c_read_func = read_func ;
134- i2c_write_func = write_func ;
121+ Dev -> i2c_multi_func = multi_func ;
122+ Dev -> i2c_read_func = read_func ;
123+ Dev -> i2c_write_func = write_func ;
135124}
136125
137126static int i2c_write (VL53L1_DEV Dev , uint16_t cmd ,
138127 uint8_t * data , uint8_t len )
139128{
140129 int result = VL53L1_ERROR_NONE ;
141130
142- if (i2c_write_func != NULL )
131+ if (Dev -> i2c_write_func != NULL )
143132 {
144133 if (Dev -> TCA9548A_Device < 8 )
145134 {
@@ -149,7 +138,7 @@ static int i2c_write(VL53L1_DEV Dev, uint16_t cmd,
149138 pthread_mutex_lock (& i2c_mutex );
150139
151140 // Write to the multiplexer
152- if (i2c_multi_func (Dev -> TCA9548A_Address , (1 << Dev -> TCA9548A_Device )) < 0 )
141+ if (Dev -> i2c_multi_func (Dev -> TCA9548A_Address , (1 << Dev -> TCA9548A_Device )) < 0 )
153142 {
154143 printf ("i2c bus on multiplexer not set.\n" );
155144 result = VL53L1_ERROR_CONTROL_INTERFACE ;
@@ -158,7 +147,7 @@ static int i2c_write(VL53L1_DEV Dev, uint16_t cmd,
158147
159148 if (result == VL53L1_ERROR_NONE )
160149 {
161- if (i2c_write_func (Dev -> I2cDevAddr , cmd , data , len ) < 0 )
150+ if (Dev -> i2c_write_func (Dev -> I2cDevAddr , cmd , data , len ) < 0 )
162151 {
163152 result = VL53L1_ERROR_CONTROL_INTERFACE ;
164153 }
@@ -183,7 +172,7 @@ static int i2c_read(VL53L1_DEV Dev, uint16_t cmd,
183172{
184173 int result = VL53L1_ERROR_NONE ;
185174
186- if (i2c_read_func != NULL )
175+ if (Dev -> i2c_read_func != NULL )
187176 {
188177 if (Dev -> TCA9548A_Device < 8 )
189178 {
@@ -193,7 +182,7 @@ static int i2c_read(VL53L1_DEV Dev, uint16_t cmd,
193182 pthread_mutex_lock (& i2c_mutex );
194183
195184 // Write to the multiplexer
196- if (i2c_multi_func (Dev -> TCA9548A_Address , (1 << Dev -> TCA9548A_Device )) < 0 )
185+ if (Dev -> i2c_multi_func (Dev -> TCA9548A_Address , (1 << Dev -> TCA9548A_Device )) < 0 )
197186 {
198187 printf ("i2c bus on multiplexer not set.\n" );
199188 result = VL53L1_ERROR_CONTROL_INTERFACE ;
@@ -202,7 +191,7 @@ static int i2c_read(VL53L1_DEV Dev, uint16_t cmd,
202191
203192 if (result == VL53L1_ERROR_NONE )
204193 {
205- if (i2c_read_func (Dev -> I2cDevAddr , cmd , data , len ) < 0 )
194+ if (Dev -> i2c_read_func (Dev -> I2cDevAddr , cmd , data , len ) < 0 )
206195 {
207196 result = VL53L1_ERROR_CONTROL_INTERFACE ;
208197 }
0 commit comments