Page 1 of 2

Using ChibiOS's I2C driver standalone

Posted: Sat Apr 29, 2017 5:48 am
by e_l_tang
I discovered that ChibiOS's I2C driver is much better than the one I'm currently using in my project. I am investigating whether it's feasible to convert my entire project to use ChibiOS, but I would like to start using its I2C driver immediately because it's so good. What modifications would I need to make to it in order to make it work without the rest of ChibiOS?

Re: Using ChibiOS's I2C driver standalone

Posted: Sat Apr 29, 2017 10:46 am
by tfAteba
Hi, e_l_tang

I thinks the starting point to use is the low device driver (hal_i2c_lld.h and hal_i2c_lld.c). You would then have a lot of dependencies from other files to resolve.

Just a recommendation, for me, it would be better to use the whole chibios in your project, why just use i2c driver?

Re: Using ChibiOS's I2C driver standalone

Posted: Sat Apr 29, 2017 5:11 pm
by e_l_tang
I know that converting my entire project to use ChibiOS is the optimal solution, and I have created threads here and here to get advice on how to do this.

Re: Using ChibiOS's I2C driver standalone

Posted: Sat Apr 29, 2017 7:24 pm
by tfAteba
Ok, thanks for all those details.

I sow that Giovanni give you a lot of advice about how to manage your project :). So now just go on and import your project to ChibiOS step by step.

Re: Using ChibiOS's I2C driver standalone

Posted: Sun Apr 30, 2017 1:41 am
by e_l_tang
Another question: would it be possible to use an Arduino library with ChibiOS, if it does things like accessing peripherals directly, enabling and disabling interrupts, etc.? For your information the library I'm thinking of is FastLED.

Re: Using ChibiOS's I2C driver standalone

Posted: Sun Apr 30, 2017 6:30 am
by Giovanni
Hi,

Usually Arduino libraries are not written with an RTOS in mind, disabling/enabling interrupts can create anomalies in scheduling if not done properly. Polling is another issue.

The answer is: it depends. You need to find out for each library.

Giovanni

Re: Using ChibiOS's I2C driver standalone

Posted: Sun Apr 30, 2017 7:11 am
by e_l_tang
Seeing that even the maintainer of the library does not know I guess my only choice is to try it and find out. Is there still a possibility for issues if my application has only a single thread?

Re: Using ChibiOS's I2C driver standalone

Posted: Sun Apr 30, 2017 4:04 pm
by Giovanni
A single thread is usually fine, the only problem could arise from disabling interrupts.

There is an approach for using code in a single thread that is then used by other threads:

You can encapsulate your library in a server thread, this thread receives messages from other threads, perform an action on the library then returns an answer. Using synchronous messages this is pretty simple. This works because the code is used only by the server so it works even if it is not reentrant.

Giovanni

Re: Using ChibiOS's I2C driver standalone

Posted: Wed May 03, 2017 5:25 am
by e_l_tang
I've done it! Would it be okay if I shared the driver on GitHub for the benefit of the AVR community?

Re: Using ChibiOS's I2C driver standalone

Posted: Wed May 03, 2017 9:49 am
by Giovanni
Of course.

Giovanni