From c1181687a71255c1ecb692e280df283aacaf6901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Ass=C3=A9nat?= Date: Sat, 26 Oct 2013 20:26:58 +0000 Subject: [PATCH] Fix floating pins bug, improve debug switches --- maplebus.c | 71 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/maplebus.c b/maplebus.c index df3dd55..a3c62da 100644 --- a/maplebus.c +++ b/maplebus.c @@ -21,6 +21,11 @@ #include #include "usbdrv.h" +#undef NOLRC +#undef TRACE_RX_START_END +#undef TRACE_DECODED +#undef TRACE_PIN1_BITS + // // // PORTC0 : Pin 1 @@ -29,10 +34,14 @@ void maple_init(void) { - DDRC &= ~0x03; + DDRC = 0xFC; + PORTC = 0x03; } +#define transmitMode() do { PORTC |= 0x03; DDRC |= 0x03; } while(0) +#define inputMode() do { PORTC |= 0x03; DDRC &= ~0x03; } while(0) -#define MAPLE_BUF_SIZE 640 + +#define MAPLE_BUF_SIZE 641 static unsigned char maplebuf[MAPLE_BUF_SIZE]; static unsigned char buf_used; static unsigned char buf_phase; @@ -47,6 +56,8 @@ static void buf_reset(void) static void buf_addBit(char value) { + // The values in maplebuf will be written + // directly to PORTC. Unused bits will be low. if (buf_phase & 0x01) { maplebuf[buf_used] = PIN_5; if (value) { @@ -72,6 +83,15 @@ static int maplebus_decode(unsigned char *data, unsigned int maxlen) unsigned char last_fell; int i; +#ifdef TRACE_DECODED + PORTB |= 0x10; + PORTB &= ~0x10; + PORTB |= 0x10; + PORTB &= ~0x10; + PORTB |= 0x10; + PORTB &= ~0x10; +#endif + // Look for the initial phase 1 (Pin 1 high, Pin 5 low). This // is to skip what we got of the sync/start of frame sequence. // @@ -90,7 +110,15 @@ static int maplebus_decode(unsigned char *data, unsigned int maxlen) last_fell = 0; for (; i