small fixes in mcp_adc

master
Paul Goeser 15 years ago
parent ef156679a1
commit cd36ba7fc3

@ -1,7 +1,10 @@
DEFINES += -DF_CPU=16000000 DEFINES += -DF_CPU=16000000
CFLAGS += -save-temps CFLAGS += -save-temps
CFLAGS += -std=gnu99 # implements C99, for <util/atomic.h>
# this removes dead code and does global linker optimization
#CFLAGS += -ffunction-sections -Wl,--gc-sections -Wl,--relax
OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o mcp_adc.o

@ -2,8 +2,6 @@
CFLAGS += -Wall -Os -I. -mmcu=atmega88 CFLAGS += -Wall -Os -I. -mmcu=atmega88
# further optimization: # further optimization:
# this removes dead code and does global linker optimization
CFLAGS += -ffunction-sections -Wl,--gc-sections -Wl,--relax
#CFLAGS += --param inline-call-cost=2 #CFLAGS += --param inline-call-cost=2
CFLAGS += -fno-move-loop-invariants # suggestions from from v-usb CFLAGS += -fno-move-loop-invariants # suggestions from from v-usb
CFLAGS += -fno-tree-scev-cprop CFLAGS += -fno-tree-scev-cprop

@ -1,4 +1,4 @@
#include <sys/types.h> #include <stdint.h>
/* analog digital converter /* analog digital converter
* scratchpad * scratchpad
@ -23,20 +23,20 @@
void mcpadc_init(uint8_t mode) void mcpadc_init(uint8_t mode)
{ {
i2c_write(ADC_ADDR, 1, &mode)) i2c_write(ADC_ADDR, 1, &mode);
} }
uint8_t mcpadc_has_new_data() uint8_t mcpadc_has_new_data()
{ {
uint8_t r[4]; uint8_t r[4];
i2c_read(ADC_ADDR, 4, r)/* 4 bytes are only needed in 18 bit mode */ i2c_read(ADC_ADDR, 4, r);/* 4 bytes are only needed in 18 bit mode */
return r[3] & ADC_NEW_SAMPLE; return(r[3] & ADC_NEW_SAMPLE);
} }
#if ADC_ENABLE_18_BIT_MODE #if ADC_ENABLE_18_BIT_MODE
int32_t mcpadc_get_data() int32_t mcpadc_get_data()
{ {
uint8_t r[4] = 0; uint8_t r[4] = {0,0,0,0};
int32_t value = 0; int32_t value = 0;
i2c_read(ADC_ADDR, 4, r);/* reading 4 bytes guarantees us one config byte */ i2c_read(ADC_ADDR, 4, r);/* reading 4 bytes guarantees us one config byte */
if(r[0] & 0x80) {value = 0xffff;} if(r[0] & 0x80) {value = 0xffff;}
@ -50,7 +50,7 @@ int32_t mcpadc_get_data()
#else #else
int16_t mcpadc_get_data() int16_t mcpadc_get_data()
{ {
uint8_t r[2] = 0; uint8_t r[2] = {0,0};
i2c_read(ADC_ADDR, 2, r);/* this will NOT work in 18 bit mode */ i2c_read(ADC_ADDR, 2, r);/* this will NOT work in 18 bit mode */
int16_t value = (r[0] << 8) | r[1];/*endianess ???*/ int16_t value = (r[0] << 8) | r[1];/*endianess ???*/
return r; return r;

Loading…
Cancel
Save