Skip to content

nRF52 I2CSlave Implementation #12161

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 7 commits into from
Apr 14, 2020
Merged

Conversation

AGlass0fMilk
Copy link
Member

Summary of changes

Implemented I2CSlave functionality for nRF52 targets. Requires PR #12160 .

Impact of changes

Migration actions required

Documentation

Update I2CSlave documentation to reflect new example showing interaction between an Mbed I2C master and I2CSlave.


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@desmond-blue


@ciarmcom ciarmcom requested review from desmond-blue and a team December 20, 2019 20:00
@ciarmcom
Copy link
Member

@AGlass0fMilk, thank you for your changes.
@desmond-blue @ARMmbed/mbed-os-maintainers @ARMmbed/mbed-os-core please review.

@AGlass0fMilk
Copy link
Member Author

@maclobdell

Copy link
Contributor

@desmond-blue desmond-blue left a comment

Choose a reason for hiding this comment

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

Why targets.json involves other platform's change? Others look good to me.

@bulislaw
Copy link
Member

I think there's a merge error in the targets.json as some of the newly introduced changes are being removed.

Also our I2CSlave implementation saddens me everytime I look at it... but we didn't have any customer request to making it better. Open for community contributions, if someone needs it and has time.

@AGlass0fMilk
Copy link
Member Author

Yeah, I must have messed up something with targets.json. I’ll fix it shortly

@bulislaw what don’t you like about the I2CSlave API? It is kind of Arduino-like (blocking, wasteful of CPU and power) but at least we have an API... I was thinking it was going to be axed soon.

One improvement would be an asynch API for slave operation.

I2CSlave is nice for multi-MCU designs where you just need simple communication. I’m using it for collecting beacon data from a BLE SoC and sending it over CAN using an STM32F0.

@AGlass0fMilk
Copy link
Member Author

@desmond-blue @bulislaw I reverted the unrelated changes in targets.json

@adbridge
Copy link
Contributor

@bulislaw could you address @AGlass0fMilk's comments ?

@bulislaw
Copy link
Member

@bulislaw what don’t you like about the I2CSlave API? It is kind of Arduino-like (blocking, wasteful of CPU and power) but at least we have an API... I was thinking it was going to be axed soon.
One improvement would be an asynch API for slave operation.
I2CSlave is nice for multi-MCU designs where you just need simple communication. I’m using it for collecting beacon data from a BLE SoC and sending it over CAN using an STM32F0.

Just ranting here... Yeah, current spinning design is not very efficient. I would say asynch is the only reasonable design pattern for slave.

bulislaw
bulislaw previously approved these changes Dec 27, 2019
@AGlass0fMilk
Copy link
Member Author

@bulislaw Does this still need work? Please update the labels accordingly.

What's stopping this from being merged?

0xc0170
0xc0170 previously requested changes Jan 3, 2020
Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

2 styling issues, otherwise LGTM

@@ -7472,6 +7472,7 @@
"FLASH",
"I2C",
"I2C_ASYNCH",
"I2CSLAVE",
Copy link
Contributor

Choose a reason for hiding this comment

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

