microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
711 stars 589 forks source link

setting DEVICE_BLE=0 via yotta causes an odd compiler error in pxt-microbit #5479

Closed tballmsft closed 7 months ago

tballmsft commented 7 months ago

This issue pertains to compiling for micro:bit V2 only. The BLE stack takes 30% of flash, so for large programs (like ones I am developing) that don't require BLE, this is a problem. I need a way to disable DEVICE_BLE in an extension I am developing. I have found the way to disable via yotta config, see below.

tballmsft commented 7 months ago

This is the way:

    "yotta": {
        "config": {
            "DEVICE_BLE": 0
        }
    }

Unfortunately, this causes a build-error in pxt-microbit:

/home/build/prjclone/pxtapp/core/pins.cpp: In function 'void pins::pushButton(DigitalPin)':
/home/build/prjclone/pxtapp/core/pins.cpp:647:13: error: expected type-specifier before 'MicroBitButton'
         new MicroBitButton((PinName)getPin((int)(pin))->name, (int)pin, MICROBIT_BUTTON_ALL_EVENTS, PinMode::PullUp)

I will investigate further.

tballmsft commented 7 months ago

The problem is that in lancaster/codal-microbit-v2 build

MicroBitButton.h is not included directly in MicroBit.h, but only indirectly by MicroBitButtonService.h, which is only included in MicroBit.h when DEVICE_BLE is enabled.

So, when DEVICE_BLE is not enabled, we get the compile error in pxt-microbit, which expectes MicroBitButton to always be available.

The fix for now, until codal-microbit-v2 revs is to include MicroBitButton.h in libcw/core/pins.cpp

tballmsft commented 7 months ago

https://github.com/microsoft/pxt-microbit/pull/5481/files