ISF  2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
FXLS8471_1.c
Go to the documentation of this file.
1 /* ###################################################################
2 ** This component module is generated by Processor Expert. Do not modify it.
3 ** Filename : FXLS8471_1.c
4 ** CDE edition : Community
5 ** Project : ISF2P2_K64F_MQX_PROJ
6 ** Processor : MK64FN1M0VLL12
7 ** Component : ISF_KSDK_Sensor_FXLS8471_Accelerometer
8 ** Version : Component 02.500, Driver 01.00, CPU db: 3.00.000
9 ** Repository : My Components
10 ** Compiler : GNU C Compiler
11 ** Date/Time : 2016-10-06, 13:38, # CodeGen: 0
12 ** Abstract :
13 **
14 ** Settings :
15 ** Component Name : FXLS8471_1
16 ** Device Address : 0x1E
17 ** Comm Channel : SPI1
18 ** Is SPI Selected : yes
19 ** Chip Select : SensorReset
20 ** Allowed Full-scale Ranges : ±0.244 mg/LSB
21 ** Sensor Specific Configuration : yes
22 ** XYZ_DATA_CFG : yes
23 ** HPF_OUT : 0
24 ** FS : 0
25 ** HP_FILTER_CUTOFF : yes
26 ** PULSE_HPF_BYP : 0
27 ** PULSE_LPF_EN : 0
28 ** SEL : 0
29 ** PL_CFG : yes
30 ** DBCNTM : 1
31 ** PL_EN : 0
32 ** PL_COUNT : 0
33 ** PL_BF_ZCOMP : yes
34 ** BKFR : 2
35 ** ZLOCK : 4
36 ** PL_THS_REG : yes
37 ** PL_THS : 16
38 ** HYS : 4
39 ** A_FFMT_CFG : yes
40 ** A_FFMT_ELE : 0
41 ** A_FFMT_OAE : 0
42 ** A_FFMT_ZEFE : 0
43 ** A_FFMT_YEFE : 0
44 ** A_FFMT_XEFE : 0
45 ** A_FFMT_THS : yes
46 ** A_FFMT_DBCNTM : 0
47 ** THS : 0
48 ** A_FFMT_COUNT : 0
49 ** PULSE_THSX : 0
50 ** PULSE_THSY : 0
51 ** PULSE_THSZ : 0
52 ** ASLP_COUNT : 0
53 ** CTRL_REG1 : yes
54 ** ASLP_RATE : 0
55 ** DR : 1
56 ** LNOISE : 0
57 ** CTRL_REG2 : yes
58 ** SMODS : 0
59 ** SLPE : 0
60 ** MODS : 0
61 ** OFF_X : 0
62 ** OFF_Y : 0
63 ** OFF_Z : 0
64 ** A_VECM_CFG : yes
65 ** A_VECM_ELE : 0
66 ** A_VECM_INITM : 0
67 ** A_VECM_UPDM : 0
68 ** A_VECM_EN : 0
69 ** A_VECM_THS : yes
70 ** A_VECM_DBCNTM : 0
71 ** A_VECM_THS : 0
72 ** A_VECM_CNT : 0
73 ** A_VECM_INITX : 0
74 ** A_VECM_INITY : 0
75 ** A_VECM_INITZ : 0
76 ** A_FFMT_THS_X : yes
77 ** A_FFMT_THS_XYZ_EN : 0
78 ** A_FFMT_THS_X : 0
79 ** A_FFMT_THS_Y : 0
80 ** A_FFMT_THS_Z : 0
81 ** Contents :
82 ** No public methods
83 **
84 ** For non-commercial use only.
85 (c) Copyright <company/user-name>, 2015,
86 http://www.<company>.com
87 mail: info@<company>.com
88 ** ###################################################################*/
89 /*!
90 ** @file FXLS8471_1.c
91 ** @version 01.00
92 ** @brief
93 **
94 */
95 /*!
96 ** @addtogroup FXLS8471_1_module FXLS8471_1 module documentation
97 ** @{
98 */
99 
100 /* MODULE FXLS8471_1. */
101 
102 #include "FXLS8471_1.h"
103 #include "isf_target.h"
104 #include "isf.h"
105 #include "isf_util.h"
106 #include "isf_spi_master_types.h"
107 #include "SensorReset.h"
108 
110 isf_status_t fsl_veryon_spi_slave_write_preprocess(void *pCmdOut, uint32 offset, uint32 size, void *pWritebuffer);
113 isf_status_t fsl_veryon_spi_slave_read_postprocess(void *pCmdOut, void* pDataOut);
114 
116 {
117  .accelFullScaleRange = 0, // Capture the accelerometer full-scale range for use in conversion routines.
118  .regCount = 41, // Number of register pairs to follow
119  .regPairs =
120  {
121  { FXLS8471_F_SETUP, 0 },
122  { FXLS8471_TRIG_CFG, 0 },
123  // Data configuration registers.
124  { FXLS8471_XYZ_DATA_CFG, (FXLS8471_SET_FIELD(HPF_OUT,0)) | (FXLS8471_SET_FIELD(FS,0)) },
125  { FXLS8471_HP_FILTER_CUTOFF, (FXLS8471_SET_FIELD(PULSE_HPF_BYP,0)) | (FXLS8471_SET_FIELD(PULSE_LPF_EN,0)) | (FXLS8471_SET_FIELD(SEL,0)) },
126  // Portrait Landscape registers.
127  { FXLS8471_PL_CFG, (FXLS8471_SET_FIELD(DBCNTM,1)) | (FXLS8471_SET_FIELD(PL_EN,0)) },
128  { FXLS8471_PL_COUNT, 0 },
129  { FXLS8471_PL_BF_ZCOMP, (FXLS8471_SET_FIELD(BKFR,1)) | (FXLS8471_SET_FIELD(ZLOCK,4)) },
130  { FXLS8471_PL_THS, (FXLS8471_SET_FIELD(PL_THS,16)) | (FXLS8471_SET_FIELD(HYS,4)) },
131  { FXLS8471_PULSE_THSX, 0 },
132  { FXLS8471_PULSE_THSY, 0 },
133  { FXLS8471_PULSE_THSZ, 0 },
134  // Freefall/Motion Detection registers.
135  { FXLS8471_FFMT_CFG, (FXLS8471_SET_FIELD(A_FFMT_ELE,0)) | (FXLS8471_SET_FIELD(A_FFMT_OAE,0)) | (FXLS8471_SET_FIELD(A_FFMT_ZEFE,0)) | (FXLS8471_SET_FIELD(A_FFMT_YEFE,0)) | (FXLS8471_SET_FIELD(A_FFMT_XEFE,0)) },
136  { FXLS8471_FFMT_THS, (FXLS8471_SET_FIELD(A_FFMT_DBCNTM,0)) | (FXLS8471_SET_FIELD(A_FFMT_THS,0)) },
137  { FXLS8471_A_FFMT_THS_X_MSB, (FXLS8471_SET_FIELD(A_FFMT_THS_XYZ_EN,0) | 0 ) },
143  { FXLS8471_FFMT_COUNT, 0 },
144  // Transient Detection registers.
145  { FXLS8471_TRANSIENT_CFG, 0 }, // Feature disabled by default (for now).
146  // Pulse Detection registers.
147  { FXLS8471_PULSE_CFG, 0 }, // Feature is disabled by default (for now).
148  // Auto-WAKE/SLEEP Detection registers.
149  { FXLS8471_ASLP_COUNT, 0 },
150  // System and Control registers.
151  { FXLS8471_CTRL_REG1, (FXLS8471_SET_FIELD(ASLP_RATE,0)) | (FXLS8471_SET_FIELD(DR,0)) | (FXLS8471_SET_FIELD(LNOISE,0)) | (FXLS8471_SET_FIELD(FREAD,0)) },
152  { FXLS8471_CTRL_REG2, (FXLS8471_SET_FIELD(SMODS,0)) | (FXLS8471_SET_FIELD(SLPE,0)) | (FXLS8471_SET_FIELD(MODS,0)) },
153  { FXLS8471_CTRL_REG3, 0 }, // Interrupt sources disabled, Active Low, Push-Pull Open Drain (defaults).
154  { FXLS8471_CTRL_REG4, 0 }, // Interrupts disabled (defaults).
155  { FXLS8471_CTRL_REG5, 0 }, // INT2 Pin (defaults).
156  // Calibration Offset registers.
157  { FXLS8471_OFF_X, 0 },
158  { FXLS8471_OFF_Y, 0 },
159  { FXLS8471_OFF_Z, 0 },
160  // Vector Magnitude Configuration registers.
161  { FXLS8471_A_VECM_CFG, (FXLS8471_SET_FIELD(A_VECM_ELE,0)) | (FXLS8471_SET_FIELD(A_VECM_INITM,0)) | (FXLS8471_SET_FIELD(A_VECM_UPDM,0)) | (FXLS8471_SET_FIELD(A_VECM_EN,0)) },
162  { FXLS8471_A_VECM_THS_MSB, (FXLS8471_SET_FIELD(A_VECM_DBCNTM,0)) | (FXLS8471_SET_FIELD(A_VECM_THS_MSB, 0)) },
164  { FXLS8471_A_VECM_CNT, 0 },
171  }
172  };
173 
174 /*!
175  * @brief This creates the sensor adapter instance for the target sensor.
176  *
177  */
179 {
181  .devInfo.pSupportedSensorDataTypes = fxls8471_SupportedDataTypes,
182  .devInfo.nNativeDataSetSize = sizeof(fxls8471_DataBuffer_t),
183  .control.Initialize = &fsl_fxls8471_i2cspi_3D_accel_Initialize,
184  .control.ValidateSettings = &fsl_fxls8471_i2cspi_3D_accel_ValidateSettings,
185  .control.Configure = &fsl_fxls8471_i2cspi_3D_accel_Configure,
186  .control.StartData = &fsl_fxls8471_i2cspi_3D_accel_StartData,
187  .control.EndData = &fsl_fxls8471_i2cspi_3D_accel_EndData,
188  .control.Calibrate = &fsl_fxls8471_i2cspi_3D_accel_Calibrate,
189  .control.Shutdown = &fsl_fxls8471_i2cspi_3D_accel_Shutdown,
190  .control.Convert = &fsl_fxls8471_i2cspi_3D_accel_Convert
191 };
192 
193 
194 #define FSL_SENSOR_SPI_CMD_LENG 0x2
201 };
202 
203 
205 {
206  .busConfig =
207  {
208  .timeout = 1000U,
209  .device =
210  {
211  .bitsPerSec = 500000U,
212  .dataBusConfig.bitsPerFrame = 8U,
213  .dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh,
214  .dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge,
215  .dataBusConfig.direction = kDspiMsbFirst,
216  },
217  .userConfig =
218  {
219  .whichCtar = kDspiCtar0,
220  .isSckContinuous = false,
221  .isChipSelectContinuous = false,
222  .whichPcs = kDspiPcs0,
223  .pcsPolarity = kDspiPcs_ActiveHigh,
224  },
225  },
226  .pSlaveInfo = &fsl_spi_sensor_type_FXLS8471_1
227 };
228 
229 static uint8 spiWriteBuffer[64];
230 static uint8 spiReadBuffer[64];
231 
233 {
234  // Call the GPIO_LDD function to initialize the chip-select.
235  GPIO_DRV_OutputPinInit((gpio_output_pin_user_config_t *)&ResetSensor_OutConfig0);
236 
237  return ISF_SUCCESS;
238 }
239 
240 isf_status_t fsl_veryon_spi_slave_write_preprocess(void *pCmdOut, uint32 offset, uint32 size, void *pWritebuffer)
241 {
242 
243  spi_mater_slaveCmd_t* pSlaveCmd = (spi_mater_slaveCmd_t*)pCmdOut;
244 
245  uint8 *pWBuff = (uint8*)spiWriteBuffer;
246  uint8 *pRBuff = (uint8 *)(pWBuff + (size + FSL_SENSOR_SPI_CMD_LENG));
247  // formatting the command for the FSL_SENSORS
248  *pWBuff = offset | 0x80 ; // offset is the internal register address of the sensor at which write is performed.
249  *(pWBuff + 1) = offset & 0x80 ; // offset is the internal register address of the sensor at which write is performed.
250 
251  // Copy the command
252  ISF_MEM_CPY((uint8*)pWritebuffer, (pWBuff + 2), size);
253 
254  // Create the slave command.
255  pSlaveCmd->size = size + FSL_SENSOR_SPI_CMD_LENG;
256  pSlaveCmd->pWriteBuffer = (uint8*)pWBuff;
257  pSlaveCmd->pReadBuffer = (uint8*)pRBuff;
258 
259  // Call the GPIO_LDD function to clear chip-select.
260  GPIO_DRV_ClearPinOutput(J1_1);
261 
262  return ISF_SUCCESS;
263 }
264 
266 {
267  spi_mater_slaveCmd_t* pSlaveCmd = (spi_mater_slaveCmd_t*)pCmdOut;
268 
269  // Call the GPIO_LDD function to set chip-select.
270  GPIO_DRV_SetPinOutput(J1_1);
271 
272  return ISF_SUCCESS;
273 }
274 
276 {
277  spi_mater_slaveCmd_t* pSlaveCmd = (spi_mater_slaveCmd_t*)pCmdOut;
278 
279  uint8 *pWBuff = (uint8*)spiReadBuffer;
280  uint8 *pRBuff = (uint8 *)(pWBuff + (size + FSL_SENSOR_SPI_CMD_LENG));
281 
282  // formatting the command for the FSL_SENSORS
283  *pWBuff = offset & 0x7F ; // offset is the internal register address of the sensor at which write is performed.
284  *(pWBuff + 1) = offset & 0x80 ; // offset is the internal register address of the sensor at which write is performed.
285  // Note: We don't care what the values are at *pWBuff after the first two bytes.
286  // Create the slave command.
287  pSlaveCmd->size = size + FSL_SENSOR_SPI_CMD_LENG;
288  pSlaveCmd->pWriteBuffer = (uint8*)pWBuff;
289  pSlaveCmd->pReadBuffer = (uint8*)pRBuff;
290  // Call the GPIO_LDD function to clear chip-select.
291  GPIO_DRV_ClearPinOutput(J1_1);
292  return ISF_SUCCESS;
293 }
294 
296 {
297 
298  spi_mater_slaveCmd_t* pSlaveCmd = (spi_mater_slaveCmd_t*)pCmdOut;
299 
300  ISF_MEM_CPY((uint8*)(pSlaveCmd->pReadBuffer + FSL_SENSOR_SPI_CMD_LENG), pDataOut , (pSlaveCmd->size - FSL_SENSOR_SPI_CMD_LENG) );
301  // Call the GPIO_LDD function to set chip-select.
302  GPIO_DRV_SetPinOutput(J1_1);
303  return ISF_SUCCESS;
304 }
305 
306 /* END FXLS8471_1. */
307 
308 /*!
309 ** @}
310 */
311 /*
312 ** ###################################################################
313 **
314 ** This file was created by Processor Expert 10.5 [05.21]
315 ** for the Freescale Kinetis series of microcontrollers.
316 **
317 ** ###################################################################
318 */
ISF board support header files.
unsigned char uint8
Definition: isf_types.h:76
#define ISF_MEM_CPY(src, dest, number_of_bytes)
Macro for the memory copy.
Definition: isf_util.h:68
isf_status_t fsl_veryon_spi_slave_write_postprocess(void *pCmdOut)
Definition: FXLS8471_1.c:265
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_EndData(isf_SensorHandle_t *pSensorHandle)
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_Shutdown(isf_SensorHandle_t *pSensorHandle)
spi_master_slaveInfo_t fsl_spi_sensor_type_FXLS8471_1
Definition: FXLS8471_1.c:195
fxls8471_Sensor_Specific_Settings_t FXLS8471_1_Sensor_Specific_Config
This allows access to the sensor specific configuration for the target sensor.
Definition: FXLS8471_1.c:115
isf_status_t fsl_veryon_spi_slave_read_preprocess(void *pCmdOut, uint32 offset, uint32 size)
Definition: FXLS8471_1.c:275
This structure defines the slave specific spi information.
spi_master_busConfig_t busConfig
#define FXLS8471_SET_FIELD(name, val)
Definition: fxls8471.h:96
const gpio_output_pin_user_config_t ResetSensor_OutConfig0[]
Configuration structure 0 for output pins.
Definition: ResetSensor.c:56
const spi_master_CommSpecificInfo_t FXLS8471_1_DeviceInfo
This allows access to the sensor communications specific configuration.
Definition: FXLS8471_1.c:204
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_Convert(volatile isf_SensorHandle_t *pSensorHandle, isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType, void *pNativeSample, void *pConvertedSample, int32 *numBytes)
This function coverts the raw sample data to the desired output type.
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_status_t fsl_veryon_spi_slave_read_postprocess(void *pCmdOut, void *pDataOut)
Definition: FXLS8471_1.c:295
isf_dsa_DeviceInfoBlock_t devInfo
isf_SensorTypes_t fxls8471_SupportedSensorTypes[]
Supported sensor and data types for FXLS8471.
The isf_util.h file contains the utility method declarations and macros.
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
This defines the DSA adapter structure required for static initialization of the concrete instance of...
isf_status_t fsl_veryon_spi_slave_write_preprocess(void *pCmdOut, uint32 offset, uint32 size, void *pWritebuffer)
Definition: FXLS8471_1.c:240
isf_SensorTypes_t * pSupportedSensorTypes
isf_status_t(* fnwritepreProcessing_t)(void *cmdOut, uint32 offset, uint32 size, void *writebuffer)
This structure defines the spi slave command format.
#define FSL_SENSOR_SPI_CMD_LENG
Definition: FXLS8471_1.c:194
isf_SensorDataTypes_t fxls8471_SupportedDataTypes[]
isf_status_t fsl_veryon_spi_slave_init(void)
Definition: FXLS8471_1.c:232
isf_status_t(* fnwritepostProcossing_t)(void *cmd)
const isf_dsa_Adapter_t FXLS8471_1_Adapter
This creates the sensor adapter instance for the target sensor.
Definition: FXLS8471_1.c:178
Main ISF header file. Contains code common to all ISF components.
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_status_t(* fnreadpreProcessing_t)(void *cmdout, uint32 offset, uint32 size)
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_StartData(isf_SensorHandle_t *pSensorHandle)
int32 isf_status_t
ISF return status type.
Definition: isf.h:76
This structure defines the dummy DSA data buffer format.
isf_spi_master_types.h defines the spi protocol adapter structure and types.
isf_status_t(* fnreadpostProcossing_t)(void *cmd, void *dataOut)
unsigned long int uint32
Definition: isf_types.h:78
isf_status_t(* fnslaveinit_t)(void)
isf_dsa_status_t fsl_fxls8471_i2cspi_3D_accel_Initialize(isf_SensorHandle_t *pSensorHandle)