diff --git a/emulator/config.dist.h b/emulator/config.dist.h new file mode 100644 index 0000000..f9f4600 --- /dev/null +++ b/emulator/config.dist.h @@ -0,0 +1,75 @@ +/** + * You can either configure everything in this file, + * or include one of the predefined configurations + * Just copy your variant of config.dist.h to config.h + */ +//#include "configs/uno.h" +//#include "configs/promicro.h" + +// SOFTWARE CONFIG +/** + * Enable MDC and/or CDC. + * Just define MDC and/or CDC + */ +#define MDC +//#define CDC + +/** + * Enable serial output + */ +//#define ENABLE_SERIAL + +// HARDWARE CONFIG + +/** + * Pin Configuration: + * Use pins on the same port. I.e., use ATmega PINs: + * Pnd for Data + * Pnc for Clock (needs to support interrupts!) + * Pnb for Busy + * + * Than set DDRx, PORTx and PINx to the port n out of {A,B,C,D} + * The Pin numbers are d,c,b + * For the clock, we also need the interrupt number and name. + * You can look these things up in your boards pin mapping online + * + * My config on a Sparkfun Pro Micro: + * DATA: Digital Pin 2 = PD1 (SDA/INT1) + * CLK: Digital Pin 3 = PD0 (OC0B/SCL/INT0) + * BUSY: Digital Pin 4 = PD4 (ICP1/ADC8) + * + * -> Port D, DATA on 1, CLK on 0, BUSY on 4. + * -> Clock is on INT0 + * + * Arduino Code was too slow, so this is done the fast way + */ +//#define DDRx DDRD +//#define PORTx PORTD +//#define PINx PIND +//#define DATA_PIN 1 +//#define BUSY_PIN 4 +//#define CLK_PIN 0 +//#define CLK_INT 0 +//#define CLK_INTx INT0 + +/** + * This macro controls a LED to signal error [perma on] or init/signaling [blink] + * For the pro micro it's predefined in the default header files, + * but you might want to write one for other boards + * + * LED blink for 1s -> signaling presence + * LED on -> processing was too low + */ +//#define RXLED1 digitalWrite (your_led_pin, HIGH) +//#define RXLED0 digitalWrite (your_led_pin, LOW) + +/** + * This macro controls a LED to signal communication + * For the pro micro it's predefined in the default header files, + * but you might want to write one for other boards + * + * LED on -> no data to process (but we saw the master) + * LED off -> processing data + */ +//#define TXLED1 digitalWrite (your_led_pin, HIGH) +//#define TXLED0 digitalWrite (your_led_pin, LOW) diff --git a/emulator/config_promicro.h b/emulator/config_promicro.h new file mode 100644 index 0000000..73c2571 --- /dev/null +++ b/emulator/config_promicro.h @@ -0,0 +1,21 @@ +//make sure to include just a single config file +#ifndef CONFIGURED +#define CONFIGURED +#else +#error JUST INCLUDE A SINGLE CONFIG FILE +#endif + +/** + * My config on a Sparkfun Pro Micro: + * DATA: Digital Pin 2 = PD1 (SDA/INT1) + * CLK: Digital Pin 3 = PD0 (OC0B/SCL/INT0) + * BUSY: Digital Pin 4 = PD4 (ICP1/ADC8) + */ +#define DDRx DDRD +#define PORTx PORTD +#define PINx PIND +#define DATA_PIN 1 +#define BUSY_PIN 4 +#define CLK_PIN 0 +#define CLK_INT 0 +#define CLK_INTx INT0 diff --git a/emulator/config_uno.h b/emulator/config_uno.h new file mode 100644 index 0000000..2346514 --- /dev/null +++ b/emulator/config_uno.h @@ -0,0 +1,26 @@ +//make sure to include just a single config file +#ifndef CONFIGURED +#define CONFIGURED +#else +#error JUST INCLUDE A SINGLE CONFIG FILE +#endif + +/** + * My config on a Arduino Uno/ATmega 168 + * DATA: Digital Pin 3 = PD3 (PCINT19/OC2B/INT1) OLD: PD1 (SDA/INT1) + * CLK: Digital Pin 2 = PD2 (PCINT18/INT0) OLD: PD0 (OC0B/SCL/INT0) + * BUSY: Digital Pin 4 = PD4 (PCINT20/XCK/T0) OLD: PD4 (ICP1/ADC8) + */ +#define DDRx DDRD +#define PORTx PORTD +#define PINx PIND +#define DATA_PIN 3 +#define BUSY_PIN 4 +#define CLK_PIN 2 +#define CLK_INT 0 +#define CLK_INTx INT0 + +#define TXLED0 +#define TXLED1 +#define RXLED0 +#define RXLED1 diff --git a/emulator/emulator.ino b/emulator/emulator.ino index fd087bf..2b7b4b4 100644 --- a/emulator/emulator.ino +++ b/emulator/emulator.ino @@ -21,67 +21,10 @@ */ /** - * Enable MDC and/or CDC. - * Just define MDC and/or CDC + * Your configuration goes to config.h + * Take a look at config.dist.h for details */ -#define MDC -//#define CDC - -/** - * Pin Configuration: - * Use pins on the same port. I.e., use ATmega PINs: - * Pnd for Data - * Pnc for Clock (needs to support interrupts!) - * Pnb for Busy - * - * Than set DDRx, PORTx and PINx to the port n out of {A,B,C,D} - * The Pin numbers are d,c,b - * For the clock, we also need the interrupt number and name. - * You can look these things up in your boards pin mapping online - * - * My config on a Sparkfun Pro Micro: - * DATA: Digital Pin 2 = PD1 (SDA/INT1) - * CLK: Digital Pin 3 = PD0 (OC0B/SCL/INT0) - * BUSY: Digital Pin 4 = PD4 (ICP1/ADC8) - * - * -> Port D, DATA on 1, CLK on 0, BUSY on 4. - * -> Clock is on INT0 - * - * Arduino Code was too slow, so this is done the fast way - */ -#define DDRx DDRD -#define PORTx PORTD -#define PINx PIND -#define DATA_PIN 1 -#define BUSY_PIN 4 -#define CLK_PIN 0 -#define CLK_INT 0 -#define CLK_INTx INT0 - -/** - * Enable serial output - */ -//#define ENABLE_SERIAL - -/** - * This macro controls a LED to signal error [perma on] or init/signaling [blink] - * For the pro micro it's predefined, but you might want to write one for other boards - * - * LED blink for 1s -> signaling presence - * LED on -> processing was too low - */ -//#define RXLED1 digitalWrite (your_led_pin, HIGH) -//#define RXLED0 digitalWrite (your_led_pin, LOW) - -/** - * This macro controls a LED to signal communication - * For the pro micro it's predefined, but you might want to write one for other boards - * - * LED on -> no data to process (but we saw the master) - * LED off -> processing data - */ -//#define TXLED1 digitalWrite (your_led_pin, HIGH) -//#define TXLED0 digitalWrite (your_led_pin, LOW) +#include "config.h" #include "blink.h" #include "io.h" @@ -202,4 +145,4 @@ bool SerialEvent () { } return false; } -#endif +#endif