-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
ssd1306: Support connecting SPI and I2C simultaneously #56887
Conversation
f21ddbc
to
37aae4b
Compare
80eba62
to
5a9155f
Compare
5a9155f
to
4e68896
Compare
4e68896
to
7b2136a
Compare
#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) |
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 patch should be first change to add multi instance support for this driver.
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 reordered commits.
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.
@soburi this is still the last patch, can you check again?
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.
@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 | ||
}; |
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.
Please stop unnecessary code reformatting.
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.
config SSD1306_REVERSE_MODE | ||
bool "SSD1306 reverse mode" | ||
help | ||
SSD1306 reverse video mode. | ||
|
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 commit should be second change before multi instance support commit.
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 reordered commits.
drivers/display/ssd1306.c
Outdated
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 | ||
}; |
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.
Please just
union ssd1306_bus {
struct i2c_dt_spec i2c;
struct spi_dt_spec spi;
};
and remove all this ifdefery.
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.
Removed #if in SPI and I2C conditionals.
However, the following parts are left because they cause unreferenced warnings.
https://github.com/zephyrproject-rtos/zephyr/pull/56887/files#diff-7da6d958478082c2b7f2549d889797958fbf4226bbee0fadbf40e3907479afadR68
https://github.com/zephyrproject-rtos/zephyr/pull/56887/files#diff-7da6d958478082c2b7f2549d889797958fbf4226bbee0fadbf40e3907479afadR94
drivers/display/ssd1306.c
Outdated
#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) |
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.
Multi instance support should be the last commit in this PR.
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 reordered commits.
7bea780
to
1a0dddb
Compare
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. |
@erwango @jfischer-no could you do another review pass once you have a chance? |
1a0dddb
to
0645aa1
Compare
@erwango @mbolivar-ampere |
@erwango @mbolivar-ampere ping |
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.
Ok for shield part.
What changed again? |
5b39a88
to
b3ebfcb
Compare
Sinse Aug 9, and I change to remove |
@mbolivar-ampere |
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]>
e6ece74
b3ebfcb
to
e6ece74
Compare
@mbolivar-ampere |
Support connecting different display for each SPI and I2C at the same time.
In a case like DTS below.
In addition, I'm doing the necessary correspondence for connecting multiple devices.