Refactoring

i2c
Savanni D'Gerinel 2022-05-07 20:16:20 -04:00
parent 565036547c
commit 1f394f20ff
7 changed files with 27 additions and 26 deletions

View File

@ -1,9 +1,8 @@
#include "../base.h"
#include "base.h"
rng_t rng_new(uint8_t seed) {
return { .mod = 255, .a = 253, .c = 41, .seed = seed };
rng_t rng = { .mod = 255, .a = 253, .c = 41, .seed = seed };
return rng;
}
uint8_t rng_sample(rng_t *state) {

View File

@ -1,3 +1,4 @@
#include <avr/io.h>
#ifndef __BASE_H__
#define __BASE_H__

View File

@ -11,21 +11,6 @@
supportedSystems = [ "x86_64-linux" "avr-none" ];
in
{
/*
packages.base."x86_64-linux" =
let pkgs = import nixpkgs { system = "x86_64-linux"; };
in pkgs.stdenv.mkDerivation rec {
name = "wearables-base";
src = "./base";
installPhase = ''
mkdir -p $out/include
cp include/base.h $out/include
'';
};
*/
/*
defaultPackage."x86_64-linux" =
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
@ -41,7 +26,11 @@
buildPhase = ''
set -x
${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base/include/ -o main.elf ${src}/prototype/src/main.c
${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base -o base.o -c ${src}/base/base.c
${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base -o sk9822.o -c ${src}/sk9822/sk9822.c
${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base -I${src}/sk9822 -o main.o -c ${src}/flame/main.c
${avr.gcc}/bin/avr-gcc ${CFLAGS} -o main.elf main.o sk9822.o base.o
$OBJCOPY -O ihex main.elf main.hex
'';
installPhase = ''
@ -49,7 +38,6 @@
cp main.elf main.hex $out
'';
};
*/
devShell."x86_64-linux" =
let
@ -67,8 +55,8 @@
name = "Wearables-shell";
buildInputs = avr;
GCC="${pkgs.pkgsCross.avr.buildPackages.gcc}";
AVR="${pkgs.avrlibc}";
GCC = pkgs.pkgsCross.avr.buildPackages.gcc;
SIMAVR = pkgs.pkgsCross.avr.buildPackages.simavr;
};
};
}

View File

@ -2,7 +2,7 @@
#include <util/delay.h>
#include <base.h>
#include "sk9822.h"
#include <sk9822.h>
uint8_t random_step(uint8_t value, uint8_t min, uint8_t max, rng_t *rng) {
int8_t step = (rng_sample(rng) % 32) - 16;

View File

@ -9,15 +9,20 @@ OBJECTS= main.o \
.SUFFIXES: .c .o .h
%.o: %.c %.h
${GCC}/bin/avr-gcc ${CFLAGS} ${AVR}/avr/include -I../base/include/ -o $@ -c $<
# /nix/store/fymsi5yk07jvcbdaka6nfhx6s2a7kgpi-avr-stage-final-gcc-debug-wrapper-10.3.0/bin/avr-gcc -O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -DF_CPU=8000000 -std=gnu99 -D__AVR_ATtiny85__=1 -mmcu=attiny85 -I../base/include/ -E -o main.E src/main.c
main: main.o sk9822.o
# ${GCC}/bin/avr-gcc ${CFLAGS} -I../base/include/ -E -o main.E src/main.c
# ${GCC}/bin/avr-gcc ${CFLAGS} -I../base/include/ -S -o main.S src/main.c
echo ${GCC}
${GCC}/bin/avr-gcc ${CFLAGS} ${LINKFLAGS} -I../base/include/ -o main.elf main.o sk9822.o
${OBJCOPY} -O ihex main.elf main.hex
%.o: %.c %.h
${GCC}/bin/avr-gcc ${CFLAGS} -I../base/include/ -o $@ -c $<
clean:
rm *.o make.elf main.hex main.S main.E

View File

@ -1,3 +1,5 @@
#include "sk9822.h"
void send_byte(io_pin_t data_pin, io_pin_t clock_pin, uint8_t byte) {
for (int i = 7; i >= 0; i--) {
if (byte & _BV(i)) {

View File

@ -1,4 +1,8 @@
#include <avr/io.h>
#include <base.h>
#ifndef __SK9822_H__
#define __SK9822_H__
typedef struct RGB_s {
uint8_t brightness;
@ -8,3 +12,5 @@ typedef struct RGB_s {
} rgb_t;
void send_pixels(io_pin_t data_pin, io_pin_t clock_pin, rgb_t *pixels, uint8_t count);
#endif