Using ChibiOS's I2C driver standalone

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

e_l_tang
Posts: 33
Joined: Sun Jul 03, 2016 7:58 pm
Been thanked: 2 times

Using ChibiOS's I2C driver standalone

Postby e_l_tang » Sat Apr 29, 2017 5:48 am

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?

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: Using ChibiOS's I2C driver standalone

Postby tfAteba » Sat Apr 29, 2017 10:46 am

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?
regards,

Theo.

e_l_tang
Posts: 33
Joined: Sun Jul 03, 2016 7:58 pm
Been thanked: 2 times

Re: Using ChibiOS's I2C driver standalone

Postby e_l_tang » Sat Apr 29, 2017 5:11 pm

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.

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: Using ChibiOS's I2C driver standalone

Postby tfAteba » Sat Apr 29, 2017 7:24 pm

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.
regards,

Theo.

e_l_tang
Posts: 33
Joined: Sun Jul 03, 2016 7:58 pm
Been thanked: 2 times

Re: Using ChibiOS's I2C driver standalone

Postby e_l_tang » Sun Apr 30, 2017 1:41 am

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.

User avatar
Giovanni
Site Admin
Posts: 12964
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 735 times
Been thanked: 610 times
Contact:

Re: Using ChibiOS's I2C driver standalone

Postby Giovanni » Sun Apr 30, 2017 6:30 am

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

e_l_tang
Posts: 33
Joined: Sun Jul 03, 2016 7:58 pm
Been thanked: 2 times

Re: Using ChibiOS's I2C driver standalone

Postby e_l_tang » Sun Apr 30, 2017 7:11 am

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?

User avatar
Giovanni
Site Admin
Posts: 12964
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 735 times
Been thanked: 610 times
Contact:

Re: Using ChibiOS's I2C driver standalone

Postby Giovanni » Sun Apr 30, 2017 4:04 pm

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

e_l_tang
Posts: 33
Joined: Sun Jul 03, 2016 7:58 pm
Been thanked: 2 times

Re: Using ChibiOS's I2C driver standalone

Postby e_l_tang » Wed May 03, 2017 5:25 am

I've done it! Would it be okay if I shared the driver on GitHub for the benefit of the AVR community?

User avatar
Giovanni
Site Admin
Posts: 12964
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 735 times
Been thanked: 610 times
Contact:

Re: Using ChibiOS's I2C driver standalone

Postby Giovanni » Wed May 03, 2017 9:49 am

Of course.

Giovanni


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 1 guest