-
Notifications
You must be signed in to change notification settings - Fork 2k
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: add gpio alternative functions #7373
Conversation
quite urgent, as need by lots of other periph drivers, see reference PRs above. |
b5c2e03
to
5396d4a
Compare
several PR are waiting for this one, could someone find time to review and ACK?! |
ping, anyone care to review, please! |
boards/remote-pa/board.c
Outdated
@@ -60,7 +60,7 @@ static void rf_switch_init(void) | |||
RF_SWITCH_PORT->DIR |= (1 << RF_SWITCH_PIN); | |||
|
|||
/* configure io-mux for used pins */ | |||
IOC->OVER[RF_SWITCH_PIN] = IOC_OVERRIDE_OE; | |||
IOC_PXX_OVER[RF_SWITCH_PIN] = IOC_OVERRIDE_OE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't this whole block be handled by a simple gpio_init
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might be right, will look into it shortly.
cpu/cc2538/include/periph_cpu.h
Outdated
* | ||
* @param[in] pin gpio pin | ||
* @return 0 on success, otherwise error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description suggests that any kind of error checking is done in the function. Looking in the function body, there isn't any. Maybe put something more concrete here, like:
0 if pin != GPIO_UNDEF, -1 otherwise
cpu/cc2538/periph/gpio.c
Outdated
return -1; | ||
} | ||
|
||
if (over >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why dont't you just use an unsigned type for this parameter and omit the condition check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already answered myself by reading (and understanding) the function description. ;)
|
cpu/cc2538/include/periph_cpu.h
Outdated
@@ -127,24 +127,15 @@ static inline uint8_t gpio_pp_num(gpio_t pin) | |||
} | |||
|
|||
/** | |||
* @brief Helper function to enable gpio hardware control | |||
* @brief Alternative GPIO init function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little arbitrary to me. I think this function initializes a pin in alternate function mode (or peripheral mode) or whatever TI is calling this. So not the function is an alternative to the default init function, but the resulting pin mode is an alternative to the default input or output mode...
boards/remote-pa/board.c
Outdated
@@ -60,7 +60,7 @@ static void rf_switch_init(void) | |||
RF_SWITCH_PORT->DIR |= (1 << RF_SWITCH_PIN); | |||
|
|||
/* configure io-mux for used pins */ | |||
IOC->OVER[RF_SWITCH_PIN] = IOC_OVERRIDE_OE; | |||
IOC_PXX_OVER[RF_SWITCH_PIN] = IOC_OVERRIDE_OE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't this whole block be handled by a simple gpio_init
?
cpu/cc2538/periph/gpio.c
Outdated
{ | ||
if (pin == GPIO_UNDEF) { | ||
return -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be done using an assert()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true that.
5396d4a
to
aa165d6
Compare
@haukepetersen comments addressed |
boards/remote-pa/board.c
Outdated
RF_SWITCH_INTERNAL; | ||
/* Set RF 2.4GHz as default */ | ||
gpio_init(RF_SWITCH_GPIO, GPIO_OUT); | ||
RF_SWITCH_2_4_GHZ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indention off by 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I somehow messed up my editor config and tab size is 2 instead of 4 - need to fix that
boards/remote-pa/include/board.h
Outdated
#define RF_SWITCH_GPIO GPIO_PD4 | ||
#define RF_SWITCH_SUB_GHZ gpio_set(RF_SWITCH_GPIO) | ||
#define RF_SWITCH_2_4_GHZ gpio_clear(RF_SWITCH_GPIO) | ||
#define RF_SWITCH_TOGGLE gpio_toggle(RF_SWITCH_GPIO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO in this context, a toggle operation does not really make sense, does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well that depends on the use-case, actually these boards have 2 radios (sub GHz and 2.4GHz). They (can) share the same antenna, hence you may want to use only one at a time which makes this short-hand macro quite useful, or not?
boards/remote-pa/include/board.h
Outdated
#define RF_SWITCH_EXTERNAL (RF_SWITCH_PORT->DATA |= (1 << RF_SWITCH_PIN)) | ||
#define RF_SWITCH_INTERNAL (RF_SWITCH_PORT->DATA &= ~(1 << RF_SWITCH_PIN)) | ||
#define RF_SWITCH_TOGGLE (RF_SWITCH_PORT->DATA ^= (1 << RF_SWITCH_PIN)) | ||
#define RF_SWITCH_GPIO GPIO_PD4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but shouldn't this be GPIO_PIN(3, 4)
?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but there are lots of these macro usages throughout the cc2538 code base and I remove them in #7320, all at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I'll that here right away.
comments addressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
5ff8498
to
f22172f
Compare
squashed |
and go. |
based on discussion in #7316 this add alternative gpio functions to be used in periph drivers to hide internal gpio configuration.