2011-09-03 12:14:29 +03:00
|
|
|
/*
|
|
|
|
* labsw.c - Lab Switch initialization and main loop
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "regs.h"
|
|
|
|
#include "usb.h"
|
|
|
|
|
2011-09-03 18:33:43 +03:00
|
|
|
#include "config.h"
|
|
|
|
#include "io.h"
|
|
|
|
|
2011-09-03 12:14:29 +03:00
|
|
|
|
|
|
|
static void init_io(void)
|
|
|
|
{
|
2011-09-03 18:33:43 +03:00
|
|
|
P0SKIP = 0xff;
|
|
|
|
P1SKIP = 0xff;
|
|
|
|
P2SKIP = 0xff;
|
|
|
|
|
|
|
|
LED_MAIN_R_MODE |= 1 << LED_MAIN_R_BIT;
|
|
|
|
LED_MAIN_G_MODE |= 1 << LED_MAIN_G_BIT;
|
2011-09-05 20:10:42 +03:00
|
|
|
LED_CH1_R_MODE |= 1 << LED_CH1_R_BIT;
|
|
|
|
LED_CH1_G_MODE |= 1 << LED_CH1_G_BIT;
|
|
|
|
LED_CH2_R_MODE |= 1 << LED_CH2_R_BIT;
|
|
|
|
LED_CH2_G_MODE |= 1 << LED_CH2_G_BIT;
|
2011-09-03 18:33:43 +03:00
|
|
|
CH1_RELAY = 0;
|
|
|
|
CH2_RELAY = 0;
|
|
|
|
CH1_RELAY_MODE |= 1 << CH1_RELAY_BIT;
|
|
|
|
CH2_RELAY_MODE |= 1 << CH2_RELAY_BIT;
|
2011-09-05 20:10:42 +03:00
|
|
|
|
|
|
|
/* @@@ we need this while using the boot loader of cntr */
|
|
|
|
CH1_OPT_MODE &= ~(1 << CH1_OPT_BIT);
|
|
|
|
CH2_OPT_MODE &= ~(1 << CH2_OPT_BIT);
|
2011-09-03 12:14:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
init_io();
|
|
|
|
|
|
|
|
usb_init();
|
|
|
|
// ep0_init();
|
|
|
|
|
|
|
|
while (1) {
|
2011-09-03 18:33:43 +03:00
|
|
|
if (!BUT_MAIN) {
|
|
|
|
LED_MAIN_R = 1;
|
|
|
|
LED_MAIN_G = 0;
|
|
|
|
} else {
|
|
|
|
LED_MAIN_R = 0;
|
|
|
|
LED_MAIN_G = 1;
|
2011-09-05 20:10:42 +03:00
|
|
|
}
|
|
|
|
if (!BUT_CH1) {
|
|
|
|
LED_CH1_R = 1;
|
|
|
|
LED_CH1_G = 0;
|
|
|
|
CH1_RELAY = 1;
|
|
|
|
CH1_OPT = 0;
|
|
|
|
} else {
|
|
|
|
LED_CH1_R = 0;
|
|
|
|
LED_CH1_G = 1;
|
2011-09-03 18:33:43 +03:00
|
|
|
CH1_RELAY = 0;
|
2011-09-05 20:10:42 +03:00
|
|
|
CH1_OPT = 1;
|
|
|
|
}
|
|
|
|
if (!BUT_CH2) {
|
|
|
|
LED_CH2_R = 1;
|
|
|
|
LED_CH2_G = 0;
|
|
|
|
CH2_RELAY = 1;
|
|
|
|
CH2_OPT = 0;
|
|
|
|
} else {
|
|
|
|
LED_CH2_R = 0;
|
|
|
|
LED_CH2_G = 1;
|
2011-09-03 18:33:43 +03:00
|
|
|
CH2_RELAY = 0;
|
2011-09-05 20:10:42 +03:00
|
|
|
CH2_OPT = 1;
|
2011-09-03 18:33:43 +03:00
|
|
|
}
|
2011-09-03 12:14:29 +03:00
|
|
|
usb_poll();
|
|
|
|
}
|
|
|
|
}
|