16 #include "clock_config.h" 18 #include "fsl_debug_console.h" 21 #include "fsl_common.h" 22 #include "freemaster.h" 23 #include "freemaster_serial_uart.h" 26 #include "Driver_I2C.h" 29 #include "issdk_hal.h" 30 #include "gpio_driver.h" 37 #define MMA865x_NUM_REGISTERS (MMA865x_OFF_Z + 1) 38 #define FF_A_FFMT_THS (0x08) 39 #define A_FFMT_COUNT (0x18) 40 #define PL_COUNT (0x15) 41 #define ASLP_COUNTER (0x07) 42 #define ACCEL_2G_SENS (0.000976) 43 #define ACCEL_4G_SENS (0.001953) 44 #define ACCEL_8G_SENS (0.003906) 46 #define RAW_ACCEL_DATA_SIZE (6U) 47 #define MAX8BITSTORAGE (255U) 178 static FMSTR_U8 recBuffer[1024*10];
191 static void init_freemaster_uart(
void);
291 FMSTR_TSA_RO_VAR(rawData, FMSTR_TSA_USERTYPE(mma865x_accelmagdata_t))
297 FMSTR_TSA_TABLE_END()
299 FMSTR_TSA_TABLE_LIST_BEGIN()
300 FMSTR_TSA_TABLE(main_table)
301 FMSTR_TSA_TABLE_LIST_END()
314 recBuffCfg.name =
"MMA865x 3-Axis Accelerometer Data";
326 uint16_t ffmt_incr = 0;
327 uint16_t pulse_incr = 0;
328 uint16_t orient_incr = 0;
329 uint16_t vecm_incr = 0;
349 init_freemaster_uart();
353 if (ARM_DRIVER_OK != status)
359 status = I2Cdrv->PowerControl(ARM_POWER_FULL);
360 if (ARM_DRIVER_OK != status)
366 status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
367 if (ARM_DRIVER_OK != status)
485 rawData.
accel[0] /= 16;
487 rawData.
accel[1] /= 16;
489 rawData.
accel[2] /= 16;
499 else if (regdata == 2)
509 registers.
accel[0] = (float) (rawData.
accel[0] * sensitivity);
510 registers.
accel[1] = (float) (rawData.
accel[1] * sensitivity);
511 registers.
accel[2] = (float) (rawData.
accel[2] * sensitivity);
558 else if((regdata & MMA865x_INT_SOURCE_SRC_FF_MT_MASK) == 0x04)
570 if (orient_incr == 1)
726 offnoiseptr->
offx = 0.0;
727 offnoiseptr->
offy = 0.0;
728 offnoiseptr->
offz = 0.0;
729 offnoiseptr->
rmsx = 0.0;
730 offnoiseptr->
rmsy = 0.0;
731 offnoiseptr->
rmsz = 0.0;
741 static uint16_t cntr=0;
745 static float xx[
N], yy[
N], zz[
N];
746 static float xm[
N], ym[
N], zm[
N];
747 static float xsq[
N], ysq[
N], zsq[
N];
749 static float sumx=0.0;
750 static float sumy=0.0;
751 static float sumz=0.0;
761 am[0]=rawData->
accel[0]*sens;
762 am[1]=rawData->
accel[1]*sens;
763 am[2]=rawData->
accel[2]*sens;
783 offnoiseptr->
offx=0-sumx;
784 offnoiseptr->
offy=0-sumy;
785 offnoiseptr->
offz=1-sumz;
806 offnoiseptr->
rmsx=pow(stdx,0.5);
807 offnoiseptr->
rmsy=pow(stdy,0.5);
808 offnoiseptr->
rmsz=pow(stdz,0.5);
815 sumx = sumy = sumz = 0;
816 stdx = stdy = stdz = 0;
823 static void init_freemaster_uart(
void)
825 uart_config_t config;
836 UART_GetDefaultConfig(&config);
837 config.baudRate_Bps = 115200U;
838 config.enableTx =
false;
839 config.enableRx =
false;
844 FMSTR_SerialSetBaseAddress((UART_Type*)BOARD_DEBUG_UART_BASEADDR);
846 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 853 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 871 #if defined __CORTEX_M && (__CORTEX_M == 4U)
const registerwritelist_t Mma865x_Config[]
Prepare the register write list to configure MMA865x in non-FIFO and ISR mode.
#define MMA865x_CTRL_REG1_DR_MASK
This structure defines the Write command List.
This defines the sensor specific information.
void offset_noise_init(mma865x_offset_noise_t *offnoiseptr)
Function to initialize offset noise measurement.
#define MMA865x_INT_SOURCE_SRC_LNDPRT_MASK
#define MMA865x_CTRL_REG4_INT_EN_PULSE_EN
#define MMA865x_XYZ_DATA_CFG_FS_MASK
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
#define MMA865x_CTRL_REG5_INT_CFG_DRDY_INT1
#define MMA865x_FF_MT_CFG_XEFE_EN
FMSTR_TSA_TABLE_BEGIN(main_table)
Target Side Addressable (TSA) table created for this application.
uint8_t trigger_accel_offnoise
const registerreadlist_t cMMA865x_pl_status[]
Prepare the register read for PL Status Register.
#define BOARD_DEBUG_UART_CLK_FREQ
int32_t update_dropdown_selection(mma865x_allregs_t *registers, uint8_t caller)
Function to update dropdown selection.
Access structure of the GPIO Driver.
const registerreadlist_t MMA865x_ALL_REG_READ[]
MMA865x register list to read all registers.
const registerreadlist_t cMMA865x_fs_src[]
Prepare the register read for FullScale range Register.
#define MMA865x_STATUS_ZYXDR_MASK
#define MMA865x_NUM_REGISTERS
#define __END_WRITE_DATA__
This structure defines offset and noise calculation parameters.
#define MMA865x_CTRL_REG3_IPOL_MASK
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define MMA865x_INT_SOURCE_SRC_PULSE_MASK
#define MMA865x_FF_MT_THS_DBCNTM_INC_CLR
int32_t MMA865x_I2C_ReadData(mma865x_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
#define MMA865x_CTRL_REG3_IPOL_ACTIVE_HIGH
mma865x_offset_noise_t offnoise_data
#define I2C_S_SIGNAL_EVENT
#define MMA865x_FF_MT_CFG_ZEFE_EN
FMSTR_REC_BUFF recBuffCfg
#define MMA865x_CTRL_REG4_INT_EN_FF_MT_EN
#define MMA865x_CTRL_REG2_MODS_MASK
#define BOARD_BootClockRUN
int32_t apply_register_read(mma865x_i2c_sensorhandle_t MMA8652drv, uint8_t offset, uint8_t *value)
Function to apply MMA8652 register read operation.
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
#define MMA865x_PULSE_CFG_XSPEFE_EN
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
GENERIC_DRIVER_GPIO * pGpioDriver
#define MMA865x_PULSE_CFG_ZSPEFE_EN
#define MMA865x_TRANSIENT_CFG_ZTEFE_EN
#define BOARD_UART_IRQ_HANDLER
int32_t MMA865x_I2C_Configure(mma865x_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
#define MMA865x_TRANSIENT_THS_DBCNTM_INC_CLR
#define __END_READ_DATA__
const registerreadlist_t cMMA865x_whoami[]
Prepare the register read for WHOAMI Register.
const registerreadlist_t cMMA865x_ffmt_src[]
Prepare the register read for FFMT Register.
The mma865x_drv.h file describes the MMA865x driver interface and structures.
void mma8652_isr_callback(void *pUserData)
ISR for MMA8652 data ready event.
#define MMA865x_CTRL_REG4_INT_EN_LNDPRT_EN
#define MMA865x_CTRL_REG4_INT_EN_DRDY_EN
#define MMA865x_TRANSIENT_CFG_XTEFE_EN
mma865x_allregs_t registers
#define BOARD_DEBUG_UART_BASEADDR
const registerreadlist_t cMMA865x_int_src[]
Prepare the register read for INT Status Register.
mma865x_acceldata_t rawData
void accel_off_noise(mma865x_acceldata_t *rawData, mma865x_offset_noise_t *offnoiseptr, float sens)
Function to measure accelerometer offset noise.
int32_t apply_register_write(mma865x_i2c_sensorhandle_t MMA8652drv, uint8_t offset, uint8_t value)
Function to apply MMA8652 register write operation.
void(* toggle_pin)(pinID_t aPinId)
#define MMA865x_PL_CFG_PL_EN_EN
#define MMA865x_CTRL_REG2_MODS_HR
uint8_t reg_addr[MMA865x_NUM_REGISTERS]
#define MMA865x_CTRL_REG4_INT_EN_TRANS_EN
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
#define MMA865x_TRANSIENT_CFG_YTEFE_EN
#define MMA865x_XYZ_DATA_CFG_FS_2G
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
This structure defines the Read command List.
This structure defines the mma865x raw data buffer.
#define MMA865x_PL_CFG_DBCNTM_CLEAR
#define MMA865x_INT_SOURCE_SRC_FF_MT_MASK
gpioHandleKSDK_t GREEN_LED
#define I2C_S_DEVICE_INDEX
int32_t apply_register_readall(mma865x_i2c_sensorhandle_t MMA8652drv)
Function to apply MMA8652 register read-all operation.
void MMA865x_I2C_SetIdleTask(mma865x_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
enum mma8652_operation_type mma865x_operation_type_t
Defines MMA8652 host operation types.
volatile bool bMma8652IntFlag
uint8_t readall_value[MMA865x_NUM_REGISTERS]
This structure defines the mma865x all registers metadata.
mma8652_operation_type
Defines MMA8652 host operation types.
void BOARD_InitDebugConsole(void)
#define MMA8652_WHOAMI_VALUE
int32_t MMA865x_I2C_Initialize(mma865x_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
#define MMA865x_FF_MT_CFG_OAE_FREEFALL
int main(void)
Main function.
#define MMA865x_PULSE_CFG_YSPEFE_EN
uint8_t complete_accel_offnoise
#define MMA865x_CTRL_REG1_DR_100HZ
#define MMA865x_FF_MT_CFG_YEFE_EN