| ISF 2.2 rev 5 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

MMA955x_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 : MMA955x_1.c
4 ** CDE edition : Standard
5 ** Project : ISF2P2_K64F_MQX_PROJ
6 ** Processor : MK64FN1M0VLL12
7 ** Component : ISF_KSDK_Sensor_MMA955x_Pedometer
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 : MMA955x_1
16 ** Device Address : 0x4C
17 ** Comm Channel : I2C1
18 ** Allowed Sample Rates : 488.28Hz
19 ** Allowed Full-scale Range : ±8 g
20 ** Contents :
21 ** No public methods
22 **
23 ** (c) Copyright Freescale Semiconductor Inc, 2015
24 http://www.freescale.com
25 ** ###################################################################*/
26 /*!
27 ** @file MMA955x_1.c
28 ** @version 01.00
29 ** @brief
30 **
31 */
32 /*!
33 ** @addtogroup MMA955x_1_module MMA955x_1 module documentation
34 ** @{
35 */
36
37 /* MODULE MMA955x_1. */
38
39 #include "MMA955x_1.h"
40 #include "isf_util.h"
41
42 uint8 MMA955x_1_ConfigRegisterBuffer[MMA955x_1_CONFIG_REGISTER_SIZE];
43
44 // Last byte for the following 3 to be updated by mma955xSetSamplingRate().
45 uint8 SelectedSampleRate[] = { 0x06, 0x20, 0x0C, 0x01, 0x00 };
46 uint8 SelectedAFEPriority[] = { 0x01, 0x20, 0x32, 0x01, 0x00 };
47 uint8 SelectedMBoxPriority[] = { 0x01, 0x20, 0x30, 0x01, 0x00 };
48
49 const uint8 SampleRates[] = { 0x07, //488.28
50 0x08, //244.17
51 0x09, //122.07
52 0x0A, //61.04
53 0x0B, //30.52
54 0x0C, //15.26
55 0x0D, //7.63
56 0x0E }; //3.81
57 const uint8 ApplicationPriorities[] = { 0xD7, //488.28
58 0xD6, //244.17
59 0xD5, //122.07
60 0xD4, //61.04
61 0xD3, //30.52
62 0xD2, //15.26
63 0xD1, //7.63
64 0xD0 }; //3.81
65
66 const uint8 const FSRange_2g[] = { 0x06, 0x20, 0x00, 0x01, 0x40 };
67 const uint8 const FSRange_4g[] = { 0x06, 0x20, 0x00, 0x01, 0x80 };
68 const uint8 const FSRange_8g[] = { 0x06, 0x20, 0x00, 0x01, 0x00 };
69
70 const uint8 const WakeApplication[] = { 0x12, 0x20, 0x06, 0x01, 0x00 };
71 const uint8 const LegacyMode[] = { 0x18, 0x20, 0x00, 0x01, 0x10 };
72 const uint8 const NormalMode[] = { 0x18, 0x20, 0x00, 0x01, 0x00 };
73 const uint8 const SleepApplication[] = { 0x12, 0x20, 0x06, 0x01, 0x01 };
74 const uint8 const MBoxQRDataXYZ[] = { 0x04, 0x20, 0x2C, 0x0C, 0x06, 0x13, 0x06, 0x12, 0x06, 0x15, 0x06, 0x14, 0x06, 0x17, 0x06, 0x16 };
75
76 const uint8 const ReadPedometerData[] = { 0x15, 0x30, 0x00, 0x0C };
77 const uint8 const ReadPedometerConfiguration[] = { 0x15, 0x10, 0x00, 0x11 };
78 const uint8 const WritePedometerConfiguration[] = { 0x15, 0x20, 0x00, 0x11 }; //Remaining bytes of payload will be added by write function.
79
80 const mma955x_Command_t const MMA955x_InitializeSequence[] =
81 {
82 {
83 .offset = 0,
84 .nByteWrite = sizeof(MBoxQRDataXYZ),
85 .pWriteBuffer = (uint8* const)MBoxQRDataXYZ
86 }
87 };
88
89 const mma955x_Command_t const MMA955x_ConfigureSequence[] =
90 {
91 {
92 .offset = 0,
93 .nByteWrite = sizeof(FSRange_8g),
94 .pWriteBuffer = (uint8* const)FSRange_8g
95 },
96 {
97 .offset = 0,
98 .nByteWrite = sizeof(SelectedSampleRate),
99 .pWriteBuffer = (uint8* const)SelectedSampleRate
100 },
101 {
102 .offset = 0,
103 .nByteWrite = sizeof(SelectedAFEPriority),
104 .pWriteBuffer = (uint8* const)SelectedAFEPriority
105 },
106 {
107 .offset = 0,
108 .nByteWrite = sizeof(SelectedMBoxPriority),
109 .pWriteBuffer = (uint8* const)SelectedMBoxPriority
110 },
111 {
112 .offset = 0,
113 .nByteWrite = sizeof(WakeApplication),
114 .pWriteBuffer = (uint8* const)WakeApplication
115 }
116 };
117
118 const mma955x_Command_t const MMA955x_StartDataSequence[] =
119 {
120 {
121 .offset = 0,
122 .nByteWrite = sizeof(LegacyMode),
123 .pWriteBuffer = (uint8* const)LegacyMode
124 }
125 };
126
127 const mma955x_Command_t const MMA955x_StopDataSequence[] =
128 {
129 {
130 .offset = 0,
131 .nByteWrite = sizeof(NormalMode),
132 .pWriteBuffer = (uint8* const)NormalMode
133 }
134 };
135
136 const mma955x_Command_t const MMA955x_ShutdownDataSequence[] =
137 {
138 {
139 .offset = 0,
140 .nByteWrite = sizeof(SleepApplication),
141 .pWriteBuffer = (uint8* const)SleepApplication
142 }
143 };
144
145 const mma955x_Command_t const MMA955x_ReadConfigurationSequence[] =
146 {
147 {
148 .offset = 0,
149 .nByteWrite = sizeof(ReadPedometerConfiguration),
150 .pWriteBuffer = (uint8* const)ReadPedometerConfiguration
151 }
152 };
153
154 const mma955x_Command_t const MMA955x_WriteConfigurationSequence[] =
155 {
156 {
157 .offset = 0,
158 .nByteWrite = sizeof(WritePedometerConfiguration),
159 .pWriteBuffer = (uint8* const)WritePedometerConfiguration
160 }
161 };
162
163 const mma955x_Command_t const MMA955x_ReadPeadometerDataSequence[] =
164 {
165 {
166 .offset = 0,
167 .nByteWrite = sizeof(ReadPedometerData),
168 .pWriteBuffer = (uint8* const)ReadPedometerData
169 }
170 };
171
172 mma955x_Sensor_Specific_Settings_t MMA955x_1_Sensor_Specific_Config =
173 {
174 .sampleDataOffset = MMA955x_1_SAMPLE_OFFSET,
175 .sampleDataSize = MMA955x_1_SAMPLE_SIZE,
176 .commandReadOffset = MMA955x_1_CONFIG_REGISTER_READ_OFFSET,
177 .commandReadSize = MMA955x_1_CONFIG_REGISTER_SIZE,
178 .engFloatConversionFactor = MMA955x_1_ACC_FLOAT_CONVERSION_FACTOR_8g,
179 .engFixedTotalWidth = 32,
180 .engFixedIntegerWidth = 16,
181 .engFixedSignBit = 1,
182 .writeConfigCommands = { .numCommands=sizeof(MMA955x_WriteConfigurationSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_WriteConfigurationSequence },
183 .readConfigCommands = { .numCommands=sizeof(MMA955x_ReadConfigurationSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_ReadConfigurationSequence },
184 .initializeCommands = { .numCommands=sizeof(MMA955x_InitializeSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_InitializeSequence },
185 .validateSettingsCommands = { .numCommands=0, .commands=NULL },
186 .configureCommands = { .numCommands=sizeof(MMA955x_ConfigureSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_ConfigureSequence },
187 .startDataCommands = { .numCommands=sizeof(MMA955x_StartDataSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_StartDataSequence },
188 .endDataCommands = { .numCommands=sizeof(MMA955x_StopDataSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_StopDataSequence },
189 .calibrateCommands = { .numCommands=0, .commands=NULL },
190 .shutdownCommands = { .numCommands=sizeof(MMA955x_ShutdownDataSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_ShutdownDataSequence },
191 .getPedometerDataCommands = { .numCommands=sizeof(MMA955x_ReadPeadometerDataSequence)/sizeof(mma955x_Command_t), .commands=MMA955x_ReadPeadometerDataSequence }
192 };
193
194 /*!
195 * @brief This creates the sensor adapter instance for the target sensor.
196 *
197 */
198 const isf_dsa_Adapter_t MMA955x_1_Adapter =
199 {
200 .devInfo.pSupportedSensorTypes = mma955x_SupportedSensorTypes,
201 .devInfo.pSupportedSensorDataTypes = mma955x_SupportedDataTypes,
202 .devInfo.nNativeDataSetSize = sizeof(mma955x_DataBuffer_t),
203 .control.Initialize = &fsl_mma955x_Initialize,
204 .control.ValidateSettings = &fsl_mma955x_ValidateSettings,
205 .control.Configure = &fsl_mma955x_Configure,
206 .control.StartData = &fsl_mma955x_StartData,
207 .control.EndData = &fsl_mma955x_EndData,
208 .control.Calibrate = &fsl_mma955x_Calibrate,
209 .control.Shutdown = &fsl_mma955x_Shutdown,
210 .control.Convert = &fsl_mma955x_Convert
211 };
212
213 const i2c_device_t MMA955x_1_DeviceInfo =
214 {
215 .baudRate_kbps = 400, // default baud rate (kbps).
216 .address = 76 // instance specific device address.
217 };
218
219
220
221 void mma955xSetSamplingRate(uint32 samplePeriod)
222 {
223 uint8 offset = 11; // The Min Value for period is 2048 2^(11) at 488.28Hz
224
225 while((samplePeriod >> offset++) > 1);
226 // The fifth byte is the setting byte to be written.
227 SelectedSampleRate[4] = SampleRates[offset-12];
228 SelectedAFEPriority[4] = ApplicationPriorities[offset-12];
229 SelectedMBoxPriority[4] = ApplicationPriorities[offset-12];
230 }
231
232 /* END MMA955x_1. */
233
234 /*!
235 ** @}
236 */
237 /*
238 ** ###################################################################
239 **
240 ** This file was created by Processor Expert 10.5 [05.21]
241 ** for the Freescale Kinetis series of microcontrollers.
242 **
243 ** ###################################################################
244 */
FSRange_4g
const uint8 const FSRange_4g[]
Definition: MMA955x_1.c:67
fsl_mma955x_EndData
isf_dsa_status_t fsl_mma955x_EndData(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma955x_i2cspi_pedo.c:313
mma955x_Sensor_Specific_Settings_t
Definition: mma955x.h:70
MMA955x_1_CONFIG_REGISTER_READ_OFFSET
#define MMA955x_1_CONFIG_REGISTER_READ_OFFSET
Definition: MMA955x_1.h:53
uint8
unsigned char uint8
Definition: isf_types.h:76
MMA955x_InitializeSequence
const mma955x_Command_t const MMA955x_InitializeSequence[]
Definition: MMA955x_1.c:80
fsl_mma955x_Configure
isf_dsa_status_t fsl_mma955x_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
Definition: fsl_mma955x_i2cspi_pedo.c:180
MMA955x_1_ConfigRegisterBuffer
uint8 MMA955x_1_ConfigRegisterBuffer[MMA955x_1_CONFIG_REGISTER_SIZE]
Definition: MMA955x_1.c:42
fsl_mma955x_Calibrate
isf_dsa_status_t fsl_mma955x_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
Definition: fsl_mma955x_i2cspi_pedo.c:380
mma955x_Command_t::offset
int32 offset
Definition: mma955x.h:59
NormalMode
const uint8 const NormalMode[]
Definition: MMA955x_1.c:72
FSRange_2g
const uint8 const FSRange_2g[]
Definition: MMA955x_1.c:66
MMA955x_ConfigureSequence
const mma955x_Command_t const MMA955x_ConfigureSequence[]
Definition: MMA955x_1.c:89
fsl_mma955x_Convert
isf_dsa_status_t fsl_mma955x_Convert(volatile isf_SensorHandle_t *pSensorHandle, isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType, void *pNativeSample, void *pConvertedSample, int32 *numBytes)
This function converts the raw sample data to the desired output type.
Definition: fsl_mma955x_i2cspi_pedo.c:529
WakeApplication
const uint8 const WakeApplication[]
Definition: MMA955x_1.c:70
MMA955x_1_Sensor_Specific_Config
mma955x_Sensor_Specific_Settings_t MMA955x_1_Sensor_Specific_Config
This allows access to the sensor specific configuration for the target sensor.
Definition: MMA955x_1.c:172
mma955xSetSamplingRate
void mma955xSetSamplingRate(uint32 samplePeriod)
Definition: MMA955x_1.c:221
MMA955x_1_CONFIG_REGISTER_SIZE
#define MMA955x_1_CONFIG_REGISTER_SIZE
Definition: MMA955x_1.h:54
fsl_mma955x_Initialize
isf_dsa_status_t fsl_mma955x_Initialize(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma955x_i2cspi_pedo.c:57
fsl_mma955x_ValidateSettings
isf_dsa_status_t fsl_mma955x_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSubSettings)
Definition: fsl_mma955x_i2cspi_pedo.c:148
WritePedometerConfiguration
const uint8 const WritePedometerConfiguration[]
Definition: MMA955x_1.c:78
SleepApplication
const uint8 const SleepApplication[]
Definition: MMA955x_1.c:73
isf_dsa_Adapter_st::devInfo
isf_dsa_DeviceInfoBlock_t devInfo
Definition: isf_dsa_adapter.h:146
fsl_mma955x_Shutdown
isf_dsa_status_t fsl_mma955x_Shutdown(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma955x_i2cspi_pedo.c:400
LegacyMode
const uint8 const LegacyMode[]
Definition: MMA955x_1.c:71
mma955x_DataBuffer_t
This structure defines the Pedometer sample data buffer format.
Definition: fsl_mma955x_i2cspi_pedo.h:28
MMA955x_ReadPeadometerDataSequence
const mma955x_Command_t const MMA955x_ReadPeadometerDataSequence[]
Definition: MMA955x_1.c:163
SelectedAFEPriority
uint8 SelectedAFEPriority[]
Definition: MMA955x_1.c:46
isf_util.h
The isf_util.h file contains the utility method declarations and macros.
mma955x_Sensor_Specific_Settings_t::sampleDataOffset
const int32 sampleDataOffset
Definition: mma955x.h:72
isf_dsa_Adapter_st
This defines the DSA adapter structure required for static initialization of the concrete instance of...
Definition: isf_dsa_adapter.h:144
ApplicationPriorities
const uint8 ApplicationPriorities[]
Definition: MMA955x_1.c:57
MMA955x_1_Adapter
const isf_dsa_Adapter_t MMA955x_1_Adapter
This creates the sensor adapter instance for the target sensor.
Definition: MMA955x_1.c:198
isf_dsa_DeviceInfoBlock_st::pSupportedSensorTypes
isf_SensorTypes_t * pSupportedSensorTypes
Definition: isf_dsa_adapter.h:70
ReadPedometerConfiguration
const uint8 const ReadPedometerConfiguration[]
Definition: MMA955x_1.c:77
FSRange_8g
const uint8 const FSRange_8g[]
Definition: MMA955x_1.c:68
MMA955x_1_SAMPLE_SIZE
#define MMA955x_1_SAMPLE_SIZE
Definition: MMA955x_1.h:52
SampleRates
const uint8 SampleRates[]
Definition: MMA955x_1.c:49
MMA955x_ShutdownDataSequence
const mma955x_Command_t const MMA955x_ShutdownDataSequence[]
Definition: MMA955x_1.c:136
MMA955x_1_DeviceInfo
const i2c_device_t MMA955x_1_DeviceInfo
This allows access to the sensor communications specific configuration.
Definition: MMA955x_1.c:213
SelectedSampleRate
uint8 SelectedSampleRate[]
Definition: MMA955x_1.c:45
MMA955x_StopDataSequence
const mma955x_Command_t const MMA955x_StopDataSequence[]
Definition: MMA955x_1.c:127
MMA955x_1_ACC_FLOAT_CONVERSION_FACTOR_8g
#define MMA955x_1_ACC_FLOAT_CONVERSION_FACTOR_8g
Definition: MMA955x_1.h:59
MMA955x_1_SAMPLE_OFFSET
#define MMA955x_1_SAMPLE_OFFSET
Definition: MMA955x_1.h:51
MMA955x_1.h
mma955x_SupportedDataTypes
isf_SensorDataTypes_t mma955x_SupportedDataTypes[]
Definition: fsl_mma955x_i2cspi_pedo.c:29
ReadPedometerData
const uint8 const ReadPedometerData[]
Definition: MMA955x_1.c:76
SelectedMBoxPriority
uint8 SelectedMBoxPriority[]
Definition: MMA955x_1.c:47
mma955x_Command_t
Definition: mma955x.h:57
MMA955x_StartDataSequence
const mma955x_Command_t const MMA955x_StartDataSequence[]
Definition: MMA955x_1.c:118
fsl_mma955x_StartData
isf_dsa_status_t fsl_mma955x_StartData(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma955x_i2cspi_pedo.c:252
MBoxQRDataXYZ
const uint8 const MBoxQRDataXYZ[]
Definition: MMA955x_1.c:74
mma955x_SupportedSensorTypes
isf_SensorTypes_t mma955x_SupportedSensorTypes[]
Supported sensor and data types.
Definition: fsl_mma955x_i2cspi_pedo.c:28
uint32
unsigned long int uint32
Definition: isf_types.h:78
MMA955x_ReadConfigurationSequence
const mma955x_Command_t const MMA955x_ReadConfigurationSequence[]
Definition: MMA955x_1.c:145
MMA955x_WriteConfigurationSequence
const mma955x_Command_t const MMA955x_WriteConfigurationSequence[]
Definition: MMA955x_1.c:154
- © Freescale Semiconductor, Inc. 2016. All Rights Reserved.