Improve the API for sk9822
This commit is contained in:
parent
4f778b79d3
commit
94efdbb1c3
|
@ -3,11 +3,11 @@ Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
|||
|
||||
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>
|
||||
|
|
40
flake.nix
40
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"; };
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
|||
|
||||
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>
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue