6 #define PIN_LED _PIN(PORTB, PORTB2)
7 #define PIN_SENSE _PIN(PORTB, PORTB4)
8 #define PIN_DRIVE _PIN(PORTB, PORTB3)
9 #define PIN_BTN _PIN(PORTB, PB1)
11 #define BTN_PRESSED (!PINVAL(PIN_BTN))
13 #define START_TIMER0 ({TCNT0 = 0; TCCR0B = 2;})
14 #define START_TIMER1 ({TCNT1 = 1; TCCR1 = 7; GTCCR |= 2;})
15 #define STOP_TIMER1 ({TCCR1 = 0; TCNT1 = 1;})
19 * Various sinks for valuable program memory
22 // #define USE_EEPROM_UPDATE /* 14 bytes */
23 //#define INTERPRET_DRIVE_COMMANDS
24 #define INTERPRET_DRIVE_SIMPLE
26 static inline void setup_hw(void)
28 /* Turn off the 1/8 clock prescaler - now running at 16MHz*/
29 CLKPR
= (1 << CLKPCE
);
34 OUTPUT_PIN(PIN_DRIVE
);
36 setpin(PIN_BTN
, 1); /* Need pullup */
38 GIMSK
|= _BV(PCIE
); /* Enable pin change interrupt for sense port */
39 PCMSK
|= _BV(PCINT4
); /* PB4, Rail sense input */
41 /* Change interrupt for button */
42 PCMSK
|= _BV(PCINT1
); /* PB1 */
44 /* Setup timer 0, used for mm_switch */
45 TCCR0A
= 0; /* Normal mode */
46 TCCR0B
= 0; /* Timer off */
47 TIMSK
|= _BV(OCIE0A
); /* Get a match interrupt */
49 /* We need 13 + 45,5 us delay, That's 464 clocks @8MHz*/
50 //OCR0A = 91; /* Prescaler 8 is used */
52 /* Timer 1 for timeout */
53 /* We set it to 1024us by prescaler 64 and running full 256 */
55 // TIMSK |= _BV(TOIE1); /* Overflow interrupt */
59 * Function to trigger an oscilloscope on the drive pin
61 * Can be altered to use the LED.
64 static void __attribute__((unused
)) trigger(void)
73 * Configuration for mm receiver code.
76 #define MM_SENSE (!PINVAL(PIN_SENSE))
77 #define MM_TSTART_FAST ({TCNT0 = 0; GTCCR |= 1; OCR0A = 110; TCCR0B = 2;})
78 #define MM_TSTART_SLOW ({TCNT0 = 0; GTCCR |= 1; OCR0A = 220; TCCR0B = 2;})
79 #define MM_TSTOP ({TCCR0B = 0;})
80 #define MM_TIMER_INT_VECT TIMER0_COMPA_vect
82 /* Costs 63 bytes program memory */
83 #define MM_FILTER_REPEATED