diff --git a/firmware/Makefile b/firmware/Makefile index 4493978..bed7b54 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -4,7 +4,7 @@ CFLAGS += -std=gnu99 # implements C99, for # 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 mcp_adc.o i2c_simple.o +OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o mcp_adc.o i2c_simple.o usb.o diff --git a/firmware/display.c b/firmware/display.c index ff5d1da..ec56c27 100644 --- a/firmware/display.c +++ b/firmware/display.c @@ -1,7 +1,6 @@ #include #include "display.h" - char display_content[40]; // is zeroed by being in .bss uint8_t display_currpos; @@ -258,3 +257,20 @@ void display_bar(int8_t value, int8_t min, int8_t max) { + + +void updateTemperature() { + if(newThermoData==1) { + newThermoData = 0; + + char str[34]; + snprintf(str, 34, "%3d.%02d\x03 %3d.%02d\x03\n%3d.%02d\x03 %3d.%02d\x03", thermoData[0]/100, thermoData[0]%100, + thermoData[1]/100, thermoData[1]%100, + thermoData[2]/100, thermoData[2]%100, + thermoData[3]/100, thermoData[3]%100 + ); + display_gotoyx(0,0); + display_puts(str); + display_update(); + } +} diff --git a/firmware/display.h b/firmware/display.h index 31f0d0f..6447319 100644 --- a/firmware/display.h +++ b/firmware/display.h @@ -1,23 +1,21 @@ -#include +#ifndef __DISPLAY_H +#define __DISPLAY_H +#include #include "lcd/lcd.h" - +#include "main.h" #define LCD_CHAR_HALFBAR 0x01 #define LCD_CHAR_BAR 0x02 #define LCD_CHAR_DEGREE 0x03 #define LCD_CHAR_BLANK 0x20 - extern const prog_uint8_t lcd_halfbar_char[]; extern const prog_uint8_t lcd_bar_char[]; extern const prog_uint8_t lcd_degree_char[]; - - extern void lcd_defchar(uint8_t contr, uint8_t addr, const prog_uint8_t * chargraph); - extern void display_put_eol(); extern void display_puts(const char * printstr); extern void display_puts_P(const prog_char * printstr); @@ -34,3 +32,7 @@ extern char getdigit(int16_t *input, int16_t div, int8_t *fillzero); extern void display_puthex(uint8_t outbyte); extern void display_bar(int8_t value, int8_t min, int8_t max); extern void display_putint(int16_t number); + +void updateTemperature(); + +#endif diff --git a/firmware/main.c b/firmware/main.c index 5a3a3c5..2233bba 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -11,12 +11,9 @@ #include "main.h" #include "display.h" #include "spi.h" +#include "usb.h" -static uint8_t newThermoData = 1; -static uint16_t thermoData[] = {1024, 814, 2475, 2243}; -volatile uint16_t timer1_acc; - #define SOFTTIMERNUMS 4 uint16_t softtimer_last[SOFTTIMERNUMS]; @@ -36,9 +33,6 @@ uint8_t softtimer(uint8_t timernum, uint16_t interval){ #define SOFTTIMER(n,a) if(softtimer((n),(a*4))) - - - void hardinit() { /* initializes the hardware */ DDRB = _BV(1) | _BV(2) | _BV(0); @@ -69,46 +63,6 @@ void softinit() { lcd_defchar(1, LCD_CHAR_DEGREE, lcd_degree_char); } -usbMsgLen_t usbFunctionSetup(uchar data[8]) { - usbRequest_t *rq = (void *)data; - static uchar dataBuffer[4]; - - if(rq->bRequest == 1){ - dataBuffer[0] = (thermoData [0] & 0xff00)>>8; - dataBuffer[1] = thermoData [0] & 0x00ff; - dataBuffer[2] = (thermoData [1] & 0xff00)>>8; - dataBuffer[3] = thermoData [1] & 0x00ff; - usbMsgPtr = dataBuffer; - return 4; - } - - if(rq->bRequest == 2){ - dataBuffer[0] = (thermoData [2] & 0xff00)>>8; - dataBuffer[1] = thermoData [2] & 0x00ff; - dataBuffer[2] = (thermoData [3] & 0xff00)>>8; - dataBuffer[3] = thermoData [3] & 0x00ff; - usbMsgPtr = dataBuffer; - return 4; - } - - return 0; -} - -void updateDisplay() { - if(newThermoData==1) { - newThermoData = 0; - - char str[34]; - snprintf(str, 34, "%3d.%02d\x03 %3d.%02d\x03\n%3d.%02d\x03 %3d.%02d\x03", thermoData[0]/100, thermoData[0]%100, - thermoData[1]/100, thermoData[1]%100, - thermoData[2]/100, thermoData[2]%100, - thermoData[3]/100, thermoData[3]%100 - ); - display_gotoyx(0,0); - display_puts(str); - display_update(); - } -} int __attribute__((noreturn)) main(void) { int i=0; @@ -124,7 +78,7 @@ int __attribute__((noreturn)) main(void) { usbPoll(); SOFTTIMER(1,100){ - updateDisplay(); + updateTemperature(); } thermoData[0]=thermoData[0]+5; diff --git a/firmware/main.h b/firmware/main.h index a3f9254..800b45e 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -9,13 +9,16 @@ * */ - #ifndef __MAIN_H #define __MAIN_H - #include +static uint8_t newThermoData = 1; +static uint16_t thermoData[] = {1024, 814, 2475, 2243}; +volatile uint16_t timer1_acc; + + #define LED1PORT PORTC #define LED1APIN 0 #define LED1BPIN 1 @@ -26,9 +29,4 @@ #define BACKLIGHTPORT PORTB #define BACKLIGHTPIN 2 - - - - - #endif //__MAIN_H diff --git a/firmware/usb.c b/firmware/usb.c new file mode 100644 index 0000000..73dc7ef --- /dev/null +++ b/firmware/usb.c @@ -0,0 +1,25 @@ +usbMsgLen_t usbFunctionSetup(uchar data[8]) { + usbRequest_t *rq = (void *)data; + static uchar dataBuffer[4]; + + if(rq->bRequest == 1){ + dataBuffer[0] = (thermoData [0] & 0xff00)>>8; + dataBuffer[1] = thermoData [0] & 0x00ff; + dataBuffer[2] = (thermoData [1] & 0xff00)>>8; + dataBuffer[3] = thermoData [1] & 0x00ff; + usbMsgPtr = dataBuffer; + return 4; + } + + if(rq->bRequest == 2){ + dataBuffer[0] = (thermoData [2] & 0xff00)>>8; + dataBuffer[1] = thermoData [2] & 0x00ff; + dataBuffer[2] = (thermoData [3] & 0xff00)>>8; + dataBuffer[3] = thermoData [3] & 0x00ff; + usbMsgPtr = dataBuffer; + return 4; + } + + return 0; +} + diff --git a/firmware/usb.h b/firmware/usb.h new file mode 100644 index 0000000..494b12d --- /dev/null +++ b/firmware/usb.h @@ -0,0 +1,6 @@ +#ifndef __USB_H +#define __USB_H + +usbMsgLen_t usbFunctionSetup(uchar data[8]); + +#endif