ISSDK  1.8
IoT Sensing Software Development Kit
mma8491q_drv.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file mma8491q_drv.c
11  * @brief The mma8491q_drv.c file implements the MMA8491 sensor driver interfaces.
12  */
13 
14 //-----------------------------------------------------------------------
15 // ISSDK Includes
16 //-----------------------------------------------------------------------
17 #include "mma8491q_drv.h"
18 
19 //-----------------------------------------------------------------------
20 // Functions
21 //-----------------------------------------------------------------------
23  ARM_DRIVER_I2C *pBus,
24  uint8_t index,
25  uint16_t sAddress)
26 {
28  MMA8491Q_STATUS_t reg = {.w = MMA8491Q_STATUS_RESERVED_MASK}; /* Set the reserved bits to 1. */
29 
30  /*! Check the input parameters. */
31  if ((pSensorHandle == NULL) || (pBus == NULL))
32  {
34  }
35 
36  pSensorHandle->deviceInfo.deviceInstance = index;
37  pSensorHandle->deviceInfo.functionParam = NULL;
38  pSensorHandle->deviceInfo.idleFunction = NULL;
39 
40  /* Since this sensor does not have who am i register, we verify Status Register Reserved bits to validate
41  * communication. */
42  status = Register_I2C_Read(pBus, &pSensorHandle->deviceInfo, sAddress, MMA8491Q_STATUS, 1, (uint8_t *)&reg);
43  if ((ARM_DRIVER_OK != status) || (MMA8491Q_STATUS_RESERVED_ZERO != reg.b.reserved))
44  {
45  pSensorHandle->isInitialized = false;
46  return SENSOR_ERROR_INIT;
47  }
48 
49  /*! Initialize the sensor handle. */
50  pSensorHandle->pCommDrv = pBus;
51  pSensorHandle->slaveAddress = sAddress;
52  pSensorHandle->isInitialized = true;
53  return SENSOR_ERROR_NONE;
54 }
55 
57  registeridlefunction_t idleTask,
58  void *userParam)
59 {
60  pSensorHandle->deviceInfo.functionParam = userParam;
61  pSensorHandle->deviceInfo.idleFunction = idleTask;
62 }
63 
65  const registerreadlist_t *pReadList,
66  uint8_t *pBuffer)
67 {
69 
70  /*! Validate for the correct handle and register read list.*/
71  if ((pSensorHandle == NULL) || (pReadList == NULL) || (pBuffer == NULL))
72  {
74  }
75 
76  /*! Check whether sensor handle is initialized before reading sensor data.*/
77  if (pSensorHandle->isInitialized != true)
78  {
79  return SENSOR_ERROR_INIT;
80  }
81 
82  /*! Parse through the read list and read the data one by one. */
83  status = Sensor_I2C_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
84  pReadList, pBuffer);
85  if (ARM_DRIVER_OK != status)
86  {
87  return SENSOR_ERROR_READ;
88  }
89 
90  return SENSOR_ERROR_NONE;
91 }
This defines the function pointers and sensor specific information.
Definition: mma8491q_drv.h:29
int32_t Sensor_I2C_Read(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, const registerreadlist_t *pReadList, uint8_t *pOutBuffer)
Read register data from a sensor.
int32_t status
int32_t Register_I2C_Read(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, uint8_t offset, uint8_t length, uint8_t *pOutBuffer)
The interface function to read a sensor register.
ARM_DRIVER_I2C * pCommDrv
Definition: mma8491q_drv.h:32
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
void MMA8491Q_I2C_SetIdleTask(mma8491q_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mma8491q_drv.c:56
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
registerDeviceInfo_t deviceInfo
Definition: mma8491q_drv.h:31
int32_t MMA8491Q_I2C_ReadData(mma8491q_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mma8491q_drv.c:64
The mma8491q_drv.h file describes the MMA8491Q driver interface and structures.
int32_t MMA8491Q_I2C_Initialize(mma8491q_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress)
The interface function to initialize the sensor.
Definition: mma8491q_drv.c:22
#define MMA8491Q_STATUS_RESERVED_MASK
Definition: mma8491q.h:70
This structure defines the Read command List.
Definition: sensor_drv.h:78
#define MMA8491Q_STATUS_RESERVED_ZERO
Definition: mma8491q.h:89
registeridlefunction_t idleFunction
Definition: sensor_drv.h:104