Skip to content
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

160 remove board defines #168

Merged
merged 19 commits into from
May 30, 2022
Merged

Conversation

mickeprag
Copy link
Contributor

@mickeprag mickeprag commented Mar 7, 2022

This is my take on #160 to remove defines for board definitions.

The goal has been to not break backwards compatibility. All current project should still work without modifications. Configuring the board to use is still possible through menuconfig, but is not required. For projects not using this library as an esp-idf component there is a new option (and default if nothing is defined) called EPD_BOARD_CUSTOM that can be used by PlatformIO projects or Arduino.
These project must call the new function epd_set_board() before epd_init() to tell which board to use.

The different code for each board is now separated into own source files to keep maintenance as clean and easy as possible. For third party boards these can also be used as a templates since it will be possible to support new boards without modify epdiy source.

Since this branch touches quite many files I have tried my best to create isolated atomic commits for easier review.

This is currently only tested on v5 boards.

@martinberlin
Copy link
Collaborator

Tested with Lilygo EPD47, just pulled Micke's repository and switched to branch 160-board_hal
Then I just run menuconfig and selected right board and display. Build reports this:

/home/martin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/epd_driver/libepd_driver.a(render.c.obj):(.literal.epd_init+0x4): undefined reference to `epd_board'

@mickeprag
Copy link
Contributor Author

Sorry, my mistake. Please try again now.

@martinberlin
Copy link
Collaborator

martinberlin commented Mar 9, 2022

Thanks Micke, now is complaining about this:

/src/epd_driver/board/epd_board_v5.c:5:10: fatal error: display_ops.h: No such file or directory
#include "display_ops.h"
^~~~~~~~~~~~~~~

Tomorrow when I find some time I will go through your code and try to get more awareness of what you modified. Now if you go into the referenced files, for example in my board epd_board_lilygo_t5_47.c and I change the includes to reference this folder:

#include "../display_ops.h"
#include "../i2s_data_bus.h"
#include "../rmt_pulse.h"

Then it compiles and by flashing I get this error:

assertion "epd_board != NULL" failed: file "/home/martin/esp/projects/pull-requests/epdiy-micke/src/epd_driver/render.c", line 249, function: epd_init

This needs an extra correction:

#if defined(CONFIG_EPD_BOARD_REVISION_LILYGO_T5_472) // --> it's without the 2:
           //     CONFIG_EPD_BOARD_REVISION_LILYGO_T5_47
  epd_set_board(&epd_board_lilygo_t5_47);
#endif

After this it refreshes and works as expected. When @mcer12 board comes I will test it also with his.
@vroland can you please test this also with a V6 board?

@mickeprag
Copy link
Contributor Author

Fixed these as well. Thanks.

@martinberlin
Copy link
Collaborator

martinberlin commented Mar 10, 2022

But did you push the changes? Or it’s me that I don’t find the commits. Now I see it’s in #include "epd_board_common.h"
But is also corrected the CONFIG_EPD_BOARD_REVISION_LILYGO_T5_472 , didn’t see that one in the commit. Thanks!

@mickeprag
Copy link
Contributor Author

I did push, yes. But there is no new commits.

@martinberlin
Copy link
Collaborator

I ask because I don't see the changes pulling from origin, same error as before is reported:
epd_board_common.c:1:10: fatal error: ../epd_board.h: No such file or directory
#include "../epd_board.h"
^~~~~~~~~~~~~~~~

Sorry but changes are not pushed, last commit in the log:
commit d7c2ced (HEAD -> 160-board_hal, origin/160-board_hal)
Date: Mon Mar 7 21:41:45 2022 +0100

@mickeprag
Copy link
Contributor Author

You have the change. The path did not contain ".." before. Why you still get compile error I need to check though.

The last commit has not been changed so the date is correct.

@martinberlin
Copy link
Collaborator

martinberlin commented Mar 10, 2022

No problem. But I must say I really don't get how is updated. Because usually if you review something, comes a new commit + push and you can check it before building it.
If the header files are in the include directory they should not need relative paths. This should be correct:

 #include "epd_board.h"

Actually that would be a better way to organize this. Header files should be in the include path and then you don't need to use this ugly relative "../" style paths. Actually I'm not sure that will compile in Arduino framework.
But overall very nice work!!!

More feedback: Refresh and update correct. Only at the end getting this:

I (978) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (7575) gpio: GPIO[5]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
E (7576) RTCIO: rtc_gpio_isolate(185): RTCIO number error

@mickeprag an additional request if you find some time: Can you prepare also an example and add it to the current ones, that shows how it should be done to declare the board dynamically? (Withouth using menuconfig)

Just declaring the Board directly in the main.c code maybe just add a comment in the the top that says that Board definition in menuconfig is not being used. That would be a nice one to test and experiment more what you did.

@martinberlin
Copy link
Collaborator

Started to play around with this so I can use it for the next revision of my S2 board
epd_board_v6_s2.zip

so you can check it out. I might have forgotten something.

Apart of that, in order to use this MCU, this are the things that need to be updated and I've on my list:

  • i2s_data_bus.c S2 has only I2S0 (only one I2S peripheral)
  • epd_board_common.c:13:33: error: 'ADC_WIDTH_BIT_12' undeclared (first use in this function); did you mean 'ADC_WIDTH_BIT_13'?
  • rmt_pulse.c:42:18: error: 'ETS_RMT_INTR_SOURCE' undeclared

martinberlin added a commit to martinberlin/epdiy-rotation that referenced this pull request Mar 27, 2022
@vroland
Copy link
Owner

vroland commented Apr 3, 2022

Thank you for going forward with this and sorry for the late reply. I like the direction this is going :)
Currently it looks like setting the VCOM voltage for V6 still only works trough defines. We shoudl probably expose an "epd_set_vcom" function in epd_board_specific.h?

@mickeprag
Copy link
Contributor Author

Thank you @vroland. I have some ideas regarding the VCOM voltage. But previously I had no way to test it since I don't have a v6 board. I just got my own version running so I should try to get some solution up on Github shortly.

@vroland
Copy link
Owner

vroland commented Apr 4, 2022

Sounds good :)

@vroland
Copy link
Owner

vroland commented Apr 20, 2022

Since I'm currently travelling I can't test this right now, so I'll have to rely on the judgement of the other contributors to try this out..

@martinberlin
Copy link
Collaborator

I will be also kind of busy at least until end of April, beginning of Mai since I'm reallocating to Barcelona and have a big mess in front of me.
But this should be tested at least in:

Let's keep it active and test it good before doing any merge. Also IMHO this should get a v1.0 tagged release and after this update it should have a different release version, so people using Platformio can relate to this using the: #v1.0 tag at the end of the github URL to avoid breaking any existing build. Maybe it's not needed but I will take some precautions provided that this is kind of a big update and touches core files.

mickeprag added 8 commits May 22, 2022 18:47
Instead of using defines to set the board hardware definitions each
board get its own file with the routines to access the hardware
functions. This way also third party boards can be implemented
without being required to modify the epdiy source.

So far only logic from display_ops.c has been ported. Work still
also exists to optimize duplicated code.

Care has been taken to not break existing code bases. If a board is
defined in menuconfig this will still be used.
The goal is to get rid of the config_reg_v*.h files
This should not be done for individual boards.
@mickeprag mickeprag force-pushed the 160-board_hal branch 2 times, most recently from 96cd9fa to 9ee422d Compare May 22, 2022 19:29
@mickeprag
Copy link
Contributor Author

I just rebased this branch on top of master and fixed the following:

  • epd_powerdown() that was only defined for LilyGO boards has been renamed to epd_powerdown_lilygo_t5_47() and is always defined. The old method is left to provide backwards compatibility but has been marked deprecated
  • To set the vcom voltage for v6 boards now have 4 options:
    1. Set the value in menuconfig (as before, for esp-idf projects)
    1. Define CONFIG_EPD_DRIVER_V6_VCOM (as before)
    1. Include the symbol int epd_driver_v6_vcom (as before, for Arduino)
    1. Implement the function uint16_t epd_board_vcom_v6() and return the voltage.

I feel I am pretty much done with this PR and is ready to merge.

@martinberlin
Copy link
Collaborator

martinberlin commented May 23, 2022

Awesome Micke, I will take some time to test it on the following days, and we can merge it.

Question: Do you think we should make a new release in case the Platformio users can still use the old way just fixing it to a release tag? (Like #6.2 )
Or we really do not have to do that? CC @mcer12

By the way tests are failing because of this:

/app/src/epd_driver/board/epd_board_common.c:1:10: fatal error: ../epd_board.h: No such file or directory
#include "../epd_board.h"
^~~~~~~~~~~~~~~~
compilation terminated.

That epd_board.h is in the include path. So I think is save to add it without the / backslash. Can you please change it?

@martinberlin martinberlin self-assigned this May 23, 2022
@martinberlin martinberlin added the refactoring This are core upgrades label May 23, 2022
@mickeprag
Copy link
Contributor Author

That epd_board.h is in the include path. So I think is save to add it without the / backslash. Can you please change it?

Done

@martinberlin martinberlin linked an issue May 30, 2022 that may be closed by this pull request
@martinberlin martinberlin merged commit f1e266c into vroland:master May 30, 2022
mickeprag added a commit to mickeprag/epdiy that referenced this pull request May 31, 2022
@mickeprag mickeprag mentioned this pull request May 31, 2022
vroland pushed a commit that referenced this pull request Jan 17, 2023
* 160 remove board defines (#168)

* Add board HAL (Hardware abstraction layer)

Instead of using defines to set the board hardware definitions each
board get its own file with the routines to access the hardware
functions. This way also third party boards can be implemented
without being required to modify the epdiy source.

So far only logic from display_ops.c has been ported. Work still
also exists to optimize duplicated code.

Care has been taken to not break existing code bases. If a board is
defined in menuconfig this will still be used.

* Move content of config_reg_v4.h into epd_board_v5.c

The goal is to get rid of the config_reg_v*.h files

* Move content of config_reg_v4.h into epd_board_v4.c

* Move content of config_reg_v6.h into epd_board_v6.c

* Move content of config_reg_v2.h into epd_board_v2_v3.c

* Move content of config_reg_v2.h into epd_board_lilygo_t5_47.c

* Remove board specific defines from display_ops.h

* Free the i2s clock pin in i2s code

This should not be done for individual boards.

* Deprecate v6 board specific functions as generic function.

Boards specific code should be marked as such.

* Move temperature readings into board code

* Implement a control interface for gpios

Move signals oe, mode and stv to this
Implement start_frame using the ctrl interface

* Move logic of end_frame() from board to display_opts

* Remove uneccesary function latch_row()

* Move logic for latch_row from board to display_opts

* Remove warning about v6_wait_for_interrupt() is unused

* Optimize set_ctrl by supplying a mask with the changed signals

* Share the temperature readings between boards v2 to v5

* Deprecate epd_powerdown() and make it to a board specific function instead

* Read vcom voltage from epd_board_vcom_v6()

This makes vcom voltage available at runtime and not at compile time

* enable CI runs on latest ESP-IDF version

Revert "disable CI runs on latest ESP-IDF for now"

This reverts commit 0e2bd15.

* replace deprecated portTICK_RATE_MS macro

The drop-in replacement is portTICK_PERIOD_MS.

See espressif/esp-idf#51.

* add missing headers

Some symbols and macros were not longer implicitly imported.

* update clock usage

Co-authored-by: jdoubleu <[email protected]>

* update GPIO usage

Co-authored-by: jdoubleu <[email protected]>

* add missing libsodium component as dependency

Disable the component manager in ESP-IDF <5.

See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/removed-components.html#components-moved-to-idf-component-registry

* fix minor errors in examples

For a thorough exaplanation of the st.c changes see https://stackoverflow.com/a/60696378/7201.

* migrate TCP/IP adapter API in mpd_status

See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/tcpip-adapter.html

* update component registration in weather example

Use the recommended flow.

* disable CI job to build arduino-esp32 with ESP-IDF v5

arduino-esp32 does not support ESP-IDF v5, yet (see https://github.com/espressif/arduino-esp32/blob/master/CMakeLists.txt#L8-L9).

* Use gpio port correctly instead of pin when getting LL device

* Fix log print format specifer in www-image example

* Add 'rules' to idf_component yaml file in mpd_status example to correctly pull in libsodium between eps-idf 4.X and 5.X

* Fix pointer arg to error handling function

* Switch between format specifiers based on esp-idf version in www-image example

* remove IRAM_ATTR macros from header declarations

* fix warnings about type incompatibilities

* replace deprecated header

See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/peripherals.html#peripheral-clock-gating

* Empty commit to kick CI to see if new esp-idf releave_v4.3 container pushed 2 days ago fixes libsodium build error

* Update cmakelists to support v5.0-beta1 driver and adc component changes. Compilation failing still, esp_adc_cal functionality neesd to be ported to new adc_cali.h and driver/esp_adc functionality

* Fix CMakeLists to support correct component lists for both idf 4.X and 5.X

* Switch 'latest' esp-idf container tag to 'v5.0-beta1'

* Explicitly add missing components to mpd_status and www-image examples cmakelists that were just inferred in 4.X

* Bump to newly release esp-idf 5.0 docker container for CI

* fix log statements after uint32_t alias changed

Co-authored-by: Micke Prag <[email protected]>
Co-authored-by: dot4qu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring This are core upgrades
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move away from defines
3 participants