Add rotation support to CO5300 display driver, and BMI270 IMU support for M5AtomS3R targets#1605
Add rotation support to CO5300 display driver, and BMI270 IMU support for M5AtomS3R targets#1605kitazaki wants to merge 7 commits intoModdable-OpenSource:publicfrom
Conversation
## Summary Add rotation support to the CO5300 display driver used by `esp32/waveshare_amoled_206`. The driver now supports `rotation` values of `0`, `90`, `180`, and `270`, consistent with other Moddable display drivers. ## Changes - Added a `rotation` getter/setter to `modules/drivers/co5300/co5300.js`. - Added native rotation state handling in `modCo5300.c`. - Updated `width` and `height` getters for 90/270 degree rotation. - Added validation for unsupported rotation values. - Added software pixel rearrangement for 90, 180, and 270 degree rotation. - Preserved the existing fast path for 0 degree rotation. ## Notes The CO5300 does not appear to provide a MADCTL-style row/column exchange mode suitable for 90/270 degree rotation. Non-zero rotations are therefore handled in software before pixel data is sent to the display. Rotated modes may be slower than the default 0 degree mode, but existing behavior is unchanged when `rotation` is not set. ## Testing Tested on `esp32/waveshare_amoled_206`, which uses the CO5300 display driver. Verified the following rotation values with `examples/piu/clock`: - `0` - `90` - `180` - `270`
## Summary This PR adds BMI270 IMU support to the M5AtomS3R target family. Moddable SDK 8.1.0 added support for the BMI270 sensor device. Since the M5AtomS3R family uses the same BMI270 IMU, this PR updates the corresponding target definitions. Updated targets: - `esp32/m5atom_s3r` - `esp32/m5atom_s3r_cam` - `esp32/m5atom_s3r_m12` ## Changes - Added the BMI270 sensor driver manifest to the M5AtomS3R target manifests. - Added `device.sensor.IMU` definitions for M5AtomS3R targets. - Added axis correction for `m5atom_s3r` so the IMU orientation matches `m5atom_s3`. - Scaled BMI270 accelerometer values from `m/s^2` to `g` for compatibility with existing AtomS3 IMU(MPU6886) examples. - Updated `examples/drivers/atoms3-imu` to handle samples that may not include accelerometer or gyroscope data immediately. - Added `examples/drivers/atoms3r-imu-console` for console-based IMU verification on displayless M5AtomS3R variants. ## Verification - `examples/drivers/atoms3-imu` with `esp32/m5atom_s3r` - `examples/drivers/atoms3r-imu-console` with `esp32/m5atom_s3r` - `examples/drivers/atoms3r-imu-console` with `esp32/m5atom_s3r_cam` - `examples/drivers/atoms3r-imu-console` with `esp32/m5atom_s3r_m12` ## Note M5Stack Core2 v1.3 also uses the BMI270 IMU. However, the Core2 hardware configuration changed between v1.1 and v1.3: the IMU changed from MPU6886 to BMI270, and the PMU changed from AXP2101 to AXP192. I plan to submit a separate PR for Core2 v1.3 after verifying the detection logic for these hardware differences.
|
@kitazaki
If it’s displayless and doesn’t depend on any specific device, you might try creating examples/drivers/sensors/bmi270. That location makes it easier to verify the driver from other devices as well. https://github.com/Moddable-OpenSource/moddable/tree/public/examples/drivers/sensors/mpu9250 can serve as a reference. For this device, polling alone might be sufficient. |
Are you sure about this? The controller appears to be rooted in MIPI. It has MADCTL (0x36), which seems like it might work. Please see section 7.5.29 of the data sheet. If it can work, it would be simpler and faster. Perhaps it is the absence of If the MADCTL really cannot be used for 90 and 270, we should optimize the transformation implementation because it could be faster. I can share some suggestions. |
## Summary Add rotation support to the CO5300 display driver. The driver now supports `rotation` values of `0`, `90`, `180`, and `270`. ## Changes - Add `rotation` getter/setter to the CO5300 JavaScript binding. - Use CO5300 `MADCTL` (`0x36`) with `MY | MX` for 180 degree rotation. - Use software pixel rearrangement for 90 and 270 degree rotation, where `MADCTL` cannot swap rows and columns. - Update width/height getters for 90/270 degree rotation. - Preserve the existing fast path for 0 degree rotation. ## Testing - `examples/piu/cards` for `esp32/waveshare_amoled_206`. - Verified 0, 90, 180, and 270 degree rotation on device.
|
Thank you for pointing this out. I rechecked section 7.5.29 of the CO5300 datasheet. MADCTL (0x36) is present, but the parameter only defines MY, MX, and RGB. However, I agree that 180 degree rotation should be possible using MY + MX. |
## Summary Add a generic BMI270 polling example under `examples/drivers/sensors/bmi270`. IMU console example with a driver-level sample that can be used from any device with a BMI270 connected over I2C. ## Changes - Add `examples/drivers/sensors/bmi270/poll`. - Import the BMI270 driver directly instead of using a device-specific `device.sensor.IMU` wrapper. - Poll accelerometer, gyroscope, and thermometer samples once per second. - Use `device.I2C.internal` when available, falling back to `device.I2C.default`. ## Testing - `esp32/m5atom_s3r` - `esp32/m5atom_s3r_cam` - `esp32/m5atom_s3r_m12`
|
Thank you for your comment. |
|
@kitazaki – The change for 180 looks good. I used Moddable Two, which has a MIPI display controller, to experiment with But... I think the 90/270 conversion can be improved. Each transaction is relatively expensive – starting/stopping a transaction takes some time. Consequently, fewer transactions have less overhead.
|
|
Thank you for the detailed feedback. I agree with your points. In particular, moving co5300SetWindow() outside the loop and increasing the rotation buffer size should reduce transaction overhead and improve performance for 90/270 rotation. I will create a small benchmark sample program, test it on the actual device, and share the results. Based on that, I will try to update the implementation with the following improvements:
The asynchronous version of co5300SendColorSync() also sounds interesting, but I think I will first measure the simpler improvements above before adding that complexity. Please give me a little time to test this. |

Summary
Add rotation support to the CO5300 display driver used by
esp32/waveshare_amoled_206.The driver now supports
rotationvalues of0,90,180, and270, consistent with other Moddable display drivers.Changes
rotationgetter/setter tomodules/drivers/co5300/co5300.js.modCo5300.c.widthandheightgetters for 90/270 degree rotation.Notes
The CO5300 does not appear to provide a MADCTL-style row/column exchange mode suitable for 90/270 degree rotation. Non-zero rotations are therefore handled in software before pixel data is sent to the display.
Rotated modes may be slower than the default 0 degree mode, but existing behavior is unchanged when
rotationis not set.Testing
Tested on
esp32/waveshare_amoled_206, which uses the CO5300 display driver.Verified the following rotation values with
examples/piu/cards:090180270