pomodoro-avr

Pomodoro timer на базе Attiny45
git clone git://git.konyahin.xyz/pomodoro-avr
Log | Files | Refs | LICENSE

interrupt.c (1196B)


      1 /*
      2  * avr pomodoro timer
      3  * © 2022 Anton Konyahin <me@konyahin.xyz>
      4  *
      5  * This program is free software: you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation, either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17 */
     18 
     19 #include <avr/io.h>
     20 #include <avr/interrupt.h>
     21 #include <avr/sleep.h>
     22 #include <util/delay.h>
     23 
     24 #include "interrupt.h"
     25 
     26 static void (*callback) (void);
     27 
     28 void
     29 init_interrupt(void (*on_press) (void))
     30 {
     31     callback = on_press;
     32 
     33     // as input
     34     DDRB &= ~(1 << PB2);
     35     // enable external interrupt
     36     GIMSK |= (1 << INT0);
     37 }
     38 
     39 ISR (INT0_vect)
     40 {
     41     if (PINB & (1 << PB2))
     42         return;
     43     _delay_ms(30);
     44     if (PINB & (1 << PB2))
     45         return;
     46     (*callback)();
     47 }
     48