From aa901656d77a6e8aec33f21d475fae1c202c6897 Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Mon, 5 Jan 2015 01:04:27 +0100 Subject: [PATCH] added simple graphing function --- atmega32u4/cooler/Makefile | 21 +- atmega32u4/cooler/cooler.c | 221 +++++++++++++++++- .../cooler/lcdlib}/.gitattributes | 0 .../cooler/lcdlib}/.gitignore | 0 .../cooler/lcdlib}/Fonts/digits_24px.c | 0 .../cooler/lcdlib}/Fonts/digits_24px.font | Bin .../cooler/lcdlib}/Fonts/digits_32px.c | 0 .../cooler/lcdlib}/Fonts/digits_32px.font | Bin .../cooler/lcdlib}/Fonts/font_fixed_16bit.c | 0 .../lcdlib}/Fonts/font_fixed_16bit.font | Bin .../cooler/lcdlib}/Fonts/font_fixed_8px.c | 0 .../lcdlib}/Fonts/font_proportional_16px.c | 0 .../lcdlib}/Fonts/font_proportional_16px.font | Bin .../lcdlib}/Fonts/font_proportional_8px.c | 0 .../lcdlib}/Fonts/font_proportional_8px.font | Bin .../cooler/lcdlib}/Fonts/symbols_16px.c | 0 .../cooler/lcdlib}/Fonts/symbols_16px.font | Bin .../cooler/lcdlib}/Fonts/symbols_8px.c | 0 .../cooler/lcdlib}/Fonts/symbols_8px.font | Bin .../lcdlib}/Fonts/template_simplefont.c | 0 {lcdlib => atmega32u4/cooler/lcdlib}/LICENSE | 0 .../cooler/lcdlib}/README.md | 0 .../cooler/lcdlib}/dogm-graphic.c | 0 .../cooler/lcdlib}/dogm-graphic.h | 0 {lcdlib => atmega32u4/cooler/lcdlib}/font.c | 21 +- {lcdlib => atmega32u4/cooler/lcdlib}/font.h | 24 +- .../cooler/lcdlib}/lcd-color-graphic.c | 122 +++++++--- .../cooler/lcdlib}/lcd-color-graphic.h | 40 ++-- atmega32u4/cooler/test.pl | 11 + atmega32u4/cooler/usb/usb_serial.c | 4 +- 30 files changed, 374 insertions(+), 90 deletions(-) rename {lcdlib => atmega32u4/cooler/lcdlib}/.gitattributes (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/.gitignore (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/digits_24px.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/digits_24px.font (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/digits_32px.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/digits_32px.font (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/font_fixed_16bit.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/font_fixed_16bit.font (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/font_fixed_8px.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/font_proportional_16px.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/font_proportional_16px.font (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/font_proportional_8px.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/font_proportional_8px.font (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/symbols_16px.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/symbols_16px.font (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/symbols_8px.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/symbols_8px.font (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/Fonts/template_simplefont.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/LICENSE (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/README.md (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/dogm-graphic.c (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/dogm-graphic.h (100%) rename {lcdlib => atmega32u4/cooler/lcdlib}/font.c (96%) rename {lcdlib => atmega32u4/cooler/lcdlib}/font.h (90%) rename {lcdlib => atmega32u4/cooler/lcdlib}/lcd-color-graphic.c (72%) rename {lcdlib => atmega32u4/cooler/lcdlib}/lcd-color-graphic.h (86%) create mode 100644 atmega32u4/cooler/test.pl diff --git a/atmega32u4/cooler/Makefile b/atmega32u4/cooler/Makefile index 6384206..0d19434 100644 --- a/atmega32u4/cooler/Makefile +++ b/atmega32u4/cooler/Makefile @@ -8,10 +8,10 @@ MCU = atmega32u4 FORMAT = ihex TARGET = cooler -SRC = $(TARGET).c usb/usb_serial.c ../../lcdlib/lcd-color-graphic.c ../../lcdlib/font.c \ - ../../lcdlib/Fonts/digits_24px.c ../../lcdlib/Fonts/digits_32px.c ../../lcdlib/Fonts/font_proportional_16px.c ../../lcdlib/Fonts/symbols_16px.c ../../lcdlib/Fonts/font_proportional_8px.c +SRC = $(TARGET).c usb/usb_serial.c lcdlib/lcd-color-graphic.c lcdlib/font.c \ + lcdlib/Fonts/digits_24px.c lcdlib/Fonts/digits_32px.c lcdlib/Fonts/font_proportional_16px.c lcdlib/Fonts/font_proportional_8px.c lcdlib/Fonts/symbols_16px.c ASRC = -OPT = s +OPT = 2 # Name of this Makefile (used for "make depend"). MAKEFILE = Makefile @@ -36,10 +36,10 @@ CINCS = CDEBUG = -g$(DEBUG) -CWARN = -Wall -Wstrict-prototypes -CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wl,--relax #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) -CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CTUNING) #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs @@ -83,7 +83,7 @@ LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) # Programming support using avrdude. Settings and variables. -AVRDUDE_PROGRAMMER = dragon_isp +AVRDUDE_PROGRAMMER = dragon_jtag AVRDUDE_PORT = usb AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex @@ -97,7 +97,7 @@ AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex # Uncomment the following if you do /not/ wish a verification to be # performed after programming the device. -#AVRDUDE_NO_VERIFY = -V +AVRDUDE_NO_VERIFY = -V # Increase verbosity level. Please use this when submitting bug # reports about avrdude. See @@ -130,7 +130,7 @@ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) # Default target. -all: build +all: build size build: elf hex eep @@ -146,7 +146,8 @@ program: $(TARGET).hex $(TARGET).eep $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) - +size: + $(SIZE) -C --mcu=$(MCU) $(TARGET).elf # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. COFFCONVERT=$(OBJCOPY) --debugging \ diff --git a/atmega32u4/cooler/cooler.c b/atmega32u4/cooler/cooler.c index 8a226a2..2a8bb79 100644 --- a/atmega32u4/cooler/cooler.c +++ b/atmega32u4/cooler/cooler.c @@ -1,18 +1,233 @@ -#define F_CPU 8000000UL +// #define F_CPU 8000000UL #include #include #include +#include #include "usb/usb_serial.h" +#include "lcdlib/lcd-color-graphic.h" +#include "lcdlib/font.h" +#define YELLOW_ON() PORTB &= ~0x1 +#define YELLOW_OFF() PORTB |= 0x1 +#define GREEN_ON() PORTD &= ~(1<>= 4; + y = 190-y; + lcd_set_pixel_col_xy(c+1,y,background); + lcd_set_pixel_col_xy(c,y,foreground); + p++; + if(p>= STORAGESIZE) p = 0; + }while(++c= '0' && c<='9') return c-'0'; + if(c >= 'a' && c<='f') return c-'a'+10; + if(c >= 'A' && c<='F') return c-'A'+10; + return -1; + } + +void showTemp(uint8_t place, int16_t val) { + uint8_t neg = 0; + int16_t t = val; + uint8_t x,y; + if(val<0) { + neg = 1; + t = val * -1; + } + + y = t & 0xF; + x = t >> 4; + + lcd_set_font(FONT_DIGITS_32,SPACING); + TOP_BACKGROUND(); + + if(place == 0) { + FIRST_VALUE_FOREGROUND(); + if(lastvalues[place]<=-160) { + if(val >-160) + lcd_set_area_xy(190,210,23,28); + } + else if (lastvalues[place]<0) { + if(val>0) + lcd_set_area_xy(220,240,23,28); + } + + if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=160)) + lcd_set_area_xy(210,246,8,39); + + FIRST_VALUE_BACKGROUND(); + if(neg) { + if(x>=10 && lastvalues[place]>-160) + lcd_set_area_xy(190,210,23,28); + else if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=0)) + lcd_set_area_xy(220,240,23,28); + } + if(x>=10) lcd_moveto_xy(8,220); + else lcd_moveto_xy(8,249); + } + else { + SECOND_VALUE_FOREGROUND(); + lcd_set_area_xy(190,210,63,68); + lcd_set_area_xy(210,246,48,79); + + SECOND_VALUE_BACKGROUND(); + if(neg) { + if(x>=10) lcd_set_area_xy(190,210,63,68); + else lcd_set_area_xy(220,240,63,68); + } + if(x>=10) lcd_moveto_xy(48,220); + else lcd_moveto_xy(48,249); + } + + TOP_BACKGROUND(); + lcd_put_int(x); + if(!place)lcd_moveto_xy(8,289); + else lcd_moveto_xy(48,289); + lcd_putc(lut[y]+'0'); + + lastvalues[place] = val; + } + + + +void pushvalue(uint8_t i, int16_t v) { + if(valuepointer[i] == STORAGESIZE-1) valuepointer[i] = 0; + else valuepointer[i]++; + values[i][valuepointer[i]] = v; + showTemp(i,v); + draw(); + } + +void printAxes(void) { + AXES_COLOR(); + BOTTOM_BACKGROUND(); + lcd_set_area_xy(20,319,100,220); + TOP_BACKGROUND(); + lcd_set_font(FONT_PROP_16,NORMAL); + lcd_putstr_xy_P(PSTR("-10"),216,0); + lcd_putstr_xy_P(PSTR(" 30"),96,0); + lcd_putstr_xy_P(PSTR("-5"),224,20); + lcd_putstr_xy_P(PSTR("0"),224,300); + lcd_draw_line(MINX,MINX,MINY-1,MAXY+1); + lcd_draw_line(MINX,MAXX,MINY-1,MINY-1); + lcd_draw_line(MINX,MAXX,MAXY+1,MAXY+1); + lcd_draw_line(MAXX+1,MAXX+1,MINY-1,MAXY+1); + lcd_set_font(FONT_PROP_8,NORMAL); + lcd_putstr_xy_P(PSTR("minutes"),228,150); + lcd_putstr_xy_P(PSTR("T"),160,10); + + FIRST_VALUE_FOREGROUND(); + lcd_set_font(FONT_PROP_16,NORMAL); + lcd_putstr_xy_P(PSTR("is"),8,190); + lcd_set_font(FONT_DIGITS_32,SPACING); + lcd_moveto_xy(8,278); + lcd_putc('.'); + SECOND_VALUE_FOREGROUND(); + lcd_set_font(FONT_PROP_16,NORMAL); + lcd_putstr_xy_P(PSTR("set"),48,190); + lcd_set_font(FONT_DIGITS_32,SPACING); + lcd_moveto_xy(48,278); + lcd_putc('.'); + + } + + + __attribute__((naked)) int main(void) { -// lcd_init(); + init(); usb_init(); + lcd_init(); + + lcd_command_1(LCD_MIRROR, LCD_BGR | LCD_FLIP_XY); + lcd_command(LCD_ON); + + TOP_BACKGROUND(); + lcd_set_area_xy(0, 0x13F, 0, 0xEF); + + lcd_set_foreground(0x1f,0x3f,0x1f); + lcd_set_font(FONT_PROP_16,DOUBLE_HEIGHT|SPACING); + lcd_putstr_xy_P(PSTR("Cooling Control"),26,30); + + + + pushvalue(0,(17*16+5)); + pushvalue(1,-(8*16+3)); + printAxes(); + + + while (1) { + int n = usb_serial_getchar(); + if (n >= 0) { + buffer[recvpointer++] = n; + if(recvpointer>BUFFERSIZE) { + recvpointer = 0; + } - while (1) { + if(n == 10 && recvpointer >= 8 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'T') { //SETnsvvv + uint16_t t = hex2int(buffer[5])*256 + hex2int(buffer[6])*16 + hex2int(buffer[7]); + if (buffer[4] == '-') t = t*-1; + pushvalue(hex2int(buffer[3]),t); + } + if(n==10) { + usb_serial_write(buffer,recvpointer); + recvpointer = 0; + } + } } } \ No newline at end of file diff --git a/lcdlib/.gitattributes b/atmega32u4/cooler/lcdlib/.gitattributes similarity index 100% rename from lcdlib/.gitattributes rename to atmega32u4/cooler/lcdlib/.gitattributes diff --git a/lcdlib/.gitignore b/atmega32u4/cooler/lcdlib/.gitignore similarity index 100% rename from lcdlib/.gitignore rename to atmega32u4/cooler/lcdlib/.gitignore diff --git a/lcdlib/Fonts/digits_24px.c b/atmega32u4/cooler/lcdlib/Fonts/digits_24px.c similarity index 100% rename from lcdlib/Fonts/digits_24px.c rename to atmega32u4/cooler/lcdlib/Fonts/digits_24px.c diff --git a/lcdlib/Fonts/digits_24px.font b/atmega32u4/cooler/lcdlib/Fonts/digits_24px.font similarity index 100% rename from lcdlib/Fonts/digits_24px.font rename to atmega32u4/cooler/lcdlib/Fonts/digits_24px.font diff --git a/lcdlib/Fonts/digits_32px.c b/atmega32u4/cooler/lcdlib/Fonts/digits_32px.c similarity index 100% rename from lcdlib/Fonts/digits_32px.c rename to atmega32u4/cooler/lcdlib/Fonts/digits_32px.c diff --git a/lcdlib/Fonts/digits_32px.font b/atmega32u4/cooler/lcdlib/Fonts/digits_32px.font similarity index 100% rename from lcdlib/Fonts/digits_32px.font rename to atmega32u4/cooler/lcdlib/Fonts/digits_32px.font diff --git a/lcdlib/Fonts/font_fixed_16bit.c b/atmega32u4/cooler/lcdlib/Fonts/font_fixed_16bit.c similarity index 100% rename from lcdlib/Fonts/font_fixed_16bit.c rename to atmega32u4/cooler/lcdlib/Fonts/font_fixed_16bit.c diff --git a/lcdlib/Fonts/font_fixed_16bit.font b/atmega32u4/cooler/lcdlib/Fonts/font_fixed_16bit.font similarity index 100% rename from lcdlib/Fonts/font_fixed_16bit.font rename to atmega32u4/cooler/lcdlib/Fonts/font_fixed_16bit.font diff --git a/lcdlib/Fonts/font_fixed_8px.c b/atmega32u4/cooler/lcdlib/Fonts/font_fixed_8px.c similarity index 100% rename from lcdlib/Fonts/font_fixed_8px.c rename to atmega32u4/cooler/lcdlib/Fonts/font_fixed_8px.c diff --git a/lcdlib/Fonts/font_proportional_16px.c b/atmega32u4/cooler/lcdlib/Fonts/font_proportional_16px.c similarity index 100% rename from lcdlib/Fonts/font_proportional_16px.c rename to atmega32u4/cooler/lcdlib/Fonts/font_proportional_16px.c diff --git a/lcdlib/Fonts/font_proportional_16px.font b/atmega32u4/cooler/lcdlib/Fonts/font_proportional_16px.font similarity index 100% rename from lcdlib/Fonts/font_proportional_16px.font rename to atmega32u4/cooler/lcdlib/Fonts/font_proportional_16px.font diff --git a/lcdlib/Fonts/font_proportional_8px.c b/atmega32u4/cooler/lcdlib/Fonts/font_proportional_8px.c similarity index 100% rename from lcdlib/Fonts/font_proportional_8px.c rename to atmega32u4/cooler/lcdlib/Fonts/font_proportional_8px.c diff --git a/lcdlib/Fonts/font_proportional_8px.font b/atmega32u4/cooler/lcdlib/Fonts/font_proportional_8px.font similarity index 100% rename from lcdlib/Fonts/font_proportional_8px.font rename to atmega32u4/cooler/lcdlib/Fonts/font_proportional_8px.font diff --git a/lcdlib/Fonts/symbols_16px.c b/atmega32u4/cooler/lcdlib/Fonts/symbols_16px.c similarity index 100% rename from lcdlib/Fonts/symbols_16px.c rename to atmega32u4/cooler/lcdlib/Fonts/symbols_16px.c diff --git a/lcdlib/Fonts/symbols_16px.font b/atmega32u4/cooler/lcdlib/Fonts/symbols_16px.font similarity index 100% rename from lcdlib/Fonts/symbols_16px.font rename to atmega32u4/cooler/lcdlib/Fonts/symbols_16px.font diff --git a/lcdlib/Fonts/symbols_8px.c b/atmega32u4/cooler/lcdlib/Fonts/symbols_8px.c similarity index 100% rename from lcdlib/Fonts/symbols_8px.c rename to atmega32u4/cooler/lcdlib/Fonts/symbols_8px.c diff --git a/lcdlib/Fonts/symbols_8px.font b/atmega32u4/cooler/lcdlib/Fonts/symbols_8px.font similarity index 100% rename from lcdlib/Fonts/symbols_8px.font rename to atmega32u4/cooler/lcdlib/Fonts/symbols_8px.font diff --git a/lcdlib/Fonts/template_simplefont.c b/atmega32u4/cooler/lcdlib/Fonts/template_simplefont.c similarity index 100% rename from lcdlib/Fonts/template_simplefont.c rename to atmega32u4/cooler/lcdlib/Fonts/template_simplefont.c diff --git a/lcdlib/LICENSE b/atmega32u4/cooler/lcdlib/LICENSE similarity index 100% rename from lcdlib/LICENSE rename to atmega32u4/cooler/lcdlib/LICENSE diff --git a/lcdlib/README.md b/atmega32u4/cooler/lcdlib/README.md similarity index 100% rename from lcdlib/README.md rename to atmega32u4/cooler/lcdlib/README.md diff --git a/lcdlib/dogm-graphic.c b/atmega32u4/cooler/lcdlib/dogm-graphic.c similarity index 100% rename from lcdlib/dogm-graphic.c rename to atmega32u4/cooler/lcdlib/dogm-graphic.c diff --git a/lcdlib/dogm-graphic.h b/atmega32u4/cooler/lcdlib/dogm-graphic.h similarity index 100% rename from lcdlib/dogm-graphic.h rename to atmega32u4/cooler/lcdlib/dogm-graphic.h diff --git a/lcdlib/font.c b/atmega32u4/cooler/lcdlib/font.c similarity index 96% rename from lcdlib/font.c rename to atmega32u4/cooler/lcdlib/font.c index 6500674..78f6f72 100644 --- a/lcdlib/font.c +++ b/atmega32u4/cooler/lcdlib/font.c @@ -207,18 +207,20 @@ uint8_t lcd_put_char(FONT_P font, uint8_t style, char character) { } //write character + uint8_t cont = 0; do { for(i=(row>>hc); i>1; } - for(uint8_t x = free_space; x>0;x--) { - LCD_WRITE(c); + for(uint8_t x = free_space<0;x--) { + LCD_WRITE(c,cont); } } LCD_MOVE(1,-char_final_width); + cont = 0; } while (++row < char_final_height); //move cursor to upper right corner of character @@ -283,7 +286,7 @@ uint16_t lcd_put_string_length(FONT_P font, uint8_t style, char* str, uint8_t le * the string from program memory. The position of the string on the display * is selected by page / col. */ -uint16_t lcd_put_string_xy_P(FONT_P font, uint8_t style, PGM_P str,uint8_t page, uint8_t col) { +uint16_t lcd_put_string_xy_P(FONT_P font, uint8_t style, PGM_P str,uint16_t page, uint16_t col) { LCD_MOVE_TO(page,col); return lcd_put_string_P(font,style,str); } @@ -294,7 +297,7 @@ uint16_t lcd_put_string_xy_P(FONT_P font, uint8_t style, PGM_P str,uint8_t page, * the string from main memory. The position of the string on the display * is selected by page / col. */ -uint8_t lcd_put_char_xy(FONT_P font, uint8_t style, char character, uint8_t page, uint8_t col) { +uint8_t lcd_put_char_xy(FONT_P font, uint8_t style, char character, uint16_t page, uint16_t col) { LCD_MOVE_TO(page,col); return lcd_put_char(font,style,character); } @@ -310,7 +313,7 @@ uint8_t lcd_putc(char c) { /****************************************************************************** * Outputs a character on the display, using the global font and style */ -uint8_t lcd_putc_xy(char c, uint8_t page, uint8_t col) { +uint8_t lcd_putc_xy(char c, uint16_t page, uint16_t col) { return lcd_put_char_xy(global_font_select, global_font_style, c, page, col); } @@ -337,7 +340,7 @@ uint16_t lcd_putstr_P(PGM_P str) { * Outputs a string on the display, using the global font and style at the * given position */ -uint16_t lcd_putstr_xy_P(PGM_P str, uint8_t page, uint8_t col) { +uint16_t lcd_putstr_xy_P(PGM_P str, uint16_t page, uint16_t col) { return lcd_put_string_xy_P(global_font_select, global_font_style, str, page, col); } diff --git a/lcdlib/font.h b/atmega32u4/cooler/lcdlib/font.h similarity index 90% rename from lcdlib/font.h rename to atmega32u4/cooler/lcdlib/font.h index 4f9d89d..79afbe7 100644 --- a/lcdlib/font.h +++ b/atmega32u4/cooler/lcdlib/font.h @@ -8,7 +8,7 @@ #include //Include your LCD graphics library here -#include "dogm-graphic.h" +#include "lcd-color-graphic.h" //declare font info structure defined below struct font_info; typedef const struct font_info * FONT_P; @@ -23,15 +23,15 @@ typedef const struct font_info * FONT_P; #define FONTS_INCLUDE_font_proportional_16px font_proportional_16px #define FONTS_INCLUDE_font_proportional_8px font_proportional_8px -#define FONTS_INCLUDE_font_fixed_8px font_fixed_8px -#define FONTS_INCLUDE_font_fixed_16px font_fixed_16px -#define FONTS_INCLUDE_symbols_8px symbols_8px -#define FONTS_INCLUDE_symbols_16px symbols_16px -#define FONTS_INCLUDE_digits_24px digits_24px +//#define FONTS_INCLUDE_font_fixed_8px font_fixed_8px +// #define FONTS_INCLUDE_font_fixed_16px font_fixed_16px +// #define FONTS_INCLUDE_symbols_8px symbols_8px +// #define FONTS_INCLUDE_symbols_16px symbols_16px +// #define FONTS_INCLUDE_digits_24px digits_24px #define FONTS_INCLUDE_digits_32px digits_32px //Set to 1 to include functions for direct output of integer & float values -#define INCLUDE_FLOAT_OUTPUT 0 +// #define INCLUDE_FLOAT_OUTPUT 1 #define INCLUDE_INTEGER_OUTPUT 1 @@ -83,7 +83,7 @@ typedef const struct font_info * FONT_P; #define LCD_MOVE(x,y) lcd_move_xy((x),(y)) //relative cursor movement #define LCD_MOVE_TO(x,y) lcd_moveto_xy((x),(y)) //absolute cursor movement -#define LCD_WRITE(x) lcd_data((x)) //write data to display +#define LCD_WRITE(x,c) lcd_write_font_byte(x,c) //lcd_data((x)) //write data to display //Functions to read the current position as provided by the LCD library #define LCD_CURRENT_COL() lcd_get_position_column() @@ -122,15 +122,15 @@ uint16_t lcd_put_string (FONT_P font, uint8_t style, char* str); uint16_t lcd_put_string_length(FONT_P font, uint8_t style, char* str, uint8_t length); uint16_t lcd_put_string_P (FONT_P font, uint8_t style, PGM_P str); uint8_t lcd_put_char (FONT_P font, uint8_t style, char c); -uint16_t lcd_put_string_xy_P (FONT_P font, uint8_t style, PGM_P str, uint8_t page, uint8_t col); -uint8_t lcd_put_char_xy (FONT_P font, uint8_t style, char character, uint8_t page, uint8_t col); +uint16_t lcd_put_string_xy_P (FONT_P font, uint8_t style, PGM_P str, uint16_t page, uint16_t col); +uint8_t lcd_put_char_xy (FONT_P font, uint8_t style, char character, uint16_t page, uint16_t col); void lcd_set_font (FONT_P font, uint8_t style); uint8_t lcd_putc (char c); -uint8_t lcd_putc_xy (char c, uint8_t page, uint8_t col); +uint8_t lcd_putc_xy (char c, uint16_t page, uint16_t col); uint16_t lcd_putstr (char* str); uint16_t lcd_putstr_P (PGM_P str); -uint16_t lcd_putstr_xy_P (PGM_P str, uint8_t page, uint8_t col); +uint16_t lcd_putstr_xy_P (PGM_P str, uint16_t page, uint16_t col); #if INCLUDE_INTEGER_OUTPUT == 1 uint16_t lcd_put_long (int32_t integer); diff --git a/lcdlib/lcd-color-graphic.c b/atmega32u4/cooler/lcdlib/lcd-color-graphic.c similarity index 72% rename from lcdlib/lcd-color-graphic.c rename to atmega32u4/cooler/lcdlib/lcd-color-graphic.c index 8403f96..c4be9fa 100644 --- a/lcdlib/lcd-color-graphic.c +++ b/atmega32u4/cooler/lcdlib/lcd-color-graphic.c @@ -14,8 +14,8 @@ * Background is used as background, e.g. when writing fonts. */ -color_t foreground = {.red=0x1F, .green=0x3F, .blue=0x1F}; -color_t background = {.red=0, .green=0, .blue=0}; +color_t foreground; +color_t background; /****************************************************************************** @@ -25,6 +25,7 @@ void lcd_init() { LCD_SET_PIN_DIRECTIONS(); //set outputs _delay_ms(1); LCD_INIT_SPI(); //Initialize SPI Interface + LCD_UNSELECT(); _delay_ms(50); LCD_RESET_ON(); //Apply Reset to the Display Controller _delay_ms(100); @@ -33,6 +34,7 @@ void lcd_init() { LCD_SELECT(); //Switches chip select on lcd_command(LCD_SLEEP_OUT); //Wake up LCD _delay_ms(70); + lcd_command_1(LCD_COLOR_MODE,LCD_16BIT); return; } @@ -40,11 +42,22 @@ void lcd_init() { /****************************************************************************** * Sends a command to the display */ -inline void lcd_command(uint8_t c) { - spi_wait_for_idle(); - LCD_CMD(); - spi_write(c); - } +// inline void lcd_command(uint8_t c) { +// spi_wait_for_idle(); +// LCD_CMD(); +// spi_write(c); +// } + + +/****************************************************************************** + * Sends a data word to the display + */ +// inline void lcd_data(uint8_t c) { +// spi_wait_for_idle(); +// LCD_DATA(); +// spi_write(c); +// } + /****************************************************************************** * Sends a command with one argument @@ -53,25 +66,14 @@ inline void lcd_command_1(uint8_t c, uint8_t data) { lcd_command(c); lcd_data(data); } - -/****************************************************************************** - * Sends a data word to the display - */ -inline void lcd_data(uint8_t c) { - spi_wait_for_idle(); - LCD_DATA(); - spi_write(c); -} - - /****************************************************************************** * Stores the main drawing color for later use */ inline void lcd_set_foreground(uint8_t r, uint8_t g, uint8_t b) { - foreground.red = r; - foreground.green = g; - foreground.blue = b; + uint16_t t = r<<11 | g<<5 | b; + foreground.c1 = t>>8; + foreground.c2 = t; } @@ -79,9 +81,9 @@ inline void lcd_set_foreground(uint8_t r, uint8_t g, uint8_t b) { * Stores the background color for later use */ inline void lcd_set_background(uint8_t r, uint8_t g, uint8_t b) { - background.red = r; - background.green = g; - background.blue = b; + uint16_t t = r<<11 | g<<5 | b; + background.c1 = t>>8; + background.c2 = t; } @@ -91,28 +93,38 @@ inline void lcd_set_background(uint8_t r, uint8_t g, uint8_t b) { inline void lcd_set_column(uint16_t start, uint16_t end) { lcd_command(LCD_SET_COLUMN); lcd_data(start >> 8); - lcd_data(start); - lcd_data(end >> 8); - lcd_data(end); + lcd_data_cont(start); + lcd_data_cont(end >> 8); + lcd_data_cont(end); } - +inline void lcd_set_column_short(uint16_t start) { + lcd_command(LCD_SET_COLUMN); + lcd_data(start >> 8); + lcd_data_cont(start); + } + /****************************************************************************** * Sets the page range used for the next write operation */ inline void lcd_set_page(uint16_t start, uint16_t end) { lcd_command(LCD_SET_PAGE); lcd_data(start >> 8); - lcd_data(start); - lcd_data(end >> 8); - lcd_data(end); + lcd_data_cont(start); + lcd_data_cont(end >> 8); + lcd_data_cont(end); + } +inline void lcd_set_page_short(uint16_t start) { + lcd_command(LCD_SET_PAGE); + lcd_data(start >> 8); + lcd_data_cont(start); } /****************************************************************************** * Writes a pixel to the display using 16 Bit color mode */ inline void lcd_send_pixel(color_t c) { - lcd_data((c.red<<3) | (c.green>>3)); - lcd_data((c.green<<5) | c.blue); + lcd_data(c.c1); + lcd_data_cont(c.c2); } /****************************************************************************** @@ -125,7 +137,16 @@ inline void lcd_set_pixel_xy(uint16_t column, uint16_t page) { lcd_send_pixel(foreground); } - +/****************************************************************************** + * Sets a pixel at a given position + */ +inline void lcd_set_pixel_col_xy(uint16_t column, uint16_t page, color_t col) { + lcd_set_page_short(page); + lcd_set_column_short(column); + lcd_command(LCD_WRITE_MEM); + lcd_send_pixel(col); + } + /****************************************************************************** * This function sets an area of the screen to a given color * col0 - left edge of the area @@ -162,7 +183,7 @@ uint16_t lcd_current_column = 0; uint16_t lcd_inc_page(int16_t s) { uint16_t p = lcd_current_page; p += s; - if (p > LCD_HEIGHT/8) + if (p > LCD_HEIGHT) p = 0; lcd_current_page = p; @@ -197,18 +218,22 @@ void lcd_moveto_xy(uint16_t page, uint16_t column) { * Moves the cursor relative to the current position * pages - number of pages to move * columns - number of columns to move + * for use with the font library only */ void lcd_move_xy(int16_t pages, int16_t columns) { - lcd_moveto_xy(lcd_inc_page(pages),lcd_inc_column(columns)); + lcd_moveto_xy(lcd_inc_page(pages*8),lcd_inc_column(columns)); } /****************************************************************************** * Takes a vertical byte from the font generator and prints it on the display * b - Bit pattern to display + * c - continue writing in same page */ -void lcd_write_font_byte(uint8_t b) { - lcd_set_page(8*lcd_current_page,8*lcd_current_page+8); +void lcd_write_font_byte(uint8_t b, uint8_t c) { + if(!c) { + lcd_set_page(lcd_current_page,lcd_current_page+8); + } lcd_set_column(lcd_current_column,lcd_current_column); lcd_command(LCD_WRITE_MEM); for(uint8_t i=0;i<8;i++) { @@ -220,4 +245,25 @@ void lcd_write_font_byte(uint8_t b) { } lcd_inc_column(1); } + + +/****************************************************************************** + * Draws a line according to Bresenham (from wikipedia) + */ +void lcd_draw_line(uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1) { + int16_t dx = abs(x1-x0); + int16_t sx = x0 dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */ + if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */ + } + } + \ No newline at end of file diff --git a/lcdlib/lcd-color-graphic.h b/atmega32u4/cooler/lcdlib/lcd-color-graphic.h similarity index 86% rename from lcdlib/lcd-color-graphic.h rename to atmega32u4/cooler/lcdlib/lcd-color-graphic.h index 41cd6ce..351cf08 100644 --- a/lcdlib/lcd-color-graphic.h +++ b/atmega32u4/cooler/lcdlib/lcd-color-graphic.h @@ -6,13 +6,13 @@ #include #include #include - +#include /***************************************************************************** * BEGIN CONFIG BLOCK *****************************************************************************/ -#define LCD_WIDTH 240 -#define LCD_HEIGHT 320 +#define LCD_WIDTH 320 +#define LCD_HEIGHT 240 //Should chip select (CS) be used? #define LCD_USE_CHIPSELECT 1 @@ -20,18 +20,18 @@ //CD Port #define PORT_DC PORTB #define DDR_DC DDRB -#define PIN_DC 0 +#define PIN_DC 6 //Reset Port -#define PORT_RST PORTA -#define DDR_RST DDRA +#define PORT_RST PORTB +#define DDR_RST DDRB #define PIN_RST 4 //Chip select #if LCD_USE_CHIPSELECT == 1 #define PORT_CS PORTB #define DDR_CS DDRB - #define PIN_CS 1 + #define PIN_CS 5 #endif //SPI routines @@ -40,10 +40,10 @@ extern void init_spi_lcd(void); #define LCD_INIT_SPI() init_spi_lcd() //Define a function that waits until SPI interface is idle -#define spi_wait_for_idle() while(! (SPSR0 & _BV(SPIF0))); +#define spi_wait_for_idle() asm volatile ("nop");while(! (SPSR & _BV(SPIF))); //Define how to write to SPI data register -#define spi_write(i) SPDR0 = i +#define spi_write(i) SPDR = i /*Example SPI setup (Atmega162) *init spi: msb first, update on falling edge , read on rising edge, 9 MHz @@ -61,12 +61,18 @@ extern void init_spi_lcd(void); //Color struct - no bit fields are used for better performance (i.e. bit shifts //can be done while waiting for SPI, not while preparing to write the pixel) typedef struct { - uint8_t red; - uint8_t green; - uint8_t blue; + uint8_t c1; + uint8_t c2; } color_t; +#define lcd_data(c) spi_wait_for_idle();LCD_DATA();spi_write(c) +#define lcd_data_cont(c) spi_wait_for_idle();spi_write(c) +#define lcd_command(c) spi_wait_for_idle();LCD_CMD();spi_write(c) + + color_t foreground; + color_t background; + /***************************************************************************** * Public Functions *****************************************************************************/ @@ -74,8 +80,8 @@ typedef struct { void lcd_init(void); //write data word or command to the LCD - void lcd_data (uint8_t data); - void lcd_command (uint8_t cmd); +// void lcd_data (uint8_t data) ; +// void lcd_command (uint8_t cmd); void lcd_command_1 (uint8_t cmd, uint8_t data); //Set the drawing and background colors @@ -91,10 +97,12 @@ typedef struct { //Set a pixel at a given location to the foreground color void lcd_set_pixel_xy(uint16_t column, uint16_t page); + void lcd_set_pixel_col_xy(uint16_t column, uint16_t page, color_t col); //Set an area to the background color void lcd_set_area_xy(uint16_t col0, uint16_t col1, uint16_t page0, uint16_t page1); - +//Draw a straight line + void lcd_draw_line(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2); //Text functions are included in font.c / font.h @@ -108,7 +116,7 @@ typedef struct { extern uint16_t lcd_current_column; static inline uint16_t lcd_get_position_page(void) {return lcd_current_page;} static inline uint16_t lcd_get_position_column(void) {return lcd_current_column;} - void lcd_write_font_byte(uint8_t b); + void lcd_write_font_byte(uint8_t b, uint8_t c); /***************************************************************************** diff --git a/atmega32u4/cooler/test.pl b/atmega32u4/cooler/test.pl new file mode 100644 index 0000000..b1eadb4 --- /dev/null +++ b/atmega32u4/cooler/test.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use Time::HiRes qw(usleep); + +open (MYFILE, '>>/dev/Xmatter_Chiller_00001'); + +for(my $i = 0;$i<300;$i++) { + my $val = sin($i/180*3.14)*16*5.2-80; + my $cmd = sprintf("SET0%s%02x%01x\n",($val<0)?'-':'+',abs($val)>>4&0xff,abs($val)&0xF); + print MYFILE $cmd; +# usleep(300000); + } \ No newline at end of file diff --git a/atmega32u4/cooler/usb/usb_serial.c b/atmega32u4/cooler/usb/usb_serial.c index 2c12a9c..02d2b00 100644 --- a/atmega32u4/cooler/usb/usb_serial.c +++ b/atmega32u4/cooler/usb/usb_serial.c @@ -42,8 +42,8 @@ // You can change these to give your code its own name. On Windows, // these are only used before an INF file (driver install) is loaded. -#define STR_MANUFACTURER L"TRB3" -#define STR_PRODUCT L"DAQi" +#define STR_MANUFACTURER L"Xmatter" +#define STR_PRODUCT L"Chiller" // All USB serial devices are supposed to have a serial number // (according to Microsoft). On windows, a new COM port is created -- 2.43.0