parent
635e55e6b0
commit
f84a135ace
@ -1 +1 @@
|
||||
Subproject commit 36d759d94c6fa9166de35624989858811a73861f
|
||||
Subproject commit 3141a62e62012dee60192e6ad1c95ee5b63fc8ce
|
@ -0,0 +1,31 @@
|
||||
#include "button.h"
|
||||
#include "main.h"
|
||||
#include "led.h"
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
void button_init()
|
||||
{
|
||||
led_init();
|
||||
|
||||
// enable pullup on button pin
|
||||
BUTTON_DDR &= ~(1<<BUTTON_PIN);
|
||||
BUTTON_PORT |= (1<<BUTTON_PIN);
|
||||
|
||||
// activate pin change interrupt
|
||||
// PCINT9
|
||||
PCMSK1 |= (1<<PCINT9);
|
||||
GIMSK |= (1<<PCIE1); // enable PCINT1
|
||||
}
|
||||
|
||||
button_state_t button_is_pressed()
|
||||
{
|
||||
return (BUTTON_REG&(1<<BUTTON_PIN)) > 0;
|
||||
}
|
||||
|
||||
ISR(PCINT1_vect) {
|
||||
if(!(BUTTON_REG&(1<<BUTTON_PIN))) {
|
||||
app.state.state.button = !app.state.state.button;
|
||||
led_toggle();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
#ifndef BUTTON_H_
|
||||
#define BUTTON_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
/* button driver */
|
||||
#define BUTTON_DDR DDRB
|
||||
#define BUTTON_PORT PORTB
|
||||
#define BUTTON_REG PINB
|
||||
#define BUTTON_PIN 1
|
||||
|
||||
typedef enum {
|
||||
BUTTON_RELEASED = 0,
|
||||
BUTTON_PRESSED = 1
|
||||
} button_state_t;
|
||||
|
||||
void button_init();
|
||||
button_state_t button_is_pressed();
|
||||
|
||||
|
||||
#endif // BUTTON_H_
|
@ -0,0 +1,16 @@
|
||||
|
||||
#ifndef APP_H__
|
||||
#define APP_H__
|
||||
|
||||
#include <communication.h>
|
||||
#include "adc.h"
|
||||
#include <slave/slave.h>
|
||||
|
||||
struct app {
|
||||
slave_t state;
|
||||
adc_sample_t adc_buffer[5];
|
||||
};
|
||||
|
||||
extern struct app app;
|
||||
|
||||
#endif
|
Loading…
Reference in new issue