Improve the API for sk9822

This commit is contained in:
Savanni D'Gerinel 2022-07-13 00:13:05 -04:00
parent 4f778b79d3
commit 94efdbb1c3
6 changed files with 67 additions and 32 deletions

View File

@ -3,11 +3,11 @@ Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Savanni's AVR library. 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 <https://www.gnu.org/licenses/>. You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <dio.h> #include <dio.h>

View File

@ -13,7 +13,6 @@
attiny85 = { mcu = "attiny85"; chip_select = "AVR_ATtiny85"; f_cpu = "8000000"; }; attiny85 = { mcu = "attiny85"; chip_select = "AVR_ATtiny85"; f_cpu = "8000000"; };
atmega32u4 = { mcu = "atmega32u4"; chip_select = "AVR_ATmega32u4"; f_cpu = "8000000"; }; atmega32u4 = { mcu = "atmega32u4"; chip_select = "AVR_ATmega32u4"; f_cpu = "8000000"; };
processor = atmega32u4;
mkLibrary = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [] }: mkLibrary = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [] }:
pkgs.stdenv.mkDerivation rec { pkgs.stdenv.mkDerivation rec {
@ -73,7 +72,6 @@
''; '';
}; };
in rec in rec
{ {
defaultPackage."x86_64-linux" = defaultPackage."x86_64-linux" =
@ -85,22 +83,10 @@
paths = [ paths = [
(packages."x86_64-linux"."prime-tx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; }) (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"."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" = packages."x86_64-linux"."dio" =
{ gcc, cflags }: { gcc, cflags }:
let 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" = devShell."x86_64-linux" =
let let
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };

View File

@ -88,14 +88,16 @@ int main (void) {
PORTB = 0; PORTB = 0;
_delay_ms(50); _delay_ms(50);
dio_t data_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 0 }; sk9822_t lights = {
dio_t clock_pin = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 }; .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); rng_t rng = rng_new(0);
animation_t animation = animation_new(); animation_t animation = animation_new();
while (1) { while (1) {
animation_step(&animation, &rng); animation_step(&animation, &rng);
send_pixels(data_pin, clock_pin, &animation.lamp, 1); sk9822_send(&lights, &animation.lamp, 1);
_delay_ms(FRAME_DELAY_MS); _delay_ms(FRAME_DELAY_MS);
} }
} }

18
lantern/main.c Normal file
View File

@ -0,0 +1,18 @@
/*
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
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 <https://www.gnu.org/licenses/>.
*/
#include <dio.h>
#include <sk9822.h>
int main(void) {
return 0;
}

View File

@ -35,13 +35,13 @@ void send_term(dio_t data_pin, dio_t clock_pin) {
send_byte(data_pin, clock_pin, 0xff); send_byte(data_pin, clock_pin, 0xff);
} }
void send_pixels(dio_t data_pin, dio_t clock_pin, rgb_t * pixels, uint8_t count) { void sk9822_send(sk9822_t *lights, rgb_t * pixels, uint8_t count) {
send_start(data_pin, clock_pin); send_start(lights->data_pin, lights->clock_pin);
for (uint8_t i = 0; i < count; i++) { for (uint8_t i = 0; i < count; i++) {
send_byte(data_pin, clock_pin, 0xe0 + pixels[i].brightness); send_byte(lights->data_pin, lights->clock_pin, 0xe0 + pixels[i].brightness);
send_byte(data_pin, clock_pin, pixels[i].r); send_byte(lights->data_pin, lights->clock_pin, pixels[i].r);
send_byte(data_pin, clock_pin, pixels[i].b); send_byte(lights->data_pin, lights->clock_pin, pixels[i].b);
send_byte(data_pin, clock_pin, pixels[i].g); 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);
} }

View File

@ -3,11 +3,11 @@ Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Savanni's AVR library. 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 <https://www.gnu.org/licenses/>. You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <avr/io.h> #include <avr/io.h>
@ -23,6 +23,11 @@ typedef struct RGB_s {
uint8_t b; uint8_t b;
} rgb_t; } 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 #endif