Skip to content

nrf: Rewrite the I2C common-hal using nrfx #972

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 1 commit into from
Jul 2, 2018

Conversation

arturo182
Copy link
Collaborator

No description provided.

@arturo182 arturo182 requested review from tannewt and hathach June 28, 2018 20:50
}

self->twi->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
nrfx_err_t err = nrfx_twim_init(&self->twim, &config, NULL, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

The config struct is interesting. Its very ASF3 style. They moved away from it because it encodes a bunch of data that's usually the default state of the peripheral once its software reset.

How does this impact code size?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I don't think it's that much of an overhead, as the config structs are not that large, they only have the fields that are really needed and I'm not sure if we can trust the peripherals to always be in a known state, so probably best to init the bare minimum always. The benfit of using the drivers instead of the hal is that (in addition to being easier to use), they also have fixes/workarounds for known silicon bugs and and general error handling that we don't have to think about.

Copy link
Member

Choose a reason for hiding this comment

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

You should measure it. :-)

I looked at the data sheet and there isn't a reset register like the SAMD peripherals have. So it makes sense to set everything.

In general I like this library and using it. I'm just giving you a heads up about our similar experiences with ASF3. Error checking is good but can add overhead if we know a given state but the compiler doesn't recognize. We have plenty of space now so starting with this is fine.

@arturo182
Copy link
Collaborator Author

I checked the sizes without and with this change:

master:
   text	   data	    bss	    dec	    hex	filename
 208680	   1196	 174168	 384044	  5dc2c	build-pca10056-s140/firmware.elf

i2c branch:
   text	   data	    bss	    dec	    hex	filename
 210360	   1196	 174220	 385776	  5e2f0	build-pca10056-s140/firmware.elf

So yeah, the change does increase the flash usage by 1.64K and we have to keep that in mind. On the bright side, I noticed that a few flags that can lower the size of generated code by 48 bytes (!) are not set in the Makefile so I will introduce another PR for that :)

@tannewt
Copy link
Member

tannewt commented Jul 2, 2018

Ok, let's keep that in the back of our minds in case we need the space later. This is good for now. Thanks!

@tannewt tannewt merged commit 05a088b into adafruit:master Jul 2, 2018
@arturo182 arturo182 deleted the nrf_i2c branch July 2, 2018 21:33
@tannewt tannewt mentioned this pull request Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants