Probe problem when writing a I2C device driver - linux-device-driver

I am a newbie in writing linux device driver, forgive me if anything stupid a asked and my poor English^^
I am trying to write a driver for a touch panel, which communicate with CPU via I2C.
I tried to add a device driver into linux platform, and the register was success, I mean the driver was loaded, but the probe function didn't fired up!!
Above is partial code of the driver i wrote.
static int i2c_ts_probe(struct i2c_client *client, const struct i2c_device_id * id) {
/* ... */
}
static int i2c_ts_remove(struct i2c_client *client) {
/* ... */
}
static const struct i2c_device_id i2c_ts_id[] = {
{"Capacitive TS", 0},
{ }
};
MODULE_DEVICE_TABLE(i2c, i2c_ts_id);
static struct i2c_driver i2c_ts = {
.id_table = i2c_ts_id,
.probe = i2c_ts_probe,
.remove = i1c_ts_remobe,
.driver = {
.name = "i2c_ts",
},
};
static int __init i2c_ts_init(void) {
return i2c_add_driver(&i2c_ts);
}
static int __init i2c_ts_exit(void) {
return i2c_del_driver(&i2c_ts);
}
module_init(i2c_ts_init);
module_exit(i2c_ts_exit);
Above is partial code in platform (/kernel/arch/arm/mach-pxa/saarb.c) used for registering the i2c device.
static struct i2c_board_info i2c_board_info_ts[] = {
{
.type = i2c_ts,
.irq = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO0)),
},
};
static void __init saarb_init(void) {
...
i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info_ts));
...
}
any suggestion and comment will be welcome, thanks^^

So that the linux device/driver model can probe your driver, there must be a device requesting it: this is achieved by comparing the name of the driver ("i2c_ts") and the type of the device in the i2c_board_info struct. In your case I guess the type is not equal to "i2c_ts".
So I would suggest that you use the I2C_BOARD_INFO macro to instantiate your device, as documented in Documentation/i2c/instantiating_devices.
static struct i2c_board_info i2c_board_info_ts[] = {
{
I2C_BOARD_INFO("i2c_ts", 0x12),
.irq = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO0)),
},
};
static void __init saarb_init(void) {
...
i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info_ts));
...
}
You had also not given an address to your device, and I2C_BOARD_INFO needs it. Read the datasheet of your touchscreen to know what that address is.
Finally, as suggested above, be sure that i2c_ts_id is correct. I am not sure it plays a role in the device/module association mechanism in the kernel, but I would say it's far less confusing it they all share the same name.

Probe method will only be called when the device matches the driver name.As you have mentioned your driver name as 'i2c_ts' please check your device tree for the device name.Both should be same.

Related

What causes and how to resolve EntryPointNotFoundException in Unity?

I'm very new to unity. I'm trying to play in unity the example room scene from livekit https://github.com/livekit/client-sdk-unity-web (Livekit enables webRTC for unity WebGL project) but I can not because I receive an EntryPointNotFoundException whenever there is a DLLImport Internal in the code.
Here is an example of the error I get :
Here is an extract code from JSRef where line 92 is:
[Preserve]
internal JSRef(JSHandle handle)
{
NativeHandle = handle;
// We add the instantiated object into the cache se we can retrieve it later if not garbage collected.
// Note that if JSRef has been garbage collected, it doesn't mean that the key doesn't exists on this map ( Finalizer is unpredictable )
Cache[handle.DangerousGetHandle()] = new WeakReference<JSRef>(this);
}
internal JSRef() : this(JSNative.NewRef()) //this is line 92
{
}
And the code where newRef is in the file JSNative:
[DllImport("__Internal")]
internal static extern JSHandle NewRef();
and this is the code for JSHandle :
public class JSHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private JSHandle() : base(true)
{
}
internal JSHandle(IntPtr ptr, bool ownsHandle) : base(ownsHandle)
{
SetHandle(ptr);
}
protected override bool ReleaseHandle()
{
return JSNative.RemRef(handle);
}
}
Please help me, I've looked on Google and other posts on StackOverflow but I don't know what to do....

