avr/flake.nix

125 lines
4.9 KiB
Nix
Raw 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" ];
in
{
2022-05-11 23:25:19 +00:00
packages."x86_64-linux"."flame" =
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-05-11 23:25:19 +00:00
name = "flame";
2022-04-17 04:43:50 +00:00
src = ./.;
MCU = "attiny85";
CHIP_SELECT = "AVR_ATtiny85";
F_CPU = "8000000";
2022-06-28 00:05:01 +00:00
CFLAGS = ''-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}'';
2022-04-17 04:43:50 +00:00
buildPhase = ''
2022-05-08 00:16:20 +00:00
${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
2022-04-17 04:43:50 +00:00
$OBJCOPY -O ihex main.elf main.hex
'';
installPhase = ''
mkdir $out
cp main.elf main.hex $out
'';
};
packages."x86_64-linux"."prime-tx" =
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" ];
MCU = "atmega32u4";
CHIP_SELECT = "AVR_ATmega32u4";
F_CPU = "8000000";
2022-06-28 00:05:01 +00:00
CFLAGS = ''-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} -DAVR=1'';
INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${src}/${dir}") includes);
buildPhase = ''
2022-06-26 15:51:40 +00:00
${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 main.elf main.o display.o spi.o rfm.o reg.o
$OBJCOPY -O ihex main.elf main.hex
'';
installPhase = ''
mkdir $out
cp main.elf main.hex $out
'';
};
packages."x86_64-linux"."radio-rx" =
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" ];
MCU = "atmega32u4";
CHIP_SELECT = "AVR_ATmega32u4";
F_CPU = "8000000";
CFLAGS = ''-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} -DAVR=1'';
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 main.elf main.o display.o spi.o rfm.o reg.o
$OBJCOPY -O ihex main.elf main.hex
'';
installPhase = ''
mkdir $out
cp main.elf main.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
};
};
}