Skip to content

Conversation

@nielsnl68
Copy link

What does this implement/fix?

This PR enables us to dynamically add more databus drivers when needed.
It is very easy to implement.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

nielsnl68 and others added 5 commits April 19, 2024 00:53
* Implement i80 bus for ili9xxx displays

* clang-tidy

* yamllint

* Fix spi_device test

---------

Co-authored-by: clydebarrow <[email protected]>
- allow dynamicly add new byte_busses via esphome's registry() method. And makes it possible to detach the ili9xxx from the different databus chooses
- make transactions nestable so you can call multiple times begin_transaction and end it
- and write_component() inline methods.
- remove unneeded code
- renamed write_cmd_data to write_command
i80:
- renamed i80Client to i80ByteBus conform SPIByteBus
- tried to making running
- ERROR: ID esp32_esp32internalgpiopin_2 is already registered (NOT FIXED)
- allowing to be used in arduino setup.
- save rd_pin
SPI:
- moving creation of SPIClient inside c++
ili9xxx:
- add missing await
@nielsnl68 nielsnl68 requested a review from clydebarrow as a code owner April 20, 2024 12:32
- allow to change default databus via callback function
- adding final_validation option
- restore part of the I80 and SPI configuration settings
- update list of models with info about screensize, available data busses and if esp8266 is supported.
@nielsnl68
Copy link
Author

Okay this is what i wanted to do for the PR i was working on.
Everything compiles fine.

@clydebarrow
Copy link
Owner

Just started looking at this.

Lots of CI checks are failing.

What are all these in ili9xxx/display.py?

            "par8",
            "par9",
            "par16",
            "par18",
            "rgb16",
            "rgb18",
            "rgb24",

These obviously refer to bus names, but should be constants, not literal strings:

            "spi",
            "i80",

The values defined in ili9xxx/display.py in the MODELS dict should be either dicts or classes. References like MODELS[model][1] and MODELS[model][2][0] don't mean much to someone reading the code.

Compiling existing yamls fails with errors:

  File "/Users/clyde/dev/opensourceprojects/esp/esphome/esphome/components/ili9xxx/display.py", line 322, in give_default_bus_type
    return MODELS[model][2][0]
           ~~~~~~^^^^^^^
KeyError: 'ili9341'
def spi_device_schema(
    cs_pin_required=True,
    default_data_rate=cv.UNDEFINED,
    default_mode=cv.UNDEFINED,
    quad=False,
    dc_pin_required=True,
    use_16BitData=False,
):

dc_pin_required should default to False - spi devices other than displays don't need a DC pin.

The "16bit_data" spi type should be removed - that's not a variation on the bus, it's a variation in how data is transferred for a specific peripheral, and there is no way of knowing in advance how that should be handled.

As discussed before, there is no purpose in allowing multiple begin_transaction calls - transactions can't be nested, and any attempt to do so is an error.

  void begin_transaction() {
    if (++this->transaction_counter == 0) {
      do_begin_transaction();
    }
  }

more to come...

@nielsnl68
Copy link
Author

Just started looking at this.

Thanks.

Lots of CI checks are failing.

Not sure where they coming from but those i checked did not seem related to my changes.

What are all these in ili9xxx/display.py?

            "par8",
            "par9",
            "par16",
            "par18",
            "rgb16",
            "rgb18",
            "rgb24",

Those are the busses the display controller can handle. This does not mean that we support them.
The different options will give the compiler the possibility to validate of the user has added enough pins for the chosen bus architecture. "par" is an alias for the i80 interface and "rgb" is an alias for the RPi_dpi interface/

These obviously refer to bus names, but should be constants, not literal strings:

I agree and i have modified those now.

            "spi",
            "i80",

The values defined in ili9xxx/display.py in the MODELS dict should be either dicts or classes. References like MODELS[model][1] and MODELS[model][2][0] don't mean much to someone reading the code.

Oww i did not read your suggestion here correct. At the moment i created some constant's defining what is what. But i think we should use the Registry solution here as well. I already implemented it in my display_driver and can implement it here as well. But can this wait until this our PR is merged?

Compiling existing yamls fails with errors:

  File "/Users/clyde/dev/opensourceprojects/esp/esphome/esphome/components/ili9xxx/display.py", line 322, in give_default_bus_type
    return MODELS[model][2][0]
           ~~~~~~^^^^^^^
KeyError: 'ili9341'

Could you show the display part of your yaml so i can see what did happen?

def spi_device_schema(
    cs_pin_required=True,
    default_data_rate=cv.UNDEFINED,
    default_mode=cv.UNDEFINED,
    quad=False,
    dc_pin_required=True,
    use_16BitData=False,
):

dc_pin_required should default to False - spi devices other than displays don't need a DC pin.

Oeps of cource that should have been false.

The "16bit_data" spi type should be removed - that's not a variation on the bus, it's a variation in how data is transferred for a specific peripheral, and there is no way of knowing in advance how that should be handled.

As discussed before, there is no purpose in allowing multiple begin_transaction calls - transactions can't be nested, and any attempt to do so is an error.

Sorry, that is your opinion. I disagree, i have used many communication packages in the past from different vendors, that worked this way.
The SPI bus does not need to be opened and closed for every command that we send. It is okay to open once and send all the commands and close the bus after that.

As i said on Discord. when we let the display driver handle the opening and closing of the transaction. and remove it in the "send_command" future then we do not need to nest here.

  void begin_transaction() {
    if (++this->transaction_counter == 0) {
      do_begin_transaction();
    }
  }

more to come...

I cant wait to see what you find more 🤞🏼

Sadly i'm not able to update this per anymore, i will send you the changes via discord.

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.

2 participants