Skip to content

ssd1306: Support connecting SPI and I2C simultaneously #56887

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 5 commits into from
Sep 13, 2023

Conversation

soburi
Copy link
Member

@soburi soburi commented Apr 16, 2023

Support connecting different display for each SPI and I2C at the same time.

In a case like DTS below.

&spi1 {
        ssd1306_spi: ssd1306@0 {
		compatible = "solomon,ssd1306fb";
                ...
        };

};

&i2c0 {
        ssd1306_i2c: ssd1306@3c {
		compatible = "solomon,ssd1306fb";
		...
	};
};

In addition, I'm doing the necessary correspondence for connecting multiple devices.

@zephyrbot zephyrbot requested a review from jfischer-no April 16, 2023 04:19
@soburi soburi force-pushed the ssd1306_i2c_and_spi branch from f21ddbc to 37aae4b Compare April 16, 2023 04:20
@soburi soburi marked this pull request as draft April 16, 2023 05:07
@soburi soburi force-pushed the ssd1306_i2c_and_spi branch from 80eba62 to 5a9155f Compare April 16, 2023 08:11
@soburi soburi marked this pull request as ready for review April 16, 2023 08:12
@soburi soburi requested review from galak and erwango as code owners April 16, 2023 08:12
@zephyrbot zephyrbot added area: Shields Shields (add-on boards) area: Devicetree Binding PR modifies or adds a Device Tree binding labels Apr 16, 2023
@zephyrbot zephyrbot requested a review from avisconti April 16, 2023 08:13
@soburi soburi changed the title drivers: display: ssd1306: Support connecting SPI and I2C at the same ssd1306: Support connecting SPI and I2C simultaneously Apr 16, 2023
@soburi soburi force-pushed the ssd1306_i2c_and_spi branch from 5a9155f to 4e68896 Compare April 16, 2023 08:45
@soburi soburi marked this pull request as draft April 17, 2023 10:05
@soburi soburi force-pushed the ssd1306_i2c_and_spi branch from 4e68896 to 7b2136a Compare April 17, 2023 12:26
@soburi soburi marked this pull request as ready for review April 18, 2023 02:01
@soburi soburi marked this pull request as draft April 18, 2023 02:02
@soburi soburi marked this pull request as ready for review April 18, 2023 02:04
Comment on lines -23 to -41
#if DT_INST_PROP(0, segment_remap) == 1
#define SSD1306_PANEL_SEGMENT_REMAP true
#else
#define SSD1306_PANEL_SEGMENT_REMAP false
#endif

#if DT_INST_PROP(0, com_invdir) == 1
#define SSD1306_PANEL_COM_INVDIR true
#else
#define SSD1306_PANEL_COM_INVDIR false
#endif

#if DT_INST_PROP(0, com_sequential) == 1
#define SSD1306_COM_PINS_HW_CONFIG SSD1306_SET_PADS_HW_SEQUENTIAL
#else
#define SSD1306_COM_PINS_HW_CONFIG SSD1306_SET_PADS_HW_ALTERNATIVE
#endif

#define SSD1306_PANEL_NUMOF_PAGES (DT_INST_PROP(0, height) / 8)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This patch should be first change to add multi instance support for this driver.

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 reordered commits.

Copy link
Member

Choose a reason for hiding this comment

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

@soburi this is still the last patch, can you check again?

Copy link
Member Author

Choose a reason for hiding this comment

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

@fabiobaltieri
Thank you for pointing out. It's certainly not good.
I fixed it.

