diff --git a/base/src/base.c b/base/base.c similarity index 62% rename from base/src/base.c rename to base/base.c index fc30f2e..2e37f0a 100644 --- a/base/src/base.c +++ b/base/base.c @@ -1,9 +1,8 @@ -#include "../base.h" - - +#include "base.h" rng_t rng_new(uint8_t seed) { - return { .mod = 255, .a = 253, .c = 41, .seed = seed }; + rng_t rng = { .mod = 255, .a = 253, .c = 41, .seed = seed }; + return rng; } uint8_t rng_sample(rng_t *state) { diff --git a/base/include/base.h b/base/base.h similarity index 95% rename from base/include/base.h rename to base/base.h index 7ec9502..c44c208 100644 --- a/base/include/base.h +++ b/base/base.h @@ -1,3 +1,4 @@ +#include #ifndef __BASE_H__ #define __BASE_H__ diff --git a/flake.nix b/flake.nix index b9ba0c2..664c77e 100644 --- a/flake.nix +++ b/flake.nix @@ -11,21 +11,6 @@ supportedSystems = [ "x86_64-linux" "avr-none" ]; in { - /* - packages.base."x86_64-linux" = - let pkgs = import nixpkgs { system = "x86_64-linux"; }; - in pkgs.stdenv.mkDerivation rec { - name = "wearables-base"; - src = "./base"; - - installPhase = '' - mkdir -p $out/include - cp include/base.h $out/include - ''; - }; - */ - - /* defaultPackage."x86_64-linux" = let pkgs = import nixpkgs { system = "x86_64-linux"; }; @@ -41,7 +26,11 @@ buildPhase = '' set -x - ${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base/include/ -o main.elf ${src}/prototype/src/main.c + + ${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base -o base.o -c ${src}/base/base.c + ${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base -o sk9822.o -c ${src}/sk9822/sk9822.c + ${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base -I${src}/sk9822 -o main.o -c ${src}/flame/main.c + ${avr.gcc}/bin/avr-gcc ${CFLAGS} -o main.elf main.o sk9822.o base.o $OBJCOPY -O ihex main.elf main.hex ''; installPhase = '' @@ -49,7 +38,6 @@ cp main.elf main.hex $out ''; }; - */ devShell."x86_64-linux" = let @@ -67,8 +55,8 @@ name = "Wearables-shell"; buildInputs = avr; - GCC="${pkgs.pkgsCross.avr.buildPackages.gcc}"; - AVR="${pkgs.avrlibc}"; + GCC = pkgs.pkgsCross.avr.buildPackages.gcc; + SIMAVR = pkgs.pkgsCross.avr.buildPackages.simavr; }; }; } diff --git a/sk9822/main.c b/flame/main.c similarity index 98% rename from sk9822/main.c rename to flame/main.c index fff6fe0..23b2fef 100644 --- a/sk9822/main.c +++ b/flame/main.c @@ -2,7 +2,7 @@ #include #include -#include "sk9822.h" +#include uint8_t random_step(uint8_t value, uint8_t min, uint8_t max, rng_t *rng) { int8_t step = (rng_sample(rng) % 32) - 16; diff --git a/sk9822/Makefile b/sk9822/Makefile index 12252bf..001ea30 100644 --- a/sk9822/Makefile +++ b/sk9822/Makefile @@ -9,15 +9,20 @@ OBJECTS= main.o \ .SUFFIXES: .c .o .h -%.o: %.c %.h - ${GCC}/bin/avr-gcc ${CFLAGS} ${AVR}/avr/include -I../base/include/ -o $@ -c $< + +# /nix/store/fymsi5yk07jvcbdaka6nfhx6s2a7kgpi-avr-stage-final-gcc-debug-wrapper-10.3.0/bin/avr-gcc -O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -DF_CPU=8000000 -std=gnu99 -D__AVR_ATtiny85__=1 -mmcu=attiny85 -I../base/include/ -E -o main.E src/main.c + main: main.o sk9822.o # ${GCC}/bin/avr-gcc ${CFLAGS} -I../base/include/ -E -o main.E src/main.c # ${GCC}/bin/avr-gcc ${CFLAGS} -I../base/include/ -S -o main.S src/main.c + echo ${GCC} ${GCC}/bin/avr-gcc ${CFLAGS} ${LINKFLAGS} -I../base/include/ -o main.elf main.o sk9822.o ${OBJCOPY} -O ihex main.elf main.hex +%.o: %.c %.h + ${GCC}/bin/avr-gcc ${CFLAGS} -I../base/include/ -o $@ -c $< + clean: rm *.o make.elf main.hex main.S main.E diff --git a/sk9822/sk9822.c b/sk9822/sk9822.c index 4d5d6b8..4505bcc 100644 --- a/sk9822/sk9822.c +++ b/sk9822/sk9822.c @@ -1,3 +1,5 @@ +#include "sk9822.h" + void send_byte(io_pin_t data_pin, io_pin_t clock_pin, uint8_t byte) { for (int i = 7; i >= 0; i--) { if (byte & _BV(i)) { diff --git a/sk9822/sk9822.h b/sk9822/sk9822.h index 8357537..b9148da 100644 --- a/sk9822/sk9822.h +++ b/sk9822/sk9822.h @@ -1,4 +1,8 @@ #include +#include + +#ifndef __SK9822_H__ +#define __SK9822_H__ typedef struct RGB_s { uint8_t brightness; @@ -8,3 +12,5 @@ typedef struct RGB_s { } rgb_t; void send_pixels(io_pin_t data_pin, io_pin_t clock_pin, rgb_t *pixels, uint8_t count); + +#endif