added all the needed template files

This commit is contained in:
jakeg00dwin 2024-04-10 10:47:04 -07:00
parent f4c29d1ac5
commit 18009c9b1f
11 changed files with 3324 additions and 101 deletions

8
.gitignore vendored
View File

@ -1,3 +1,11 @@
main.o
main.map
main.elf
build/CMakeFiles
build/src
build/tests
build/CMakeCache.txt
build/CTestTestfile.cmake
build/Makefile
build/cmake_install.cmake
build/compile_commands.json

68
CMakeLists.txt Normal file
View File

@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.20)
# Use the fancy version substitution
project(cmake-cpputest-template
VERSION 1.0
DESCRIPTION "template for cmake + cpputest"
LANGUAGES C CXX
)
enable_testing()
set(TARGET_GROUP production CACHE STRING "Group to build")
if(MSVC OR MSYS OR MINGW)
message("### SETUP FOR WINDOWS ###")
add_definitions(-DWINDOWS)
else()
message("### SETUP FOR UNIX ###")
add_definitions(-DUNIX)
endif()
# For being able to used LSP
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Request C 17 standard features
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_C_FLAGS "-Wall -Werror -Wpedantic")
# SETUP THE CXX flags for .cpp
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "-Wall -Werror -Wpedantic")
# #######################################
# TESTING STUFF
# #######################################
if (UNIT_TESTING)
if(DEFINED ENV{CPPUTEST_HOME})
message(STATUS "Using CppUTest home: $ENV{CPPUTEST_HOME}")
set(CPPUTEST_INCLUDE_DIRS $ENV{CPPUTEST_HOME}/include)
set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
else()
find_package(PkgConfig REQUIRED)
pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
endif()
include_directories(
${CPPUTEST_INCLUDE_DIRS}
/usr/include/c++/11/
)
link_directories(${CPPUTEST_LIBRARIES})
add_subdirectory(tests)
endif()
# #######################################
# PROJECT SPECIFIC
# #######################################
add_subdirectory(src)

2854
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

101
README.md
View File

@ -1,101 +0,0 @@
# AVR ATiny13 Project 002
This is the firmware for a latching dual relay system. It allows the user to
switch two DPDT relays by with two separate switches.
## Components:
**Micro:** AVR ATiny13, ATiny25/45/85
## Instructions:
1. Power the system using a 1.8v~5.5v power supply
2. Set/program the AVR to use a 1MHz clock rate.
3. Connect the pins as described above.
**ACTIVATING RELAYS:**
1. Activate the desired button with a quick press <= 350ms.
2. Repeat to toggle the relay.
**TEMPORARY TOGGLE:**
1. Press and hold the desired button >= 350ms.
2. Let go to disable.
**SAVING SETTINGS:**
1. Press and hold the target button.
2. While holding the button power cycle the device.
3. When the setting is successfully saved the relay/led will blink/toggle.
4. repeat until desired preset is saved.
## Technical Aspects:
The use of C style bitfields has been used inside a struct to maintain a global
state. It minimizes the size of the binary once compiled.
The majority of the code is blocking/polling; overhead from introducing
interrupts and ISR(interrupt service routines) wasn't as clean and made it more
platform dependent.
The code right now can for the most part be ported to any AVR micro-controller
with no changes.
## Timings
The current setup is calculated for a attiny13/a running at 4.8Mhz without the
clock divider fuse set.
This means that the actual f_cpu is 4.8Mhz to calculate the delay times
we can use this formula:
$$
msPerOverflow = 1000ms / (\frac{4.8Mhz}{64} * \frac{1}{256}) \approx 6.8ms
$$
Where $64$ is the pre scaler setting and $256$ is the maximum value of the 8bit
timer.
## BUILDING PROJECT:
**On Unix**
```sh
git clone <REPOURL>
cd <REPO>
make flash
```
## Flashing the Project
**On Windows(usbtinyisp)**
1. Install the usbtiny driver:
1. plug in usbtiny device
2. Install the drivers from: [adafruit](https://learn.adafruit.com/usbtinyisp/drivers)
2. open Powershell
3. navigate to the repo directory *cd Downloads\gf_002*
4. enter the command below.
```ps1
./avrdude.exe -p t13 -c usbtiny -B 125kHz -U flash:w:.\pre_built\attiny13_4-8Mhz.hex -U lfuse:w:0x79:m -U hfuse:w:0xFF:m -U lock:w:0xFF:m
```
**On Windows(usbASP)**
1. Install the usbasp driver:
1. plug in usbasp device
2. run the 'zadig-2.8.exe' program
3. select the libusb 32 on the right by clicking the down arrow to select.
2. open Powershell
3. navigate to the repo directory *cd Downloads\gf_002*
4. enter the command below.
```ps1
./avrdude.exe -p t13 -c usbasp -B 125kHz -U flash:w:.\pre_built\attiny13_4-8Mhz.hex -U lfuse:w:0x79:m -U hfuse:w:0xFF:m -U lock:w:0xFF:m
```

1
compile_commands.json Symbolic link
View File

@ -0,0 +1 @@
./build/compile_commands.json

242
otto.sh Executable file
View File

@ -0,0 +1,242 @@
#!/bin/sh
# Author: Jake Goodwin
# Date: 2024
# Filename: otto.sh
CROSS_TC_WIN="$(pwd)/i686-w64-mingw32_toolchain.cmake"
CMAKE_VERBOSE="ON"
CROSS_COMPILE=1
TEMPLATE_FILES=".template_files"
MODULE_DIR="${TEMPLATE_FILES}/modules"
add_compile_commands () {
if [ -f ./compile_commands.json ]; then
echo "compile_commands.json already exists!\n"
else
echo "Creating new symlink for compile commands!\n"
ln -s ./build/compile_commands.json ./compile_commands.json
fi
}
clear_cmake_cache () {
cd ./build
rm -rf CMakeCache.txt CMakeFiles/
}
does_module_exist () {
local basename="$1"
if [ -d "src/${basename}" ]; then
echo "1"
else
echo "0"
fi
}
add_module_to_cmakes () {
local basename="$1"
echo "add_subdirectory(${basename})" >> ./src/CMakeLists.txt
# Tests cmake file needs to be edited in place.
sed -i'' "s/# TEST_DIRS.*$/# TEST_DIRS\r\nadd_subdirectory(${basename})/g" ./tests/CMakeLists.txt
sed -i'' "s/# TEST_LINKS.*$/# TEST_LINKS\r\n\t${basename}/g" ./tests/CMakeLists.txt
}
remove_module_from_cmakes () {
local basename="$1"
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./src/CMakeLists.txt
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./tests/CMakeLists.txt
sed -i'' "s/^.*${basename}.*$//g" ./tests/CMakeLists.txt
}
git_add_module () {
local basename="$1"
read -p "Auto add to git?(y/n):" CHOICE
if [ "${CHOICE}" = "n" ]; then
echo "not being added!"
return 0
fi
modsrc_dir="./src/${basename}"
modtest_dir="./tests/${basename}"
# Now we add the new files to the git tracked files
git add ${modsrc_dir}/*
git add ${modsrc_dir}
git add ${modtest_dir}/*
git add ${modtest_dir}
git add ./src/CMakeLists.txt
git add ./tests/CMakeLists.txt
}
git_remove_module () {
local basename="$1"
read -p "Auto del from git?(y/n):" CHOICE
if [ "${CHOICE}" -eq "n" ]; then
echo "not being removed!"
return 0
fi
modsrc_dir="./src/${basename}"
modtest_dir="./tests/${basename}"
# Now we add the new files to the git tracked files
git rm -r ${modsrc_dir}/*
git rm -r ${modsrc_dir}
git rm -r ${modtest_dir}/*
git rm -r ${modtest_dir}
git rm -r ./src/CMakeLists.txt
git rm -r ./tests/CMakeLists.txt
}
add_new_module () {
read -p "Enter the name of the module:" modname
result=$(does_module_exist "$modname")
if [ "${result}" -eq "1" ]; then
echo "Module already exists!"
echo "Exiting without changing anything"
exit
fi
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
modsrc_dir="./src/${modname}"
modtest_dir="./tests/${modname}"
echo "creating: ${modsrc_dir}, ${modtest_dir}"
mkdir $modsrc_dir
mkdir $modtest_dir
#copy the template files.
echo "copying & customizing template files..."
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h
sed "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
sed "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
# Add the module to the cmake lists files.
add_module_to_cmakes "${modname}"
echo "Resulting files/dirs:"
tree -L 2 $modsrc_dir
tree -L 2 $modtest_dir
# Now we add the new files to the git tracked files
git_add_module "${modname}"
}
del_module () {
read -p "Enter the name of the module:" modname
rm -r ./tests/${modname}
rm -r ./src/${modname}
remove_module_from_cmakes "${modname}"
}
cross_compile () {
echo "ERROR: Currently no toolchain / target!"
}
build_release() {
clear_cmake_cache
cmake -DCAM_HANDLER_LIB=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
make
}
build_main () {
clear_cmake_cache
cmake -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
make main
}
run_c_tests () {
clear_cmake_cache
cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
make AllTests && ./tests/AllTests
}
print_menu () {
echo "BUILD MENU:"
echo "1. Run Tests"
echo "2. Build Project"
echo "3. Build for release"
echo "4. cross compile for XXXXXX"
echo "5. Add new module to project"
echo "6. Delete module from project"
echo "7. Exit"
}
main() {
add_compile_commands
valid_choice=false
while [ "$valid_choice" != true ]; do
print_menu
read -p "Enter your choice: " choice
case $choice in
1)
echo "You selected Option 1"
valid_choice=true
run_c_tests
;;
2)
echo "You selected Option 2"
valid_choice=true
build_main
;;
3)
echo "You selected Option 3"
valid_choice=true
build_release
;;
4)
echo "You selected Option 4"
valid_choice=true
cross_compile
;;
5)
echo "You selected Option 5"
valid_choice=true
add_new_module
;;
6)
echo "You selected Option 6"
valid_choice=true
del_module
;;
7)
echo "Exiting..."
exit 0
;;
*)
echo "Invalid choice. Please select a valid option."
;;
esac
done
}
main

86
setup.sh Executable file
View File

@ -0,0 +1,86 @@
#!/bin/sh
#Author: Jake G
#Date: 2024
#Filename: setup.sh
PKG_MNGR=""
DEBIAN=0
FBSD=0
SYSINSTALL=0
DEV_UTILS="vim tmux fzf"
install_dev_utils () {
ICMD=""
if [ $DEBIAN -eq 1 ]; then
ICMD="sudo apt install"
elif [ $FBSD -eq 1 ]; then
ICMD="sudo pkg install"
fi
for util in $DEV_UTILS
do
${ICMD} ${util}
done
}
check_os () {
if [ -f /etc/debian_version ]; then
DEBIAN=1
elif [ -f /etc/freebsd-update.conf ]; then
FBSD=1
fi
}
remove_template_examples () {
echo "does nothing right now"
}
install_needed_dependencies () {
# Check the OS
echo "checking the OS..."
# If it's debian based then apt install
# If it's freeBSD then pkg
# If it's windows....you're SOL
}
create_project_symlinks () {
# Allows the clangd LSP to find it.
ln -s ./build/compile_commands.json ./compile_commands.json
}
build_cpputest () {
git submodule add https://github.com/cpputest/cpputest.git
git sumodule status
cd ./cpputest/build
cmake ../
if [ SYSINSTALL -eq 1]; then
make install
else
make
fi
}
# The default setup stuff.
default () {
remove_template_examples
install_needed_dependencies
create_project_symlinks
}
setup() {
echo "Setting up env"
check_os
install_dev_utils
}
setup

12
tests/AllTests.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "CppUTest/CommandLineTestRunner.h"
//ImportTestGroups
IMPORT_TEST_GROUP(simple_test);
//START: main
int main(int argc, char** argv)
{
return RUN_ALL_TESTS(argc, argv);
}
//END: main

16
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
project(Tests)
# TEST_DIRS
add_subdirectory(simple_test)
# TEST_RUNNER
add_executable(AllTests
AllTests.cpp
)
target_link_libraries(AllTests
${CPPUTEST_LIBRARIES}/libCppUTest.a
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
# TEST_LINKS
simple_test
)

View File

@ -0,0 +1,11 @@
# TEST_RUNNER
add_library(simple_test
simple_test.cpp
)
target_link_libraries(simple_test
${CPPUTEST_LIBRARIES}/libCppUTest.a
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
)

View File

@ -0,0 +1,26 @@
#include "CppUTest/TestHarness.h"
/*
extern C
{
#include "simple.h"
}
*/
TEST_GROUP(simple_test)
{
void setup()
{
}
void teardown()
{
}
};
TEST(simple_test, passing_test)
{
CHECK_TRUE(1);
}