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

cpu, cc2538: gpio helper functions #7316

Merged
merged 1 commit into from
Jul 7, 2017

Conversation

smlng
Copy link
Member

@smlng smlng commented Jul 5, 2017

this PR make some periph-gpio helper function accessible by other periph drivers of CC2538, such as I2C, SPI, and UART. Follow up PRs will adapt named periph drivers to use RIOTs gpio API instead of the cc2538 internal API, to simplify usage and periph_conf.

@smlng smlng added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Area: drivers Area: Device drivers Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Jul 5, 2017
@smlng smlng requested review from A-Paul and a user July 5, 2017 07:14
@smlng smlng self-assigned this Jul 5, 2017
@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 6, 2017
@smlng smlng added this to the Release 2017.10 milestone Jul 6, 2017
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

The function gpio_port_num() returns a wrong value.
Otherwise only small things, see comments.

@@ -14,6 +15,7 @@
* @brief CPU specific definitions for internal peripheral handling
*
* @author Hauke Petersen <[email protected]>
* @author Sebastian Meiling <[email protected]>
Copy link

Choose a reason for hiding this comment

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

The indentation is not correct

{
return (int)(pin & PIN_MASK);
}
/**
Copy link

Choose a reason for hiding this comment

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

Insert a blank line

}

/**
* @brief Helper function to enable gpio software control
Copy link

Choose a reason for hiding this comment

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

Helper function to disable gpio software control ?

Copy link
Member Author

Choose a reason for hiding this comment

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

no? it disables hardware control, as it is the reverse of gpio_hw_ctrl() above.

Copy link

Choose a reason for hiding this comment

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

Yes, you have right :)

static inline int gpio_port_num(gpio_t pin)
{
return (int)((pin & PORTNUM_MASK) >> PORTNUM_SHIFT) - 1;
}
Copy link

Choose a reason for hiding this comment

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

The return value of this function is for any gpio pin -1. Detected by a hardware test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't reproduce that. I added debug output to gpio_init, you can try tests/periph_gpio for example and init one of the LEDs with init_put 3 4 you will see debug output showing real pin address (uint32_t) as well as port and pin recovered from that. For me looks like that:

> init_out 3 4
2017-07-06 16:52:33,730 - INFO #  init_out 3 4
2017-07-06 16:52:33,731 - INFO # GPIO 1074642948, PORT: 3, PIN: 4

static inline int gpio_pp_num(gpio_t pin)
{
return (gpio_port_num(pin) * 8) + gpio_pin_num(pin);
}
Copy link

Choose a reason for hiding this comment

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

The return value of this function is because of gpio_port_num() wrong.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Everything looks good. I have tested the function gpio_port_num () not correctly.

}

/**
* @brief Helper function to enable gpio software control
Copy link

Choose a reason for hiding this comment

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

Yes, you have right :)

*/
static inline uint8_t gpio_pin_num(gpio_t pin)
{
return (int)(pin & PIN_MASK);
Copy link

Choose a reason for hiding this comment

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

The conversion is wrong. It should be uint8_t.

Copy link
Member Author

Choose a reason for hiding this comment

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

oops missed that

@smlng
Copy link
Member Author

smlng commented Jul 7, 2017

squashed, lets see if murdock gets happy

@smlng
Copy link
Member Author

smlng commented Jul 7, 2017

@PeterKietzmann I assume @dnahm is not allow[ed] to(officially) approve for RIOT PRs [yet], correct? Can you help and proxy-approve - this PR is kind of important for all follow ups, which I'd like to rebase after this merge.

Copy link
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

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

Code-wise looks fine and @dnahm approved testing. ACK and go

@PeterKietzmann PeterKietzmann merged commit 9fd24e2 into RIOT-OS:master Jul 7, 2017
@smlng smlng deleted the cpu/cc2538/periph_gpio branch July 7, 2017 11:57
@haukepetersen
Copy link
Contributor

Hej, nice effort cleaning up the cc2538 code after all. But I fear this PR is going only half the way and is not really helping in separating concerns: the actual solution for simplification and stricter separation of periph drivers is not to export internal GPIO driver functionality to other GPIO drivers, but to extend the interface locally with CPU internal functions for configuring pins in alternate function mode and so on.

Simply have a look at e.g. gpio_init_analog() and gpio_init_af() functions for the stm32 CPUS (cpu/stm32_common/include/periph_cpu_common.h). With this approach, all the other periph drivers can configure their pins in whatever mode they need, without having anything to know about the internals of the GPIO driver...

@smlng
Copy link
Member Author

smlng commented Jul 13, 2017

@haukepetersen I'm not sure if I completely get what you mean, but I guess you meant to hide such things in the I2C driver: here?

@haukepetersen
Copy link
Contributor

exactly. For the concrete situation, I would imagine the i2c driver doing something like:

...
gpio_init_af(i2c_config[dev].scl, IOC_I2CMSSCL, I2C_CMSSCL, IOC_OVERRIDE_PUE);
gpio_init_af(i2c_config[dev].sda, IOC_I2CMSSDA, I2C_CMSSDA, IOC_OVERRIDE_PUE);

This way the gpio init code in the i2c driver is simplified a bit, and more importantly, the gpio_ini_af() function can be used exactly in the same way in other periph drivers...

@smlng
Copy link
Member Author

smlng commented Jul 13, 2017

ah, thanks for clarification! I'll mark the other periph driver reworks as WIP and will adapt ...

@haukepetersen
Copy link
Contributor

nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants