Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7b8f62e
small beautifies
Keven1994 Nov 29, 2018
f757147
removed compiler warning unused parameter
Keven1994 Dec 11, 2018
0976a21
.
Keven1994 Dec 11, 2018
c60e1a3
more [[nodiscard]] constexpr ... noexcept
SetZero Dec 24, 2018
626799a
Merge remote-tracking branch 'origin/runtimechanges' into runtimechanges
SetZero Dec 24, 2018
eff51bb
some improvements
Keven1994 Jan 6, 2019
334d45d
Merge remote-tracking branch 'origin/runtimechanges' into runtimechanges
Keven1994 Jan 6, 2019
88ebf1a
.
Keven1994 Jan 6, 2019
1f71c2f
small improvements
SetZero Jan 7, 2019
e8db2e3
Merge remote-tracking branch 'origin/runtimechanges' into runtimechanges
SetZero Jan 7, 2019
e9efd80
cond exceptions
Keven1994 Jan 8, 2019
3d4dc14
small improvements
Keven1994 Jan 9, 2019
a110284
bugfix
Keven1994 Jan 9, 2019
54e8e02
Bugfix
SetZero Jan 14, 2019
32d4459
Merge remote-tracking branch 'origin/runtimechanges' into runtimechanges
SetZero Jan 14, 2019
5e93e01
Bugfix
SetZero Jan 14, 2019
55b4aca
cosmetic changes
Keven1994 Jan 15, 2019
00e2144
Merge remote-tracking branch 'origin/runtimechanges' into runtimechanges
Keven1994 Jan 15, 2019
48bba06
iterator for LibUSBDeviceList
SetZero Jan 19, 2019
0ae6316
Merge remote-tracking branch 'origin/runtimechanges' into runtimechanges
SetZero Jan 19, 2019
54b7b4f
Bugfixes + readability improvements
SetZero Jan 25, 2019
c4064be
Update README.md
SetZero Jan 26, 2019
433fe8b
Fix
SetZero Jan 30, 2019
afc61dd
Merge remote-tracking branch 'origin/runtimechanges' into runtimechanges
SetZero Jan 31, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)
project(SPI)

set(CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -ludev -Da4963_debug")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -ludev -O3 -Da4963_debug")

include_directories(.)
include_directories(inc)
Expand All @@ -17,8 +17,8 @@ add_executable(hid main.cpp)
find_library(LIBUSB_LIBRARY
NAMES usb-1.0)

find_library(LIBEVPP
NAMES libevpp.so)
find_library(UDEV
NAMES libudev.so)

find_path(LIBUSB_INCLUDE_DIR
NAMES libusb.h
Expand All @@ -44,32 +44,6 @@ FIND_LIBRARY(
${UDEV_PATH_LIB}
)

IF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)
SET(UDEV_FOUND "YES")
execute_process(COMMAND pkg-config --atleast-version=143 libudev RESULT_VARIABLE UDEV_STABLE)
# retvale is 0 of the condition is "true" so we need to negate the value...
if (UDEV_STABLE)
set(UDEV_STABLE 0)
else (UDEV_STABLE)
set(UDEV_STABLE 1)
endif (UDEV_STABLE)
MESSAGE("udev linked")
message(STATUS "libudev stable: ${UDEV_STABLE}")
ENDIF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)

IF (UDEV_FOUND)
MESSAGE(STATUS "Found UDev: ${UDEV_LIBRARIES}")
MESSAGE(STATUS " include: ${UDEV_INCLUDE_DIR}")
ELSE (UDEV_FOUND)
MESSAGE(STATUS "UDev not found.")
MESSAGE(STATUS "UDev: You can specify includes: -DUDEV_PATH_INCLUDES=/opt/udev/include")
MESSAGE(STATUS " currently found includes: ${UDEV_INCLUDE_DIR}")
MESSAGE(STATUS "UDev: You can specify libs: -DUDEV_PATH_LIB=/opt/udev/lib")
MESSAGE(STATUS " currently found libs: ${UDEV_LIBRARIES}")
IF (UDev_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find UDev library")
ENDIF (UDev_FIND_REQUIRED)
ENDIF (UDEV_FOUND)

## Include Directories

Expand All @@ -91,7 +65,7 @@ include_directories(src/CustomDataTypes)
add_subdirectory(src/CustomDataTypes)

# LIBEVPP
target_link_libraries(hid src spi usbb inc utils scales a4963 cdt ${LIBUSB_LIBRARY})
target_link_libraries(hid src spi usbb inc utils scales a4963 cdt ${UDEV} ${LIBUSB_LIBRARY})

#add_executable(SPI
# inc/mcp2210_api.c
Expand Down
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
hid
# Unofficial A4963 Flashing Software

This is an unofficial free A4963 flashing Software for Linux.

Used Libaries:
- [nlohmann JSON](https://github.com/nlohmann/json)
- [MCP2210 Linux Libary](https://www.microchip.com/wwwproducts/en/MCP2210)
- [cxxopts](https://github.com/jarro2783/cxxopts/blob/master/include/cxxopts.hpp)
- [spdlog](https://github.com/gabime/spdlog)

### Build
```sh
$ cd A4963
$ cmake .
$ make .
```

### Commands

| Plugin | README |
| ------ | ------ |
| -h, --help | Shows all command line arguments |
| -d, --debug | Enables debug output |
| -j, --json [file] | Selects the json file to read from |
| -g, --generate | Generates a default json file on startup, this will take -j location, if existing |
| -f, --force | This will overwrite any exiting settings file. Only possible if -g is specified |
| -c, --client | This will enable interactive client mode |
| -i, --interface [interface] | Select the interface to flash from. Possible values: "mcp" and "atmega" |
| -s, --settings-check | Only check if the settings file syntax is correct. This will **not** flash any data to the chip, even if an interface is specified! |

#### Examples:
```sh
# Read from config.json and flash with mcp2210
$ ./hid --json config.json --interface mcp
# same as above
$ ./hid -j config.json -i mcp
# additionally force generate config.json and show debug output
$ ./hid -gfd -j config.json -i mcp
```

### Development

- This Software is written in C++17
- Currently only tested on gcc
- A Windows build is available in the "Windows" branch. This branch is **not up to date**! If you want to use this software on Windows you can either open a ticket and I'll port it to the newest version if there is enough demand or help me port it by forking the repository and doing a pull-request.
32 changes: 19 additions & 13 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "src/SPI/ATmega32U4SPI.h"
#include "src/SPI/SPIBridge.h"
#include "inc/json.h"

#ifdef __linux__
#include "mcp2210_api.h"
#include "src/SPI/mcp2210_hal.h"
Expand All @@ -22,7 +23,7 @@
#include "src/Devices/A4963/DeserializeA4963.h"
#include "src/utils/scales/UnitScale.h"

int consoleInterface(const std::string& spiDevice);
int consoleInterface(const std::string& spiDevice,const std::string& config);
void flashJSON(const std::string& spiDevice, const std::string& filename, bool enable_debug = false);
int simpleInput(int min, int max);
int serverInterface(const char* spiDevice);
Expand All @@ -31,7 +32,8 @@ void parseArguments(int argc, char** argv);
static inline constexpr int nrOfOptions = 5;

void clearInput();
void loadFromFile(std::shared_ptr<NS_A4963::A4963>& device, const std::string& filename, bool enable_debug = false);
void flashFileFromDevice(std::shared_ptr<NS_A4963::A4963> &device, const std::string &filename,
bool enable_debug = false);
void setRegisterVal(std::shared_ptr<NS_A4963::A4963>& device);
void showRegisterVal(std::shared_ptr<NS_A4963::A4963>& device);
bool generateDefault(bool force = false, const std::string& filename = "config.json");
Expand Down Expand Up @@ -94,7 +96,11 @@ void parseArguments(int argc, char** argv) {

if(result.count("client") > 0 && result.count("interface") > 0) {
auto interface = result["interface"].as<std::string>();
consoleInterface(interface);
if(result.count("json") > 0)
consoleInterface(interface,result["json"].as<std::string>());
else{
consoleInterface(interface,"config.json");
}
return;
} else if(result.count("client") > 0 && result.count("interface") <= 0) {
std::cout << "Missing Parameter: --interface!" << std::endl;
Expand Down Expand Up @@ -161,8 +167,8 @@ void flashJSON(const std::string& spiDevice, const std::string& filename, bool e
return;
}
} else if(spiDevice == "mcp") {
spi = std::make_shared<MCP2210>();
pin = MCP2210::pin0;
spi = std::make_shared<MCP2210<>>();
pin = MCP2210<>::pin0;
} else if(spiDevice.empty()) {
spi = nullptr;
}
Expand All @@ -171,10 +177,10 @@ void flashJSON(const std::string& spiDevice, const std::string& filename, bool e
if(spi)
spi->slaveRegister(device, pin);

loadFromFile(device, filename, enable_debug);
flashFileFromDevice(device, filename, enable_debug);
}

int consoleInterface(const std::string& spiDevice){
int consoleInterface(const std::string& spiDevice, const std::string& config){
std::shared_ptr<NS_A4963::A4963> device;
std::shared_ptr<spi::SPIBridge> spi;
usb::LibUSBDeviceList deviceList;
Expand All @@ -190,17 +196,17 @@ int consoleInterface(const std::string& spiDevice){
return 0;
}
} else {
std::shared_ptr<MCP2210> dev = std::make_shared<MCP2210>();
std::shared_ptr<MCP2210<>> dev = std::make_shared<MCP2210<>>();
while(!*dev){
std::cout << " device not connected, try again?: y/n" << std::endl;
std::string str;
std::cin >> str;
std::getline(std::cin,str);
if(str == "y")
dev->connect();
else break;
}
spi = dev;
pin = MCP2210::pin0;
pin = MCP2210<>::pin0;
}
device = std::make_shared<NS_A4963::A4963>(spi);
spi->slaveRegister(device, pin);
Expand All @@ -210,7 +216,7 @@ int consoleInterface(const std::string& spiDevice){
int choice = simpleInput(1, nrOfOptions);
switch (choice) {
case 1: {
loadFromFile(device, "config.json");
flashFileFromDevice(device, config);
break;
}
case 2: {
Expand Down Expand Up @@ -273,7 +279,7 @@ bool generateDefault(bool force, const std::string& filename){
void setRegisterVal(std::shared_ptr<NS_A4963::A4963>& device){
std::cout << "Enter the name of the register you want to set, or \"exit\" to cancel" << std::endl;
std::string str;
NS_A4963::A4963RegisterNames mask;
NS_A4963::A4963RegisterNames mask{};
while(true) {
std::getline(std::cin,str);
if (str == "exit") break;
Expand All @@ -297,7 +303,7 @@ void setRegisterVal(std::shared_ptr<NS_A4963::A4963>& device){
}
}

void loadFromFile(std::shared_ptr<NS_A4963::A4963>& device, const std::string& filename, bool enable_debug){
void flashFileFromDevice(std::shared_ptr<NS_A4963::A4963> &device, const std::string &filename, bool enable_debug){
using namespace nlohmann;
using namespace NS_A4963;

Expand Down
26 changes: 13 additions & 13 deletions src/CustomDataTypes/Hertz.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace CustomDataTypes::Frequency {
using parent_type = SIUnit<Hertz<Rep, Period>, Rep, Period>;
public:
static constexpr std::string_view abr_value = "Hz";
constexpr explicit Hertz(Rep input) : parent_type{input} {}
constexpr explicit Hertz(Rep input) noexcept : parent_type{input} {}
};

using nanohertz = Hertz<std::intmax_t, std::nano>;
Expand All @@ -33,51 +33,51 @@ namespace CustomDataTypes::Frequency {
using exahertz = Hertz<std::intmax_t, std::exa>;

namespace literals {
constexpr nanohertz operator ""_nHz(unsigned long long element) {
constexpr nanohertz operator ""_nHz(unsigned long long element) noexcept {
return nanohertz(static_cast<std::intmax_t>(element));
}

constexpr Hertz<long double, std::nano> operator ""_nHz(long double element) {
constexpr Hertz<long double, std::nano> operator ""_nHz(long double element) noexcept {
return Hertz<long double, std::nano>(element);
}

constexpr microhertz operator ""_uHz(unsigned long long element) {
constexpr microhertz operator ""_uHz(unsigned long long element) noexcept {
return microhertz(static_cast<std::intmax_t>(element));
}

constexpr Hertz<long double, std::micro> operator ""_uHz(long double element) {
constexpr Hertz<long double, std::micro> operator ""_uHz(long double element) noexcept {
return Hertz<long double, std::micro>(element);
}

constexpr millihertz operator ""_mHz(unsigned long long element) {
constexpr millihertz operator ""_mHz(unsigned long long element) noexcept {
return millihertz(static_cast<std::intmax_t>(element));
}

constexpr Hertz<long double, std::milli> operator ""_mHz(long double element) {
constexpr Hertz<long double, std::milli> operator ""_mHz(long double element) noexcept {
return Hertz<long double, std::milli>(element);
}

constexpr hertz operator ""_Hz(unsigned long long element) {
constexpr hertz operator ""_Hz(unsigned long long element) noexcept {
return hertz(static_cast<std::intmax_t>(element));
}

constexpr Hertz<long double> operator ""_Hz(long double element) {
constexpr Hertz<long double> operator ""_Hz(long double element) noexcept {
return Hertz<long double>(element);
}

constexpr kilohertz operator ""_kHz(unsigned long long element) {
constexpr kilohertz operator ""_kHz(unsigned long long element) noexcept {
return kilohertz(static_cast<std::intmax_t>(element));
}

constexpr Hertz<long double, std::kilo> operator ""_kHz(long double element) {
constexpr Hertz<long double, std::kilo> operator ""_kHz(long double element) noexcept {
return Hertz<long double, std::kilo>(element);
}

constexpr megahertz operator ""_MHz(unsigned long long element) {
constexpr megahertz operator ""_MHz(unsigned long long element) noexcept {
return megahertz(static_cast<std::intmax_t>(element));
}

constexpr Hertz<long double, std::mega> operator ""_MHz(long double element) {
constexpr Hertz<long double, std::mega> operator ""_MHz(long double element) noexcept {
return Hertz<long double, std::mega>(element);
}
}
Expand Down
Loading