Skip to content

Conversation

@VynDragon
Copy link
Contributor

No DMA, no async.

Tested on bl602 and bl618.

josuah
josuah previously approved these changes Oct 28, 2025
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting to see what's happening with phase0, phase1, phase2, phase3 (timing of individual signal steps of I2C AFAIU).

I would have assumed sys_read32/sys_write32 would have been enough to tell GCC not to shuffle the order of IO register read/write, curious to follow-up on that.

Just proposing reminders about MHZ() but not sure if that's something you even wanted to use (i.e. other I2C drivers don't use them).

josuah
josuah previously approved these changes Nov 2, 2025
josuah
josuah previously approved these changes Nov 2, 2025
josuah
josuah previously approved these changes Nov 3, 2025
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra hardware + bus/protocol error handling added, also LGTM!

Adds i2c binding and nodes

Signed-off-by: Camille BAUD <[email protected]>
josuah
josuah previously approved these changes Nov 4, 2025
@VynDragon
Copy link
Contributor Author

@teburd PTAL

Copy link
Contributor

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use kernel primitives for queueing threads rather than looping on hardware busy status.

return 0;
}

while (i2c_bflb_busy(dev) && !sys_timepoint_expired(end_timeout)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k_sem/k_mutex here instead of busy looping to provide a thread queuing mechanism with a timeout.

e.g.

k_sem_take(data->lock, K_FOREVER);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not intended for checking thread queuing, it's for bad states. there no thread queuing mechanism, i suppose there should be one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes there should be a semaphore or mutex here on the blocking transfer call to block threads until the hardware is usable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
i += ret;
end_timeout = sys_timepoint_calc(K_MSEC(I2C_WAIT_TIMEOUT_MS));
while ((i2c_bflb_busy(dev)
Copy link
Contributor

@teburd teburd Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have some interrupts it seems to get events from the hardware, tight looping for completions like this is I'd say generally frowned on if you have an interrupt to tell you instead.

Broadly speaking looping over the messages int he thread context, sending, waiting, repeat isn't workable with any other I2C API (submit) which means supporting this device with sensors will involve a fallback mechanism which is less than optimal.

Non-blocking comment but highly recommended.

Copy link
Contributor Author

@VynDragon VynDragon Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it does mostly check the interrupts, are you saying it should set a completion flag from the interrupt instead and semaphore wait for it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should set a completion flag (semaphore) one time when the entire transfer of i2c_msg array is done. You should not be looping in i2c_transfer ideally.

Writing your driver this way will enable you to add .submit later much easier (highly recommended).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i see. I am aware of this issue, this is intended to be basic like this, improvement on this angle would be done when/if submit and other async stuffs are implemented, I have no issue rewriting this bit when this will be necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why its a non-blocking comment, it'd be nice, but its not expected in this PR

Introduce synchronous i2c driver

Signed-off-by: Camille BAUD <[email protected]>
Adds I2C tests running

Signed-off-by: Camille BAUD <[email protected]>
@VynDragon VynDragon requested a review from josuah November 14, 2025 16:18
Fix bad formatting.

Signed-off-by: Camille BAUD <[email protected]>
@sonarqubecloud
Copy link

@kartben kartben merged commit 6f7eeaf into zephyrproject-rtos:main Nov 15, 2025
28 checks passed
@VynDragon VynDragon deleted the bflb_i2c branch November 15, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants