From cbc941282074856fc6179761b70a0c9879b0b64d Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Tue, 11 Oct 2011 21:56:36 +0200 Subject: update firmware to @319 --- firmware/adc.c | 152 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 81 insertions(+), 71 deletions(-) (limited to 'firmware/adc.c') diff --git a/firmware/adc.c b/firmware/adc.c index a9449b7..915dbce 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -37,19 +37,27 @@ #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((int)buf[2]); - break; + adc_init_usb(buf[2]); + break; + case CMD_ADC_DEINIT_PIN: + adc_deinit_usb(buf[2]); + break; case CMD_ADC_GET: - adc_get_usb((int)buf[2]); - break; + adc_get_usb(buf[2]); + break; case CMD_ADC_REF: - adc_ref_usb((int)buf[2]); - break; + adc_ref_usb(buf[2]); + break; default: answer[0]=buf[0]; @@ -59,42 +67,49 @@ void adc_parser(char *buf) } } -int adc_init(int pin) +int adc_init(uint8_t pin) { - if (pin >= 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; + if (pin >= 10 && pin <= 17) + { + octopus.ports[pin] = PIN_AD; + ADMUX |= (1< 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; } -void adc_ref_usb(int ref) +void adc_ref_usb(uint8_t ref) { answer[0]=CMD_ADC_REF; answer[1]=adc_ref(ref); - CommandAnswer(2); + answer[2]=0; + CommandAnswer(3); } -int adc_ref(int ref) +int adc_ref(uint8_t ref) { - ADMUX = 0x00; - - switch(ref){ - case PARAM_ADC_AREF: break; - case PARAM_ADC_AVCC: ADMUX |= (1<