1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-15 10:30:37 +02:00

labsw/fw/: added simple button -> LED / relay change loop

This commit is contained in:
Werner Almesberger 2011-09-03 12:33:43 -03:00
parent e73383b7d8
commit 5649c890f7
4 changed files with 89 additions and 1 deletions

View File

@ -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

View File

@ -1 +1,2 @@
#include "usb-id.h"
#include "io-parts.h"

43
labsw/fw/io.h Normal file
View File

@ -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 */

View File

@ -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();
}
}