Initial commit

This commit is contained in:
Savanni D'Gerinel 2022-04-17 00:43:50 -04:00
commit 5487c27c50
7 changed files with 140 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.direnv
result

19
base/include/base.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef __BASE_H__
#define __BASE_H__
typedef struct IO_PIN {
volatile uint8_t *port;
uint8_t pin;
} io_pin_t;
inline void set_pin(io_pin_t *pin) {
*(pin->port) |= 1 << pin->pin;
}
inline void clear_pin(io_pin_t *pin) {
*(pin->port) &= 0xff ^ (1 << pin->pin);
}
#endif

26
flake.lock Normal file
View File

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1649944829,
"narHash": "sha256-wjOgLfjCdyoRamMOrVJceeDJk4LvJsQOxBoT3k16/7Q=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2f06b87f64bc06229e05045853e0876666e1b023",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-21.11",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

66
flake.nix Normal file
View File

@ -0,0 +1,66 @@
{
description = "Wearables";
inputs = {
nixpkgs.url = "nixpkgs/nixos-21.11";
};
outputs = { self, nixpkgs }:
let
version = builtins.string 0 8 self.lastModifiedDate;
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"; };
avr = pkgs.pkgsCross.avr.buildPackages;
in pkgs.stdenv.mkDerivation rec {
name = "hello";
src = ./.;
MCU = "attiny85";
CHIP_SELECT = "AVR_ATtiny85";
F_CPU = "8000000";
CFLAGS = ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -DF_CPU=${F_CPU} -std=gnu99 -D__${CHIP_SELECT}__=1 -mmcu=${MCU}'';
buildPhase = ''
set -x
${avr.gcc}/bin/avr-gcc ${CFLAGS} -I${src}/base/include/ -o main.elf ${src}/prototype/src/main.c
$OBJCOPY -O ihex main.elf main.hex
'';
installPhase = ''
mkdir $out
cp main.elf main.hex $out
'';
};
devShell."x86_64-linux" =
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
avr = with pkgs.pkgsCross.avr.buildPackages; [
binutils
gcc
avrdude
];
in
pkgs.mkShell {
name = "Wearables-shell";
buildInputs = avr;
};
};
}

1
flash-trinket Executable file
View File

@ -0,0 +1 @@
avrdude -c usbtiny -p attiny85 -U flash:w:$1:i; sleep 5; avrdude -c usbtiny -p attiny85 -D -U flash:w:$1:i

25
prototype/src/main.c Normal file
View File

@ -0,0 +1,25 @@
#include <avr/io.h>
#include <util/delay.h>
#include <base.h>
int main (void) {
DDRB = 0x18;
PORTB = 0x00;
_delay_ms(500);
io_pin_t enable_pin = { .port = &PORTB, .pin = 3 };
io_pin_t data_pin = { .port = &PORTB, .pin = 4 };
set_pin(&enable_pin);
for (uint8_t i = 0; i < 10; i++) {
set_pin(&data_pin);
_delay_ms(500);
clear_pin(&data_pin);
_delay_ms(500);
}
clear_pin(&enable_pin);
while(1) {};
}