Open microbit-carlos opened 1 year ago
Yes, CPP macro definitions inside "codal": {} don't seem to work for me.
What definitions are generated by the documented CODAL example? https://makecode.com/extensions/pxt-json#:~:text=microbit%2Ddal%3A-,CODAL%20example,-%3A CODAL needs DEVICE_COMPONENT_COUNT and DEVICE_DMESG_BUFFER_SIZE
Is there a scheme like the yotta DAL equivalent? "yotta": { "config": { "microbit-dal": { xxx-yyy }}} becomes YOTTA_CFG_MICROBIT_DAL_XXX_YYY and "yotta": { "config": { "codal": { xxx-yyy }}} becomes DEVICE_XXX_YYY, or perhaps YOTTA_CFG_CODAL_XXX_YYY
So does the example here generate DEVICE_RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL or YOTTA_CFG_CODAL_RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL?
When does yotta_cfg_mappings get used? https://github.com/lancaster-university/codal-microbit-v2/blob/master/inc/compat/yotta_cfg_mappings.h
Ah, yeah, looks like you are on the right track @martinwork.
With these values in a pxt.json file:
"yotta": {
"config": {
"codal": {
"MICROBIT_BLE_UTILITY_SERVICE": 1,
"MICROBIT_BLE_UTILITY_SERVICE_PAIRING": 1,
"RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL": 1
},
"microbit-dal": {
"RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL": 1
},
"RANDOM_MACRO_IN_YOTTA_CONFIG": 1
}
}
With a local build I can inspect the generated codal.json file:
The interesting bits being:
"definitions": {
"DEVICE_MICROBIT_BLE_UTILITY_SERVICE": 1,
"DEVICE_MICROBIT_BLE_UTILITY_SERVICE_PAIRING": 1,
"DEVICE_RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL": 1,
"RANDOM_MACRO_IN_YOTTA_CONFIG": 1,
"MICROBIT_DAL_RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL": 1,
"YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE": 1,
"YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE_PAIRING": 1,
"YOTTA_CFG_CODAL_RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL": 1,
"YOTTA_CFG_RANDOM_MACRO_IN_YOTTA_CONFIG": 1,
"YOTTA_CFG_MICROBIT_DAL_RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL": 1,
},
"config": {
"DEVICE_MICROBIT_BLE_UTILITY_SERVICE": 1,
"DEVICE_MICROBIT_BLE_UTILITY_SERVICE_PAIRING": 1,
"DEVICE_RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL": 1,
"RANDOM_MACRO_IN_YOTTA_CONFIG": 1,
"MICROBIT_DAL_RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL": 1,
"YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE": 1,
"YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE_PAIRING": 1,
"YOTTA_CFG_CODAL_RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL": 1,
"YOTTA_CFG_RANDOM_MACRO_IN_YOTTA_CONFIG": 1,
"YOTTA_CFG_MICROBIT_DAL_RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL": 1,
}
So MakeCode is prepending DEVICE_
and YOTTA_CFG_CODAL_
to the macros added via yotta.config.codal
.
@abchatra we need a way to add C++ defines to a single target without MakeCode prepending to the macro name, so that we can add flags to V2 only with the data logging extension:
@microbit-carlos We could add to yotta_cfg_mappings
#ifdef YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE
#define MICROBIT_BLE_UTILITY_SERVICE YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE
#endif
#ifdef YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE_PAIRING
#define MICROBIT_BLE_UTILITY_SERVICE_PAIRING YOTTA_CFG_CODAL_MICROBIT_BLE_UTILITY_SERVICE_PAIRING
#endif
It seems strange to be going via YOTTA, but at least the text in pxt.json would match the macro needed by the program, which stays MICROBIT rather than DEVICE
Yeah, I'd be a bit weird to be creating yotta macros for V2-only features.
And for any existing or future flags we'd have to manually "fix" each individual flag in the CODAL codebase, when it's something fixable in the MakeCode macro/codal.json generation. Basically we'd have to do the same thing for anything configurable in MicroBitConfig.h
(and other header files) so that we could configure them only for V2.
I'd prefer to resolve this in the MakeCode side.
I guess having "generic" CODAL defines automatically prepended with DEVICE_
might have been okay when originally implemented, as by convention that's how they've been named inside CODAL, however some since then some configuration macros have also been named starting with CODAL_
instead, so it no longer applies.
And for micro:bit CODAL we do have a few configs that start with MICROBIT_
that are V2 specific.
So now, it would make sense for MakeCode to not prepend the macro names defined in yotta.config.codal
. Or, at least, to also generate the defines without the prepend (like yotta.config
does).
Yes, I was only thinking about how to make the utility service defines work cleanly right now.
also generate the defines without the prepend
That sounds like it might be simple to do, as MakeCode already generates DEVICE_ and YOTTA_CFGCODAL versions.
Should there be some checks on the names and values, for example, is the name all capitals with a recognised prefix? I'm thinking yotta_cfg_mappings acts as a filter in yotta builds.
After discussion in sync today @abchatra and team will take a look and come back to us early next week about whether we should deploy the workaround in the short term
@carlosperate is this still an issue?
Yes, the issue being that MakeCode always prepends DEVICE_
to the name of every flag added to yotta.config.codal
and MICROBIT_DAL
to every flag added to yotta.config.microbit-dal
.
At the moment we workaround this by either adding the same flag to both builds in yotta.config
, or expecting the name mangling, but it is confusing.
The main problem can arise if somebody needs to create a flag for a C++ extension that needs to have different values in DAL vs CODAL. So a pxt.json file like this will end up with flags renamed to DEVICE_CUSTOM_FLAG
in V2 and MICROBIT_DAL_CUSTOM_FLAG
in V1:
"yotta": {
"config": {
"codal": {
"CUSTOM_FLAG": 1
},
"microbit-dal": {
"CUSTOM_FLAG": 2
}
}
}
Describe the bug From the documentation in https://github.com/microsoft/pxt/blob/d6fa4dffb4bf95eb7c5ab8f93323d64f240bc157/docs/extensions/pxt-json.md#setting-c-constants-for-dal-config---yotta this should work, but when tested it does not set up the macro in the CODAL builds:
Adding the macros to
yotta.config
instead does work, but that adds them to both V1 and V2 builds.To Reproduce
To test this I've created this MakeCode programme with a C++ file that prints macro values, based on this @martinwork's extension for the same purpose: https://github.com/martinwork/pxt-cpp/blob/master/ext.cpp
The project example can be imported from: https://github.com/microbit-carlos/makecode-macrotest
Output:
As show,
RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL
should be equal to1
, but as an undefined macro it prints its name.RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL
is correctly undefined, as that's a macro for V1 DAL only.Expected behavior
The expected output on a micro:bit V2 would have been:
Screenshots N/A
micro:bit version (please complete the following information):
V2.xx
Desktop (please complete the following information): N/A
Additional context
makecode.microbit.org version: 6.1.5 Microsoft MakeCode version: 9.1.11 microbit runtime version: v2.2.0-rc6 codal-microbit-v2 runtime version: v0.2.57