summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/Sensor Watch Accelerometer Test/app.c91
-rwxr-xr-xapps/Sensor Watch Accelerometer Test/make/.gitignore1
-rwxr-xr-xapps/Sensor Watch Accelerometer Test/make/Makefile10
-rw-r--r--make.mk2
-rw-r--r--watch-library/driver/lis2dh.c116
-rw-r--r--watch-library/driver/lis2dh.h187
6 files changed, 407 insertions, 0 deletions
diff --git a/apps/Sensor Watch Accelerometer Test/app.c b/apps/Sensor Watch Accelerometer Test/app.c
new file mode 100644
index 00000000..9ad0d56f
--- /dev/null
+++ b/apps/Sensor Watch Accelerometer Test/app.c
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include "watch.h"
+#include "lis2dh.h"
+
+// This application displays data from the old Sensor Watch Motion sensor board.
+// Note that this board required A0 to be set high to power the sensor.
+// Future accelerometer boards will be powered directly from VCC.
+// Also note that this board has its INT1 pin wired to A1, which is not an external
+// wake pin. Future accelerometer boards will wire interrupt pins to A2 and A4.
+
+uint8_t axis = 0;
+
+void cb_light_pressed() {
+ axis = 1;
+}
+
+void cb_mode_pressed() {
+ axis = 2;
+}
+
+void cb_alarm_pressed() {
+ axis = 3;
+}
+
+void app_init() {
+ gpio_set_pin_direction(A0, GPIO_DIRECTION_OUT);
+ gpio_set_pin_function(A0, GPIO_PIN_FUNCTION_OFF);
+ gpio_set_pin_level(A0, true);
+
+ watch_enable_display();
+
+ watch_enable_external_interrupts();
+ watch_register_interrupt_callback(BTN_MODE, cb_mode_pressed, INTERRUPT_TRIGGER_RISING);
+ watch_register_interrupt_callback(BTN_LIGHT, cb_light_pressed, INTERRUPT_TRIGGER_RISING);
+ watch_register_interrupt_callback(BTN_ALARM, cb_alarm_pressed, INTERRUPT_TRIGGER_RISING);
+
+ watch_enable_i2c();
+
+ lis2dh_begin();
+
+ lis2dh_set_range(LIS2DH_RANGE_2_G);
+ lis2dh_set_data_rate(LIS2DH_DATA_RATE_10_HZ);
+}
+
+void app_wake_from_backup() {
+}
+
+void app_setup() {
+}
+
+void app_prepare_for_standby() {
+}
+
+void app_wake_from_standby() {
+}
+
+bool app_loop() {
+ if (lis2dh_have_new_data()) {
+ lis2dh_reading reading;
+ lis2dh_acceleration_measurement measurement = lis2dh_get_acceleration_measurement(&reading);
+
+ // printf("%d,%d,%d\n", reading.x, reading.y, reading.z);
+ printf("%f,%f,%f\n", measurement.x, measurement.y, measurement.z);
+
+ char buf[11] = {0};
+ switch (axis) {
+ case 1:
+ sprintf(buf, "AC X%-6d", reading.x);
+ break;
+ case 2:
+ sprintf(buf, "AC Y%-6d", reading.y);
+ break;
+ case 3:
+ sprintf(buf, "AC Z%-6d", reading.z);
+ break;
+ default:
+ sprintf(buf, " %2d%2d%2d", abs(reading.x >> 9), abs(reading.y >> 9), abs(reading.z >> 9));
+ if (reading.x < 0) buf[0] = '_';
+ if (reading.y < 0) buf[1] = '_';
+ if (reading.z < 0) buf[3] = '_';
+ break;
+ }
+
+ watch_display_string(buf, 0);
+ }
+
+ return false;
+}
diff --git a/apps/Sensor Watch Accelerometer Test/make/.gitignore b/apps/Sensor Watch Accelerometer Test/make/.gitignore
new file mode 100755
index 00000000..567609b1
--- /dev/null
+++ b/apps/Sensor Watch Accelerometer Test/make/.gitignore
@@ -0,0 +1 @@
+build/
diff --git a/apps/Sensor Watch Accelerometer Test/make/Makefile b/apps/Sensor Watch Accelerometer Test/make/Makefile
new file mode 100755
index 00000000..c66ad20c
--- /dev/null
+++ b/apps/Sensor Watch Accelerometer Test/make/Makefile
@@ -0,0 +1,10 @@
+TOP = ../../..
+include $(TOP)/make.mk
+
+INCLUDES += \
+ -I../
+
+SRCS += \
+ ../app.c
+
+include $(TOP)/rules.mk
diff --git a/make.mk b/make.mk
index 9792579c..f6a37c7e 100644
--- a/make.mk
+++ b/make.mk
@@ -61,6 +61,7 @@ INCLUDES += \
-I$(TOP)/watch-library/config/ \
-I$(TOP)/watch-library/hw/ \
-I$(TOP)/watch-library/watch/ \
+ -I$(TOP)/watch-library/driver/ \
-I$(TOP)/watch-library
SRCS += \
@@ -112,6 +113,7 @@ SRCS += \
$(TOP)/watch-library/hpl/sercom/hpl_sercom.c \
$(TOP)/watch-library/hpl/slcd/hpl_slcd.c \
$(TOP)/watch-library/hpl/systick/hpl_systick.c \
+ $(TOP)/watch-library/driver/lis2dh.c \
DEFINES += \
-D__SAML22J18A__ \
diff --git a/watch-library/driver/lis2dh.c b/watch-library/driver/lis2dh.c
new file mode 100644
index 00000000..24534481
--- /dev/null
+++ b/watch-library/driver/lis2dh.c
@@ -0,0 +1,116 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2021 Joey Castillo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRABIN_DIR=${CONFIG_BINARY_FOLDER:-./bin} BASE_URL="${BASE_URL:-https://downloads.openwrt.org/snapshots}" CHECK_INSTALLED="${CHECK_INSTALLED:-y}" TARGET_URL="$BASE_URL/targets/$TARGET/$SUBTARGET/packages/Packages.gz" CONFIG_URL="$BASE_URL/targets/$TARGET/$SUBTARGET/config.buildinfo" PACKAGES_URL="$BASE_URL/packages/$ARCH/base/Packages.gz" if command -v curl > /dev/null; then DOWNLOAD_METHOD="curl" else DOWNLOAD_METHOD="wget --output-document=-" fi help() { sed -rn 's/^### ?//;T;p' "$0" } package_size () { FOUND_PACKAGE= if [ -z "$CHECK_INSTALLED" ]; then SEARCH_PATTERN="Size" else SEARCH_PATTERN="Installed-Size" fi while IFS= read -r line; do if [ "$line" = "Package: $2" ]; then FOUND_PACKAGE=y fi if [ -n "$FOUND_PACKAGE" ]; then case $line in "$SEARCH_PATTERN"*) echo "$line" | cut -d ' ' -f 2 break ;; esac fi done < "$1" } compare_sizes () { TOTAL_DIFF="0" for PACKAGE in $PACKAGES; do if [ "$PACKAGE" = "libc" ]; then continue fi PACKAGE_FILE=$(find "$BIN_DIR/packages/$ARCH/" \ "$BIN_DIR/targets/$TARGET/$SUBTARGET/" \ -name "${PACKAGE}_*.ipk" 2>/dev/null | head -n1) if [ -z "$PACKAGE_FILE" ]; then continue fi if [ -z "$CHECK_INSTALLED" ]; then SIZE_LOCAL=$(stat -c '%s' "$PACKAGE_FILE") else SIZE_LOCAL=$(tar tzvf "$PACKAGE_FILE" ./data.tar.gz | awk '{ print $3 }') fi SIZE_UPSTREAM=$(package_size "$TMP_INDEX" "$PACKAGE") SIZE_DIFF="$((SIZE_LOCAL - SIZE_UPSTREAM))" TOTAL_DIFF="$((TOTAL_DIFF + SIZE_DIFF))" if [ "$SIZE_DIFF" -gt 0 ]; then SIZE_DIFF="+$SIZE_DIFF" fi if [ -n "$SIZE_UPSTREAM" ]; then echo "${SIZE_DIFF} ${SIZE_LOCAL} ${SIZE_UPSTREAM} $PACKAGE" else echo "$PACKAGE is missing upstream" fi done echo "~~~~~~~ total change ${TOTAL_DIFF}" } if [ "$1" = "-h" ]; then help exit 0 fi if [ "$1" = "-p" ]; then CHECK_INSTALLED= fi echo "Compare packages of $TARGET/$SUBTARGET/$ARCH": echo "$PACKAGES" echo echo "Checking configuration difference" TMP_CONFIG=$(mktemp /tmp/config.XXXXXX) sed -n 's/^ \+config \(.*\)/\1/p' config/Config-build.in config/Config-devel.in > "${TMP_CONFIG}-FOCUS" sort .config | grep -f "${TMP_CONFIG}-FOCUS" | grep -v "^#" | sort > "${TMP_CONFIG}-LOCAL" mv .config .config.bak "$DOWNLOAD_METHOD" "$CONFIG_URL" > .config make defconfig > /dev/null 2> /dev/null grep -f "${TMP_CONFIG}-FOCUS" .config | grep -v "^#" | sort > "${TMP_CONFIG}-UPSTREAM" mv .config.bak .config echo echo " --- start config diff ---" diff -u "${TMP_CONFIG}-LOCAL" "${TMP_CONFIG}-UPSTREAM" echo " --- end config diff ---" rm "${TMP_CONFIG}-FOCUS" "${TMP_CONFIG}-UPSTREAM" "${TMP_CONFIG}-LOCAL" echo if [ -z "$CHECK_INSTALLED" ]; then echo "Checking IPK package size" else echo "Checking installed size" fi echo echo "Fetching latest package indexes..." TMP_INDEX=$(mktemp /tmp/size_compare_package_index.XXXXXX) "$DOWNLOAD_METHOD" "$TARGET_URL" | gzip -d > "$TMP_INDEX" || exit 1 "$DOWNLOAD_METHOD" "$PACKAGES_URL" | gzip -d >> "$TMP_INDEX" || exit 1 echo echo "Comparing package sizes..." echo "Change Local Remote Package" compare_sizes | sort -g -r rm "$TMP_INDEX"
ass='add'>+#define LIS2DH_CTRL5_VAL_FIFO_EN 0b01000000
+#define LIS2DH_CTRL5_VAL_LIR_INT1 0b00001000
+#define LIS2DH_CTRL5_VAL_D4D_INT1 0b00000100
+#define LIS2DH_CTRL5_VAL_LIR_INT2 0b00000010
+#define LIS2DH_CTRL5_VAL_D4D_INT2 0b00000001
+
+#define LIS2DH_REG_CTRL6 0x25
+#define LIS2DH_CTRL6_VAL_I2_CLICK 0b10000000
+#define LIS2DH_CTRL6_VAL_I2_INT1 0b01000000
+#define LIS2DH_CTRL6_VAL_I2_INT2 0b00100000
+#define LIS2DH_CTRL6_VAL_BOOT_I2 0b00010000
+#define LIS2DH_CTRL6_VAL_P2_ACT 0b00001000
+#define LIS2DH_CTRL6_VAL_H_L_ACTIVE 0b00000000
+
+#define LIS2DH_REG_REFERENCE 0x26
+
+#define LIS2DH_REG_STATUS 0x27
+#define LIS2DH_STATUS_VAL_ZYXOR 0b10000000
+#define LIS2DH_STATUS_VAL_ZOR 0b01000000
+#define LIS2DH_STATUS_VAL_YOR 0b00100000
+#define LIS2DH_STATUS_VAL_XOR 0b00010000
+#define LIS2DH_STATUS_VAL_ZYXDA 0b00001000
+#define LIS2DH_STATUS_VAL_ZDA 0b00000100
+#define LIS2DH_STATUS_VAL_YDA 0b00000010
+#define LIS2DH_STATUS_VAL_XDA 0b00000001
+
+#define LIS2DH_REG_OUT_X_L 0x28
+#define LIS2DH_REG_OUT_X_H 0x29
+#define LIS2DH_REG_OUT_Y_L 0x2A
+#define LIS2DH_REG_OUT_Y_H 0x2B
+#define LIS2DH_REG_OUT_Z_L 0x2C
+#define LIS2DH_REG_OUT_Z_H 0x2D
+
+#define LIS2DH_REG_FIFO_CTRL 0x2E
+#define LIS2DH_REG_FIFO_SRC 0x2F
+#define LIS2DH_REG_INT1_CFG 0x30
+#define LIS2DH_REG_INT1_SRC 0x31
+#define LIS2DH_REG_INT1_THS 0x32
+#define LIS2DH_REG_INT1_DUR 0x33
+#define LIS2DH_REG_CLICK_CFG 0x38
+#define LIS2DH_REG_CLICK_SRC 0x39
+#define LIS2DH_REG_CLICK_THS 0x3A
+#define LIS2DH_REG_TIME_LIMIT 0x3B
+#define LIS2DH_REG_TIME_LATENCY 0x3C
+#define LIS2DH_REG_TIME_WINDOW 0x3D
+
+#endif // LIS2DH_H