Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: i2c: add i2c master #2026

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maass-hamburg
Copy link
Contributor

@maass-hamburg maass-hamburg commented Jul 31, 2024

add a i2c master similar to LiteSPI.

This has the big benefit by using crossbar, that the i2c bus can be used at the same time by drivers, that are in logic, and from the CPU.

The driver for zephyr can be found here: zephyrproject-rtos/zephyr#76554

@enjoy-digital
Copy link
Owner

Thanks @maass-hamburg, will try to review soon (but will be in holidays at the end of the week for 2 weeks).

@AndrewD might also be interested.

@AndrewD
Copy link
Collaborator

AndrewD commented Aug 3, 2024

@maass-hamburg this does sound very interesting: do you have any examples of a gateware driver that uses this core?

We have been using the misoc i2c core for a while (recently integrated in litex): it's a step up from bitbank but small and limited, so we will look seriously at your core soon.

@maass-hamburg
Copy link
Contributor Author

maass-hamburg commented Aug 5, 2024

mcp9843.py.txt
@AndrewD here is one driver for the mcp9843 temperature sensor.

To add it you just have to add this code:

        from mcp9843 import MCP9843
        self.submodules.mcp9843 = mcp9843 = MCP9843()
        hvi2c.add_i2c_device(mcp9843)

hvi2c is here the submodule of LiteI2C

@AndrewD
Copy link
Collaborator

AndrewD commented Aug 5, 2024

Thanks, that looks like quite a logical interface and the usage pattern is similar to your zephyr driver which is as I expected.

I think we will transition our usage to this core. It already exposes capabilities we were thinking about adding to the misoc i2c interface I pushed to litex recently.

Do you have any unit tests for the core you can share?

@maass-hamburg
Copy link
Contributor Author

maass-hamburg commented Aug 5, 2024

Do you have any unit tests for the core you can share?

Unfortunately I haven't wrote any for it yet.

@AndrewD
Copy link
Collaborator

AndrewD commented Aug 21, 2024

I just had another look at this: the next thing that come to mind is support for IRQ so the a message can be queued without polling for completion. For example IRQ based on tx and rx fifo watermarks similar to spimmap would be one such strategy. See spi_mmap.py#L305-L315 for an implementation.

@enjoy-digital
Copy link
Owner

@maass-hamburg: sorry for the delay, just to let you know that I'll try to merge it soon, just need to think of the way we integrate it.

@maass-hamburg
Copy link
Contributor Author

@enjoy-digital what do you think about putting it into its own repo, like LiteSPI? There we could also add some simple i2c drivers for peripherals in logic.

@enjoy-digital
Copy link
Owner

@maass-hamburg: Thanks, I was also thinking about this and this would also give your more flexibility for the development. I just created https://github.com/litex-hub/litei2c and you should have receive an invitation to maintain it. Feel free to create an initial structure close to LiteSPI and push the core to it.

@maass-hamburg maass-hamburg force-pushed the core_litei2c branch 2 times, most recently from 05702d8 to 91e1a46 Compare September 27, 2024 08:46
add litei2c to litex.

Signed-off-by: Fin Maaß <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants