Commit 23b06ebd authored by Maureen Helm's avatar Maureen Helm Committed by Anas Nashif
Browse files

samples: Add fxos8700 sample application



Adds a fxos8700 sample application that uses the sensor data ready
trigger to periodically print accelerometer and magnetometer data.

Change-Id: I43fef6cd6090b58d8d0168a25558a3a05781ea5d
Signed-off-by: default avatarMaureen Helm <maureen.helm@nxp.com>
parent 4d9cc669
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
# Makefile - fxos8700 sample
#
# Copyright (c) 2016, Freescale Semiconductor, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

BOARD ?= frdm_k64f
CONF_FILE ?= prj.conf

include $(ZEPHYR_BASE)/Makefile.inc
+32 −0
Original line number Diff line number Diff line
Title: fxos8700

Description:

A sensor application that demonstrates how to use the fxos8700 data ready
interrupt to read accelerometer/magnetometer data synchronously.

--------------------------------------------------------------------------------

Building and Running Project:

This project outputs sensor data to the console. It requires an fxos8700
sensor, which is present on the frdm_k64f and hexiwear_k64 boards. It does not
work on QEMU.

    make BOARD=frdm_k64f
or
    make BOARD=hexiwear_k64

--------------------------------------------------------------------------------

Sample Output:

AX=  9.835380 AY=  0.009576 AZ=  0.383072 MX=  0.015000 MY=  0.509000 MZ=  1.346000
AX=  9.816226 AY=  0.038307 AZ=  0.497993 MX=  0.029000 MY=  0.522000 MZ=  1.350000
AX=  9.844957 AY=  0.067037 AZ=  0.430956 MX=  0.025000 MY=  0.518000 MZ=  1.353000
AX=  9.835380 AY=  0.038307 AZ=  0.497993 MX=  0.026000 MY=  0.507000 MZ=  1.352000
AX=  9.825803 AY=  0.057460 AZ=  0.421379 MX=  0.030000 MY=  0.502000 MZ=  1.342000
AX=  9.816226 AY=  0.019153 AZ=  0.478840 MX=  0.017000 MY=  0.523000 MZ=  1.318000
AX=  9.835380 AY=  0.000000 AZ=  0.507570 MX=  0.014000 MY=  0.502000 MZ=  1.367000

<repeats endlessly>
+8 −0
Original line number Diff line number Diff line
CONFIG_STDOUT_CONSOLE=y
CONFIG_SYS_LOG=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_FXOS8700=y
CONFIG_FXOS8700_SYS_LOG_LEVEL=4
CONFIG_FXOS8700_MODE_HYBRID=y
CONFIG_FXOS8700_TRIGGER_OWN_THREAD=y
+18 −0
Original line number Diff line number Diff line
# Makefile - fxos8700 sample
#
# Copyright (c) 2016, Freescale Semiconductor, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

obj-y = main.o
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2016 Freescale Semiconductor, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <zephyr.h>
#include <sensor.h>
#include <stdio.h>

static void trigger_handler(struct device *dev, struct sensor_trigger *trigger)
{
	struct sensor_value accel[3];
	struct sensor_value magn[3];

	sensor_sample_fetch(dev);

	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_ANY, accel);
	sensor_channel_get(dev, SENSOR_CHAN_MAGN_ANY, magn);

	/* Print accel x,y,z and mag x,y,z data */
	printf("AX=%3d.%06d AY=%3d.%06d AZ=%3d.%06d "
	       "MX=%3d.%06d MY=%3d.%06d MZ=%3d.%06d\n",
		accel[0].val1, accel[0].val2,
		accel[1].val1, accel[1].val2,
		accel[2].val1, accel[2].val2,
		magn[0].val1, magn[0].val2,
		magn[1].val1, magn[1].val2,
		magn[2].val1, magn[2].val2
	      );
}

void main(void)
{
	struct device *dev = device_get_binding(CONFIG_FXOS8700_NAME);

	if (dev == NULL) {
		printf("Could not get fxos8700 device\n");
		return;
	}

	struct sensor_trigger trig = {
		.type = SENSOR_TRIG_DATA_READY,
		.chan = SENSOR_CHAN_ACCEL_ANY,
	};

	if (sensor_trigger_set(dev, &trig, trigger_handler)) {
		printf("Could not set trigger\n");
		return;
	}
}
Loading