diff --git a/display/display.c b/display/display.c index 615d89f..54195c1 100644 --- a/display/display.c +++ b/display/display.c @@ -10,11 +10,12 @@ Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRAN You should have received a copy of the GNU General Public License along with Lumeto. If not, see . */ -#include -#include -#include #include #include +#include +#include + +#include "display.h" #define ENABLE _BV(5) #define CHARCODE _BV(4) diff --git a/flake.nix b/flake.nix index cc38445..3547a5c 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,138 @@ ''; }; + packages."x86_64-linux"."sk9822" = + { mcu, chip_select, f_cpu }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + avr = pkgs.pkgsCross.avr.buildPackages; + in pkgs.stdenv.mkDerivation rec { + name = "sk9822"; + src = ./.; + + buildInputs = [ + (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) + ]; + + CFLAGS = cflags { inherit mcu chip_select f_cpu; }; + INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); + OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); + + buildPhase = '' + ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o sk9822.o -c ${src}/sk9822/sk9822.c + ''; + installPhase = '' + mkdir $out + cp sk9822/sk9822.h sk9822.o $out/ + ''; + }; + + packages."x86_64-linux"."shift-register" = + { mcu, chip_select, f_cpu }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + avr = pkgs.pkgsCross.avr.buildPackages; + in pkgs.stdenv.mkDerivation rec { + name = "shift-register"; + src = ./.; + + buildInputs = [ + (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) + ]; + + CFLAGS = cflags { inherit mcu chip_select f_cpu; }; + INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); + OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); + + buildPhase = '' + ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o shift_register.o -c ${src}/shift_register/shift_register.c + ''; + installPhase = '' + mkdir $out + cp shift_register/shift_register.h shift_register.o $out/ + ''; + }; + + packages."x86_64-linux"."spi" = + { mcu, chip_select, f_cpu }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + avr = pkgs.pkgsCross.avr.buildPackages; + in pkgs.stdenv.mkDerivation rec { + name = "spi"; + src = ./.; + + buildInputs = [ + (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) + ]; + + CFLAGS = cflags { inherit mcu chip_select f_cpu; }; + INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); + OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); + + buildPhase = '' + ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o spi.o -c ${src}/spi/spi.c + ''; + installPhase = '' + mkdir $out + cp spi/spi.h spi.o $out/ + ''; + }; + + packages."x86_64-linux"."rfm" = + { mcu, chip_select, f_cpu }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + avr = pkgs.pkgsCross.avr.buildPackages; + in pkgs.stdenv.mkDerivation rec { + name = "rfm"; + src = ./.; + + buildInputs = [ + (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) + (packages."x86_64-linux"."spi" { inherit mcu chip_select f_cpu; }) + ]; + + CFLAGS = cflags { inherit mcu chip_select f_cpu; }; + INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); + OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); + + buildPhase = '' + ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o rfm.o -c ${src}/rfm69hcw/rfm.c + ''; + installPhase = '' + mkdir $out + cp rfm69hcw/rfm.h rfm.o $out/ + ''; + }; + + packages."x86_64-linux"."display" = + { mcu, chip_select, f_cpu }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + avr = pkgs.pkgsCross.avr.buildPackages; + in pkgs.stdenv.mkDerivation rec { + name = "display"; + src = ./.; + + buildInputs = [ + (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) + (packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; }) + ]; + + CFLAGS = cflags { inherit mcu chip_select f_cpu; }; + INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); + OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); + + buildPhase = '' + ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o display.o -c ${src}/display/display.c + ''; + installPhase = '' + mkdir $out + cp display/display.h display.o $out/ + ''; + }; + packages."x86_64-linux"."flame" = { mcu, chip_select, f_cpu }: let @@ -59,21 +191,18 @@ name = "flame"; src = ./.; - CFLAGS = cflags { inherit mcu chip_select f_cpu; }; - buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) + (packages."x86_64-linux"."sk9822" { inherit mcu chip_select f_cpu; }) ]; + CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' - set -x - echo Object files: ${OBJECT_FILES} - ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o sk9822.o -c ${src}/sk9822/sk9822.c - ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -I${src}/sk9822 -o main.o -c ${src}/flame/main.c - ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o flame.elf main.o sk9822.o ${OBJECT_FILES} + ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/flame/main.c + ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o flame.elf main.o ${OBJECT_FILES} $OBJCOPY -O ihex flame.elf flame.hex ''; installPhase = '' @@ -92,18 +221,24 @@ name = "prime-tx"; src = ./.; - includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ]; + # includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ]; + + buildInputs = [ + (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) + (packages."x86_64-linux"."spi" { inherit mcu chip_select f_cpu; }) + (packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; }) + (packages."x86_64-linux"."rfm" { inherit mcu chip_select f_cpu; }) + (packages."x86_64-linux"."display" { inherit mcu chip_select f_cpu; }) + ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; - INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${src}/${dir}") includes); + INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); + OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); + buildPhase = '' - ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o rfm.o -c ${src}/rfm69hcw/rfm.c - ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o spi.o -c ${src}/spi/spi.c - ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o reg.o -c ${src}/shift_register/shift_register.c - ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o display.o -c ${src}/display/display.c ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/prime-tx/main.c - ${avr.gcc}/bin/avr-gcc ${CFLAGS} -o prime-tx.elf main.o display.o spi.o rfm.o reg.o + ${avr.gcc}/bin/avr-gcc ${CFLAGS} -o prime-tx.elf main.o ${OBJECT_FILES} $OBJCOPY -O ihex prime-tx.elf prime-tx.hex ''; installPhase = '' diff --git a/rfm69hcw/rfm.c b/rfm69hcw/rfm.c index ebd1c2a..a89dd42 100644 --- a/rfm69hcw/rfm.c +++ b/rfm69hcw/rfm.c @@ -11,8 +11,8 @@ You should have received a copy of the GNU General Public License along with Lum */ -#include #include +#include "rfm.h" #define REG_FIFO 0x00 #define REG_OP_MODE 0x01 diff --git a/rfm69hcw/rfm.h b/rfm69hcw/rfm.h index 5b94ccd..d786627 100644 --- a/rfm69hcw/rfm.h +++ b/rfm69hcw/rfm.h @@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License along with Lum #include #include #include -#include typedef enum RFM_ERROR_TYPES { Ok, diff --git a/shift_register/shift_register.c b/shift_register/shift_register.c index 50d12ec..ce99177 100644 --- a/shift_register/shift_register.c +++ b/shift_register/shift_register.c @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with Lum #include #include -#include +#include "shift_register.h" void sr_strobe_line(dio_t *line) { dio_set(line, 1); diff --git a/spi/spi.c b/spi/spi.c index c9f3855..ac3d4ed 100644 --- a/spi/spi.c +++ b/spi/spi.c @@ -11,8 +11,8 @@ You should have received a copy of the GNU General Public License along with Lum */ -#include #include +#include "spi.h" void spi_initialize(spi_t *spi) { dio_set_direction(&spi->clock, LINE_OUT);