diff --git a/.gitignore b/.gitignore index abb89c0..f535e6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -cmake-build-debug/* +cmake-build-debug-avr/* .idea/* main.bin main.hex diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5dd0ea8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.21) +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_C_STANDARD 99) +project(vfdprog C) + +set(CMAKE_C_COMPILER avr-gcc) +set(OBJCOPY avr-objcopy) +set(TARGET_CPU atmega88) + +add_compile_definitions("__AVR_${TARGET_CPU}__" "F_CPU=8000000UL") +include_directories(/usr/lib/avr/include) +set(CMAKE_C_FLAGS "-Os -mcall-prologues -mmcu=${TARGET_CPU} -Wall") + +add_link_options(-Wl,--print-memory-usage) +add_executable(${PROJECT_NAME}.bin main.c PT6302.c PT6302.h) + +add_custom_target( + FLASH + ${OBJCOPY} -j .text -j .data -O ihex ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex && + avrdude -p ${TARGET_CPU} -c USBasp -v -U flash:w:${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex:a + DEPENDS ${PROJECT_NAME}.bin + COMMENT "Flash to ${TARGET_CPU}" +) \ No newline at end of file diff --git a/Makefile b/Makefile index 09d561b..7da58e6 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,11 @@ OBJCOPY=avr-objcopy CFLAGS=-std=c99 -Wall -g -Os -mcall-prologues -mmcu=${MCU} -DF_CPU=${F_CPU} -I/usr/lib/avr/include/ TARGET=main SRCS=main.c PT6302.c PT6302.h - + all: ${CC} ${CFLAGS} -o ${TARGET}.bin ${SRCS} - ${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex - + ${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex + flash: avrdude -p ${MCU} -c usbasp -U flash:w:${TARGET}.hex:i -F -P usb diff --git a/PT6302.c b/PT6302.c index f0db39f..527d5cc 100644 --- a/PT6302.c +++ b/PT6302.c @@ -17,7 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA */ -#define F_CPU 8000000UL #include #include #include "PT6302.h"