From 38cd2efb0a087035dfde9b654921f22bd6e15108 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 2 Dec 2022 11:42:42 +0100 Subject: [PATCH] Added starter example project. --- .gitignore | 1 + .vscode/c_cpp_properties.json | 18 ++++++++++++++++++ Makefile | 17 +++++++++++++++++ README.md | 14 ++++++++++++++ src/gympal.c | 15 +++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 Makefile create mode 100644 src/gympal.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6dd29b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..626b358 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "AVR", + "includePath": [ + "${workspaceFolder}/**", + "/lib/avr/include/**" + ], + "defines": [], + "compilerPath": "/usr/bin/avr-gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "gcc-avr", + "configurationProvider": "ms-vscode.makefile-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8e16276 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +all: clean build + +clean: + rm -rf bin/ + +flash: build + avrdude -c arduino -p atmega328p -P /dev/ttyUSB0 -b115200 -U flash:w:bin/gympal.hex:i + +build: gympal.hex + +gympal.hex: src/gympal.c bin + avr-gcc -Wall -Os -DF_CPU=16000000UL -mmcu=atmega328p -c src/gympal.c -o bin/gympal.o + avr-gcc -Os -mmcu=atmega328p -o bin/gympal.elf bin/gympal.o + avr-objcopy -O ihex -R .eeprom bin/gympal.elf bin/gympal.hex + +bin: + mkdir bin \ No newline at end of file diff --git a/README.md b/README.md index 2719b69..cdfc019 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # GymPal A simple device for recording gym sessions, using AVR. + +## Development +The software for this system is developed in C, using [avr-libc](https://www.nongnu.org/avr-libc/), and the build toolchain is managed by make, using [avr-gcc](https://linux.die.net/man/1/avr-gcc) and [avr-dude](https://github.com/avrdudes/avrdude) to upload firmware to the Atmega328p microcontroller. + +To compile the firmware, you can run `make`. + +To upload the firmware to an Arduino, run `make flash`. + +### Helpful Links +The following links are helpful for learning how to program an AVR-based microcontroller. + +- [avr-libc Homepage](https://www.nongnu.org/avr-libc/) +- [avr-libc Library Reference](https://www.nongnu.org/avr-libc/user-manual/modules.html) +- [avrdude Firmware Uploader](https://github.com/avrdudes/avrdude) diff --git a/src/gympal.c b/src/gympal.c new file mode 100644 index 0000000..4025db6 --- /dev/null +++ b/src/gympal.c @@ -0,0 +1,15 @@ +#include +#include + +int main() { + // Pin 12 == Port B4, aka 4th bit on the B register. + // Set pin 12 as output. + DDRB = 1 << PORTB4; + // Set pin 12 as HIGH. + PORTB = 1 << PORTB4; + // Delay for 1 second. + _delay_ms(1000.0); + // Set pin 12 as LOW. + PORTB = 0 << PORTB4; + return 0; +} \ No newline at end of file