ISSDK  1.8
IoT Sensing Software Development Kit
mma9553_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 mma9553_drv.c
11  * @brief The mma9553_drv.c file implements the MMA9553L sensor driver interface.
12  */
13 
14 //-----------------------------------------------------------------------
15 // ISSDK Includes
16 //-----------------------------------------------------------------------
17 #include "gpio_driver.h"
18 #include "mma9553_drv.h"
19 #include "systick_utils.h"
20 
21 //-----------------------------------------------------------------------
22 // Global Variables
23 //-----------------------------------------------------------------------
27 
28 /*! @brief Suspend the Pedometer Application. */
29 static uint8_t SuspendPedometer[] = {0x17, 0x20, 0x05, 0x01, 0x20};
30 
31 /*! @brief Suspend the AFE Application. */
32 static uint8_t SuspendAFE[] = {0x17, 0x20, 0x07, 0x01, 0x40};
33 
34 /*! @brief Read Suspend Registers. */
35 static const uint8_t ReadSuspendRegisters[] = {0x17, 0x10, 0x04, 0x04};
36 
37 /*! @brief Write Suspend Registers (The actual value has to be updated as required). */
38 static uint8_t WriteSuspendRegisters[] = {0x17, 0x20, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00};
39 
40 //-----------------------------------------------------------------------
41 // Constants
42 //-----------------------------------------------------------------------
43 /*! @brief The Read Version Info Command. */
44 const uint8_t ReadVersionInfo[4] = {0x00, 0x00, 0x00, 0x0C};
45 
46 /*! @brief Configure MBOX for QR Data and XYZ Axes Command. */
47 const uint8_t MBoxQRDataXYZ[16] = {0x04, 0x20, 0x2C, 0x0C, 0x06, 0x13, 0x06, 0x12,
48  0x06, 0x15, 0x06, 0x14, 0x06, 0x17, 0x06, 0x16};
49 
50 /*! @brief Set Sensor to Legacy (free running) Mode Command. */
51 const uint8_t SetLegacyMode[5] = {0x18, 0x20, 0x00, 0x01, 0x10};
52 
53 /*! @brief Set Sensor to Legacy Mode with INT_O interrupt on completion of the AFE sampling. */
54 const uint8_t SetLegacyIntMode[5] = {0x18, 0x20, 0x00, 0x01, 0xB0};
55 
56 /*! @brief Set sensor to Wake Mode Command. */
57 const uint8_t WakeApplication[5] = {0x12, 0x20, 0x06, 0x01, 0x00};
58 
59 /*! @brief Command to reset all applications of the sensor. */
60 const uint8_t ResetApplication[5] = {0x17, 0x20, 0x03, 0x01, 0x01};
61 
62 /*! @brief Full-Scale Range Selections. */
63 const uint8_t SetFSRange_2g[5] = {0x06, 0x20, 0x00, 0x01, 0x40};
64 const uint8_t SetFSRange_4g[5] = {0x06, 0x20, 0x00, 0x01, 0x80};
65 const uint8_t SetFSRange_8g[5] = {0x06, 0x20, 0x00, 0x01, 0x00};
66 
67 /*! @brief Sample Rate Commands. */
68 const uint8_t SetSampleRate_488Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x07};
69 const uint8_t SetSampleRate_244Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x08};
70 const uint8_t SetSampleRate_122Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x09};
71 const uint8_t SetSampleRate_61Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x0A};
72 const uint8_t SetSampleRate_30Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x0B};
73 const uint8_t SetSampleRate_15Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x0C};
74 const uint8_t SetSampleRate_7Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x0D};
75 const uint8_t SetSampleRate_3Hz[5] = {0x06, 0x20, 0x0C, 0x01, 0x0E};
76 
77 /*! @brief AFE Priority Commands. */
78 const uint8_t SetAFEPriority_for488Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD7};
79 const uint8_t SetAFEPriority_for224Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD6};
80 const uint8_t SetAFEPriority_for122Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD5};
81 const uint8_t SetAFEPriority_for61Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD4};
82 const uint8_t SetAFEPriority_for30Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD3};
83 const uint8_t SetAFEPriority_for15Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD2};
84 const uint8_t SetAFEPriority_for7Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD1};
85 const uint8_t SetAFEPriority_for3Hz[5] = {0x01, 0x20, 0x32, 0x01, 0xD0};
86 
87 /*! @brief MBox Priority Commands. */
88 const uint8_t SetMBoxPriority_for488Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD7};
89 const uint8_t SetMBoxPriority_for244Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD6};
90 const uint8_t SetMBoxPriority_for122Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD5};
91 const uint8_t SetMBoxPriority_for61Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD4};
92 const uint8_t SetMBoxPriority_for30Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD3};
93 const uint8_t SetMBoxPriority_for15Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD2};
94 const uint8_t SetMBoxPriority_for7Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD1};
95 const uint8_t SetMBoxPriority_for3Hz[5] = {0x01, 0x20, 0x30, 0x01, 0xD0};
96 
97 /*! @brief Command to Read Pedometer Data. */
98 const uint8_t ReadPedometerData[4] = {0x15, 0x30, 0x00, 0x0C};
99 
102 
104  {ReadSuspendRegisters, 0, sizeof(ReadSuspendRegisters)}, __END_WRITE_CMD__};
105 
106 const registercommandlist_t MMA9553_ActivateCommands[] = {{WriteSuspendRegisters, 0, sizeof(WriteSuspendRegisters)},
107  {WakeApplication, 0, sizeof(WakeApplication)},
108  {SetLegacyMode, 0, sizeof(SetLegacyMode)},
110 
112  {SuspendAFE, 0, sizeof(SuspendAFE)}, {SuspendPedometer, 0, sizeof(SuspendPedometer)}, __END_WRITE_CMD__};
113 
116 
117 //-----------------------------------------------------------------------
118 // Functions
119 //-----------------------------------------------------------------------
120 void MMA9553_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
121 {
122  spiCmdParams_t *pSlaveCmd = pCmdOut;
123 
124  uint8_t *pWBuff = mma9553_spiRead_CmdBuffer;
125  uint8_t *pRBuff = mma9553_spiRead_DataBuffer;
126 
127  /* Formatting for Read command of MMA9553 SENSOR. */
128  *(pWBuff) =
129  (offset & 0x7F) << 1; /* offset is the internal register address of the sensor at which write is performed. */
130 
131  /* Create the slave read command. */
132  pSlaveCmd->size = size + MMA9553_SPI_CMD_LEN;
133  pSlaveCmd->pWriteBuffer = pWBuff;
134  pSlaveCmd->pReadBuffer = pRBuff;
135 }
136 
137 void MMA9553_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer)
138 {
139  spiCmdParams_t *pSlaveCmd = pCmdOut;
140 
141  uint8_t *pWBuff = mma9553_spiWrite_CmdDataBuffer;
142  uint8_t *pRBuff = mma9553_spiWrite_CmdDataBuffer + size + MMA9553_SPI_CMD_LEN;
143 
144  /* Formatting for Write command of MMA9553 SENSOR. */
145  *(pWBuff) =
146  (offset | 0x40) << 1; /* offset is the internal register address of the sensor at which write is performed. */
147 
148  /* Copy the slave write command */
149  memcpy(pWBuff + MMA9553_SPI_CMD_LEN, pWritebuffer, size);
150 
151  /* Create the slave command. */
152  pSlaveCmd->size = size + MMA9553_SPI_CMD_LEN;
153  pSlaveCmd->pWriteBuffer = pWBuff;
154  pSlaveCmd->pReadBuffer = pRBuff;
155 }
156 
158  mma9553_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, void *pReset)
159 {
160  int32_t status;
161  uint8_t cmdRespHdr[MMA9553_HDR_SIZE] = {0};
163 
164  /*! Check the input parameters. */
165  if (pSensorHandle == NULL || pBus == NULL || pSlaveSelect == NULL || pReset == NULL)
166  {
168  }
169 
170  /*! Initialize the sensor handle. */
171  pSensorHandle->pCommDrv = pBus;
174  pSensorHandle->slaveParams.pTargetSlavePinID = pSlaveSelect;
175  pSensorHandle->slaveParams.spiCmdLen = MMA9553_SPI_CMD_LEN;
177 
178  pSensorHandle->deviceInfo.deviceInstance = index;
179  pSensorHandle->deviceInfo.functionParam = NULL;
180  pSensorHandle->deviceInfo.idleFunction = NULL;
181 
182  /* Initialize the Slave Select and reset Pins. */
183  pGPIODriver->pin_init(pSlaveSelect, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
184  pGPIODriver->pin_init(pReset, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
185 
186  /* Pull down SS and Reset */
187  pGPIODriver->clr_pin(pSlaveSelect);
188  pGPIODriver->set_pin(pReset);
189 
190  BOARD_DELAY_ms(1); /* Wait for Part to Complete Reset */
191  pGPIODriver->clr_pin(pReset);
192 
193  BOARD_DELAY_ms(2); /* Wait for Part to Initialize in SPI Mode */
194  pGPIODriver->set_pin(pSlaveSelect);
195 
196  /* Verify if the SPI connection by writing command to fetch Version Info and waiting for a sufficient duration.
197  * A valid response COCO and length fields indicate command acceptance and by nature Sensor Identity. */
198  Register_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams, 0,
200  BOARD_DELAY_ms(1);
201  status = Register_SPI_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams, 0,
202  sizeof(cmdRespHdr), cmdRespHdr);
203  if (ARM_DRIVER_OK != status || (cmdRespHdr[1] & 0x80) != 0x80 || cmdRespHdr[2] != ReadVersionInfo[3] ||
204  cmdRespHdr[3] != ReadVersionInfo[3])
205  {
206  pSensorHandle->isInitialized = false;
207  return SENSOR_ERROR_INIT;
208  }
209 
210  /* Send the Initialize commands to the Sensor. */
211  status = Sensor_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
212  MMA9553_InitializeCommand, MMA9553_COCO_ERROR_MASK);
213  if (ARM_DRIVER_OK != status)
214  {
215  return SENSOR_ERROR_WRITE;
216  }
217 
218  pSensorHandle->isInitialized = true;
219  return SENSOR_ERROR_NONE;
220 }
221 
223  registeridlefunction_t idleTask,
224  void *userParam)
225 {
226  pSensorHandle->deviceInfo.functionParam = userParam;
227  pSensorHandle->deviceInfo.idleFunction = idleTask;
228 }
229 
231 {
232  int32_t status;
233  uint8_t standbyRegister[MMA9553_HDR_SIZE + STANDBY_REG_SIZE];
234 
235  /*! Validate for the correct handle and register write list.*/
236  if ((pSensorHandle == NULL) || (pCommandList == NULL))
237  {
239  }
240 
241  /*! Check whether sensor handle is initialized before applying configuration.*/
242  if (pSensorHandle->isInitialized != true)
243  {
244  return SENSOR_ERROR_INIT;
245  }
246 
247  /* Write command to fetch Standby register. */
248  status = Sensor_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
249  MMA9553_ReadSuspendRegistersCommand, MMA9553_COCO_ERROR_MASK);
250  if (ARM_DRIVER_OK != status)
251  {
252  return SENSOR_ERROR_WRITE;
253  }
254 
255  /* Read the standby register values. */
256  status = Register_SPI_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams, 0,
257  sizeof(standbyRegister), standbyRegister);
258  if (ARM_DRIVER_OK != status)
259  {
260  return SENSOR_ERROR_READ;
261  }
262 
263  /* Set Bits for AFE and Pedometer Standby. */
264  SuspendAFE[MMA9553_HDR_SIZE] |= standbyRegister[MMA9553_HDR_SIZE + 3];
265  SuspendPedometer[MMA9553_HDR_SIZE] |= standbyRegister[MMA9553_HDR_SIZE + 1];
266 
267  /* Put the sensor to Standby Mode. */
268  status = Sensor_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
269  MMA9553_StandbyCommands, MMA9553_COCO_ERROR_MASK);
270  if (ARM_DRIVER_OK != status)
271  {
272  return SENSOR_ERROR_WRITE;
273  }
274 
275  /* Send the requested commands to the Sensor. */
276  status = Sensor_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
277  pCommandList, MMA9553_COCO_ERROR_MASK);
278  if (ARM_DRIVER_OK != status)
279  {
280  return SENSOR_ERROR_WRITE;
281  }
282 
283  /* Put the sensor to out of standby Mode. */
284  memcpy(WriteSuspendRegisters + MMA9553_HDR_SIZE, standbyRegister + MMA9553_HDR_SIZE, STANDBY_REG_SIZE);
285  status = Sensor_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
286  MMA9553_ActivateCommands, MMA9553_COCO_ERROR_MASK);
287  if (ARM_DRIVER_OK != status)
288  {
289  return SENSOR_ERROR_WRITE;
290  }
291 
292  return SENSOR_ERROR_NONE;
293 }
294 
296  const registercommandlist_t *pCommandList,
297  const registerreadlist_t *pResponseList,
298  uint8_t *pBuffer)
299 {
300  int32_t status;
301 
302  /*! Validate for the correct handle and command list.*/
303  if (pSensorHandle == NULL || (pCommandList == NULL && pResponseList == NULL))
304  {
306  }
307 
308  /*! Check whether sensor handle is initialized before reading sensor data.*/
309  if (pSensorHandle->isInitialized != true)
310  {
311  return SENSOR_ERROR_INIT;
312  }
313 
314  if (pCommandList != NULL)
315  { /* Write command to fetch configuration. */
316  status = Sensor_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
317  pCommandList, MMA9553_COCO_ERROR_MASK);
318  if (ARM_DRIVER_OK != status)
319  {
320  return SENSOR_ERROR_WRITE;
321  }
322  }
323 
324  /*! Parse through the read list and read the data one by one. */
325  if (pResponseList != NULL)
326  {
327  status = Sensor_SPI_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
328  pResponseList, pBuffer);
329  if (ARM_DRIVER_OK != status)
330  {
331  return SENSOR_ERROR_READ;
332  }
333  }
334 
335  return SENSOR_ERROR_NONE;
336 }
337 
339 {
340  int32_t status;
341 
342  if (pSensorHandle == NULL)
343  {
345  }
346 
347  /*! Check whether sensor handle is initialized before triggering sensor reset.*/
348  if (pSensorHandle->isInitialized != true)
349  {
350  return SENSOR_ERROR_INIT;
351  }
352 
353  /*! Trigger sensor device reset.*/
354  status = Sensor_SPI_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, &pSensorHandle->slaveParams,
355  MMA9553_ResetCommand, MMA9553_COCO_ERROR_MASK);
356  if (ARM_DRIVER_OK != status)
357  {
358  return SENSOR_ERROR_WRITE;
359  }
360  else
361  {
362  /*! De-initialize sensor handle. */
363  pSensorHandle->isInitialized = false;
364  }
365 
366  return SENSOR_ERROR_NONE;
367 }
368 
370  ARM_DRIVER_I2C *pBus,
371  uint8_t index,
372  uint16_t sAddress)
373 {
374  int32_t status;
375  uint8_t cmdRespHdr[MMA9553_HDR_SIZE] = {0};
376 
377  /*! Check the input parameters. */
378  if ((pSensorHandle == NULL) || (pBus == NULL))
379  {
381  }
382 
383  pSensorHandle->deviceInfo.deviceInstance = index;
384  pSensorHandle->deviceInfo.functionParam = NULL;
385  pSensorHandle->deviceInfo.idleFunction = NULL;
386 
387  /* Verify if the I2C connection by writing command to fetch Version Info and waiting for a sufficient duration.
388  * A valid response COCO and length fields indicate command acceptance and by nature Sensor Identity. */
389  Register_I2C_BlockWrite(pBus, &pSensorHandle->deviceInfo, sAddress, 0, ReadVersionInfo, sizeof(ReadVersionInfo));
390  BOARD_DELAY_ms(1);
391  status = Register_I2C_Read(pBus, &pSensorHandle->deviceInfo, sAddress, 0, sizeof(cmdRespHdr), cmdRespHdr);
392  if (ARM_DRIVER_OK != status || (cmdRespHdr[1] & 0x80) != 0x80 || cmdRespHdr[2] != ReadVersionInfo[3] ||
393  cmdRespHdr[3] != ReadVersionInfo[3])
394  {
395  pSensorHandle->isInitialized = false;
396  return SENSOR_ERROR_INIT;
397  }
398 
399  /* Send the Initialize commands to the Sensor. */
400  status = Sensor_I2C_BlockWrite(pBus, &pSensorHandle->deviceInfo, sAddress, MMA9553_InitializeCommand,
402  if (ARM_DRIVER_OK != status)
403  {
404  pSensorHandle->isInitialized = false;
405  return SENSOR_ERROR_WRITE;
406  }
407 
408  pSensorHandle->pCommDrv = pBus;
409  pSensorHandle->slaveAddress = sAddress;
410  pSensorHandle->isInitialized = true;
411  return SENSOR_ERROR_NONE;
412 }
413 
415  registeridlefunction_t idleTask,
416  void *userParam)
417 {
418  pSensorHandle->deviceInfo.functionParam = userParam;
419  pSensorHandle->deviceInfo.idleFunction = idleTask;
420 }
421 
423 {
424  int32_t status;
425  uint8_t standbyRegister[MMA9553_HDR_SIZE + STANDBY_REG_SIZE];
426 
427  /* Validate for the correct handle.*/
428  if ((pSensorHandle == NULL) || (pCommandList == NULL))
429  {
431  }
432 
433  /*! Check whether sensor handle is initialized before applying configuration.*/
434  if (pSensorHandle->isInitialized != true)
435  {
436  return SENSOR_ERROR_INIT;
437  }
438 
439  /* Write command to fetch Standby register. */
440  status = Sensor_I2C_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
441  MMA9553_ReadSuspendRegistersCommand, MMA9553_COCO_ERROR_MASK);
442  if (ARM_DRIVER_OK != status)
443  {
444  return SENSOR_ERROR_WRITE;
445  }
446 
447  /* Read the standby register values. */
448  status = Register_I2C_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress, 0,
449  sizeof(standbyRegister), standbyRegister);
450  if (ARM_DRIVER_OK != status)
451  {
452  return SENSOR_ERROR_READ;
453  }
454 
455  /* Set Bits for AFE and Pedometer Standby. */
456  SuspendAFE[MMA9553_HDR_SIZE] |= standbyRegister[MMA9553_HDR_SIZE + 3];
457  SuspendPedometer[MMA9553_HDR_SIZE] |= standbyRegister[MMA9553_HDR_SIZE + 1];
458 
459  /* Put the sensor to Standby Mode. */
460  status = Sensor_I2C_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
461  MMA9553_StandbyCommands, MMA9553_COCO_ERROR_MASK);
462  if (ARM_DRIVER_OK != status)
463  {
464  return SENSOR_ERROR_WRITE;
465  }
466 
467  /* Send the requested commands to the Sensor. */
468  status = Sensor_I2C_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
469  pCommandList, MMA9553_COCO_ERROR_MASK);
470  if (ARM_DRIVER_OK != status)
471  {
472  return SENSOR_ERROR_WRITE;
473  }
474 
475  /* Put the sensor to out of standby Mode. */
476  memcpy(WriteSuspendRegisters + MMA9553_HDR_SIZE, standbyRegister + MMA9553_HDR_SIZE, STANDBY_REG_SIZE);
477  status = Sensor_I2C_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
478  MMA9553_ActivateCommands, MMA9553_COCO_ERROR_MASK);
479  if (ARM_DRIVER_OK != status)
480  {
481  return SENSOR_ERROR_WRITE;
482  }
483 
484  return SENSOR_ERROR_NONE;
485 }
486 
488  const registercommandlist_t *pCommandList,
489  const registerreadlist_t *pResponseList,
490  uint8_t *pBuffer)
491 {
492  int32_t status;
493 
494  /*! Validate for the correct handle and register read list.*/
495  if (pSensorHandle == NULL || (pCommandList == NULL && pResponseList == NULL))
496  {
498  }
499 
500  /*! Check whether sensor handle is initialized before reading sensor data.*/
501  if (pSensorHandle->isInitialized != true)
502  {
503  return SENSOR_ERROR_INIT;
504  }
505 
506  if (pCommandList != NULL)
507  { /* Write command to fetch configuration. */
508  status = Sensor_I2C_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
509  pCommandList, MMA9553_COCO_ERROR_MASK);
510  if (ARM_DRIVER_OK != status)
511  {
512  return SENSOR_ERROR_WRITE;
513  }
514  }
515 
516  if (pResponseList != NULL)
517  { /* Parse through the read list and read the data one by one */
518  status = Sensor_I2C_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
519  pResponseList, pBuffer);
520  if (ARM_DRIVER_OK != status)
521  {
522  return SENSOR_ERROR_READ;
523  }
524  }
525 
526  return SENSOR_ERROR_NONE;
527 }
528 
530 {
531  int32_t status;
532 
533  if (pSensorHandle == NULL)
534  {
536  }
537 
538  /*! Check whether sensor handle is initialized before triggering sensor reset.*/
539  if (pSensorHandle->isInitialized != true)
540  {
541  return SENSOR_ERROR_INIT;
542  }
543 
544  /* Reset the device to put it into default state. */
545  status = Sensor_I2C_BlockWrite(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
546  MMA9553_ResetCommand, MMA9553_COCO_ERROR_MASK);
547  if (ARM_DRIVER_OK != status)
548  {
549  return SENSOR_ERROR_WRITE;
550  }
551  else
552  {
553  /*! De-initialize sensor handle. */
554  pSensorHandle->isInitialized = false;
555  }
556 
557  return SENSOR_ERROR_NONE;
558 }
#define MMA9553_HDR_SIZE
Size of fixed header bytes in sensor commands.
Definition: mma9553.h:14
void(* set_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:46
uint32_t size
const uint8_t SetLegacyIntMode[5]
Set Sensor to Legacy Mode with INT_O interrupt on completion of the AFE sampling. ...
Definition: mma9553_drv.c:54
const uint8_t SetSampleRate_3Hz[5]
Definition: mma9553_drv.c:75
const uint8_t SetSampleRate_15Hz[5]
Definition: mma9553_drv.c:73
This defines the sensor specific information for I2C.
Definition: mma9553_drv.h:44
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.
const uint8_t ResetApplication[5]
Command to reset all applications of the sensor.
Definition: mma9553_drv.c:60
const uint8_t SetMBoxPriority_for488Hz[5]
MBox Priority Commands.
Definition: mma9553_drv.c:88
const registercommandlist_t MMA9553_StandbyCommands[]
Definition: mma9553_drv.c:111
int32_t status
void MMA9553_I2C_SetIdleTask(mma9553_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mma9553_drv.c:414
const uint8_t WakeApplication[5]
Set sensor to Wake Mode Command.
Definition: mma9553_drv.c:57
const registercommandlist_t MMA9553_ResetCommand[]
Definition: mma9553_drv.c:114
int32_t MMA9553_SPI_Configure(mma9553_spi_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList)
The interface function to configure he sensor.
Definition: mma9553_drv.c:230
GENERIC_DRIVER_GPIO * pGPIODriver
const uint8_t SetLegacyMode[5]
Set Sensor to Legacy (free running) Mode Command.
Definition: mma9553_drv.c:51
#define MMA9553_SS_ACTIVE_VALUE
Is the Slave Select Pin Active Low or High.
Definition: mma9553_drv.h:85
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.
void BOARD_DELAY_ms(uint32_t delay_ms)
Function to insert delays.
Definition: systick_utils.c:81
This structure defines the Block command List.
Definition: sensor_drv.h:87
This defines the sensor specific information for SPI.
Definition: mma9553_drv.h:33
const uint8_t SetFSRange_8g[5]
Definition: mma9553_drv.c:65
const registercommandlist_t MMA9553_ActivateCommands[]
Definition: mma9553_drv.c:106
int32_t MMA9553_SPI_Initialize(mma9553_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, void *pReset)
The interface function to initialize the sensor.
Definition: mma9553_drv.c:157
const uint8_t SetAFEPriority_for61Hz[5]
Definition: mma9553_drv.c:81
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:38
const uint8_t SetMBoxPriority_for3Hz[5]
Definition: mma9553_drv.c:95
int32_t Sensor_I2C_BlockWrite(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, const registercommandlist_t *pCommandList, uint8_t error_mask)
Write commands to a sensor.
Definition: sensor_io_i2c.c:24
const uint8_t MBoxQRDataXYZ[16]
Configure MBOX for QR Data and XYZ Axes Command.
Definition: mma9553_drv.c:47
const uint8_t SetMBoxPriority_for122Hz[5]
Definition: mma9553_drv.c:90
void(* clr_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:47
int32_t MMA9553_I2C_Configure(mma9553_i2c_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList)
The interface function to configure he sensor.
Definition: mma9553_drv.c:422
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
const uint8_t SetSampleRate_122Hz[5]
Definition: mma9553_drv.c:70
The mma9553_drv.h file describes the MMA9553L driver interface and structures.
int32_t Sensor_SPI_Read(ARM_DRIVER_SPI *pCommDrv, registerDeviceInfo_t *devInfo, void *pReadParams, const registerreadlist_t *pReadList, uint8_t *pOutBuffer)
Read register data from a sensor.
const uint8_t SetAFEPriority_for7Hz[5]
Definition: mma9553_drv.c:84
const uint8_t SetMBoxPriority_for7Hz[5]
Definition: mma9553_drv.c:94
const uint8_t SetMBoxPriority_for15Hz[5]
Definition: mma9553_drv.c:93
const uint8_t SetMBoxPriority_for61Hz[5]
Definition: mma9553_drv.c:91
const uint8_t ReadPedometerData[4]
Command to Read Pedometer Data.
Definition: mma9553_drv.c:98
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
fpSpiReadPreprocessFn_t pReadPreprocessFN
The SPI Slave Transfer Command Params SDK2.0 Driver.
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:177
const uint8_t SetMBoxPriority_for244Hz[5]
Definition: mma9553_drv.c:89
const registercommandlist_t MMA9553_ReadSuspendRegistersCommand[]
Definition: mma9553_drv.c:103
int32_t MMA9553_I2C_CommandResponse(mma9553_i2c_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList, const registerreadlist_t *pResponseList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mma9553_drv.c:487
const uint8_t SetSampleRate_30Hz[5]
Definition: mma9553_drv.c:72
const uint8_t SetAFEPriority_for122Hz[5]
Definition: mma9553_drv.c:80
registerDeviceInfo_t deviceInfo
Definition: mma9553_drv.h:35
const uint8_t SetSampleRate_61Hz[5]
Definition: mma9553_drv.c:71
#define MMA9553_SPI_MAX_MSG_SIZE
The MAX size of SPI message.
Definition: mma9553_drv.h:77
#define __END_WRITE_CMD__
Definition: sensor_drv.h:57
const uint8_t ReadVersionInfo[4]
The Read Version Info Command.
Definition: mma9553_drv.c:44
spiSlaveSpecificParams_t slaveParams
Definition: mma9553_drv.h:38
const uint8_t SetAFEPriority_for224Hz[5]
Definition: mma9553_drv.c:79
const uint8_t SetSampleRate_488Hz[5]
Sample Rate Commands.
Definition: mma9553_drv.c:68
const uint8_t SetSampleRate_244Hz[5]
Definition: mma9553_drv.c:69
int32_t Sensor_SPI_BlockWrite(ARM_DRIVER_SPI *pCommDrv, registerDeviceInfo_t *devInfo, void *pWriteParams, const registercommandlist_t *pCommandList, uint8_t error_mask)
Write commands to a sensor.
Definition: sensor_io_spi.c:24
#define STANDBY_REG_SIZE
Size of Standby Registers.
Definition: mma9553.h:20
void MMA9553_SPI_SetIdleTask(mma9553_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
Definition: mma9553_drv.c:222
int32_t MMA9553_I2C_Initialize(mma9553_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress)
The interface function to initialize the sensor.
Definition: mma9553_drv.c:369
ARM_DRIVER_SPI * pCommDrv
Definition: mma9553_drv.h:36
const uint8_t SetAFEPriority_for3Hz[5]
Definition: mma9553_drv.c:85
void MMA9553_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer)
The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
Definition: mma9553_drv.c:137
int32_t Register_SPI_BlockWrite(ARM_DRIVER_SPI *pCommDrv, registerDeviceInfo_t *devInfo, void *pWriteParams, uint8_t offset, const uint8_t *pBuffer, uint8_t bytesToWrite)
The interface function to block write to a sensor register.
int32_t Register_I2C_BlockWrite(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, uint8_t offset, const uint8_t *pBuffer, uint8_t bytesToWrite)
The interface function to write a sensor register.
uint8_t mma9553_spiRead_CmdBuffer[MMA9553_SPI_MAX_MSG_SIZE]
Definition: mma9553_drv.c:24
int32_t MMA9553_SPI_CommandResponse(mma9553_spi_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList, const registerreadlist_t *pResponseList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mma9553_drv.c:295
const uint8_t SetMBoxPriority_for30Hz[5]
Definition: mma9553_drv.c:92
void MMA9553_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: mma9553_drv.c:120
fpSpiWritePreprocessFn_t pWritePreprocessFN
const uint8_t SetSampleRate_7Hz[5]
Definition: mma9553_drv.c:74
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
Definition: Driver_GPIO.h:41
const uint8_t SetAFEPriority_for30Hz[5]
Definition: mma9553_drv.c:82
This structure defines the Read command List.
Definition: sensor_drv.h:78
const uint8_t SetAFEPriority_for488Hz[5]
AFE Priority Commands.
Definition: mma9553_drv.c:78
#define MMA9553_COCO_ERROR_MASK
The Error Bit Mask in COCO Byte.
Definition: mma9553_drv.h:73
ARM Systick Utilities.
const uint8_t SetFSRange_2g[5]
Full-Scale Range Selections.
Definition: mma9553_drv.c:63
uint8_t mma9553_spiRead_DataBuffer[MMA9553_SPI_MAX_MSG_SIZE]
Definition: mma9553_drv.c:25
#define MMA9553_SPI_CMD_LEN
The size of the Sensor specific SPI Header.
Definition: mma9553_drv.h:81
ARM_DRIVER_I2C * pCommDrv
Definition: mma9553_drv.h:47
registerDeviceInfo_t deviceInfo
Definition: mma9553_drv.h:46
const uint8_t SetFSRange_4g[5]
Definition: mma9553_drv.c:64
const registercommandlist_t MMA9553_InitializeCommand[]
Definition: mma9553_drv.c:100
uint8_t mma9553_spiWrite_CmdDataBuffer[MMA9553_SPI_MAX_MSG_SIZE]
Definition: mma9553_drv.c:26
int32_t Register_SPI_Read(ARM_DRIVER_SPI *pCommDrv, registerDeviceInfo_t *devInfo, void *pReadParams, uint8_t offset, uint8_t length, uint8_t *pOutBuffer)
The interface function to read a sensor register.
int32_t MMA9553_I2C_DeInit(mma9553_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mma9553_drv.c:529
registeridlefunction_t idleFunction
Definition: sensor_drv.h:104
int32_t MMA9553_SPI_DeInit(mma9553_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mma9553_drv.c:338
const uint8_t SetAFEPriority_for15Hz[5]
Definition: mma9553_drv.c:83