Skip to content

use native float instead of mp obj floats - #11

Draft
christopherwun wants to merge 2 commits into
initialization-hard-fault-memaccessfrom
native-floats-to-avoid-memleak
Draft

christopherwun wants to merge 2 commits into
initialization-hard-fault-memaccessfrom
native-floats-to-avoid-memleak

Conversation

@christopherwun

@christopherwun christopherwun commented Nov 20, 2025 •

Copy link
Copy Markdown
Collaborator

In response to Jocelyn's comment in #10. Tested and it still streams data the same way. All this does is changes the struct to use float's instead of the mp_obj_t type. This makes them mutable and prevents us from generating new pointers to new float objects on each call to report. Should reduce garbage collection requirements but means that these fields will not be accessible from Python layer (they are not currently used there anyways).

Checked for performance improvements and didn't see anything significant (in the short-term at least):

With MicroPython objs (immutable floats) for data:
image

With C floats for data:
image

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR converts MicroPython object floats (mp_obj_t) to native C floats in the BNO080 sensor driver's internal data structures, reducing garbage collection overhead while maintaining functionality at the Python API level.

  • Converts internal data storage from mp_obj_t to native float for sensor arrays (fquat, accel, gyro, mag, grav)
  • Updates data parsing functions to use powf() instead of pow() for better float performance
  • Modifies the read function to convert native floats to MicroPython objects only when accessed from Python

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
shared-module/bno080/BNO080.h Changes struct member types from mp_obj_t to float for five sensor data arrays
shared-module/bno080/BNO080.c Updates data assignment, initialization, and reading logic to work with native floats; converts pow() to powf() in most places; changes return value from NULL to mp_const_none

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread shared-module/bno080/BNO080.c Outdated
Comment thread shared-module/bno080/BNO080.c Outdated
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.

2 participants