ffa98a9dd3b8e67caf03ee13005251987636f72b
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)
10 #define PIN_TRIGGER _PIN(PORTB, PB0)
11 #define BTN_PRESSED (!PINVAL(PIN_BTN))
13 #define STOP_TIMER1 ({TCCR1 = 0; TCNT1 = 1;})
17 static inline void setup_hw(void)
19 /* Turn off the 1/8 clock prescaler - now running at 16MHz*/
20 CLKPR
= (1 << CLKPCE
);
24 setpin(PIN_TRIGGER
, 0);
25 setpin(PIN_BTN
, 1); /* Need pullup */
28 OUTPUT_PIN(PIN_DRIVE
);
30 OUTPUT_PIN(PIN_TRIGGER
);
32 GIMSK
|= _BV(PCIE
); /* Enable pin change interrupt for sense port */
33 PCMSK
|= _BV(PCINT4
); /* PB4, Rail sense input */
35 /* Change interrupt for button */
36 PCMSK
|= _BV(PCINT1
); /* PB1 */
38 /* Setup timer 0, used for mm_switch */
39 TCCR0A
= 0; /* Normal mode */
40 TCCR0B
= 2; /* Prescaler 8 */
51 GTCCR
|= _BV(PWM1B
) | _BV(COM1B0
);
57 * Function to trigger an oscilloscope on the drive pin
59 * Can be altered to use the LED.
62 static inline void __attribute__((unused
)) trigger(void)
64 setpin(PIN_TRIGGER
, 1);
65 setpin(PIN_TRIGGER
, 0);
68 static inline void __attribute__((unused
)) trigger_on(void)
70 setpin(PIN_TRIGGER
, 1);
73 static inline void __attribute__((unused
)) trigger_off(void)
75 setpin(PIN_TRIGGER
, 0);
79 * Configuration for mm receiver code.
81 #define MM_SENSE (PINVAL(PIN_SENSE))
82 #define MM_TIMER_INT_VECT TIMER0_OVF_vect
85 GTCCR |= _BV(TSM) | _BV(PSR0); \
90 #define MM_RESETFLAG TIFR |= _BV(OVF0)
91 //#define MM_USE_QUEUE
92 #define MM_QUEUE_DEPTH 8
93 #define MM_USE_CALLBACK
95 #ifdef USE_REGISTER_VARS
96 uint8_t register drive_on
asm("r12");
97 uint8_t register slope
asm("r13");