From 06dac6551418ba817798c187f198b9b00c1dda74 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 7 May 2018 11:26:42 -0700 Subject: altos: add 'vidtime', a simple brightness monitor 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 --- src/vidtime/ao_vidtime.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/vidtime/ao_vidtime.c (limited to 'src/vidtime/ao_vidtime.c') diff --git a/src/vidtime/ao_vidtime.c b/src/vidtime/ao_vidtime.c new file mode 100644 index 00000000..e7f2c219 --- /dev/null +++ b/src/vidtime/ao_vidtime.c @@ -0,0 +1,105 @@ +/* + * Copyright © 2012 Keith Packard + * + * 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 +#include + +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(); +} -- cgit v1.2.3 From 5a26df7db9453bf0596f729a23efb90e5e8a63c7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 16 May 2018 22:05:26 -0700 Subject: altos/vidtime: Check for value change in normal code, not irq This makes sure each value change is reported to the user. Signed-off-by: Keith Packard --- src/vidtime/ao_vidtime.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/vidtime/ao_vidtime.c') diff --git a/src/vidtime/ao_vidtime.c b/src/vidtime/ao_vidtime.c index e7f2c219..1b9b9e1c 100644 --- a/src/vidtime/ao_vidtime.c +++ b/src/vidtime/ao_vidtime.c @@ -24,33 +24,25 @@ static uint8_t vidtime_monitor; static void vidtime(void) { + uint8_t old = 0, got; + 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); + while ((got = sensor_value) == old) + ao_sleep(&sensor_value); + printf("%d\n", got); flush(); + old = got; } } 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); - } + sensor_value = ao_gpio_get(AO_SENSOR_PORT, AO_SENSOR_PIN, foo); + ao_wakeup(&sensor_value); } static struct ao_task vidtime_task; -- cgit v1.2.3