ISF  2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
fsl_mma8491q_i2c_3D_accel.c
Go to the documentation of this file.
1 /**
2  * @file fsl_mma8491q_i2c_3D_accel.c
3  * @brief The \b fsl_mma8491q_i2c_3D_accel.c contains the MMA8491Q Accelerometer family routine Set
4  * implementations. Freescale supports several families of 3-axis intelligent accelerometers
5  * with overlapping register definitions and feature sets. This file implements a sensor adapter
6  * for this part families.
7  *
8  * @copyright Copyright (c) 2015, Freescale Semiconductor, Inc.
9  */
10 
11 #include "mma8491q.h"
12 #include "isf_devmsg.h"
13 #include "isf_sensors.h"
16 //This adapter works only with 4 GPIO component support.
17 #include "SensorEnable.h"
18 #include "OutX.h"
19 #include "OutY.h"
20 #include "OutZ.h"
21 
22 /*
23  * Public externally declared functions
24  */
25 // This is used for a one time call-back to delay sensor data reads after EN =1 is set.
26 #define T_ON_8491Q_MICROSECONDS (700)
27 
28 /*
29  * Formats the MMA8491Q sensor data according to the specification and returns
30  * the destination data in the form MSB,LSB, for two bytes in one 16-bit type
31  */
32 #define mma8491q_xyz_format(destination, msb, lsb) destination = (((uint16)msb) << 8) | lsb;
33 
34 // Sensor EN pin.
35 const uint32_t en_pin = J199_3;
36 const uint32_t x_out_pin = J1_5;
37 const uint32_t y_out_pin = J1_5;
38 const uint32_t z_out_pin = J1_5;
39 
40 // Check Sensor who am I value.
41 void mma8491q_CheckId(int32_t *status, void* pSensorHandle);
42 
43 // Conversion factors for supported Data Types.
44 #define MMA8491Q_ACCEL_FLOAT_CONVERSION_FACTOR 0.000244
45 #define MMA8491Q_ACCEL_FIXED_CONVERSION_FACTOR 16
46 
47 // Converter routines for the supported data types.
48 static isf_dsa_status_t float_accel3d_converter(mma8491q_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma8491q_DataBuffer_t *nativeSample, void *vpConvertedSample);
49 static isf_dsa_status_t fixed_accel3d_converter(mma8491q_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma8491q_DataBuffer_t *nativeSample, void *vpConvertedSample);
50 
51 // routine to get the accelerometer data from the sensor
53 
54 // declare a static sensor mode.
56 
57 //Since for this Sensor we need to read data after a certain delay, create a holder for the additional callback.
58 static bm_callback_token_t token_cb_Read_Data;
59 
62 
63 // This is the MMA8491Q accelerometer adapter initialization routine.
65 {
66  isf_status_t retStat;
67 
68  // Check that the sensor handle is valid.
69  if( NULL == pSensorHandle)
70  {
71  return DSA_ERR_PARAM;
72  }
73 
74  // Check if the sensor is available, already initialized.
75  if(pSensorHandle->adapterStatus > DSA_STATE_NOT_INITIALIZED)
76  {
77  return DSA_ERR_INITIALIZE;
78  }
79 
80  // Allocate the adapter specific memory for the descriptor and cast a direct pointer to it.
81  //pSensorHandle->pDeviceDescriptor = (DeviceDescriptor_t *)_lwmem_alloc_system_zero(sizeof(DeviceDescriptor_t));
82  pSensorHandle->pDeviceDescriptor = (DeviceDescriptor_t *)OSA_MemAllocZero(sizeof(DeviceDescriptor_t));
83 
84  // Create helper reference pointers into the descriptor.
85  DeviceDescriptor_t *pDeviceDescriptor = pSensorHandle->pDeviceDescriptor;
86  if(NULL == pDeviceDescriptor)
87  {
88  return DSA_ERR_INITIALIZE;
89  }
90 
91  // Allocate the current sample data buffer and initialize it.
92  //pDeviceDescriptor->pCurrentSample = _lwmem_alloc_system_zero(sizeof(mma8491q_DataBuffer_t));
93  pDeviceDescriptor->pCurrentSample = OSA_MemAllocZero(sizeof(mma8491q_DataBuffer_t));
94  mma8491q_DataBuffer_t *pCurrentSampleBuffer = (mma8491q_DataBuffer_t *)pDeviceDescriptor->pCurrentSample;
95  pCurrentSampleBuffer->timestamp = 0;
96  pCurrentSampleBuffer->accel[0] = 0;
97  pCurrentSampleBuffer->accel[1] = 0;
98  pCurrentSampleBuffer->accel[2] = 0;
99  pCurrentSampleBuffer->xOut = 0;
100  pCurrentSampleBuffer->yOut = 0;
101  pCurrentSampleBuffer->zOut = 0;
102 
103  dm_ChannelDescriptor_t *pChannelDescriptor = &pDeviceDescriptor->cDescriptor;
104 
105  // Initialize the channel.
106  if(ISF_SUCCESS != dm_channel_init(pSensorHandle->pSensorStaticConfig->channelId, pChannelDescriptor))
107  {
108  return DSA_ERR_INITIALIZE;
109  }
110 
111  // Start the bus.
112  if(ISF_SUCCESS != dm_channel_start(pChannelDescriptor))
113  {
114  return DSA_ERR_INITIALIZE;
115  }
116 
117  // Get the channel state to check if it is ready to use.
118  if(COMM_STATE_OK != dm_channel_get_state(pChannelDescriptor))
119  {
120  return DSA_ERR_INITIALIZE;
121  }
122 
123  // Turn on Plutino Enable so that I2C communication is active for RLI etc.
124  GPIO_DRV_SetPinOutput(en_pin);
125 
126  // takes 900usec to enable the I2C bus
127  OSA_TimeDelay(1);
128 
129  // Open the device and get the device handler.
130  if(ISF_SUCCESS != dm_device_open(pChannelDescriptor, (void *)pSensorHandle->pSensorStaticConfig->commInfo, &pDeviceDescriptor->deviceHandle))
131  {
132  return DSA_ERR_INITIALIZE;
133  }
134 
135  // Query the sensor to validate Device Messaging initialization and the sensor identity.
136  mma8491q_CheckId(&retStat,pSensorHandle);
137  if(ISF_SUCCESS != retStat)
138  {
139  return DSA_ERR_INITIALIZE;
140  }
141 
142  // Set the adapter state to be initialized.
143  pSensorHandle->adapterStatus = DSA_STATE_INITIALIZED;
144 
145  // Create a semaphore to synchronize the device descriptor across tasks
146  //if(kStatus_OSA_Success != _lwsem_create(&pDeviceDescriptor->deviceSemaphore, 1))
147  if(kStatus_OSA_Success != OSA_SemaCreate(&pDeviceDescriptor->deviceSemaphore, 1))
148  {
149  return DSA_ERR_INITIALIZE;
150  }
151 
152  pDeviceDescriptor->skipFramecnt = 0;
153 
154  return ISF_SUCCESS;
155 }
156 
157 // This is the MMA8491Q Accelerometer adapter settings validation routine.
159 { // Check the input arguments.
160  if((NULL == pSensorHandle) || (NULL == pSensorSettings))
161  {
162  return DSA_ERR_PARAM;
163  }
164 
165  return ISF_SUCCESS;
166 }
167 
168 // This is the MMA8491Q accelerometer adapter settings configuration
170 { // Check the input arguments.
171  if((NULL == pSensorHandle) || (NULL == pSensorSettings))
172  {
173  return DSA_ERR_PARAM;
174  }
175 
177  DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*)(pSensorHandle->pDeviceDescriptor);
178 
179  // Check the device descriptor, sensor specific settings.
180  if(NULL == pDeviceDescriptor)
181  {
182  return retStat;
183  }
184 
185  // Lock the device descriptor.
186  //_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0);
187  OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
188 
189  // Check the driver state.
190  if(DSA_STATE_INITIALIZED > pSensorHandle->adapterStatus)
191  {
192  goto unlockdescriptor;
193  }
194 
195  // User Notice: This is a required function call. If it is not here, there may be conflicts, data loss,
196  // or any number of undesirable things may occur.
197  if(ISF_SUCCESS != dm_channel_acquire_lock(&pDeviceDescriptor->cDescriptor, 0))
198  {
199  goto unlockchannel;
200  }
201 
202  /* Initialize the Sensor state machine to start from SHUTDOWN. */
204 
205  // Register the periodic callback function with the Bus Manager.
206  // This is callback 1 which establishes the sample rate up to 800 Hz for the MMA8491Q to enable the sensor
207  pDeviceDescriptor->token = bm_register_periodic_callback(pSensorSettings->nSamplePeriod,
209  if(BM_ERROR & pDeviceDescriptor->token) // Check for Bus Manager error and return on failure.
210  {
211  goto unlockchannel;
212  }
213 
214  // This is the callback 2 which will be OneShot to collect data and disable the sensor.
217  if(BM_ERROR & token_cb_Read_Data) // Check for Bus Manager error and return on failure.
218  {
219  goto unlockchannel;
220  }
221 
222  //Store the configured settings
223  pSensorHandle->controlData.sensorSettings = *pSensorSettings;
224 
225  // Set the adapter to indicate fully configured.
227  retStat = ISF_SUCCESS;
228 
229 unlockchannel:
230  // Unlock the channel.
231  // The explicit lock must be released when the configuration is done allowing the bus to be used by others.
232  // User Notice: This is a required function call.
233  retStat = dm_channel_release_lock(&pDeviceDescriptor->cDescriptor);
234  if(ISF_SUCCESS != retStat)
235  {
236  return retStat;
237  }
238 
239 unlockdescriptor:
240  // Unlock the device descriptor.
241  //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
242  OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
243 
244  return retStat;
245 }
246 
247 // This is the MMA8491Q accelerometer adapter routine to calibrate the sensor.
248 // Calibration has not yet been implemented in ISF.
250 {
251  if((NULL == pSensorHandle) || (NULL == pCalData))
252  {
253  return DSA_ERR_PARAM;
254  }
255 
256  return ISF_SUCCESS;
257 }
258 
259 // This is the MMA8491Q accelerometer adapter routine to start sensor data.
261 {
262  if(NULL == pSensorHandle)
263  {
264  return DSA_ERR_PARAM;
265  }
266 
268  DeviceDescriptor_t *pDescriptor = pSensorHandle->pDeviceDescriptor;
269 
270  // Check the device descriptor.
271  if(NULL == pDescriptor)
272  {
273  return DSA_ERR_PARAM;
274  }
275 
276  // Lock the device descriptor.
277  //_lwsem_wait_ticks(&pDescriptor->deviceSemaphore, 0);
278  OSA_SemaWait(&pDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
279 
280  // Check the driver state.
281  if(DSA_STATE_CONFIGURED_STOPPED > pSensorHandle->adapterStatus)
282  {
283  goto unlockdescriptor;
284  }
285 
286  // Schedule the Bus Manager sampling timer for the sensor selected by the user ( > 1 up to 200 Hz)
287  // and schedule a periodic callback that will only run once
288  if(BM_ERROR & bm_start(FALSE, pDescriptor->token))
289  { // Check for Bus Manager error and return on failure.
290  goto unlockdescriptor;
291  }
292 
293  // Set the adapter state to indicate that the sensor is transitioned to starting
295 
296  retStat = ISF_SUCCESS;
297 
298 unlockdescriptor:
299  // Unlock the device descriptor.
300  //_lwsem_post(&pDescriptor->deviceSemaphore);
301  OSA_SemaPost(&pDescriptor->deviceSemaphore);
302 
303  return retStat;
304 }
305 
306 // This is the MMA8491Q accelerometer adapter routine to stop sensor data.
308 {
309  if(NULL == pSensorHandle)
310  {
311  return DSA_ERR_PARAM;
312  }
313 
314  isf_status_t retStat = DSA_ERR_END_DATA;
315  // Cast the void input pointer to a typed pointer.
316  DeviceDescriptor_t* pDescriptor = pSensorHandle->pDeviceDescriptor;
317 
318  // Check the device descriptor.
319  if(NULL == pDescriptor)
320  {
321  return retStat;
322  }
323 
324  // Lock the device descriptor.
325  //_lwsem_wait_ticks(&pDescriptor->deviceSemaphore, 0);
326  OSA_SemaWait(&pDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
327 
328  // Check the driver state.
329  if(DSA_STATE_CONFIGURED_STOPPED >= pSensorHandle->adapterStatus)
330  {
331  goto unlockdescriptor;
332  }
333 
334  // Check that the adapter is not already started.
335  if(DSA_STATE_CONFIGURED_STARTED == pSensorHandle->adapterStatus)
336  { // If it is, then stop the Bus Manager (BM) periodic callbacks for
337  // start and end
338  isf_status_t bmStopStatus = bm_stop(pDescriptor->token);
339  if(BM_ERROR & bmStopStatus)
340  {
341  goto unlockdescriptor;
342  }
343  }
344 
345  // Leave on Plutino Enable so that I2C subsystem is active.
346  GPIO_DRV_SetPinOutput(en_pin);
347 
348  // Set the adapter back to the initialized state.
350  retStat = ISF_SUCCESS;
351 
352 unlockdescriptor:
353  // Unlock the device descriptor.
354  //_lwsem_post(&pDescriptor->deviceSemaphore);
355  OSA_SemaPost(&pDescriptor->deviceSemaphore);
356 
357  return retStat;
358 }
359 
361 {
362  isf_status_t retStat = DSA_ERR_END_DATA;
363 
364  if(NULL == pSensorHandle)
365  {
366  return DSA_ERR_PARAM;
367  }
368 
369  // Create helper reference pointers.
370  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
371 
372  // Remove the sensor adapter from the Bus Manager callbacks.
373  isf_status_t bmUnregisterStatus = bm_unregister_callback(token_cb_Read_Data);
374  if(BM_ERROR & bmUnregisterStatus)
375  {
376  return DSA_ERR_SHUTDOWN;
377  }
378 
379  bmUnregisterStatus = bm_unregister_callback(pDeviceDescriptor->token);
380  if(BM_ERROR & bmUnregisterStatus)
381  {
382  return DSA_ERR_SHUTDOWN;
383  }
384 
385  /* Reset the Sensor State machine to reflect shutdown. */
387 
388  // Set the adapter back to the initialized state.
389  pSensorHandle->adapterStatus = DSA_STATE_INITIALIZED;
390  return ISF_SUCCESS;
391 }
392 
393 /*
394  * This routine sets the enable GPIO pin of the sensor to transition to ACTIVE
395  */
397 {
398  volatile isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
399 
400  if(NULL == pSensorHandle)
401  {
402  return;
403  }
404  DeviceDescriptor_t* pDescriptor = (DeviceDescriptor_t*)(pSensorHdl->pDeviceDescriptor);
405  if(NULL == pDescriptor)
406  {
407  return;
408  }
409 
410  // Lock the device descriptor.
411  //_lwsem_wait_ticks(&pDescriptor->deviceSemaphore, 0);
412  OSA_SemaWait(&pDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
413 
414  // Check that the adaptor state is STARTED and the sensor mode is SHUTDOWN
415  if((DSA_STATE_CONFIGURED_STARTED == pSensorHdl->adapterStatus)
417  {
418  // Set GPIO EN=1 to Enable the sensor and set its state to ACTIVE and start the callback.
419  GPIO_DRV_SetPinOutput(en_pin);
421  (void) bm_start(FALSE, token_cb_Read_Data);
422  }
423 
424  // Unlock the device descriptor.
425  //_lwsem_post(&pDescriptor->deviceSemaphore);
426  OSA_SemaPost(&pDescriptor->deviceSemaphore);
427 }
428 
429 /*
430  * This is the STANDBY mode of the sensor that collects data
431  */
432 void fsl_mma8491q_read_data_OneShotCallback(void* pSensorHandle)
433 {
434  int32 numBytes;
435  isf_status_t st;
436  volatile isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
437 
438  if(NULL == pSensorHandle)
439  {
440  return;
441  }
442 
444  DeviceDescriptor_t *pDescriptor = (DeviceDescriptor_t*)(pSensorHdl->pDeviceDescriptor);
445  if(NULL == pDescriptor)
446  {
447  return;
448  }
449 
450  mma8491q_DataBuffer_t *pCurrentSampleBuffer = (mma8491q_DataBuffer_t *)pDescriptor->pCurrentSample;
451 
452  // Apply sample skip if necessary.
453  if (pDescriptor->skipFramecnt)
454  { // Not done skipping samples.
455  --pDescriptor->skipFramecnt;
456  return;
457  }
458 
459  // Read the timestamp and put it into the Sensor Manager(SM) data buffer.
460  pCurrentSampleBuffer->timestamp = isf_time_util_get_usec();
461 
462  // Lock the device descriptor.
463  //_lwsem_wait_ticks(&pDescriptor->deviceSemaphore, 0);
464  OSA_SemaWait(&pDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
465 
466  // Check that the sensor adaptor is STARTED and that the mode is ACTIVE
467  if((DSA_STATE_CONFIGURED_STARTED == pSensorHdl->adapterStatus)
469  {
470  // acquire the sensor data
471  st = mma8491q_getAccelData(pDescriptor, &pCurrentSampleBuffer->accel[0]);
472  if(st != MMA8491Q_DATA_SUCCESS)
473  {
474  goto unlockdescriptor;
475  }
476 
477  // After acquisition of the data set the sensor mode to SHUTDOWN
478  // and Turn off the GPIO EN=0 the enable pin of the MMA8491Q and disable the callback.
479  GPIO_DRV_ClearPinOutput(en_pin);
481  (void) bm_stop(token_cb_Read_Data);
482 
483  // Lock the fifo for update.
484  if(kStatus_OSA_Success != isf_fifo_lock(pFifo))
485  {
486  goto unlockdescriptor;
487  }
488 
490  pCurrentSampleBuffer->xOut = GPIO_DRV_ReadPinInput(x_out_pin);
491  pCurrentSampleBuffer->yOut = GPIO_DRV_ReadPinInput(y_out_pin);
492  pCurrentSampleBuffer->zOut = GPIO_DRV_ReadPinInput(z_out_pin);
493 
494  // write the new data
496  {
497  *pFifoEntry = *pCurrentSampleBuffer;
498  }
499  else
500  {
502  pSensorHdl,
505  pCurrentSampleBuffer,
506  pFifoEntry,
507  &numBytes);
508  }
509 
510  // Increment the fifo to the next sample entry.
511  st = isf_fifo_el_increment(pFifo);
512 
513  // Unlock the fifo.
514  isf_fifo_unlock(pFifo);
515 
516  if (st == ISF_FIFO_FULL)
517  {
518  // Notify the user using their registered event information
519  //_lwevent_set(pSensorHdl->controlData.pEventGroup,(uint32_t)pSensorHdl->controlData.nEventFieldIndex);
520  OSA_EventSet(pSensorHdl->controlData.pEventGroup,(uint32_t)pSensorHdl->controlData.nEventFieldIndex);
521  }
522  }
523 
524 unlockdescriptor:
525  // Unlock the device descriptor.
526  //_lwsem_post(&pDescriptor->deviceSemaphore);
527  OSA_SemaPost(&pDescriptor->deviceSemaphore);
528 }
529 
531  (
532  volatile isf_SensorHandle_t *pSensorHandle,
533  isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType,
534  void *pNativeSample,
535  void *pConvertedSample,
536  int32 *numBytes
537  )
538 {
541 
542  pConverter = NULL;
543  switch (convertToType)
544  {
546  if(resultType == DSA_RESULT_TYPE_ENG_FLOAT)
547  {
548  pConverter = float_accel3d_converter;
549  }
550  else if(resultType == DSA_RESULT_TYPE_ENG_FIXED)
551  {
552  pConverter = fixed_accel3d_converter;
553  }
554  break;
555 
556  default:
558  }
559  if(pConverter == NULL)
560  {
562  }
563 
564  retStat = pConverter(
566  (mma8491q_DataBuffer_t *)pNativeSample, pConvertedSample);
567 
568  return retStat;
569 }
570 
571 /*!
572  * @brief This function validates the MMA8491Q sensor is connected via the I2C bus.
573  */
574 void mma8491q_CheckId(int32_t *status, void* pSensorHandle)
575 {
576  uint8 buffer[1] = {0};
577  int32 retStat = SENSOR_ERROR_CHECKID;
578 
579  // Create and validate helper reference pointers.
580  isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
581  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
582  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
583 
584  if(ISF_SUCCESS != dm_device_read(pDeviceHandle, MMA8491Q_WHOAMI_VALUE, &buffer[0], 1, 1))
585  {
586  *status = retStat;
587  }
588  if(MMA8491Q_WHOAMI_VALUE != buffer[0])
589  {
590  *status = retStat;
591  }
592 
593  *status = ISF_SUCCESS;
594 }
595 
596 #define DATA_BUFFER_SIZE_8491Q (7)
597 /*
598  * Get the acceleration data from the MMA8491Q by using device messaging to interface with I2C
599  */
601 {
602  uint8 registerData[DATA_BUFFER_SIZE_8491Q];
603 
604  // Read the i2c buffer
605  if(ISF_SUCCESS != dm_device_read(&pDescriptor->deviceHandle,
607  {
608  return SENSOR_ERROR_GETDATA;
609  }
610 
611  // Check the status bit for good data in the buffer
612  if( registerData[0] & (uint8)ZYXDR_MASK)
613  {
614  // copy the data into the destination buffer
615  mma8491q_xyz_format(pAccelData[0], registerData[1], registerData[2]); // x
616  mma8491q_xyz_format(pAccelData[1], registerData[3], registerData[4]); // y
617  mma8491q_xyz_format(pAccelData[2], registerData[5], registerData[6]); // z
618 
619  return MMA8491Q_DATA_SUCCESS;
620  }
621  else
622  {
623  return MMA8491Q_DATA_FAIL;
624  }
625 }
626 
627 static isf_dsa_status_t float_accel3d_converter(mma8491q_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma8491q_DataBuffer_t *nativeSample, void *vpConvertedSample)
628 {
629  isf_Acceleration3D_Float_t *convertedSample = (isf_Acceleration3D_Float_t *)vpConvertedSample;
630  convertedSample->timestamp = nativeSample->timestamp;
631  // These factors and offsets really depends on the configured sensor Range in pSensorSpecificConfig
632  convertedSample->accel[0] = nativeSample->accel[0] * MMA8491Q_ACCEL_FLOAT_CONVERSION_FACTOR;
633  convertedSample->accel[1] = nativeSample->accel[1] * MMA8491Q_ACCEL_FLOAT_CONVERSION_FACTOR;
634  convertedSample->accel[2] = nativeSample->accel[2] * MMA8491Q_ACCEL_FLOAT_CONVERSION_FACTOR;
635 
636  return ISF_SUCCESS;
637 }
638 
639 static isf_dsa_status_t fixed_accel3d_converter(mma8491q_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma8491q_DataBuffer_t *nativeSample, void *vpConvertedSample)
640 {
641  isf_Acceleration3D_EngFixed_t *convertedSample = (isf_Acceleration3D_EngFixed_t *)vpConvertedSample;
642  convertedSample->timestamp = nativeSample->timestamp;
643  // These factors and offsets really depend on the configured sensor Range in pSensorSpecificConfig
644  convertedSample->accel[0] = nativeSample->accel[0] * MMA8491Q_ACCEL_FIXED_CONVERSION_FACTOR;
645  convertedSample->accel[1] = nativeSample->accel[1] * MMA8491Q_ACCEL_FIXED_CONVERSION_FACTOR;
646  convertedSample->accel[2] = nativeSample->accel[2] * MMA8491Q_ACCEL_FIXED_CONVERSION_FACTOR;
647 
648  return ISF_SUCCESS;
649 }
isf_status_t fsl_mma8491q_i2c_3D_accel_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
volatile mma8491q_mode_t mma8491q_mode
isf_status_t dm_channel_start(dm_ChannelDescriptor_t *apChannelDescriptor)
This function starts a channel.
void * pSensorSpecificSettings
unsigned char uint8
Definition: isf_types.h:76
Standard fixed type for three axis accelerometers.
const uint32_t x_out_pin
uint32 isf_time_util_get_usec(void)
This API returns the time in microseconds.
Definition: isf_util.c:55
isf_status_t dm_device_open(dm_ChannelDescriptor_t *apChannelDescriptor, void *apDevice, dm_DeviceDescriptor_t *apDeviceDescriptor)
This function creates a device handle for a device at a specified channel address.
uint32 timestamp
Time stamp value in micro-seconds.
const void * commInfo
isf_dsa_ControlData_t controlData
isf_fifo_status_t isf_fifo_lock(isf_fifo_t *pFifo)
Lock a sample buffer for exclusive access.
Definition: isf_fifo.c:170
comm_State_t dm_channel_get_state(dm_ChannelDescriptor_t *apChannelDescriptor)
This function returns the channel state.
isf_fifo_status_t isf_fifo_unlock(isf_fifo_t *pFifo)
Release the exclusive access lock on a sample buffer.
Definition: isf_fifo.c:199
isf_dsa_status_t fsl_mma8491q_i2c_3D_accel_Shutdown(isf_SensorHandle_t *pSensorHandle)
isf_fifo_status_t isf_fifo_el_increment(isf_fifo_t *pFifo)
Routine increments the insert pointer after direct access.
Definition: isf_fifo.c:237
int16 accel[3]
Accelerometer raw data buffer. MMA8491Q supports X,Y,Z axes(3).
isf_sensors.h contains the ISF Generic Sensor definitions and data structures required when a client ...
#define MMA8491Q_ACCEL_FLOAT_CONVERSION_FACTOR
mma8491q_mode_t
Definition: mma8491q.h:67
#define FALSE
Definition: isf_types.h:86
#define ZYXDR_MASK
Definition: mma8491q.h:35
dm_DeviceDescriptor_t deviceHandle
Definition: isf_sensors.h:52
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
uint8 yOut
The Tilt Y data from the sensor.
Define the sensor device descriptor.
Definition: isf_sensors.h:49
isf_status_t fsl_mma8491q_i2c_3D_accel_EndData(isf_SensorHandle_t *pSensorHandle)
#define DATA_BUFFER_SIZE_8491Q
isf_dsa_status_t fsl_mma8491q_i2c_3D_accel_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
uint32 bm_callback_token_t
This type defines the Bus Manager token. Each callback registered with the Bus Manager receives a uni...
Definition: isf_bm.h:79
isf_SensorTypes_t
dm_ChannelDescriptor_t cDescriptor
Definition: isf_sensors.h:51
const uint32_t z_out_pin
isf_status_t bm_unregister_callback(bm_callback_token_t aToken)
This API unregisters one or more callbacks.
uint8 xOut
The Tilt X data from the sensor.
isf_acceleration_g_fixed_32s1i16_t accel[3]
int32 isf_dsa_status_t
This is the Sensor Manager API return type definition.
#define MMA8491Q_WHOAMI_VALUE
Definition: mma8491q.h:16
#define MMA8491Q_ACCEL_FIXED_CONVERSION_FACTOR
isf_acceleration_g_float_t accel[3]
signed short int int16
Definition: isf_types.h:73
void fsl_mma8491q_i2c_3D_accel_PeriodicCallback(void *pSensorHandle)
isf_status_t dm_channel_acquire_lock(dm_ChannelDescriptor_t *apChannelDescriptor, isf_duration_t aTimeout)
This function locks the channel for exclusive access.
enum isf_dsa_result_enums isf_dsa_result_types_t
const uint32_t y_out_pin
bm_callback_token_t bm_register_periodic_callback(isf_duration_t aPeriod, bm_callback_t *pCallback, void *pCbData)
This API schedules a callback at the specified period.
isf_status_t fsl_mma8491q_i2c_3D_accel_StartData(isf_SensorHandle_t *pSensorHandle)
isf_dsa_status_t fsl_mma8491q_i2c_3D_accel_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_dsa_result_types_t resultFormat
The mma8491q.h contains register definitions and macros as well as the type definitions and public fu...
The fsl_mma8491q_i2c_3D_accel.h file contains the definitions and functions supporting the MMA8491q S...
isf_SensorDataTypes_t
isf_status_t dm_channel_init(dm_ChannelId_t aChannelId, dm_ChannelDescriptor_t *apChannelDescriptor)
This function initializes a channel.
isf_status_t bm_stop(bm_callback_token_t aTokens)
This API stops one or more callback(s) by setting them to the inactive state.
const isf_SensorConfig_t * pSensorStaticConfig
isf_status_t bm_start(boolean aSync, bm_callback_token_t aTokens)
This API sets one or more callback(s) to the active state.
isf_SensorDataTypes_t resultType
void mma8491q_CheckId(int32_t *status, void *pSensorHandle)
This function validates the MMA8491Q sensor is connected via the I2C bus.
uint8 zOut
The Tilt Z data from the sensor.
MMA8491Q data buffer format.
isf_dsa_AdapterStatus_t adapterStatus
signed long int int32
Definition: isf_types.h:74
sys_channelId_t channelId
const uint32_t en_pin
Standard float type for three axis accelerometers.
isf_status_t dm_device_read(dm_DeviceDescriptor_t *apDeviceDescriptor, int32 aOffset, uint8 *apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead)
This function reads from a device.
#define BM_ERROR
This value specifies a general Bus Manager error. If an error occurs in registering a callback...
Definition: isf_bm.h:57
int32 isf_status_t
ISF return status type.
Definition: isf.h:76
isf_SensorDataTypes_t mma8491q_SupportedDataTypes[]
This defines the DSA sensor configuration parameter structure configuring the sensor settings by a su...
isf_dsa_SensorSettings_t sensorSettings
isf_dsa_status_t fsl_mma8491q_i2c_3D_accel_Convert(volatile isf_SensorHandle_t *pSensorHandle, isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType, void *pNativeSample, void *pConvertedSample, int32 *numBytes)
isf_dsa_status_t fsl_mma8491q_i2c_3D_accel_Initialize(isf_SensorHandle_t *pSensorHandle)
#define mma8491q_xyz_format(destination, msb, lsb)
void * isf_fifo_el_get_insert_pointer(isf_fifo_t *pFifo)
Routine returns the insert pointer for direct access.
Definition: isf_fifo.c:229
isf_status_t dm_channel_release_lock(dm_ChannelDescriptor_t *apChannelDescriptor)
This function releases exclusive channel access.
void fsl_mma8491q_read_data_OneShotCallback(void *pSensorHandle)
This structure defines a handle for the device.
Definition: isf_devmsg.h:61
isf_devmsg.h defines the API definitions and types for the Intelligent Sensing (ISF) Device Messaging...
The isf_accelerometer_types.h file contains the ISF data type definitions for use with the ISF generi...
Definition: OutX.h:82
semaphore_t deviceSemaphore
Definition: isf_sensors.h:54
This structure is a declaration of a channel descriptor type.
Definition: isf_devmsg.h:50
isf_SensorTypes_t mma8491q_SupportedSensorTypes[]
Supported sensor and data types for MMA8491q.
#define ISF_FIFO_FULL
Definition: isf_fifo.h:33
#define T_ON_8491Q_MICROSECONDS
bm_callback_token_t token
Definition: isf_sensors.h:53
isf_dsa_status_t mma8491q_getAccelData(DeviceDescriptor_t *pDescriptor, int16 *pAccelData)