Skip to content

Add I2C slave support #3287

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

Closed
wants to merge 7 commits into from
Closed

Add I2C slave support #3287

wants to merge 7 commits into from

Conversation

mrnerdhair
Copy link

This is from the i2c_slave branch of bjoham/esp8266_Arduino, rebased against master.

bjoham and others added 6 commits February 3, 2017 22:34
Moved #defines and declarations to top of file
Renaming, adding static keyword
Renaming, adding static keyword
@robertoostenveld
Copy link

see also #3237

@devyte devyte mentioned this pull request Feb 21, 2018
Copy link
Member

@igrr igrr left a comment

Choose a reason for hiding this comment

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

At this point the PR contains too much unused commented out code, and very few comments to explain the logic. I am not confident that maintainers of the repo will be able to support this code effectively unless these issues are addressed.

The other problem i see is that the code size (including IRAM) and DRAM usage will increase for all users of Wire library, even if they are not using slave mode. The PR should come with some measurements which show how much the code/data size have increased. If this increase is significant, measures should be taken to ensure that new features are only linked into the binary if slave mode is actually used in the application.

//pinMode(12, OUTPUT);
//pinMode(14, OUTPUT);
//pinMode(13, OUTPUT);
//digitalWrite(2, HIGH);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of commenting unused lines, please consider removing them

ets_timer_setfn(&timer, onTimer, NULL);

// create event task
ets_task(eventTask, EVENTTASK_QUEUE_PRIO, eventTaskQueue, EVENTTASK_QUEUE_SIZE);
Copy link
Member

Choose a reason for hiding this comment

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

When using I2C in master mode, it should not be necessary to create this event task and the timer. Same applies to twi_txBuffer and twi_rxBuffer — these should be linked in if only master mode is used.

// transmit master read ready signal, with or without ack
if (ack) {
//TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
Copy link
Member

Choose a reason for hiding this comment

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

Is this commented out line needed?

}

#if 1
Copy link
Member

Choose a reason for hiding this comment

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

is this #if 1 needed?

void ICACHE_RAM_ATTR twi_stop(void)
{
// send stop condition
Copy link
Member

Choose a reason for hiding this comment

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

The reset of the file is indented with spaces, please make indentation consistent.

while (false) { //TWCR & _BV(TWSTO)){
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

This loop seems to be a no-op, can it be removed?

void ICACHE_RAM_ATTR onTimer(void *timer_arg)
{
//digitalWrite(13, HIGH);
Copy link
Member

Choose a reason for hiding this comment

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

likewise — remove commented out lines of code.

//switch(TW_STATUS){
switch(status) {
#if 0
Copy link
Member

Choose a reason for hiding this comment

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

Can this block be removed instead of disabling it?

#define TWIP_READ_ACK 12
#define TWIP_RWAIT_ACK 13
#define TWIP_WRITE 14
#define TWIP_BUS_ERR 15
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 great to describe what each of these states means, and what are the possible transitions. Looking at the code, it seems to me that some of the states here are not actually being used. This does not help understand how the proposed code works.

@devyte
Copy link
Collaborator

devyte commented Feb 21, 2018

CC @bjoham

@devyte
Copy link
Collaborator

devyte commented Oct 26, 2018

Closing in favor of #5226 .

@devyte devyte closed this Oct 26, 2018
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.

5 participants