20 #include "fsl_lptmr.h" 21 #include "clock_config.h" 26 #include "Driver_I2C.h" 27 #include "Driver_USART.h" 32 #include "issdk_hal.h" 33 #include "gpio_driver.h" 37 #include "auto_detection_service.h" 43 #define mma8491q_en_callback LPTMR0_IRQHandler 45 #define MMA8491Q_T_ODR_ms 100U 46 #define MMA8491Q_STREAM_DATA_SIZE 13 48 #define APPLICATION_NAME "MMA8491 Accelerometer Demo" 50 #define APPLICATION_VERSION "2.5" 52 #define LPTMR_T_CORRECTION_ms 2 73 .interruptMode = kPORT_InterruptOrDMADisabled,
75 .portPinConfig.mux = kPORT_MuxAsGpio,
87 uint32_t delay, count, systemCoreClock;
89 systemCoreClock = CLOCK_GetCoreSysClkFreq();
91 for(count=0;count<delay;count++)
100 LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
107 lptmr_config_t lptmrConfig;
109 LPTMR_GetDefaultConfig(&lptmrConfig);
110 LPTMR_Init(LPTMR0, &lptmrConfig);
111 LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
112 EnableIRQ(LPTMR0_IRQn);
115 LPTMR_SetTimerPeriod(LPTMR0, MSEC_TO_COUNT((samplingInterval-
LPTMR_T_CORRECTION_ms), CLOCK_GetFreq(kCLOCK_LpoClk)));
120 uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse,
size_t *hostMsgSize,
size_t respBufferSize)
122 bool success =
false;
137 if (respBufferSize >= boardNameLen + shieldNameLen + appNameLen + 3)
146 hostResponse[*hostMsgSize] = appNameLen;
149 memcpy(hostResponse + *hostMsgSize,
embAppName, appNameLen);
150 *hostMsgSize += appNameLen;
152 hostResponse[*hostMsgSize] = boardNameLen;
155 memcpy(hostResponse + *hostMsgSize,
boardString, boardNameLen);
156 *hostMsgSize += boardNameLen;
158 hostResponse[*hostMsgSize] = shieldNameLen;
161 memcpy(hostResponse + *hostMsgSize,
shieldString, shieldNameLen);
162 *hostMsgSize += shieldNameLen;
172 switch (hostCommand[0])
177 LPTMR_StartTimer(LPTMR0);
186 LPTMR_StopTimer(LPTMR0);
239 if (ARM_DRIVER_OK != status)
245 status = pI2cDriver->PowerControl(ARM_POWER_FULL);
246 if (ARM_DRIVER_OK != status)
252 status = pI2cDriver->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
253 if (ARM_DRIVER_OK != status)
260 if (ARM_DRIVER_OK != status)
266 status = pUartDriver->PowerControl(ARM_POWER_FULL);
267 if (ARM_DRIVER_OK != status)
274 if (ARM_DRIVER_OK != status)
334 if (ARM_DRIVER_OK != status)
350 rawData.
accel[0] = ((int16_t)data[0] << 8) | (data[1]);
351 rawData.
accel[0] /= 4;
352 rawData.
accel[1] = ((int16_t)data[2] << 8) | (data[3]);
353 rawData.
accel[1] /= 4;
354 rawData.
accel[2] = ((int16_t)data[4] << 8) | (data[5]);
355 rawData.
accel[2] /= 4;
void(* set_pin)(pinID_t aPinId)
char embAppName[ADS_MAX_STRING_LENGTH]
uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress)
This defines the function pointers and sensor specific information.
The GPIO Configuration KSDK.
void Host_IO_Receive(host_cmd_proc_fn_t process_host_command, uint8_t encoding)
volatile bool bMma849qDataReady
#define APPLICATION_NAME
Unique Name for this application which should match the target GUI pkg name.
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
uint32_t(* read_pin)(pinID_t aPinId)
volatile bool bStreamingEnabled
ARM_DRIVER_I2C * pCommDrv
#define HOST_PRO_CMD_W_CFG_TAG
Access structure of the GPIO Driver.
#define APPLICATION_VERSION
Version to distinguish between instances the same application based on target Shield and updates...
gpioConfigKSDK_t gGpioConfigInPins
void(* clr_pin)(pinID_t aPinId)
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define HOST_S_SIGNAL_EVENT
void MMA8491Q_I2C_SetIdleTask(mma8491q_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
gpio_pin_config_t pinConfig
#define I2C_S_SIGNAL_EVENT
const registerreadlist_t cMma8491qStatus[]
Address of Status Register.
char boardString[ADS_MAX_STRING_LENGTH]
void Host_IO_Add_ISO_Header(uint8_t streamID, uint8_t *pStreamingPacket, size_t sizePayload)
#define BOARD_DEBUG_UART_BAUDRATE
#define MMA8491Q_STREAM_DATA_SIZE
#define BOARD_BootClockRUN
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
int main(void)
Main function.
registerDeviceInfo_t deviceInfo
uint8_t streamingPacket[STREAMING_HEADER_LEN+FXLS8962_STREAM_DATA_SIZE]
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
const registerreadlist_t cMma8491qOutput[]
Address and size of Raw Acceleration Data.
void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding)
void BOARD_SystickStart(int32_t *pStart)
Function to Record the Start systick.
#define MMA8491Q_T_ON_TYPICAL
uint32_t BOARD_SystickElapsedTime_us(int32_t *pStart)
Function to compute the Elapsed Time.
This structure defines the mma8491q data buffer.
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
#define HOST_PRO_INT_DEV_TAG
void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength)
The function to register Application Name and initialte ADS.
int32_t MMA8491Q_I2C_ReadData(mma8491q_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
#define MMA8491Q_STATUS_ZYXDR_MASK
fxos8700_accelmagdata_t rawData
#define MMA8491Q_DATA_SIZE
The mma8491q_drv.h file describes the MMA8491Q driver interface and structures.
char shieldString[ADS_MAX_STRING_LENGTH]
int32_t MMA8491Q_I2C_Initialize(mma8491q_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress)
The interface function to initialize the sensor.
#define MMA8491Q_T_ODR_ms
void(* toggle_pin)(pinID_t aPinId)
#define ADS_MAX_STRING_LENGTH
void BOARD_SystickEnable(void)
Function to enable systicks framework.
#define STREAMING_HEADER_LEN
volatile bool bMma8491qReady
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
bool process_host_command(uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
This structure defines the Read command List.
gpioHandleKSDK_t GREEN_LED
#define I2C_S_DEVICE_INDEX
void mma8491q_timer_fwk_init(uint32_t samplingInterval)
#define LPTMR_T_CORRECTION_ms
#define HOST_PRO_INT_CMD_TAG
Bit aligned values for Host Protocol Interface IDs (Bits 5-6).
GENERIC_DRIVER_GPIO * pGpioDriver
#define mma8491q_en_callback