Build up libraries for prime-tx

This commit is contained in:
Savanni D'Gerinel 2022-07-12 23:48:51 -04:00
parent 53651c161b
commit c80db33d02
6 changed files with 156 additions and 21 deletions

View File

@ -10,11 +10,12 @@ Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRAN
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>. You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
#include <display.h>
#include <util/delay.h>
#include <base.h> #include <base.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <util/delay.h>
#include "display.h"
#define ENABLE _BV(5) #define ENABLE _BV(5)
#define CHARCODE _BV(4) #define CHARCODE _BV(4)

163
flake.nix
View File

@ -50,6 +50,138 @@
''; '';
}; };
packages."x86_64-linux"."sk9822" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "sk9822";
src = ./.;
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
];
CFLAGS = cflags { 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 = ''
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o sk9822.o -c ${src}/sk9822/sk9822.c
'';
installPhase = ''
mkdir $out
cp sk9822/sk9822.h sk9822.o $out/
'';
};
packages."x86_64-linux"."shift-register" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "shift-register";
src = ./.;
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
];
CFLAGS = cflags { 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 = ''
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o shift_register.o -c ${src}/shift_register/shift_register.c
'';
installPhase = ''
mkdir $out
cp shift_register/shift_register.h shift_register.o $out/
'';
};
packages."x86_64-linux"."spi" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "spi";
src = ./.;
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
];
CFLAGS = cflags { 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 = ''
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o spi.o -c ${src}/spi/spi.c
'';
installPhase = ''
mkdir $out
cp spi/spi.h spi.o $out/
'';
};
packages."x86_64-linux"."rfm" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "rfm";
src = ./.;
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."spi" { inherit mcu chip_select f_cpu; })
];
CFLAGS = cflags { 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 = ''
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o rfm.o -c ${src}/rfm69hcw/rfm.c
'';
installPhase = ''
mkdir $out
cp rfm69hcw/rfm.h rfm.o $out/
'';
};
packages."x86_64-linux"."display" =
{ mcu, chip_select, f_cpu }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "display";
src = ./.;
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; })
];
CFLAGS = cflags { 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 = ''
${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o display.o -c ${src}/display/display.c
'';
installPhase = ''
mkdir $out
cp display/display.h display.o $out/
'';
};
packages."x86_64-linux"."flame" = packages."x86_64-linux"."flame" =
{ mcu, chip_select, f_cpu }: { mcu, chip_select, f_cpu }:
let let
@ -59,21 +191,18 @@
name = "flame"; name = "flame";
src = ./.; src = ./.;
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
buildInputs = [ buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."sk9822" { inherit mcu chip_select f_cpu; })
]; ];
CFLAGS = cflags { inherit mcu chip_select f_cpu; };
INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs);
OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs);
buildPhase = '' buildPhase = ''
set -x ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/flame/main.c
echo Object files: ${OBJECT_FILES} ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o flame.elf main.o ${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 $OBJCOPY -O ihex flame.elf flame.hex
''; '';
installPhase = '' installPhase = ''
@ -92,18 +221,24 @@
name = "prime-tx"; name = "prime-tx";
src = ./.; src = ./.;
includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ]; # includes = [ "base" "spi" "shift_register" "rfm69hcw" "display" ];
buildInputs = [
(packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."spi" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."rfm" { inherit mcu chip_select f_cpu; })
(packages."x86_64-linux"."display" { inherit mcu chip_select f_cpu; })
];
CFLAGS = cflags { inherit mcu chip_select f_cpu; }; CFLAGS = cflags { inherit mcu chip_select f_cpu; };
INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${src}/${dir}") includes); INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs);
OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs);
buildPhase = '' 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} ${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 ${avr.gcc}/bin/avr-gcc ${CFLAGS} -o prime-tx.elf main.o ${OBJECT_FILES}
$OBJCOPY -O ihex prime-tx.elf prime-tx.hex $OBJCOPY -O ihex prime-tx.elf prime-tx.hex
''; '';
installPhase = '' installPhase = ''

View File

@ -11,8 +11,8 @@ You should have received a copy of the GNU General Public License along with Lum
*/ */
#include <rfm.h>
#include <stdio.h> #include <stdio.h>
#include "rfm.h"
#define REG_FIFO 0x00 #define REG_FIFO 0x00
#define REG_OP_MODE 0x01 #define REG_OP_MODE 0x01

View File

@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License along with Lum
#include <base.h> #include <base.h>
#include <spi.h> #include <spi.h>
#include <stdbool.h> #include <stdbool.h>
#include <display.h>
typedef enum RFM_ERROR_TYPES { typedef enum RFM_ERROR_TYPES {
Ok, Ok,

View File

@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with Lum
#include <util/delay.h> #include <util/delay.h>
#include <base.h> #include <base.h>
#include <shift_register.h> #include "shift_register.h"
void sr_strobe_line(dio_t *line) { void sr_strobe_line(dio_t *line) {
dio_set(line, 1); dio_set(line, 1);

View File

@ -11,8 +11,8 @@ You should have received a copy of the GNU General Public License along with Lum
*/ */
#include <spi.h>
#include <util/delay.h> #include <util/delay.h>
#include "spi.h"
void spi_initialize(spi_t *spi) { void spi_initialize(spi_t *spi) {
dio_set_direction(&spi->clock, LINE_OUT); dio_set_direction(&spi->clock, LINE_OUT);