~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-pcint.c

  • Committer: Selene Scriven
  • Date: 2020-07-06 20:24:28 UTC
  • mfrom: (188.1.294 fsm)
  • Revision ID: bzr@toykeeper.net-20200706202428-7pyen2ow9q2rtd9p
merged nearly a year of updates from the fsm branch, including the new product map

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <util/delay_basic.h>
25
25
 
26
26
uint8_t button_is_pressed() {
27
 
    // remember the past 32 measurements
28
 
    static uint32_t readings = 0;
29
 
    // take at least one new measurement,
30
 
    // and wait for measurements to settle to all zeroes or all ones
31
 
    do {
32
 
        // shift past readings and add current value
33
 
        readings = (readings << 1) | ((SWITCH_PORT & (1<<SWITCH_PIN)) == 0);
34
 
        // wait a moment
35
 
        _delay_loop_2(BOGOMIPS/16);  // up to 2ms to stabilize
36
 
    }
37
 
    while ((readings != 0) && (readings != 0xFFFFFFFF));
38
 
    button_last_state = readings;
39
 
    return readings;
 
27
    uint8_t value = ((SWITCH_PORT & (1<<SWITCH_PIN)) == 0);
 
28
    button_last_state = value;
 
29
    return value;
40
30
}
41
31
 
42
32
inline void PCINT_on() {
75
65
 
76
66
//void button_change_interrupt() {
77
67
#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 1634)
78
 
EMPTY_INTERRUPT(PCINT0_vect);
 
68
//EMPTY_INTERRUPT(PCINT0_vect);
 
69
#ifdef PCINT_vect
 
70
ISR(PCINT_vect) {
 
71
#else
 
72
ISR(PCINT0_vect) {
 
73
#endif
 
74
    irq_pcint = 1;
 
75
}
79
76
#else
80
77
    #error Unrecognized MCU type
81
78
#endif
104
101
        pushed = push_event(B_RELEASE);
105
102
    }
106
103
 
107
 
    // check if sequence matches any defined sequences
108
 
    // if so, send event to current state callback
 
104
    // send event to the current state callback
109
105
    if (pushed) {
110
106
        button_last_state = pressed;
111
107
        emit_current_event(0);