#include #include #include "adc.h" #include "led.h" #include "button.h" #include "main.h" /* Communication driver */ #define SLAVE_ENABLE_DDR DDRA #define SLAVE_ENABLE_REG PINA #define SLAVE_ENABLE_PIN 1 #include #include "main.h" void comm_init(); // the public instance of the app buffer struct app app = {}; uint8_t channel_map[ADC_BUFFER_SIZE] = { 0, 1, 2, 3, 7 }; // initalizes the application modules void init() { // init button module (making the button light up on press) // module also updates app.buffer.button for us button_init(); // init adc module // will sample 0x8F (CHANNEL 8 and 0-3) // this module also updates app.buffer.poti and slider for us adc_init(channel_map); // init communication module comm_init(); // start all modules adc_start(); // activate interrupts (effectivly starting the application) sei(); } void comm_init() { DDRA |= (1<>7)&0x7F; if (++count == ADC_BUFFER_SIZE) { comm_state = COMM_SEND_END; } else { comm_state = COMM_SEND_START; } break; case COMM_SEND_END: count = 0; USIDR = app.state.state.button | 0x80; default: comm_state = COMM_WAIT; adc_start(); break; } USISR |= (1< // little debug helper function // FIXME: remove when not needed void delay(uint16_t d) { while(d--) { _delay_ms(1); } } int main() { init(); while(1) { // service serial interface // slightly more stable then interrupt comm_service(); } }