a commit...
This commit is contained in:
+15
-21
@@ -1,14 +1,15 @@
|
|||||||
// Tinio - the Tiny I/O tool
|
// Tinio - the Tiny I/O tool
|
||||||
#include <CyUSBCommon.h>
|
#include <CyUSBCommon.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
// those vars are to be used with locateDevice function
|
// those vars are to be used with locateDevice function
|
||||||
const uint8_t maxDevs = 16; // 16 connected devices should be enough...
|
const uint8_t maxDevs = 16; // 16 connected devices should be enough...
|
||||||
const CY_VID_PID deviceVidPid{UINT16(0x04b4), UINT16(0x0004)}; // the id for the chip
|
const CY_VID_PID deviceVidPid{UINT16(0x04b4),
|
||||||
|
UINT16(0x0004)}; // the id for the chip
|
||||||
uint8_t deviceNumList[maxDevs];
|
uint8_t deviceNumList[maxDevs];
|
||||||
uint8_t deviceCount;
|
uint8_t deviceCount;
|
||||||
CY_DEVICE_INFO deviceInfoList[maxDevs];
|
CY_DEVICE_INFO deviceInfoList[maxDevs];
|
||||||
@@ -132,23 +133,22 @@ int locateDevice() // locate the device and verify it's the right one
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int selectDevice() {
|
int attachDevices() {
|
||||||
|
|
||||||
if (whichDev > deviceCount) {
|
|
||||||
puts("The requested device doesn't exist.");
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < deviceCount; i++) {
|
for (int i = 0; i < deviceCount; i++) {
|
||||||
int rs = evalErrors(CyOpen(deviceNumList[i], interfaceNum, &deviceHandleList[i]));
|
int rs = evalErrors(
|
||||||
if (rs != 0)
|
CyOpen(deviceNumList[i], interfaceNum, &deviceHandleList[i]));
|
||||||
{
|
if (rs != 0) {
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int setGPIO(int targetPin, uint8_t value) {
|
||||||
|
int retval = evalErrors(CySetGpioValue(deviceHandleList[whichDev-1], targetPin, value));
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
int isstrdigit(const char *str) {
|
int isstrdigit(const char *str) {
|
||||||
for (; *str != '\0'; str++) {
|
for (; *str != '\0'; str++) {
|
||||||
if (!(isdigit(*str))) {
|
if (!(isdigit(*str))) {
|
||||||
@@ -156,7 +156,6 @@ int isstrdigit(const char *str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
@@ -170,8 +169,7 @@ int parseCmdLine(int acount, char * const* arglist) {
|
|||||||
while ((opt = getopt(acount, arglist, "d:s:r:v:i:") != -1)) {
|
while ((opt = getopt(acount, arglist, "d:s:r:v:i:") != -1)) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
if ( !(isstrdigit(optarg)) )
|
if (!(isstrdigit(optarg))) {
|
||||||
{
|
|
||||||
puts("Unknown argument for switch -d");
|
puts("Unknown argument for switch -d");
|
||||||
puts("Arguments MUST be integer numbers!");
|
puts("Arguments MUST be integer numbers!");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -180,23 +178,19 @@ int parseCmdLine(int acount, char * const* arglist) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if ( !(isstrdigit(optarg)) )
|
if (!(isstrdigit(optarg))) {
|
||||||
{
|
|
||||||
puts("Unknown argument for switch -s");
|
puts("Unknown argument for switch -s");
|
||||||
puts("Arguments MUST be integer numbers!");
|
puts("Arguments MUST be integer numbers!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// TODO complete when set and read GPIO are done
|
// TODO complete when set and read GPIO are done
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int main(int argc, char const *argv[]) {
|
int main(int argc, char const *argv[]) {
|
||||||
initLib();
|
initLib();
|
||||||
locateDevice();
|
locateDevice();
|
||||||
selectDevice();
|
attachDevices();
|
||||||
// test();
|
// test();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user