Parameterize processor settings

This commit is contained in:
Savanni D'Gerinel 2022-07-12 23:09:04 -04:00
parent 6787d7484e
commit 6c02253868
1 changed files with 27 additions and 15 deletions

View File

@ -9,6 +9,11 @@
let let
version = builtins.string 0 8 self.lastModifiedDate; version = builtins.string 0 8 self.lastModifiedDate;
supportedSystems = [ "x86_64-linux" "avr-none" ]; 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 in rec
{ {
defaultPackage."x86_64-linux" = defaultPackage."x86_64-linux" =
@ -17,13 +22,27 @@
in pkgs.symlinkJoin { in pkgs.symlinkJoin {
name = "avr-monorepo"; name = "avr-monorepo";
paths = [ paths = [
packages."x86_64-linux"."flame" (packages."x86_64-linux"."flame" processor)
packages."x86_64-linux"."prime-tx" (packages."x86_64-linux"."prime-tx" processor)
packages."x86_64-linux"."radio-rx" (packages."x86_64-linux"."radio-rx" processor)
]; ];
}; };
/*
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 = ./.;
};
*/
packages."x86_64-linux"."flame" = packages."x86_64-linux"."flame" =
{ mcu, chip_select, f_cpu }:
let let
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages; avr = pkgs.pkgsCross.avr.buildPackages;
@ -31,10 +50,7 @@
name = "flame"; name = "flame";
src = ./.; src = ./.;
MCU = "attiny85"; CFLAGS = cflags { inherit mcu chip_select f_cpu; };
CHIP_SELECT = "AVR_ATtiny85";
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}'';
buildPhase = '' 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 base.o -c ${src}/base/base.c
@ -50,6 +66,7 @@
}; };
packages."x86_64-linux"."prime-tx" = packages."x86_64-linux"."prime-tx" =
{ mcu, chip_select, f_cpu }:
let let
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib; lib = pkgs.lib;
@ -60,10 +77,7 @@
includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ]; includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ];
MCU = "atmega32u4"; CFLAGS = cflags { inherit mcu chip_select f_cpu; };
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); INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${src}/${dir}") includes);
buildPhase = '' buildPhase = ''
@ -82,6 +96,7 @@
}; };
packages."x86_64-linux"."radio-rx" = packages."x86_64-linux"."radio-rx" =
{ mcu, chip_select, f_cpu }:
let let
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib; lib = pkgs.lib;
@ -92,10 +107,7 @@
includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ]; includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ];
MCU = "atmega32u4"; CFLAGS = cflags { inherit mcu chip_select f_cpu; };
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); INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${src}/${dir}") includes);
buildPhase = '' buildPhase = ''