From 5d9d373a959271b498710817d08c2ea8e153aa6e Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Thu, 13 Oct 2011 20:33:30 +0200 Subject: correct firmware?? --- firmware/adc.c | 152 +++++++++++++++++++++++++++------------------------------ 1 file changed, 71 insertions(+), 81 deletions(-) (limited to 'firmware/adc.c') diff --git a/firmware/adc.c b/firmware/adc.c index 915dbce..a9449b7 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -37,27 +37,19 @@ #include "protocol.h" #include "adc.h" -#include -#include "debug.h" - - void adc_parser(char *buf) { - //debugf("adc parser CMD %02x\n",buf[0]); switch(buf[0]) { case CMD_ADC_INIT_PIN: - adc_init_usb(buf[2]); - break; - case CMD_ADC_DEINIT_PIN: - adc_deinit_usb(buf[2]); - break; + adc_init_usb((int)buf[2]); + break; case CMD_ADC_GET: - adc_get_usb(buf[2]); - break; + adc_get_usb((int)buf[2]); + break; case CMD_ADC_REF: - adc_ref_usb(buf[2]); - break; + adc_ref_usb((int)buf[2]); + break; default: answer[0]=buf[0]; @@ -67,49 +59,42 @@ void adc_parser(char *buf) } } -int adc_init(uint8_t pin) +int adc_init(int pin) { - if (pin >= 10 && pin <= 17) - { - octopus.ports[pin] = PIN_AD; - ADMUX |= (1<= 33 && pin <= 40) + { + octopus.ports[pin] = PIN_AD; + + switch(pin) + { + case 40: break; + case 39: break; + case 38: break; + case 37: break; + case 36: break; + case 35: break; + case 34: break; + case 33: break; + default: + return RSP_IMPOSSIBLE_PIN_CONFIG; + } + return RSP_OK; + } + return RSP_UNKOWN_PIN; } -void adc_init_usb(uint8_t pin) +void adc_init_usb(int pin) { answer[0]=CMD_ADC_INIT_PIN; - answer[1]=(unsigned char)adc_init(pin); - answer[2]=0; - - CommandAnswer(3); -} - -int adc_deinit(uint8_t pin) -{ - if (octopus.ports[pin] == PIN_AD) - { - octopus.ports[pin] = PIN_NONE; - return RSP_OK; - } - - return RSP_UNKOWN_PIN; -} - -void adc_deinit_usb(uint8_t pin) -{ - answer[0]=CMD_ADC_DEINIT_PIN; - answer[1]= (unsigned char)adc_deinit(pin); + answer[1]= (unsigned char)adc_init(pin); answer[2]=0; CommandAnswer(3); } -void adc_get_usb(uint8_t pin) +void adc_get_usb(int pin) { + uint16_t result; //uint8_t result[2]; @@ -125,59 +110,64 @@ void adc_get_usb(uint8_t pin) } -int adc_get(uint8_t pin, uint16_t *value) +int adc_get(int pin, uint16_t *value) { - *value = 0; - - if (octopus.ports[pin] == PIN_AD) - { - // 40 => 0 - // 39 => 1 - // 38 => 2 - // pin => 40-pin - *value =_adc_read_channel(17 - pin); - debugf("Wert %i\r\n",*value); - return RSP_OK; - } - else - return RSP_WRONG_PIN_CONFIG; + *value = 0; + + if (octopus.ports[pin] == PIN_AD) + { + switch (pin) + { + case 40: *value =_adc_read_channel(0); break; + case 39: *value =_adc_read_channel(1); break; + case 38: *value =_adc_read_channel(2); break; + case 37: *value =_adc_read_channel(3); break; + case 36: *value =_adc_read_channel(4); break; + case 35: *value =_adc_read_channel(5); break; + case 34: *value =_adc_read_channel(6); break; + case 33: *value =_adc_read_channel(7); break; + default: + return RSP_IMPOSSIBLE_PIN_CONFIG; + } + return RSP_OK; + } + else + { + return RSP_WRONG_PIN_CONFIG; + } } -void adc_ref_usb(uint8_t ref) +void adc_ref_usb(int ref) { answer[0]=CMD_ADC_REF; answer[1]=adc_ref(ref); - answer[2]=0; - CommandAnswer(3); + CommandAnswer(2); } -int adc_ref(uint8_t ref) +int adc_ref(int ref) { - ADMUX = 0x00; - - switch(ref) - { - case PARAM_ADC_AREF: break; - case PARAM_ADC_AVCC: ADMUX |= (1<