STSW-STLKT01: Drivers/BSP/SensorTile/SensorTile_gg.c Source File

STSW-STLKT01

STSW-STLKT01
SensorTile_gg.c
Go to the documentation of this file.
1 
37 /* Includes ------------------------------------------------------------------*/
38 #include "SensorTile_gg.h"
39 #include "STC3115_Driver.h"
40 
76 static DrvContextTypeDef GG_SensorHandle[ GG_MAX_NUM ];
77 static GG_Data_t GG_Data[ GG_MAX_NUM ];
78 static STC3115_Data_t STC3115_0_Data;
79 
102 DrvStatusTypeDef BSP_GG_Init( void **handle )
103 {
104  GG_Drv_t *driver = NULL;
105 
106  if(GG_SensorHandle[ STC3115_0 ].isInitialized == 1)
107  {
108  /* We have reached the max num of instance for this component */
109  return COMPONENT_ERROR;
110  }
111 
112  if ( Sensor_IO_I2C_Init() == COMPONENT_ERROR )
113  {
114  return COMPONENT_ERROR;
115  }
116 
117  /* Setup sensor handle. */
118  GG_SensorHandle[ STC3115_0 ].who_am_i = STC3115_ID;
119  GG_SensorHandle[ STC3115_0 ].ifType = 0; // SPI interface
120  GG_SensorHandle[ STC3115_0 ].address = STC3115_SLAVE_ADDRESS;
121  GG_SensorHandle[ STC3115_0 ].spiDevice = 0;
122  GG_SensorHandle[ STC3115_0 ].instance = STC3115_0;
123  GG_SensorHandle[ STC3115_0 ].isInitialized = 0;
124  GG_SensorHandle[ STC3115_0 ].isEnabled = 0;
125  GG_SensorHandle[ STC3115_0 ].isCombo = 1;
126  GG_SensorHandle[ STC3115_0 ].pData = ( void * )&GG_Data[ STC3115_0 ];
127  GG_SensorHandle[ STC3115_0 ].pVTable = ( void * )&STC3115_Drv;
128  GG_SensorHandle[ STC3115_0 ].pExtVTable = 0;
129 
130  GG_Data[ STC3115_0 ].pComponentData = ( void * )&STC3115_0_Data;
131  GG_Data[ STC3115_0 ].pExtData = 0;
132 
133  *handle = (void *)&GG_SensorHandle[ STC3115_0 ];
134 // *handle = (void *)GG_SensorHandle;
135 
136  driver = ( GG_Drv_t * )((DrvContextTypeDef *)(*handle))->pVTable;
137 
138  if ( driver->Init == NULL )
139  {
140  memset((*handle), 0, sizeof(DrvContextTypeDef));
141  *handle = NULL;
142  return COMPONENT_ERROR;
143  }
144 
145  if ( driver->Init( (DrvContextTypeDef *)(*handle) ) == COMPONENT_ERROR )
146  {
147  memset((*handle), 0, sizeof(DrvContextTypeDef));
148  *handle = NULL;
149  return COMPONENT_ERROR;
150  }
151 
152  return COMPONENT_OK;
153 }
154 
155 
162 DrvStatusTypeDef BSP_GG_DeInit( void **handle )
163 {
164  DrvContextTypeDef *ctx = (DrvContextTypeDef *)(*handle);
165  GG_Drv_t *driver = NULL;
166 
167  if(ctx == NULL)
168  {
169  return COMPONENT_ERROR;
170  }
171 
172  driver = ( GG_Drv_t * )ctx->pVTable;
173 
174  if ( driver->DeInit == NULL )
175  {
176  return COMPONENT_ERROR;
177  }
178 
179  if ( driver->DeInit( ctx ) == COMPONENT_ERROR )
180  {
181  return COMPONENT_ERROR;
182  }
183 
184  memset(ctx, 0, sizeof(DrvContextTypeDef));
185 
186  *handle = NULL;
187 
188  return COMPONENT_OK;
189 }
190 
191 
192 
193 
194 
195 
203 DrvStatusTypeDef BSP_GG_IsInitialized( void *handle, uint8_t *status )
204 {
205  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
206 
207  if(ctx == NULL)
208  {
209  return COMPONENT_ERROR;
210  }
211 
212  if ( status == NULL )
213  {
214  return COMPONENT_ERROR;
215  }
216 
217  *status = ctx->isInitialized;
218 
219  return COMPONENT_OK;
220 }
221 
222 
223 
231 DrvStatusTypeDef BSP_GG_IsCombo( void *handle, uint8_t *status )
232 {
233  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
234 
235  if(ctx == NULL)
236  {
237  return COMPONENT_ERROR;
238  }
239 
240  if ( status == NULL )
241  {
242  return COMPONENT_ERROR;
243  }
244 
245  *status = ctx->isCombo;
246 
247  return COMPONENT_OK;
248 }
249 
250 
258 DrvStatusTypeDef BSP_GG_Get_WhoAmI( void *handle, uint8_t *who_am_i )
259 {
260 
261  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
262  GG_Drv_t *driver = NULL;
263 
264  if(ctx == NULL)
265  {
266  return COMPONENT_ERROR;
267  }
268 
269  driver = ( GG_Drv_t * )ctx->pVTable;
270 
271  if ( who_am_i == NULL )
272  {
273  return COMPONENT_ERROR;
274  }
275  if ( driver->Get_WhoAmI == NULL )
276  {
277  return COMPONENT_ERROR;
278  }
279  if ( driver->Get_WhoAmI( ctx, who_am_i ) == COMPONENT_ERROR )
280  {
281  return COMPONENT_ERROR;
282  }
283 
284  return COMPONENT_OK;
285 }
286 
287 
295 DrvStatusTypeDef BSP_GG_Task(void *handle, uint8_t* vm_mode)
296 {
297  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
298  GG_Drv_t *driver = NULL;
299 
300  if(ctx == NULL)
301  {
302  return COMPONENT_ERROR;
303  }
304 
305  driver = ( GG_Drv_t * )ctx->pVTable;
306 
307  if(driver->Task == NULL)
308  {
309  return COMPONENT_ERROR;
310  }
311 
312  return driver->Task( ctx, vm_mode );
313 }
314 
315 
316 
323 DrvStatusTypeDef BSP_GG_Reset(void *handle)
324 {
325  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
326  GG_Drv_t *driver = NULL;
327 
328  if(ctx == NULL)
329  {
330  return COMPONENT_ERROR;
331  }
332 
333  driver = ( GG_Drv_t * )ctx->pVTable;
334 
335  if(driver->Reset == NULL)
336  {
337  return COMPONENT_ERROR;
338  }
339 
340  return driver->Reset( ctx );
341 }
342 
343 
350 DrvStatusTypeDef BSP_GG_Stop(void *handle)
351 {
352  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
353  GG_Drv_t *driver = NULL;
354 
355  if(ctx == NULL)
356  {
357  return COMPONENT_ERROR;
358  }
359 
360  driver = ( GG_Drv_t * )ctx->pVTable;
361 
362  if(driver->Stop == NULL)
363  {
364  return COMPONENT_ERROR;
365  }
366 
367  return driver->Stop( ctx );
368 }
369 
370 
378 DrvStatusTypeDef BSP_GG_GetOCV(void *handle, uint32_t* ocv)
379 {
380  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
381  GG_Drv_t *driver = NULL;
382 
383  if(ctx == NULL)
384  {
385  return COMPONENT_ERROR;
386  }
387 
388  driver = ( GG_Drv_t * )ctx->pVTable;
389 
390  if(driver->GetOCV == NULL)
391  {
392  return COMPONENT_ERROR;
393  }
394 
395  return driver->GetOCV( ctx, ocv);
396 }
397 
398 
406 DrvStatusTypeDef BSP_GG_GetSOC(void *handle, uint32_t* soc)
407 {
408  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
409  GG_Drv_t *driver = NULL;
410 
411  if(ctx == NULL)
412  {
413  return COMPONENT_ERROR;
414  }
415 
416  driver = ( GG_Drv_t * )ctx->pVTable;
417 
418  if(driver->GetSOC == NULL)
419  {
420  return COMPONENT_ERROR;
421  }
422 
423  return driver->GetSOC( ctx, soc);
424 }
425 
426 
434 DrvStatusTypeDef BSP_GG_GetChargeValue(void *handle, uint32_t* chrgValue)
435 {
436  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
437  GG_Drv_t *driver = NULL;
438 
439  if(ctx == NULL)
440  {
441  return COMPONENT_ERROR;
442  }
443 
444  driver = ( GG_Drv_t * )ctx->pVTable;
445 
446  if(driver->GetChargeValue == NULL)
447  {
448  return COMPONENT_ERROR;
449  }
450 
451  return driver->GetChargeValue( ctx, chrgValue);
452 }
453 
454 
462 DrvStatusTypeDef BSP_GG_GetPresence(void *handle, uint32_t* presence)
463 {
464  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
465  GG_Drv_t *driver = NULL;
466 
467  if(ctx == NULL)
468  {
469  return COMPONENT_ERROR;
470  }
471 
472  driver = ( GG_Drv_t * )ctx->pVTable;
473 
474  if(driver->GetPresence == NULL)
475  {
476  return COMPONENT_ERROR;
477  }
478 
479  return driver->GetPresence( ctx, presence);
480 }
481 
482 
490 DrvStatusTypeDef BSP_GG_GetCurrent(void *handle, int32_t* current)
491 {
492  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
493  GG_Drv_t *driver = NULL;
494 
495  if(ctx == NULL)
496  {
497  return COMPONENT_ERROR;
498  }
499 
500  driver = ( GG_Drv_t * )ctx->pVTable;
501 
502  if(driver->GetCurrent == NULL)
503  {
504  return COMPONENT_ERROR;
505  }
506 
507  return driver->GetCurrent( ctx, current);
508 }
509 
510 
518 DrvStatusTypeDef BSP_GG_GetVoltage(void *handle, uint32_t* voltage)
519 {
520  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
521  GG_Drv_t *driver = NULL;
522 
523  if(ctx == NULL)
524  {
525  return COMPONENT_ERROR;
526  }
527 
528  driver = ( GG_Drv_t * )ctx->pVTable;
529 
530  if(driver->GetVoltage == NULL)
531  {
532  return COMPONENT_ERROR;
533  }
534 
535  return driver->GetVoltage( ctx, voltage);
536 }
537 
538 
546 DrvStatusTypeDef BSP_GG_GetTemperature(void *handle, int32_t* temp)
547 {
548  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
549  GG_Drv_t *driver = NULL;
550 
551  if(ctx == NULL)
552  {
553  return COMPONENT_ERROR;
554  }
555 
556  driver = ( GG_Drv_t * )ctx->pVTable;
557 
558  if(driver->GetTemperature == NULL)
559  {
560  return COMPONENT_ERROR;
561  }
562 
563  return driver->GetTemperature( ctx, temp);
564 }
565 
573 DrvStatusTypeDef BSP_GG_GetRemTime(void *handle, int32_t* remTime)
574 {
575  DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
576  GG_Drv_t *driver = NULL;
577 
578  if(ctx == NULL)
579  {
580  return COMPONENT_ERROR;
581  }
582 
583  driver = ( GG_Drv_t * )ctx->pVTable;
584 
585  if(driver->GetRemTime == NULL)
586  {
587  return COMPONENT_ERROR;
588  }
589 
590  return driver->GetRemTime( ctx, remTime);
591 }
592 
609 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
DrvStatusTypeDef BSP_GG_GetSOC(void *handle, uint32_t *soc)
Get the SOC.
DrvStatusTypeDef BSP_GG_Stop(void *handle)
Stop the gas gauge system.
DrvStatusTypeDef BSP_GG_GetPresence(void *handle, uint32_t *presence)
Get the presence.
DrvStatusTypeDef BSP_GG_IsInitialized(void *handle, uint8_t *status)
Check if the gas gauge sensor is initialized.
DrvStatusTypeDef BSP_GG_Get_WhoAmI(void *handle, uint8_t *who_am_i)
Get the WHO_AM_I ID of the gas gauge sensor.
DrvStatusTypeDef BSP_GG_GetRemTime(void *handle, int32_t *remTime)
Get the estimated remaining time.
This file contains definitions for SensorTile_gg.c firmware driver.
DrvStatusTypeDef BSP_GG_IsCombo(void *handle, uint8_t *status)
Check if the gas gauge sensor is combo.
DrvStatusTypeDef BSP_GG_GetChargeValue(void *handle, uint32_t *chrgValue)
Get the charge value.
DrvStatusTypeDef BSP_GG_GetCurrent(void *handle, int32_t *current)
Get the current.
DrvStatusTypeDef BSP_GG_Task(void *handle, uint8_t *vm_mode)
Task to read periodically data of STC3115.
DrvStatusTypeDef BSP_GG_GetVoltage(void *handle, uint32_t *voltage)
Get the voltage.
DrvStatusTypeDef BSP_GG_Init(void **handle)
Set GG Initialization.
DrvStatusTypeDef BSP_GG_GetOCV(void *handle, uint32_t *ocv)
Get the OCV.
DrvStatusTypeDef Sensor_IO_I2C_Init(void)
Configures sensor SPI interface.
Definition: SensorTile.c:274
DrvStatusTypeDef BSP_GG_GetTemperature(void *handle, int32_t *temp)
Get the temperature.
DrvStatusTypeDef BSP_GG_DeInit(void **handle)
Deinitialize a gas gauge sensor.
DrvStatusTypeDef BSP_GG_Reset(void *handle)
Reboot memory content of GG.
Generated by   doxygen 1.8.13