46 #include "fsl_lptmr.h" 47 #include "clock_config.h" 52 #include "Driver_I2C.h" 53 #include "Driver_USART.h" 58 #include "issdk_hal.h" 59 #include "gpio_driver.h" 63 #include "auto_detection_service.h" 69 #define mma8491q_en_callback LPTMR0_IRQHandler 71 #define MMA8491Q_T_ODR_ms 100U 72 #define MMA8491Q_STREAM_DATA_SIZE 13 74 #define APPLICATION_NAME "MMA8491 Accelerometer Demo" 76 #define APPLICATION_VERSION "2.5" 78 #define LPTMR_T_CORRECTION_ms 2 99 .interruptMode = kPORT_InterruptOrDMADisabled,
100 .portPinConfig = {0},
101 .portPinConfig.mux = kPORT_MuxAsGpio,
113 uint32_t delay, count, systemCoreClock;
115 systemCoreClock = CLOCK_GetCoreSysClkFreq();
117 for(count=0;count<delay;count++)
126 LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
133 lptmr_config_t lptmrConfig;
135 LPTMR_GetDefaultConfig(&lptmrConfig);
136 LPTMR_Init(LPTMR0, &lptmrConfig);
137 LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
138 EnableIRQ(LPTMR0_IRQn);
141 LPTMR_SetTimerPeriod(LPTMR0, MSEC_TO_COUNT((samplingInterval-
LPTMR_T_CORRECTION_ms), CLOCK_GetFreq(kCLOCK_LpoClk)));
146 uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse,
size_t *hostMsgSize,
size_t respBufferSize)
148 bool success =
false;
163 if (respBufferSize >= boardNameLen + shieldNameLen + appNameLen + 3)
172 hostResponse[*hostMsgSize] = appNameLen;
175 memcpy(hostResponse + *hostMsgSize,
embAppName, appNameLen);
176 *hostMsgSize += appNameLen;
178 hostResponse[*hostMsgSize] = boardNameLen;
181 memcpy(hostResponse + *hostMsgSize,
boardString, boardNameLen);
182 *hostMsgSize += boardNameLen;
184 hostResponse[*hostMsgSize] = shieldNameLen;
187 memcpy(hostResponse + *hostMsgSize,
shieldString, shieldNameLen);
188 *hostMsgSize += shieldNameLen;
198 switch (hostCommand[0])
203 LPTMR_StartTimer(LPTMR0);
212 LPTMR_StopTimer(LPTMR0);
265 if (ARM_DRIVER_OK != status)
271 status = pI2cDriver->PowerControl(ARM_POWER_FULL);
272 if (ARM_DRIVER_OK != status)
278 status = pI2cDriver->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
279 if (ARM_DRIVER_OK != status)
286 if (ARM_DRIVER_OK != status)
292 status = pUartDriver->PowerControl(ARM_POWER_FULL);
293 if (ARM_DRIVER_OK != status)
300 if (ARM_DRIVER_OK != status)
360 if (ARM_DRIVER_OK != status)
376 rawData.
accel[0] = ((int16_t)data[0] << 8) | (data[1]);
377 rawData.
accel[0] /= 4;
378 rawData.
accel[1] = ((int16_t)data[2] << 8) | (data[3]);
379 rawData.
accel[1] /= 4;
380 rawData.
accel[2] = ((int16_t)data[4] << 8) | (data[5]);
381 rawData.
accel[2] /= 4;
bool process_host_command(uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
uint32_t BOARD_SystickElapsedTime_us(int32_t *pStart)
Function to compute the Elapsed Time.
const registerreadlist_t cMma8491qStatus[]
Address of Status Register.
ARM_DRIVER_I2C * pCommDrv
char boardString[ADS_MAX_STRING_LENGTH]
#define MMA8491Q_STATUS_ZYXDR_MASK
#define APPLICATION_NAME
Unique Name for this application which should match the target GUI pkg name.
#define HOST_PRO_CMD_W_CFG_TAG
#define LPTMR_T_CORRECTION_ms
#define HOST_S_SIGNAL_EVENT
char shieldString[ADS_MAX_STRING_LENGTH]
void Host_IO_Receive(host_cmd_proc_fn_t process_host_command, uint8_t encoding)
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
#define BOARD_BootClockRUN
int main(void)
Main function.
#define MMA8491Q_DATA_SIZE
uint8_t data[FXLS8962_DATA_SIZE]
void(* toggle_pin)(pinID_t aPinId)
The GPIO Configuration KSDK.
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 ADS_MAX_STRING_LENGTH
#define HOST_PRO_INT_DEV_TAG
uint8_t streamingPacket[STREAMING_HEADER_LEN+FXLS8962_STREAM_DATA_SIZE]
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
#define HOST_PRO_INT_CMD_TAG
Bit aligned values for Host Protocol Interface IDs (Bits 5-6).
registerDeviceInfo_t deviceInfo
#define __END_READ_DATA__
uint32_t(* read_pin)(pinID_t aPinId)
#define MMA8491Q_STREAM_DATA_SIZE
volatile bool bStreamingEnabled
#define APPLICATION_VERSION
Version to distinguish between instances the same application based on target Shield and updates...
gpioHandleKSDK_t GREEN_LED
gpioConfigKSDK_t gGpioConfigInPins
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_en_callback
gpio_pin_config_t pinConfig
void Host_IO_Add_ISO_Header(uint8_t streamID, uint8_t *pStreamingPacket, size_t sizePayload)
void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding)
void(* set_pin)(pinID_t aPinId)
void(* clr_pin)(pinID_t aPinId)
void mma8491q_timer_fwk_init(uint32_t samplingInterval)
void BOARD_SystickEnable(void)
Function to enable systicks framework.
const registerreadlist_t cMma8491qOutput[]
Address and size of Raw Acceleration Data.
void MMA8491Q_I2C_SetIdleTask(mma8491q_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
This defines the function pointers and sensor specific information.
#define I2C_S_DEVICE_INDEX
GENERIC_DRIVER_GPIO * pGpioDriver
The mma8491q_drv.h file describes the MMA8491Q driver interface and structures.
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
#define BOARD_DEBUG_UART_BAUDRATE
volatile bool bMma8491qReady
Access structure of the GPIO Driver.
void BOARD_SystickStart(int32_t *pStart)
Function to Record the Start systick.
#define MMA8491Q_T_ODR_ms
void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength)
The function to register Application Name and initialte ADS.
fxls8962_acceldataUser_t rawData
uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress)
char embAppName[ADS_MAX_STRING_LENGTH]
#define MMA8491Q_T_ON_TYPICAL
This structure defines the Read command List.
The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
This structure defines the mma8491q data buffer.
#define STREAMING_HEADER_LEN
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
volatile bool bMma849qDataReady
#define I2C_S_SIGNAL_EVENT