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

Psoc ino i2c #57

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Psoc ino i2c #57

wants to merge 4 commits into from

Conversation

IFX-Anusha
Copy link

@IFX-Anusha IFX-Anusha commented Feb 12, 2025

Single and Multi board tests in arduino core tests are working

Screenshot 2025-02-07 173113
Screenshot 2025-02-07 173547
Screenshot 2025-02-07 172852

Copy link
Member

@jaenrig-ifx jaenrig-ifx left a comment

Choose a reason for hiding this comment

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

Good job 🔨 🦾 A few things we can further discuss.

In general, this Wire API I don´t feel is the most intuitive... But this is nothing we can do, unless we change the standard 😃 ⚔️
The API mix basic low level I2C functions START - transfer - STOP, with a atomic transfer functions.
For example, for writing something master-slave we will beginTransmission() and write(), and finally the real transfer is only happening in endTransmission()...
But as said, it is what it is🎈

@@ -0,0 +1,3 @@
#######################################
# Syntax Coloring Map For Wire
Copy link
Member

Choose a reason for hiding this comment

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

This is empty? Will be completed in a another ticket?

void onRequest(void (*function)(void));

private:
static TwoWire *instances[I2C_HOWNMANY];
Copy link
Member

@jaenrig-ifx jaenrig-ifx Feb 13, 2025

Choose a reason for hiding this comment

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

Do we need to keep a list of TwoWire instances statically?
Same for the cyhal_ic2_t ?
Isn´t it simpler that each class instance keeps its own struct of cyhal_i2c_t?

uint8_t instance;
bool is_master;
uint16_t slave_address;
static uint8_t rxBuffer[BUFFER_LENGTH];
Copy link
Member

@jaenrig-ifx jaenrig-ifx Feb 13, 2025

Choose a reason for hiding this comment

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

If the buffer are static, what would happen when we have 2 instances of the Wire class?
They are shared between the 2 instances? How would that work?

TwoWire(cyhal_gpio_t sda, cyhal_gpio_t scl, uint8_t instance = 0);

void begin();
void begin(uint16_t address);
Copy link
Member

@jaenrig-ifx jaenrig-ifx Feb 13, 2025

Choose a reason for hiding this comment

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

All these overloaded functions for begin() required?
Wouldn´t uint8_t cover any standard use case address range?

As far as I understand, the I2c standard considers 7-bit addresses. + W/R bit.

And now reading the Wikipedia, I find some oddities like up to 10 bits 🤯
Anyhow, that configuration is not even possible in this API, neither in the cyhal i2c API...


#include "Wire.h"

#define I2C_DEFAULT_FREQ 100000
Copy link
Member

Choose a reason for hiding this comment

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

Preferably we do not use macros in C++.
It could be a static const uint16_t?
https://stackoverflow.com/questions/1637332/static-const-vs-define and other reasons.
I also have a few macros to reconvert in the wifi class 😛

Copy link
Member

Choose a reason for hiding this comment

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

By the way, since we are mixing this anyhow with endless C files, we won´t be able to avoid some of the potential troubles 🤷‍♂️


#define I2C_DEFAULT_FREQ 100000

uint8_t TwoWire::rxBuffer[BUFFER_LENGTH];
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if this ring buffer implementation is encapsulated in a minimal class and functions.
For example:
https://gist.github.com/jhschwartz/a7577efd60393fb15bce877282bdceb5#file-ringbuffer-hpp
Or as they did in MicroPython I2S:
https://github.com/Infineon/micropython/blob/ports-psoc6-main/extmod/machine_i2s.c#L111-L115

It should not be a reusable, generic, fully featured ring buffer lib. Just the minimal set of encapsulated features.
The maintenance of this will improve and its readability.

}

void TwoWire::begin() {
end();
Copy link
Member

Choose a reason for hiding this comment

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

What happens if you try to free() without init() ?
I would expect the user to be in charge of calling explicitly to end().
Or any reason to end() when calling begin() ?

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.

2 participants