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