struct spi_buf_set tx_bufs = {
.buffers = &tx_buf,
.count = 1
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please stop unnecessary code reformatting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines -38 to -42
config SSD1306_REVERSE_MODE
bool "SSD1306 reverse mode"
help
SSD1306 reverse video mode.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This commit should be second change before multi instance support commit.

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 reordered commits.

Comment on lines 51 to 33
union ssd1306_bus {
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
struct i2c_dt_spec i2c;
#endif
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
struct spi_dt_spec spi;
#endif
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please just

union ssd1306_bus {
	struct i2c_dt_spec i2c;
	struct spi_dt_spec spi;
};

and remove all this ifdefery.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines 483 to 524
#define SSD1306_CONFIG_SPI(inst) \
{ \
.bus = {.spi = SPI_DT_SPEC_INST_GET( \
inst, SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8), \
0)}, \
.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
.bus_ready = ssd1306_bus_ready_spi, .write_bus = ssd1306_write_bus_spi, \
.bus_name = ssd1306_bus_name_spi, \
IF_ENABLED(DT_ANY_INST_ON_BUS_STATUS_OKAY(spi), \
(.data_cmd = GPIO_DT_SPEC_INST_GET(inst, data_cmd_gpios), )) \
}

#define SSD1306_CONFIG_I2C(inst) \
{ \
.bus = {.i2c = I2C_DT_SPEC_INST_GET(inst)}, \
.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
.bus_ready = ssd1306_bus_ready_i2c, .write_bus = ssd1306_write_bus_i2c, \
.bus_name = ssd1306_bus_name_i2c, \
IF_ENABLED(DT_ANY_INST_ON_BUS_STATUS_OKAY(spi), (.data_cmd = {0}, )) \
}

#define SSD1306_DEFINE(inst) \
static struct ssd1306_data ssd1306_driver_##inst; \
static const struct ssd1306_config ssd1306_config_##inst = \
COND_CODE_1(DT_INST_ON_BUS(inst, spi), (SSD1306_CONFIG_SPI(inst)), \
(SSD1306_CONFIG_I2C(inst))); \
\
DEVICE_DT_INST_DEFINE(inst, ssd1306_init, NULL, &ssd1306_driver_##inst, \
&ssd1306_config_##inst, POST_KERNEL, CONFIG_DISPLAY_INIT_PRIORITY, \
&ssd1306_driver_api);

DT_INST_FOREACH_STATUS_OKAY(SSD1306_DEFINE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Multi instance support should be the last commit in this PR.

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 reordered commits.

@soburi soburi force-pushed the ssd1306_i2c_and_spi branch 3 times, most recently from 7bea780 to 1a0dddb Compare April 19, 2023 21:37
@soburi soburi requested a review from jfischer-no April 19, 2023 22:07
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jun 19, 2023
@fabiobaltieri
Copy link
Member

@erwango @jfischer-no could you do another review pass once you have a chance?

@github-actions github-actions bot removed the Stale label Jun 21, 2023
@soburi soburi force-pushed the ssd1306_i2c_and_spi branch from 1a0dddb to 0645aa1 Compare June 22, 2023 22:12
@soburi
Copy link
Member Author

soburi commented Aug 21, 2023

@erwango @mbolivar-ampere
Could you take a look please?

@fabiobaltieri
Copy link
Member

@erwango @mbolivar-ampere ping

erwango
erwango previously approved these changes Aug 30, 2023
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Ok for shield part.

@jfischer-no
Copy link
Collaborator

What changed again?

@soburi soburi dismissed stale reviews from erwango and fabiobaltieri via b3ebfcb August 31, 2023 04:26
@soburi soburi force-pushed the ssd1306_i2c_and_spi branch from 5b39a88 to b3ebfcb Compare August 31, 2023 04:26
@zephyrbot zephyrbot requested a review from kartben August 31, 2023 04:26
@soburi
Copy link
Member Author

soburi commented Aug 31, 2023

@jfischer-no

What changed again?

Sinse Aug 9,
I fixed about pointed by @mbolivar-ampere #56887 (review)

and I change to remove #undef DT_DRV_COMPAT line.

https://github.com/zephyrproject-rtos/zephyr/compare/382db6dd259f314d9527b2e25eedd2aa303a0c37..e4646cf81d7346a04b62e7497c8db786b5533297

jfischer-no
jfischer-no previously approved these changes Aug 31, 2023
fabiobaltieri
fabiobaltieri previously approved these changes Aug 31, 2023
erwango
erwango previously approved these changes Aug 31, 2023
@soburi
Copy link
Member Author

soburi commented Sep 5, 2023

@mbolivar-ampere
Could you take a look again, please?

Rename `DT_COMPAT_ON_BUS_INTERNAL` to
`DT_HAS_COMPAT_ON_BUS_STATUS_OKAY` to make it a public DT API.

It is helpful for code that handles multiple DT_DRV_COMPAT in one file,
such as in the following cases.

```
 #if (DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(some_sensor, i2c) || \
      DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(another_sensor, i2c)
 ...
 #endif

 #define DT_DRV_COMPAT some_sensor
 DT_INST_FOREACH_STATUS_OKAY(DEFINE_SOME_SENSOR)

 #undef DT_DRV_COMPAT
 #define DT_DRV_COMPAT another_sensor
 DT_INST_FOREACH_STATUS_OKAY(DEFINE_ANOTHER_SENSOR)
```

Signed-off-by: TOKITA Hiroshi <[email protected]>
Store properties defined in dts in ssd1306_config's fields.
And replace code that uses DT_INST_PROP (0, ...) by config properties.

Signed-off-by: TOKITA Hiroshi <[email protected]>
When multiple devices are connected, the SSD1306_REVERSE_MODE setting
cannot switch for each device.
Add an equivalent setting to the devicetree properties to replace it.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Determine sh1106 from the `compatibility` value instead of
the SSD1306_CONTROLLER_TYPE setting.

Change the settings in `boards/shields/ssd1306/sh1106_128x64.overlay`
to follow this change.
Remove the SSD1306_CONTROLLER_TYPE from its Kconfig.defconfig,
and set the `compatibility` to `sinowealth,sh1106`.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Support connecting different display for each SPI and I2C
at the same time.

In a case like DTS below.

```
&spi1 {
        ssd1306_spi: ssd1306@0 {
		compatible = "solomon,ssd1306fb";
                ...
        };

};

&i2c0 {
        ssd1306_i2c: ssd1306@3c {
		compatible = "solomon,ssd1306fb";
		...
	};
};
```

Signed-off-by: TOKITA Hiroshi <[email protected]>
@soburi soburi dismissed stale reviews from erwango, fabiobaltieri, and jfischer-no via e6ece74 September 8, 2023 22:16
@soburi soburi force-pushed the ssd1306_i2c_and_spi branch from b3ebfcb to e6ece74 Compare September 8, 2023 22:16
@soburi
Copy link
Member Author

soburi commented Sep 8, 2023

@mbolivar-ampere
ping

@mbolivar-ampere mbolivar-ampere merged commit 9fcfb31 into zephyrproject-rtos:main Sep 13, 2023
@soburi soburi deleted the ssd1306_i2c_and_spi branch September 13, 2023 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Devicetree area: Display area: Shields Shields (add-on boards)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants