-
Notifications
You must be signed in to change notification settings - Fork 214
lsm6ds3tr: avoid unnecessary heap allocations #766
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
base: release
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit that I think would do wonders for readability. I'd love to feature this in a youtube video once it is done if y'all don't mind!
d.buf[0] = CTRL2_G | ||
d.buf[1] = uint8(d.gyroRange) | uint8(d.gyroSampleRate) | ||
err = d.bus.Tx(d.Address, d.buf[0:2], nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we abstract these calls to something like d.writeReg8/readReg8
?
func (d *Device) writeReg8(addr, value byte) error {
d.buf[0] = addr
d.buf[1] = value
return err = d.bus.Tx(d.Address, d.buf[0:2], nil)
}
func (d *Device) readReg8(addr byte) (byte,error) {
d.buf[0] = addr
err := d.bus.Tx(d.Address, d.buf[0:1], d.buf[1:2])
return d.buf[1], err
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just one of many drivers that scream for such improvement, a trial balloon if you wish.
Each of these drivers will have to repeat the pattern.
Any ideas how could we implement these helper functions once and re-use them, instead of implementing in every driver anew?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I agree with @soypat some helper methods would make the code a bit easier to read.
Nothing against from my side. All kudos to @aykevl for the idea, btw. |
This re-uses internal buffer to avoid unnecessary heap allocations in lsm6ds3tr driver; switches away from the legacy I2C interface.