152 lines
5.8 KiB
Nix
152 lines
5.8 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" ];
|
|
in
|
|
{
|
|
packages."x86_64-linux"."flame" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
avr = pkgs.pkgsCross.avr.buildPackages;
|
|
in pkgs.stdenv.mkDerivation rec {
|
|
name = "flame";
|
|
src = ./.;
|
|
|
|
MCU = "attiny85";
|
|
CHIP_SELECT = "AVR_ATtiny85";
|
|
F_CPU = "8000000";
|
|
CFLAGS = ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -DF_CPU=${F_CPU} -std=gnu99 -D__${CHIP_SELECT}__=1 -mmcu=${MCU}'';
|
|
|
|
buildPhase = ''
|
|
${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
|
|
$OBJCOPY -O ihex main.elf main.hex
|
|
'';
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp main.elf main.hex $out
|
|
'';
|
|
};
|
|
|
|
packages."x86_64-linux"."morse-tx" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
lib = pkgs.lib;
|
|
avr = pkgs.pkgsCross.avr.buildPackages;
|
|
in pkgs.stdenv.mkDerivation rec {
|
|
name = "morse-tx";
|
|
src = ./.;
|
|
|
|
includes = [ "base" "spi" "morse" "rfm69hcw" ];
|
|
|
|
MCU = "atmega32u4";
|
|
CHIP_SELECT = "AVR_ATmega32u4";
|
|
F_CPU = "8000000";
|
|
CFLAGS = ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -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 morse.o -c ${src}/morse/morse.c
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/morse_tx/main.c
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o main.elf main.o morse.o spi.o rfm.o
|
|
$OBJCOPY -O ihex main.elf main.hex
|
|
'';
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp main.elf main.hex $out
|
|
'';
|
|
};
|
|
|
|
packages."x86_64-linux"."spi_test" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
lib = pkgs.lib;
|
|
avr = pkgs.pkgsCross.avr.buildPackages;
|
|
in pkgs.stdenv.mkDerivation rec {
|
|
name = "spi-test";
|
|
src = ./.;
|
|
|
|
includes = [ "base" "spi" ];
|
|
|
|
MCU = "atmega32u4";
|
|
CHIP_SELECT = "AVR_ATmega32u4";
|
|
F_CPU = "8000000";
|
|
CFLAGS = ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -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 spi.o -c ${src}/spi/spi.c
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/spi_test/main.c
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o main.elf main.o spi.o
|
|
$OBJCOPY -O ihex main.elf main.hex
|
|
'';
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp main.elf main.hex $out
|
|
'';
|
|
};
|
|
|
|
packages."x86_64-linux"."lcd" =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
lib = pkgs.lib;
|
|
avr = pkgs.pkgsCross.avr.buildPackages;
|
|
in pkgs.stdenv.mkDerivation rec {
|
|
name = "lcd";
|
|
src = ./.;
|
|
|
|
includes = [ "base" "shift_register" "spi" ];
|
|
|
|
MCU = "atmega32u4";
|
|
CHIP_SELECT = "AVR_ATmega32u4";
|
|
F_CPU = "8000000";
|
|
CFLAGS = ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -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 base.o -c ${src}/base/base.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/reg.c
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/lcd/main.c
|
|
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o main.elf main.o reg.o spi.o base.o
|
|
$OBJCOPY -O ihex main.elf main.hex
|
|
'';
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp main.elf main.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;
|
|
};
|
|
};
|
|
}
|