Saved working stuff
This commit is contained in:
66
vn-interface/CMakeLists.txt
Normal file
66
vn-interface/CMakeLists.txt
Normal file
@ -0,0 +1,66 @@
|
||||
project(vn-interface)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
set(CMAKE_TOOLCHAIN_FILE gcc-arm-none-eabi.cmake)
|
||||
|
||||
# include for standard directories
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# include for creating config.cmake
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
set(SOURCES src/vn200.cpp)
|
||||
|
||||
set(CPU_PARAMETERS
|
||||
-mcpu=cortex-m4
|
||||
-mthumb
|
||||
-mfpu=fpv4-sp-d16
|
||||
-mfloat-abi=hard)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
${CPU_PARAMETERS}
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wno-unused-parameter
|
||||
$<$<COMPILE_LANGUAGE:CXX>:
|
||||
-Wno-volatile
|
||||
-Wsuggest-override
|
||||
-Wno-missing-field-initializers>
|
||||
$<$<CONFIG:Debug>:-Og -g3 -ggdb>
|
||||
$<$<CONFIG:Release>:-Og -g0>)
|
||||
|
||||
# Link the desire include directories of the library - different for build and install
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE vn-interface::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
)
|
||||
4
vn-interface/Config.cmake.in
Normal file
4
vn-interface/Config.cmake.in
Normal file
@ -0,0 +1,4 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/vn-interfaceTargets.cmake")
|
||||
|
||||
23
vn-interface/gcc-arm-none-eabi.cmake
Normal file
23
vn-interface/gcc-arm-none-eabi.cmake
Normal file
@ -0,0 +1,23 @@
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
# Some default GCC settings
|
||||
set(TOOLCHAIN_PREFIX arm-none-eabi-)
|
||||
set(FLAGS
|
||||
"-fdata-sections -ffunction-sections \
|
||||
--specs=nano.specs -Wl,--gc-sections")
|
||||
set(CPP_FLAGS
|
||||
"-fno-rtti -fno-exceptions \
|
||||
-fno-threadsafe-statics")
|
||||
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS})
|
||||
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS})
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
|
||||
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)
|
||||
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")
|
||||
set(CMAKE_LINK_LIBRARY_SUFFIX ".elf")
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
206
vn-interface/include/vn-interface/vn200.h
Normal file
206
vn-interface/include/vn-interface/vn200.h
Normal file
@ -0,0 +1,206 @@
|
||||
#ifndef _VN200_
|
||||
#define _VN200_
|
||||
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#define VN200_SPI_READ 0x01
|
||||
#define VN200_SPI_WRITE 0x02
|
||||
|
||||
namespace VN200 {
|
||||
namespace SPI {
|
||||
namespace BinaryGroups {
|
||||
typedef uint8_t bit_offset_t;
|
||||
namespace Group1 {
|
||||
// /* The bit offset of group 1 */
|
||||
// const bit_offset_t BitOffset = 0;
|
||||
// /* The output fields of group 1 */
|
||||
// enum OutputFields {
|
||||
// TimeStartup = 0,
|
||||
// TimeGps,
|
||||
// TimeSyncIn,
|
||||
// YawPitchRoll,
|
||||
// Quaternion,
|
||||
// AngularRate,
|
||||
// Position,
|
||||
// Velocity,
|
||||
// Accel,
|
||||
// Imu,
|
||||
// MagPres,
|
||||
// DeltaTheta,
|
||||
// InsStatus,
|
||||
// SyncInCnt,
|
||||
// TimeGpsPps,
|
||||
// EMPTY15
|
||||
// };
|
||||
|
||||
// /* TODO */
|
||||
// const uint8_t payload_sizes[16] = {8, 8, 8, 12, 16, 12, 24, 12, 12, 24, 20, 28, 2, 4, 8, 0};
|
||||
} // namespace Group1
|
||||
} // namespace BinaryGroups
|
||||
|
||||
// /* Abstract base class for all packages. */
|
||||
// struct binary_package_t {
|
||||
// /* TODO */
|
||||
// binary_package_t(){};
|
||||
// /* TODO */
|
||||
// virtual uint16_t size() = 0;
|
||||
// /* TODO */
|
||||
// virtual uint8_t *to_array() = 0;
|
||||
|
||||
// std::vector<uint8_t> v;
|
||||
// };
|
||||
|
||||
/* TODO */
|
||||
union header_t {
|
||||
struct request_t {
|
||||
uint8_t Cmd = 0; /* Defined in VN200_SPI_READ - set in standard constructor */
|
||||
uint8_t ID = 0; /* Register ID */
|
||||
uint16_t Empty = 0; /* Spacer */
|
||||
request_t(uint8_t ID, uint8_t Cmd) {
|
||||
this->ID = ID;
|
||||
this->Cmd = Cmd;
|
||||
};
|
||||
};
|
||||
struct response_t {
|
||||
uint8_t Empty1 = 0; /* Spacer */
|
||||
uint8_t Cmd = 0; /* Defined in VN200_SPI_READ - set in standard constructor */
|
||||
uint8_t ID = 0; /* Register ID */
|
||||
uint8_t Empty2 = 0; /* Spacer */
|
||||
response_t(){};
|
||||
response_t(uint8_t ID, uint8_t Cmd) {
|
||||
this->ID = ID;
|
||||
this->Cmd = Cmd;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/* TODO */
|
||||
// struct configuration_t : binary_package_t {
|
||||
// uint16_t AsyncMode;
|
||||
// uint16_t RateDivisor;
|
||||
// uint16_t OutputGroup;
|
||||
// uint8_t NumOutputFields;
|
||||
// uint16_t *OutputFields; /* Array with unknown size. Set in constructor. */
|
||||
// /* TODO */
|
||||
// configuration_t(uint8_t NumOutputFields = 1 /* TODO */) {
|
||||
// OutputFields = new uint16_t[NumOutputFields];
|
||||
// this->NumOutputFields = NumOutputFields;
|
||||
// };
|
||||
// /* TODO */
|
||||
// ~configuration_t() {
|
||||
// delete OutputFields;
|
||||
// OutputFields = nullptr;
|
||||
// }
|
||||
// /* TODO */
|
||||
// uint16_t size() override;
|
||||
// /* TODO */
|
||||
// uint8_t *to_array() override;
|
||||
// /* TODO */
|
||||
// void setBinaryGroups(std::vector<SPI::BinaryGroups::bit_offset_t> desired_groups);
|
||||
// /* TODO */
|
||||
// void setOutputFields(SPI::BinaryGroups::bit_offset_t group_bit_offset, std::vector<int> desired_output_fields);
|
||||
// };
|
||||
|
||||
/* Writes the desired payload into the specified register */
|
||||
template <typename payload_t> struct pkg_request_write_t {
|
||||
struct header_t::request_t header;
|
||||
payload_t payload;
|
||||
/* TODO */
|
||||
pkg_request_write_t(uint8_t ID) : header(ID, VN200_SPI_WRITE){};
|
||||
};
|
||||
|
||||
/* Writes the desired payload into the specified register */
|
||||
struct pkg_request_read_t {
|
||||
struct header_t::request_t header;
|
||||
/* TODO */
|
||||
pkg_request_read_t(uint8_t ID) : header(ID, VN200_SPI_READ){};
|
||||
};
|
||||
|
||||
/* Writes the desired payload into the specified register */
|
||||
template <typename payload_t> struct pkg_response_t {
|
||||
struct header_t::response_t header;
|
||||
payload_t payload;
|
||||
/* TODO */
|
||||
pkg_response_t() : header(){};
|
||||
};
|
||||
|
||||
namespace IMU {
|
||||
const uint8_t ID = 54;
|
||||
struct imu_t {
|
||||
float MagX = 0.0;
|
||||
float MagY = 0.0;
|
||||
float MagZ = 0.0;
|
||||
float AccelX = 0.0;
|
||||
float AccelY = 0.0;
|
||||
float AccelZ = 0.0;
|
||||
float GyroX = 0.0;
|
||||
float GyroY = 0.0;
|
||||
float GyroZ = 0.0;
|
||||
float Pressure = 0.0;
|
||||
};
|
||||
} // namespace IMU
|
||||
namespace ATT {
|
||||
const uint8_t ID = 239;
|
||||
struct attitude_t {
|
||||
float Yaw = 0.0;
|
||||
float Pitch = 0.0;
|
||||
float Roll = 0.0;
|
||||
float BodyAccelX = 0.0;
|
||||
float BodyAccelY = 0.0;
|
||||
float BodyAccelZ = 0.0;
|
||||
float GyroX = 0.0;
|
||||
float GyroY = 0.0;
|
||||
float GyroZ = 0.0;
|
||||
};
|
||||
} // namespace ATT
|
||||
namespace INS {
|
||||
namespace LLA {
|
||||
const uint8_t ID = 63;
|
||||
struct lla_t {
|
||||
float Yaw = 0.0;
|
||||
float Pitch = 0.0;
|
||||
float Roll = 0.0;
|
||||
double Lattitude = 0.0;
|
||||
double Longitude = 0.0;
|
||||
double Altitude = 0.0;
|
||||
float VelocityX = 0.0;
|
||||
float VelocityY = 0.0;
|
||||
float VelocityZ = 0.0;
|
||||
float AccelX = 0.0;
|
||||
float AccelY = 0.0;
|
||||
float AccelZ = 0.0;
|
||||
float AngularRateX = 0.0;
|
||||
float AngularRateY = 0.0;
|
||||
float AngularRateZ = 0.0;
|
||||
};
|
||||
} // namespace LLA
|
||||
} // namespace INS
|
||||
namespace GPS {
|
||||
namespace LLA {
|
||||
const uint8_t ID = 58;
|
||||
struct lla_t {
|
||||
double Time = 0.0;
|
||||
uint16_t Week = 0;
|
||||
uint8_t GpsFix = 0;
|
||||
uint8_t NumSats = 0;
|
||||
uint32_t PADDING = 0;
|
||||
double Latitude = 0.0;
|
||||
double Longitude = 0.0;
|
||||
double Altitude = 0.0;
|
||||
float NedVelX = 0.0;
|
||||
float NedVelY = 0.0;
|
||||
float NedVelZ = 0.0;
|
||||
float NorthAcc = 0.0;
|
||||
float EastAcc = 0.0;
|
||||
float VertAcc = 0.0;
|
||||
float SpeedAcc = 0.0;
|
||||
float TimeAcc = 0.0;
|
||||
};
|
||||
} // namespace LLA
|
||||
} // namespace GPS
|
||||
} // namespace SPI
|
||||
} // namespace VN200
|
||||
|
||||
#endif
|
||||
70
vn-interface/src/vn200.cpp
Normal file
70
vn-interface/src/vn200.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
#include "vn-interface/vn200.h"
|
||||
|
||||
namespace VN200 {
|
||||
namespace SPI {
|
||||
|
||||
// payload_size_t::payload_size_t() {
|
||||
// group1 = {{BinaryGroups::Group1::TimeStartup, 8}, {BinaryGroups::Group1::TimeGps, 8}, {BinaryGroups::Group1::TimeSyncIn, 8},
|
||||
// {BinaryGroups::Group1::YawPitchRoll, 12}, {BinaryGroups::Group1::Quaternion, 16}, {BinaryGroups::Group1::AngularRate, 12},
|
||||
// {BinaryGroups::Group1::Position, 24}, {BinaryGroups::Group1::Velocity, 12}, {BinaryGroups::Group1::Accel, 12},
|
||||
// {BinaryGroups::Group1::Imu, 24}, {BinaryGroups::Group1::MagPres, 20}, {BinaryGroups::Group1::DeltaTheta, 28},
|
||||
// {BinaryGroups::Group1::InsStatus, 2}, {BinaryGroups::Group1::SyncInCnt, 4}, {BinaryGroups::Group1::TimeGpsPps, 8},
|
||||
// {BinaryGroups::Group1::EMPTY15, 0}};
|
||||
// }
|
||||
|
||||
// uint16_t configuration_t::size() { return sizeof(AsyncMode) + sizeof(RateDivisor) + sizeof(OutputGroup) + NumOutputFields * sizeof(uint16_t); }
|
||||
|
||||
// uint8_t *configuration_t::to_array() {
|
||||
// v.clear();
|
||||
// v.push_back(AsyncMode && 0xFF);
|
||||
// v.push_back(AsyncMode >> 8);
|
||||
// v.push_back(RateDivisor && 0xFF);
|
||||
// v.push_back(RateDivisor >> 8);
|
||||
// v.push_back(OutputGroup && 0xFF);
|
||||
// v.push_back(OutputGroup >> 8);
|
||||
// for (uint8_t i = 0; i < NumOutputFields; i++) {
|
||||
// v.push_back(OutputFields[i] && 0xFF);
|
||||
// v.push_back(OutputFields[i] >> 8);
|
||||
// }
|
||||
// return &v[0];
|
||||
// }
|
||||
|
||||
// void configuration_t::setBinaryGroups(std::vector<SPI::BinaryGroups::bit_offset_t> desired_groups) {
|
||||
// bool hit = false;
|
||||
// /* Iterate over every bit of the OutputGroup */
|
||||
// for (uint8_t i = 0; i < 8; i++) {
|
||||
// for (auto desired_group : desired_groups) {
|
||||
// if (desired_group == i) {
|
||||
// hit = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (hit) {
|
||||
// OutputGroup++;
|
||||
// hit = false;
|
||||
// }
|
||||
// OutputGroup = OutputGroup << 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// void configuration_t::setOutputFields(SPI::BinaryGroups::bit_offset_t group_bit_offset, std::vector<int> desired_output_fields) {
|
||||
// bool hit = false;
|
||||
// /* Iterate over every bit of the OutputGroup */
|
||||
// for (uint8_t i = 0; i < 16; i++) {
|
||||
// for (auto desired_output_field : desired_output_fields) {
|
||||
// if (desired_output_field == i) {
|
||||
// hit = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (hit) {
|
||||
// OutputFields[group_bit_offset]++;
|
||||
// hit = false;
|
||||
// }
|
||||
// OutputFields[group_bit_offset] = OutputFields[group_bit_offset] << 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
} // namespace SPI
|
||||
// namespace SPI
|
||||
} // namespace VN200
|
||||
Reference in New Issue
Block a user