6 #define PIN_LED _PIN(PORTB, PORTB2)
7 #define PIN_SENSE _PIN(PORTB, PORTB4)
8 #define PIN_DRIVE _PIN(PORTB, PORTB3)
9 //#define PIN_DRIVE PIN_LED
10 #define PIN_BTN _PIN(PORTB, PB1)
12 #define BTN_PRESSED (!PINVAL(PIN_BTN))
14 #define START_TIMER0 ({TCNT0 = 0; TCCR0B = 2;})
15 #define START_TIMER1 ({TCNT1 = 1; TCCR1 = 7; GTCCR |= 2;})
16 #define STOP_TIMER1 ({TCCR1 = 0; TCNT1 = 1;})
18 static inline void setup_hw(void)
20 /* Turn off the 1/8 clock prescaler - now running at 16MHz*/
21 CLKPR
= (1 << CLKPCE
);
26 OUTPUT_PIN(PIN_DRIVE
);
28 setpin(PIN_BTN
, 1); /* Need pullup */
30 GIMSK
|= _BV(PCIE
); /* Enable pin change interrupt for sense port */
31 PCMSK
|= _BV(PCINT4
); /* PB4, Rail sense input */
33 /* Change interrupt for button */
34 PCMSK
|= _BV(PCINT1
); /* PB1 */
36 /* Setup timer 0, used for mm_switch */
37 TCCR0A
= 0; /* Normal mode */
38 TCCR0B
= 0; /* Timer off */
39 TIMSK
|= _BV(OCIE0A
); /* Get a match interrupt */
46 GTCCR
|= _BV(PWM1B
) | _BV(COM1B0
);
52 * Function to trigger an oscilloscope on the drive pin
54 * Can be altered to use the LED.
57 static void __attribute__((unused
)) trigger(void)
66 * Configuration for mm receiver code.
69 #define MM_SENSE (!PINVAL(PIN_SENSE))
70 #define MM_TSTART ({TCNT0 = 0; GTCCR |= 1; OCR0A = 115; TCCR0B = 2;})
71 #define MM_TIMER_INT_VECT TIMER0_COMPA_vect
73 /* Costs 38 bytes program memory */
74 #define MM_FILTER_REPEATED
75 #define USE_EEPROM_UPDATE
77 #ifdef USE_REGISTER_VARS
78 uint8_t register drive_on
asm("r8");