diff --git a/firmware/slider/CMakeLists.txt b/firmware/slider/CMakeLists.txt index caade73..050e91c 100644 --- a/firmware/slider/CMakeLists.txt +++ b/firmware/slider/CMakeLists.txt @@ -7,5 +7,5 @@ project(slider_firmware C) add_subdirectory(SliderCommunication) -add_avr_executable(slider_firmware led.c main.c adc.c button.c) +add_avr_executable(slider_firmware led.c main.c adc.c button.c comm.c) target_link_libraries(slider_firmware DSPLAB_SliderCommunication) diff --git a/firmware/slider/adc.c b/firmware/slider/adc.c index 439796a..2b22eec 100644 --- a/firmware/slider/adc.c +++ b/firmware/slider/adc.c @@ -16,21 +16,9 @@ adc_t adc; /* adc driver */ void adc_init(uint8_t * channels) { - adc.current_channel = 0; - adc.channel_map = channels; +// adc.current_channel = 0; +// adc.channel_map = channels; ADMUX = channels[0]; - ADCSRA = (1< + +void comm_init() +{ + DDRA |= (1< -#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, + 0, 2, 3, 7 @@ -49,12 +46,8 @@ void init() sei(); } -void comm_init() -{ - DDRA |= (1<>7)&0x7F; if (++count == ADC_BUFFER_SIZE) { @@ -97,20 +98,23 @@ static inline void comm_service() } break; case COMM_SEND_END: + // cleanup the transaction count = 0; - USIDR = app.state.state.button | 0x80; + // transmit the button state and end of transaction + USIDR = app.button | 0x80; default: comm_state = COMM_WAIT; - adc_start(); + // reset channel of adc back to 0 + adc_set_channel(channel_map[0]); break; } USISR |= (1< // little debug helper function diff --git a/firmware/slider/main.h b/firmware/slider/main.h index 3e8c14a..f9025aa 100644 --- a/firmware/slider/main.h +++ b/firmware/slider/main.h @@ -7,9 +7,9 @@ #include struct app { - slave_t state; + volatile uint8_t button; }; extern struct app app; -#endif \ No newline at end of file +#endif