From: Roman Bazalevskiy Date: Sun, 23 Apr 2017 10:20:33 +0000 (+0300) Subject: Добавлен модуль ядра и приложение для работы с трехосевыми магнитометрами. X-Git-Url: https://git.rvb.name/lede-packages.git/commitdiff_plain/5164dd813dd5280ac38bddc4357f74eaa3088e63 Добавлен модуль ядра и приложение для работы с трехосевыми магнитометрами. --- diff --git a/3-axis/Makefile b/3-axis/Makefile new file mode 100644 index 0000000..de1aef1 --- /dev/null +++ b/3-axis/Makefile @@ -0,0 +1,32 @@ +# +# Copyright (C) Felix Fietkau +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=3-axis +PKG_RELEASE:=1 + +PKG_FLAGS:=nonshared + +include $(INCLUDE_DIR)/package.mk + +define Package/3-axis + SECTION:=utils + CATEGORY:=Utilities + TITLE:=3-axis input device monitoring tool +endef + +define Package/$(PKG_NAME)/Build/Compile + $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/3-axis ./src/3-axis.c +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/3-axis $(1)/usr/bin/ +endef + +$(eval $(call BuildPackage,3-axis)) diff --git a/3-axis/Makefile~ b/3-axis/Makefile~ new file mode 100644 index 0000000..fa46f23 --- /dev/null +++ b/3-axis/Makefile~ @@ -0,0 +1,32 @@ +# +# Copyright (C) Felix Fietkau +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +yinclude $(TOPDIR)/rules.mk + +PKG_NAME:=3-axis +PKG_RELEASE:=1 + +PKG_FLAGS:=nonshared + +include $(INCLUDE_DIR)/package.mk + +define Package/3-axis + SECTION:=utils + CATEGORY:=Utilities + TITLE:=3-axis input device monitoring tool +endef + +define Package/$(PKG_NAME)/Build/Compile + $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/3-axis ./src/3-axis.c +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/3-axis $(1)/usr/bin/ +endef + +$(eval $(call BuildPackage,3-axis)) diff --git a/3-axis/README.md b/3-axis/README.md new file mode 100644 index 0000000..3e993cf --- /dev/null +++ b/3-axis/README.md @@ -0,0 +1,51 @@ +# linux-am2320-driver +Linux Device Driver for AM2320 + +**Experimental** + +Tested on a Raspberry pi 3 with kernel version 4.4.14-v7+ + +Usage +------ +You need to have the proper kernel headers installed to build this driver. Use this tool to install kernel headers https://github.com/notro/rpi-source + +1. clone this repo +2. git clone linux-am2320-driver +3. cd into directory +4. type make +5. sudo insmod am2320.ko +6. type lsmod and see whether the driver is loaded properly +7. sudo bash +8. if you have a new Raspberry pi (B+, 2 or 3) + + echo am2320 0x5c > /sys/class/i2c-adapter/i2c-1/new_device + + else if this is a Rev. 1 + + echo am2320 0x5c > /sys/class/i2c-adapter/i2c-0/new_device + +Viewing measurements +====================== +cat /sys/bus/i2c/devices/1-005c/temp1_input + +cat /sys/bus/i2c/devices/1-005c/humidity1_input + +OR + +cat /sys/class/i2c-adapter/i2c-1/1-005c/temp1_input + +cat /sys/class/i2c-adapter/i2c-1/1-005c/humidity1_input + +To remove from kernel +===================== +sudo bash +echo 0x5c > /sys/class/i2c-adapter/i2c-1/delete_device + +then do, + +rmmod am2320 + +Cleaning the directory +======================= +make clean + diff --git a/3-axis/src/.gitignore b/3-axis/src/.gitignore new file mode 100644 index 0000000..ea93743 --- /dev/null +++ b/3-axis/src/.gitignore @@ -0,0 +1,5 @@ +*.c~ +*.swp +*.o +*.ko +resources/ diff --git a/3-axis/src/3-axis.c b/3-axis/src/3-axis.c new file mode 100644 index 0000000..cff0640 --- /dev/null +++ b/3-axis/src/3-axis.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int read_all(int fd, char *buf, int count) +{ + int n_read = 0; + while (n_read != count) { + int result = read(fd, buf + n_read, count - n_read); + if (result < 0) + return result; + else if (result == 0) + return n_read; + n_read += result; + } + return n_read; +} + +int main(int argc, char *argv[]) +{ + int fd; + struct input_event ev; + __s32 x_value, + y_value, + z_value; + __u8 x_got=0, + y_got=0, + z_got=0; + int timeout=10; + int start; + + assert(16 == sizeof(struct input_event)); + + if (argc != 2) { + fprintf(stderr, "missing /dev/input/XXX\n"); + return 1; + } + + start=time(0); + + if ((fd = open(argv[1], O_RDONLY)) == -1) { + perror("open"); + return 1; + } + + while (! (x_got && y_got && z_got)) { + + int ret = read(fd, (char *) &ev, sizeof(struct input_event)); + if (ret != sizeof(struct input_event)) { + fprintf(stderr, "ret == %d\n", ret); + perror("read"); + return 1; + } + if (ev.type==3 && ev.code==16) { + x_value=ev.value; + x_got=1; + } + if (ev.type==3 && ev.code==17) { + y_value=ev.value; + y_got=1; + } + if (ev.type==3 && ev.code==10) { + z_value=ev.value; + z_got=1; + } + if (time(0) > start+timeout) break; + } + + close(fd); + + if (x_got && y_got && z_got) { + printf("%d %d %d\n",x_value,y_value,z_value); + } else { + fprintf(stderr, "data not aquired until timeout"); + perror("timeout"); + return 1; + } + + return 0; +} diff --git a/3-axis/src/Makefile b/3-axis/src/Makefile new file mode 100644 index 0000000..9caa364 --- /dev/null +++ b/3-axis/src/Makefile @@ -0,0 +1,9 @@ +SRCS = 3-axis.c +OBJS = $(SRCS:.c=.o) + +3-axis: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +clean: + rm -f $(OBJS) + rm -f 3-axis diff --git a/3-axis/src/Makefile~ b/3-axis/src/Makefile~ new file mode 100644 index 0000000..cb160fe --- /dev/null +++ b/3-axis/src/Makefile~ @@ -0,0 +1,9 @@ +SRCS = 3-axis +OBJS = $(SRCS:.c=.o) + +3-axis: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +clean: + rm -f $(OBJS) + rm -f 3-axis diff --git a/hmc5843/Makefile b/hmc5843/Makefile new file mode 100644 index 0000000..ccbf939 --- /dev/null +++ b/hmc5843/Makefile @@ -0,0 +1,52 @@ +# +# Copyright (C) 2007 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +# $Id: $ + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/kernel.mk + +PKG_NAME:=hmc5843 +PKG_VERSION:=0.1 +PKG_RELEASE:=2 + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk + +MAKEFLAGS_KMOD:= -C "$(LINUX_DIR)" \ + CROSS_COMPILE="$(TARGET_CROSS)" \ + ARCH="$(LINUX_KARCH)" \ + PATH="$(TARGET_PATH)" \ + SUBDIRS="$(PKG_BUILD_DIR)" + +define KernelPackage/hmc5843 + SUBMENU:=Other modules + DEPENDS:=+kmod-i2c-core +kmod-input-core + TITLE:=Kernel driver for HMC5843 3-axis magnetometer + URL:= + FILES:=$(PKG_BUILD_DIR)/hmc5843.$(LINUX_KMOD_SUFFIX) + VERSION:=$(LINUX_VERSION)+$(PKG_VERSION)-$(PKG_RELEASE) + AUTOLOAD:=$(call AutoLoad,80,hmc5843) + $(call AddDepends/hwmon,+kmod-i2c-core,+kmod-input-core) +endef + +define KernelPackage/hmc5843/description + Kernel driver for HMC5843 i2c 3-axis magnetometers family +endef + + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ +endef + +define Build/Compile + $(MAKE) $(MAKEFLAGS_KMOD) \ + modules +endef + +$(eval $(call KernelPackage,hmc5843)) diff --git a/hmc5843/Makefile~ b/hmc5843/Makefile~ new file mode 100644 index 0000000..fa88f42 --- /dev/null +++ b/hmc5843/Makefile~ @@ -0,0 +1,53 @@ +# +# Copyright (C) 2007 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +# $Id: $ + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/kernel.mk + +PKG_NAME:=hmc5843 +PKG_VERSION:=0.1 +PKG_RELEASE:=2 + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk + +MAKEFLAGS_KMOD:= -C "$(LINUX_DIR)" \ + CROSS_COMPILE="$(TARGET_CROSS)" \ + ARCH="$(LINUX_KARCH)" \ + PATH="$(TARGET_PATH)" \ + SUBDIRS="$(PKG_BUILD_DIR)" + +define KernelPackage/hmc5843 + SUBMENU:=Other modules + DEPENDS:=+kmod-i2c-core +kmod-input-core + TITLE:=Kernel driver for HMC5843 3-axis magnetometer + URL:= + FILES:=$(PKG_BUILD_DIR)/hmc5843.$(LINUX_KMOD_SUFFIX) + VERSION:=$(LINUX_VERSION)+$(PKG_VERSION)-$(PKG_RELEASE) + AUTOLOAD:=$(call AutoLoad,80,hmc5843) + $(call AddDepends/hwmon,+kmod-i2c-core,+kmod-input-core) +endef + +define KernelPackage/hmc5843/description + Kernel driver for HMC5843 i2c 3-axis magnetometers family +endef + + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ +endef + +define Build/Compile + $(MAKE) $(MAKEFLAGS_KMOD) \ + modules + $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/single-event ./src/single-event.c +endef + +$(eval $(call KernelPackage,hmc5843)) diff --git a/hmc5843/README.md b/hmc5843/README.md new file mode 100644 index 0000000..3e993cf --- /dev/null +++ b/hmc5843/README.md @@ -0,0 +1,51 @@ +# linux-am2320-driver +Linux Device Driver for AM2320 + +**Experimental** + +Tested on a Raspberry pi 3 with kernel version 4.4.14-v7+ + +Usage +------ +You need to have the proper kernel headers installed to build this driver. Use this tool to install kernel headers https://github.com/notro/rpi-source + +1. clone this repo +2. git clone linux-am2320-driver +3. cd into directory +4. type make +5. sudo insmod am2320.ko +6. type lsmod and see whether the driver is loaded properly +7. sudo bash +8. if you have a new Raspberry pi (B+, 2 or 3) + + echo am2320 0x5c > /sys/class/i2c-adapter/i2c-1/new_device + + else if this is a Rev. 1 + + echo am2320 0x5c > /sys/class/i2c-adapter/i2c-0/new_device + +Viewing measurements +====================== +cat /sys/bus/i2c/devices/1-005c/temp1_input + +cat /sys/bus/i2c/devices/1-005c/humidity1_input + +OR + +cat /sys/class/i2c-adapter/i2c-1/1-005c/temp1_input + +cat /sys/class/i2c-adapter/i2c-1/1-005c/humidity1_input + +To remove from kernel +===================== +sudo bash +echo 0x5c > /sys/class/i2c-adapter/i2c-1/delete_device + +then do, + +rmmod am2320 + +Cleaning the directory +======================= +make clean + diff --git a/hmc5843/src b/hmc5843/src new file mode 160000 index 0000000..84b1ca1 --- /dev/null +++ b/hmc5843/src @@ -0,0 +1 @@ +Subproject commit 84b1ca12926769ba7a1380ee5ffdf652791b6594