diff --git a/ArduinoI2C/ArduinoI2C.ino b/ArduinoI2C/ArduinoI2C.ino new file mode 100644 index 00000000..39d491a7 --- /dev/null +++ b/ArduinoI2C/ArduinoI2C.ino @@ -0,0 +1,56 @@ + +#include +#include "odrive.h" + + +// See odrive.h for a description +bool I2C_transaction(uint8_t slave_addr, const uint8_t * tx_buffer, size_t tx_length, uint8_t * rx_buffer, size_t rx_length) { + // transmit + if (tx_buffer) { + Wire.beginTransmission(slave_addr); + if (Wire.write(tx_buffer, tx_length) != tx_length) + return false; + bool should_stop = !rx_buffer; + if (Wire.endTransmission(should_stop) != 0) + return false; + } + + // receive + if (rx_buffer) { + while(Wire.available()) Wire.read(); // flush input buffer + if (Wire.requestFrom(slave_addr, (uint8_t)rx_length, (uint8_t)true /* stop after receiving */) != rx_length) + return false; + for (size_t i = 0; i < rx_length; ++i) + rx_buffer[i] = Wire.read(); + } + + return true; +} + + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); +} + +byte odrive_num = 7; +byte x; + +void loop() { + bool success; + + float val; + success = odrive::read_property(odrive_num, &val); + if (success) { + Serial.println(val, HEX); + } else { + Serial.println("error"); + } + + success = odrive::write_property(odrive_num, x++); + if (!success) + Serial.println("error"); + + delay(500); +} + diff --git a/ArduinoI2C/odrive.h b/ArduinoI2C/odrive.h new file mode 100644 index 00000000..fb89ccb5 --- /dev/null +++ b/ArduinoI2C/odrive.h @@ -0,0 +1,143 @@ +/* +* ODrive I2C communication library +* This file implements I2C communication with the ODrive. +* +* - Implement the C function I2C_transaction to provide low level I2C access. +* - Use read_property() to read properties from the ODrive. +* - Use write_property() to modify properties on the ODrive. +* - Use endpoint_type_t to retrieve the underlying type +* of a given property. +* +* To regenerate the interface definitions, flash an ODrive with the new +* firmware, then run +* ../tools/odrivetool generate-code --output odrive_endpoints.h +*/ + + +#include +#include + +#include "odrive_endpoints.h" + +#ifdef __AVR__ +// AVR-GCC doesn't ship with the STL, so we use our own little excerpt +#include "type_traits.h" +#else +#include +#endif + + +extern "C" { + +/* @brief Send and receive data to/from an I2C slave +* +* This function carries out the following sequence: +* 1. generate a START condition +* 2. if the tx_buffer is not null: +* a. send 7-bit slave address (with the LSB 0) +* b. send all bytes in the tx_buffer +* 3. if both tx_buffer and rx_buffer are not null, generate a REPEATED START condition +* 4. if the rx_buffer is not null: +* a. send 7-bit slave address (with the LSB 1) +* b. read rx_length bytes into rx_buffer +* 5. send STOP condition +* +* @param slave_addr: 7-bit slave address (the MSB is ignored) +* @return true if all data was transmitted and received as requested by the caller, false otherwise +*/ +bool I2C_transaction(uint8_t slave_addr, const uint8_t * tx_buffer, size_t tx_length, uint8_t * rx_buffer, size_t rx_length); + +} + + +namespace odrive { + static constexpr const uint8_t i2c_addr = (0xD << 3); // write: 1101xxx0, read: 1101xxx1 + + template + using bit_width = std::integral_constant; + + template + using byte_width = std::integral_constant::value + 7) / 8>; + + + template + struct unsigned_int_of_size; + + template<> struct unsigned_int_of_size<32> { typedef uint32_t type; }; + + + template + typename std::enable_if::value, T>::type + read_le(const uint8_t buffer[byte_width::value]) { + T value = 0; + for (size_t i = 0; i < byte_width::value; ++i) + value |= (static_cast(buffer[i]) << (i << 3)); + return value; + } + + template + typename std::enable_if::value, T>::type + read_le(const uint8_t buffer[]) { + using T_Int = typename unsigned_int_of_size::value>::type; + T_Int value = read_le(buffer); + return *reinterpret_cast(&value); + } + + template + typename std::enable_if::value, void>::type + write_le(uint8_t buffer[byte_width::value], T value) { + for (size_t i = 0; i < byte_width::value; ++i) + buffer[i] = (value >> (i << 3)) & 0xff; + } + + template + typename std::enable_if::value, T>::type + write_le(uint8_t buffer[byte_width::value], T value) { + using T_Int = typename unsigned_int_of_size::value>::type; + write_le(buffer, *reinterpret_cast(&value)); + } + + /* @brief Read from an endpoint on the ODrive + * + * Usage example: + * float val; + * success = odrive::read_property(0, &val); + * + * @param num Selects the ODrive. For instance the value 4 selects + * the ODrive that has [A2, A1, A0] connected to [VCC, GND, GND]. + * @return true if the I2C transaction succeeded, false otherwise + */ + template + bool read_property(uint8_t num, endpoint_type_t* value) { + uint8_t i2c_tx_buffer[4]; + write_le(i2c_tx_buffer, IPropertyId); + write_le(i2c_tx_buffer + sizeof(i2c_tx_buffer) - 2, json_crc); + uint8_t i2c_rx_buffer[byte_width>::value]; + if (!I2C_transaction(i2c_addr + num, + i2c_tx_buffer, sizeof(i2c_tx_buffer), + i2c_rx_buffer, sizeof(i2c_rx_buffer))) + return false; + if (value) + *value = read_le>(i2c_rx_buffer); + return true; + } + + /* @brief Write to an endpoint on the ODrive + * + * Usage example: + * success = odrive::write_property(0, 10000); + * + * @param num Selects the ODrive. For instance the value 4 selects + * the ODrive that has [A2, A1, A0] connected to [VCC, GND, GND]. + * @return true if the I2C transaction succeeded, false otherwise + */ + template + bool write_property(uint8_t num, endpoint_type_t value) { + uint8_t i2c_tx_buffer[4 + byte_width>::value]; + write_le(i2c_tx_buffer, IPropertyId); + write_le>(i2c_tx_buffer + 2, value); + write_le(i2c_tx_buffer + sizeof(i2c_tx_buffer) - 2, json_crc); + return I2C_transaction(i2c_addr + num, i2c_tx_buffer, sizeof(i2c_tx_buffer), nullptr, 0); + } + +} diff --git a/ArduinoI2C/odrive_endpoints.h b/ArduinoI2C/odrive_endpoints.h new file mode 100644 index 00000000..e8e4ee98 --- /dev/null +++ b/ArduinoI2C/odrive_endpoints.h @@ -0,0 +1,444 @@ +/* +* This file was autogenerated using the "odrivetool generate-code" feature. +* +* The file matches a specific firmware version. If you add/remove/rename any +* properties exposed by the ODrive, this file needs to be regenerated, otherwise +* the ODrive will ignore all commands. +*/ + +#ifndef __ODRIVE_ENDPOINTS_HPP +#define __ODRIVE_ENDPOINTS_HPP + + +namespace odrive { + +static constexpr const uint16_t json_crc = 0x7199; + +enum { + VBUS_VOLTAGE = 1, + SERIAL_NUMBER = 2, + HW_VERSION_MAJOR = 3, + HW_VERSION_MINOR = 4, + HW_VERSION_VARIANT = 5, + FW_VERSION_MAJOR = 6, + FW_VERSION_MINOR = 7, + FW_VERSION_REVISION = 8, + FW_VERSION_UNRELEASED = 9, + USER_CONFIG_LOADED = 10, + BRAKE_RESISTOR_ARMED = 11, + SYSTEM_STATS__UPTIME = 12, + SYSTEM_STATS__MIN_HEAP_SPACE = 13, + SYSTEM_STATS__MIN_STACK_SPACE_AXIS0 = 14, + SYSTEM_STATS__MIN_STACK_SPACE_AXIS1 = 15, + SYSTEM_STATS__MIN_STACK_SPACE_COMMS = 16, + SYSTEM_STATS__MIN_STACK_SPACE_USB = 17, + SYSTEM_STATS__MIN_STACK_SPACE_UART = 18, + SYSTEM_STATS__MIN_STACK_SPACE_USB_IRQ = 19, + SYSTEM_STATS__MIN_STACK_SPACE_STARTUP = 20, + SYSTEM_STATS__USB__RX_CNT = 21, + SYSTEM_STATS__USB__TX_CNT = 22, + SYSTEM_STATS__USB__TX_OVERRUN_CNT = 23, + SYSTEM_STATS__I2C__ADDR = 24, + SYSTEM_STATS__I2C__ADDR_MATCH_CNT = 25, + SYSTEM_STATS__I2C__RX_CNT = 26, + SYSTEM_STATS__I2C__ERROR_CNT = 27, + CONFIG__BRAKE_RESISTANCE = 28, + CONFIG__ENABLE_UART = 29, + CONFIG__ENABLE_I2C_INSTEAD_OF_CAN = 30, + CONFIG__DC_BUS_UNDERVOLTAGE_TRIP_LEVEL = 31, + CONFIG__DC_BUS_OVERVOLTAGE_TRIP_LEVEL = 32, + AXIS0__ERROR = 33, + AXIS0__ENABLE_STEP_DIR = 34, + AXIS0__CURRENT_STATE = 35, + AXIS0__REQUESTED_STATE = 36, + AXIS0__LOOP_COUNTER = 37, + AXIS0__CONFIG__STARTUP_MOTOR_CALIBRATION = 38, + AXIS0__CONFIG__STARTUP_ENCODER_INDEX_SEARCH = 39, + AXIS0__CONFIG__STARTUP_ENCODER_OFFSET_CALIBRATION = 40, + AXIS0__CONFIG__STARTUP_CLOSED_LOOP_CONTROL = 41, + AXIS0__CONFIG__STARTUP_SENSORLESS_CONTROL = 42, + AXIS0__CONFIG__ENABLE_STEP_DIR = 43, + AXIS0__CONFIG__COUNTS_PER_STEP = 44, + AXIS0__CONFIG__RAMP_UP_TIME = 45, + AXIS0__CONFIG__RAMP_UP_DISTANCE = 46, + AXIS0__CONFIG__SPIN_UP_CURRENT = 47, + AXIS0__CONFIG__SPIN_UP_ACCELERATION = 48, + AXIS0__CONFIG__SPIN_UP_TARGET_VEL = 49, + AXIS0__MOTOR__ERROR = 50, + AXIS0__MOTOR__ARMED_STATE = 51, + AXIS0__MOTOR__IS_CALIBRATED = 52, + AXIS0__MOTOR__CURRENT_MEAS_PHB = 53, + AXIS0__MOTOR__CURRENT_MEAS_PHC = 54, + AXIS0__MOTOR__DC_CALIB_PHB = 55, + AXIS0__MOTOR__DC_CALIB_PHC = 56, + AXIS0__MOTOR__PHASE_CURRENT_REV_GAIN = 57, + AXIS0__MOTOR__CURRENT_CONTROL__P_GAIN = 58, + AXIS0__MOTOR__CURRENT_CONTROL__I_GAIN = 59, + AXIS0__MOTOR__CURRENT_CONTROL__V_CURRENT_CONTROL_INTEGRAL_D = 60, + AXIS0__MOTOR__CURRENT_CONTROL__V_CURRENT_CONTROL_INTEGRAL_Q = 61, + AXIS0__MOTOR__CURRENT_CONTROL__IBUS = 62, + AXIS0__MOTOR__CURRENT_CONTROL__FINAL_V_ALPHA = 63, + AXIS0__MOTOR__CURRENT_CONTROL__FINAL_V_BETA = 64, + AXIS0__MOTOR__CURRENT_CONTROL__IQ_SETPOINT = 65, + AXIS0__MOTOR__CURRENT_CONTROL__IQ_MEASURED = 66, + AXIS0__MOTOR__CURRENT_CONTROL__MAX_ALLOWED_CURRENT = 67, + AXIS0__MOTOR__GATE_DRIVER__DRV_FAULT = 68, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_GENERAL = 69, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_ADC_CB_I = 70, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_ADC_CB_DC = 71, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_MEAS_R = 72, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_MEAS_L = 73, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_ENC_CALIB = 74, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_IDX_SEARCH = 75, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_FOC_VOLTAGE = 76, + AXIS0__MOTOR__TIMING_LOG__TIMING_LOG_FOC_CURRENT = 77, + AXIS0__MOTOR__CONFIG__PRE_CALIBRATED = 78, + AXIS0__MOTOR__CONFIG__POLE_PAIRS = 79, + AXIS0__MOTOR__CONFIG__CALIBRATION_CURRENT = 80, + AXIS0__MOTOR__CONFIG__RESISTANCE_CALIB_MAX_VOLTAGE = 81, + AXIS0__MOTOR__CONFIG__PHASE_INDUCTANCE = 82, + AXIS0__MOTOR__CONFIG__PHASE_RESISTANCE = 83, + AXIS0__MOTOR__CONFIG__DIRECTION = 84, + AXIS0__MOTOR__CONFIG__MOTOR_TYPE = 85, + AXIS0__MOTOR__CONFIG__CURRENT_LIM = 86, + AXIS0__CONTROLLER__POS_SETPOINT = 87, + AXIS0__CONTROLLER__VEL_SETPOINT = 88, + AXIS0__CONTROLLER__VEL_INTEGRATOR_CURRENT = 89, + AXIS0__CONTROLLER__CURRENT_SETPOINT = 90, + AXIS0__CONTROLLER__CONFIG__CONTROL_MODE = 91, + AXIS0__CONTROLLER__CONFIG__POS_GAIN = 92, + AXIS0__CONTROLLER__CONFIG__VEL_GAIN = 93, + AXIS0__CONTROLLER__CONFIG__VEL_INTEGRATOR_GAIN = 94, + AXIS0__CONTROLLER__CONFIG__VEL_LIMIT = 95, + AXIS0__ENCODER__ERROR = 106, + AXIS0__ENCODER__IS_READY = 107, + AXIS0__ENCODER__INDEX_FOUND = 108, + AXIS0__ENCODER__SHADOW_COUNT = 109, + AXIS0__ENCODER__COUNT_IN_CPR = 110, + AXIS0__ENCODER__OFFSET = 111, + AXIS0__ENCODER__PHASE = 112, + AXIS0__ENCODER__POS_ESTIMATE = 113, + AXIS0__ENCODER__POS_CPR = 114, + AXIS0__ENCODER__PLL_VEL = 115, + AXIS0__ENCODER__PLL_KP = 116, + AXIS0__ENCODER__PLL_KI = 117, + AXIS0__ENCODER__CONFIG__USE_INDEX = 118, + AXIS0__ENCODER__CONFIG__PRE_CALIBRATED = 119, + AXIS0__ENCODER__CONFIG__IDX_SEARCH_SPEED = 120, + AXIS0__ENCODER__CONFIG__CPR = 121, + AXIS0__ENCODER__CONFIG__OFFSET = 122, + AXIS0__ENCODER__CONFIG__CALIB_RANGE = 123, + AXIS0__SENSORLESS_ESTIMATOR__ERROR = 124, + AXIS0__SENSORLESS_ESTIMATOR__PHASE = 125, + AXIS0__SENSORLESS_ESTIMATOR__PLL_POS = 126, + AXIS0__SENSORLESS_ESTIMATOR__PLL_VEL = 127, + AXIS0__SENSORLESS_ESTIMATOR__PLL_KP = 128, + AXIS0__SENSORLESS_ESTIMATOR__PLL_KI = 129, + AXIS1__ERROR = 130, + AXIS1__ENABLE_STEP_DIR = 131, + AXIS1__CURRENT_STATE = 132, + AXIS1__REQUESTED_STATE = 133, + AXIS1__LOOP_COUNTER = 134, + AXIS1__CONFIG__STARTUP_MOTOR_CALIBRATION = 135, + AXIS1__CONFIG__STARTUP_ENCODER_INDEX_SEARCH = 136, + AXIS1__CONFIG__STARTUP_ENCODER_OFFSET_CALIBRATION = 137, + AXIS1__CONFIG__STARTUP_CLOSED_LOOP_CONTROL = 138, + AXIS1__CONFIG__STARTUP_SENSORLESS_CONTROL = 139, + AXIS1__CONFIG__ENABLE_STEP_DIR = 140, + AXIS1__CONFIG__COUNTS_PER_STEP = 141, + AXIS1__CONFIG__RAMP_UP_TIME = 142, + AXIS1__CONFIG__RAMP_UP_DISTANCE = 143, + AXIS1__CONFIG__SPIN_UP_CURRENT = 144, + AXIS1__CONFIG__SPIN_UP_ACCELERATION = 145, + AXIS1__CONFIG__SPIN_UP_TARGET_VEL = 146, + AXIS1__MOTOR__ERROR = 147, + AXIS1__MOTOR__ARMED_STATE = 148, + AXIS1__MOTOR__IS_CALIBRATED = 149, + AXIS1__MOTOR__CURRENT_MEAS_PHB = 150, + AXIS1__MOTOR__CURRENT_MEAS_PHC = 151, + AXIS1__MOTOR__DC_CALIB_PHB = 152, + AXIS1__MOTOR__DC_CALIB_PHC = 153, + AXIS1__MOTOR__PHASE_CURRENT_REV_GAIN = 154, + AXIS1__MOTOR__CURRENT_CONTROL__P_GAIN = 155, + AXIS1__MOTOR__CURRENT_CONTROL__I_GAIN = 156, + AXIS1__MOTOR__CURRENT_CONTROL__V_CURRENT_CONTROL_INTEGRAL_D = 157, + AXIS1__MOTOR__CURRENT_CONTROL__V_CURRENT_CONTROL_INTEGRAL_Q = 158, + AXIS1__MOTOR__CURRENT_CONTROL__IBUS = 159, + AXIS1__MOTOR__CURRENT_CONTROL__FINAL_V_ALPHA = 160, + AXIS1__MOTOR__CURRENT_CONTROL__FINAL_V_BETA = 161, + AXIS1__MOTOR__CURRENT_CONTROL__IQ_SETPOINT = 162, + AXIS1__MOTOR__CURRENT_CONTROL__IQ_MEASURED = 163, + AXIS1__MOTOR__CURRENT_CONTROL__MAX_ALLOWED_CURRENT = 164, + AXIS1__MOTOR__GATE_DRIVER__DRV_FAULT = 165, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_GENERAL = 166, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_ADC_CB_I = 167, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_ADC_CB_DC = 168, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_MEAS_R = 169, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_MEAS_L = 170, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_ENC_CALIB = 171, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_IDX_SEARCH = 172, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_FOC_VOLTAGE = 173, + AXIS1__MOTOR__TIMING_LOG__TIMING_LOG_FOC_CURRENT = 174, + AXIS1__MOTOR__CONFIG__PRE_CALIBRATED = 175, + AXIS1__MOTOR__CONFIG__POLE_PAIRS = 176, + AXIS1__MOTOR__CONFIG__CALIBRATION_CURRENT = 177, + AXIS1__MOTOR__CONFIG__RESISTANCE_CALIB_MAX_VOLTAGE = 178, + AXIS1__MOTOR__CONFIG__PHASE_INDUCTANCE = 179, + AXIS1__MOTOR__CONFIG__PHASE_RESISTANCE = 180, + AXIS1__MOTOR__CONFIG__DIRECTION = 181, + AXIS1__MOTOR__CONFIG__MOTOR_TYPE = 182, + AXIS1__MOTOR__CONFIG__CURRENT_LIM = 183, + AXIS1__CONTROLLER__POS_SETPOINT = 184, + AXIS1__CONTROLLER__VEL_SETPOINT = 185, + AXIS1__CONTROLLER__VEL_INTEGRATOR_CURRENT = 186, + AXIS1__CONTROLLER__CURRENT_SETPOINT = 187, + AXIS1__CONTROLLER__CONFIG__CONTROL_MODE = 188, + AXIS1__CONTROLLER__CONFIG__POS_GAIN = 189, + AXIS1__CONTROLLER__CONFIG__VEL_GAIN = 190, + AXIS1__CONTROLLER__CONFIG__VEL_INTEGRATOR_GAIN = 191, + AXIS1__CONTROLLER__CONFIG__VEL_LIMIT = 192, + AXIS1__ENCODER__ERROR = 203, + AXIS1__ENCODER__IS_READY = 204, + AXIS1__ENCODER__INDEX_FOUND = 205, + AXIS1__ENCODER__SHADOW_COUNT = 206, + AXIS1__ENCODER__COUNT_IN_CPR = 207, + AXIS1__ENCODER__OFFSET = 208, + AXIS1__ENCODER__PHASE = 209, + AXIS1__ENCODER__POS_ESTIMATE = 210, + AXIS1__ENCODER__POS_CPR = 211, + AXIS1__ENCODER__PLL_VEL = 212, + AXIS1__ENCODER__PLL_KP = 213, + AXIS1__ENCODER__PLL_KI = 214, + AXIS1__ENCODER__CONFIG__USE_INDEX = 215, + AXIS1__ENCODER__CONFIG__PRE_CALIBRATED = 216, + AXIS1__ENCODER__CONFIG__IDX_SEARCH_SPEED = 217, + AXIS1__ENCODER__CONFIG__CPR = 218, + AXIS1__ENCODER__CONFIG__OFFSET = 219, + AXIS1__ENCODER__CONFIG__CALIB_RANGE = 220, + AXIS1__SENSORLESS_ESTIMATOR__ERROR = 221, + AXIS1__SENSORLESS_ESTIMATOR__PHASE = 222, + AXIS1__SENSORLESS_ESTIMATOR__PLL_POS = 223, + AXIS1__SENSORLESS_ESTIMATOR__PLL_VEL = 224, + AXIS1__SENSORLESS_ESTIMATOR__PLL_KP = 225, + AXIS1__SENSORLESS_ESTIMATOR__PLL_KI = 226, + TEST_PROPERTY = 227, +}; + +template +struct endpoint_type; + +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint64_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint32_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef uint16_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef bool type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef int32_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint8_t type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef float type; }; +template<> struct endpoint_type { typedef uint32_t type; }; + + +template +using endpoint_type_t = typename endpoint_type::type; + +} + +#endif __ODRIVE_ENDPOINTS_HPP \ No newline at end of file diff --git a/ArduinoI2C/type_traits.h b/ArduinoI2C/type_traits.h new file mode 100644 index 00000000..4c4b0367 --- /dev/null +++ b/ArduinoI2C/type_traits.h @@ -0,0 +1,267 @@ +/* +* This file is a very small part of the GCC STL because AVR-GCC ships +* without the STL. +*/ + +namespace std +{ + + /** + * @defgroup metaprogramming Metaprogramming + * @ingroup utilities + * + * Template utilities for compile-time introspection and modification, + * including type classification traits, type property inspection traits + * and type transformation traits. + * + * @{ + */ + + /// integral_constant + template + struct integral_constant + { + static constexpr _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant<_Tp, __v> type; + constexpr operator value_type() const noexcept { return value; } +#if __cplusplus > 201103L + +#define __cpp_lib_integral_constant_callable 201304 + + constexpr value_type operator()() const noexcept { return value; } +#endif + }; + + template + constexpr _Tp integral_constant<_Tp, __v>::value; + + /// The type used as a compile-time boolean with true value. + typedef integral_constant true_type; + + /// The type used as a compile-time boolean with false value. + typedef integral_constant false_type; + + template + using __bool_constant = integral_constant; + +#if __cplusplus > 201402L +# define __cpp_lib_bool_constant 201505 + template + using bool_constant = integral_constant; +#endif + + + // Primary type categories. + + template + struct remove_cv; + + template + struct __is_void_helper + : public false_type { }; + + template<> + struct __is_void_helper + : public true_type { }; + + /// is_void + template + struct is_void + : public __is_void_helper::type>::type + { }; + + template + struct __is_integral_helper + : public false_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + +#ifdef _GLIBCXX_USE_WCHAR_T + template<> + struct __is_integral_helper + : public true_type { }; +#endif + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; + + // Conditionalizing on __STRICT_ANSI__ here will break any port that + // uses one of these types for size_t. +#if defined(__GLIBCXX_TYPE_INT_N_0) + template<> + struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0> + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; +#endif +#if defined(__GLIBCXX_TYPE_INT_N_1) + template<> + struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1> + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; +#endif +#if defined(__GLIBCXX_TYPE_INT_N_2) + template<> + struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2> + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; +#endif +#if defined(__GLIBCXX_TYPE_INT_N_3) + template<> + struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3> + : public true_type { }; + + template<> + struct __is_integral_helper + : public true_type { }; +#endif + + /// is_integral + template + struct is_integral + : public __is_integral_helper::type>::type + { }; + + template + struct __is_floating_point_helper + : public false_type { }; + + template<> + struct __is_floating_point_helper + : public true_type { }; + + template<> + struct __is_floating_point_helper + : public true_type { }; + + template<> + struct __is_floating_point_helper + : public true_type { }; + +#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) + template<> + struct __is_floating_point_helper<__float128> + : public true_type { }; +#endif + + /// is_floating_point + template + struct is_floating_point + : public __is_floating_point_helper::type>::type + { }; + + + + + // Const-volatile modifications. + + /// remove_const + template + struct remove_const + { typedef _Tp type; }; + + template + struct remove_const<_Tp const> + { typedef _Tp type; }; + + /// remove_volatile + template + struct remove_volatile + { typedef _Tp type; }; + + template + struct remove_volatile<_Tp volatile> + { typedef _Tp type; }; + + /// remove_cv + template + struct remove_cv + { + typedef typename + remove_const::type>::type type; + }; + + + // Primary template. + /// Define a member typedef @c type only if a boolean constant is true. + template + struct enable_if + { }; + + // Partial specialization for true. + template + struct enable_if + { typedef _Tp type; }; + + + // Type relations. + + /// is_same + template + struct is_same + : public false_type { }; + + template + struct is_same<_Tp, _Tp> + : public true_type { }; +}