From 5649c890f79f1a6ab9af121f9a38ba8a3482df05 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 3 Sep 2011 12:33:43 -0300 Subject: [PATCH] labsw/fw/: added simple button -> LED / relay change loop --- labsw/fw/Makefile | 22 +++++++++++++++++++++- labsw/fw/config.h | 1 + labsw/fw/io.h | 43 +++++++++++++++++++++++++++++++++++++++++++ labsw/fw/labsw.c | 24 ++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 labsw/fw/io.h diff --git a/labsw/fw/Makefile b/labsw/fw/Makefile index d2bba16..ac49633 100644 --- a/labsw/fw/Makefile +++ b/labsw/fw/Makefile @@ -12,7 +12,7 @@ MAIN = labsw -OBJS = $(MAIN) usb descr # version ep0 +OBJS = $(MAIN) usb descr version # ep0 F32XBASE = ../../../f32xbase @@ -28,6 +28,26 @@ USB_ID = $(shell \ .PHONY: dfu +all: io-parts.h + +io-parts.h: io.h Makefile + cpp -dD $< | \ + sed '1,/IO_H/d' | \ + awk \ + 'BEGIN { print "/* MACHINE-GENERATED. DO NOT EDIT ! */"; \ + print "#ifndef IO_PARTS_H"; \ + print "#define IO_PARTS_H"; } \ + /#define/ && $$3 != "" { \ + split($$3, a, "_"); \ + print $$1, $$2 "_PORT", a[1]; \ + print $$1, $$2 "_MODE", a[1] "MDOUT"; \ + print $$1, $$2 "_BIT", a[2]; } \ + END { print "#endif" }' >$@ || \ + { rm -f $@; exit 1; } + +#clean:: +# rm -f io-parts.h + # hack: for now, we just reuse the boot loader from cntr USB_ID = 20b7:cb72 diff --git a/labsw/fw/config.h b/labsw/fw/config.h index f9c4b8c..165f2d6 100644 --- a/labsw/fw/config.h +++ b/labsw/fw/config.h @@ -1 +1,2 @@ #include "usb-id.h" +#include "io-parts.h" diff --git a/labsw/fw/io.h b/labsw/fw/io.h new file mode 100644 index 0000000..c02fa14 --- /dev/null +++ b/labsw/fw/io.h @@ -0,0 +1,43 @@ +/* + * io.h - I/O pin assignment + * + * Written 2011 by Werner Almesberger + * Copyright 2011 Werner Almesberger + * + * 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; either version 2 of the License, or + * (at your option) any later version. + */ + + +#ifndef IO_H +#define IO_H + +#define IN_1 P0_0 +#define IN_2 P0_1 +#define IN_4 P0_2 +#define IN_3 P0_3 + +#define BUT_MAIN P0_5 +#define BUT_CH1 P0_6 +#define BUT_CH2 P0_7 + +#define LED_CH1_R P1_0 +#define LED_CH1_G P1_1 +#define LED_CH2_R P1_2 +#define LED_CH2_G P1_3 +#define LED_MAIN_R P1_4 +#define LED_MAIN_G P1_5 + +#define CH1_RELAY P2_0 +#define CH2_RELAY P2_1 +#define CH2_OPT P2_2 +#define CH1_OPT P2_3 + +#define OUT_1 P2_4 +#define OUT_2 P2_5 +#define OUT_3 P2_6 +#define OUT_4 P2_7 + +#endif /* !IO_H */ diff --git a/labsw/fw/labsw.c b/labsw/fw/labsw.c index 9948bd7..b97f7c9 100644 --- a/labsw/fw/labsw.c +++ b/labsw/fw/labsw.c @@ -16,9 +16,22 @@ #include "regs.h" #include "usb.h" +#include "config.h" +#include "io.h" + static void init_io(void) { + P0SKIP = 0xff; + P1SKIP = 0xff; + P2SKIP = 0xff; + + LED_MAIN_R_MODE |= 1 << LED_MAIN_R_BIT; + LED_MAIN_G_MODE |= 1 << LED_MAIN_G_BIT; + CH1_RELAY = 0; + CH2_RELAY = 0; + CH1_RELAY_MODE |= 1 << CH1_RELAY_BIT; + CH2_RELAY_MODE |= 1 << CH2_RELAY_BIT; } @@ -30,6 +43,17 @@ void main(void) // ep0_init(); while (1) { + if (!BUT_MAIN) { + LED_MAIN_R = 1; + LED_MAIN_G = 0; + CH1_RELAY = 1; + CH2_RELAY = 1; + } else { + LED_MAIN_R = 0; + LED_MAIN_G = 1; + CH1_RELAY = 0; + CH2_RELAY = 0; + } usb_poll(); } }