# HG changeset patch # User John Tsiombikas # Date 1410226847 -10800 # Node ID 9db99968b55e6986cfd0d4beb22cb9b0a538b893 initial commit, screen test working diff -r 000000000000 -r 9db99968b55e .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Sep 09 04:40:47 2014 +0300 @@ -0,0 +1,6 @@ +\.o$ +\.swp$ +\.hex$ +\.eep$ +^avrgame$ +\.map$ diff -r 000000000000 -r 9db99968b55e Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Tue Sep 09 04:40:47 2014 +0300 @@ -0,0 +1,34 @@ +src = $(wildcard *.c) +obj = $(src:.c=.o) +bin = avrgame +hex = $(bin).hex +eep = $(bin).eep + +mcu_gcc = atmega328p +mcu_dude = m328p + +CC = avr-gcc +OBJCOPY = avr-objcopy + +CFLAGS = -O2 -pedantic -Wall -mmcu=$(mcu_gcc) -DF_CPU=1000000 +LDFLAGS = -Wl,-Map,$(bin).map -mmcu=$(mcu_gcc)# -Wl,-u,vfprintf -lprintf_flt -lm + +.PHONY: all +all: $(hex) $(eep) + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +$(hex): $(bin) + $(OBJCOPY) -j .text -j .data -O ihex -R .eeprom $< $@ + +$(eep): $(bin) + $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ + +.PHONY: program +program: $(hex) + avrdude -c usbtiny -p $(mcu_dude) -e -U flash:w:$(hex) + +.PHONY: clean +clean: + rm -f $(bin) $(obj) $(hex) $(eep) $(bin).map diff -r 000000000000 -r 9db99968b55e avrgame.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/avrgame.c Tue Sep 09 04:40:47 2014 +0300 @@ -0,0 +1,38 @@ +#include +#include +#include "dotmatrix.h" + +/* hardware setup + * - Port B[1,5]: lcd signals (see dotmatrix.h) + * - B1: clk + * - B2: Din + * - B3: DC + * - B4: CE + * - B5: RST + */ + +/*int lcd_stream_write(char c, FILE *fp);*/ + +/*FILE stream_lcd = FDEV_SETUP_STREAM(lcd_stream_write, NULL, _FDEV_SETUP_WRITE);*/ + +int main(void) +{ + /* stdout = stderr = &stream_lcd; */ + + dm_init(); + dm_test(); + + for(;;) { + _delay_ms(800); + } + + return 0; +} + +#if 0 +int lcd_stream_write(char c, FILE *fp) +{ + /* TODO terminal shit handling */ + return 0; +} +#endif diff -r 000000000000 -r 9db99968b55e dotmatrix.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dotmatrix.c Tue Sep 09 04:40:47 2014 +0300 @@ -0,0 +1,190 @@ +#include +#include "dotmatrix.h" + +enum { CMD, DATA }; + +#define CMD_DISPCTL(x) (((x) & 7) | (1 << 3)) +#define CMD_FUNCSET(x) (((x) & 7) | (1 << 5)) +#define CMD_SETY(x) (((x) & 7) | (1 << 6)) +#define CMD_SETX(x) (((x) & 0x7f) | (1 << 7)) + +#define CMD_EXT_BIAS(x) (((x) & 7) | (1 << 4)) +#define CMD_EXT_VOP(x) (((x) & 0x7f) | (1 << 7)) + +#define FSET_BASIC 0 +#define FSET_EXTENDED 1 +#define FSET_VERTICAL 2 +#define FSET_POWERDOWN 3 + +#define DCTL_BLANK 0 +#define DCTL_NORMAL 4 +#define DCTL_ALL 1 +#define DCTL_INVERSE 5 + +#define FRAME_BYTES ((DM_WIDTH / 8) * DM_HEIGHT) + +#define PINMASK \ + ((1 << DM_PIN_CLK) | \ + (1 << DM_PIN_DIN) | \ + (1 << DM_PIN_DC) | \ + (1 << DM_PIN_CE) | \ + (1 << DM_PIN_RST)) + +#define SET(var, bit) ((var) |= 1 << (bit)) +#define CLR(var, bit) ((var) &= ~(1 << (bit))) + +#define NOP() asm volatile ("nop") + +static void start_send(void); +static void send(int type, unsigned char c); +static void stop_send(void); +static void send_byte(int type, unsigned char c); + +static int mode; + +int dm_init(void) +{ + int vop; + + DM_DDR |= PINMASK; /* set used pins as outputs */ + SET(DM_PORT, DM_PIN_CE); + SET(DM_PORT, DM_PIN_RST); + + /* reset the lcd controller */ + CLR(DM_PORT, DM_PIN_RST); + NOP(); + SET(DM_PORT, DM_PIN_RST); + + /* set Vop (???) */ + start_send(); + send(CMD, CMD_FUNCSET(FSET_EXTENDED)); + send(CMD, CMD_EXT_VOP(80)); + + /* select function set (vertical addressing, basic set) */ + send(CMD, CMD_FUNCSET(FSET_VERTICAL | FSET_BASIC)); + + /* enable display (normal mode) */ + mode = DCTL_NORMAL; + send(CMD, CMD_DISPCTL(mode)); + stop_send(); + + dm_clear(0); + + return 0; +} + +/* fill the screen with a test pattern */ +void dm_test(void) +{ + static const unsigned char pattern[] = { + 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, + 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, + 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, + 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f + }; + int i; + + for(i=0; i FRAME_BYTES) { + bytes = FRAME_BYTES; + } + + start_send(); + send(CMD, CMD_SETY(x / 8)); + send(CMD, CMD_SETX(y)); + + for(i=0; i>= 1; + + SET(DM_PORT, DM_PIN_CLK); + NOP(); + } + */ +} + +static void send_byte(int type, unsigned char c) +{ + start_send(); + send(type, c); + stop_send(); +} diff -r 000000000000 -r 9db99968b55e dotmatrix.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dotmatrix.h Tue Sep 09 04:40:47 2014 +0300 @@ -0,0 +1,27 @@ +#ifndef DOTMATRIX_H_ +#define DOTMATRIX_H_ + +#include + +/* change these port/pin assignments to match the circuit */ +#define DM_PORT PORTB +#define DM_DDR DDRB +#define DM_PIN_CLK 5 /* sck */ +#define DM_PIN_DIN 3 /* mosi */ +#define DM_PIN_DC 1 +#define DM_PIN_CE 2 +#define DM_PIN_RST 0 +/* end of config block, don't touch anything below */ + +#define DM_WIDTH 48 +#define DM_HEIGHT 84 + +int dm_init(void); +void dm_test(void); + +void dm_invert(void); + +void dm_clear(unsigned char val); +void dm_copy(int x, int y, const unsigned char *fb, int bytes); + +#endif /* DOTMATRIX_H_ */