From b5f86d5972ef13412e43c7b8381d25d2a01b9eb8 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sat, 3 Apr 2021 17:40:17 +0200 Subject: [PATCH] Restructure files --- .gitignore | 19 ++++++++++++++++--- {prog_tool => client}/eepprog.py | 0 pin_allocation.txt => docs/pin_allocation.txt | 0 {firmware_src => firmware}/Makefile | 11 ++++++----- {firmware_src => firmware/src}/BitIO.h | 1 - {firmware_src => firmware/src}/config.h | 0 {firmware_src => firmware/src}/eeprom.c | 1 - {firmware_src => firmware/src}/eeprom.h | 0 {firmware_src => firmware/src}/main.c | 3 +-- {firmware_src => firmware/src}/protocol.c | 1 - {firmware_src => firmware/src}/protocol.h | 0 {firmware_src => firmware/src}/uart.c | 13 ++++++------- {firmware_src => firmware/src}/uart.h | 0 13 files changed, 29 insertions(+), 20 deletions(-) rename {prog_tool => client}/eepprog.py (100%) rename pin_allocation.txt => docs/pin_allocation.txt (100%) rename {firmware_src => firmware}/Makefile (85%) rename {firmware_src => firmware/src}/BitIO.h (99%) rename {firmware_src => firmware/src}/config.h (100%) rename {firmware_src => firmware/src}/eeprom.c (99%) rename {firmware_src => firmware/src}/eeprom.h (100%) rename {firmware_src => firmware/src}/main.c (99%) rename {firmware_src => firmware/src}/protocol.c (99%) rename {firmware_src => firmware/src}/protocol.h (100%) rename {firmware_src => firmware/src}/uart.c (99%) rename {firmware_src => firmware/src}/uart.h (100%) diff --git a/.gitignore b/.gitignore index 802bd71..072e680 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,12 @@ -# C code: object files etc. +# IDE / editor files +.idea/ +.vscode/ +.*.swp + +# General +/tmp + +# C code *.o *.obj *.elf @@ -6,5 +14,10 @@ *.gch *.pch -# vim swap files -.*.swp +# Python +__pycache__ +*.py[cod] +/venv + +# Firmware +/firmware/build diff --git a/prog_tool/eepprog.py b/client/eepprog.py similarity index 100% rename from prog_tool/eepprog.py rename to client/eepprog.py diff --git a/pin_allocation.txt b/docs/pin_allocation.txt similarity index 100% rename from pin_allocation.txt rename to docs/pin_allocation.txt diff --git a/firmware_src/Makefile b/firmware/Makefile similarity index 85% rename from firmware_src/Makefile rename to firmware/Makefile index 17bdb40..ee9c4a0 100644 --- a/firmware_src/Makefile +++ b/firmware/Makefile @@ -8,7 +8,7 @@ OBJCOPY = avr-objcopy # Compiler and linker flags CFLAGS = -Wall -std=c11 -Os -LDFLAGS = +LDFLAGS = # Target platform and programmer GCC_MCU = atmega16a @@ -16,9 +16,9 @@ AVRDUDE_PARTNO = m16 AVRDUDE_PROGRAMMER = usbtiny # Make target and object files -TARGET = eepprog -OBJECTS = main.o uart.o eeprom.o protocol.o -HEADERS = config.h BitIO.h uart.h eeprom.h protocol.h +TARGET = build/eepprog +OBJECTS = build/main.o build/uart.o build/eeprom.o build/protocol.o +HEADERS = src/config.h src/BitIO.h src/uart.h src/eeprom.h src/protocol.h # Default target (build hex file) all: hex @@ -41,7 +41,8 @@ $(TARGET).elf: $(OBJECTS) $(CC) -mmcu=$(GCC_MCU) $(LDFLAGS) -o $(TARGET).elf $(OBJECTS) # Object files -%.o: %.c $(HEADERS) +build/%.o: src/%.c $(HEADERS) + @mkdir -p build/ $(CC) -mmcu=$(GCC_MCU) $(CFLAGS) -c -o $@ $< diff --git a/firmware_src/BitIO.h b/firmware/src/BitIO.h similarity index 99% rename from firmware_src/BitIO.h rename to firmware/src/BitIO.h index 1cb6eb4..51770ae 100644 --- a/firmware_src/BitIO.h +++ b/firmware/src/BitIO.h @@ -41,4 +41,3 @@ static inline void BIT_BOOL_SET(volatile uint8_t *target, uint8_t bit, bool enab }; #endif /* BITIO_H_ */ - diff --git a/firmware_src/config.h b/firmware/src/config.h similarity index 100% rename from firmware_src/config.h rename to firmware/src/config.h diff --git a/firmware_src/eeprom.c b/firmware/src/eeprom.c similarity index 99% rename from firmware_src/eeprom.c rename to firmware/src/eeprom.c index 7783727..8ed6fed 100644 --- a/firmware_src/eeprom.c +++ b/firmware/src/eeprom.c @@ -114,4 +114,3 @@ void eepromWriteByte(address_t address, uint8_t data) { // Write pulse width high (50ns) _NOP(); } - diff --git a/firmware_src/eeprom.h b/firmware/src/eeprom.h similarity index 100% rename from firmware_src/eeprom.h rename to firmware/src/eeprom.h diff --git a/firmware_src/main.c b/firmware/src/main.c similarity index 99% rename from firmware_src/main.c rename to firmware/src/main.c index b86772f..d27fdb6 100644 --- a/firmware_src/main.c +++ b/firmware/src/main.c @@ -15,10 +15,9 @@ int main(void) { // Write initial message via UART uartPutString("INFO -- EEPROM programmer by binaryDiv\r\n"); - + while(1) { // Run main loop endlessly protocolMainLoop(); } } - diff --git a/firmware_src/protocol.c b/firmware/src/protocol.c similarity index 99% rename from firmware_src/protocol.c rename to firmware/src/protocol.c index 52a376f..454bdcf 100644 --- a/firmware_src/protocol.c +++ b/firmware/src/protocol.c @@ -139,4 +139,3 @@ void protocolMainLoop() { parseNextCommand(); } } - diff --git a/firmware_src/protocol.h b/firmware/src/protocol.h similarity index 100% rename from firmware_src/protocol.h rename to firmware/src/protocol.h diff --git a/firmware_src/uart.c b/firmware/src/uart.c similarity index 99% rename from firmware_src/uart.c rename to firmware/src/uart.c index 287ad54..b8f2499 100644 --- a/firmware_src/uart.c +++ b/firmware/src/uart.c @@ -20,10 +20,10 @@ void uartInit() { // U2X mode not necessary UCSRA &= ~(1 << U2X); #endif - + // Enable transmitter and receiver UCSRB |= (1 << TXEN) | (1 << RXEN); - + // Set frame format (8 bit) UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0); } @@ -33,7 +33,7 @@ void uartPutChar(unsigned char data) { // Block until controller is ready to send while (!(UCSRA & (1 << UDRE))) { } - + // Write character to UART data register UDR = data; } @@ -51,7 +51,7 @@ unsigned char uartGetChar() { // Block until a character has been received while (!(UCSRA & (1 << RXC))) { } - + // Get character and return return UDR; } @@ -80,15 +80,14 @@ uint8_t uartGetLine(char* buffer, uint8_t maxLength) { // Write character to buffer *buffer++ = nextChar; - + // Increment counter readChars++; } - + // Write a terminating '\0' byte *buffer++ = '\0'; // Return number of read bytes (excluding the \0) return readChars; } - diff --git a/firmware_src/uart.h b/firmware/src/uart.h similarity index 100% rename from firmware_src/uart.h rename to firmware/src/uart.h