Can a BLE Server identify which component is connected to it?

I have this project, where I need to create a BLE-Server (ESP32) to exchange data with a Laptop/Smartphone etc.... . The code is written with Arduino IDE, using the ESP32 BLE Arduino library and seems like the following
void Setup() {
BLEDevice::init("MIDI_BOX"); // Name of the BLE_Device
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
MIDI_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_WRITE_NR
);
pCharacteristic->addDescriptor(new BLE2902());
pCharacteristic->setCallbacks(new MyCallbacks());
pService->start();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
BLEDevice::startAdvertising();
};
Having this said, when I want to connect my Laptop or Smartphone to this server. It needs to indetify which kind of device is connected to(Apple, Microsoft,). The manufacturer data seems a good idea for me but I don't how to get this information when there is a connection.
A callback fonction is provided by the BLEServer:
class MyServerCallbacks: public BLEServerCallbacks { //can I here do smth to get manufacturer data ??
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
Can anyone explain to me how it should be done, or are there any better way of thinking ?
Thnx in advance

STM32 FreeRTOS - UART Deferred Interrupt Problem

I am trying to read data with unkown size using UART Receive Interrupt. In the call back function, I enabled Rx interrupt in order to read characters until \n is gotten. If \n is get, then higher priority task which is deferred interrupt handler is woken. The problem is that I tried to read one by one byte via call back function and I tried to put each character into a buffer, but unfortunately buffer could not get any character. Moreover, deferred interrupt handler could not be woken.
My STM32 board is STM32F767ZI, and my IDE is KEIL.
Some Important notes before sharing the code:
1. rxIndex and gpsBuffer are declared as global.
2. Periodic function works without any problem.
Here is my code:
Periodic Function, Priority = 1
void vPeriodicTask(void *pvParameters)
{
const TickType_t xDelay500ms = pdMS_TO_TICKS(500UL);
while (1) {
vTaskDelay(xDelay500ms);
HAL_UART_Transmit(&huart3,(uint8_t*)"Imu\r\n",sizeof("Imu\r\n"),1000);
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_7);
}
}
Deferred Interrupt, Priority = 3
void vHandlerTask(void *pvParameters)
{
const TickType_t xMaxExpectedBlockTime = pdMS_TO_TICKS(1000);
while(1) {
if (xSemaphoreTake(xBinarySemaphore,xMaxExpectedBlockTime) == pdPASS) {
HAL_UART_Transmit(&huart3,(uint8_t*)"Semaphore Acquired\r\n",sizeof("Semaphore
Acquired\r\n"),1000);
// Some important processes will be added here
rxIndex = 0;
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_14);
}
}
}
Call back function:
void HAL_UART_RxCptlCallBack(UART_HandleTypeDef *huart)
{
gpsBuffer[rxIndex++] = rData;
if (rData == 0x0A) {
BaseType_t xHigherPriorityTaskWoken;
xSemaphoreGiveFromISR(xBinarySemaphore,&xHigherPriorityTaskWoken);
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
HAL_UART_Receive_IT(huart,(uint8_t*)&rData,1);
}
Main function
HAL_UART_Receive_IT(&huart3,&rData,1);
xBinarySemaphore = xSemaphoreCreateBinary();
if (xBinarySemaphore != NULL) {
//success
xTaskCreate(vHandlerTask,"Handler",128,NULL,1,&vHandlerTaskHandler);
xTaskCreate(vPeriodicTask,"Periodic",128,NULL,3,&vPeriodicTaskHandler);
vTaskStartScheduler();
}
Using HAL for it is a best way to get into the troubles. It uses HAL_Delay which is systick dependant and you should rewrite this function to read RTOS tick instead.
I use queues to pass the data (the references to data) but it should work. There is always a big question mark when using the HAL functions.
void HAL_UART_RxCptlCallBack(UART_HandleTypeDef *huart)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
gpsBuffer[rxIndex++] = rData;
if (rData == 0x0A) {
if(xSemaphoreGiveFromISR(xBinarySemaphore,&xHigherPriorityTaskWoken) == pdFALSE)
{
/* some error handling */
}
}
HAL_UART_Receive_IT(huart,(uint8_t*)&rData,1);
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
Concluding if I use HAL & RTOS I always modify the way HAL handles timeouts.

Connection not working from Android to UWP on desktop - ZeroMq (NetMq)

I tried some examples of ZMQ on C++,C# and Python. I am trying to have Request-Reply pattern to connect Android device to PC running UWP with Xamarin forms.
Below is the Requestor code:
public void HelloWorld()
{
var timer = new Timer(60000);
timer.Start();
timer.Elapsed += (sender, args) =>
{
this.Cancel = true;
timer.Stop();
};
// Create
const string endpoint = "tcp://PC_ip:3245";
using (var request = new RequestSocket())
{
request.Bind(endpoint);
Thread.Sleep(2000);
while (!Cancel)
{
request.SendFrame("Requester says hello");
var reply = request.ReceiveFrameString();
Debug.WriteLine("Gets reply {0}",reply);
}
}
}
Reply socket code:
public void HelloWorld()
{
var timer = new Timer(60000);
const string endpoint = "tcp://PC_ip:3245";
timer.Start();
timer.Elapsed += (sender, args) =>
{
timer.Stop();
Cancel = true;
};
using (var replierSocket = new ResponseSocket())
{
replierSocket.Connect(endpoint);
Thread.Sleep(2000);
while (!Cancel)
{
var replyFromRequester = replierSocket.ReceiveFrameString();
Debug.WriteLine("Got reply {0}", replyFromRequester);
replierSocket.SendFrame("Response socket say hello");
}
}
}
Cancel is boolean
I went through some questions posted on this and added delay and these connection code blocks only trigger after button clicks on app.
While debugging , request.ReceiveFrameString() replierSocket.ReceiveFrameString(); are not even hit.
I am new to network programming , I understand that for REQ/REP pattern the code has to be in particular order which I traced and fixed I believe and turned off firewall on my PC so that firewall wont block my incoming connections from Android device.
PC_ip stands for IPv4 address I got from ipconfig /all for my wifi. I also tried external ip of my machine from sites like whatsmyip.org at ResponseSocket but I still dont get response between devices.
Please let me know what am I doing wrong.
Issue replication repository : GitHub/me/XamZeroMq

Write to HID with Chip Selection with .NET Console App

Hi I am writing a simple console app that needs to write bytes to MCP2210 USB to SPI Master
I found this library over here, seems to do good job with connecting the device and reading the metadata.
I am writing message to the board as below
public static byte[] Talk()
{
var device = DeviceList.Local.GetHidDevices(1240, 222).FirstOrDefault();
if (device == null)
{
Console.WriteLine($"Could not find a device with Vendor Id:1240, Product Id:222 ");
return null;
}
var reportDescriptor = device.GetReportDescriptor();
foreach (var deviceItem in reportDescriptor.DeviceItems)
{
Console.WriteLine("Opening device for 20 seconds...");
if (!device.TryOpen(out var hidStream))
{
Console.WriteLine("Failed to open device.");
continue;
}
Console.WriteLine("Opened device.");
hidStream.ReadTimeout = Timeout.Infinite;
hidStream.Write(new byte[3] {60, 00, 00});
}
Not sure If I am writing it correctly.
While writing I need to do a chip selection as displayed in this other terminal
Any help is greatly appreciated
Here is the MC I am using https://www.microchip.com/wwwproducts/en/MCP2210
I do not see a closing of your stream. This may cause your data to not even being sent (at least not in time).
Consider using blocks with streams.
But with out parameters not possible.