can you fix alignment here and line below?

} else {

/* Initialze driver in blocking mode. */
nrfx_twi_init(&nordic_nrf5_instance[instance],
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 HAL file, isn't it using spaces as defined in astyle config ? I can see this is 8 spaces at least, or even tabs?

As it was , it was following the style.

@0xc0170 0xc0170 added the release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 label Jan 3, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Jan 3, 2020

Once updated, we will run CI

@AGlass0fMilk
Copy link
Member Author

Tabs are the bane of my existence... I will revise.

I recently discovered Eclipse has TWO settings you need to change to use spaces instead of tabs so hopefully this will be the last time this happens... 🤞

@AGlass0fMilk
Copy link
Member Author

Alright! I fixed my configurations for tabs in both my laptop's eclipse instances and my emacs settings! I also untabified targets.json and i2c_api.c.

This PR should be good to go when the PR it relies on is fixed up. It may need a rebase though.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 9, 2020

This PR should be good to go when the PR it relies on is fixed up. It may need a rebase though.

Rebased needed, correct.

@AGlass0fMilk
Copy link
Member Author

@0xc0170 I will rebase once #12160 is merged.

@AGlass0fMilk
Copy link
Member Author

@0xc0170 I realize there are a lot of stupid little whitespace commits/changes in this PR currently. I will deal with those when I rebase.

@0xc0170 0xc0170 removed the release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 label Jan 13, 2020
@mergify
Copy link

mergify bot commented Jan 20, 2020

This PR cannot be merged due to conflicts. Please rebase to resolve them.

@adbridge
Copy link
Contributor

@AGlass0fMilk as per our guidelines, as this is a feature update the following fields need to be filled in with sufficient information for adopters of this functionality:
Impact of changes
Migration actions required

Thanks.

@0xc0170 0xc0170 self-requested a review February 6, 2020 09:12
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 6, 2020

@AGlass0fMilk Shall we close and reopen once rebased and fixed or an update incoming anytime soon?

@mergify mergify bot dismissed 0xc0170’s stale review April 3, 2020 09:40

Pull request has been modified.

@AGlass0fMilk
Copy link
Member Author

Rebased. Tested and working.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 6, 2020

@AGlass0fMilk We are making 5.15 CI jobs priority currently, this will be scheduled when we can.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 8, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Apr 8, 2020

Test run: FAILED

Summary: 2 of 3 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM

@mergify mergify bot added needs: work and removed needs: CI labels Apr 8, 2020
@AGlass0fMilk
Copy link
Member Author

@0xc0170 Seems like unrelated failures on this target:
DISCO_L475VG_IOT01A

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 9, 2020

There was an example broken, will restart testing

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 9, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Apr 9, 2020

Test run: FAILED

Summary: 2 of 3 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM

@AGlass0fMilk
Copy link
Member Author

@0xc0170 Seems to be another CI issue.

Just to be sure, it's not related to the fact that this PR modifies the I2CSlave example?

mbed-os/drivers/I2CSlave.h

Lines 37 to 126 in 6baab6c

* Example Simple I2C slave and master (requires two Mbed-boards):
* @code
* #include <mbed.h>
* #include <mbed_wait_api.h>
* #include <string.h>
*
* #define BUILD_I2C_SLAVE 1 // Build for slave or master of this example
*
* #define SLAVE_ADDR 0xA0
* #define BUFFER_SIZE 6
*
* #if BUILD_I2C_SLAVE
*
* // Slave side of the example
*
* #if !DEVICE_I2CSLAVE
* #error [NOT_SUPPORTED] I2C Slave is not supported
* #endif
*
* I2CSlave slave(I2C_SDA, I2C_SCL);
*
* int main() {
*
* char buf[BUFFER_SIZE] = "ABCDE";
*
* slave.address(SLAVE_ADDR);
* while (1) {
* int i = slave.receive();
* switch (i) {
* case I2CSlave::ReadAddressed:
* // Write back the buffer from the master
* slave.write(buf, BUFFER_SIZE);
* printf("Written to master (addressed): %s\n", buf);
* break;
*
* case I2CSlave::WriteGeneral:
* slave.read(buf, BUFFER_SIZE);
* printf("Read from master (general): %s\n", buf);
* break;
*
* case I2CSlave::WriteAddressed:
* slave.read(buf, BUFFER_SIZE);
* printf("Read from master (addressed): %s\n", buf);
* break;
* }
* }
* }
*
* #else
*
* // Master side of the example
*
* I2C master(I2C_SDA, I2C_SCL);
*
* static const char* to_send[] = { "abcde", "12345", "EFGHI" };
*
* int main() {
* char buf[BUFFER_SIZE];
* int send_index = 0;
*
* while (1) {
* strcpy(buf, to_send[send_index]);
*
* // Write the new message to the slave
* if (master.write(SLAVE_ADDR, buf, BUFFER_SIZE)) {
* printf("Failed to write to slave!\n");
* } else {
* printf("Written to slave: %s\n", buf);
* }
*
* // Read what the slave has (should be identical)
* if (master.read(SLAVE_ADDR, buf, BUFFER_SIZE)) {
* printf("Failed to read from slave!\n");
* } else {
* printf("Read from slave: %s\n", buf);
* }
*
* // Change the message we're writing to the slave
* send_index++;
* if (send_index > 2) {
* send_index = 0;
* }
*
* wait_us(500000); // Wait 0.5s
* }
* }
*
* #endif
*
* @endcode

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 14, 2020

Correct, will restart

@mbed-ci
Copy link

mbed-ci commented Apr 14, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 3
Build artifacts

@0xc0170 0xc0170 merged commit 098c72a into ARMmbed:master Apr 14, 2020
@mergify mergify bot removed the ready for merge label Apr 14, 2020
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.

7 participants