342 lines
10 KiB
Nix
342 lines
10 KiB
Nix
{
|
|
description = "AVR";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "nixpkgs/nixos-21.11";
|
|
};
|
|
|
|
outputs = { self, nixpkgs }:
|
|
let
|
|
version = builtins.string 0 8 self.lastModifiedDate;
|
|
supportedSystems = [ "x86_64-linux" "avr-none" ];
|
|
mcu_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;
|
|
|
|
mkLibrary = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [] }:
|
|
pkgs.stdenv.mkDerivation rec {
|
|
name = pname;
|
|
src = psrc;
|
|
|
|
buildInputs = pbuildInputs;
|
|
|
|
include_dirs = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}/include") buildInputs);
|
|
object_files = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs);
|
|
|
|
dontUnpack = true;
|
|
dontConfigure = true;
|
|
|
|
buildPhase = ''
|
|
for source in ${src}/*.c; do
|
|
if [ -e $source ]; then
|
|
${gcc} ${cflags} ${include_dirs} -c $source
|
|
fi
|
|
done
|
|
for source in ${src}/src/*.c; do
|
|
if [ -e $source ]; then
|
|
${gcc} ${cflags} ${include_dirs} -c $source
|
|
fi
|
|
done
|
|
cp ${src}/*.h ${src}/src/*.h . || true
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/include $out/lib
|
|
cp *.h $out/include || true
|
|
cp *.o $out/lib || true
|
|
'';
|
|
};
|
|
|
|
mkProgram = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [], pnativeBuildInputs ? [] }:
|
|
pkgs.stdenv.mkDerivation rec {
|
|
name = pname;
|
|
src = psrc;
|
|
|
|
buildInputs = pbuildInputs;
|
|
nativeBuildInputs = pnativeBuildInputs;
|
|
|
|
include_dirs = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}/include") pbuildInputs);
|
|
object_files = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/lib/*.o") pbuildInputs);
|
|
|
|
dontUnpack = true;
|
|
dontConfigure = true;
|
|
|
|
buildPhase = ''
|
|
for source in ${src}/*.c; do
|
|
if [ -e $source ]; then
|
|
${gcc} ${cflags} ${include_dirs} -c $source
|
|
fi
|
|
done
|
|
|
|
${gcc} -o ${name} ${cflags} ${object_files} *.o
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
cp ${name} $out/bin
|
|
'';
|
|
};
|
|
|
|
mkTests = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [], pnativeBuildInputs ? [] }:
|
|
pkgs.stdenv.mkDerivation rec {
|
|
name = pname;
|
|
src = psrc;
|
|
|
|
buildInputs = pbuildInputs;
|
|
nativeBuildInputs = pnativeBuildInputs;
|
|
|
|
include_dirs = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}/include") buildInputs);
|
|
object_files = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/lib/*.o") buildInputs);
|
|
|
|
dontUnpack = true;
|
|
dontConfigure = true;
|
|
|
|
buildPhase = ''
|
|
for source in ${src}/tests/*.c; do
|
|
if [ -e $source ]; then
|
|
${gcc} ${cflags} ${include_dirs} -c $source
|
|
fi
|
|
done
|
|
|
|
${gcc} -o ${name} ${cflags} ${object_files} *.o
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
cp ${name} $out/bin
|
|
'';
|
|
};
|
|
|
|
in rec
|
|
{
|
|
defaultPackage."x86_64-linux" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
avr = pkgs.pkgsCross.avr.buildPackages;
|
|
in pkgs.symlinkJoin {
|
|
name = "avr-monorepo";
|
|
paths = [
|
|
(packages."x86_64-linux"."prime-tx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; })
|
|
(packages."x86_64-linux"."radio-rx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; })
|
|
(packages."x86_64-linux"."packet-radio" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = "-Wall -Werror"; })
|
|
(packages."x86_64-linux"."packet-radio-tests" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = "-Wall -Werror"; })
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."dio" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "dio";
|
|
psrc = ./dio;
|
|
};
|
|
|
|
packages."x86_64-linux"."rng" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "rng";
|
|
psrc = ./rng;
|
|
};
|
|
|
|
packages."x86_64-linux"."animation" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "animation";
|
|
psrc = ./animation;
|
|
};
|
|
|
|
packages."x86_64-linux"."sk9822" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "sk9822";
|
|
psrc = ./sk9822;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."shift-register" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "shift-register";
|
|
psrc = ./shift-register;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."spi" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "spi";
|
|
psrc = ./spi;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."rfm" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "rfm";
|
|
psrc = ./rfm69hcw;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."display" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "display";
|
|
psrc = ./display;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."packet-radio_" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in packages."x86_64-linux"."packet-radio" { gcc = "${pkgs.gcc}/bin/gcc"; cflags = "-Wall -Werror"; };
|
|
|
|
packages."x86_64-linux"."packet-radio" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkLibrary {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "packet-radio";
|
|
psrc = ./packet-radio;
|
|
pbuildInputs = [ ];
|
|
};
|
|
|
|
packages."x86_64-linux"."packet-radio-tests_" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in packages."x86_64-linux"."packet-radio-tests" { gcc = "${pkgs.gcc}/bin/gcc"; cflags = "-Wall -Werror -lcriterion"; };
|
|
|
|
packages."x86_64-linux"."packet-radio-tests" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkTests {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "packet-radio-tests";
|
|
psrc = ./packet-radio;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."packet-radio" { inherit gcc cflags; })
|
|
];
|
|
pnativeBuildInputs = [
|
|
pkgs.criterion
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."prime-tx" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkProgram {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "prime-tx";
|
|
psrc = ./prime-tx;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."rfm" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."display" { inherit gcc cflags; })
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."radio-rx" =
|
|
{ gcc, cflags }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in mkProgram {
|
|
pkgs = pkgs;
|
|
gcc = gcc;
|
|
cflags = cflags;
|
|
pname = "radio-rx";
|
|
psrc = ./radio-rx;
|
|
pbuildInputs = [
|
|
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."rfm" { inherit gcc cflags; })
|
|
(packages."x86_64-linux"."display" { inherit gcc cflags; })
|
|
];
|
|
};
|
|
|
|
devShell."x86_64-linux" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
avr = with pkgs.pkgsCross.avr.buildPackages; [
|
|
binutils
|
|
gcc
|
|
gdb
|
|
avrdude
|
|
simavr
|
|
gtkwave
|
|
criterion
|
|
];
|
|
in
|
|
pkgs.mkShell {
|
|
name = "avr-shell";
|
|
buildInputs = avr;
|
|
|
|
GCC = pkgs.pkgsCross.avr.buildPackages.gcc;
|
|
SIMAVR = pkgs.pkgsCross.avr.buildPackages.simavr;
|
|
};
|
|
};
|
|
}
|