commit
513810e138
@ -0,0 +1,9 @@
|
||||
apps --- contains a sub-directory for each application
|
||||
drivers --- device driver modules (hardware independent)
|
||||
drivers/avr --- device driver modules specifically for AVR architecture
|
||||
drivers/test --- device driver modules for test scaffold
|
||||
common --- common modules (utilities, etc.)
|
||||
doc --- documentation
|
||||
etc --- miscellaneous scripts
|
||||
fonts --- fonts and font creation program
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
This directory contains a number of test applications contained in
|
||||
their own sub-directories. Within each sub-directory are two
|
||||
makefiles; one called Makefile and the other called Makefile.test. By
|
||||
default when make is run it will read Makefile.
|
||||
|
||||
make --- builds the application for the ATmega8
|
||||
make program --- programs the application into the ATmega8 flash memory
|
||||
make clean --- deletes the object and executable files
|
||||
|
||||
|
||||
The other makefile, Makefile.test, will compile the application
|
||||
natively for the PC with a test scaffold replacing the AVR dependent
|
||||
modules. This allows the application to be run and debugged on a PC.
|
||||
|
||||
make -f Makefile.test --- builds the application for the PC
|
||||
make -f Makefile.test clean --- deletes the object and executable files
|
||||
@ -0,0 +1,54 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for bounce1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
bounce1.o: bounce1.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
bounce1.out: bounce1.o pacer.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: bounce1.out
|
||||
$(OBJCOPY) -O ihex bounce1.out bounce1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash bounce1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for bounce1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
bounce1-test.o: bounce1.c ../../utils/pacer.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
bounce1: timer-test.o mgetkey-test.o bounce1-test.o pacer-test.o pio-test.o system-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) bounce1 timer-test.o mgetkey-test.o bounce1-test.o pacer-test.o pio-test.o system-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,113 @@
|
||||
/** @file bounce1.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Simple bouncing dot program
|
||||
|
||||
@defgroup bounce1 Bounce1 application
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "pacer.h"
|
||||
#include "pio.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 10
|
||||
|
||||
|
||||
/* Define PIO pins driving LED matrix rows and columns. */
|
||||
static pio_t ledmat_rows[] =
|
||||
{
|
||||
LEDMAT_ROW1_PIO, LEDMAT_ROW2_PIO, LEDMAT_ROW3_PIO, LEDMAT_ROW4_PIO,
|
||||
LEDMAT_ROW5_PIO, LEDMAT_ROW6_PIO, LEDMAT_ROW7_PIO
|
||||
};
|
||||
static pio_t ledmat_cols[] =
|
||||
{
|
||||
LEDMAT_COL1_PIO, LEDMAT_COL2_PIO, LEDMAT_COL3_PIO,
|
||||
LEDMAT_COL4_PIO, LEDMAT_COL5_PIO
|
||||
};
|
||||
|
||||
|
||||
/** Turn single LED within matrix on or off.
|
||||
@param col LED column number
|
||||
@param row LED row number
|
||||
@param state LED state */
|
||||
static void ledmat_pixel_set (int col, int row, bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
pio_output_low (ledmat_rows[row]);
|
||||
pio_output_low (ledmat_cols[col]);
|
||||
}
|
||||
else
|
||||
{
|
||||
pio_output_high (ledmat_rows[row]);
|
||||
pio_output_high (ledmat_cols[col]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Initialise LED matrix PIO pins. */
|
||||
static void ledmat_init (void)
|
||||
{
|
||||
uint8_t row;
|
||||
uint8_t col;
|
||||
|
||||
for (row = 0; row < 7; row++)
|
||||
{
|
||||
pio_config_set (ledmat_rows[row], PIO_OUTPUT_HIGH);
|
||||
pio_output_high (ledmat_rows[row]);
|
||||
}
|
||||
|
||||
for (col = 0; col < 5; col++)
|
||||
{
|
||||
pio_config_set (ledmat_cols[col], PIO_OUTPUT_HIGH);
|
||||
pio_output_high (ledmat_cols[col]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int row;
|
||||
int col;
|
||||
int rowinc;
|
||||
int colinc;
|
||||
|
||||
system_init ();
|
||||
ledmat_init ();
|
||||
|
||||
row = 3;
|
||||
col = 2;
|
||||
rowinc = 1;
|
||||
colinc = 1;
|
||||
|
||||
ledmat_pixel_set (col, row, 1);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
ledmat_pixel_set (col, row, 0);
|
||||
|
||||
col += colinc;
|
||||
row += rowinc;
|
||||
|
||||
if (row > 6 || row < 0)
|
||||
{
|
||||
row -= rowinc * 2;
|
||||
rowinc = -rowinc;
|
||||
}
|
||||
|
||||
if (col > 4 || col < 0)
|
||||
{
|
||||
col -= colinc * 2;
|
||||
colinc = -colinc;
|
||||
}
|
||||
|
||||
ledmat_pixel_set (col, row, 1);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for bounce2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
bounce2.o: bounce2.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
bounce2.out: bounce2.o display.o ledmat.o pacer.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: bounce2.out
|
||||
$(OBJCOPY) -O ihex bounce2.out bounce2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash bounce2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for bounce2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
bounce2-test.o: bounce2.c ../../utils/pacer.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
bounce2: timer-test.o display-test.o pio-test.o pacer-test.o ledmat-test.o system-test.o mgetkey-test.o bounce2-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) bounce2 timer-test.o display-test.o pio-test.o pacer-test.o ledmat-test.o system-test.o mgetkey-test.o bounce2-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
/** @file bounce2.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Simple bouncing dot program
|
||||
|
||||
@defgroup bounce2 Bounce2 application
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "pacer.h"
|
||||
#include "display.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 200
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int row;
|
||||
int col;
|
||||
int rowinc;
|
||||
int colinc;
|
||||
int tick;
|
||||
|
||||
system_init ();
|
||||
display_init ();
|
||||
|
||||
row = 3;
|
||||
col = 2;
|
||||
rowinc = 1;
|
||||
colinc = 1;
|
||||
|
||||
display_pixel_set (col, row, 1);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
tick = 0;
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tick++;
|
||||
|
||||
if (tick >= 10)
|
||||
{
|
||||
tick = 0;
|
||||
|
||||
/* Erase previous position. */
|
||||
display_pixel_set (col, row, 0);
|
||||
|
||||
col += colinc;
|
||||
row += rowinc;
|
||||
|
||||
if (row > 6 || row < 0)
|
||||
{
|
||||
row -= rowinc * 2;
|
||||
rowinc = -rowinc;
|
||||
}
|
||||
|
||||
if (col > 4 || col < 0)
|
||||
{
|
||||
col -= colinc * 2;
|
||||
colinc = -colinc;
|
||||
}
|
||||
|
||||
/* Draw new position. */
|
||||
display_pixel_set (col, row, 1);
|
||||
}
|
||||
|
||||
display_update ();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for bounce3
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce3.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
bounce3.o: bounce3.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
bounce3.out: bounce3.o display.o ledmat.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: bounce3.out
|
||||
$(OBJCOPY) -O ihex bounce3.out bounce3.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash bounce3.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for bounce3
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce3
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
bounce3-test.o: bounce3.c ../../utils/pacer.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
bounce3: timer-test.o display-test.o pio-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o bounce3-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) bounce3 timer-test.o display-test.o pio-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o bounce3-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
/** @file bounce3.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Simple bouncing dot program. This has a deliberate bug!
|
||||
|
||||
@defgroup bounce3 Bounce3 application
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "pacer.h"
|
||||
#include "tinygl.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 200
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
tinygl_point_t pos;
|
||||
int xinc;
|
||||
int yinc;
|
||||
int tick;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
|
||||
pos.y = 3;
|
||||
pos.x = 2;
|
||||
yinc = 1;
|
||||
xinc = 1;
|
||||
|
||||
tinygl_draw_point (pos, 1);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
tick = 0;
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tick++;
|
||||
|
||||
if (tick >= 10)
|
||||
{
|
||||
tick = 0;
|
||||
|
||||
/* Erase previous position. */
|
||||
tinygl_draw_point (pos, 0);
|
||||
|
||||
pos.x += xinc;
|
||||
pos.y += yinc;
|
||||
|
||||
if (pos.y > 6)
|
||||
{
|
||||
pos.y -= yinc * 2;
|
||||
yinc = -yinc;
|
||||
}
|
||||
|
||||
if (pos.x > 4)
|
||||
{
|
||||
pos.x -= xinc * 2;
|
||||
xinc = -xinc;
|
||||
}
|
||||
|
||||
/* Draw new position. */
|
||||
tinygl_draw_point (pos, 1);
|
||||
}
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for bounce4
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce4.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
bounce4.o: bounce4.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/boing.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
boing.o: ../../utils/boing.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/boing.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
bounce4.out: boing.o bounce4.o display.o ledmat.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: bounce4.out
|
||||
$(OBJCOPY) -O ihex bounce4.out bounce4.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash bounce4.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for bounce4
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce4
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
boing-test.o: ../../utils/boing.c ../../drivers/display.h ../../utils/boing.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
bounce4-test.o: bounce4.c ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../utils/boing.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
bounce4: timer-test.o display-test.o pio-test.o pacer-test.o boing-test.o ledmat-test.o tinygl-test.o bounce4-test.o system-test.o mgetkey-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) bounce4 timer-test.o display-test.o pio-test.o pacer-test.o boing-test.o ledmat-test.o tinygl-test.o bounce4-test.o system-test.o mgetkey-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/** @file bounce4.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Multiple bouncing dot program
|
||||
|
||||
@defgroup bounce4 Bounce4 application
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "pacer.h"
|
||||
#include "tinygl.h"
|
||||
#include "boing.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 200
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int tick;
|
||||
boing_state_t balls[2];
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
tick = 0;
|
||||
|
||||
balls[0] = boing_init (0, 1, DIR_NE);
|
||||
balls[1] = boing_init (4, 5, DIR_SE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tick++;
|
||||
|
||||
if (tick >= 40)
|
||||
{
|
||||
int i;
|
||||
|
||||
tick = 0;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
/* Erase previous position. */
|
||||
tinygl_draw_point (balls[i].pos, 0);
|
||||
|
||||
balls[i] = boing_update (balls[i]);
|
||||
|
||||
/* Draw new position. */
|
||||
tinygl_draw_point (balls[i].pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for bounce5
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce5.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
bounce5.o: bounce5.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/boing.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
boing.o: ../../utils/boing.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/boing.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
bounce5.out: boing.o bounce5.o display.o ledmat.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: bounce5.out
|
||||
$(OBJCOPY) -O ihex bounce5.out bounce5.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash bounce5.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for bounce5
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: bounce5
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
boing-test.o: ../../utils/boing.c ../../drivers/display.h ../../utils/boing.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
bounce5-test.o: bounce5.c ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../utils/boing.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
bounce5: timer-test.o display-test.o pio-test.o pacer-test.o boing-test.o bounce5-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) bounce5 timer-test.o display-test.o pio-test.o pacer-test.o boing-test.o bounce5-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
/** @file bounce5.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Multiple bouncing dot program
|
||||
|
||||
@defgroup bounce5 Bounce5 application
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "pacer.h"
|
||||
#include "tinygl.h"
|
||||
#include "boing.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 200
|
||||
|
||||
|
||||
/* Determine if two balls have collided
|
||||
@param balls array of all the ball states
|
||||
@param num_balls number of balls in array
|
||||
@param this_ball index of ball to check
|
||||
@return index of ball collided with or -1 for no collision */
|
||||
static int collision_detect (boing_state_t *balls, int num_balls, int this_ball)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_balls; i++)
|
||||
{
|
||||
/* Cannot collide with self. */
|
||||
if (i == this_ball)
|
||||
continue;
|
||||
|
||||
if (balls[i].pos.x == balls[this_ball].pos.x
|
||||
&& balls[i].pos.y == balls[this_ball].pos.y)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int tick;
|
||||
boing_state_t balls[3];
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
tick = 0;
|
||||
|
||||
balls[0] = boing_init (0, 1, DIR_NE);
|
||||
balls[1] = boing_init (4, 5, DIR_SE);
|
||||
balls[2] = boing_init (4, 5, DIR_SW);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tick++;
|
||||
|
||||
/* Flash the first two balls at different rates. */
|
||||
tinygl_draw_point (balls[0].pos, tick % 2 < 1);
|
||||
tinygl_draw_point (balls[1].pos, tick % 4 < 2);
|
||||
|
||||
if (tick >= 40)
|
||||
{
|
||||
int i;
|
||||
|
||||
tick = 0;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
/* Erase previous position. */
|
||||
tinygl_draw_point (balls[i].pos, 0);
|
||||
|
||||
/* Check for collision; if so reverse direction. */
|
||||
balls[i] = boing_update (balls[i]);
|
||||
|
||||
/* Perhaps should make ball that is hit reverse as well? */
|
||||
if (collision_detect (balls, 2, i) > 0)
|
||||
{
|
||||
balls[i] = boing_reverse (balls[i]);
|
||||
}
|
||||
|
||||
/* Draw previous position. */
|
||||
tinygl_draw_point (balls[i].pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for chooser
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: chooser.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
chooser.o: chooser.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
chooser.out: chooser.o display.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: chooser.out
|
||||
$(OBJCOPY) -O ihex chooser.out chooser.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash chooser.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for chooser
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: chooser
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
chooser-test.o: chooser.c ../../drivers/navswitch.h ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
chooser: timer-test.o display-test.o pio-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o navswitch-test.o chooser-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) chooser timer-test.o display-test.o pio-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o navswitch-test.o chooser-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,81 @@
|
||||
/** @file chooser.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Homework winner chooser
|
||||
|
||||
@defgroup chooser Homework winner chooser.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "navswitch.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
static void show_num (char ch, uint8_t count)
|
||||
{
|
||||
char buffer[4];
|
||||
|
||||
/* FIXME! */
|
||||
buffer[0] = ch;
|
||||
buffer[1] = count / 10 + '0';
|
||||
buffer[2] = count % 10 + '0';
|
||||
buffer[3] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
navswitch_init ();
|
||||
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT);
|
||||
|
||||
tinygl_text ("NUM?");
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_PUSH))
|
||||
{
|
||||
show_num ('T', count);
|
||||
}
|
||||
else if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
{
|
||||
if (count > 0)
|
||||
count--;
|
||||
show_num ('N', count);
|
||||
}
|
||||
else if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
{
|
||||
count++;
|
||||
show_num ('N', count);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for demo1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: demo1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
demo1.o: demo1.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
demo1.out: demo1.o pio.o system.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: demo1.out
|
||||
$(OBJCOPY) -O ihex demo1.out demo1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash demo1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for demo1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: demo1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
demo1-test.o: demo1.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/pio.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
demo1: demo1-test.o mgetkey-test.o pio-test.o system-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) demo1 demo1-test.o mgetkey-test.o pio-test.o system-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
/** @file demo1.c
|
||||
@author M.P. Hayes
|
||||
@date 25 Aug 2011
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "pio.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
system_init ();
|
||||
|
||||
pio_config_set (LED1_PIO, PIO_OUTPUT_HIGH);
|
||||
|
||||
while (1)
|
||||
{
|
||||
pio_output_toggle (LED1_PIO);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for demo2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: demo2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
demo2.o: demo2.c ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
demo2.out: demo2.o led.o pio.o system.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: demo2.out
|
||||
$(OBJCOPY) -O ihex demo2.out demo2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash demo2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for demo2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: demo2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
demo2-test.o: demo2.c ../../drivers/led.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/pio.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
demo2: demo2-test.o led-test.o mgetkey-test.o pio-test.o system-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) demo2 demo2-test.o led-test.o mgetkey-test.o pio-test.o system-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
/** @file demo2.c
|
||||
@author M.P. Hayes
|
||||
@date 25 Aug 2011
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "led.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
bool state = 0;
|
||||
|
||||
system_init ();
|
||||
|
||||
led_init ();
|
||||
|
||||
while (1)
|
||||
{
|
||||
led_set (LED1, state);
|
||||
state = !state;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for fonttest1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: fonttest1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
fonttest1.o: fonttest1.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/navswitch.h ../../fonts/font3x5_1.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
fonttest1.out: display.o fonttest1.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: fonttest1.out
|
||||
$(OBJCOPY) -O ihex fonttest1.out fonttest1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash fonttest1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for fonttest1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: fonttest1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
fonttest1-test.o: fonttest1.c ../../drivers/navswitch.h ../../utils/font.h ../../drivers/test/system.h ../../fonts/font3x5_1.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
fonttest1: timer-test.o display-test.o pio-test.o pacer-test.o tinygl-test.o ledmat-test.o system-test.o fonttest1-test.o navswitch-test.o mgetkey-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) fonttest1 timer-test.o display-test.o pio-test.o pacer-test.o tinygl-test.o ledmat-test.o system-test.o fonttest1-test.o navswitch-test.o mgetkey-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,105 @@
|
||||
/** @file fonttest1.c
|
||||
@author M.P. Hayes
|
||||
@date 3 Sep 2010
|
||||
@brief Simple font test program
|
||||
|
||||
@defgroup fonttest1 Simple font test program.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "../fonts/font3x5_1.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
static font_t *fonts[] =
|
||||
{
|
||||
&font5x7_1,
|
||||
&font3x5_1
|
||||
};
|
||||
static tinygl_text_mode_t modes[] =
|
||||
{
|
||||
TINYGL_TEXT_MODE_STEP,
|
||||
TINYGL_TEXT_MODE_STEP
|
||||
};
|
||||
|
||||
|
||||
static void choose_font (int font_num)
|
||||
{
|
||||
tinygl_font_set (fonts[font_num]);
|
||||
tinygl_text_mode_set (modes[font_num]);
|
||||
tinygl_clear ();
|
||||
}
|
||||
|
||||
|
||||
static char show_char (int font_num, char ch)
|
||||
{
|
||||
char string[2];
|
||||
|
||||
if (ch < FONT_FIRST (fonts[font_num]))
|
||||
ch = FONT_LAST (fonts[font_num]);
|
||||
else if (ch > FONT_LAST (fonts[font_num]))
|
||||
ch = FONT_FIRST (fonts[font_num]);
|
||||
|
||||
string[0] = ch;
|
||||
string[1] = 0;
|
||||
tinygl_text (string);
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
char c = 'A';
|
||||
unsigned int font_num = 0;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
|
||||
navswitch_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
choose_font (font_num);
|
||||
tinygl_text_speed_set (10);
|
||||
|
||||
c = show_char (font_num, c);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_PUSH))
|
||||
{
|
||||
font_num++;
|
||||
if (font_num >= ARRAY_SIZE (fonts))
|
||||
font_num = 0;
|
||||
|
||||
choose_font (font_num);
|
||||
c = show_char (font_num, c);
|
||||
}
|
||||
else if (navswitch_push_event_p (NAVSWITCH_WEST)
|
||||
|| navswitch_push_event_p (NAVSWITCH_SOUTH))
|
||||
{
|
||||
c = show_char (font_num, c - 1);
|
||||
}
|
||||
else if (navswitch_push_event_p (NAVSWITCH_EAST)
|
||||
|| navswitch_push_event_p (NAVSWITCH_NORTH))
|
||||
{
|
||||
c = show_char (font_num, c + 1);
|
||||
}
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
Use this directory for your final game and its module(s). Only the
|
||||
files in this directory will be marked.
|
||||
|
||||
Ensure you use the svn add command to add your files to the subversion
|
||||
repository. For example,
|
||||
|
||||
svn add game.c
|
||||
svn add Makefile
|
||||
@ -0,0 +1,57 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for hello1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
hello1.o: hello1.c ../../drivers/avr/system.h ../../drivers/ledmat.h ../../utils/pacer.h simplefont.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
hello1.out: hello1.o ledmat.o pacer.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: hello1.out
|
||||
$(OBJCOPY) -O ihex hello1.out hello1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash hello1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for hello1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
hello1-test.o: hello1.c ../../utils/pacer.h ../../drivers/ledmat.h simplefont.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
hello1: timer-test.o pio-test.o pacer-test.o ledmat-test.o hello1-test.o system-test.o mgetkey-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) hello1 timer-test.o pio-test.o pacer-test.o ledmat-test.o hello1-test.o system-test.o mgetkey-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/** @file hello1.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Simple message display program
|
||||
|
||||
@defgroup hello1 Simple message display program
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "simplefont.h"
|
||||
#include "pacer.h"
|
||||
#include "ledmat.h"
|
||||
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate in Hz. */
|
||||
#define MESSAGE_RATE 2
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
char message[] = "HELLO WORLD";
|
||||
uint8_t col = 0;
|
||||
uint8_t index = 0;
|
||||
uint8_t tick = 0;
|
||||
|
||||
system_init ();
|
||||
ledmat_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
ledmat_display_column (font[(message[index] - ' ') * 5 + col],
|
||||
col);
|
||||
|
||||
col++;
|
||||
if (col > 4)
|
||||
col = 0;
|
||||
|
||||
/* Advance message. */
|
||||
tick++;
|
||||
if (tick >= LOOP_RATE / MESSAGE_RATE)
|
||||
{
|
||||
tick = 0;
|
||||
index++;
|
||||
if (!message[index])
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
#ifndef SIMPLEFONT_H_
|
||||
#define SIMPLEFONT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static uint8_t font[] = {
|
||||
/* */ 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
/* ! */ 0x00, 0x00, 0x5F, 0x00, 0x00,
|
||||
/* " */ 0x00, 0x03, 0x00, 0x03, 0x00,
|
||||
/* # */ 0x12, 0x7F, 0x12, 0x7F, 0x12,
|
||||
/* $ */ 0x26, 0x49, 0x7F, 0x49, 0x32,
|
||||
/* % */ 0x43, 0x33, 0x08, 0x66, 0x61,
|
||||
/* & */ 0x36, 0x49, 0x55, 0x23, 0x50,
|
||||
/* ' */ 0x00, 0x00, 0x03, 0x00, 0x00,
|
||||
/* ( */ 0x00, 0x1C, 0x63, 0x41, 0x00,
|
||||
/* ) */ 0x00, 0x41, 0x63, 0x1C, 0x00,
|
||||
/* * */ 0x49, 0x2A, 0x7F, 0x2A, 0x49,
|
||||
/* + */ 0x08, 0x08, 0x7F, 0x08, 0x08,
|
||||
/* , */ 0x00, 0x40, 0x70, 0x00, 0x00,
|
||||
/* - */ 0x08, 0x08, 0x08, 0x08, 0x08,
|
||||
/* . */ 0x00, 0x00, 0x40, 0x00, 0x00,
|
||||
/* / */ 0x40, 0x30, 0x08, 0x06, 0x01,
|
||||
/* 0 */ 0x3E, 0x51, 0x49, 0x45, 0x3E,
|
||||
/* 1 */ 0x00, 0x42, 0x7F, 0x40, 0x00,
|
||||
/* 2 */ 0x42, 0x61, 0x51, 0x49, 0x46,
|
||||
/* 3 */ 0x21, 0x41, 0x45, 0x4B, 0x31,
|
||||
/* 4 */ 0x18, 0x14, 0x12, 0x7F, 0x10,
|
||||
/* 5 */ 0x27, 0x45, 0x45, 0x45, 0x39,
|
||||
/* 6 */ 0x3C, 0x4A, 0x49, 0x49, 0x30,
|
||||
/* 7 */ 0x01, 0x01, 0x79, 0x05, 0x03,
|
||||
/* 8 */ 0x37, 0x49, 0x49, 0x49, 0x36,
|
||||
/* 9 */ 0x06, 0x49, 0x49, 0x29, 0x1E,
|
||||
/* : */ 0x00, 0x00, 0x14, 0x00, 0x00,
|
||||
/* ; */ 0x00, 0x40, 0x74, 0x00, 0x00,
|
||||
/* < */ 0x00, 0x08, 0x14, 0x22, 0x41,
|
||||
/* = */ 0x14, 0x14, 0x14, 0x14, 0x14,
|
||||
/* > */ 0x41, 0x22, 0x14, 0x08, 0x00,
|
||||
/* ? */ 0x00, 0x06, 0x59, 0x05, 0x02,
|
||||
/* @ */ 0x3E, 0x41, 0x4D, 0x51, 0x4E,
|
||||
/* A */ 0x7E, 0x11, 0x11, 0x11, 0x7E,
|
||||
/* B */ 0x41, 0x7F, 0x49, 0x49, 0x36,
|
||||
/* C */ 0x3E, 0x41, 0x41, 0x41, 0x22,
|
||||
/* D */ 0x41, 0x7F, 0x41, 0x41, 0x3E,
|
||||
/* E */ 0x7F, 0x49, 0x49, 0x49, 0x49,
|
||||
/* F */ 0x7F, 0x09, 0x09, 0x09, 0x01,
|
||||
/* G */ 0x3E, 0x41, 0x41, 0x49, 0x7A,
|
||||
/* H */ 0x7F, 0x08, 0x08, 0x08, 0x7F,
|
||||
/* I */ 0x00, 0x41, 0x7F, 0x41, 0x00,
|
||||
/* J */ 0x20, 0x40, 0x41, 0x3F, 0x01,
|
||||
/* K */ 0x7F, 0x08, 0x14, 0x22, 0x41,
|
||||
/* L */ 0x7F, 0x40, 0x40, 0x40, 0x40,
|
||||
/* M */ 0x7F, 0x02, 0x0C, 0x02, 0x7F,
|
||||
/* N */ 0x7F, 0x06, 0x08, 0x30, 0x7F,
|
||||
/* O */ 0x3E, 0x41, 0x41, 0x41, 0x3E,
|
||||
/* P */ 0x7F, 0x09, 0x09, 0x09, 0x06,
|
||||
/* Q */ 0x7E, 0x41, 0x51, 0x21, 0x5E,
|
||||
/* R */ 0x7F, 0x09, 0x19, 0x29, 0x46,
|
||||
/* S */ 0x26, 0x49, 0x49, 0x49, 0x32,
|
||||
/* T */ 0x01, 0x01, 0x7F, 0x01, 0x01,
|
||||
/* U */ 0x3F, 0x40, 0x40, 0x40, 0x3F,
|
||||
/* V */ 0x1F, 0x20, 0x40, 0x20, 0x1F,
|
||||
/* W */ 0x7F, 0x20, 0x18, 0x20, 0x7F,
|
||||
/* X */ 0x63, 0x14, 0x08, 0x14, 0x63,
|
||||
/* Y */ 0x07, 0x08, 0x70, 0x08, 0x07,
|
||||
/* Z */ 0x61, 0x51, 0x49, 0x45, 0x43,
|
||||
/* [ */ 0x00, 0x7F, 0x41, 0x41, 0x00,
|
||||
/* \ */ 0x01, 0x06, 0x08, 0x30, 0x40,
|
||||
/* ] */ 0x00, 0x41, 0x41, 0x7F, 0x00,
|
||||
/* ^ */ 0x00, 0x06, 0x01, 0x06, 0x00,
|
||||
/* _ */ 0x40, 0x40, 0x40, 0x40, 0x40,
|
||||
/* ` */ 0x00, 0x01, 0x02, 0x00, 0x00
|
||||
};
|
||||
|
||||
#define FONT_WIDTH 5
|
||||
#define FONT_ASCII_OFFSET ' '
|
||||
#define FONT_TABLE_SIZE (sizeof(font)/FONT_WIDTH)
|
||||
|
||||
#endif
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for hello2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
hello2.o: hello2.c ../../drivers/avr/system.h ../../drivers/display.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
hello2.out: display.o hello2.o ledmat.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: hello2.out
|
||||
$(OBJCOPY) -O ihex hello2.out hello2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash hello2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for hello2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
hello2-test.o: hello2.c ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
hello2: timer-test.o display-test.o pio-test.o hello2-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) hello2 timer-test.o display-test.o pio-test.o hello2-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
/** @file hello2.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Simple message display program using tinygl
|
||||
|
||||
@defgroup hello2 Simple message display program using tinygl
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
|
||||
tinygl_text ("HELLO WORLD");
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for hello3
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello3.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
hello3.o: hello3.c ../../drivers/avr/system.h ../../drivers/display.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
hello3.out: display.o hello3.o ledmat.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: hello3.out
|
||||
$(OBJCOPY) -O ihex hello3.out hello3.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash hello3.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for hello3
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello3
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
hello3-test.o: hello3.c ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
hello3: timer-test.o display-test.o pio-test.o hello3-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) hello3 timer-test.o display-test.o pio-test.o hello3-test.o pacer-test.o ledmat-test.o tinygl-test.o system-test.o mgetkey-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
/** @file hello3.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Simple message display program using tinygl
|
||||
|
||||
@defgroup hello3 Simple message display program using tinygl
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT);
|
||||
|
||||
tinygl_text ("HELLO WORLD");
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for hello4
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello4.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
hello4.o: hello4.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
hello4.out: display.o hello4.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: hello4.out
|
||||
$(OBJCOPY) -O ihex hello4.out hello4.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash hello4.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for hello4
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: hello4
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
hello4-test.o: hello4.c ../../drivers/navswitch.h ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
hello4: timer-test.o display-test.o pio-test.o hello4-test.o pacer-test.o tinygl-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) hello4 timer-test.o display-test.o pio-test.o hello4-test.o pacer-test.o tinygl-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
/** @file hello4.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Simple message display program using display module.
|
||||
|
||||
@defgroup hello4 Simple message display program using tinygl
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
|
||||
navswitch_init ();
|
||||
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
|
||||
tinygl_text ("HELLO WORLD");
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP);
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_grab1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_grab1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_grab1.o: ir_grab1.c ../../drivers/avr/delay.h ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir.o: ../../drivers/ir.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_grab1.out: display.o ir.o ir_grab1.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_grab1.out
|
||||
$(OBJCOPY) -O ihex ir_grab1.out ir_grab1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_grab1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_grab1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_grab1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir-test.o: ../../drivers/ir.c ../../drivers/test/pio.h ../../drivers/ir.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_grab1-test.o: ir_grab1.c ../../drivers/navswitch.h ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/test/delay.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_grab1: timer-test.o display-test.o pio-test.o pacer-test.o tinygl-test.o ir-test.o ledmat-test.o system-test.o ir_grab1-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_grab1 timer-test.o display-test.o pio-test.o pacer-test.o tinygl-test.o ir-test.o ledmat-test.o system-test.o ir_grab1-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,135 @@
|
||||
/** @file ir_grab1.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_grab1 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir.h"
|
||||
#include "delay.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
/* At 2400 baud and 36 kHz modulation, there are 15 cycles per bit. */
|
||||
#define CODE_LEN_MAX 2000
|
||||
#define CODESEQ_LEN_MAX 200
|
||||
|
||||
#define IR_MODULATION_PERIOD_US (1e6 / IR_MODULATION_FREQ)
|
||||
#define TWEAK_US 0.5
|
||||
|
||||
|
||||
typedef struct code
|
||||
{
|
||||
uint16_t on;
|
||||
uint16_t off;
|
||||
} code_t;
|
||||
|
||||
|
||||
static void transmit (code_t *codeseq, uint8_t size)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
ir_tx_set (1, codeseq[i].on);
|
||||
ir_tx_set (0, codeseq[i].off);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t capture (code_t *codeseq, uint8_t size)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
uint16_t count;
|
||||
|
||||
for (count = 0; count < CODE_LEN_MAX && ir_rx_get (); count++)
|
||||
{
|
||||
DELAY_US (IR_MODULATION_PERIOD_US - TWEAK_US);
|
||||
}
|
||||
codeseq[i].on = count;
|
||||
|
||||
/* Something funny here. */
|
||||
if (count >= CODE_LEN_MAX)
|
||||
return 0;
|
||||
|
||||
for (count = 0; count < CODE_LEN_MAX && !ir_rx_get (); count++)
|
||||
{
|
||||
DELAY_US (IR_MODULATION_PERIOD_US - TWEAK_US);
|
||||
}
|
||||
codeseq[i].off = count;
|
||||
|
||||
if (count >= CODE_LEN_MAX)
|
||||
return i + 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
static void show_char (char ch)
|
||||
{
|
||||
char buffer[2];
|
||||
|
||||
buffer[0] = ch;
|
||||
buffer[1] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
uint8_t size = 0;
|
||||
code_t codeseq[CODESEQ_LEN_MAX];
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
|
||||
navswitch_init ();
|
||||
ir_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
show_char ('W');
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_PUSH))
|
||||
{
|
||||
transmit (codeseq, size);
|
||||
show_char ('T');
|
||||
}
|
||||
|
||||
if (ir_rx_get ())
|
||||
{
|
||||
size = capture (codeseq, CODESEQ_LEN_MAX);
|
||||
show_char (size == 0 ? 'E' : 'R');
|
||||
// size = capture (codeseq, 9);
|
||||
// show_char ('0' + size);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_grab2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_grab2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_grab2.o: ir_grab2.c ../../drivers/avr/delay.h ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/navswitch.h ../../fonts/font3x5_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h ../../utils/uint8toa.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir.o: ../../drivers/ir.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
uint8toa.o: ../../utils/uint8toa.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_grab2.out: display.o ir.o ir_grab2.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o uint8toa.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_grab2.out
|
||||
$(OBJCOPY) -O ihex ir_grab2.out ir_grab2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_grab2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_grab2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_grab2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_grab2-test.o: ir_grab2.c ../../drivers/navswitch.h ../../utils/font.h ../../drivers/test/system.h ../../fonts/font3x5_1.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/ir.h ../../utils/uint8toa.h ../../drivers/test/delay.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir-test.o: ../../drivers/ir.c ../../drivers/test/pio.h ../../drivers/ir.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
uint8toa-test.o: ../../utils/uint8toa.c ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_grab2: timer-test.o ir_grab2-test.o display-test.o pio-test.o pacer-test.o tinygl-test.o ir-test.o uint8toa-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_grab2 timer-test.o ir_grab2-test.o display-test.o pio-test.o pacer-test.o tinygl-test.o ir-test.o uint8toa-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,153 @@
|
||||
/** @file ir_grab2.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_grab2 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir.h"
|
||||
#include "delay.h"
|
||||
#include "uint8toa.h"
|
||||
#include "../fonts/font3x5_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 2000
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
/* At 2400 baud and 36 kHz modulation, there are 15 cycles per bit.
|
||||
With a Sony start code of length 4.5 x 0.6 ms there are 86 cycles. */
|
||||
#define COUNT_MAX 250
|
||||
#define CODESEQ_LEN_MAX 40
|
||||
|
||||
#define IR_MODULATION_PERIOD_US (1e6 / IR_MODULATION_FREQ)
|
||||
#define TWEAK_US 0.5
|
||||
|
||||
|
||||
typedef uint8_t count_t;
|
||||
|
||||
typedef struct code
|
||||
{
|
||||
count_t on;
|
||||
count_t off;
|
||||
} code_t;
|
||||
|
||||
|
||||
static void transmit (code_t *codeseq, uint8_t size)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
ir_tx_set (1, codeseq[i].on);
|
||||
ir_tx_set (0, codeseq[i].off);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t capture (code_t *codeseq, uint8_t size)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
count_t count;
|
||||
|
||||
for (count = 0; count < COUNT_MAX && ir_rx_get (); count++)
|
||||
{
|
||||
DELAY_US (IR_MODULATION_PERIOD_US - TWEAK_US);
|
||||
}
|
||||
codeseq[i].on = count;
|
||||
|
||||
/* Something funny here. */
|
||||
if (count >= COUNT_MAX)
|
||||
return 0;
|
||||
|
||||
for (count = 0; count < COUNT_MAX && !ir_rx_get (); count++)
|
||||
{
|
||||
DELAY_US (IR_MODULATION_PERIOD_US - TWEAK_US);
|
||||
}
|
||||
codeseq[i].off = count;
|
||||
|
||||
if (count >= COUNT_MAX)
|
||||
return i + 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
static void show_char (char ch)
|
||||
{
|
||||
char buffer[2];
|
||||
|
||||
buffer[0] = ch;
|
||||
buffer[1] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
static void show_num (char ch, uint8_t num)
|
||||
{
|
||||
char buffer[5];
|
||||
|
||||
buffer[0] = ch;
|
||||
uint8toa (num, buffer + 1, 0);
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
uint8_t size = 0;
|
||||
code_t codeseq[CODESEQ_LEN_MAX];
|
||||
uint8_t count = 0;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font3x5_1);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
|
||||
navswitch_init ();
|
||||
ir_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
show_num ('W', count);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_PUSH))
|
||||
{
|
||||
transmit (codeseq, size);
|
||||
show_char ('T');
|
||||
}
|
||||
|
||||
if (ir_rx_get ())
|
||||
{
|
||||
size = capture (codeseq, CODESEQ_LEN_MAX);
|
||||
show_num (size == 0 ? 'E' : 'R', size);
|
||||
count++;
|
||||
// size = capture (codeseq, 9);
|
||||
// show_char ('0' + size);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_grab3
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_grab3.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_grab3.o: ir_grab3.c ../../drivers/avr/delay.h ../../drivers/avr/eeprom.h ../../drivers/avr/system.h ../../drivers/button.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/led.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
eeprom.o: ../../drivers/avr/eeprom.c ../../drivers/avr/eeprom.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
button.o: ../../drivers/button.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/button.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir.o: ../../drivers/ir.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_grab3.out: button.o display.o eeprom.o ir.o ir_grab3.o led.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_grab3.out
|
||||
$(OBJCOPY) -O ihex ir_grab3.out ir_grab3.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_grab3.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_grab3
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_grab3
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
button-test.o: ../../drivers/button.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/button.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir-test.o: ../../drivers/ir.c ../../drivers/test/pio.h ../../drivers/ir.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
eeprom-test.o: ../../drivers/test/eeprom.c ../../drivers/test/eeprom.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_grab3-test.o: ir_grab3.c ../../drivers/navswitch.h ../../drivers/test/delay.h ../../drivers/test/system.h ../../drivers/test/eeprom.h ../../utils/font.h ../../drivers/led.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/button.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_grab3: timer-test.o pio-test.o led-test.o display-test.o button-test.o pacer-test.o tinygl-test.o ir-test.o ledmat-test.o eeprom-test.o system-test.o mgetkey-test.o ir_grab3-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_grab3 timer-test.o pio-test.o led-test.o display-test.o button-test.o pacer-test.o tinygl-test.o ir-test.o ledmat-test.o eeprom-test.o system-test.o mgetkey-test.o ir_grab3-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,245 @@
|
||||
/** @file ir_grab3.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_grab3 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "button.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir.h"
|
||||
#include "led.h"
|
||||
#include "delay.h"
|
||||
#include "eeprom.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 2000
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
/* At 2400 baud and 36 kHz modulation, there are 15 cycles per bit.
|
||||
With a Sony start code of length 4.5 x 0.6 ms there are 86 cycles. */
|
||||
#define COUNT_MAX 250
|
||||
|
||||
#define CODESEQ_LEN_MAX 25
|
||||
|
||||
#define CODESEQ_NUM 5
|
||||
|
||||
#define IR_MODULATION_PERIOD_US (1e6 / IR_MODULATION_FREQ)
|
||||
|
||||
#define LOOP_TWEAK_US 1.5
|
||||
|
||||
|
||||
typedef enum {STATE_NORMAL, STATE_LEARN, STATE_STORE} state_t;
|
||||
|
||||
|
||||
typedef uint8_t count_t;
|
||||
|
||||
typedef struct code
|
||||
{
|
||||
count_t on;
|
||||
count_t off;
|
||||
} code_t;
|
||||
|
||||
|
||||
static void transmit (code_t *codeseq)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; codeseq[i].on != 0; i++)
|
||||
{
|
||||
ir_tx_set (1, codeseq[i].on);
|
||||
ir_tx_set (0, codeseq[i].off);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t capture (code_t *codeseq, uint8_t size)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < size - 1; i++)
|
||||
{
|
||||
count_t count;
|
||||
|
||||
for (count = 0; count < COUNT_MAX && ir_rx_get (); count++)
|
||||
{
|
||||
DELAY_US (IR_MODULATION_PERIOD_US - LOOP_TWEAK_US);
|
||||
}
|
||||
codeseq[i].on = count;
|
||||
|
||||
for (count = 0; count < COUNT_MAX && !ir_rx_get (); count++)
|
||||
{
|
||||
DELAY_US (IR_MODULATION_PERIOD_US - LOOP_TWEAK_US - 1.0);
|
||||
}
|
||||
codeseq[i].off = count;
|
||||
|
||||
if (count >= COUNT_MAX)
|
||||
{
|
||||
/* Mark end of sequence. */
|
||||
codeseq[i + 1].on = 0;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
/* Sequence is too long. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void codeseqs_write (code_t *codeseqs, uint8_t len, uint8_t num)
|
||||
{
|
||||
eeprom_write (0, codeseqs, sizeof (codeseqs[0]) * len * num);
|
||||
}
|
||||
|
||||
|
||||
static void codeseqs_read (code_t *codeseqs, uint8_t len, uint8_t num)
|
||||
{
|
||||
/* When the EEPROM is erased all the bytes are 0xFF so set to
|
||||
sensible defaults. */
|
||||
eeprom_read (0, codeseqs, sizeof (codeseqs[0]) * len * num);
|
||||
if (codeseqs[0].on == 0xff)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
codeseqs[i * len].on = 0;
|
||||
|
||||
codeseqs_write (codeseqs, len, num);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int switch_get (void)
|
||||
{
|
||||
if (navswitch_push_event_p (NAVSWITCH_PUSH))
|
||||
return 0;
|
||||
else if (navswitch_push_event_p (NAVSWITCH_NORTH))
|
||||
return 1;
|
||||
else if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
return 2;
|
||||
else if (navswitch_push_event_p (NAVSWITCH_SOUTH))
|
||||
return 3;
|
||||
else if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
return 4;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
state_t state = STATE_NORMAL;
|
||||
code_t codeseq[CODESEQ_LEN_MAX];
|
||||
code_t codeseqs[CODESEQ_LEN_MAX * CODESEQ_NUM];
|
||||
int seq;
|
||||
static const char *strings[] = {"P", "N", "E", "S", "W"};
|
||||
|
||||
codeseqs_read (codeseqs, CODESEQ_LEN_MAX, CODESEQ_NUM);
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
|
||||
navswitch_init ();
|
||||
button_init ();
|
||||
led_init ();
|
||||
ir_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
tinygl_text ("X");
|
||||
led_set (LED1, 0);
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case STATE_NORMAL:
|
||||
|
||||
tinygl_update ();
|
||||
navswitch_update ();
|
||||
button_update ();
|
||||
|
||||
seq = switch_get ();
|
||||
|
||||
if (seq != -1)
|
||||
{
|
||||
tinygl_text (strings[seq]);
|
||||
transmit (&codeseqs[seq * CODESEQ_LEN_MAX]);
|
||||
}
|
||||
|
||||
if (button_push_event_p (BUTTON1))
|
||||
{
|
||||
led_set (LED1, 1);
|
||||
state = STATE_LEARN;
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_LEARN:
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Loop as fast as possible so that capture start of IR transmission
|
||||
as soon as possible. */
|
||||
button_update ();
|
||||
|
||||
if (ir_rx_get ())
|
||||
{
|
||||
if (capture (codeseq, CODESEQ_LEN_MAX))
|
||||
{
|
||||
tinygl_text ("?");
|
||||
led_set (LED1, 1);
|
||||
state = STATE_STORE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (button_push_event_p (BUTTON1))
|
||||
{
|
||||
led_set (LED1, 0);
|
||||
state = STATE_NORMAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_STORE:
|
||||
|
||||
tinygl_update ();
|
||||
navswitch_update ();
|
||||
button_update ();
|
||||
|
||||
seq = switch_get ();
|
||||
|
||||
if (seq != -1)
|
||||
{
|
||||
memcpy (&codeseqs[seq * CODESEQ_LEN_MAX], codeseq, sizeof (codeseq));
|
||||
codeseqs_write (codeseqs, CODESEQ_LEN_MAX, CODESEQ_NUM);
|
||||
tinygl_text (strings[seq]);
|
||||
led_set (LED1, 0);
|
||||
state = STATE_NORMAL;
|
||||
}
|
||||
|
||||
if (button_push_event_p (BUTTON1))
|
||||
{
|
||||
led_set (LED1, 0);
|
||||
state = STATE_NORMAL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_serial_test1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_serial_test1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_serial_test1.o: ir_serial_test1.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/ir_serial.h ../../drivers/navswitch.h ../../fonts/font3x5_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir.o: ../../drivers/ir.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial.o: ../../drivers/ir_serial.c ../../drivers/avr/delay.h ../../drivers/avr/system.h ../../drivers/ir.h ../../drivers/ir_serial.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_serial_test1.out: display.o ir.o ir_serial.o ir_serial_test1.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_serial_test1.out
|
||||
$(OBJCOPY) -O ihex ir_serial_test1.out ir_serial_test1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_serial_test1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_serial_test1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_serial_test1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial-test.o: ../../drivers/ir_serial.c ../../drivers/ir.h ../../drivers/ir_serial.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial_test1-test.o: ir_serial_test1.c ../../drivers/navswitch.h ../../utils/font.h ../../drivers/ir_serial.h ../../drivers/test/system.h ../../fonts/font3x5_1.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir-test.o: ../../drivers/ir.c ../../drivers/test/pio.h ../../drivers/ir.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_serial_test1: timer-test.o display-test.o pio-test.o ir_serial-test.o pacer-test.o ir_serial_test1-test.o tinygl-test.o ir-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_serial_test1 timer-test.o display-test.o pio-test.o ir_serial-test.o pacer-test.o ir_serial_test1-test.o tinygl-test.o ir-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,101 @@
|
||||
/** @file ir_serial_test1.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_serial_test1 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir_serial.h"
|
||||
#include "../fonts/font3x5_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
static void show_count (uint8_t count)
|
||||
{
|
||||
char buffer[3];
|
||||
|
||||
/* FIXME! */
|
||||
buffer[0] = 'S';
|
||||
buffer[1] = count + '0';
|
||||
buffer[2] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
static void show_err (uint8_t err)
|
||||
{
|
||||
char buffer[3];
|
||||
|
||||
buffer[0] = 'E';
|
||||
buffer[1] = err + '0';
|
||||
buffer[2] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int count = 5;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font3x5_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
|
||||
|
||||
navswitch_init ();
|
||||
ir_serial_init ();
|
||||
|
||||
show_count (count);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
int ret;
|
||||
uint8_t data;
|
||||
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
ir_serial_transmit (1);
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
ir_serial_transmit (2);
|
||||
|
||||
ret = ir_serial_receive (&data);
|
||||
if (ret == IR_SERIAL_OK)
|
||||
{
|
||||
if (data == 1)
|
||||
count--;
|
||||
else if (data == 2)
|
||||
count++;
|
||||
else
|
||||
count = 0;
|
||||
show_count (count);
|
||||
}
|
||||
else if (ret < 0)
|
||||
{
|
||||
show_err (-ret);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_serial_test2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_serial_test2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_serial_test2.o: ir_serial_test2.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/ir_serial.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir.o: ../../drivers/ir.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial.o: ../../drivers/ir_serial.c ../../drivers/avr/delay.h ../../drivers/avr/system.h ../../drivers/ir.h ../../drivers/ir_serial.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_serial_test2.out: display.o ir.o ir_serial.o ir_serial_test2.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_serial_test2.out
|
||||
$(OBJCOPY) -O ihex ir_serial_test2.out ir_serial_test2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_serial_test2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_serial_test2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_serial_test2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial-test.o: ../../drivers/ir_serial.c ../../drivers/ir.h ../../drivers/ir_serial.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial_test2-test.o: ir_serial_test2.c ../../drivers/navswitch.h ../../drivers/ir_serial.h ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/ir.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir-test.o: ../../drivers/ir.c ../../drivers/test/pio.h ../../drivers/ir.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_serial_test2: timer-test.o display-test.o pio-test.o ir_serial-test.o pacer-test.o ir_serial_test2-test.o tinygl-test.o ir-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_serial_test2 timer-test.o display-test.o pio-test.o ir_serial-test.o pacer-test.o ir_serial_test2-test.o tinygl-test.o ir-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
/** @file ir_serial_test2.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_serial_test2 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir_serial.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
static void show_count (uint8_t count)
|
||||
{
|
||||
char buffer[2];
|
||||
|
||||
/* FIXME! */
|
||||
buffer[0] = count + '0';
|
||||
buffer[1] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int count = 5;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP);
|
||||
|
||||
navswitch_init ();
|
||||
ir_serial_init ();
|
||||
|
||||
show_count (count);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
int ret;
|
||||
uint8_t data;
|
||||
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
ir_serial_transmit (1);
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
ir_serial_transmit (2);
|
||||
|
||||
ret = ir_serial_receive (&data);
|
||||
if (ret == IR_SERIAL_OK)
|
||||
{
|
||||
if (data == 1)
|
||||
count--;
|
||||
else if (data == 2)
|
||||
count++;
|
||||
show_count (count);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_serial_test3
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_serial_test3.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_serial_test3.o: ir_serial_test3.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/ir_serial.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir.o: ../../drivers/ir.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial.o: ../../drivers/ir_serial.c ../../drivers/avr/delay.h ../../drivers/avr/system.h ../../drivers/ir.h ../../drivers/ir_serial.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_serial_test3.out: display.o ir.o ir_serial.o ir_serial_test3.o ledmat.o navswitch.o pacer.o pio.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_serial_test3.out
|
||||
$(OBJCOPY) -O ihex ir_serial_test3.out ir_serial_test3.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_serial_test3.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_serial_test3
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_serial_test3
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial-test.o: ../../drivers/ir_serial.c ../../drivers/ir.h ../../drivers/ir_serial.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir-test.o: ../../drivers/ir.c ../../drivers/test/pio.h ../../drivers/ir.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial_test3-test.o: ir_serial_test3.c ../../drivers/navswitch.h ../../drivers/ir_serial.h ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/ir.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_serial_test3: timer-test.o display-test.o pio-test.o ir_serial-test.o pacer-test.o tinygl-test.o ir-test.o ledmat-test.o ir_serial_test3-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_serial_test3 timer-test.o display-test.o pio-test.o ir_serial-test.o pacer-test.o tinygl-test.o ir-test.o ledmat-test.o ir_serial_test3-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
/** @file ir_serial_test3.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_serial_test3 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir_serial.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
static void show_count (uint8_t count)
|
||||
{
|
||||
char buffer[2];
|
||||
|
||||
/* FIXME! */
|
||||
buffer[0] = count + '0';
|
||||
buffer[1] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int count = 5;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP);
|
||||
|
||||
navswitch_init ();
|
||||
ir_serial_init ();
|
||||
|
||||
show_count (count);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
int ret;
|
||||
uint8_t data;
|
||||
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
ir_serial_transmit (--count);
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
ir_serial_transmit (++count);
|
||||
|
||||
ret = ir_serial_receive (&data);
|
||||
if (ret == IR_SERIAL_OK)
|
||||
show_count (data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_uart_test1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_uart_test1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_uart_test1.o: ir_uart_test1.c ../../drivers/avr/ir_uart.h ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_uart.o: ../../drivers/avr/ir_uart.c ../../drivers/avr/ir_uart.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/avr/timer0.h ../../drivers/avr/usart1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
prescale.o: ../../drivers/avr/prescale.c ../../drivers/avr/prescale.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer0.o: ../../drivers/avr/timer0.c ../../drivers/avr/bits.h ../../drivers/avr/prescale.h ../../drivers/avr/system.h ../../drivers/avr/timer0.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
usart1.o: ../../drivers/avr/usart1.c ../../drivers/avr/system.h ../../drivers/avr/usart1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_uart_test1.out: display.o ir_uart.o ir_uart_test1.o ledmat.o navswitch.o pacer.o pio.o prescale.o system.o timer.o timer0.o tinygl.o usart1.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_uart_test1.out
|
||||
$(OBJCOPY) -O ihex ir_uart_test1.out ir_uart_test1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_uart_test1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_uart_test1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_uart_test1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_uart-test.o: ../../drivers/test/ir_uart.c ../../drivers/test/ir_uart.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_uart_test1-test.o: ir_uart_test1.c ../../drivers/navswitch.h ../../drivers/test/system.h ../../utils/font.h ../../drivers/test/ir_uart.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_uart_test1: timer-test.o display-test.o pio-test.o pacer-test.o ir_uart-test.o tinygl-test.o ledmat-test.o system-test.o ir_uart_test1-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_uart_test1 timer-test.o display-test.o pio-test.o pacer-test.o ir_uart-test.o tinygl-test.o ledmat-test.o system-test.o ir_uart_test1-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
/** @file ir_uart_test1.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_uart_test1 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir_uart.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
static void show_count (uint8_t count)
|
||||
{
|
||||
char buffer[2];
|
||||
|
||||
/* FIXME! */
|
||||
buffer[0] = count + '0';
|
||||
buffer[1] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int count = 5;
|
||||
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP);
|
||||
|
||||
navswitch_init ();
|
||||
ir_uart_init ();
|
||||
|
||||
show_count (count);
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
ir_uart_putc ('1');
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
ir_uart_putc ('2');
|
||||
|
||||
if (ir_uart_read_ready_p ())
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
data = ir_uart_getc ();
|
||||
|
||||
if (data == '1')
|
||||
count--;
|
||||
else if (data == '2')
|
||||
count++;
|
||||
show_count (count);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for ir_uart_test2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_uart_test2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
ir_uart_test2.o: ir_uart_test2.c ../../drivers/avr/ir_uart.h ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_uart.o: ../../drivers/avr/ir_uart.c ../../drivers/avr/ir_uart.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/avr/timer0.h ../../drivers/avr/usart1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
prescale.o: ../../drivers/avr/prescale.c ../../drivers/avr/prescale.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer0.o: ../../drivers/avr/timer0.c ../../drivers/avr/bits.h ../../drivers/avr/prescale.h ../../drivers/avr/system.h ../../drivers/avr/timer0.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
usart1.o: ../../drivers/avr/usart1.c ../../drivers/avr/system.h ../../drivers/avr/usart1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ir_uart_test2.out: display.o ir_uart.o ir_uart_test2.o ledmat.o navswitch.o pacer.o pio.o prescale.o system.o timer.o timer0.o tinygl.o usart1.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: ir_uart_test2.out
|
||||
$(OBJCOPY) -O ihex ir_uart_test2.out ir_uart_test2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash ir_uart_test2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for ir_uart_test2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: ir_uart_test2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_uart_test2-test.o: ir_uart_test2.c ../../drivers/navswitch.h ../../drivers/test/system.h ../../utils/font.h ../../drivers/test/ir_uart.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_uart-test.o: ../../drivers/test/ir_uart.c ../../drivers/test/ir_uart.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
ir_uart_test2: timer-test.o display-test.o pio-test.o ir_uart_test2-test.o pacer-test.o ir_uart-test.o tinygl-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) ir_uart_test2 timer-test.o display-test.o pio-test.o ir_uart_test2-test.o pacer-test.o ir_uart-test.o tinygl-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
/** @file ir_uart_test2.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2009
|
||||
@brief Test program for IR serial communnications.
|
||||
|
||||
@defgroup ir_uart_test2 Test program for IR serial communications.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "ir_uart.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
/* Define text update rate (characters per 10 s). */
|
||||
#define MESSAGE_RATE 10
|
||||
|
||||
|
||||
static void show_char (char ch)
|
||||
{
|
||||
char buffer[2];
|
||||
|
||||
buffer[0] = ch;
|
||||
buffer[1] = 0;
|
||||
tinygl_text (buffer);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
system_init ();
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (MESSAGE_RATE);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP);
|
||||
|
||||
navswitch_init ();
|
||||
ir_uart_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
show_char ('M');
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
uint8_t data = 'M';
|
||||
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
tinygl_update ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
ir_uart_putc (--data);
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
ir_uart_putc (++data);
|
||||
|
||||
if (ir_uart_read_ready_p ())
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
data = ir_uart_getc ();
|
||||
show_char (data);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for led1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
led1.o: led1.c ../../drivers/avr/system.h ../../drivers/led.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
led1.out: led.o led1.o pacer.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: led1.out
|
||||
$(OBJCOPY) -O ihex led1.out led1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash led1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for led1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led1-test.o: led1.c ../../drivers/led.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
led1: timer-test.o led-test.o pio-test.o pacer-test.o system-test.o mgetkey-test.o led1-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) led1 timer-test.o led-test.o pio-test.o pacer-test.o system-test.o mgetkey-test.o led1-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
/** @file led1.c
|
||||
@author M.P. Hayes
|
||||
@date 5 Oct 2010
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "led.h"
|
||||
#include "pacer.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 1000
|
||||
|
||||
#define LED_RATE 2
|
||||
|
||||
int main (void)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
unsigned int period = LOOP_RATE / LED_RATE;
|
||||
|
||||
system_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
led_init ();
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
led_set (LED1, count < period / 2);
|
||||
count++;
|
||||
if (count >= period)
|
||||
count = 0;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for led2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
led2.o: led2.c ../../drivers/avr/system.h ../../drivers/led.h ../../drivers/navswitch.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
led2.out: led.o led2.o navswitch.o pacer.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: led2.out
|
||||
$(OBJCOPY) -O ihex led2.out led2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash led2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for led2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led2-test.o: led2.c ../../drivers/led.h ../../utils/pacer.h ../../drivers/navswitch.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
led2: timer-test.o led-test.o pio-test.o pacer-test.o system-test.o led2-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) led2 timer-test.o led-test.o pio-test.o pacer-test.o system-test.o led2-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
/** @file led2.c
|
||||
@author M.P. Hayes
|
||||
@date 5 Oct 2010
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "led.h"
|
||||
#include "pacer.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 1000
|
||||
|
||||
#define LED_RATE_INC 2
|
||||
#define LED_RATE_MIN 0
|
||||
#define LED_RATE_MAX 100
|
||||
|
||||
typedef struct pen pen_t;
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int freq = 1;
|
||||
unsigned int count = 0;
|
||||
unsigned int period = LOOP_RATE / freq;
|
||||
|
||||
system_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
led_init ();
|
||||
navswitch_init ();
|
||||
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_SOUTH))
|
||||
{
|
||||
freq -= LED_RATE_INC;
|
||||
if (freq < LED_RATE_MIN)
|
||||
freq = LED_RATE_MIN;
|
||||
|
||||
period = LOOP_RATE / freq;
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_NORTH))
|
||||
{
|
||||
freq += LED_RATE_INC;
|
||||
if (freq > LED_RATE_MAX)
|
||||
freq = LED_RATE_MAX;
|
||||
|
||||
period = LOOP_RATE / freq;
|
||||
}
|
||||
|
||||
led_set (LED1, count < period / 2);
|
||||
count++;
|
||||
if (count >= period)
|
||||
count = 0;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for led3
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led3.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
led3.o: led3.c ../../drivers/avr/system.h ../../drivers/led.h ../../drivers/navswitch.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
led3.out: led.o led3.o navswitch.o pacer.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: led3.out
|
||||
$(OBJCOPY) -O ihex led3.out led3.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash led3.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for led3
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led3
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led3-test.o: led3.c ../../drivers/led.h ../../utils/pacer.h ../../drivers/navswitch.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
led3: timer-test.o led-test.o pio-test.o system-test.o pacer-test.o mgetkey-test.o navswitch-test.o led3-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) led3 timer-test.o led-test.o pio-test.o system-test.o pacer-test.o mgetkey-test.o navswitch-test.o led3-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
/** @file led3.c
|
||||
@author M.P. Hayes
|
||||
@date 5 Oct 2010
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "led.h"
|
||||
#include "pacer.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 1000
|
||||
|
||||
#define LED_RATE 50
|
||||
#define LED_DUTY_INC 5
|
||||
#define LED_DUTY_MIN 0
|
||||
#define LED_DUTY_MAX 100
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int duty = 50;
|
||||
unsigned int count = 0;
|
||||
unsigned int period = LOOP_RATE / LED_RATE;
|
||||
unsigned int offcount = period * duty / 100;
|
||||
|
||||
system_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
led_init ();
|
||||
navswitch_init ();
|
||||
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_SOUTH))
|
||||
{
|
||||
duty -= LED_DUTY_INC;
|
||||
if (duty < LED_DUTY_MIN)
|
||||
duty = LED_DUTY_MIN;
|
||||
|
||||
offcount = period * duty / 100;
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_NORTH))
|
||||
{
|
||||
duty += LED_DUTY_INC;
|
||||
if (duty > LED_DUTY_MAX)
|
||||
duty = LED_DUTY_MAX;
|
||||
offcount = period * duty / 100;
|
||||
}
|
||||
|
||||
led_set (LED1, count < offcount);
|
||||
count++;
|
||||
if (count >= period)
|
||||
count = 0;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for led4
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led4.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
led4.o: led4.c ../../drivers/avr/system.h ../../drivers/led.h ../../drivers/navswitch.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
led4.out: led.o led4.o navswitch.o pacer.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: led4.out
|
||||
$(OBJCOPY) -O ihex led4.out led4.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash led4.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for led4
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led4
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led4-test.o: led4.c ../../drivers/led.h ../../utils/pacer.h ../../drivers/navswitch.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
led4: timer-test.o led-test.o pio-test.o led4-test.o pacer-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) led4 timer-test.o led-test.o pio-test.o led4-test.o pacer-test.o system-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
/** @file led4.c
|
||||
@author M.P. Hayes
|
||||
@date 5 Oct 2010
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "led.h"
|
||||
#include "pacer.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 4000
|
||||
|
||||
#define LED_RATE 40
|
||||
|
||||
typedef struct pen pen_t;
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
unsigned int duty[] = {0, 1, 2, 5, 10, 20, 50, 100};
|
||||
unsigned int duty_index = 3;
|
||||
unsigned int count = 0;
|
||||
unsigned int period = LOOP_RATE / LED_RATE;
|
||||
unsigned int offcount = period * duty[duty_index] / 100;
|
||||
|
||||
system_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
led_init ();
|
||||
navswitch_init ();
|
||||
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
/* There is no need to poll the switches so frequently but it
|
||||
keeps the code simpler. */
|
||||
navswitch_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_SOUTH))
|
||||
{
|
||||
if (duty_index > 0)
|
||||
duty_index--;
|
||||
|
||||
offcount = (period * duty[duty_index] + 50) / 100;
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_NORTH))
|
||||
{
|
||||
duty_index++;
|
||||
if (duty_index >= ARRAY_SIZE (duty))
|
||||
duty_index = ARRAY_SIZE (duty) - 1;
|
||||
offcount = (period * duty[duty_index] + 50) / 100;
|
||||
}
|
||||
|
||||
led_set (LED1, count < offcount);
|
||||
count++;
|
||||
if (count >= period)
|
||||
count = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for led5
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led5.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
led5.o: led5.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
led5.out: led.o led5.o pio.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: led5.out
|
||||
$(OBJCOPY) -O ihex led5.out led5.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash led5.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for led5
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: led5
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led5-test.o: led5.c ../../drivers/test/timer.h ../../drivers/led.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
led5: timer-test.o mgetkey-test.o led-test.o pio-test.o led5-test.o system-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) led5 timer-test.o mgetkey-test.o led-test.o pio-test.o led5-test.o system-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
/** @file led5.c
|
||||
@author M.P. Hayes
|
||||
@date 18 Aug 2011
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "timer.h"
|
||||
#include "led.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
timer_tick_t now;
|
||||
|
||||
system_init ();
|
||||
|
||||
timer_init ();
|
||||
led_init ();
|
||||
|
||||
now = timer_get ();
|
||||
while (1)
|
||||
{
|
||||
led_set (LED1, 1);
|
||||
|
||||
now = timer_wait_until (now + (timer_tick_t)(TIMER_RATE * 0.5));
|
||||
|
||||
led_set (LED1, 0);
|
||||
|
||||
now = timer_wait_until (now + (timer_tick_t)(TIMER_RATE * 0.75));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for pio1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: pio1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
pio1.o: pio1.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
pio1.out: pio.o pio1.o system.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: pio1.out
|
||||
$(OBJCOPY) -O ihex pio1.out pio1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash pio1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for pio1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: pio1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio1-test.o: pio1.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
pio1: mgetkey-test.o pio1-test.o pio-test.o system-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) pio1 mgetkey-test.o pio1-test.o pio-test.o system-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
/** @file pio1.c
|
||||
@author M.P. Hayes
|
||||
@date 25 Aug 2011
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "pio.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
system_init ();
|
||||
|
||||
pio_config_set (LED1_PIO, PIO_OUTPUT_HIGH);
|
||||
|
||||
while (1)
|
||||
{
|
||||
pio_output_toggle (LED1_PIO);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for pio2
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: pio2.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
pio2.o: pio2.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
pio2.out: pio.o pio2.o system.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: pio2.out
|
||||
$(OBJCOPY) -O ihex pio2.out pio2.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash pio2.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for pio2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: pio2
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
pio2-test.o: pio2.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
pio2: pio2-test.o mgetkey-test.o pio-test.o system-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) pio2 pio2-test.o mgetkey-test.o pio-test.o system-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
/** @file pio2.c
|
||||
@author M.P. Hayes
|
||||
@date 25 Aug 2011
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "pio.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
uint16_t count = 0;
|
||||
|
||||
system_init ();
|
||||
|
||||
pio_config_set (LED1_PIO, PIO_OUTPUT_HIGH);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (count > 10000)
|
||||
{
|
||||
pio_output_toggle (LED1_PIO);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for pio3
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: pio3.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
pio3.o: pio3.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
pio3.out: pio.o pio3.o system.o timer.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: pio3.out
|
||||
$(OBJCOPY) -O ihex pio3.out pio3.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash pio3.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for pio3
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: pio3
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio3-test.o: pio3.c ../../drivers/test/timer.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
pio3: timer-test.o mgetkey-test.o pio-test.o pio3-test.o system-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) pio3 timer-test.o mgetkey-test.o pio-test.o pio3-test.o system-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
/** @file pio3.c
|
||||
@author M.P. Hayes
|
||||
@date 25 Aug 2011
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "pio.h"
|
||||
#include "timer.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 1000
|
||||
|
||||
#define LED_RATE 2
|
||||
|
||||
int main (void)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
unsigned int period = LOOP_RATE / LED_RATE;
|
||||
|
||||
system_init ();
|
||||
|
||||
timer_init ();
|
||||
|
||||
pio_config_set (LED1_PIO, PIO_OUTPUT_HIGH);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
timer_wait (TIMER_RATE / LOOP_RATE);
|
||||
|
||||
pio_output_set (LED1_PIO, count < period / 2);
|
||||
count++;
|
||||
if (count >= period)
|
||||
count = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for scribble1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: scribble1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
scribble1.o: scribble1.c ../../drivers/avr/system.h ../../drivers/button.h ../../drivers/display.h ../../drivers/led.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
button.o: ../../drivers/button.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/button.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led.o: ../../drivers/led.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/led.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
scribble1.out: button.o display.o led.o ledmat.o navswitch.o pacer.o pio.o scribble1.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: scribble1.out
|
||||
$(OBJCOPY) -O ihex scribble1.out scribble1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash scribble1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for scribble1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: scribble1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
led-test.o: ../../drivers/led.c ../../drivers/led.h ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
button-test.o: ../../drivers/button.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/button.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
scribble1-test.o: scribble1.c ../../drivers/navswitch.h ../../drivers/test/system.h ../../utils/font.h ../../drivers/led.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/button.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
scribble1: timer-test.o led-test.o display-test.o pio-test.o button-test.o pacer-test.o tinygl-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o scribble1-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) scribble1 timer-test.o led-test.o display-test.o pio-test.o button-test.o pacer-test.o tinygl-test.o ledmat-test.o system-test.o mgetkey-test.o navswitch-test.o scribble1-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
/** @file scribble1.c
|
||||
@author M.P. Hayes
|
||||
@date 5 Oct 2010
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "button.h"
|
||||
#include "navswitch.h"
|
||||
#include "led.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
#define SCRIBBLE_SPEED 2
|
||||
|
||||
|
||||
typedef enum dir dir_t;
|
||||
|
||||
struct pen
|
||||
{
|
||||
/* Current pos of pen. */
|
||||
tinygl_point_t pos;
|
||||
/* Current state of pen. */
|
||||
bool state;
|
||||
};
|
||||
|
||||
typedef struct pen pen_t;
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
pen_t pen;
|
||||
|
||||
system_init ();
|
||||
|
||||
pen.pos.x = TINYGL_WIDTH / 2;
|
||||
pen.pos.y = TINYGL_HEIGHT / 2;
|
||||
pen.state = 1;
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
led_init ();
|
||||
button_init ();
|
||||
navswitch_init ();
|
||||
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_draw_point (pen.pos, pen.state);
|
||||
|
||||
led_set (LED1, pen.state);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
bool draw = 0;
|
||||
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
navswitch_update ();
|
||||
button_update ();
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST) && pen.pos.x > 0)
|
||||
{
|
||||
pen.pos.x--;
|
||||
draw = 1;
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST) && pen.pos.x < TINYGL_WIDTH - 1)
|
||||
{
|
||||
pen.pos.x++;
|
||||
draw = 1;
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_SOUTH) && pen.pos.y < TINYGL_HEIGHT - 1)
|
||||
{
|
||||
pen.pos.y++;
|
||||
draw = 1;
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_NORTH) && pen.pos.y > 0)
|
||||
{
|
||||
pen.pos.y--;
|
||||
draw = 1;
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_PUSH)
|
||||
|| button_push_event_p (BUTTON1))
|
||||
{
|
||||
pen.state = !pen.state;
|
||||
led_set (LED1, pen.state);
|
||||
}
|
||||
|
||||
if (draw)
|
||||
tinygl_draw_point (pen.pos, pen.state);
|
||||
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for snake1
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: snake1.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
snake1.o: snake1.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/navswitch.h ../../fonts/font5x7_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch.o: ../../drivers/navswitch.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/navswitch.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
snake1.out: display.o ledmat.o navswitch.o pacer.o pio.o snake1.o system.o timer.o tinygl.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: snake1.out
|
||||
$(OBJCOPY) -O ihex snake1.out snake1.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash snake1.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for snake1
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: snake1
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
snake1-test.o: snake1.c ../../drivers/navswitch.h ../../drivers/test/system.h ../../utils/font.h ../../utils/tinygl.h ../../utils/pacer.h ../../drivers/display.h ../../fonts/font5x7_1.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
navswitch-test.o: ../../drivers/navswitch.c ../../drivers/test/pio.h ../../drivers/navswitch.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
snake1: timer-test.o display-test.o pio-test.o system-test.o pacer-test.o tinygl-test.o ledmat-test.o snake1-test.o mgetkey-test.o navswitch-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) snake1 timer-test.o display-test.o pio-test.o system-test.o pacer-test.o tinygl-test.o ledmat-test.o snake1-test.o mgetkey-test.o navswitch-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,127 @@
|
||||
/** @file snake1.c
|
||||
@author M.P. Hayes
|
||||
@date 5 Oct 2010
|
||||
@note The sneake head deliberately moves off screen unless turned.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "navswitch.h"
|
||||
#include "tinygl.h"
|
||||
#include "pacer.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
|
||||
/* Define polling rate in Hz. */
|
||||
#define LOOP_RATE 300
|
||||
|
||||
#define SNAKE_SPEED 2
|
||||
|
||||
enum dir {DIR_N, DIR_E, DIR_S, DIR_W};
|
||||
|
||||
typedef enum dir dir_t;
|
||||
|
||||
struct snake
|
||||
{
|
||||
/* Current head of snake. */
|
||||
tinygl_point_t pos;
|
||||
/* Current direction. */
|
||||
enum dir dir;
|
||||
};
|
||||
|
||||
typedef struct snake snake_t;
|
||||
|
||||
|
||||
static snake_t snake_move (snake_t snake)
|
||||
{
|
||||
switch (snake.dir)
|
||||
{
|
||||
case DIR_N:
|
||||
snake.pos.y = snake.pos.y - 1;
|
||||
break;
|
||||
|
||||
case DIR_E:
|
||||
snake.pos.x = snake.pos.x + 1;
|
||||
break;
|
||||
|
||||
case DIR_S:
|
||||
snake.pos.y = snake.pos.y + 1;
|
||||
break;
|
||||
|
||||
case DIR_W:
|
||||
snake.pos.x = snake.pos.x - 1;
|
||||
break;
|
||||
}
|
||||
tinygl_draw_point (snake.pos, 1);
|
||||
return snake;
|
||||
}
|
||||
|
||||
|
||||
static snake_t snake_turn_left (snake_t snake)
|
||||
{
|
||||
dir_t newdir[] = {DIR_W, DIR_N, DIR_E, DIR_S};
|
||||
|
||||
snake.dir = newdir[snake.dir];
|
||||
return snake;
|
||||
}
|
||||
|
||||
|
||||
static snake_t snake_turn_right (snake_t snake)
|
||||
{
|
||||
dir_t newdir[] = {DIR_E, DIR_S, DIR_W, DIR_N};
|
||||
|
||||
snake.dir = newdir[snake.dir];
|
||||
return snake;
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
snake_t snake;
|
||||
int tick = 0;
|
||||
|
||||
system_init ();
|
||||
|
||||
snake.dir = DIR_N;
|
||||
snake.pos.x = TINYGL_WIDTH / 2;
|
||||
snake.pos.y = TINYGL_HEIGHT - 1;
|
||||
|
||||
tinygl_init (LOOP_RATE);
|
||||
tinygl_font_set (&font5x7_1);
|
||||
|
||||
navswitch_init ();
|
||||
|
||||
pacer_init (LOOP_RATE);
|
||||
|
||||
tinygl_draw_point (snake.pos, 1);
|
||||
|
||||
/* Paced loop. */
|
||||
while (1)
|
||||
{
|
||||
/* Wait for next tick. */
|
||||
pacer_wait ();
|
||||
|
||||
navswitch_update ();
|
||||
|
||||
tick = tick + 1;
|
||||
if (tick > LOOP_RATE / SNAKE_SPEED)
|
||||
{
|
||||
tick = 0;
|
||||
snake = snake_move (snake);
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_WEST))
|
||||
{
|
||||
snake = snake_turn_left (snake);
|
||||
}
|
||||
|
||||
if (navswitch_push_event_p (NAVSWITCH_EAST))
|
||||
{
|
||||
snake = snake_turn_right (snake);
|
||||
}
|
||||
|
||||
|
||||
tinygl_update ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 12 Sep 2010
|
||||
# Descr: Makefile for space10
|
||||
|
||||
# Definitions.
|
||||
CC = avr-gcc
|
||||
CFLAGS = -mmcu=atmega32u2 -Os -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../fonts -I../../drivers -I../../drivers/avr
|
||||
OBJCOPY = avr-objcopy
|
||||
SIZE = avr-size
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: space10.out
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
space10.o: space10.c ../../drivers/avr/eeprom.h ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ir.h ../../drivers/ir_serial.h ../../fonts/font3x5_1.h ../../utils/font.h ../../utils/pacer.h ../../utils/tinygl.h ../../utils/uint8toa.h flasher.h spacey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
flasher.o: flasher.c ../../drivers/avr/system.h flasher.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
spacey.o: spacey.c ../../drivers/avr/system.h spacey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
eeprom.o: ../../drivers/avr/eeprom.c ../../drivers/avr/eeprom.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio.o: ../../drivers/avr/pio.c ../../drivers/avr/pio.h ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system.o: ../../drivers/avr/system.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer.o: ../../drivers/avr/timer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display.o: ../../drivers/display.c ../../drivers/avr/system.h ../../drivers/display.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir.o: ../../drivers/ir.c ../../drivers/avr/delay.h ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ir.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial.o: ../../drivers/ir_serial.c ../../drivers/avr/delay.h ../../drivers/avr/system.h ../../drivers/ir.h ../../drivers/ir_serial.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat.o: ../../drivers/ledmat.c ../../drivers/avr/pio.h ../../drivers/avr/system.h ../../drivers/ledmat.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer.o: ../../utils/pacer.c ../../drivers/avr/system.h ../../drivers/avr/timer.h ../../utils/pacer.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl.o: ../../utils/tinygl.c ../../drivers/avr/system.h ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
uint8toa.o: ../../utils/uint8toa.c ../../drivers/avr/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
space10.out: display.o eeprom.o flasher.o ir.o ir_serial.o ledmat.o pacer.o pio.o space10.o spacey.o system.o timer.o tinygl.o uint8toa.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lm
|
||||
$(SIZE) $@
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) *.o *.out *.hex
|
||||
|
||||
|
||||
# Target: program project.
|
||||
.PHONY: program
|
||||
program: space10.out
|
||||
$(OBJCOPY) -O ihex space10.out space10.hex
|
||||
dfu-programmer atmega32u2 erase; dfu-programmer atmega32u2 flash space10.hex; dfu-programmer atmega32u2 start
|
||||
|
||||
|
||||
@ -0,0 +1,75 @@
|
||||
# File: Makefile
|
||||
# Author: M. P. Hayes, UCECE
|
||||
# Date: 11 Sep 2010
|
||||
# Descr: Makefile for space10
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wstrict-prototypes -Wextra -g -I. -I../../utils -I../../drivers -I../../drivers/test
|
||||
|
||||
DEL = rm
|
||||
|
||||
|
||||
# Default target.
|
||||
all: space10
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
space10-test.o: space10.c ../../utils/font.h ../../drivers/ir_serial.h ../../drivers/test/system.h ../../drivers/test/eeprom.h ../../fonts/font3x5_1.h flasher.h ../../utils/tinygl.h spacey.h ../../utils/pacer.h ../../drivers/display.h ../../drivers/ir.h ../../utils/uint8toa.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
timer-test.o: ../../drivers/test/timer.c ../../drivers/test/timer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
display-test.o: ../../drivers/display.c ../../drivers/ledmat.h ../../drivers/display.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
spacey-test.o: spacey.c spacey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pio-test.o: ../../drivers/test/pio.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir_serial-test.o: ../../drivers/ir_serial.c ../../drivers/ir.h ../../drivers/ir_serial.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
pacer-test.o: ../../utils/pacer.c ../../drivers/test/timer.h ../../utils/pacer.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
flasher-test.o: flasher.c flasher.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
tinygl-test.o: ../../utils/tinygl.c ../../drivers/display.h ../../utils/font.h ../../utils/tinygl.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
uint8toa-test.o: ../../utils/uint8toa.c ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ledmat-test.o: ../../drivers/ledmat.c ../../drivers/test/avrtest.h ../../drivers/test/pio.h ../../drivers/ledmat.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
eeprom-test.o: ../../drivers/test/eeprom.c ../../drivers/test/eeprom.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
system-test.o: ../../drivers/test/system.c ../../drivers/test/pio.h ../../drivers/test/avrtest.h ../../drivers/test/mgetkey.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
ir-test.o: ../../drivers/ir.c ../../drivers/test/pio.h ../../drivers/ir.h ../../drivers/test/avrtest.h ../../drivers/test/delay.h ../../drivers/test/system.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
mgetkey-test.o: ../../drivers/test/mgetkey.c ../../drivers/test/mgetkey.h
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
|
||||
# Link: create executable file from object files.
|
||||
space10: space10-test.o timer-test.o display-test.o spacey-test.o pio-test.o ir_serial-test.o pacer-test.o flasher-test.o tinygl-test.o uint8toa-test.o ledmat-test.o eeprom-test.o system-test.o ir-test.o mgetkey-test.o
|
||||
$(CC) $(CFLAGS) $^ -o $@ -lrt
|
||||
|
||||
|
||||
# Clean: delete derived files.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-$(DEL) space10 space10-test.o timer-test.o display-test.o spacey-test.o pio-test.o ir_serial-test.o pacer-test.o flasher-test.o tinygl-test.o uint8toa-test.o ledmat-test.o eeprom-test.o system-test.o ir-test.o mgetkey-test.o
|
||||
|
||||
|
||||
@ -0,0 +1,100 @@
|
||||
/** @file flasher.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 13 March 2005
|
||||
@brief
|
||||
*/
|
||||
|
||||
#include "flasher.h"
|
||||
|
||||
|
||||
/* These routines are for flashing a LED or beeping a piezo tweeter.
|
||||
Perhaps they should be separated into software PWM and flash
|
||||
pattern sequencing. */
|
||||
|
||||
int8_t
|
||||
flasher_pattern_set (flasher_t flasher, flasher_pattern_t *pattern)
|
||||
{
|
||||
flasher->pattern = pattern;
|
||||
flasher->mod_count = 0;
|
||||
flasher->flasher_count = 0;
|
||||
flasher->flashes_count = 0;
|
||||
flasher->flasher_prescale = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
flasher_pattern_t *
|
||||
flasher_pattern_get (flasher_t flasher)
|
||||
{
|
||||
return flasher->pattern;
|
||||
}
|
||||
|
||||
|
||||
/* FIXME. */
|
||||
int8_t
|
||||
flasher_phase_set (flasher_t flasher, uint8_t phase)
|
||||
{
|
||||
flasher->mod_count = 0;
|
||||
flasher->flasher_count = 0;
|
||||
flasher->flashes_count = phase;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Return the next state for the associated device. For example,
|
||||
to control the flashing of a LED use:
|
||||
|
||||
led_set (led, flasher_update (flasher)); */
|
||||
bool
|
||||
flasher_update (flasher_t flasher)
|
||||
{
|
||||
if (!flasher->pattern)
|
||||
return 0;
|
||||
|
||||
flasher->mod_count++;
|
||||
if (flasher->mod_count >= flasher->pattern->mod_period)
|
||||
{
|
||||
flasher->mod_count = 0;
|
||||
flasher->flasher_prescale++;
|
||||
|
||||
if (flasher->flasher_prescale >= FLASHER_PRESCALE)
|
||||
{
|
||||
flasher->flasher_prescale = 0;
|
||||
flasher->flasher_count++;
|
||||
|
||||
if (flasher->flasher_count >= flasher->pattern->flasher_period)
|
||||
{
|
||||
flasher->flasher_count = 0;
|
||||
flasher->flashes_count++;
|
||||
|
||||
if (!flasher->pattern->period)
|
||||
{
|
||||
/* One shot mode. */
|
||||
if (flasher->flashes_count >= flasher->pattern->flashes)
|
||||
{
|
||||
/* Disable pattern. */
|
||||
flasher->pattern = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (flasher->flashes_count >= flasher->pattern->period)
|
||||
{
|
||||
flasher->flashes_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flasher->mod_count < flasher->pattern->mod_duty
|
||||
&& flasher->flasher_count < flasher->pattern->flasher_duty
|
||||
&& flasher->flashes_count < flasher->pattern->flashes;
|
||||
}
|
||||
|
||||
|
||||
/* Create a new flasher device. */
|
||||
flasher_t
|
||||
flasher_init (flasher_obj_t *flasher)
|
||||
{
|
||||
flasher_pattern_set (flasher, 0);
|
||||
return flasher;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue