1

We are developing an embedded device running Linux, which needs to act as a usb serial gadget and connect to android phones for different types of data transfer. In order to initiate the communication with the host usb (android phone), I need to detect whenever the USB host is connected to the device. I came to know about writing udev rules in order to run an executable on usb host insertion/removal, but We already have a main C program that manages all of the device's main functionality. I would be running a thread in this program which would be responsible for this communication. Is there any way by which I can receive the USB hotplug event in this thread. I am really trying to avoid using loops in this thread so that it doesn't get CPU intensive. So is there any way by which I can receive the USB hotplug event?

poseidon
  • 11
  • 5
  • 1
    Communication is initiated according to USB protocol. Your gadget can be simply constructed by using ConfigFS. Whenever cable is connected it will do all initialization automatically inside the kernel. Why do you need separate program for this? – 0andriy Nov 28 '19 at 18:14
  • 1
    @poseidon I guess you will need dbus library to detect the usb hotplug event. Please have a look at this post: https://stackoverflow.com/questions/14144781/receiving-notification-event-signal-of-usb-device-insertion-in-c It may be of some help. – Gaurav Pathak Nov 29 '19 at 05:23
  • 1
    can dbus library be used on usb gadget devices running linux? – poseidon Nov 29 '19 at 09:45

0 Answers0