diff --git a/firmware/slider/SliderCommunication b/firmware/slider/SliderCommunication index 3141a62..362c654 160000 --- a/firmware/slider/SliderCommunication +++ b/firmware/slider/SliderCommunication @@ -1 +1 @@ -Subproject commit 3141a62e62012dee60192e6ad1c95ee5b63fc8ce +Subproject commit 362c65440c49e09e06e89299d51a25003e9724a0 diff --git a/firmware/slider/adc.c b/firmware/slider/adc.c index 1e978fe..439796a 100644 --- a/firmware/slider/adc.c +++ b/firmware/slider/adc.c @@ -12,56 +12,25 @@ #include // global adc instance -volatile adc_t adc; - -static inline void adc_next() { - do { - adc.current_channel = (adc.current_channel+1)%8; - - if (!adc.current_channel) { - adc.current_sample = adc.buffer.ptr-1; - } - } while(!(adc.channel_mask & (1< -typedef struct { - byte_t * buffer_start, * buffer_end; - - volatile byte_t * read; - volatile byte_t * write; - volatile byte_t count; - - iface_t iface; -} comm_t; - -comm_t comm; - -void comm_write(iface_t * iface, byte_t byte) { - if ((comm.write == comm.read) && comm.count) { - // write overflow - return; - } - - *comm.write = byte; - ++comm.count; - - // advance write pointer - if ((++comm.write) >= comm.buffer_end) { - comm.write = comm.buffer_start; - } -} - -inline byte_t comm_read() { - if (!comm.count) - return 0x00; - - byte_t result = *comm.read; - - --comm.count; - if ((++comm.read) >= comm.buffer_end) { - comm.read = comm.buffer_start; - } - - return result; -} - -byte_t comm_buffer[10]; - -void comm_init() -{ - comm.buffer_start = comm_buffer; - comm.buffer_end = comm_buffer + sizeof(comm_buffer); - - // reset buffer - comm.write = comm.buffer_start; - comm.read = comm.buffer_start; - comm.count = 0; - - // TODO: setup pins - 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 @@ -158,8 +126,10 @@ void delay(uint16_t d) int main() { init(); - + while(1) { - // nothing to do here, the application is interrupt-driven + // service serial interface + // slightly more stable then interrupt + comm_service(); } }