lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
43 stars 52 forks source link

Difference from V1 - Default pull mode of V2 P3,4,6,7,10 after display.disable() is None #391

Open martinwork opened 10 months ago

martinwork commented 10 months ago

Apparent pull mode of P3,4,6,7,10 after display.disable()

To see if mode is down or none connect a dangling lead to e.g. P3. Universal hex test-pin3.hex.zip outputs display pin values, without setting pull.

With the code below, DMESG enabled, and DMESG("setPull %p = %d", this, (int) pullMode); added to setPull, I see the output below. https://github.com/lancaster-university/codal-nrf52/blob/84b1aeec870addcfb6027a924dbfe83f1f10c6db/source/NRF52Pin.cpp#L701

The only setPulls after disabling the display are for P0,P1,P2,P9. It seems the display pins are already configured as digital inputs, so return here https://github.com/lancaster-university/codal-nrf52/blob/84b1aeec870addcfb6027a924dbfe83f1f10c6db/source/NRF52Pin.cpp#L279 but in any case their pullMode member is None because of this https://github.com/lancaster-university/codal-microbit-v2/blob/1bb648e00da9204b6e707cc71248f74e2c0e3b95/model/MicroBitIO.cpp#L104 and https://github.com/lancaster-university/codal-microbit-v2/blob/1bb648e00da9204b6e707cc71248f74e2c0e3b95/source/NRF52LedMatrix.cpp#L168

When the pull mode is none, all display pins show the same value when one pin is connected.

0 0x20002638
1 0x20002650
2 0x20002668
3 0x20002680
4 0x20002698
6 0x200026C8
7 0x200026E0
9 0x20002710
10 0x20002728
setPull 0x20002638 = 1
setPull 0x20002650 = 1
setPull 0x20002668 = 1
setPull 0x20002710 = 1
0,0,0,1,1,1,1,0,1
0,0,0,1,1,1,1,0,1
0,0,0,1,1,1,1,0,1
0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0
#include "MicroBit.h"
#include "codaldmesg.h"

#ifndef MICROBIT_CODAL
#ifdef CODAL_CONFIG_H
#define MICROBIT_CODAL 1
#else
#define MICROBIT_CODAL 0
#endif
#endif

MicroBit uBit;

#if MICROBIT_CODAL
#define mypullNONE PullMode::None
#define mypullDOWN PullMode::Down
#else
#define mypullNONE PullNone
#define mypullDOWN PullDown
#endif

#undef MYPULL
//#define MYPULL mypullNONE
//#define MYPULL mypullDOWN

void forever()
{
  uBit.display.disable();

//#ifdef MYPULL
//  uBit.io.P3.setPull( MYPULL);
//  uBit.io.P4.setPull( MYPULL);
//  uBit.io.P6.setPull( MYPULL);
//  uBit.io.P7.setPull( MYPULL);
//  uBit.io.P9.setPull( MYPULL);
//  uBit.io.P10.setPull( MYPULL);
//#endif

  DMESG( "0 %p", &uBit.io.P0);
  DMESG( "1 %p", &uBit.io.P1);
  DMESG( "2 %p", &uBit.io.P2);
  DMESG( "3 %p", &uBit.io.P3);
  DMESG( "4 %p", &uBit.io.P4);
  DMESG( "6 %p", &uBit.io.P6);
  DMESG( "7 %p", &uBit.io.P7);
  DMESG( "9 %p", &uBit.io.P9);
  DMESG( "10 %p", &uBit.io.P10);

  while (true)
  {
    ManagedString str;
    str = str + ManagedString( (int) uBit.io.P0.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P1.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P2.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P3.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P4.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P6.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P7.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P9.getDigitalValue()) + ",";
    str = str + ManagedString( (int) uBit.io.P10.getDigitalValue());
    DMESG( str.toCharArray());
    uBit.sleep(100);
  }
}

int main()
{
    uBit.init();

    create_fiber( forever);
    release_fiber();
    return 0;
}