c733c71765b5adf574ce49c72ab2be376b03b9cd
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;})
20 * Various sinks for valuable program memory
23 // #define USE_EEPROM_UPDATE /* 14 bytes */
24 //#define INTERPRET_DRIVE_COMMANDS
25 #define INTERPRET_DRIVE_SIMPLE
27 static inline void setup_hw(void)
29 /* Turn off the 1/8 clock prescaler - now running at 16MHz*/
30 CLKPR
= (1 << CLKPCE
);
35 OUTPUT_PIN(PIN_DRIVE
);
37 setpin(PIN_BTN
, 1); /* Need pullup */
39 GIMSK
|= _BV(PCIE
); /* Enable pin change interrupt for sense port */
40 PCMSK
|= _BV(PCINT4
); /* PB4, Rail sense input */
42 /* Change interrupt for button */
43 PCMSK
|= _BV(PCINT1
); /* PB1 */
45 /* Setup timer 0, used for mm_switch */
46 TCCR0A
= 0; /* Normal mode */
47 TCCR0B
= 0; /* Timer off */
48 TIMSK
|= _BV(OCIE0A
); /* Get a match interrupt */
50 /* We need 13 + 45,5 us delay, That's 464 clocks @8MHz*/
51 //OCR0A = 91; /* Prescaler 8 is used */
53 /* Timer 1 for timeout */
54 /* We set it to 1024us by prescaler 64 and running full 256 */
56 // TIMSK |= _BV(TOIE1); /* Overflow interrupt */
60 * Function to trigger an oscilloscope on the drive pin
62 * Can be altered to use the LED.
65 static void __attribute__((unused
)) trigger(void)
74 * Configuration for mm receiver code.
77 #define MM_SENSE (!PINVAL(PIN_SENSE))
78 #define MM_TSTART_FAST ({TCNT0 = 0; GTCCR |= 1; OCR0A = 120; TCCR0B = 2;})
79 #define MM_TSTART_SLOW ({TCNT0 = 0; GTCCR |= 1; OCR0A = 230; TCCR0B = 2;})
80 #define MM_TSTOP ({TCCR0B = 0;})
81 #define MM_TIMER_INT_VECT TIMER0_COMPA_vect
83 /* Costs 63 bytes program memory */
84 #define MM_FILTER_REPEATED
86 #define USE_EEPROM_UPDATE