LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 02-09-2016, 03:22 PM   #1
Jasson
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Rep: Reputation: Disabled
mouse device representation in linux / may be controlling the mouse by GPIOs


Yea.... its me again,

since the last visit i could do some steps forward.
I actually found a way to control single GPIOs from Qt C++ App WITHOUT the need to install anything else or typing "stuff" to the command line.


Questions
1) How is the mouse represented in a linux system?
For example, when one uses a touchdisplay the "mouse commands" are fed into the system somehow different

2.)
Could there be a way to control the mouse (cursor and left-click" by GPIO, I2C...?
Even if i need a driver for that.
3.) If there are allready UART, I2C drivers in an image showing up in the /sys/dev or /sys/tty directorys - is it possible to map them into mous controls (pessimisticaly i guess No...)
4.) Are there guides or books dealing around how to write drivers for linux? Im sure there is no
"How-to-write-I2C-mouse-Driver-for-an-Android-running-Banana-Pi",
but may be a general source with the scope on giving an orientaion of what information has to be gathered. Actually im afraid it ends up in bare-metal-programming which makes me dependent to the available documentation of a specific SoC...

best regards!
 
Old 02-10-2016, 08:56 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,837
Blog Entries: 13

Rep: Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893
Quote:
Originally Posted by Jasson View Post
Yea.... its me again,

since the last visit i could do some steps forward.
I actually found a way to control single GPIOs from Qt C++ App WITHOUT the need to install anything else or typing "stuff" to the command line.
Welcome back to LQ
Quote:
Originally Posted by Jasson View Post
Questions
1) How is the mouse represented in a linux system?
For example, when one uses a touchdisplay the "mouse commands" are fed into the system somehow different

2.)
Could there be a way to control the mouse (cursor and left-click" by GPIO, I2C...?
Even if i need a driver for that.
3.) If there are allready UART, I2C drivers in an image showing up in the /sys/dev or /sys/tty directorys - is it possible to map them into mous controls (pessimisticaly i guess No...)
4.) Are there guides or books dealing around how to write drivers for linux? Im sure there is no
"How-to-write-I2C-mouse-Driver-for-an-Android-running-Banana-Pi",
but may be a general source with the scope on giving an orientaion of what information has to be gathered. Actually im afraid it ends up in bare-metal-programming which makes me dependent to the available documentation of a specific SoC...

best regards!
The mouse is an input device. You should see it under /dev/input/mouse0 or something close to that. The information is usually binary. A thing to do is use the sudo command to echo out the mouse0 file and then move your mouse and you'll see some non-printable character representations stream to your terminal. That will confirm you are looking at the resource which is mapped to your mouse.
Code:
/dev/input$ sudo cat mouse0 

   ��������8����(�8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8��8�^C
I've done a lot of Qt programming and the only times I've had to write custom drivers for anything such as using a mouse or keyboard over GPIO, UART, or I2C is if said mouse or keyboard is coming in via that means from some custom embedded board. What the custom driver does is takes the signals and decodes them to where it has discriminated each atomic gesture or intention. Like a numeric keypad may only have 0 through 9 and then enter, so the driver would need to understand eleven different input signal types.

Once you discern the key type from whatever form of input you have, you then can create a QKeyEvent and post it to the Qt engine.
Code:
QKeyEvent *thumb_left = new QKeyEvent(QEvent::KeyPress, Qt::Key_Backtab, Qt::NoModifier, "", FALSE, 1);
QApplication::postEvent(scene, thumb_left);
Otherwise if you have a true input device and it is entering input signals via an existing driver, then all you need do is determine which /dev resource is mapped to your input device. Likely if it is one of the normal HID type of drivers, Qt already supports it as an input device.

I've never been very good at finding a single resource to serve my learning needs. I'd look for an online guide about Linux device driver writing, determine if that was either too insufficient or too detailed for me, but read as much as I could stand. And I'd also look for example driver code that I could get through and was also similar to the driver I wished to write. That usually gives me a good indication as to whether or not I was in over my head. Best of luck if you choose to go that route.
 
Old 02-11-2016, 08:22 AM   #3
Jasson
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
Hello rtmistler,

thanks for your detailed answer!!

So do i get it right by this
Quote:
the only times I've had to write custom drivers for anything such as using a mouse or keyboard over GPIO, UART, or I2C is if said mouse or keyboard is coming in via that means from some custom embedded board.
that my second question can be answered with yes?
Quote:
2.) Could there be a way to control the mouse (cursor and left-click" by GPIO, I2C...?
Even if i need a driver for that.

Quote:
the only times I've had to write custom drivers for anything such as using a mouse or keyboard over GPIO, UART, or I2C is if said mouse or keyboard is coming in via that means from some custom embedded board.
So, you allready did, what im thinking to do? Use a "Pin-hardware" for mouse/keyboard control? To estimate the effort i have to do - im i correct i have to do bare-metal-programming?
My way of thinking about a driver is, that is is the layer between hardware and OS. On hardware side the driver talks to the registers of the CPU and presents the results in specific value-types trough an standadized API to the OS.

My "English-To-German-Interface" (LOL) possibly isnt good enogh to understand this
Quote:
What the custom driver does is takes the signals and decodes them to where it has discriminated each atomic gesture or intention.
Do you mean by atomic, that every single keyhit or mousemove is recognized? (i know "atomic" in a manner of single-CPU-Tick-Instructions" like mutex-access).
And what means "where" in this context? Can you link me to educational sources you have used for
Quote:
the only times I've had to write custom drivers
best regards,
Jasson
 
Old 02-11-2016, 08:32 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,837
Blog Entries: 13

Rep: Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893
What I meant by the term atomic was to describe singular inputs at their most fundamental level. Not clock ticks in a CPU, but it is a great analogy because CPU clock ticks are the most fundamental level of CPU activity. On a mouse, the smallest amount of input action. "slide left 1 pixel", "slide down 1 pixel", "left button pressed", "left button released". I think you understand that and were just asking for clarification of my use of terms. Hopefully that makes my intents clear.

I agree that #2 is a yes and that you are thinking about a driver correctly.

At this point you need to therefore write your driver. I'd recommend looking for an existing mouse driver, seeing how it is coded, and try to mimic what it does, in fact, start with it and try to rewrite it so that the lower layer, the part interfacing with the actual hardware is the portion which you change. Thus you may find that you make a real mouse driver for you custom hardware. Which would be your intent.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
raspberry pie controlling mouse using accelerometer sensor parmeet Linux - Embedded & Single-board computer 4 10-15-2015 02:46 PM
[SOLVED] Controlling mouse with joypad 512upload Ubuntu 2 11-03-2010 11:32 AM
Mouse gestures not seen in xev, volume not controlling PCM jabulani_jonny Linux - Hardware 1 05-07-2006 11:01 PM
USB Device Representation in Linux BobCap Programming 1 10-12-2005 09:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration