|
I would like somebody to walk me thru this code to help me understand some details I am having an issue with.
The purpose of the code is to send 8 bits data to hardware – LCD - using SPI communication protocol and Linux ioctl, in C++.
It in an essence works, but I “do not get” totally how.
Since I am not interested in psychoanalysis of my code or “doing it differently” I would prefer to hold off my questions until somebody with interest and knowledge of all of the above – passing data to function , operation of ioctl “command” - SPI_IOC_MESSAGE and SPI (bidirectional ) communication replies.
Basic implementation of the code is a copy of C code and I like to clean it up so it looks as real C++.
function call
vna.spi.SPI_Transfer_3_Line(1);// send command - software reset
function SPI transfer
Reformatted
int C_IOCTL_SPI::SPI_Transfer_3_Line(char data) {
#ifdef DEBUG
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " data " << +data << endl;
cout << " @ line \033[0m " << dec << __LINE__ << endl;
cout << "\033[0m " << endl;
#endif
struct spi_ioc_transfer xfer[2];
unsigned char buf[32], *bp;
unsigned char tx_buf[32], *tx_bp;
unsigned char rx_buf[32], *rx_bp;
int len, status;
if (FileDescriptor) {
#ifdef DEBUG
cout << "FileDescriptor OK " << dec << +FileDescriptor << endl;
#endif
}
memset(xfer, 0, sizeof xfer);
memset(buf, 0, sizeof buf);
memset(tx_buf, 0, sizeof tx_buf);
memset(rx_buf, 0, sizeof rx_buf);
len = sizeof buf;
buf[0] = data;
xfer[0].tx_buf = (unsigned long) buf;
xfer[0].rx_buf = (unsigned long) buf;
xfer[0].len = 1; for (int index = 0; index != xfer[0].len; index++)
cout << "TX buffer index " << dec << index << " 0x" << hex << +buf[index]<< endl;
for (int index = 0; index < 0x10; index++) {
if (buf[index])
cout
<< " ******************** commnad tx buffer value "
<< +buf[index] << endl;
}
xfer[1].rx_buf = (unsigned long) buf;
xfer[1].len = 16; status = ioctl(FileDescriptor, SPI_IOC_MESSAGE(2), xfer);
if (status < 0) {
cout << "status " << status << endl;
perror("Transfer error SPI_IOC_MESSAGE");
return -1;
}
printf("Expected reply of %d characters \n", len);
printf("Processed %d characters \n", status);
#ifdef DEBUG
cout << " TX DATA 0x" << hex << +data << endl;
cout << " TX DATA dec " << dec << +data << endl;
#endif
printf("response(%d): ", status);
for (int index = 0; index != xfer[1].len; index++) {
if (buf[index])
cout
<< " !!!!!!!!!!!!!!!!!!!!!! DATA response rx buffer value "
modified 27-Dec-18 12:43pm.
|
|
|
|
|
Vaclav_ wrote: This post (code) is NOT formatted due to copy from text editor It would not take much effort to format it correctly.
|
|
|
|
|
Hi Richard , I often wonder if you are actually reading my posts.
In case you missed it -here it is again
I am not interested in psychoanalysis of my code
And if this offends you - feeling is mutual.
I hope some day you will get / realize that I am looking for REAL help.
I know you are knowledgeable and can give a real help so stop this "I am your mother" posts.
Have a great 2019.
Cheers Vaclav
|
|
|
|
|
I did not psychoanalyse anything. I merely pointed out that presenting your question in a format that can be read easily by anyone offering help, is not difficult. The tools provided at the top of the edit box in these forums has everything you need. You ask for someone to take time out to work through a lot of unfamiliar code in order to explain it to your satisfaction. So, perhaps you could take time out to present your question in the standard (for this forum) format.
|
|
|
|
|
I need to know how to:
1) Change default keyboard layout
2) Add CD rom support
3) Find some documentation that tells me this!
Any help hugely appreciated,
|
|
|
|
|
Is our main thrust here C/C++ working with maybe QT? Or are we going in for BASH scripts.
...I just realized...this is going to be the Python forum, isn't it?
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
Mono/WinForms rules on any platform
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Yeah, but we already generally have forums for that. There's gotta be something that makes it specifically "Linux Programming".
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
It's supposed to cover all languages/frameworks used for programming on Linux for Linux.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Thanks Chris, for enabling my insanity!
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Shouldn't it be called "Linux Development"?
Why is it programming when you do it on Linux, and development when you do it on Windows?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Because they are racist!
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
They are not races, but OS-es. AFAIK, there's no law against Ossisism
Still it bugs me, since it is inconsistent.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: there's no law against Ossisism Give it time.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Eddy Vluggen wrote: Why is it programming when you do it on Linux, and development when you do it on Windows?
Because we're all a bunch of cavement. It used to be called programming on Windows, too, but then MS wanted to improve our station in life. Noticed they didn't call it "engineering".
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|