aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-02-01 20:59:22 +0530
committerAkshay Nair <phenax5@gmail.com>2026-02-01 20:59:24 +0530
commit8fa32bb0414c3164d8c3467c5db4c1a912627fc4 (patch)
tree0d1c3b5f1aa27f77b4678b6f65f38b8b09dfce37
parent7224fce49e4fa8c0b966dcc8d4f9b1d12b02f66a (diff)
downloaddaft-watch-8fa32bb0414c3164d8c3467c5db4c1a912627fc4.tar.gz
daft-watch-8fa32bb0414c3164d8c3467c5db4c1a912627fc4.zip
Remove platformio stuff and switch to avr-gcc
-rw-r--r--.clangd2
-rw-r--r--.gitignore2
-rw-r--r--compile_flags.txt14
-rw-r--r--flake.nix4
-rw-r--r--justfile52
-rw-r--r--platformio.ini43
-rwxr-xr-xsetup_compiledb.sh30
-rw-r--r--src/main.c50
-rw-r--r--src/main.cpp16
9 files changed, 104 insertions, 109 deletions
diff --git a/.clangd b/.clangd
index f7f6556..2ac690e 100644
--- a/.clangd
+++ b/.clangd
@@ -1,2 +1,2 @@
CompileFlags:
- Remove: [-mlongcalls, -free, -mtext-section-literals, -fipa-pta, -fno-tree-switch-conversion, -fstrict-volatile-bitfields]
+ Compiler: avr-gcc
diff --git a/.gitignore b/.gitignore
index 1628473..b02bdb5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@
.cache/
compile_commands.json
compiler_defines.h
+a.out
+out/
diff --git a/compile_flags.txt b/compile_flags.txt
new file mode 100644
index 0000000..7e86e45
--- /dev/null
+++ b/compile_flags.txt
@@ -0,0 +1,14 @@
+-g
+-Os
+-std=gnu99
+-Isrc
+-mmcu=attiny84a
+-DF_CPU=1000000L
+-I/nix/store/ivhsczriimr31rrmly0bcj03gv4qa3q7-avr-libc-avr-2.2.1/avr/include
+-L/nix/store/ivhsczriimr31rrmly0bcj03gv4qa3q7-avr-libc-avr-2.2.1/avr/lib
+-funsigned-char
+-funsigned-bitfields
+-fpack-struct
+-fshort-enums
+-Wall
+-Wstrict-prototypes
diff --git a/flake.nix b/flake.nix
index b947856..8263e1f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -21,13 +21,16 @@
(lib.hiPrio gcc)
platformio-core
avrdude
+ pkgs.pkgsCross.avr.buildPackages.gcc
openocd
glibc
+ pkgs.pkgsCross.avr.avrlibc
# dev
clang-tools
unixtools.xxd
just
+ pkg-config
];
multiPkgs = pkgs: (with pkgs; [ udev ]);
@@ -35,6 +38,7 @@
profile = ''
export DIRENV_DISABLE_HOOK=1; # Dont recursively load direnv inside shell
export WITH_NIX_PREFIX="fhs";
+ export AVR_LIBC="${pkgs.pkgsCross.avr.avrlibc}";
'';
};
in
diff --git a/justfile b/justfile
index 749fde6..4978f92 100644
--- a/justfile
+++ b/justfile
@@ -1,28 +1,42 @@
-build:
- pio run -e attiny84;
+set export
+set unstable
-check:
- pio check --skip-packages
+default:
+ just --choose || true
-upload:
- pio run -e attiny84 -t upload
+AVR_LIBC := env("AVR_LIBC", "/usr/lib/avr")
+F_CPU := "1000000"
+MCU := "attiny84a"
+MCU_PART := "attiny84"
+SRC := "./src/main.c"
+OUTDIR := "./out"
+PROGRAMMER := "arduino"
+UPLOAD_SPEED := "19200"
+SERIAL_PORT := "/dev/ttyUSB0"
-clean:
- pio run -t clean
+CFLAGS := f"-g -Os -std=gnu99 -Isrc -mmcu={{MCU}} -DF_CPU={{F_CPU}}L \
+-I{{AVR_LIBC}}/avr/include -L{{AVR_LIBC}}/avr/lib \
+-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes"
-update:
- pio pkg update
+AVRDUDE := f"avrdude -v -p {{MCU_PART}} -c {{PROGRAMMER}} -P {{SERIAL_PORT}} -b {{UPLOAD_SPEED}}"
-monitor:
- pio device monitor
+build: compile_flags
+ mkdir -p {{OUTDIR}}
+ avr-gcc {{CFLAGS}} {{SRC}} -o {{OUTDIR}}/out.elf
+ avr-objcopy -O ihex -R .eeprom {{OUTDIR}}/out.elf {{OUTDIR}}/out.hex
-test:
- pio test -e test
+write:
+ [ -f "{{OUTDIR}}/out.hex" ] || (echo "No out.hex. Run build"; exit 1);
+ {{AVRDUDE}} -U "flash:w:{{OUTDIR}}/out.hex:i"
-format:
- find include/ src/ -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i
+read:
+ {{AVRDUDE}} -F -U flash:r:-:h
-devsetup:
- # COMPILATIONDB_INCLUDE_TOOLCHAIN=true pio run -t compiledb
- ./setup_compiledb.sh
+clean:
+ rm -rf {{OUTDIR}}
+
+format:
+ find src/ -iname '*.h' -o -iname '*.c' | xargs clang-format -i
+compile_flags:
+ echo '{{CFLAGS}}' | tr ' ' '\n' > ./compile_flags.txt
diff --git a/platformio.ini b/platformio.ini
deleted file mode 100644
index 1fab521..0000000
--- a/platformio.ini
+++ /dev/null
@@ -1,43 +0,0 @@
-; PlatformIO Project Configuration File
-;
-; Build options: build flags, source filter
-; Upload options: custom upload port, speed and extra flags
-; Library options: dependencies, extra library storages
-; Advanced options: extra scripting
-;
-; Please visit documentation for the other options and examples
-; https://docs.platformio.org/page/projectconf.html
-
-[cfg]
-build_flags =
- -Ilib -Isrc
- -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -Wno-format-extra-args
- -std=gnu++2a
-build_unflags = -Os -std=gnu++14
-monitor_filters =
- time
- colorize
- send_on_enter
- esp32_exception_decoder
-
-[env:attiny84]
-platform = atmelavr
-board = attiny84
-framework = arduino
-board_build.mcu = attiny84
-board_build.f_cpu = 1000000L
-upload_protocol = arduino
-upload_speed = 19200
-upload_port = /dev/ttyUSB0
-upload_flags =
- -C
- $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
- -p
- $BOARD_MCU
- -P
- $UPLOAD_PORT
- -b
- $UPLOAD_SPEED
- -c
- $UPLOAD_PROTOCOL
-
diff --git a/setup_compiledb.sh b/setup_compiledb.sh
deleted file mode 100755
index 9233bb1..0000000
--- a/setup_compiledb.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env bash
-
-export COMPILATIONDB_INCLUDE_TOOLCHAIN=true
-
-# Compile the project
-pio run -t compiledb
-
-# Clean up existing define files
-rm -f _compiler_defines.h compiler_defines.h clang_defines.h
-
-# Generate defines for clang
-gcc -dM -xc++ /dev/null -c -v -E 2>/dev/null | sed "s/\([^[:space:]]\+[[:space:]]\+[^[:space:]]\+\)\(.*\)/\1/;s/#define/#undef/" >clang_defines.h
-
-# Iterate through compile_commands.json and extract compiler defines
-for comp in $(cat compile_commands.json | grep -E "\"command\": \"[^[:space:]]* -o" | sed 's:"command"\: "::g; s:-o.*::g' | sort | uniq); do
- set -x
- $comp -dM -E -xc++ /dev/null >>_compiler_defines.h
- set +x
-done
-
-# Combine defines from clang and extracted defines
-cat clang_defines.h > compiler_defines.h
-cat _compiler_defines.h | sort | uniq >> compiler_defines.h
-
-# Clean up temporary define files
-rm -f _compiler_defines.h clang_defines.h
-
-# Update compile_commands.json with additional include flags
-sed -i "s:.cpp\",:.cpp -include $${PWD}/compiler_defines.h\",:" compile_commands.json
-sed -i "s:.c\",:.c -include $${PWD}/compiler_defines.h\",:" compile_commands.json
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..a7e2646
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,50 @@
+#include <avr/io.h>
+#include <util/delay.h>
+
+// gfedcba
+const long digits[] = {
+ 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110,
+ 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111,
+};
+
+// a, b, c, d, e, f, g
+const int segment_pins[] = {4, 5, 6, 7, 8, 9, 10};
+
+void write_digit(int digit) {
+ if (digit > 9 || digit < 0)
+ return;
+
+ long mask = digits[digit];
+ for (int i = 0; i < 7; i++) {
+ short on = 0 != (mask & (i == 0 ? 1 : 2 << (i - 1)));
+ // digitalWrite(segment_pins[i], on);
+ }
+}
+
+void setup(void) {
+ for (int i = 0; i < 7; i++) {
+ int pin = segment_pins[i];
+ DDRA |= (1 << PA1);
+ }
+}
+
+int i = 0;
+void loop(void) {
+ write_digit(i);
+ _delay_ms(500);
+ i = (i + 1) % 10;
+}
+
+int main(void) {
+ setup();
+
+ while (1) {
+ loop();
+ // PORTA |= (1 << PA1);
+ // _delay_ms(500);
+ // PORTA &= ~(1 << PA1);
+ // _delay_ms(500);
+ }
+
+ return 0;
+}
diff --git a/src/main.cpp b/src/main.cpp
deleted file mode 100644
index 6226244..0000000
--- a/src/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <Arduino.h>
-
-// Physical Pin 2 on the ATtiny84a is Arduino Digital Pin 0
-#define LED_PIN 0
-
-void setup() {
- // Initialize the digital pin as an output.
- pinMode(LED_PIN, OUTPUT);
-}
-
-void loop() {
- digitalWrite(LED_PIN, HIGH); // Turn the LED on
- delay(1000); // Wait for a second
- digitalWrite(LED_PIN, LOW); // Turn the LED off
- delay(1000); // Wait for a second
-}