Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Savanni D'Gerinel | 6f8a80b149 | |
Savanni D'Gerinel | 9e3787b314 | |
Savanni D'Gerinel | ef1c0c5834 |
24
flake.nix
24
flake.nix
|
@ -90,6 +90,7 @@
|
|||
(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; avr = true; })
|
||||
(packages."x86_64-linux"."lantern-controller" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; avr = true; })
|
||||
(packages."x86_64-linux"."tron-bag" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags attiny85; avr = true; })
|
||||
];
|
||||
};
|
||||
|
||||
|
@ -284,6 +285,29 @@
|
|||
];
|
||||
};
|
||||
|
||||
packages."x86_64-linux"."tron-bag_" =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
avr = pkgs.pkgsCross.avr.buildPackages;
|
||||
in packages."x86_64-linux"."tron-bag" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags attiny85; avr = true; };
|
||||
packages."x86_64-linux"."tron-bag" =
|
||||
{ gcc, cflags, avr }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in mkProgram {
|
||||
pkgs = pkgs;
|
||||
gcc = gcc;
|
||||
cflags = cflags;
|
||||
pname = "tron-bag";
|
||||
psrc = ./tron-bag;
|
||||
inherit avr;
|
||||
|
||||
pbuildInputs = [
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
pkgs.pkgsCross.avr.buildPackages.simavr
|
||||
];
|
||||
};
|
||||
|
||||
devShell."x86_64-linux" =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <dio.h>
|
||||
|
||||
#define FPS 10
|
||||
#define FPS_MS 1000 / FPS
|
||||
#define MULT 5
|
||||
|
||||
typedef struct {
|
||||
uint8_t value;
|
||||
int8_t inc;
|
||||
} counter_t;
|
||||
|
||||
void counter_update(counter_t *self) {
|
||||
int16_t value = self->value;
|
||||
value += self->inc;
|
||||
|
||||
if (value >= 255) {
|
||||
self->value = 255;
|
||||
self->inc = -1;
|
||||
} else if (value <= 0) {
|
||||
self->value = 0;
|
||||
self->inc = 1;
|
||||
} else {
|
||||
self->value = value;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
DDRB = 0xff;
|
||||
PORTB = 0;
|
||||
|
||||
GTCCR = 0;
|
||||
TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM01) | _BV(WGM00);
|
||||
TCCR0B = _BV(CS00);
|
||||
|
||||
counter_t red = (counter_t){ .value = 128, .inc = 1 };
|
||||
counter_t blue = (counter_t){ .value = 0, .inc = 1 };
|
||||
|
||||
while(1) {
|
||||
OCR0A = red.value;
|
||||
OCR0B = blue.value;
|
||||
|
||||
_delay_ms(10);
|
||||
|
||||
counter_update(&red);
|
||||
counter_update(&blue);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue