Skip to content

Commit

Permalink
Squash merge dev branch into main. Changes:
Browse files Browse the repository at this point in the history
* Refactoring: moved global defines to digilivolo.h, code split into 2 additional units based on functions: usb_func.[ch] which handles USB HID related things & args.[ch] which handles command line options, help and copyright messages.
* Some text messages from software improved.
* Added comment headers to source files.
* hidapi version requirement set to 0.13 (as it's in fact).
* Added arm-linux-gnueabihf-gcc-toolchain.cmake file for cross-compiling arm binaries.
  • Loading branch information
N-Storm committed Apr 29, 2024
1 parent ca15655 commit e7916cf
Show file tree
Hide file tree
Showing 16 changed files with 461 additions and 188 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build firmware
name: Build DigiLivolo firmware
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- { os: ubuntu-latest, shell: bash, c_compiler: clang }
- { os: windows-latest, shell: 'msys2 {0}', c_compiler: gcc, binary_orig: digilivolo.exe, binary_target: digilivolo-win-x86_64.exe }
- { os: windows-latest, shell: pwsh, c_compiler: gcc }
- { os: windows-latest, shell: pwsh, c_compiler: clang }
- { os: windows-latest, shell: pwsh, c_compiler: clang }
build_type: [Release]
defaults:
run:
Expand Down
10 changes: 7 additions & 3 deletions firmware/lib/DLUSB/DLUSB.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Name: DLUSB.c
* Part of the DigiLivolo firmware.
* https://github.com/N-Storm/DigiLivolo/
* Copyright (c) 2024 GitHub user N-Storm.
*
* Based on DLUSB library from Digistump Arduino: https://github.com/ArminJo/DigistumpArduino
* Based on V-USB Arduino Examples by Philip J. Lindsay
* Modification for the Digispark by Erik Kettenburg, Digistump LLC
Expand All @@ -9,11 +13,11 @@
* Original author: Christian Starkjohann
* Arduino modifications by: Philip J. Lindsay
* Creation Date: 2008-04-11
* Tabsize: 4
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
* This Revision: $Id: main.c 692 2008-11-07 15:07:40Z cs $
* License: GNU GPL v3 or later
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <Arduino.h>
#include <avr/io.h>
#include <avr/wdt.h>
Expand Down
12 changes: 9 additions & 3 deletions firmware/lib/DLUSB/DLUSB.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
/* Name: DLUSB.h
* Part of the DigiLivolo firmware.
* https://github.com/N-Storm/DigiLivolo/
* Copyright (c) 2024 GitHub user N-Storm.
*
* Based on DigiUSB library from Digistump Arduino: https://github.com/ArminJo/DigistumpArduino
* Based on Obdev's AVRUSB code and under the same license.
* Based on Obdev's AVRUSB code.
*
* TODO: Make a proper file header. :-)
* License: GNU GPL v3 or later
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef __DLUSB_h__
#define __DLUSB_h__

Expand Down
1 change: 0 additions & 1 deletion firmware/lib/Livolo/Livolo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Released into the public domain.
01/12/2013 - code optimization, thanks Maarten! http://forum.arduino.cc/index.php?topic=153525.msg1489857#msg1489857
*/

#include "Arduino.h"
Expand Down
20 changes: 20 additions & 0 deletions firmware/src/DigiLivolo.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/* Part of the DigiLivolo firmware.
* https://github.com/N-Storm/DigiLivolo/
* Copyright (c) 2024 GitHub user N-Storm.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <Arduino.h>
#include <DLUSB.h>
#include <Livolo.h>
Expand Down
8 changes: 5 additions & 3 deletions software/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(PROJECT_NAME "digilivolo")
project(${PROJECT_NAME} C)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=gnu11 -flto -ffunction-sections -fdata-sections -ffat-lto-objects -Wall -Wl,--warn-common -Wl,--gc-sections")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -std=gnu11 -flto -ffunction-sections -fdata-sections -ffat-lto-objects -Wall -Wl,--warn-common -Wl,--gc-sections")
endif()
set(HIDAPI_WITH_LIBUSB FALSE)
set(BUILD_SHARED_LIBS FALSE) # HIDAPI as static library on all platforms

Expand Down Expand Up @@ -30,15 +32,15 @@ if(NOT USE_SYSTEM_HIDAPI)
message(STATUS "hidapi will be built from sources")
else()
message(STATUS "Finding library hidapi")
find_package(hidapi 0.12 REQUIRED)
find_package(hidapi 0.13 REQUIRED)
endif()

message(STATUS "Using HIDAPI: ${hidapi_VERSION}")

add_subdirectory(lib/argp-standalone)

configure_file(src/git_version.h.in src/git_version.h @ONLY)
add_executable(${PROJECT_NAME} src/digilivolo.c)
add_executable(${PROJECT_NAME} src/args.c src/digilivolo.c src/usb_func.c)
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/src")
target_link_libraries(${PROJECT_NAME} hidapi::hidapi argp-standalone)

Expand Down
3 changes: 3 additions & 0 deletions software/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash
# Part of the DigiLivolo control software.
# https://github.com/N-Storm/DigiLivolo/
#
# Builds project from sources with a cmake.
# If called with an argument "full" (build.sh full), does a full rebuild.
#
# SPDX-License-Identifier: GPL-3.0-or-later

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

Expand Down
22 changes: 22 additions & 0 deletions software/cmake/arm-linux-gnueabihf-gcc-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

SET (TRIPLET arm-linux-gnueabihf)
SET(CMAKE_C_COMPILER ${TRIPLET}-gcc)

# Build for Cortex-A7 if required
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-a7 -mtune=cortex-a7")

# set path(s) to search for libraries/binaries/headers
# SET (CMAKE_FIND_ROOT_PATH /usr/${TRIPLET} /usr/lib/${TRIPLET} /usr/include /usr/include/${TRIPLET})
# ensure only cross-dirs are searched
# SET (ONLY_CMAKE_FIND_ROOT_PATH TRUE)

# We have cross pkg-config installed instead
SET(PKG_CONFIG_EXECUTABLE ${TRIPLET}-pkg-config)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
119 changes: 119 additions & 0 deletions software/src/args.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* Part of the DigiLivolo control software.
* https://github.com/N-Storm/DigiLivolo/
* Copyright (c) 2024 GitHub user N-Storm.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#include "digilivolo.h"

#include <hidapi.h>
#include "usb_func.h"

#include "git_version.h"
#include "args.h"

// [argp] Program documentation.
// const char* argp_program_version = GIT_VERSION;
const char prognamever[] = "digilivolo " GIT_VERSION "\n";
const char doc[] = "\nSoftware to control DigiLivolo devices.\n";

const char* argp_program_bug_address = "https://github.com/N-Storm/DigiLivolo/\n\
Copyright (c) 2024 GitHub user N-Storm.\n\
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>";

// [argp] A description of the arguments we accept.
char args_doc[] = "REMOTE_ID KEY_ID";

// [argp] The options we understand.
struct argp_option options[] = {
{0, 0, 0, 0, "Positional arguments:" },
{"REMOTE_ID", 0, 0, OPTION_DOC | OPTION_NO_USAGE, "Livilo Remote ID (1-65535)" },
{"KEY_ID", 0, 0, OPTION_DOC | OPTION_NO_USAGE, "Livilo Key ID (1-255)" },
{0, 0, 0, 0, "Options:" },
{"verbose", 'v', 0, 0, "Produce verbose output" },
{ 0 }
};

// [argp] Command-line arguments.
arguments_t arguments;

// [argp] Parse a single option.
error_t parse_opt(int key, char* arg, struct argp_state* state)
{
/* Get the input argument from argp_parse, which we
* know is a pointer to our arguments structure. */
struct arguments* arguments = state->input;

switch (key) {
case 'v':
arguments->verbose = true;
break;

case ARGP_KEY_ARG:
if (state->arg_num >= 2)
// Too many arguments.
argp_usage(state);

char* endptr;
// Convert argument to long
long value = strtol(arg, &endptr, 0);
// Check if it was valid long value
if (*endptr == '\0') {
switch (state->arg_num) {
case 0:
// Out of range
if (value > 65535 || value <= 0)
argp_usage(state);
else
arguments->remote_id = (uint16_t)value;
break;

case 1:
// Out of range
if (value > 255 || value <= 0)
argp_usage(state);
else
arguments->key_id = (uint8_t)value;
break;

default:
return ARGP_ERR_UNKNOWN;
}
}
else
// REMOTE_ID or KEY_ID not an unsigned integer
argp_usage(state);

break;

case ARGP_KEY_END:
if (state->arg_num < 2)
// Not enough arguments.
argp_usage(state);
break;

default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
56 changes: 56 additions & 0 deletions software/src/args.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Part of the DigiLivolo control software.
* https://github.com/N-Storm/DigiLivolo/
* Copyright (c) 2024 GitHub user N-Storm.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef __args_h__
#define __args_h__

#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#include "digilivolo.h"

#include "git_version.h"
#include <argp.h>

// [argp] A description of the arguments we accept.
extern char args_doc[];

// [argp] The options we understand.
extern struct argp_option options[];

// [argp] Program documentation.
// const char* argp_program_version = GIT_VERSION;
extern const char prognamever[];
extern const char doc[];
extern const char* argp_program_bug_address;

// [argp] Command-line arguments.
typedef struct arguments {
uint16_t remote_id;
uint8_t key_id;
bool verbose;
} arguments_t;

extern arguments_t arguments;

extern error_t parse_opt(int key, char* arg, struct argp_state* state);

#endif // __args_h__
Loading

0 comments on commit e7916cf

Please sign in to comment.