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

microbit: Allocate all DAL objects on the DAL heap, to save BSS. #580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions inc/microbit/microbitdal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class MicroPythonI2C : public MicroBitI2C {
}
};

extern MicroPythonI2C ubit_i2c;
extern MicroPythonI2C *ubit_i2c;
extern MicroBitAccelerometer *ubit_accelerometer;
extern MicroBitDisplay ubit_display;
extern MicroBitDisplay *ubit_display;
extern MicroBitCompass *ubit_compass;
extern MicroBitCompassCalibrator *ubit_compass_calibrator;

Expand Down
16 changes: 9 additions & 7 deletions source/microbit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Global instances of the mbed/DAL components that we use
gpio_t reset_button_gpio;
gpio_irq_t reset_button_gpio_irq;
MicroBitDisplay ubit_display;
MicroPythonI2C ubit_i2c(I2C_SDA0, I2C_SCL0);
MicroBitDisplay *ubit_display;
MicroPythonI2C *ubit_i2c;

// Global pointers to instances of DAL components that are created dynamically
MicroBitAccelerometer *ubit_accelerometer;
Expand Down Expand Up @@ -147,13 +147,15 @@ int main(void) {
gpio_irq_set(&reset_button_gpio_irq, IRQ_FALL, 1);

// Create dynamically-allocated DAL components
ubit_accelerometer = &MicroBitAccelerometer::autoDetect(ubit_i2c);
ubit_compass = &MicroBitCompass::autoDetect(ubit_i2c);
ubit_compass_calibrator = new MicroBitCompassCalibrator(*ubit_compass, *ubit_accelerometer, ubit_display);
ubit_display = new MicroBitDisplay();
ubit_i2c = new MicroPythonI2C(I2C_SDA0, I2C_SCL0);
ubit_accelerometer = &MicroBitAccelerometer::autoDetect(*ubit_i2c);
ubit_compass = &MicroBitCompass::autoDetect(*ubit_i2c);
ubit_compass_calibrator = new MicroBitCompassCalibrator(*ubit_compass, *ubit_accelerometer, *ubit_display);

for (;;) {
extern uint32_t __StackTop;
static uint32_t mp_heap[10240 / sizeof(uint32_t)];
static uint32_t mp_heap[10368 / sizeof(uint32_t)];

// Initialise memory regions: stack and MicroPython heap
mp_stack_set_top(&__StackTop);
Expand All @@ -167,7 +169,7 @@ int main(void) {

// Initialise the micro:bit peripherals
microbit_seed_random();
ubit_display.disable();
ubit_display->disable();
microbit_display_init();
microbit_filesystem_init();
microbit_pin_init();
Expand Down
4 changes: 2 additions & 2 deletions source/microbit/microbitcompass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ mp_obj_t microbit_compass_calibrate(mp_obj_t self_in) {
(void)self_in;
ticker_stop();
//uBit.systemTicker.attach_us(&uBit, &MicroBit::systemTick, MICROBIT_DEFAULT_TICK_PERIOD * 1000); TODO what to replace with?
ubit_display.enable();
ubit_display->enable();
ubit_compass->calibrate();
ubit_display.disable();
ubit_display->disable();
//uBit.systemTicker.detach(); TODO what to replace with?
ticker_start();
microbit_display_init();
Expand Down
2 changes: 1 addition & 1 deletion source/microbit/microbiti2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const mp_obj_type_t microbit_i2c_type = {

const microbit_i2c_obj_t microbit_i2c_obj = {
{&microbit_i2c_type},
.i2c = &ubit_i2c,
.i2c = ubit_i2c,
};

}