avr-something

Something something AVR side…
git clone git://henryandlizzy.uk/avr-something
Log | Files | Refs | README

commit 9a85f431e72420a3bce50d333d1fb8bc15671bfd
Author: Henry Wilson <m3henry@googlemail.com>
Date:   Fri,  2 Feb 2018 01:18:04 +0000

initial commit

Diffstat:
A.gitignore | 5+++++
AREADME.md | 7+++++++
Abinary.s | 15+++++++++++++++
Aio.h | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aled-test.cpp | 13+++++++++++++
Aled.cpp | 7+++++++
Aled.h | 3+++
Amakefile | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Api.txt | 1+
9 files changed, 177 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,5 @@ +*.o +*.d + +*.elf +*.hex diff --git a/README.md b/README.md @@ -0,0 +1,7 @@ +## AVR-??? + +So far this is just a playground + +- [x] Super cool makefile +- [x] Uses C++17 +- [ ] Everything else??? diff --git a/binary.s b/binary.s @@ -0,0 +1,15 @@ +.macro usefile name:req file:req +.section .text.\name + +.global \name\()_size +.global \name\()_begin +.global \name\()_end + +\name\()_size: + .short \name\()_end - \name\()_begin +\name\()_begin: + .incbin "\file" +\name\()_end: +.endm + + usefile pi "pi.txt" diff --git a/io.h b/io.h @@ -0,0 +1,69 @@ +#pragma once +#include <inttypes.h> + +template <typename T = uint8_t> +constexpr T volatile& memory(uintptr_t addr) +{ + return *reinterpret_cast<T*>(addr); +} + +namespace io +{ +namespace pin +{ + constexpr auto& A() + { + return memory(0x20); + } + constexpr auto& B() + { + return memory(0x23); + } + constexpr auto& C() + { + return memory(0x26); + } + constexpr auto& D() + { + return memory(0x29); + } +} +namespace direction +{ + constexpr auto& A() + { + return memory(0x21); + } + constexpr auto& B() + { + return memory(0x24); + } + constexpr auto& C() + { + return memory(0x27); + } + constexpr auto& D() + { + return memory(0x2A); + } +} +namespace out +{ + constexpr auto& A() + { + return memory(0x22); + } + constexpr auto& B() + { + return memory(0x25); + } + constexpr auto& C() + { + return memory(0x28); + } + constexpr auto& D() + { + return memory(0x2B); + } +} +} diff --git a/led-test.cpp b/led-test.cpp @@ -0,0 +1,13 @@ +#include "led.h" +#include "io.h" +#include <util/delay.h> + +int main(void) +{ + io::direction::B() |= 0x80; + for(;;) + { + blink(); + _delay_ms(333); + } +} diff --git a/led.cpp b/led.cpp @@ -0,0 +1,7 @@ +#include "led.h" +#include "io.h" + +void blink(void) +{ + io::pin::B() |= 0x80; +} diff --git a/led.h b/led.h @@ -0,0 +1,3 @@ +#pragma once + +void blink(); diff --git a/makefile b/makefile @@ -0,0 +1,57 @@ +CC = avr-gcc +CFLAGS = -Os -DF_CPU=12000000 -flto +CPPFLAGS = -std=c++17 +TARGET_ARCH = -mmcu=atmega644p + +DEPFLAGS = -MT $@ -MMD -MP -MF .$*.d + +COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c + +# Create our phony targets to avoid files interfering +.PHONY: clean install + +# Generate a list of sources and objects +C_SOURCES = $(wildcard *.c) +CPP_SOURCES = $(wildcard *.cpp) +ASM_SOURCES = $(wildcard *.s) +OBJECTS = $(C_SOURCES:%.c=.%.o) $(CPP_SOURCES:%.cpp=.%.o) $(ASM_SOURCES:%.s=.%.o) + +program.hex: program.elf + @ avr-objcopy -O ihex program.elf program.hex + +# The final target, with dependancies generated from the sources list +program.elf: $(OBJECTS) + @ $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -Wl,--gc-sections -o $@ $^ + +# The install target +install: program.hex + @ avrdude -c usbasp -p m644p -U $< + +# Clean up everything that we generate +clean: + @ rm -f program.hex program.elf .*.o .*.d + +# Delete the built-in rules for building object files from .c files... +%.o : %.c +# ...so that our rule is used instead. +.%.o : %.c .%.d makefile + @ $(COMPILE.c) $(OUTPUT_OPTION) $< + +%.o : %.cpp +.%.o : %.cpp .%.d makefile + @ $(COMPILE.c) $(OUTPUT_OPTION) $< + +%.o : %.s +.%.o : %.s .%.d makefile + @ avr-as --MD .$*.d -c -o $@ $< + +# Create a pattern rule with an empty recipe, so that +# `make` won’t fail if the dependency file doesn’t exist. +.%.d: ; + +# Mark the dependency files precious, so they won’t be +# automatically deleted as intermediate files. +.PRECIOUS: .%.d + +# Include all of the dependency files +include $(wildcard .*.d) diff --git a/pi.txt b/pi.txt @@ -0,0 +1 @@ +pi = 3.14126979