ISF  2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
FXOS8700_2.c
Go to the documentation of this file.
1 /* ###################################################################
2 ** This component module is generated by Processor Expert. Do not modify it.
3 ** Filename : FXOS8700_2.c
4 ** CDE edition : Community
5 ** Project : ISF2P2_K64F_MQX_PROJ
6 ** Processor : MK64FN1M0VLL12
7 ** Component : ISF_KSDK_Sensor_FXOS8700_ECompass
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 : FXOS8700_2
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 ** FF_MT_CFG : yes
40 ** ELE : 0
41 ** OAE : 0
42 ** ZEFE : 0
43 ** YEFE : 0
44 ** XEFE : 0
45 ** FF_MT_THS : yes
46 ** DBCNTM : 0
47 ** THS : 0
48 ** FF_MT_COUNT : 0
49 ** M_OFF_X : 0
50 ** M_OFF_Y : 0
51 ** M_OFF_Z : 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 ** M_CTRL_REG1 : yes
62 ** M_ACAL : 0
63 ** M_HMS : 1
64 ** M_CTRL_REG3 : yes
65 ** M_RAW : 0
66 ** M_ASLP_OS : 0
67 ** M_THS_XYZ_UPDATE : 0
68 ** Contents :
69 ** No public methods
70 **
71 ** For non-commercial use only.
72 (c) Copyright <company/user-name>, 2015,
73 http://www.<company>.com
74 mail: info@<company>.com
75 ** ###################################################################*/
76 /*!
77 ** @file FXOS8700_2.c
78 ** @version 01.00
79 ** @brief
80 **
81 */
82 /*!
83 ** @addtogroup FXOS8700_2_module FXOS8700_2 module documentation
84 ** @{
85 */
86 
87 /* MODULE FXOS8700_2. */
88 
89 #include "FXOS8700_2.h"
90 #include "isf_spi_master_types.h"
91 #include "SensorReset.h"
92 
94 isf_status_t fsl_gauss_spi_slave_write_preprocess(void *pCmdOut, uint32 offset, uint32 size, void *pWritebuffer);
97 isf_status_t fsl_gauss_spi_slave_read_postprocess(void *pCmdOut, void* pDataOut);
98 
100 {
101  .accelFullScaleRange = 0, // Capture the accelerometer full-scale range for use in conversion routines.
102  .mode = 1,
103  .regCount = 30, // Number of register pairs to follow
104  .regPairs =
105  {
106  { FXOS8700_INT_SOURCE, 0 },
107  // Data configuration registers.
108  { FXOS8700_XYZ_DATA_CFG, (FXOS8700_SET_FIELD(HPF_OUT,0)) | (FXOS8700_SET_FIELD(FS,0)) },
109  { FXOS8700_HP_FILTER_CUTOFF, (FXOS8700_SET_FIELD(PULSE_HPF_BYP,0)) | (FXOS8700_SET_FIELD(PULSE_LPF_EN,0)) | (FXOS8700_SET_FIELD(SEL,0)) },
110  // Portrait Landscape registers.
111  { FXOS8700_PL_CFG, (FXOS8700_SET_FIELD(DBCNTM,1)) | (FXOS8700_SET_FIELD(PL_EN,0)) },
112  { FXOS8700_PL_COUNT, 0 },
113  { FXOS8700_PL_BF_ZCOMP, (FXOS8700_SET_FIELD(BKFR,1)) | (FXOS8700_SET_FIELD(ZLOCK,4)) },
114  { FXOS8700_PL_THS_REG, (FXOS8700_SET_FIELD(PL_THS,16)) | (FXOS8700_SET_FIELD(HYS,4)) },
115  // Freefall/Motion Detection registers.
116  { FXOS8700_FF_MT_CFG, (FXOS8700_SET_FIELD(ELE,0)) | (FXOS8700_SET_FIELD(OAE,0)) | (FXOS8700_SET_FIELD(ZEFE,0)) | (FXOS8700_SET_FIELD(YEFE,0)) | (FXOS8700_SET_FIELD(XEFE,0)) },
117  { FXOS8700_FF_MT_THS, (FXOS8700_SET_FIELD(DBCNTM,0)) | (FXOS8700_SET_FIELD(THS,0)) },
118  { FXOS8700_FF_MT_COUNT, 0 },
119  // Transient Detection registers.
120  { FXOS8700_TRANSIENT_CFG, 0 }, // Feature disabled by default (for now).
121  // Pulse Detection registers.
122  { FXOS8700_PULSE_CFG, 0 }, // Feature is disabled by default (for now).
123  // Auto-WAKE/SLEEP Detection registers.
124  { FXOS8700_ASLP_COUNT, 0 },
125  // System and Control registers.
126  { FXOS8700_CTRL_REG1, (FXOS8700_SET_FIELD(ASLP_RATE,0)) | (FXOS8700_SET_FIELD(DR,0)) | (FXOS8700_SET_FIELD(LNOISE,0)) | (FXOS8700_SET_FIELD(F_READ,0)) },
127  { FXOS8700_CTRL_REG2, (FXOS8700_SET_FIELD(SMODS,0)) | (FXOS8700_SET_FIELD(SLPE,0)) | (FXOS8700_SET_FIELD(MODS,0)) },
128  { FXOS8700_CTRL_REG3, 0 }, // Interrupt sources disabled, Active Low, Push-Pull Open Drain (defaults).
129  { FXOS8700_CTRL_REG4, 0 }, // Interrupts disabled (defaults).
130  { FXOS8700_CTRL_REG5, 0 }, // INT2 Pin (defaults).
131  // Calibration Offset registers.
132  { FXOS8700_OFF_X, 0 },
133  { FXOS8700_OFF_Y, 0 },
134  { FXOS8700_OFF_Z, 0 },
135  { FXOS8700_M_OFF_X_MSB, 0 },
136  { FXOS8700_M_OFF_X_LSB, 0 },
137  { FXOS8700_M_OFF_Y_MSB, 0 },
138  { FXOS8700_M_OFF_Y_LSB, 0 },
139  { FXOS8700_M_OFF_Z_MSB, 0 },
140  { FXOS8700_M_OFF_Z_LSB, 0 },
141  { FXOS8700_M_CTRL_REG1, (FXOS8700_SET_FIELD(M_ACAL,0)) | (FXOS8700_SET_FIELD(M_HMS,1)) },
142  { FXOS8700_M_CTRL_REG2, (FXOS8700_SET_FIELD(M_AUTOINC,0)) | (FXOS8700_SET_FIELD(M_RST_CNT,3)) },
143  { FXOS8700_M_CTRL_REG3, (FXOS8700_SET_FIELD(M_RAW,0)) | (FXOS8700_SET_FIELD(M_ASLP_OS,0)) | (FXOS8700_SET_FIELD(M_THS_XYZ_UPDATE,0)) }
144  }
145  };
146 
147 /*!
148  * @brief This creates the sensor adapter instance for the target sensor.
149  *
150  */
152 {
154  .devInfo.pSupportedSensorDataTypes = fxos8700_SupportedDataTypes,
155  .devInfo.nNativeDataSetSize = sizeof(fxos8700_DataBuffer_t),
156  .control.Initialize = &fsl_fxos8700_i2cspi_6D_AccMag_Initialize,
157  .control.ValidateSettings = &fsl_fxos8700_i2cspi_6D_AccMag_ValidateSettings,
158  .control.Configure = &fsl_fxos8700_i2cspi_6D_AccMag_Configure,
159  .control.StartData = &fsl_fxos8700_i2cspi_6D_AccMag_StartData,
160  .control.EndData = &fsl_fxos8700_i2cspi_6D_AccMag_EndData,
161  .control.Calibrate = &fsl_fxos8700_i2cspi_6D_AccMag_Calibrate,
162  .control.Shutdown = &fsl_fxos8700_i2cspi_6D_AccMag_Shutdown,
163  .control.Convert = &fsl_fxos8700_i2cspi_6D_AccMag_Convert
164 };
165 
166 
167 #define FSL_SENSOR_SPI_CMD_LENG 0x2
174 };
175 
176 
178 {
179  .busConfig =
180  {
181  .timeout = 1000U,
182  .device =
183  {
184  .bitsPerSec = 500000U,
185  .dataBusConfig.bitsPerFrame = 8U,
186  .dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh,
187  .dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge,
188  .dataBusConfig.direction = kDspiMsbFirst,
189  },
190  .userConfig =
191  {
192  .whichCtar = kDspiCtar0,
193  .isSckContinuous = false,
194  .isChipSelectContinuous = false,
195  .whichPcs = kDspiPcs0,
196  .pcsPolarity = kDspiPcs_ActiveHigh,
197  },
198  },
199  .pSlaveInfo = &fsl_spi_sensor_type_FXOS8700_2
200 };
201 
202 static uint8 spiRead_CmdBuffer[64];
203 static uint8 spiRead_DataBuffer[64];
204 static uint8 spiWrite_CmdDataBuffer[64];
205 
207 {
208  // Call the GPIO_LDD function to initialize the chip-select.
209  GPIO_DRV_OutputPinInit(&(ResetSensor_OutConfig0));
210 
211  return ISF_SUCCESS;
212 }
213 
214 isf_status_t fsl_gauss_spi_slave_write_preprocess(void *pCmdOut, uint32 offset, uint32 size, void *pWritebuffer)
215 {
216  spi_mater_slaveCmd_t* pSlaveCmd = (spi_mater_slaveCmd_t*)pCmdOut;
217 
218  uint8 *pWBuff = spiWrite_CmdDataBuffer;
219  uint8 *pRBuff = spiWrite_CmdDataBuffer + size + FSL_SENSOR_SPI_CMD_LENG;
220 
221  // formatting the command for the FSL_SENSORS
222  *(pWBuff) = offset | 0x80 ; // offset is the internal register address of the sensor at which write is performed.
223  *(pWBuff+1) = offset & 0x80 ; // offset is the internal register address of the sensor at which write is performed.
224 
225  // Copy the command
226  ISF_MEM_CPY((uint8*)pWritebuffer, (pWBuff + FSL_SENSOR_SPI_CMD_LENG), size);
227 
228  // Create the slave command.
229  pSlaveCmd->size = size + FSL_SENSOR_SPI_CMD_LENG;
230  pSlaveCmd->pWriteBuffer = (uint8*)pWBuff;
231  pSlaveCmd->pReadBuffer = (uint8*)pRBuff;
232 
233  // Call the GPIO_LDD function to clear chip-select.
234  GPIO_DRV_ClearPinOutput(J1_1);
235 
236  return ISF_SUCCESS;
237 }
238 
240 {
241  // Call the GPIO_LDD function to set chip-select.
242  GPIO_DRV_SetPinOutput(J1_1);
243 
244  return ISF_SUCCESS;
245 }
246 
248 {
249  spi_mater_slaveCmd_t* pSlaveCmd = (spi_mater_slaveCmd_t*)pCmdOut;
250 
251  uint8 *pWBuff = spiRead_CmdBuffer;
252  uint8 *pRBuff = spiRead_DataBuffer;
253 
254  // formatting the command for the FSL_SENSORS
255  *(pWBuff) = offset & 0x7F ; // offset is the internal register address of the sensor at which write is performed.
256  *(pWBuff+1) = offset & 0x80 ; // offset is the internal register address of the sensor at which write is performed.
257 
258  // Create the slave command.
259  pSlaveCmd->size = size + FSL_SENSOR_SPI_CMD_LENG;
260  pSlaveCmd->pWriteBuffer = (uint8*)pWBuff;
261  pSlaveCmd->pReadBuffer = (uint8*)pRBuff;
262 
263  // Call the GPIO_LDD function to clear chip-select.
264  GPIO_DRV_ClearPinOutput(J1_1);
265 
266  return ISF_SUCCESS;
267 }
268 
270 {
271  spi_mater_slaveCmd_t* pSlaveCmd = (spi_mater_slaveCmd_t*)pCmdOut;
272 
273  ISF_MEM_CPY((uint8*)(pSlaveCmd->pReadBuffer + FSL_SENSOR_SPI_CMD_LENG), pDataOut , (pSlaveCmd->size - FSL_SENSOR_SPI_CMD_LENG) );
274 
275  // Call the GPIO_LDD function to set chip-select.
276  GPIO_DRV_SetPinOutput(J1_1);
277 
278  return ISF_SUCCESS;
279 }
280 /* END FXOS8700_2. */
281 
282 /*!
283 ** @}
284 */
285 /*
286 ** ###################################################################
287 **
288 ** This file was created by Processor Expert 10.5 [05.21]
289 ** for the Freescale Kinetis series of microcontrollers.
290 **
291 ** ###################################################################
292 */
unsigned char uint8
Definition: isf_types.h:76
#define FXOS8700_SET_FIELD(name, val)
Definition: fxos8700.h:144
This structure defines the dummy DSA data buffer format.
#define ISF_MEM_CPY(src, dest, number_of_bytes)
Macro for the memory copy.
Definition: isf_util.h:68
isf_status_t fsl_gauss_spi_slave_read_preprocess(void *pCmdOut, uint32 offset, uint32 size)
Definition: FXOS8700_2.c:247
spi_master_slaveInfo_t fsl_spi_sensor_type_FXOS8700_2
Definition: FXOS8700_2.c:168
isf_status_t fsl_gauss_spi_slave_write_preprocess(void *pCmdOut, uint32 offset, uint32 size, void *pWritebuffer)
Definition: FXOS8700_2.c:214
#define FSL_SENSOR_SPI_CMD_LENG
Definition: FXOS8700_2.c:167
const isf_dsa_Adapter_t FXOS8700_2_Adapter
This creates the sensor adapter instance for the target sensor.
Definition: FXOS8700_2.c:151
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_Initialize(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXOS8700 sensor adapter initialization.
This structure defines the slave specific spi information.
spi_master_busConfig_t busConfig
isf_SensorTypes_t fxos8700_SupportedSensorTypes[]
Supported sensor and data types for FXOS8700.
const gpio_output_pin_user_config_t ResetSensor_OutConfig0[]
Configuration structure 0 for output pins.
Definition: ResetSensor.c:56
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
This is the concrete implementation of the FXOS8700 sensor adapter for configuration.
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_StartData(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXOS8700 sensor adapter for start Data.
isf_dsa_DeviceInfoBlock_t devInfo
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
This is the concrete implementation of the FXOS8700 sensor adapter for calibration ...
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_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.
This defines the DSA adapter structure required for static initialization of the concrete instance of...
isf_SensorTypes_t * pSupportedSensorTypes
isf_status_t(* fnwritepreProcessing_t)(void *cmdOut, uint32 offset, uint32 size, void *writebuffer)
isf_SensorDataTypes_t fxos8700_SupportedDataTypes[]
This structure defines the spi slave command format.
isf_status_t(* fnwritepostProcossing_t)(void *cmd)
isf_status_t fsl_gauss_spi_slave_read_postprocess(void *pCmdOut, void *pDataOut)
Definition: FXOS8700_2.c:269
isf_status_t fsl_gauss_spi_slave_write_postprocess(void *pCmdOut)
Definition: FXOS8700_2.c:239
isf_status_t(* fnreadpreProcessing_t)(void *cmdout, uint32 offset, uint32 size)
int32 isf_status_t
ISF return status type.
Definition: isf.h:76
isf_spi_master_types.h defines the spi protocol adapter structure and types.
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_Shutdown(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXOS8700 sensor adapter for shutdown . ...
isf_status_t(* fnreadpostProcossing_t)(void *cmd, void *dataOut)
isf_status_t fsl_gauss_spi_slave_init(void)
Definition: FXOS8700_2.c:206
unsigned long int uint32
Definition: isf_types.h:78
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_EndData(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXOS8700 sensor adapter for End Data.
fxos8700_Sensor_Specific_Settings_t FXOS8700_2_Sensor_Specific_Config
This allows access to the sensor specific configuration for the target sensor.
Definition: FXOS8700_2.c:99
isf_dsa_status_t fsl_fxos8700_i2cspi_6D_AccMag_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
This is the concrete implementation of the FXOS8700 sensor adapter for validating current settings...
const spi_master_CommSpecificInfo_t FXOS8700_2_DeviceInfo
This allows access to the sensor communications specific configuration.
Definition: FXOS8700_2.c:177
isf_status_t(* fnslaveinit_t)(void)