12-11-2020, 01:06 PM
(12-07-2020, 05:08 AM)xyzzy Wrote:Simple enough, thanks. I've written a simple C++ program to read some text files from the location, you've mentioned, to add to my already bloated conkyrc to conveniently monitor what's going on with USB-C.(12-04-2020, 02:39 PM)wrzomar Wrote: Is there a simple way to debug USB-C PD on the Pinebook Pro?Simple. Doubt that...
It uses a FUSB302 to control the USB PD bus. There is a datasheet for it and it can be accessed over I2C. So you could see what is going on if you can read a datasheet and use i2cset and i2cget to inspect the device. You can also look around in /sys/bus/i2c/devices/4-0022/typec
Code:
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
using namespace std;
const string MASTER_PATH = "/sys/bus/i2c/devices/4-0022/typec/port0/";
const string DATA_ROLE_F = "data_role";
const string ORIENTATION_F = "orientation";
const string PORT_TYPE_F = "port_type";
const string POWER_OPERATION_MODE_F = "power_operation_mode";
const string POWER_ROLE_F = "power_role";
const string PREFERRED_ROLE_F = "preferred_role";
const string SUPPORTED_ACCESSORY_MODES_F = "supported_accessory_modes";
const string UEVENT_F = "uevent";
const string USB_POWER_DELIVERY_REVISION_F = "usb_power_delivery_revision";
const string USB_TYPEC_REVISION_F = "usb_typec_revision";
const string VCONN_SOURCE_F = "vconn_source";
constexpr int FILENAMES_SIZE = 4;
const string FILENAMES[FILENAMES_SIZE] = {ORIENTATION_F, DATA_ROLE_F, POWER_ROLE_F, POWER_OPERATION_MODE_F};
const string SHORTCUTS[FILENAMES_SIZE] = {"O", "DR", "PR", "POM"};
bool printFromFile(const int index);
int main()
{
for(int i = 0; i < FILENAMES_SIZE; i++)
{
bool result = printFromFile(i);
if(i < FILENAMES_SIZE - 1){
if(i == 2 || i == 3 || i == 6)
cout << endl;
}
if(!result)
break;
}
cout << endl;
return 0;
}
bool printFromFile(const int index)
{
cout << SHORTCUTS[index] << ":";
ifstream file;
file.open(MASTER_PATH + FILENAMES[index]);
if(!file){
cout << "!file ";
}
else{
stringstream stringStream;
stringStream << file.rdbuf();
file.close();
string contents = stringStream.str();
if(!contents.empty() && contents[contents.length() - 1] == '\n'){
contents.erase(contents.length() - 1);
}
int openBracket = contents.find('[');
int closeBracket = contents.find(']');
if(openBracket != string::npos && closeBracket != string::npos && openBracket < closeBracket){
string strbetween = contents.substr(openBracket+1, closeBracket-openBracket-1);
contents = strbetween;
}
cout << contents << " ";
if(index == 0 && contents == "unknown")
return(false);
else
return(true);
}
}
For a few days everything worked fine and I didn't have to reboot, but today I had to reboot twice. When it's charging using USB 3.0 but other USB-C functions aren't working (including charging using USB-C port on the powebank with Power Delivery), the 'orientation' file contains 'unknown'. If everything is fine, the 'orientation' file contains 'unknown' only when unplugged and 'normal' or 'reverse' when plugged. I didn't read the datasheet yet. I didn't check if FUSB302 is working at all when this happens.