forked from meshtastic/firmware
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add lateInitVariant() as a concept. see below for docs
(from src/extra_variants/README.md) This directory tree is designed to solve two problems. - The ESP32 arduino/platformio project doesn't support the nice "if initVariant() is found, call that after init" behavior of the nrf52 builds (they use initVariant() internally). - Over the years a lot of 'board specific' init code has been added to init() in main.cpp. It would be great to have a general/clean mechanism to allow developers to specify board specific/unique code in a clean fashion without mucking in main. So we are borrowing the initVariant() ideas here (by using weak gcc references). You can now define lateInitVariant() if your board needs it. If you'd like a board specific variant to be run, add the variant.cpp file to an appropriately named subdirectory and check for \_VARIANT_boardname in the cpp file (so that your code is only built for your board). You'll need to define \_VARIANT_boardname in your corresponding variant.h file. See existing boards for examples. This approach has no added runtime cost.
- Loading branch information
1 parent
5ce5b7b
commit cdafa87
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# About extra_variants | ||
|
||
This directory tree is designed to solve two problems. | ||
|
||
- The ESP32 arduino/platformio project doesn't support the nice "if initVariant() is found, call that after init" behavior of the nrf52 builds (they use initVariant() internally). | ||
- Over the years a lot of 'board specific' init code has been added to init() in main.cpp. It would be great to have a general/clean mechanism to allow developers to specify board specific/unique code in a clean fashion without mucking in main. | ||
|
||
So we are borrowing the initVariant() ideas here (by using weak gcc references). You can now define lateInitVariant() if your board needs it. | ||
|
||
If you'd like a board specific variant to be run, add the variant.cpp file to an appropriately named | ||
subdirectory and check for \_VARIANT_boardname in the cpp file (so that your code is only built for your board). | ||
You'll need to define \_VARIANT_boardname in your corresponding variant.h file. | ||
See existing boards for examples. | ||
|
||
This approach has no added runtime cost. |
34 changes: 34 additions & 0 deletions
34
src/platform/extra_variants/heltec_wireless_tracker/variant.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "configuration.h" | ||
|
||
#ifdef _VARIANT_HELTEC_WIRELESS_TRACKER | ||
|
||
#include "GPS.h" | ||
#include "GpioLogic.h" | ||
#include "graphics/TFTDisplay.h" | ||
|
||
// Heltec tracker specific init | ||
void lateInitVariant() | ||
{ | ||
// LOG_DEBUG("Heltec tracker initVariant\n"); | ||
#ifdef VEXT_ENABLE | ||
GpioPin *hwEnable = new GpioHwPin(VEXT_ENABLE); | ||
GpioVirtPin *virtGpsEnable = gps ? gps->enablePin : new GpioVirtPin(); | ||
|
||
// On this board we are actually using the backlightEnable signal to already be controlling a physical enable to the | ||
// display controller. But we'd _ALSO_ like to have that signal drive a virtual GPIO. So nest it as needed. | ||
GpioVirtPin *virtScreenEnable = new GpioVirtPin(); | ||
if (TFTDisplay::backlightEnable) { | ||
GpioPin *physScreenEnable = TFTDisplay::backlightEnable; | ||
GpioPin *splitter = new GpioSplitter(virtScreenEnable, physScreenEnable); | ||
TFTDisplay::backlightEnable = splitter; | ||
|
||
// Assume screen is initially powered | ||
splitter->set(true); | ||
} | ||
|
||
// If either the GPS or the screen is on, turn on the external power regulator | ||
new GpioBinaryTransformer(virtGpsEnable, virtScreenEnable, hwEnable, GpioBinaryTransformer::Or); | ||
#endif | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters