moved some functions

master
Dario Ernst 15 years ago
parent 3a7ac07aae
commit f103e30cd1

@ -4,7 +4,7 @@ CFLAGS += -std=gnu99 # implements C99, for <util/atomic.h>
# this removes dead code and does global linker optimization # this removes dead code and does global linker optimization
#CFLAGS += -ffunction-sections -Wl,--gc-sections -Wl,--relax #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

@ -1,7 +1,6 @@
#include <string.h> #include <string.h>
#include "display.h" #include "display.h"
char display_content[40]; // is zeroed by being in .bss char display_content[40]; // is zeroed by being in .bss
uint8_t display_currpos; 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();
}
}

@ -1,23 +1,21 @@
#include <avr/pgmspace.h> #ifndef __DISPLAY_H
#define __DISPLAY_H
#include <avr/pgmspace.h>
#include "lcd/lcd.h" #include "lcd/lcd.h"
#include "main.h"
#define LCD_CHAR_HALFBAR 0x01 #define LCD_CHAR_HALFBAR 0x01
#define LCD_CHAR_BAR 0x02 #define LCD_CHAR_BAR 0x02
#define LCD_CHAR_DEGREE 0x03 #define LCD_CHAR_DEGREE 0x03
#define LCD_CHAR_BLANK 0x20 #define LCD_CHAR_BLANK 0x20
extern const prog_uint8_t lcd_halfbar_char[]; extern const prog_uint8_t lcd_halfbar_char[];
extern const prog_uint8_t lcd_bar_char[]; extern const prog_uint8_t lcd_bar_char[];
extern const prog_uint8_t lcd_degree_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 lcd_defchar(uint8_t contr, uint8_t addr, const prog_uint8_t * chargraph);
extern void display_put_eol(); extern void display_put_eol();
extern void display_puts(const char * printstr); extern void display_puts(const char * printstr);
extern void display_puts_P(const prog_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_puthex(uint8_t outbyte);
extern void display_bar(int8_t value, int8_t min, int8_t max); extern void display_bar(int8_t value, int8_t min, int8_t max);
extern void display_putint(int16_t number); extern void display_putint(int16_t number);
void updateTemperature();
#endif

@ -11,12 +11,9 @@
#include "main.h" #include "main.h"
#include "display.h" #include "display.h"
#include "spi.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 #define SOFTTIMERNUMS 4
uint16_t softtimer_last[SOFTTIMERNUMS]; 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))) #define SOFTTIMER(n,a) if(softtimer((n),(a*4)))
void hardinit() { void hardinit() {
/* initializes the hardware */ /* initializes the hardware */
DDRB = _BV(1) | _BV(2) | _BV(0); DDRB = _BV(1) | _BV(2) | _BV(0);
@ -69,46 +63,6 @@ void softinit() {
lcd_defchar(1, LCD_CHAR_DEGREE, lcd_degree_char); 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 __attribute__((noreturn)) main(void) {
int i=0; int i=0;
@ -124,7 +78,7 @@ int __attribute__((noreturn)) main(void) {
usbPoll(); usbPoll();
SOFTTIMER(1,100){ SOFTTIMER(1,100){
updateDisplay(); updateTemperature();
} }
thermoData[0]=thermoData[0]+5; thermoData[0]=thermoData[0]+5;

@ -9,13 +9,16 @@
* *
*/ */
#ifndef __MAIN_H #ifndef __MAIN_H
#define __MAIN_H #define __MAIN_H
#include <stdint.h> #include <stdint.h>
static uint8_t newThermoData = 1;
static uint16_t thermoData[] = {1024, 814, 2475, 2243};
volatile uint16_t timer1_acc;
#define LED1PORT PORTC #define LED1PORT PORTC
#define LED1APIN 0 #define LED1APIN 0
#define LED1BPIN 1 #define LED1BPIN 1
@ -26,9 +29,4 @@
#define BACKLIGHTPORT PORTB #define BACKLIGHTPORT PORTB
#define BACKLIGHTPIN 2 #define BACKLIGHTPIN 2
#endif //__MAIN_H #endif //__MAIN_H

@ -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;
}

@ -0,0 +1,6 @@
#ifndef __USB_H
#define __USB_H
usbMsgLen_t usbFunctionSetup(uchar data[8]);
#endif
Loading…
Cancel
Save