avr/flake.nix

411 lines
15 KiB
Nix
Raw Permalink Normal View History

2022-04-17 04:43:50 +00:00
{
2022-05-11 23:25:19 +00:00
description = "AVR";
2022-04-17 04:43:50 +00:00
inputs = {
nixpkgs.url = "nixpkgs/nixos-21.11";
};
outputs = { self, nixpkgs }:
let
version = builtins.string 0 8 self.lastModifiedDate;
supportedSystems = [ "x86_64-linux" "avr-none" ];
2022-07-13 03:09:04 +00:00
cflags = { mcu, chip_select, f_cpu }: ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Werror -Wstrict-prototypes -DF_CPU=${f_cpu} -std=gnu99 -D__${chip_select}__=1 -mmcu=${mcu}'';
attiny85 = { mcu = "attiny85"; chip_select = "AVR_ATtiny85"; f_cpu = "8000000"; };
atmega32u4 = { mcu = "atmega32u4"; chip_select = "AVR_ATmega32u4"; f_cpu = "8000000"; };
processor = atmega32u4;
in rec
2022-04-17 04:43:50 +00:00
{
defaultPackage."x86_64-linux" =
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in pkgs.symlinkJoin {
name = "avr-monorepo";
paths = [
2022-07-13 03:09:04 +00:00
(packages."x86_64-linux"."flame" processor)
(packages."x86_64-linux"."prime-tx" processor)
(packages."x86_64-linux"."radio-rx" processor)
2022-07-18 03:19:13 +00:00
(packages."x86_64-linux"."interrupts" processor)
];
};
packages."x86_64-linux"."base-attiny85" = (packages."x86_64-linux"."base" attiny85);
2022-07-13 03:09:04 +00:00
packages."x86_64-linux"."base" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "base";
src = ./.;
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
installPhase = ''
mkdir $out
cp base/base.h $out/
'';
};
packages."x86_64-linux"."rng" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "rng";
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 rng.o -c ${src}/rng/rng.c
'';
installPhase = ''
mkdir $out
cp rng/rng.h rng.o $out/
'';
};
packages."x86_64-linux"."animation" =
2022-07-18 03:19:13 +00:00
{ gcc, mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in pkgs.stdenv.mkDerivation rec {
name = "animation";
src = ./.;
2022-07-18 03:01:27 +00:00
# CFLAGS = cflags { inherit mcu chip_select f_cpu; };
buildPhase = ''
2022-07-18 03:01:27 +00:00
${gcc} -o animation.o -c ${src}/animation/animation.c
'';
installPhase = ''
mkdir $out
cp animation/animation.h animation.o $out/
'';
2022-07-13 03:09:04 +00:00
};
2022-07-18 03:01:27 +00:00
packages."x86_64-linux"."animation-test" =
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
in pkgs.stdenv.mkDerivation rec {
name = "animation-test";
src = ./.;
buildInputs = [
(packages."x86_64-linux"."animation" { inherit gcc; })
];
INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs);
OBJECT_FILES = lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs);
gcc = "${pkgs.gcc}/bin/gcc";
buildPhase = ''
${gcc} ${INCLUDE_DIRS} -o main.o -c ${src}/animation/main.c
${gcc} ${INCLUDE_DIRS} -o animation-test main.o ${OBJECT_FILES}
'';
installPhase = ''
mkdir $out
cp animation-test $out
'';
};
2022-07-13 03:48:51 +00:00
packages."x86_64-linux"."sk9822" =
2022-07-13 03:09:04 +00:00
{ mcu, chip_select, f_cpu }:
2022-04-17 04:43:50 +00:00
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
2022-07-13 03:48:51 +00:00
name = "sk9822";
2022-04-17 04:43:50 +00:00
src = ./.;
2022-07-13 03:48:51 +00:00
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
];
2022-07-13 03:09:04 +00:00
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
2022-07-13 03:48:51 +00:00
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 = ./.;
2022-04-17 04:43:50 +00:00
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
];
2022-07-13 03:48:51 +00:00
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);
2022-04-17 04:43:50 +00:00
buildPhase = ''
2022-07-13 03:48:51 +00:00
${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
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
2022-07-13 03:48:51 +00:00
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "flame";
src = ./.;
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."sk9822" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."rng" { inherit mcu chip_select f_cpu; })
2022-07-18 03:19:13 +00:00
(packages."x86_64-linux"."animation" { inherit mcu chip_select f_cpu;
gcc = "${avr.gcc}/bin/avr-gcc"; })
2022-07-13 03:48:51 +00:00
];
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 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
2022-04-17 04:43:50 +00:00
'';
installPhase = ''
mkdir $out
cp flame.elf flame.hex $out
2022-04-17 04:43:50 +00:00
'';
};
packages."x86_64-linux"."prime-tx" =
2022-07-13 03:09:04 +00:00
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "prime-tx";
src = ./.;
2022-07-13 03:48:51 +00:00
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; })
];
2022-07-13 03:09:04 +00:00
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
2022-07-13 03:48:51 +00:00
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 main.o -c ${src}/prime-tx/main.c
2022-07-13 03:48:51 +00:00
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o prime-tx.elf main.o ${OBJECT_FILES}
$OBJCOPY -O ihex prime-tx.elf prime-tx.hex
'';
installPhase = ''
mkdir $out
cp prime-tx.elf prime-tx.hex $out
'';
};
packages."x86_64-linux"."radio-rx" =
2022-07-13 03:09:04 +00:00
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
2022-07-16 21:31:24 +00:00
name = "radio-rx";
src = ./.;
2022-07-13 03:50:20 +00:00
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; })
];
2022-07-13 03:09:04 +00:00
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
2022-07-13 03:50:20 +00:00
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 main.o -c ${src}/radio-rx/main.c
2022-07-13 03:50:20 +00:00
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o radio-rx.elf main.o ${OBJECT_FILES}
$OBJCOPY -O ihex radio-rx.elf radio-rx.hex
'';
installPhase = ''
mkdir $out
cp radio-rx.elf radio-rx.hex $out
'';
};
2022-07-16 21:31:24 +00:00
packages."x86_64-linux"."interrupts-standalone" = (packages."x86_64-linux"."interrupts" atmega32u4);
packages."x86_64-linux"."interrupts" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "interrupts";
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; })
(packages."x86_64-linux"."display" { 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 main.o -c ${src}/interrupts/main.c
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o interrupts.elf main.o ${OBJECT_FILES}
$OBJCOPY -O ihex interrupts.elf interrupts.hex
'';
installPhase = ''
mkdir $out
cp interrupts.elf interrupts.hex $out
'';
};
2022-04-17 04:43:50 +00:00
devShell."x86_64-linux" =
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = with pkgs.pkgsCross.avr.buildPackages; [
binutils
gcc
2022-05-07 23:49:54 +00:00
gdb
2022-04-17 04:43:50 +00:00
avrdude
2022-05-07 23:49:54 +00:00
simavr
gtkwave
2022-04-17 04:43:50 +00:00
];
in
pkgs.mkShell {
2022-05-11 23:25:19 +00:00
name = "avr-shell";
2022-04-17 04:43:50 +00:00
buildInputs = avr;
2022-05-07 23:49:54 +00:00
2022-05-08 00:16:20 +00:00
GCC = pkgs.pkgsCross.avr.buildPackages.gcc;
SIMAVR = pkgs.pkgsCross.avr.buildPackages.simavr;
2022-04-17 04:43:50 +00:00
};
};
}