Skip to content

[lightning-ln882h] Add support for Lightning LN882H family #312

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 45 commits into from
Mar 25, 2025

Conversation

lamauny
Copy link
Contributor

@lamauny lamauny commented Jan 7, 2025

I'm happy to contribute to this excellent project by adding basic support for Lightning Ln882h family.

Supported features

Wifi AP is only working in Open Auth mode, and Mixed mode (AP+STA) is not supported

More supported features will be added in the future, but this support is sufficient to pilot the relay and handle button of my aliexpress smart light module (kind-of) based on a LN-02 module.

Links to the PR on other repos adding this feature :

@divadiow
Copy link

have you tested this on LN882x? LN882H is a newer family with a different SDK.

@lamauny
Copy link
Contributor Author

lamauny commented Jan 14, 2025

have you tested this on LN882x? LN882H is a newer family with a different SDK.

no, i've only tested on ln882h, but ln882h is from the ln822x family , so it's worth testing.
"LN882H (LN882x family, H series) WiFi&BLE Combo"

@divadiow
Copy link

hmm. I thought that too. I have flashed OpenBeken LN882H builds to LN8825B quite a number of times without success.

Are you building separate LN882X binaries or is the output a single LN882 fw?

@lamauny
Copy link
Contributor Author

lamauny commented Jan 14, 2025

Hey, I've had a look to the vector table of the 2 chips and they are different, so these chips are definitely not fully compatible.

Copy link
Contributor Author

@lamauny lamauny left a comment

Choose a reason for hiding this comment

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

Many files updated.
Please see my comments on boardgen generated files.

@kuba2k2
Copy link
Member

kuba2k2 commented Feb 28, 2025

@lamauny
Unfortunately, I'm unable to compile LibreTiny with this PR - it fails on Windows.
Because the OS is case-insensitive, the LN SDK is incorrectly picking up LT headers (in particular - wifi.h and serial.h) instead of the SDK headers. This causes inclusion of C++ code in C units, which fails for obvious reasons.

The SDK (on GitHub) will have to modified to rename the two header files (possibly more?). For instance, they could be prefixed with ln_.

@lamauny
Copy link
Contributor Author

lamauny commented Mar 1, 2025

@lamauny Unfortunately, I'm unable to compile LibreTiny with this PR - it fails on Windows. Because the OS is case-insensitive, the LN SDK is incorrectly picking up LT headers (in particular - wifi.h and serial.h) instead of the SDK headers. This causes inclusion of C++ code in C units, which fails for obvious reasons.

The SDK (on GitHub) will have to modified to rename the two header files (possibly more?). For instance, they could be prefixed with ln_.

Could it be fixed by changing include path order ?

@kuba2k2
Copy link
Member

kuba2k2 commented Mar 1, 2025

I don't think so. In that case LibreTiny would then pick up wrong headers.
The easiest way would be to rename the headers in SDK.

@lamauny
Copy link
Contributor Author

lamauny commented Mar 1, 2025

and if we add a dummy fixup WiFi.h with something like

#ifdef LN882H_SDK // or ifndef __cplusplus ?
#include "wifi_lib_export/wifi.h"
#else
#include_next "WiFi.h" 
#endif

modify SDK is maybe the easiest way but it's a bit of a shame, it will make sdk updates more difficult

@kuba2k2
Copy link
Member

kuba2k2 commented Mar 1, 2025

This solution would only work for the SDK .c files, but LibreTiny files would not be able to include the SDK's wifi.h when they are needed (in sdk_private.h). EDIT: ...unless you use the wifi_lib_export in sdk_private as well - then it might work. I can test this on Windows later.

SDK updates are rarely needed. Because the SDK commits are usually poorly described, updating might break existing LibreTiny functions (we've seen something like this with Realtek). So I think it shouldn't be a concern that updates won't be possible easily.

@lamauny
Copy link
Contributor Author

lamauny commented Mar 1, 2025

maybe libretiny files could include wifi_lib_export/wifi.h when needed ?
EDIT: need to add components/wifi to include paths

@kuba2k2
Copy link
Member

kuba2k2 commented Mar 1, 2025

I tested your idea, it won't work - LibreTiny's WiFi library is before fixups in the include path. The best solution (and the only possible one, I think) will be to rename the headers.

In file included from C:/Users/Kuba/.platformio/platforms/libretiny/cores/common/arduino/libraries/api/WiFi/WiFiEvents.h:9,
                 from C:/Users/Kuba/.platformio/platforms/libretiny/cores/common/arduino/src/Events.h:26,
(the one below is included incorrectly)
                 from C:/Users/Kuba/.platformio/platforms/libretiny/cores/common/arduino/libraries/api/WiFi/wifi.h:25,
                 from C:/Users/Kuba/.platformio/packages/framework-lightning-ln882h/components/utils/system_parameter.h:4,
                 from C:/Users/Kuba/.platformio/platforms/libretiny/cores/lightning-ln882h/base/sdk_private.h:56,
                 from C:/Users/Kuba/.platformio/platforms/libretiny/boards/variants/wl2s.c:6:

@lamauny
Copy link
Contributor Author

lamauny commented Mar 1, 2025

Is it wanted that fixups include paths are after common path ? just asking.

@kuba2k2
Copy link
Member

kuba2k2 commented Mar 1, 2025

Not necessarily - but fixups are intended to replace SDK headers/code, not to solve complex problems with duplicated header names.

In the Beken SDK there was a similar issue, where FreeRTOS's list.h was named the same as Beken's list.h (two different headers). Simply renaming it was the easiest choice and works to this day.

@lamauny
Copy link
Contributor Author

lamauny commented Mar 4, 2025

@kuba2k2 do you think you can modify the SDK files and check the compilation on Windows platform ? I don't have a Windows machine on hand.

EDIT: I've done the modification on SDK by simply adding dummy header files, no file modification ;-)
tested by mounting a FAT32 usb key as a case insensitive filesystem.

@lamauny lamauny requested a review from kuba2k2 March 16, 2025 09:38
@lamauny
Copy link
Contributor Author

lamauny commented Mar 16, 2025

ltchiptool updated too

@kuba2k2 kuba2k2 changed the title Add support for Lightning Ln882h family [lightning-ln882h] Add support for Lightning LN882H family Mar 25, 2025
@kuba2k2 kuba2k2 merged commit 69e7e2d into libretiny-eu:master Mar 25, 2025
2 checks passed
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.

5 participants