Skip to content

Reduce the IRAM usage of I2C code by 600-1500 bytes #6326

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

Merged
merged 25 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7126fbf
Reduce the IRAM (and heap) usage of I2C code
earlephilhower Jul 22, 2019
5ba2dd3
Make most variables ints, not uint8_ts
earlephilhower Jul 22, 2019
f55ab36
Make local flag vars int
earlephilhower Jul 22, 2019
37e10b9
Factor out !scl in onSdaChange
earlephilhower Jul 22, 2019
423a5bf
Make tiny twi_reply inline
earlephilhower Jul 22, 2019
62f9599
Inline additional twi_** helper functions
earlephilhower Jul 22, 2019
014f87f
Convert state machine to 1-hot for faster lookup
earlephilhower Jul 22, 2019
9ae9af1
Factor out twi_status setting
earlephilhower Jul 24, 2019
b975996
Use a struct to hold globals for TWI
earlephilhower Jul 24, 2019
52bf8ac
Use enums for states, move one more var to twi struct
earlephilhower Jul 25, 2019
31e54a0
Save 4 heap bytes by reprdering struct
earlephilhower Jul 25, 2019
fd8b6c5
Convert to C++ class, clean up code
earlephilhower Jul 26, 2019
0cdca29
Run astyle core.conf, clean up space/tab/etc.
earlephilhower Jul 26, 2019
eb7b2b9
Merge branch 'master' into reducei2ciram
earlephilhower Aug 8, 2019
3552bfc
Merge branch 'master' into reducei2ciram
earlephilhower Aug 19, 2019
51e1e34
Merge branch 'master' into reducei2ciram
earlephilhower Sep 15, 2019
1c14e9e
Merge branch 'master' into reducei2ciram
d-a-v Oct 3, 2019
f04d65c
Merge branch 'master' into reducei2ciram
earlephilhower Oct 4, 2019
f67ddf5
Add enum use comment, rename twi::delay, fix SDA/SCL_READ bool usage
earlephilhower Oct 4, 2019
dd6a854
Replace clock stretch repeated code w/inline loop
earlephilhower Oct 4, 2019
a23864a
Remove slave code when not using slave mode
earlephilhower Oct 4, 2019
991380d
Re-allmanize the i2c core and Wire library
earlephilhower Oct 14, 2019
7410bc5
Merge branch 'master' into reducei2ciram
earlephilhower Oct 14, 2019
88209b5
Add i2c and lib to restyle.sh
earlephilhower Oct 14, 2019
1012d40
Add comment about bool-as-int in slave eventhndlr
earlephilhower Oct 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Re-allmanize the i2c core and Wire library
No functional changes, only formatting.
  • Loading branch information
earlephilhower committed Oct 14, 2019
commit 991380dbe4d1b8b61e049864ff87b49214e0be44
6 changes: 4 additions & 2 deletions cores/esp8266/core_esp8266_si2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class Twi
// Handle the case where a slave needs to stretch the clock with a time-limited busy wait
inline void WAIT_CLOCK_STRETCH()
{
for (unsigned int t = 0; !SCL_READ() && (t < twi_clockStretchLimit); t++) {
for (unsigned int t = 0; !SCL_READ() && (t < twi_clockStretchLimit); t++)
{
/* noop */
}
}
Expand Down Expand Up @@ -253,7 +254,8 @@ void Twi::setAddress(uint8_t address)

void Twi::enableSlave()
{
if (!_slaveEnabled) {
if (!_slaveEnabled)
{
attachInterrupt(twi_scl, onSclChange, CHANGE);
attachInterrupt(twi_sda, onSdaChange, CHANGE);
_slaveEnabled = true;
Expand Down
34 changes: 17 additions & 17 deletions cores/esp8266/twi.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
twi.h - Software I2C library for esp8266
twi.h - Software I2C library for esp8266

Copyright (c) 2015 Hristo Gochkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified January 2017 by Bjorn Hammarberg ([email protected]) - i2c slave support
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified January 2017 by Bjorn Hammarberg ([email protected]) - i2c slave support
*/
#ifndef SI2C_h
#define SI2C_h
Expand Down Expand Up @@ -48,8 +48,8 @@ uint8_t twi_status();

uint8_t twi_transmit(const uint8_t*, uint8_t);

void twi_attachSlaveRxEvent( void (*)(uint8_t*, size_t) );
void twi_attachSlaveTxEvent( void (*)(void) );
void twi_attachSlaveRxEvent(void (*)(uint8_t*, size_t));
void twi_attachSlaveTxEvent(void (*)(void));
void twi_reply(uint8_t);
//void twi_stop(void);
void twi_releaseBus(void);
Expand Down
Loading