166 lines
6.1 KiB
Nix
166 lines
6.1 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" ];
|
|
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
|
|
{
|
|
defaultPackage."x86_64-linux" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
in pkgs.symlinkJoin {
|
|
name = "avr-monorepo";
|
|
paths = [
|
|
(packages."x86_64-linux"."flame" processor)
|
|
(packages."x86_64-linux"."prime-tx" processor)
|
|
(packages."x86_64-linux"."radio-rx" processor)
|
|
];
|
|
};
|
|
|
|
packages."x86_64-linux"."base-attiny85" = (packages."x86_64-linux"."base" attiny85);
|
|
|
|
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; };
|
|
|
|
buildPhase = ''
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o base.o -c ${src}/base/base.c
|
|
'';
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp base/base.h base.o $out/
|
|
'';
|
|
};
|
|
|
|
packages."x86_64-linux"."flame" =
|
|
{ mcu, chip_select, f_cpu }:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
avr = pkgs.pkgsCross.avr.buildPackages;
|
|
in pkgs.stdenv.mkDerivation rec {
|
|
name = "flame";
|
|
src = ./.;
|
|
|
|
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
|
|
|
|
buildInputs = [
|
|
(packages."x86_64-linux"."base" { 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}
|
|
$OBJCOPY -O ihex flame.elf flame.hex
|
|
'';
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp flame.elf flame.hex $out
|
|
'';
|
|
};
|
|
|
|
packages."x86_64-linux"."prime-tx" =
|
|
{ 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 = ./.;
|
|
|
|
includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ];
|
|
|
|
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
|
|
INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${src}/${dir}") includes);
|
|
|
|
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
|
|
$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" =
|
|
{ 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 = ./.;
|
|
|
|
includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ];
|
|
|
|
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
|
|
INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${src}/${dir}") includes);
|
|
|
|
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}/radio-rx/main.c
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o radio-rx.elf main.o display.o spi.o rfm.o reg.o
|
|
$OBJCOPY -O ihex radio-rx.elf radio-rx.hex
|
|
'';
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp radio-rx.elf radio-rx.hex $out
|
|
'';
|
|
};
|
|
|
|
devShell."x86_64-linux" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
avr = with pkgs.pkgsCross.avr.buildPackages; [
|
|
binutils
|
|
gcc
|
|
gdb
|
|
avrdude
|
|
simavr
|
|
gtkwave
|
|
];
|
|
in
|
|
pkgs.mkShell {
|
|
name = "avr-shell";
|
|
buildInputs = avr;
|
|
|
|
GCC = pkgs.pkgsCross.avr.buildPackages.gcc;
|
|
SIMAVR = pkgs.pkgsCross.avr.buildPackages.simavr;
|
|
};
|
|
};
|
|
}
|