Commit b05c4866 authored by insult's avatar insult

Kopiert fra gamle "imponator.git" repo

parents
# MCU name
MCU = atmega168
CFLAGS = -g -Os \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += -std=gnu99
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
TARGET = imp2005
SRC = $(TARGET).c imp_decoder.c
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Programming support using avrdude. Settings and variables.
#
# The settings here only apply for programming the imponator on a *nix
# platform with avrdude version 5 intalled. If you are programming on a
# windows platform, please consult the winavr docs.
AVRDUDE_PROGRAMMER = jtag2isp
AVRDUDE_PORT = usb
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = /usr/avr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
# Define programs and commands.
SHELL = bash
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# Programming support using avrdude.
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default targets.
all: omega hart emil nabla kth timini
default: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
omega:
python2 animgen2.py omega > imp_autogen.h
make default
mv ${TARGET}.hex hex/imponator_omega.hex
hart:
python2 animgen2.py hart > imp_autogen.h
make default
mv ${TARGET}.hex hex/imponator_hart.hex
emil:
python2 animgen2.py emil > imp_autogen.h
make default
mv ${TARGET}.hex hex/imponator_emil.hex
nabla:
python2 animgen2.py nabla > imp_autogen.h
make default
mv ${TARGET}.hex hex/imponator_nabla.hex
kth:
python2 animgen2.py kth > imp_autogen.h
make default
mv ${TARGET}.hex hex/imponator_kth.hex
timini:
python2 animgen2.py timini > imp_autogen.h
make default
mv ${TARGET}.hex hex/imponator_timini.hex
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
@echo
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) imponator_*.hex
$(REMOVE) imp_autogen.h
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
# Listing of phony targets.
.PHONY : all default omega emil nabla kth begin finish end sizebefore sizeafter\
gccversion coff extcoff clean clean_list program
#!/usr/bin/env python
import sys
## PATH RELATED ##################################################################
PATHS = {}
IMPONATORS = ("omega","nabla","kth","emil","hart","timini")
def define_paths(imponator):
p = {} # p is short for paths
if imponator in ('omega', 'nabla'):
# Remap lists:
p['map_grd0'] = [0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7]
p['map_grd1'] = [0xF, 0xE, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8]
# Definittion of paths:
p['full'] = [0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,
0xe,0xf]
p['circ'] = p['full']
p['circ2_enter'] = p['full'][:0x2]
p['circ2'] = p['full'][0x3:0xc]
p['circ2_exit'] = p['full'][0xc:]
elif imponator in 'hart':
# Remap lists:
p['map_grd0'] = [0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7]
p['map_grd1'] = [0xF, 0xE, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8]
# Definittion of paths:
p['full'] = [0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,
0xe,0xf]
p['circ'] = p['full'][-1:] + p['full'][:]
p['circ_left'] = p['circ'][:9]
p['circ_right'] = p['circ'][8:]
elif imponator == 'kth':
# Remap lists:
p['map_grd0'] = [0x0, 0x1, 0x2, 0x3, 0x9, 0x6, 0x5, 0x4]
p['map_grd1'] = [0xF, 0xE, 0xD, 0xC, 0x8, 0x7, 0xA, 0xB]
# Definittion of paths:
p['full'] = [0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,
0xe,0xf]
p['circ'] = [0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x8,0x7,0xa,0xb,
0xc,0xd,0xe,0xf]
p['circ_lower'] = p['circ'][:0xa]
p['circ_upper'] = p['circ'][0x9:]
elif imponator == 'timini':
# Remap lists:
p['map_grd0'] = [0x9, 0x8, 0xA, 0xD, 0x5, 0xB, 0x7, 0x6]
p['map_grd1'] = [0x0, 0x1, 0xF, 0xE, 0x4, 0xC, 0x2, 0x3]
#LED mapping
#-3---4---5---6-
#---F---E-------
#-2-----------7-
#-------D-------
#-1-----------8-
#-------C---A---
#-0-----------9-
#-------B-------
# Definittion of paths:
p['full'] = [0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,
0xC,0xD,0xE,0xF]
p['line_v0'] = p['full'][:5]
p['line_v1'] = p['full'][5:6]
p['line_v2'] = p['full'][6:10]
p['line_v3'] = p['full'][10:11]
p['line_v4'] = p['full'][11:]
p['line_h0'] = [0x8,0xB,0xF]
p['line_h1'] = [0x9,0xA,0xD,0xE]
p['line_h2'] = [0x0,0xC,0x7]
p['line_h3'] = [0x1,0x4,0x6]
p['line_h4'] = [0x2,0x3,0x5]
p['circ'] = p['full']
p['circ_left'] = p['circ'][:10]
p['circ_right'] = p['circ'][9:]
p['T'] = [0x3, 0x4, 0x5, 0x6, 0xB, 0xC, 0xD, 0xE]
p['I'] = [0xB, 0xC, 0xD, 0xE]
p['M'] = [0xD, 0xE, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x6, 0x7, 0x8, 0x9]
p['N'] = [0x0, 0x1, 0x2, 0x3, 0xF, 0xD, 0xA, 0x9, 0x8, 0x7, 0x6]
elif imponator == 'emil':
# Remap lists:
p['map_grd0'] = [0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7]
p['map_grd1'] = [0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF]
# Definittion of paths:
p['full'] = [0x2,0x1,0x0,0x9,0x8,0xA,0xB,0xC,0x4,0x3,0xD,0xF,
0xE,0x7,0x6,0x5]
p['line_v0'] = p['full'][:5]
p['line_v1'] = p['full'][5:6]
p['line_v2'] = p['full'][6:10]
p['line_v3'] = p['full'][10:11]
p['line_v4'] = p['full'][11:]
p['line_h0'] = [0x8,0xB,0xF]
p['line_h1'] = [0x9,0xA,0xD,0xE]
p['line_h2'] = [0x0,0xC,0x7]
p['line_h3'] = [0x1,0x4,0x6]
p['line_h4'] = [0x2,0x3,0x5]
p['circ'] = p['line_v0'] + p['line_v1'] + p['line_v2'][1:] +\
reverse_path(p['line_v2'][1:-1]) + p['line_v3'] + p['line_v4']
p['circ_left'] = p['circ'][:10]
p['circ_right'] = p['circ'][9:]
p['E'] = p['line_v0'] + p['line_h0'][1:] + p['line_h2'][1:] +\
p['line_h4']
p['M'] = p['full'][:6] + p['full'][7:8] + p['full'][10:]
p['I'] = p['line_v2']
p['L'] = p['line_v0'] + p['line_h4'][1:]
return p
## ANIMATION RELATED ###########################################################
def dim_all(frame, dim=0x01):
for i in xrange(len(frame)):
if frame[i] > 0x0: frame[i] -= dim
if frame[i] < 0x0: frame[i] = 0
return frame
def reverse_path(list):
list_r = list[:]
list_r.reverse()
return list_r
def merge_paths(path1, path2):
""" Merges two paths in a funny manner """
path = []
# Find wich path is longest:
if len(path2) < len(path1):
short_path = path2
long_path = path1
else:
short_path = path1
long_path = path2
# Join paths:
for i in xrange(len(short_path)):
path.append(long_path[i])
path.append(short_path[i])
# Append the rest of long_path
path.extend(long_path[len(short_path)-1:])
return path
def map_frame(frame, time=0x01):
""" Takes list of length 16 and a hexidescimal 0-f, generates c code that
can be included in "imp_animation_macros.h".
"""
# Create and return a remeped list:
hex_str_list = []
for i in xrange(8):
a = PATHS['map_grd0'][i]
b = PATHS['map_grd1'][i]
hex_str_list.append("0x%x%x" % (frame[a], frame[b]))
return '{{' + ", ".join(hex_str_list) + "}, 0x0%x}" % (time)
## ANIMATION GENERATOR FUNCTIONS ###################################################
def worm(path, time=0x00, fade=0x3, max_wait=0x0f):
animation_str = ''
frame = [0x00 for i in xrange(16)]
# Snake walk:
for i in path:
frame = dim_all(frame, fade)
frame[i] = 0xf
animation_str += ' ' + map_frame(frame, time) + ', \\\n'
# Fade out:
if fade != 0 and max_wait != 0:
for i in xrange(0xf/fade):
if i > max_wait:
break
frame = dim_all(frame, fade)
animation_str += ' ' + map_frame(frame, time) + ', \\\n'
# End line:
animation_str += ' ' + map_frame(frame, time) + '\n'
return animation_str
def single_dot(path, time=0x00):
return worm(path, time, fade=0x0f)
def longframe(path, time=0x0f):
animation_str = ''
frame = [0x00 for i in xrange(16)]
# Fill entire path:
for i in path:
frame[i] = 0xf
# Create long frame:
animation_str += ' ' + map_frame(frame, time) + '\n'
return animation_str
## ANIMATIONS #################################################################
def anim_default():
p = PATHS
print '#define SHIFT_ONE_CW \\'
path = p['circ'][:]
print single_dot(path, 0x00)
print '\n'
print '#define SHIFT_ONE_CCW \\'
path.reverse()
print single_dot(path, 0x00)
print '\n'
print '#define WORM_CW \\'
path = p['circ'][:]
print worm(path)
print '\n'
print '#define WORM_CCW \\'
path.reverse()
print worm(path)
def anim_omega():
anim_default()
p = PATHS
pass
def anim_hart():
anim_default()
p = PATHS
print '\n'
print '#define FONTENA \\'
path = merge_paths(p['circ_right'], reverse_path(p['circ_left']))
print worm(path, 0x01)
def anim_nabla():
anim_default()
p = PATHS
pass
def anim_emil():
anim_default()
print '\n'
p = PATHS
print '#define E \\'
path = p['E'][:]
print worm(path, 1, 0, 1)
print '\n'
print '#define M \\'
path = p['M'][:]
print worm(path, 1, 0, 1)
print '\n'
print '#define I \\'
path = p['I'][:]
print worm(path, 1, 0, 1)
print '\n'
print '#define L \\'
path = p['L'][:]
print worm(path, 1, 0, 1)
print '\n'
print '#define WORM_LEFT_CCW \\'
path = p['circ_left'][:]
print worm(path)
print '\n'
print '#define WORM_LEFT_CW \\'
path.reverse()
print worm(path)
print '\n'
print '#define WORM_RIGHT_CCW \\'
path = p['circ_right'][:]
print worm(path)
print '\n'
print '#define WORM_RIGHT_CW \\'
path.reverse()
print worm(path)
print '\n'
print '#define FONTENA \\'
path = merge_paths(p['circ_right'], reverse_path(p['circ_left']))
print worm(path, 0x01)
def anim_timini():
anim_default()
print '\n'
p = PATHS
print '#define T \\'
path = p['T'][:]
print longframe(path)
print '\n'
print '#define I \\'
path = p['I'][:]
print longframe(path)
print '\n'
print '#define M \\'
path = p['M'][:]
print longframe(path)
print '\n'
print '#define N \\'
path = p['N'][:]
print longframe(path)
print '\n'
print '#define WORM_LEFT_CCW \\'
path = p['circ_left'][:]
print worm(path)
print '\n'
print '#define WORM_LEFT_CW \\'
path.reverse()
print worm(path)
print '\n'
print '#define WORM_RIGHT_CCW \\'
path = p['circ_right'][:]
print worm(path)
print '\n'
print '#define WORM_RIGHT_CW \\'
path.reverse()
print worm(path)
print '\n'
print '#define FONTENA \\'
path = merge_paths(p['circ_right'], reverse_path(p['circ_left']))
print worm(path, 0x01)
def anim_kth():
anim_default()
print '\n'
p = PATHS
print '#define WORM_CW \\'
path = p['circ_lower'][:] + reverse_path(p['circ_upper'])
print worm(path)
print '\n'
print '#define WORM_CCW \\'
path.reverse()
print worm(path)
print '\n'
print '#define WORM_LOWER_CW \\'
path = p['circ_lower'][:]
print worm(path)
print '\n'
print '#define WORM_LOWER_CCW \\'
path.reverse()
print worm(path)
print '\n'
print '#define WORM_UPPER_CW \\'
path = p['circ_upper']
print worm(path)
print '\n'
print '#define WORM_UPPER_CCW \\'
path.reverse()
print worm(path)
print '\n'
print '#define FONTENA \\'
path = merge_paths(p['circ_lower'], reverse_path(p['circ_upper']))
print worm(path, 0x2)
## MAIN #######################################################################
def main():
if len(sys.argv) != 2 or sys.argv[1].lower() not in IMPONATORS:
print >> sys.stderr, "Usage: python animgen2.py omega|hart|nabla|kth|emil|timini"
exit(1)
imponator = sys.argv[1].lower()
print "/* WARNING: This file is generated by animgen2.py, and will be\n"\
" overwritten the next time you issue the make commnad! */", '\n'
print "#define _IMPONATOR_%s" % imponator.upper(), '\n'
global PATHS
PATHS = define_paths(imponator)
if imponator == 'omega':
anim_omega()
if imponator == 'hart':
anim_hart()
if imponator == 'nabla':
anim_nabla()
if imponator == 'emil':
anim_emil()
if imponator == 'timini':
anim_timini()
elif imponator == 'kth':
anim_kth()
if __name__ == '__main__':
main()
:100000000C944C030C9469030C9469030C946903DD
:100010000C9469030C9469030C9469030C946903B0
:100020000C9469030C9495030C9469030C94690374
:100030000C9469030C94C6030C9469030C94690333
:100040000C946B030C9469030C9469030C9469037E
:100050000C9469030C9469030C9469030C94690370
:100060000C9469030C9469030000F0000000000088
:100070000100F0F0000000000001F0F0F0000000CE
:10008000000001F0FFF0000000000001FFFFF000A1
:100090000000000001FFFFF00F0000000001FFFF63
:1000A000F00F0000000F01FFFFF00F0F00000F0125
:1000B000FFFFF00F0F0000FF01FFFFF00F0F000028
:1000C000FF01FFFFF0FF0F0000FF01FFFFF0FF0F38
:1000D000F000FF01FFFFF0FF0FF000FF010000F054
:1000E00000000000000100F0F0000000000001F03E
:1000F000F0F0000000000001F0FFF0000000000040
:1001000001FFFFF0000000000001FFFFFF00000002
:10011000000001FFFFFF000F00000001FFFFFF00D4
:100120000F0F000001FFFFFF000F0F000F01FFFF87
:10013000FF000F0F0F0F01FFFFFF000F0F0FFF0159
:10014000FFFFFF000F0FFFFF01FFFFFF000FFFFF8B
:10015000FF01FFFFFF000FFFFFFF010000000F0086