Moddable-OpenSource / moddable

Tools for developers to create truly open IoT products using standard JavaScript on low cost microcontrollers.
http://www.moddable.com
1.34k stars 236 forks source link

display issues on new m5-Stick C hardware #473

Closed wilberforce closed 4 years ago

wilberforce commented 4 years ago

Build environment: Windows Target device: new m5-Stick C

Description Getting display smudging on the new hardware. Works ok on the older hardware. Photo to follow

Steps to Reproduce Interestingly the sample: https://github.com/Moddable-OpenSource/moddable/tree/public/examples/drivers/m5stickc-imu works fine.

The app I'm building uses both BLU and WIFI.

This seems to be related to changes in the last 3 weeks - I've not been able to narrow it down yet.

Expected behavior Both old and new hardware to display cleanly.

Images upper unit: new hardware (MPU6886)

lower unit: old hardware (SH200Q)

image

phoddie commented 4 years ago

@wilberforce, that's an artifact I'm not sure I could generate in software (at least not easily!). I'm going to guess this is a hardware configuration problem. (I don't have an M5 Stick, so I can only guess)

The recent addition of support for M5Stack CORE2 included changes to the driver code for the AXP192 power management chip. I believe that chip controls power to the display. The AXP192 code was reorganized to put the device specific code into setup-target.js. Maybe you can review those changes?

It is curious that you don't see a problem with the IMU ball example. That might be because it has a 25% gray background color, which is much less bright than your project's white background.

@meganetaaan seems to understand the AXP192. Maybe he can help?

wilberforce commented 4 years ago

@phoddie

The recent addition of support for M5Stack CORE2 included changes to the driver code for the AXP192 power management chip Thanks for the direction - I'll roll this back and see if this makes a difference.

It is curious that you don't see a problem with the IMU ball example. That might be because it has a 25% gray background color Another area to try - the problem still exists with the brightness so between 7-15. I'll try the actual background colour too.

Thanks for the hints - exactly was I was after!

https://github.com/Moddable-OpenSource/moddable/commit/96f7a42820e9b49a5afce0512bee98f458b03f31#diff-4693061397f7cc50ec6f13276d947f3f

wilberforce commented 4 years ago

@phoddie @meganetaaan

I've got to the bottom of it - it's when I call the brightness setter.

I'm passing the value 10, so it's writing to 0x28 with the value 160.

brightness=10;
global.power.brightness = brightness;

https://github.com/Moddable-OpenSource/moddable/blob/public/build/devices/esp32/targets/m5stick_c/setup-target.js#L139-L142

As soon as this happens, the display smudges...

phoddie commented 4 years ago

Cool!

FWIW - Tthe range of brightness should be 0 to 100. That's what the backlight control on Moddable Two uses:

https://github.com/Moddable-OpenSource/moddable/blob/ece6a84f3190d1191bf4698c656aad0755d6d5e3/build/devices/esp32/targets/moddable_two/setup-target.js#L12-L19

So the 10 you are passing is valid. I guess the question that needs to be sorted out is the range of the power register at 0x28.

wilberforce commented 4 years ago

Existing:

set brightness(brightness) {
    const b = (brightness & 0x0f) << 4;
    this.writeByte(0x28, b);
  }

https://github.com/m5stack/M5StickC/blob/master/src/AXP192.cpp#L155-L163

uint8_t buf = Read8bit( 0x28 );
    Write1Byte( 0x28 , ((buf & 0x0f) | (brightness << 4)) );
phoddie commented 4 years ago

Thanks for the reference to the M5StickC code. The complete function is helpful

As you noted above, the low nibble of the register is getting overwritten. But, the range is 0 to 12 is important too. It is 0 to 12, so we should map the 0 to 100 input. Something like this?

set brightness(value) {
    if (value <= 0)
        value = 0;
    else if (value >= 100)
        value = 12;
    else
        value = (value / 100) * 12;
    this.writeByte(0x28, (this.readByte(0x28) & 0x0F) | (value << 4));
}
meganetaaan commented 4 years ago

Sorry to be late! I didn't know that so many has been updated on the original repos since my first PR for adding M5StickC target.

wilberforce commented 4 years ago

@meganetaaan

Thanks for looking at this.

I agree with the 12 vs 15 thing - unless it was deemed > 12 was too bright and drawing too much current? I'll give it a go.

As far as startup sequence goes- rather than Writing directly to registers - are we better off using your classes in AXP192. This way in the manifest we could define what get intialised?

The other thing I have been considering is this: https://github.com/m5stack/M5StickC/blob/master/examples/Advanced/AXP192/BtnIrq/BtnIrq.ino

This allows the power on/off button to be used as a normal button - the press causes an IRQ (on pin 35) and then you poll the button.

This means we could have buttons A, B and C. I was thinking of using these a select. up and down for a menu system.

Also the stuff for wake-up on movement could be useful too.

wilberforce commented 4 years ago

@meganetaaan

That change works fine. I'll do a pull request