Skip to content

Conversation

@carlescufi
Copy link
Member

Convert to the new GPIO API, use raw access since this is a low-level
GPIO-based driver.

Signed-off-by: Carles Cufi [email protected]

Convert to the new GPIO API, use raw access since this is a low-level
GPIO-based driver.

Signed-off-by: Carles Cufi <[email protected]>
/* Set the column pins to their correct values */
for (pin = LED_COL1_GPIO_PIN; pin <= LED_COL9_GPIO_PIN; pin++) {
gpio_pin_write(disp->dev, pin, !!(val & BIT(pin)));
gpio_pin_set_raw(disp->dev, pin, !!(val & BIT(pin)));
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 did not want to change the original !!(), leaving it to @jhedberg if he prefers to use a simple & instead.

Copy link
Member

@jhedberg jhedberg Jan 24, 2020

Choose a reason for hiding this comment

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

Aren't the correct values of the last parameter 0 and 1? That's what the !! is there for.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way the function is documented x & mask should work ("Writing any value other than 0 will set it to a high physical level.") Either !!(x & mask) or (x & mask) != 0 are good for clarity of intention. Sometimes people are confused by !!x though I personally like it (except where MISRA essential type requires a "boolean" expression).

@carlescufi
Copy link
Member Author

Tested on the micro:bit, using the display sample.

/* Set the column pins to their correct values */
for (pin = LED_COL1_GPIO_PIN; pin <= LED_COL9_GPIO_PIN; pin++) {
gpio_pin_write(disp->dev, pin, !!(val & BIT(pin)));
gpio_pin_set_raw(disp->dev, pin, !!(val & BIT(pin)));
Copy link
Contributor

Choose a reason for hiding this comment

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

The way the function is documented x & mask should work ("Writing any value other than 0 will set it to a high physical level.") Either !!(x & mask) or (x & mask) != 0 are good for clarity of intention. Sometimes people are confused by !!x though I personally like it (except where MISRA essential type requires a "boolean" expression).

@carlescufi carlescufi changed the title drivers: display: mb_display: Convert to the new GPIO API [topic-gpio] drivers: display: mb_display: Convert to the new GPIO API Jan 25, 2020
@MaureenHelm MaureenHelm merged this pull request into zephyrproject-rtos:topic-gpio Jan 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants