source "$APPSDIR/examples/slsiwifi/Kconfig"
source "$APPSDIR/examples/mqtt_test/Kconfig"
source "$APPSDIR/examples/eeprom_test/Kconfig"
+source "$APPSDIR/examples/sensorbd_demo/Kconfig"
endmenu
--- /dev/null
+config EXAMPLES_SENSORBOARD
+ bool "Sensor Board Example"
+ select GPIO
+ select S5J_GPIO
+ select SPI
+ select S5J_SPI
+ select SERIAL
+ select S5J_UART0
+ select S5J_UART1
+ select S5J_UART2
+ select S5J_UART3
+ select I2C
+ select I2C_USERIO
+ select S5J_I2C
+ select PWM
+ select S5J_PWM
+ default n
+ ---help---
+ Enable the Sensor Board Example
--- /dev/null
+###########################################################################
+#
+# Copyright 2016 Samsung Electronics All Rights Reserved.
+#
+# 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.
+#
+###########################################################################
+############################################################################
+# apps/examples/sensorbd/Makefile
+#
+# Copyright (C) 2008, 2010-2013 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# built-in application info
+
+APPNAME = sensorbd
+PRIORITY = SCHED_PRIORITY_DEFAULT
+STACKSIZE = 2048
+
+# Example
+
+ASRCS =
+CSRCS =
+CSRCS += $(wildcard examples/*.c)
+MAINSRC = sensorbd_main.c
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
+OBJS = $(AOBJS) $(COBJS)
+
+ifneq ($(CONFIG_BUILD_KERNEL),y)
+ OBJS += $(MAINOBJ)
+endif
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
+ifeq ($(WINTOOL),y)
+ BIN = ..\\..\\libapps$(LIBEXT)
+else
+ BIN = ../../libapps$(LIBEXT)
+endif
+endif
+
+ifeq ($(WINTOOL),y)
+ INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
+else
+ INSTALL_DIR = $(BIN_DIR)
+endif
+
+CONFIG_EXAMPLES_SENSORBOARD_PROGNAME ?= sensorbd$(EXEEXT)
+PROGNAME = $(CONFIG_EXAMPLES_SENSORBOARD_PROGNAME)
+
+ROOTDEPPATH = --dep-path .
+
+# Common build
+
+VPATH =
+
+all: .built
+.PHONY: clean depend distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+.built: $(OBJS)
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ @touch .built
+
+ifeq ($(CONFIG_BUILD_KERNEL),y)
+$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
+ @echo "LD: $(PROGNAME)"
+ $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
+ $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
+
+install: $(BIN_DIR)$(DELIM)$(PROGNAME)
+
+else
+install:
+
+endif
+
+context:
+
+.depend: Makefile $(SRCS)
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @touch $@
+
+depend: .depend
+
+clean:
+ $(call DELFILE, .built)
+ $(call CLEAN)
+
+distclean: clean
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+
+-include Make.dep
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/gpio_ledonoff.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <fcntl.h>
+#include <tinyara/gpio.h>
+
+static void gpio_write(int port, int value)
+{
+ static char buf[16];
+ snprintf(buf, 16, "/dev/gpio%d", port);
+ int fd = open(buf, O_RDWR);
+
+ int mode = value ? GPIO_DRIVE_PULLUP : GPIO_DRIVE_PULLDOWN;
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_IN);
+ ioctl(fd, GPIO_CMD_SET_DRIVE, mode);
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_OUT);
+ write(fd, (void *)&value, sizeof(int));
+
+ close(fd);
+}
+
+void ledonoff_main(int argc, char *argv[])
+{
+ int i, j, z, num, dim[7], result[7];
+ srand(time(NULL));
+ for (i = 0; i < 30; i++) {
+ num = rand() % 127;
+ printf("%03d: ", num);
+
+ for (j = 0; num > 0; j++) {
+ dim[j] = num % 2;
+ num = num / 2;
+ }
+ for (z = 0; z < 7; z++) {
+ result[z] = 0;
+ }
+ for (z = j - 1; z >= 0; z--) {
+ result[6 - z] = dim[z];
+ }
+
+ for (j = 0; j < 7; j++) {
+ printf("%d ", result[j]);
+
+ switch (j) {
+ case 0: gpio_write(51, result[j]); break;
+ case 1: gpio_write(52, result[j]); break;
+ case 2: gpio_write(53, result[j]); break;
+ case 3: gpio_write(54, result[j]); break;
+ case 4: gpio_write(55, result[j]); break;
+ case 5: gpio_write(39, result[j]); break;
+ case 6: gpio_write(41, result[j]); break;
+ }
+ }
+ printf("\n");
+
+ up_mdelay(500);
+ }
+ gpio_write(51, 0);
+ gpio_write(52, 0);
+ gpio_write(53, 0);
+ gpio_write(54, 0);
+ gpio_write(55, 0);
+ gpio_write(39, 0);
+ gpio_write(41, 0);
+}
\ No newline at end of file
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/gpio_loopback.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <fcntl.h>
+#include <tinyara/gpio.h>
+
+#define XGPIO1 30
+#define XGPIO2 31
+#define XGPIO3 32
+#define XGPIO8 37
+#define XGPIO9 38
+#define XGPIO11 40
+
+static int gpio_read(int port)
+{
+ int value = -1;
+ static char buf[16];
+ snprintf(buf, 16, "/dev/gpio%d", port);
+ int fd = open(buf, O_RDWR);
+
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_IN);
+ read(fd, (void *)&value, sizeof(int));
+
+ close(fd);
+ return value;
+}
+
+static void gpio_write(int port, int value)
+{
+ static char buf[16];
+ snprintf(buf, 16, "/dev/gpio%d", port);
+ int fd = open(buf, O_RDWR);
+
+ int mode = value ? GPIO_DRIVE_PULLUP : GPIO_DRIVE_PULLDOWN;
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_IN);
+ ioctl(fd, GPIO_CMD_SET_DRIVE, mode);
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_OUT);
+ write(fd, (void *)&value, sizeof(int));
+
+ close(fd);
+}
+
+void gpioloopback_main(int argc, char *argv[])
+{
+ int tc;
+ for (tc = 0; tc < 3; tc++) {
+ int nA = 0, nB = 0;
+ switch (tc) {
+ case 0: nA = XGPIO9; nB = XGPIO11; break;
+ case 1: nA = XGPIO8; nB = XGPIO2; break;
+ case 2: nA = XGPIO1; nB = XGPIO3; break;
+ default: break;
+ }
+
+ int readA, readB;
+ readA = gpio_read(nA);
+
+ if (readA == 0) {
+ gpio_write(nA, 1);
+
+ readA = gpio_read(nA);
+ readB = gpio_read(nB);
+
+ if (readA != readB) {
+ printf("gpio%d and gpio%d is not connect!\n", nA, nB);
+ gpio_write(nA, 0);
+ }
+ } else {
+ gpio_write(nA, 0);
+
+ readA = gpio_read(nA);
+ readB = gpio_read(nB);
+
+ if (readA != readB) {
+ printf("gpio%d and gpio%d is not connect!\n", nA, nB);
+ gpio_write(nA, 0);
+ }
+ }
+
+ printf("gpio%d and gpio%d is connect!\n", nA, nB);
+ gpio_write(nA, 0);
+ }
+}
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/gpio_starterled.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <fcntl.h>
+#include <tinyara/gpio.h>
+
+static int gpio_read(int port)
+{
+ int value = -1;
+ static char buf[16];
+ snprintf(buf, 16, "/dev/gpio%d", port);
+ int fd = open(buf, O_RDWR);
+
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_IN);
+ read(fd, (void *)&value, sizeof(int));
+
+ close(fd);
+ return value;
+}
+
+static void gpio_write(int port, int value)
+{
+ static char buf[16];
+ snprintf(buf, 16, "/dev/gpio%d", port);
+ int fd = open(buf, O_RDWR);
+
+ int mode = value ? GPIO_DRIVE_PULLUP : GPIO_DRIVE_PULLDOWN;
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_IN);
+ ioctl(fd, GPIO_CMD_SET_DRIVE, mode);
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_OUT);
+ write(fd, (void *)&value, sizeof(int));
+
+ close(fd);
+}
+
+void starterled_main(int argc, char *argv[])
+{
+ int i;
+ int r_led = 45;
+ int b_led = 49;
+ int r_but = 42;
+ int b_but = 44;
+
+ printf("Press R/B Test Button!\n");
+
+ for (i = 0; i < 30; i++) {
+ int r_read = gpio_read(r_but);
+ int b_read = gpio_read(b_but);
+
+ if (r_read == 0) {
+ gpio_write(r_led, 1);
+ } else if (r_read == 1) {
+ gpio_write(r_led, 0);
+ }
+
+ if (b_read == 0) {
+ gpio_write(b_led, 1);
+ } else if (r_read == 1) {
+ gpio_write(b_led, 0);
+ }
+
+ up_mdelay(500);
+ }
+ gpio_write(r_led, 0);
+ gpio_write(b_led, 0);
+}
\ No newline at end of file
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/gpio_switch.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <fcntl.h>
+#include <tinyara/gpio.h>
+
+static int gpio_read(int port)
+{
+ int value = -1;
+ static char buf[16];
+ snprintf(buf, 16, "/dev/gpio%d", port);
+ int fd = open(buf, O_RDWR);
+
+ ioctl(fd, GPIO_CMD_SET_DIRECTION, GPIO_DIRECTION_IN);
+ read(fd, (void *)&value, sizeof(int));
+
+ close(fd);
+ return value;
+}
+
+void switch_main(int argc, char *argv[])
+{
+ // XEINT0 ~ XEINT2
+ // gpio57 ~ gpio59
+
+ int i;
+ for (i = 0; i < 30; i++) {
+ if (gpio_read(57) == 0) {
+ printf("XEINT0 pressed\n");
+ }
+ if (gpio_read(58) == 0) {
+ printf("XEINT1 pressed\n");
+ }
+ if (gpio_read(59) == 0) {
+ printf("XEINT2 pressed\n");
+ }
+
+ up_mdelay(500);
+ }
+}
\ No newline at end of file
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/i2c_mpu9250.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <tinyara/i2c.h>
+
+#include "i2c_mpu9250.h"
+
+enum mpu9250_axis_e
+{
+ MPU9250_AXIS_X = 0,
+ MPU9250_AXIS_Y = 1,
+ MPU9250_AXIS_Z = 2,
+};
+
+static int mpu9250_initialize(void);
+
+static struct i2c_dev_s *i2c_dev;
+static struct i2c_config_s configs;
+
+uint8_t mpu9250_disable_mask[3] =
+{
+ MPU9250_DISABLE_XA_MASK,
+ MPU9250_DISABLE_YA_MASK,
+ MPU9250_DISABLE_ZA_MASK,
+};
+
+uint8_t mpu9250_accel_out[3] =
+{
+ MPU9250_ACCEL_XOUT_H,
+ MPU9250_ACCEL_YOUT_H,
+ MPU9250_ACCEL_ZOUT_H,
+};
+
+static uint32_t mpu9250_get_axis(uint8_t i)
+{
+ uint8_t data[2];
+ int ret;
+ uint8_t reg;
+ data[0] = 0;
+ data[1] = 0;
+
+ reg = MPU9250_PWR_MGMT_2;
+
+ ret = i2c_write(i2c_dev, &configs, ®, 1);
+ if (ret < 0) {
+ printf("i2c_write fail(%d)\n", ret);
+ return -ret;
+ }
+
+ up_mdelay(1);
+
+ ret = i2c_read(i2c_dev, &configs, data, 1);
+ if (ret < 0) {
+ printf("i2c_read fail(%d)\n", ret);
+ return -ret;
+ }
+
+ if (0 != (data[0] & mpu9250_disable_mask[i])) {
+ printf("Disabled (%d) axis(%d)\n", i, ret);
+ return 0;
+ }
+
+ up_mdelay(1);
+
+ reg = mpu9250_accel_out[i];
+
+ ret = i2c_write(i2c_dev, &configs, ®, 1);
+ if (ret < 0) {
+ printf("i2c_write fail(%d)\n", ret);
+ return -ret;
+ }
+
+ up_mdelay(1);
+
+ ret = i2c_read(i2c_dev, &configs, data, 2);
+
+ if (ret < 0) {
+ printf("i2c_read fail(%d)\n", ret);
+ return -ret;
+ }
+
+ return (uint16_t)(data[0] << 8) | data[1];
+}
+
+/****************************************************************************
+ * Name: mpu9250_initialize
+ ****************************************************************************/
+
+static int mpu9250_initialize(void)
+{
+ uint8_t data[2];
+ int ret;
+ data[0] = MPU9250_PWR_MGMT_1;
+ data[1] = 0x80;
+
+ ret = i2c_write(i2c_dev, &configs, data, 2);
+ if (ret < 0) {
+ printf("i2c_write fail(%d)\n", ret);
+ return -ret;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mpu9250_main
+ ****************************************************************************/
+
+int mpu9250_main(int argc, char *argv[])
+{
+ int i;
+ uint16_t data[3];
+
+ int port = 1;
+ i2c_dev = up_i2cinitialize(port);
+ if (i2c_dev == NULL) {
+ printf("i2ctest_main: up_i2cinitialize(i2c:%d) failed\n", port);
+ goto errout;
+ }
+
+ configs.frequency = 40000;
+ configs.address = MPU9250_ADDR;
+ configs.addrlen = 7;
+
+ mpu9250_initialize();
+
+ printf("ACC: %-10s%-10s%-10s\n", "X", "Y", "Z");
+
+ for (i = 0; i < 30; i++ ) {
+ data[0] = mpu9250_get_axis(MPU9250_AXIS_X);
+ if (data[0] < 0) {
+ break;
+ }
+
+ data[1] = mpu9250_get_axis(MPU9250_AXIS_Y);
+ if (data[1] < 0) {
+ break;
+ }
+
+ data[2] = mpu9250_get_axis(MPU9250_AXIS_Z);
+ if (data[2] < 0) {
+ break;
+ }
+
+ printf("ACC: %-10d%-10d%-10d\n", (int16_t)data[0], (int16_t)data[1], (int16_t)data[2]);
+
+ up_mdelay(500);
+ }
+
+ return OK;
+
+errout:
+ fflush(stdout);
+ return ERROR;
+}
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/i2c_mpu9250.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_EXAMPLES_SENSORBD_EXAMPLES_I2C_MPU9250_H
+#define __APPS_EXAMPLES_SENSORBD_EXAMPLES_I2C_MPU9250_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MPU9250_ADDR (0x68)
+
+#define MPU9250_DEFAULT_ADDRESS 0xD1
+#define MPU9250_ALT_DEFAULT_ADDRESS 0xD2
+
+#define MPU9250_SELF_TEST_X_GYRO 0x00
+#define MPU9250_SELF_TEST_Y_GYRO 0x01
+#define MPU9250_SELF_TEST_Z_GYRO 0x02
+
+#define MPU9250_SELF_TEST_X_ACCEL 0x0D
+#define MPU9250_SELF_TEST_Y_ACCEL 0x0E
+#define MPU9250_SELF_TEST_Z_ACCEL 0x0F
+
+#define MPU9250_XG_OFFSET_H 0x13
+#define MPU9250_XG_OFFSET_L 0x14
+#define MPU9250_YG_OFFSET_H 0x15
+#define MPU9250_YG_OFFSET_L 0x16
+#define MPU9250_ZG_OFFSET_H 0x17
+#define MPU9250_ZG_OFFSET_L 0x18
+#define MPU9250_SMPLRT_DIV 0x19
+#define MPU9250_CONFIG 0x1A
+#define MPU9250_GYRO_CONFIG 0x1B
+#define MPU9250_ACCEL_CONFIG 0x1C
+#define MPU9250_ACCEL_CONFIG2 0x1D
+#define MPU9250_LP_ACCEL_ODR 0x1E
+#define MPU9250_WOM_THR 0x1F
+
+#define MPU9250_FIFO_EN 0x23
+#define MPU9250_I2C_MST_CTRL 0x24
+#define MPU9250_I2C_SLV0_ADDR 0x25
+#define MPU9250_I2C_SLV0_REG 0x26
+#define MPU9250_I2C_SLV0_CTRL 0x27
+#define MPU9250_I2C_SLV1_ADDR 0x28
+#define MPU9250_I2C_SLV1_REG 0x29
+#define MPU9250_I2C_SLV1_CTRL 0x2A
+#define MPU9250_I2C_SLV2_ADDR 0x2B
+#define MPU9250_I2C_SLV2_REG 0x2C
+#define MPU9250_I2C_SLV2_CTRL 0x2D
+#define MPU9250_I2C_SLV3_ADDR 0x2E
+#define MPU9250_I2C_SLV3_REG 0x2F
+#define MPU9250_I2C_SLV3_CTRL 0x30
+#define MPU9250_I2C_SLV4_ADDR 0x31
+#define MPU9250_I2C_SLV4_REG 0x32
+#define MPU9250_I2C_SLV4_DO 0x33
+#define MPU9250_I2C_SLV4_CTRL 0x34
+#define MPU9250_I2C_SLV4_DI 0x35
+#define MPU9250_I2C_MST_STATUS 0x36
+#define MPU9250_INT_PIN_CFG 0x37
+#define MPU9250_INT_ENABLE 0x38
+
+#define MPU9250_INT_STATUS 0x3A
+#define MPU9250_ACCEL_XOUT_H 0x3B
+#define MPU9250_ACCEL_XOUT_L 0x3C
+#define MPU9250_ACCEL_YOUT_H 0x3D
+#define MPU9250_ACCEL_YOUT_L 0x3E
+#define MPU9250_ACCEL_ZOUT_H 0x3F
+#define MPU9250_ACCEL_ZOUT_L 0x40
+#define MPU9250_TEMP_OUT_H 0x41
+#define MPU9250_TEMP_OUT_L 0x42
+#define MPU9250_GYRO_XOUT_H 0x43
+#define MPU9250_GYRO_XOUT_L 0x44
+#define MPU9250_GYRO_YOUT_H 0x45
+#define MPU9250_GYRO_YOUT_L 0x46
+#define MPU9250_GYRO_ZOUT_H 0x47
+#define MPU9250_GYRO_ZOUT_L 0x48
+#define MPU9250_EXT_SENS_DATA_00 0x49
+#define MPU9250_EXT_SENS_DATA_01 0x4A
+#define MPU9250_EXT_SENS_DATA_02 0x4B
+#define MPU9250_EXT_SENS_DATA_03 0x4C
+#define MPU9250_EXT_SENS_DATA_04 0x4D
+#define MPU9250_EXT_SENS_DATA_05 0x4E
+#define MPU9250_EXT_SENS_DATA_06 0x4F
+#define MPU9250_EXT_SENS_DATA_07 0x50
+#define MPU9250_EXT_SENS_DATA_08 0x51
+#define MPU9250_EXT_SENS_DATA_09 0x52
+#define MPU9250_EXT_SENS_DATA_10 0x53
+#define MPU9250_EXT_SENS_DATA_11 0x54
+#define MPU9250_EXT_SENS_DATA_12 0x55
+#define MPU9250_EXT_SENS_DATA_13 0x56
+#define MPU9250_EXT_SENS_DATA_14 0x57
+#define MPU9250_EXT_SENS_DATA_15 0x58
+#define MPU9250_EXT_SENS_DATA_16 0x59
+#define MPU9250_EXT_SENS_DATA_17 0x5A
+#define MPU9250_EXT_SENS_DATA_18 0x5B
+#define MPU9250_EXT_SENS_DATA_19 0x5C
+#define MPU9250_EXT_SENS_DATA_20 0x5D
+#define MPU9250_EXT_SENS_DATA_21 0x5E
+#define MPU9250_EXT_SENS_DATA_22 0x5F
+#define MPU9250_EXT_SENS_DATA_23 0x60
+
+#define MPU9250_I2C_SLV0_DO 0x63
+#define MPU9250_I2C_SLV1_DO 0x64
+#define MPU9250_I2C_SLV2_DO 0x65
+#define MPU9250_I2C_SLV3_DO 0x66
+#define MPU9250_I2C_MST_DELAY_CTRL 0x67
+#define MPU9250_SIGNAL_PATH_RESET 0x68
+#define MPU9250_MOT_DETECT_CTRL 0x69
+#define MPU9250_USER_CTRL 0x6A
+#define MPU9250_PWR_MGMT_1 0x6B
+#define MPU9250_PWR_MGMT_2 0x6C
+
+#define MPU9250_FIFO_COUNTH 0x72
+#define MPU9250_FIFO_COUNTL 0x73
+#define MPU9250_FIFO_R_W 0x74
+#define MPU9250_WHO_AM_I 0x75
+#define MPU9250_XA_OFFSET_H 0x77
+#define MPU9250_XA_OFFSET_L 0x78
+
+#define MPU9250_YA_OFFSET_H 0x7A
+#define MPU9250_YA_OFFSET_L 0x7B
+
+#define MPU9250_ZA_OFFSET_H 0x7D
+#define MPU9250_ZA_OFFSET_L 0x7E
+
+/* reset values */
+
+#define WHOAMI_RESET_VAL 0x71
+#define POWER_MANAGMENT_1_RESET_VAL 0x01
+#define DEFAULT_RESET_VALUE 0x00
+
+#define WHOAMI_DEFAULT_VAL 0x68
+
+/* CONFIG register masks */
+
+#define MPU9250_FIFO_MODE_MASK 0x40
+#define MPU9250_EXT_SYNC_SET_MASK 0x38
+#define MPU9250_DLPF_CFG_MASK 0x07
+
+/* GYRO_CONFIG register masks */
+
+#define MPU9250_XGYRO_CTEN_MASK 0x80
+#define MPU9250_YGYRO_CTEN_MASK 0x40
+#define MPU9250_ZGYRO_CTEN_MASK 0x20
+#define MPU9250_GYRO_FS_SEL_MASK 0x18
+#define MPU9250_FCHOICE_B_MASK 0x03
+
+#define MPU9250_GYRO_FULL_SCALE_250DPS 0
+#define MPU9250_GYRO_FULL_SCALE_500DPS 1
+#define MPU9250_GYRO_FULL_SCALE_1000DPS 2
+#define MPU9250_GYRO_FULL_SCALE_2000DPS 3
+
+/* ACCEL_CONFIG register masks */
+
+#define MPU9250_AX_ST_EN_MASK 0x80
+#define MPU9250_AY_ST_EN_MASK 0x40
+#define MPU9250_AZ_ST_EN_MASK 0x20
+#define MPU9250_ACCEL_FS_SEL_MASK 0x18
+
+#define MPU9250_FULL_SCALE_2G 0
+#define MPU9250_FULL_SCALE_4G 1
+#define MPU9250_FULL_SCALE_8G 2
+#define MPU9250_FULL_SCALE_16G 3
+
+/* ACCEL_CONFIG_2 register masks */
+
+#define MPU9250_ACCEL_FCHOICE_B_MASK 0xC0
+#define MPU9250_A_DLPF_CFG_MASK 0x03
+
+/* LP_ACCEL_ODR register masks */
+
+#define MPU9250_LPOSC_CLKSEL_MASK 0x0F
+
+/* FIFO_EN register masks */
+
+#define MPU9250_TEMP_FIFO_EN_MASK 0x80
+#define MPU9250_GYRO_XOUT_MASK 0x40
+#define MPU9250_GYRO_YOUT_MASK 0x20
+#define MPU9250_GYRO_ZOUT_MASK 0x10
+#define MPU9250_ACCEL_MASK 0x08
+#define MPU9250_SLV2_MASK 0x04
+#define MPU9250_SLV1_MASK 0x02
+#define MPU9250_SLV0_MASK 0x01
+
+/* I2C_MST_CTRL register masks */
+
+#define MPU9250_MULT_MST_EN_MASK 0x80
+#define MPU9250_WAIT_FOR_ES_MASK 0x40
+#define MPU9250_SLV_3_FIFO_EN_MASK 0x20
+#define MPU9250_I2C_MST_P_NSR_MASK 0x10
+#define MPU9250_I2C_MST_CLK_MASK 0x0F
+
+/* I2C_SLV0_ADDR register masks */
+
+#define MPU9250_I2C_SLV0_RNW_MASK 0x80
+#define MPU9250_I2C_ID_0_MASK 0x7F
+
+/* I2C_SLV0_CTRL register masks */
+
+#define MPU9250_I2C_SLV0_EN_MASK 0x80
+#define MPU9250_I2C_SLV0_BYTE_SW_MASK 0x40
+#define MPU9250_I2C_SLV0_REG_DIS_MASK 0x20
+#define MPU9250_I2C_SLV0_GRP_MASK 0x10
+#define MPU9250_I2C_SLV0_LENG_MASK 0x0F
+
+/* I2C_SLV1_ADDR register masks */
+
+#define MPU9250_I2C_SLV1_RNW_MASK 0x80
+#define MPU9250_I2C_ID_1_MASK 0x7F
+
+/* I2C_SLV1_CTRL register masks */
+
+#define MPU9250_I2C_SLV1_EN_MASK 0x80
+#define MPU9250_I2C_SLV1_BYTE_SW_MASK 0x40
+#define MPU9250_I2C_SLV1_REG_DIS_MASK 0x20
+#define MPU9250_I2C_SLV1_GRP_MASK 0x10
+#define MPU9250_I2C_SLV1_LENG_MASK 0x0F
+
+/* I2C_SLV2_ADDR register masks */
+
+#define MPU9250_I2C_SLV2_RNW_MASK 0x80
+#define MPU9250_I2C_ID_2_MASK 0x7F
+
+/* I2C_SLV2_CTRL register masks */
+
+#define MPU9250_I2C_SLV2_EN_MASK 0x80
+#define MPU9250_I2C_SLV2_BYTE_SW_MASK 0x40
+#define MPU9250_I2C_SLV2_REG_DIS_MASK 0x20
+#define MPU9250_I2C_SLV2_GRP_MASK 0x10
+#define MPU9250_I2C_SLV2_LENG_MASK 0x0F
+
+/* I2C_SLV3_ADDR register masks */
+
+#define MPU9250_I2C_SLV3_RNW_MASK 0x80
+#define MPU9250_I2C_ID_3_MASK 0x7F
+
+/* I2C_SLV3_CTRL register masks */
+
+#define MPU9250_I2C_SLV3_EN_MASK 0x80
+#define MPU9250_I2C_SLV3_BYTE_SW_MASK 0x40
+#define MPU9250_I2C_SLV3_REG_DIS_MASK 0x20
+#define MPU9250_I2C_SLV3_GRP_MASK 0x10
+#define MPU9250_I2C_SLV3_LENG_MASK 0x0F
+
+/* I2C_SLV4_ADDR register masks */
+
+#define MPU9250_I2C_SLV4_RNW_MASK 0x80
+#define MPU9250_I2C_ID_4_MASK 0x7F
+
+/* I2C_SLV4_CTRL register masks */
+
+#define MPU9250_I2C_SLV4_EN_MASK 0x80
+#define MPU9250_SLV4_DONE_INT_EN_MASK 0x40
+#define MPU9250_I2C_SLV4_REG_DIS_MASK 0x20
+#define MPU9250_I2C_MST_DLY_MASK 0x1F
+
+/* I2C_MST_STATUS register masks */
+
+#define MPU9250_PASS_THROUGH_MASK 0x80
+#define MPU9250_I2C_SLV4_DONE_MASK 0x40
+#define MPU9250_I2C_LOST_ARB_MASK 0x20
+#define MPU9250_I2C_SLV4_NACK_MASK 0x10
+#define MPU9250_I2C_SLV3_NACK_MASK 0x08
+#define MPU9250_I2C_SLV2_NACK_MASK 0x04
+#define MPU9250_I2C_SLV1_NACK_MASK 0x02
+#define MPU9250_I2C_SLV0_NACK_MASK 0x01
+
+/* INT_PIN_CFG register masks */
+
+#define MPU9250_ACTL_MASK 0x80
+#define MPU9250_OPEN_MASK 0x40
+#define MPU9250_LATCH_INT_EN_MASK 0x20
+#define MPU9250_INT_ANYRD_2CLEAR_MASK 0x10
+#define MPU9250_ACTL_FSYNC_MASK 0x08
+#define MPU9250_FSYNC_INT_MODE_EN_MASK 0x04
+#define MPU9250_BYPASS_EN_MASK 0x02
+
+/* INT_ENABLE register masks */
+
+#define MPU9250_WOM_EN_MASK 0x40
+#define MPU9250_FIFO_OFLOW_EN_MASK 0x10
+#define MPU9250_FSYNC_INT_EN_MASK 0x08
+#define MPU9250_RAW_RDY_EN_MASK 0x01
+
+/* INT_STATUS register masks */
+
+#define MPU9250_WOM_INT_MASK 0x40
+#define MPU9250_FIFO_OFLOW_INT_MASK 0x10
+#define MPU9250_FSYNC_INT_MASK 0x08
+#define MPU9250_RAW_DATA_RDY_INT_MASK 0x01
+
+/* I2C_MST_DELAY_CTRL register masks */
+
+#define MPU9250_DELAY_ES_SHADOW_MASK 0x80
+#define MPU9250_I2C_SLV4_DLY_EN_MASK 0x10
+#define MPU9250_I2C_SLV3_DLY_EN_MASK 0x08
+#define MPU9250_I2C_SLV2_DLY_EN_MASK 0x04
+#define MPU9250_I2C_SLV1_DLY_EN_MASK 0x02
+#define MPU9250_I2C_SLV0_DLY_EN_MASK 0x01
+
+/* SIGNAL_PATH_RESET register masks */
+
+#define MPU9250_GYRO_RST_MASK 0x04
+#define MPU9250_ACCEL_RST_MASK 0x02
+#define MPU9250_TEMP_RST_MASK 0x01
+
+/* MOT_DETECT_CTRL register masks */
+
+#define MPU9250_ACCEL_INTEL_EN_MASK 0x80
+#define MPU9250_ACCEL_INTEL_MODE_MASK 0x40
+
+/* USER_CTRL register masks */
+
+#define MPU9250_FIFO_EN_MASK 0x40
+#define MPU9250_I2C_MST_EN_MASK 0x20
+#define MPU9250_I2C_IF_DIS_MASK 0x10
+#define MPU9250_FIFO_RST_MASK 0x04
+#define MPU9250_I2C_MST_RST_MASK 0x02
+#define MPU9250_SIG_COND_RST_MASK 0x01
+
+/* PWR_MGMT_1 register masks */
+
+#define MPU9250_H_RESET_MASK 0x80
+#define MPU9250_SLEEP_MASK 0x40
+#define MPU9250_CYCLE_MASK 0x20
+#define MPU9250_GYRO_STANDBY_CYCLE_MASK 0x10
+#define MPU9250_PD_PTAT_MASK 0x08
+#define MPU9250_CLKSEL_MASK 0x07
+
+/* PWR_MGMT_2 register masks */
+
+#define MPU9250_DISABLE_XA_MASK 0x20
+#define MPU9250_DISABLE_YA_MASK 0x10
+#define MPU9250_DISABLE_ZA_MASK 0x08
+#define MPU9250_DISABLE_XG_MASK 0x04
+#define MPU9250_DISABLE_YG_MASK 0x02
+#define MPU9250_DISABLE_ZG_MASK 0x01
+
+#define MPU9250_DISABLE_XYZA_MASK 0x38
+#define MPU9250_DISABLE_XYZG_MASK 0x07
+
+/* Magnetometer register maps */
+
+#define MPU9250_MAG_ADDRESS 0x0C
+
+#define MPU9250_MAG_WIA 0x00
+#define MPU9250_MAG_INFO 0x01
+#define MPU9250_MAG_ST1 0x02
+#define MPU9250_MAG_XOUT_L 0x03
+#define MPU9250_MAG_XOUT_H 0x04
+#define MPU9250_MAG_YOUT_L 0x05
+#define MPU9250_MAG_YOUT_H 0x06
+#define MPU9250_MAG_ZOUT_L 0x07
+#define MPU9250_MAG_ZOUT_H 0x08
+#define MPU9250_MAG_ST2 0x09
+#define MPU9250_MAG_CNTL 0x0A
+#define MPU9250_MAG_RSV 0x0B /* reserved mystery meat */
+#define MPU9250_MAG_ASTC 0x0C
+#define MPU9250_MAG_TS1 0x0D
+#define MPU9250_MAG_TS2 0x0E
+#define MPU9250_MAG_I2CDIS 0x0F
+#define MPU9250_MAG_ASAX 0x10
+#define MPU9250_MAG_ASAY 0x11
+#define MPU9250_MAG_ASAZ 0x12
+
+/* Magnetometer register masks */
+#define MPU9250_WIA_MASK 0x48
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+int mpu9250_main(int argc, char *argv[]);
+
+#endif /* __APPS_EXAMPLES_SENSORBD_EXAMPLES_I2C_MPU9250_H */
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/i2c_tcs34725.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <tinyara/i2c.h>
+#include <tinyara/math.h>
+
+#define TCS34725_ADDRESS (0x29)
+#define TCS34725_COMMAND_BIT (0x80)
+
+#define TCS34725_ENABLE (0x00)
+#define TCS34725_ENABLE_AEN (0x02) /* RGBC Enable - Writing 1 actives the ADC, 0 disables it */
+#define TCS34725_ENABLE_PON (0x01) /* Power on - Writing 1 activates the internal oscillator, 0 disables it */
+#define TCS34725_ATIME (0x01) /* Integration time */
+#define TCS34725_CONTROL (0x0F) /* Set the gain level for the sensor */
+#define TCS34725_ID (0x12) /* 0x44 = TCS34721/TCS34725, 0x4D = TCS34723/TCS34727 */
+#define TCS34725_CDATAL (0x14) /* Clear channel data */
+#define TCS34725_RDATAL (0x16) /* Red channel data */
+#define TCS34725_GDATAL (0x18) /* Green channel data */
+#define TCS34725_BDATAL (0x1A) /* Blue channel data */
+
+#define TCS34725_INTEGRATIONTIME_2_4MS (0xFF) /* 2.4ms - 1 cycle */
+#define TCS34725_INTEGRATIONTIME_24MS (0xF6) /* 24ms - 10 cycles */
+#define TCS34725_INTEGRATIONTIME_50MS (0xEB) /* 50ms - 20 cycles */
+#define TCS34725_INTEGRATIONTIME_101MS (0xD5) /* 101ms - 42 cycles */
+#define TCS34725_INTEGRATIONTIME_154MS (0xC0) /* 154ms - 64 cycles */
+#define TCS34725_INTEGRATIONTIME_700MS (0x00) /* 700ms - 256 cycles */
+
+#define TCS34725_GAIN_1X (0x00) /* No gain */
+#define TCS34725_GAIN_4X (0x01) /* 4x gain */
+#define TCS34725_GAIN_16X (0x02) /* 16x gain */
+#define TCS34725_GAIN_60X (0x03) /* 60x gain */
+
+static struct i2c_dev_s *i2c_dev;
+static struct i2c_config_s configs;
+
+uint32_t tcs34725IntegrationTime;
+
+static void tcs34725_write(uint8_t addr, uint8_t data)
+{
+ uint8_t reg[2];
+ reg[0] = TCS34725_COMMAND_BIT | addr;
+ reg[1] = data;
+
+ i2c_write(i2c_dev, &configs, reg, 2);
+}
+
+static void tcs34725_read(uint8_t addr, uint8_t *data, uint8_t bytecnt)
+{
+ uint8_t reg;
+ reg = TCS34725_COMMAND_BIT | addr;
+ i2c_write(i2c_dev, &configs, ®, 1);
+ i2c_read(i2c_dev, &configs, data, bytecnt);
+}
+
+static void tcs34725_getdata(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)
+{
+ tcs34725_read(TCS34725_CDATAL, (uint8_t *)c, 2);
+ tcs34725_read(TCS34725_RDATAL, (uint8_t *)r, 2);
+ tcs34725_read(TCS34725_GDATAL, (uint8_t *)g, 2);
+ tcs34725_read(TCS34725_BDATAL, (uint8_t *)b, 2);
+
+ switch (tcs34725IntegrationTime) {
+ case TCS34725_INTEGRATIONTIME_2_4MS:
+ up_mdelay(3);
+ break;
+ case TCS34725_INTEGRATIONTIME_24MS:
+ up_mdelay(24);
+ break;
+ case TCS34725_INTEGRATIONTIME_50MS:
+ up_mdelay(50);
+ break;
+ case TCS34725_INTEGRATIONTIME_101MS:
+ up_mdelay(101);
+ break;
+ case TCS34725_INTEGRATIONTIME_154MS:
+ up_mdelay(154);
+ break;
+ case TCS34725_INTEGRATIONTIME_700MS:
+ up_mdelay(700);
+ break;
+ }
+}
+
+inline float powfl(const float x, const float y)
+{
+ return (float)(pow((double)x, (double)y));
+}
+
+static uint16_t tcs34725_calclux(uint16_t r, uint16_t g, uint16_t b)
+{
+ float illuminance;
+
+ return (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
+
+ return (uint16_t)illuminance;
+}
+
+/****************************************************************************
+* Name: tcs34725_calctemperature
+****************************************************************************/
+
+static uint16_t tcs34725_calctemperature(uint16_t r, uint16_t g, uint16_t b)
+{
+ float X, Y, Z;
+ float xc, yc;
+ float n;
+ float cct;
+
+ X = (-0.14282F * r) + (1.54924F * g) + (-0.95641F * b);
+ Y = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
+ Z = (-0.68202F * r) + (0.77073F * g) + (0.56332F * b);
+
+ xc = (X) / (X + Y + Z);
+ yc = (Y) / (X + Y + Z);
+
+ n = (xc - 0.3320F) / (0.1858F - yc);
+
+ cct = (449.0F * powfl(n, 3)) + (3525.0F * powfl(n, 2)) + (6823.3F * n) + 5520.33F;
+
+ return (uint16_t)cct;
+}
+
+static void tcs34725_initialize(void)
+{
+ uint8_t reg;
+ tcs34725IntegrationTime = TCS34725_INTEGRATIONTIME_50MS;
+
+ tcs34725_read(TCS34725_ID, ®, 1);
+ if ((reg != 0x44) && (reg != 0x10)) {
+ printf("Bad devie id(0x%02x)\n", reg);
+ return;
+ }
+ printf("Successfully read device id(0x%02x)\n", reg);
+
+ tcs34725_write(TCS34725_ATIME, tcs34725IntegrationTime);
+ tcs34725_write(TCS34725_CONTROL, TCS34725_GAIN_4X);
+ tcs34725_write(TCS34725_ENABLE, TCS34725_ENABLE_PON);
+ up_mdelay(10);
+
+ tcs34725_write(TCS34725_ENABLE, TCS34725_ENABLE_PON | TCS34725_ENABLE_AEN);
+ up_mdelay(10);
+}
+
+void tcs34725_main(int argc, char *argv[])
+{
+ int i, port = 1;
+ uint16_t r, g, b, c, temp, lux;
+
+ i2c_dev = up_i2cinitialize(port);
+ if (i2c_dev == NULL) {
+ printf("up_i2cinitialize failed(i2c:%d)\n", port);
+ fflush(stdout);
+ }
+
+ configs.frequency = 400000;
+ configs.address = TCS34725_ADDRESS;
+ configs.addrlen = 7;
+
+ tcs34725_initialize();
+
+ for (i = 0; i < 30; i++) {
+ tcs34725_getdata(&r, &g, &b, &c);
+
+ temp = tcs34725_calctemperature(r, g, b);
+ lux = tcs34725_calclux(r, g, b);
+
+ printf("(R:%d), (G:%d), (B:%d), (C:%d), (Color Temp:%d), (Lux:%d)\n", r, g, b, c, temp, lux);
+ up_mdelay(500);
+ }
+}
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/pwm_buzzer.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <fcntl.h>
+#include <tinyara/pwm.h>
+
+#define c3 3822 /* PWM: 130.82 Hz, note freq: 130.81 Hz, error 0.01% */
+#define e3 3034 /* PWM: 164.80 Hz, note freq: 164.81 Hz, error 0.01% */
+#define g3x 2408 /* PWM: 207.64 Hz, note freq: 207.65 Hz, error 0.01% */
+#define a3 2273 /* PWM: 219.97 Hz, note freq: 220.00 Hz, error 0.01% */
+#define b3 2025 /* PWM: 246.91 Hz, note freq: 246.94 Hz, error 0.01% */
+#define c4 1911 /* PWM: 261.64 Hz, note freq: 261.63 Hz, error 0.01% */
+#define d4 1703 /* PWM: 293.60 Hz, note freq: 293.66 Hz, error 0.02% */
+#define d4x 1607 /* PWM: 311.14 Hz, note freq: 311.13 Hz, error 0.00% */
+#define e4 1517 /* PWM: 329.60 Hz, note freq: 329.63 Hz, error 0.01% */
+#define f4 1432 /* PWM: 349.16 Hz, note freq: 349.23 Hz, error 0.02% */
+#define g4 1276 /* PWM: 391.85 Hz, note freq: 392.00 Hz, error 0.04% */
+#define a4 1136 /* PWM: 440.14 Hz, note freq: 440.00 Hz, error 0.03% */
+#define h4 1012 /* PWM: 494.07 Hz, note freq: 493.88 Hz, error 0.04% */
+#define c5 956 /* PWM: 523.01 Hz, note freq: 523.25 Hz, error 0.05% */
+#define p 1
+
+int octavef[] = {c4, d4, e4, f4, g4, a4, h4, c5};
+int octaved[] = {8, 8, 8, 8, 8, 8, 8, 8};
+
+int furelisef[] =
+{
+ e4, d4x, e4, d4x, e4, b3, d4, c4, a3, p, c3, e3, a3, b3, p, e3, g3x, b3, c4, p, e3,
+ e3, d4x, e4, d4x, e4, b3, d4, c4, a3, p, c3, e3, a3, b3, p, e3, c4, b3, a3
+};
+
+int furelised[] =
+{
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 4, 8, 8, 8, 8, 4, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 4, 8, 8, 8, 8, 4
+};
+
+void pwmbuzzer_main(int argc, char *argv[])
+{
+ int i, fd1, fd2;
+ struct pwm_info_s pwm_info;
+
+ fd1 = open("/dev/pwm1", O_RDWR);
+ fd2 = open("/dev/pwm2", O_RDWR);
+
+ for (i = 0; i < 8; i++) {
+ pwm_info.frequency = octavef[i];
+ pwm_info.duty = octaved[i];
+ ioctl(fd1, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&pwm_info));
+ ioctl(fd1, PWMIOC_START);
+
+ up_mdelay(400);
+ }
+
+ for (i = 0; i < 40; i++) {
+ pwm_info.frequency = furelisef[i];
+ pwm_info.duty = furelised[i];
+ ioctl(fd2, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&pwm_info));
+ ioctl(fd2, PWMIOC_START);
+
+ up_mdelay(400);
+ }
+
+ ioctl(fd1, PWMIOC_STOP);
+ close(fd1);
+ ioctl(fd2, PWMIOC_STOP);
+ close(fd2);
+}
\ No newline at end of file
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/pwm_buzzer.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <fcntl.h>
+#include <tinyara/pwm.h>
+
+void ledpwm_main(int argc, char *argv[])
+{
+ int i, fd1, fd2, fd3, fd4;
+ struct pwm_info_s pwm_info;
+
+ fd1 = open("/dev/pwm0", O_RDWR);
+ fd2 = open("/dev/pwm3", O_RDWR);
+ fd3 = open("/dev/pwm4", O_RDWR);
+ fd4 = open("/dev/pwm5", O_RDWR);
+ pwm_info.frequency = 1000;
+
+ for (i = 0; i < 100; i = i + 3) {
+ printf("brightness %d, %d\n", i, 99 - i);
+
+ pwm_info.duty = i;
+ ioctl(fd1, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&pwm_info));
+ ioctl(fd2, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&pwm_info));
+ ioctl(fd1, PWMIOC_START);
+ ioctl(fd2, PWMIOC_START);
+
+ pwm_info.duty = 99 - i;
+ ioctl(fd3, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&pwm_info));
+ ioctl(fd4, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&pwm_info));
+ ioctl(fd3, PWMIOC_START);
+ ioctl(fd4, PWMIOC_START);
+
+ up_mdelay(200);
+ }
+
+ up_mdelay(2000);
+ ioctl(fd1, PWMIOC_STOP);
+ ioctl(fd2, PWMIOC_STOP);
+ ioctl(fd3, PWMIOC_STOP);
+ ioctl(fd4, PWMIOC_STOP);
+ close(fd1);
+ close(fd2);
+ close(fd3);
+ close(fd4);
+}
\ No newline at end of file
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/spi_k6ds3.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <tinyara/spi/spi.h>
+
+#define K6DS3_FACTORY_ID 0x69
+#define K6DS3_REG_WHO_AM_I 0x0F
+#define K6DS3_REG_CTRL1_XL 0x10
+#define K6DS3_REG_CTRL2_G 0x11
+
+#define K6DS3_REG_OUTX_G (0x22 | 0x80) /* length: 2-bytes */
+#define K6DS3_REG_OUTY_G (0x24 | 0x80) /* length: 2-bytes */
+#define K6DS3_REG_OUTZ_G (0x26 | 0x80) /* length: 2-bytes */
+#define K6DS3_REG_OUTX_XL (0x28 | 0x80) /* length: 2-bytes */
+#define K6DS3_REG_OUTY_XL (0x2A | 0x80) /* length: 2-bytes */
+#define K6DS3_REG_OUTZ_XL (0x2C | 0x80) /* length: 2-bytes */
+
+static struct spi_dev_s *spi_dev;
+
+static char spi_read(int port, int addr, int frequency, int bits, int conf)
+{
+ unsigned char buf[2];
+ buf[0] = addr;
+
+ SPI_LOCK(spi_dev, true);
+
+ SPI_SETFREQUENCY(spi_dev, frequency);
+ SPI_SETBITS(spi_dev, bits);
+ SPI_SETMODE(spi_dev, conf);
+
+ SPI_SELECT(spi_dev, port, true);
+ SPI_RECVBLOCK(spi_dev, buf, 2);
+ SPI_SELECT(spi_dev, port, false);
+
+ SPI_LOCK(spi_dev, false);
+
+ return buf[1];
+}
+
+static void spi_write(int port, int addr, int frequency, int bits, int conf, char value)
+{
+ unsigned char buf[2];
+ buf[0] = addr;
+ buf[1] = value;
+
+ SPI_LOCK(spi_dev, true);
+
+ SPI_SETFREQUENCY(spi_dev, frequency);
+ SPI_SETBITS(spi_dev, bits);
+ SPI_SETMODE(spi_dev, conf);
+
+ SPI_SELECT(spi_dev, port, true);
+ SPI_SNDBLOCK(spi_dev, buf, 2);
+ SPI_SELECT(spi_dev, port, false);
+
+ SPI_LOCK(spi_dev, false);
+}
+
+void k6ds3_main(int argc, char *argv[])
+{
+ int port = 0;
+ int freq = 1000000;
+ int bits = 8;
+ int conf = 0;
+
+ spi_dev = up_spiinitialize(port);
+
+ if (spi_read(port, K6DS3_REG_WHO_AM_I, freq, bits, conf) != K6DS3_FACTORY_ID) {
+ printf("It is not K6DS3 \n");
+ return;
+ }
+
+ uint16_t x_speed, y_speed, z_speed, p_gyro, r_gyro, y_gyro;
+ uint32_t x = 0, y = 0, z = 0;
+
+ int i;
+ for (i = 0; i < 30; i++) {
+ spi_write(port, K6DS3_REG_CTRL1_XL, freq, bits, conf, 0x80);
+ x_speed = spi_read(port, K6DS3_REG_OUTX_XL, freq, bits, conf);
+ y_speed = spi_read(port, K6DS3_REG_OUTY_XL, freq, bits, conf);
+ z_speed = spi_read(port, K6DS3_REG_OUTZ_XL, freq, bits, conf);
+
+ spi_write(port, K6DS3_REG_CTRL2_G, freq, bits, conf, 0x80);
+ p_gyro = spi_read(port, K6DS3_REG_OUTX_G, freq, bits, conf);
+ r_gyro = spi_read(port, K6DS3_REG_OUTY_G, freq, bits, conf);
+ y_gyro = spi_read(port, K6DS3_REG_OUTZ_G, freq, bits, conf);
+
+ x = (x_speed | (p_gyro << 8));
+ y = (y_speed | (r_gyro << 8));
+ z = (z_speed | (y_gyro << 8));
+
+ printf("x(0x%08x), y(0x%08x), z(0x%08x)\n", x, y, z);
+
+ up_mdelay(1000);
+ }
+}
\ No newline at end of file
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/spi_lis3lv02qd.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <tinyara/spi/spi.h>
+
+#define LIS3LV02DQ_CONF_REG_1 0x20
+#define LIS3LV02DQ_WHO_AM_I 0x8F
+
+#define LIS3LV02DQ_OUTX_L (0x28 | 0x80)
+#define LIS3LV02DQ_OUTX_H (0x29 | 0x80)
+#define LIS3LV02DQ_OUTY_L (0x2a | 0x80)
+#define LIS3LV02DQ_OUTY_H (0x2b | 0x80)
+#define LIS3LV02DQ_OUTZ_L (0x2c | 0x80)
+#define LIS3LV02DQ_OUTZ_H (0x2d | 0x80)
+
+static struct spi_dev_s *spi_dev;
+
+static char spi_read(int port, int addr, int frequency, int bits, int conf)
+{
+ unsigned char buf[2];
+ buf[0] = addr;
+
+ SPI_LOCK(spi_dev, true);
+
+ SPI_SETFREQUENCY(spi_dev, frequency);
+ SPI_SETBITS(spi_dev, bits);
+ SPI_SETMODE(spi_dev, conf);
+
+ SPI_SELECT(spi_dev, port, true);
+ SPI_RECVBLOCK(spi_dev, buf, 2);
+ SPI_SELECT(spi_dev, port, false);
+
+ SPI_LOCK(spi_dev, false);
+
+ return buf[1];
+}
+
+static void spi_write(int port, int addr, int frequency, int bits, int conf, char value)
+{
+ unsigned char buf[2];
+ buf[0] = addr;
+ buf[1] = value;
+
+ SPI_LOCK(spi_dev, true);
+
+ SPI_SETFREQUENCY(spi_dev, frequency);
+ SPI_SETBITS(spi_dev, bits);
+ SPI_SETMODE(spi_dev, conf);
+
+ SPI_SELECT(spi_dev, port, true);
+ SPI_SNDBLOCK(spi_dev, buf, 2);
+ SPI_SELECT(spi_dev, port, false);
+
+ SPI_LOCK(spi_dev, false);
+}
+
+void lis3lv02qd_main(int argc, char *argv[])
+{
+ int port = 0;
+ int freq = 1000000;
+ int bits = 8;
+ int conf = 0;
+
+ spi_dev = up_spiinitialize(port);
+
+ if (spi_read(port, LIS3LV02DQ_WHO_AM_I, freq, bits, conf) != 0x3A) {
+ printf("It is not LIS3LV02DQ \n");
+ return;
+ }
+
+ uint16_t x_low, x_high, y_low, y_high, z_low, z_high;
+ uint32_t x = 0, y = 0, z = 0;
+
+ int i;
+ for (i = 0; i < 30; i++) {
+ spi_write(port, LIS3LV02DQ_CONF_REG_1, freq, bits, conf, 0x87);
+
+ x_low = spi_read(port, LIS3LV02DQ_OUTX_L, freq, bits, conf);
+ x_high = spi_read(port, LIS3LV02DQ_OUTX_H, freq, bits, conf);
+ y_low = spi_read(port, LIS3LV02DQ_OUTY_L, freq, bits, conf);
+ y_high = spi_read(port, LIS3LV02DQ_OUTY_H, freq, bits, conf);
+ z_low = spi_read(port, LIS3LV02DQ_OUTZ_L, freq, bits, conf);
+ z_high = spi_read(port, LIS3LV02DQ_OUTZ_H, freq, bits, conf);
+
+ x = (x_low | (x_high << 8));
+ y = (y_low | (y_high << 8));
+ z = (z_low | (z_high << 8));
+
+ printf("x(0x%08x), y(0x%08x), z(0x%08x)\n", x, y, z);
+
+ up_mdelay(1000);
+ }
+}
\ No newline at end of file
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * 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.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/examples/sensorbd/examples/uart_loopback.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/select.h>
+
+void uartloopback_main(int argc, char *argv[])
+{
+ static char buf[16];
+ int port, ret = 0;
+ for (port = 0; port < 4; port++) {
+ snprintf(buf, 16, "/dev/ttyS%d", port);
+ int fd = open(buf, O_RDWR | O_NOCTTY);
+ if (fd < 0) {
+ ret = 1;
+ } else {
+ // tx
+ char buf_tx[255] = "Hello";
+ if (write(fd, buf_tx, 5) < 0) {
+ ret = 1;
+ }
+
+ // rx
+ char buf_rx[255];
+ struct timeval tv;
+ fd_set readfds;
+ FD_ZERO(&readfds);
+ FD_SET(fd, &readfds);
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+
+ if (select(fd + 1, &readfds, NULL, NULL, &tv) < 0) {
+ ret = 1;
+ } else if (FD_ISSET(fd, &readfds)) {
+ if (read(fd, buf_rx, 5) < 0) {
+ ret = 1;
+ }
+ }
+
+ int i;
+ for (i = 0; i < 5; i++) {
+ if (buf_tx[i] != buf_rx[i]) {
+ ret = 1;
+ }
+ }
+
+ if (ret) {
+ printf("UART%d LOOPBACK FAIL!!!\n", port);
+ if (fd > 0) {
+ close(fd);
+ }
+ ret = 0;
+ } else {
+ printf("UART%d LOOPBACK PASS!!!\n", port);
+ close(fd);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+#include <stdio.h>
+#include <apps/shell/tash.h>
+
+static void show_usage(FAR const char *program)
+{
+ printf("USAGE:\n");
+ printf(" %s led : gpio led on/off test\n", program);
+ printf(" %s ledpwm : pwm led on/off test\n", program);
+ printf(" %s ledst : gpio starter board led test\n", program);
+ printf(" %s uart : uart loopback test\n", program);
+ printf(" %s gpio : gpio loopback test\n", program);
+ printf(" %s button : gpio button interrupt test\n", program);
+ printf(" %s pwm : pwm buzzer test\n", program);
+ printf(" %s tcs34725 : i2c rgb sensor(tcs34725) test\n", program);
+ printf(" %s mpu9250 : i2c 9-axis motion tracking sensor(MPU9250) test\n", program);
+ printf(" %s k6ds : spi 6-axis acceler sensor(K6DS) test\n", program);
+ printf(" %s lis3lv02qd : spi 3-axis acceler sensor(LIS3LV02QD) test\n", program);
+}
+
+#ifdef CONFIG_BUILD_KERNEL
+int main(int argc, FAR char *argv[])
+#else
+int sensorbd_main(int argc, FAR char *argv[])
+#endif
+{
+ int ret = 0;
+
+ switch (argc) {
+ case 2:
+ if (strcmp(argv[1], "led") == 0) {
+ ledonoff_main(argc, argv);
+ } else if (strcmp(argv[1], "ledpwm") == 0) {
+ ledpwm_main(argc, argv);
+ } else if (strcmp(argv[1], "ledst") == 0) {
+ starterled_main(argc, argv);
+ } else if (strcmp(argv[1], "uart") == 0) {
+ uartloopback_main(argc, argv);
+ } else if (strcmp(argv[1], "gpio") == 0) {
+ gpioloopback_main(argc, argv);
+ } else if (strcmp(argv[1], "button") == 0) {
+ switch_main(argc, argv);
+ } else if (strcmp(argv[1], "pwm") == 0) {
+ pwmbuzzer_main(argc, argv);
+ } else if (strcmp(argv[1], "tcs34725") == 0) {
+ tcs34725_main(argc, argv);
+ } else if (strcmp(argv[1], "mpu9250") == 0) {
+ mpu9250_main(argc, argv);
+ } else if (strcmp(argv[1], "k6ds") == 0) {
+ k6ds3_main(argc, argv);
+ } else if (strcmp(argv[1], "lis3lv02qd") == 0) {
+ lis3lv02qd_main(argc, argv);
+ } else {
+ show_usage(argv[0]);
+ }
+ break;
+
+ default:
+ show_usage(argv[0]);
+ break;
+ }
+
+ return ret;
+}
\ No newline at end of file
# CONFIG_EXAMPLES_WAKAAMA_CLIENT is not set
# CONFIG_EXAMPLES_WORKQUEUE is not set
# CONFIG_EXAMPLES_ARTIK_DEMO is not set
+# CONFIG_EXAMPLES_SENSORBOARD is not set
#
# Network Utilities