Skip to content

Commit

Permalink
Merge pull request #5 from bloguetronica/v1.1.0
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
samuelfmlourenco authored Dec 2, 2021
2 parents d879b90 + 533da45 commit 251d6da
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This class was originally derived from the corresponding class for Qt, version
3.0.1. The current version (1.0.0) follows the C++11 standard.
3.0.1. The current version (1.1.0) follows the C++11 standard.
30 changes: 29 additions & 1 deletion itusb1device.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* ITUSB1 device class - Version 1.0.0
/* ITUSB1 device class - Version 1.1.0
Requires CP2130 class version 1.0.0 or later
Copyright (c) 2021 Samuel Lourenço
Expand All @@ -20,6 +20,7 @@


// Includes
#include <sstream>
#include <unistd.h>
#include <vector>
#include "itusb1device.h"
Expand Down Expand Up @@ -85,6 +86,12 @@ void ITUSB1Device::detach(int &errcnt, std::string &errstr)
}
}

// Returns the silicon version of the CP2130 bridge
CP2130::SiliconVersion ITUSB1Device::getCP2130SiliconVersion(int &errcnt, std::string &errstr)
{
return cp2130_.getSiliconVersion(errcnt, errstr);
}

// Gets the VBUS current
// Important: SPI mode should be configured for channel 0, before using this function!
float ITUSB1Device::getCurrent(int &errcnt, std::string &errstr)
Expand All @@ -100,6 +107,12 @@ float ITUSB1Device::getCurrent(int &errcnt, std::string &errstr)
return currentCodeSum / (4.0 * N_SAMPLES); // Return the average current out of "N_SAMPLES" [5] for each measurement (currentCode / 4.0 for a single reading)
}

// Returns the hardware revision of the device
std::string ITUSB1Device::getHardwareRevision(int &errcnt, std::string &errstr)
{
return hardwareRevision(getUSBConfig(errcnt, errstr));
}

// Gets the manufacturer descriptor from the device
std::u16string ITUSB1Device::getManufacturerDesc(int &errcnt, std::string &errstr)
{
Expand Down Expand Up @@ -188,6 +201,21 @@ void ITUSB1Device::switchUSBPower(bool value, int &errcnt, std::string &errstr)
cp2130_.setGPIO1(!value, errcnt, errstr); // GPIO.1 corresponds to the !UPEN signal
}

// Helper function that returns the hardware revision from a given USB configuration
std::string ITUSB1Device::hardwareRevision(const CP2130::USBConfig &config)
{
std::string revision;
if (config.majrel > 1 && config.majrel <= 27) {
revision += static_cast<char>(config.majrel + 'A' - 2); // Append major revision letter (a major release number value of 2 corresponds to the letter "A" and so on)
}
if (config.majrel == 1 || config.minrel != 0) {
std::ostringstream stream;
stream << static_cast<int>(config.minrel);
revision += stream.str(); // Append minor revision number
}
return revision;
}

// Helper function to list devices
std::list<std::string> ITUSB1Device::listDevices(int &errcnt, std::string &errstr)
{
Expand Down
5 changes: 4 additions & 1 deletion itusb1device.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* ITUSB1 device class - Version 1.0.0
/* ITUSB1 device class - Version 1.1.0
Requires CP2130 class version 1.0.0 or later
Copyright (c) 2021 Samuel Lourenço
Expand Down Expand Up @@ -52,7 +52,9 @@ class ITUSB1Device
void attach(int &errcnt, std::string &errstr);
void close();
void detach(int &errcnt, std::string &errstr);
CP2130::SiliconVersion getCP2130SiliconVersion(int &errcnt, std::string &errstr);
float getCurrent(int &errcnt, std::string &errstr);
std::string getHardwareRevision(int &errcnt, std::string &errstr);
std::u16string getManufacturerDesc(int &errcnt, std::string &errstr);
bool getOvercurrentStatus(int &errcnt, std::string &errstr);
std::u16string getProductDesc(int &errcnt, std::string &errstr);
Expand All @@ -67,6 +69,7 @@ class ITUSB1Device
void switchUSBData(bool value, int &errcnt, std::string &errstr);
void switchUSBPower(bool value, int &errcnt, std::string &errstr);

static std::string hardwareRevision(const CP2130::USBConfig &config);
static std::list<std::string> listDevices(int &errcnt, std::string &errstr);
};

Expand Down

0 comments on commit 251d6da

Please sign in to comment.