From 94efdbb1c3d27c3b82e3e577b9220bf6c987fe71 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 13 Jul 2022 00:13:05 -0400 Subject: [PATCH] Improve the API for sk9822 --- display/display.c | 6 +++--- flake.nix | 40 +++++++++++++++++++++++++--------------- flame/main.c | 8 +++++--- lantern/main.c | 18 ++++++++++++++++++ sk9822/sk9822.c | 14 +++++++------- sk9822/sk9822.h | 13 +++++++++---- 6 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 lantern/main.c diff --git a/display/display.c b/display/display.c index acd851a..fce6f94 100644 --- a/display/display.c +++ b/display/display.c @@ -3,11 +3,11 @@ Copyright 2022, Savanni D'Gerinel This file is part of Savanni's AVR library. -Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with Lumeto. If not, see . +You should have received a copy of the GNU General Public License along with this AVR library. If not, see . */ #include diff --git a/flake.nix b/flake.nix index ebb44c3..0e90d64 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,6 @@ attiny85 = { mcu = "attiny85"; chip_select = "AVR_ATtiny85"; f_cpu = "8000000"; }; atmega32u4 = { mcu = "atmega32u4"; chip_select = "AVR_ATmega32u4"; f_cpu = "8000000"; }; - processor = atmega32u4; mkLibrary = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [] }: pkgs.stdenv.mkDerivation rec { @@ -73,7 +72,6 @@ ''; }; - in rec { defaultPackage."x86_64-linux" = @@ -85,22 +83,10 @@ paths = [ (packages."x86_64-linux"."prime-tx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; }) (packages."x86_64-linux"."radio-rx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; }) + (packages."x86_64-linux"."lantern" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; }) ]; }; - /* packages."x86_64-linux"."dio-attiny85" = (packages."x86_64-linux"."dio" attiny85); */ - - /* - packages."x86_64-linux"."dio" = - let - pkgs = import nixpkgs { system = "x86_64-linux"; }; - in mkLibrary { - mkDerivation = pkgs.stdenv.mkDerivation; - gcc = - cflags = - name = - */ - packages."x86_64-linux"."dio" = { gcc, cflags }: let @@ -252,6 +238,30 @@ ]; }; + packages."x86_64-linux"."lantern_" = + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + avr = pkgs.pkgsCross.avr.buildPackages; + in packages."x86_64-linux"."lantern" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; }; + packages."x86_64-linux"."lantern" = + { gcc, cflags }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + in mkProgram { + pkgs = pkgs; + gcc = gcc; + cflags = cflags; + pname = "lantern"; + psrc = ./lantern; + + pbuildInputs = [ + (packages."x86_64-linux"."dio" { inherit gcc cflags; }) + (packages."x86_64-linux"."shift-register" { inherit gcc cflags; }) + (packages."x86_64-linux"."display" { inherit gcc cflags; }) + (packages."x86_64-linux"."sk9822" { inherit gcc cflags; }) + ]; + }; + devShell."x86_64-linux" = let pkgs = import nixpkgs { system = "x86_64-linux"; }; diff --git a/flame/main.c b/flame/main.c index d15d79d..27d0bfc 100644 --- a/flame/main.c +++ b/flame/main.c @@ -88,14 +88,16 @@ int main (void) { PORTB = 0; _delay_ms(50); - dio_t data_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 0 }; - dio_t clock_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 }; + sk9822_t lights = { + .data_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 0 }, + .clock_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 } + }; rng_t rng = rng_new(0); animation_t animation = animation_new(); while (1) { animation_step(&animation, &rng); - send_pixels(data_pin, clock_pin, &animation.lamp, 1); + sk9822_send(&lights, &animation.lamp, 1); _delay_ms(FRAME_DELAY_MS); } } diff --git a/lantern/main.c b/lantern/main.c new file mode 100644 index 0000000..ff25e46 --- /dev/null +++ b/lantern/main.c @@ -0,0 +1,18 @@ +/* +Copyright 2022, Savanni D'Gerinel + +This file is part of Savanni's AVR library. + +This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this AVR library. If not, see . +*/ + +#include +#include + +int main(void) { + return 0; +} diff --git a/sk9822/sk9822.c b/sk9822/sk9822.c index 84e25de..544b381 100644 --- a/sk9822/sk9822.c +++ b/sk9822/sk9822.c @@ -35,13 +35,13 @@ void send_term(dio_t data_pin, dio_t clock_pin) { send_byte(data_pin, clock_pin, 0xff); } -void send_pixels(dio_t data_pin, dio_t clock_pin, rgb_t * pixels, uint8_t count) { - send_start(data_pin, clock_pin); +void sk9822_send(sk9822_t *lights, rgb_t * pixels, uint8_t count) { + send_start(lights->data_pin, lights->clock_pin); for (uint8_t i = 0; i < count; i++) { - send_byte(data_pin, clock_pin, 0xe0 + pixels[i].brightness); - send_byte(data_pin, clock_pin, pixels[i].r); - send_byte(data_pin, clock_pin, pixels[i].b); - send_byte(data_pin, clock_pin, pixels[i].g); + send_byte(lights->data_pin, lights->clock_pin, 0xe0 + pixels[i].brightness); + send_byte(lights->data_pin, lights->clock_pin, pixels[i].r); + send_byte(lights->data_pin, lights->clock_pin, pixels[i].b); + send_byte(lights->data_pin, lights->clock_pin, pixels[i].g); } - send_term(data_pin, clock_pin); + send_term(lights->data_pin, lights->clock_pin); } diff --git a/sk9822/sk9822.h b/sk9822/sk9822.h index 67e18c2..bb4c3f6 100644 --- a/sk9822/sk9822.h +++ b/sk9822/sk9822.h @@ -3,11 +3,11 @@ Copyright 2022, Savanni D'Gerinel This file is part of Savanni's AVR library. -Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with Lumeto. If not, see . +You should have received a copy of the GNU General Public License along with this AVR library. If not, see . */ #include @@ -23,6 +23,11 @@ typedef struct RGB_s { uint8_t b; } rgb_t; -void send_pixels(dio_t data_pin, dio_t clock_pin, rgb_t *pixels, uint8_t count); +typedef struct SK9822 { + dio_t data_pin; + dio_t clock_pin; +} sk9822_t; + +void sk9822_send(sk9822_t *lights, rgb_t *pixels, uint8_t count); #endif