PROJECT = doglight
BUILDDIR = build
UINCDIR += src

# Enable / disable debugging
USE_OPT += -DENABLE_DEBUG=0

USE_OPT += -O2 -g -gdwarf-2 -g3 \
	-fno-omit-frame-pointer -fno-common -std=gnu99

# Base system & bootup
PROJECT_CSRC += src/main.c src/board.c src/debug.c

# Shell
PROJECT_CSRC += src/shell_commands.c

# MMA7660 accelerometer
PROJECT_CSRC += src/mma7660_acc.c

# Task for reading the sensors
PROJECT_CSRC += src/sensor_task.c

# RTC driver
PROJECT_CSRC += src/stm32l_rtc.c

# ADC wrappers
PROJECT_CSRC += src/stm32l_adc.c

# Main state machine
PROJECT_CSRC += src/main_logic.c

# Runtime statistics
PROJECT_CSRC += src/stats.c

# Baselibc
#PROJECT_CSRC += src_common/libc_glue.c
UINCDIR += baselibc/include
ULIBS += baselibc/libc.a -lm -lgcc -nodefaultlibs

UADEFS =
ULIBDIR =

include Makefile.chibios
	
deploy: all
	#st-flash write /dev/stlinkv1_3 $(BUILDDIR)/$(PROJECT).bin 0x08000000
	openocd -d0 -f interface/stlink-v1.cfg -f target/stm32lx_stlink.cfg \
		-c init -c targets -c "reset halt" \
		-c "flash write_image erase $(BUILDDIR)/$(PROJECT).elf" \
		-c "reset run" -c shutdown

debug: all
	arm-none-eabi-gdb $(BUILDDIR)/$(PROJECT).elf
