altos: add 'vidtime', a simple brightness monitor
authorKeith Packard <keithp@keithp.com>
Mon, 7 May 2018 18:26:42 +0000 (11:26 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 7 May 2018 18:26:42 +0000 (11:26 -0700)
This is a testing tool for video refresh tracking. It uses the mpusb
v3.0 hardware and monitors the phototransistor value, sending 0 or 1
to the USB port when the value changes.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/vidtime/.gitignore [new file with mode: 0644]
src/vidtime/Makefile [new file with mode: 0644]
src/vidtime/ao_pins.h [new file with mode: 0644]
src/vidtime/ao_vidtime.c [new file with mode: 0644]
src/vidtime/flash-loader/.gitignore [new file with mode: 0644]
src/vidtime/flash-loader/Makefile [new file with mode: 0644]
src/vidtime/flash-loader/ao_pins.h [new file with mode: 0644]

diff --git a/src/vidtime/.gitignore b/src/vidtime/.gitignore
new file mode 100644 (file)
index 0000000..471b7fd
--- /dev/null
@@ -0,0 +1,2 @@
+ao_product.h
+vidtime-*
diff --git a/src/vidtime/Makefile b/src/vidtime/Makefile
new file mode 100644 (file)
index 0000000..327614b
--- /dev/null
@@ -0,0 +1,65 @@
+#
+# AltOS build
+#
+#
+
+include ../stmf0/Makefile.defs
+
+INC = \
+       ao.h \
+       ao_arch.h \
+       ao_arch_funcs.h \
+       ao_boot.h \
+       ao_pins.h \
+       ao_product.h \
+       ao_task.h \
+       stm32f0.h \
+       Makefile
+
+ALTOS_SRC = \
+       ao_boot_chain.c \
+       ao_interrupt.c \
+       ao_product.c \
+       ao_romconfig.c \
+       ao_cmd.c \
+       ao_dma_stm.c \
+       ao_exti_stm.c \
+       ao_task.c \
+       ao_stdio.c \
+       ao_panic.c \
+       ao_timer.c \
+       ao_mutex.c \
+       ao_usb_stm.c
+
+PRODUCT=VidTime
+PRODUCT_DEF=-DVIDTIME
+IDPRODUCT=0x002b
+
+CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS) -Os -g
+
+PROGNAME=vidtime-v1.0
+PROG=$(PROGNAME)-$(VERSION).elf
+HEX=$(PROGNAME)-$(VERSION).ihx
+
+SRC=$(ALTOS_SRC) ao_vidtime.c
+OBJ=$(SRC:.c=.o)
+
+all: $(PROG) $(HEX)
+
+$(PROG): Makefile $(OBJ) altos.ld
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS)
+
+ao_product.h: ao-make-product.5c ../Version
+       $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
+
+$(OBJ): $(INC)
+
+distclean:     clean
+
+clean:
+       rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx
+       rm -f ao_product.h
+
+install:
+
+uninstall:
diff --git a/src/vidtime/ao_pins.h b/src/vidtime/ao_pins.h
new file mode 100644 (file)
index 0000000..fe9d387
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_PINS_H_
+#define _AO_PINS_H_
+
+#define HAS_TASK_QUEUE         1
+
+#define IS_FLASH_LOADER        0
+
+#define AO_POWER_MANAGEMENT    0
+
+/* 48MHz clock based on USB */
+#define AO_HSI48       1
+
+/* HCLK = 48MHz */
+#define AO_AHB_PRESCALER       1
+#define AO_RCC_CFGR_HPRE_DIV   STM_RCC_CFGR_HPRE_DIV_1
+
+/* APB = 48MHz */
+#define AO_APB_PRESCALER       1
+#define AO_RCC_CFGR_PPRE_DIV   STM_RCC_CFGR_PPRE_DIV_1
+
+#define HAS_EEPROM             0
+#define USE_INTERNAL_FLASH     0
+#define USE_STORAGE_CONFIG     0
+#define USE_EEPROM_CONFIG      0
+
+#define HAS_BEEP               0
+
+#define HAS_USB                        1
+#define AO_USB_DIRECTIO                0
+#define AO_PA11_PA12_RMP       1
+
+#define HAS_SPI_0              0
+
+#define AO_SENSOR_PORT         (&stm_gpioa)
+#define AO_SENSOR_PIN          3
+
+#define LOW_LEVEL_DEBUG                0
+
+#endif /* _AO_PINS_H_ */
diff --git a/src/vidtime/ao_vidtime.c b/src/vidtime/ao_vidtime.c
new file mode 100644 (file)
index 0000000..e7f2c21
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <ao.h>
+#include <ao_exti.h>
+
+static uint8_t sensor_value;
+static uint8_t vidtime_monitor;
+
+static void
+vidtime(void)
+{
+       ao_exti_enable(AO_SENSOR_PORT, AO_SENSOR_PIN);
+       for (;;) {
+               while (!vidtime_monitor)
+                       ao_sleep(&vidtime_monitor);
+               ao_sleep(&sensor_value);
+               printf("%d\n", sensor_value);
+               flush();
+       }
+}
+
+static void
+sensor_interrupt(void)
+{
+       uint8_t new = ao_gpio_get(AO_SENSOR_PORT, AO_SENSOR_PIN, foo);
+
+#if 0
+       if (new)
+               ao_exti_set_mode(AO_SENSOR_PORT, AO_SENSOR_PIN,
+                                AO_EXTI_MODE_FALLING);
+       else
+               ao_exti_set_mode(AO_SENSOR_PORT, AO_SENSOR_PIN,
+                                AO_EXTI_MODE_RISING);
+#endif
+       if (new != sensor_value) {
+               sensor_value = new;
+               ao_wakeup(&sensor_value);
+       }
+}
+
+static struct ao_task  vidtime_task;
+
+static void
+ao_init_vidtime(void)
+{
+       ao_enable_port(AO_SENSOR_PORT);
+       ao_exti_setup(AO_SENSOR_PORT, AO_SENSOR_PIN,
+                     AO_EXTI_MODE_RISING|
+                     AO_EXTI_MODE_FALLING|
+                     AO_EXTI_MODE_PULL_NONE|
+                     AO_EXTI_PRIORITY_MED,
+                     sensor_interrupt);
+       ao_add_task(&vidtime_task, vidtime, "vidtime");
+}
+
+static void
+ao_set_vidtime(void)
+{
+       ao_cmd_decimal();
+       if (ao_cmd_status == ao_cmd_success) {
+               vidtime_monitor = ao_cmd_lex_i != 0;
+               ao_wakeup(&vidtime_monitor);
+       }
+}
+
+const struct ao_cmds   ao_vidtime_cmds[] = {
+       { ao_set_vidtime, "V <0 off, 1 on>\0Enable/disable timing monitor" },
+       { 0, NULL }
+};
+
+void main(void)
+{
+       ao_clock_init();
+
+       ao_task_init();
+
+       ao_timer_init();
+
+       ao_dma_init();
+
+       ao_init_vidtime();
+
+       ao_usb_init();
+
+       ao_cmd_init();
+
+       ao_cmd_register(&ao_vidtime_cmds[0]);
+
+       ao_start_scheduler();
+}
diff --git a/src/vidtime/flash-loader/.gitignore b/src/vidtime/flash-loader/.gitignore
new file mode 100644 (file)
index 0000000..05f1a4d
--- /dev/null
@@ -0,0 +1,2 @@
+ao_product.h
+vidtime*
diff --git a/src/vidtime/flash-loader/Makefile b/src/vidtime/flash-loader/Makefile
new file mode 100644 (file)
index 0000000..57c65b5
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# AltOS flash loader build
+#
+
+TOPDIR=../..
+HARDWARE=vidtime-v1.0
+include $(TOPDIR)/stmf0/Makefile-flash.defs
diff --git a/src/vidtime/flash-loader/ao_pins.h b/src/vidtime/flash-loader/ao_pins.h
new file mode 100644 (file)
index 0000000..7feb936
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_PINS_H_
+#define _AO_PINS_H_
+
+#include <ao_flash_stm_pins.h>
+
+/* Debug port PA15 (pin 23) */
+
+#define AO_BOOT_PIN                    1
+#define AO_BOOT_APPLICATION_GPIO       (stm_gpioa)
+#define AO_BOOT_APPLICATION_PIN                15
+#define AO_BOOT_APPLICATION_VALUE      1
+#define AO_BOOT_APPLICATION_MODE       AO_EXTI_MODE_PULL_UP
+
+#define AO_USB_DIRECTIO                0
+#define AO_PA11_PA12_RMP       1
+
+#endif /* _AO_PINS_H_ */