Skip to content
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

buttons.c (demo branch) #169

Open
VonSzarvas opened this issue Apr 2, 2018 · 5 comments
Open

buttons.c (demo branch) #169

VonSzarvas opened this issue Apr 2, 2018 · 5 comments

Comments

@VonSzarvas
Copy link

VonSzarvas commented Apr 2, 2018

Buttons is broken because some pins are hard-defined.

Suggested update (with original code in comments after each changed line):

old:

low(2);

high(4);
waitcnt(CLKFREQ/4000 + CNT);
tDecay[1] = rc_time(4,1);

high(27);
waitcnt(CLKFREQ/4000 + CNT);
tDecay[0] = rc_time(27,1);
low(2);

new:

high(NAV_TOUCH_L);
waitcnt(CLKFREQ/4000 + CNT);
tDecay[1] = rc_time(NAV_TOUCH_L,1);

high(NAV_TOUCH_R);
waitcnt(CLKFREQ/4000 + CNT);
tDecay[0] = rc_time(NAV_TOUCH_R,1);

rc_time leaves the pin as an input when it's done, right?

Extra idea- After the above code block, set the pins low to mitigate interference?

low(NAV_TOUCH_L);
low(NAV_TOUCH_R); 
@PropGit
Copy link
Contributor

PropGit commented Apr 2, 2018

@VonSzarvas - Yes, rc_time should be leaving the pins as input when it's done. @AndyLindsay can correct me if I'm wrong.

If we later set the pins low, they'll be set back to outputs. Is that what you intend, so there's no floating button lines (is that the "interference" you mean)?

Question: What's on I/O 2 (that was set low twice in the old code but not at all in the new)?

@AndyLindsay
Copy link
Contributor

AndyLindsay commented Apr 2, 2018

I don't think I wrote that. The button code for the non-WX badge was this:

int button( int pad )
{
  char *addr = (char *) tself->p_pinslist;
  int pin = addr[6-pad];
  int ctr = 0;
  for(int i = 0; i < 5; i++)
  {
    high(pin);
    pause(1);
    input(pin);
    pause(5);
    int pb = input(pin);
    if(pb) ctr++;
    low(pin);
    pause(1);
  }
  return !(ctr == 5);
}


int buttons(void)
{
  int pb = 0;
  int mask = tself->pinsmask;
  for(int i = 0; i < 5; i++)
  {
    //high(pin);
    OUTA |= mask;
    DIRA |= mask;
    pause(1);
    //input(pin);
    DIRA &= (~mask);
    pause(5);
    //int pb = input(pin);
    pb |= ~INA;
    //low(pin);
    OUTA &= (~mask);
    DIRA |= mask;
    pause(1);
  }
  char *addr = (char *) tself->p_pinslist;
  int pads = 0, pin;
  for(int i = 0; i < 7; i++)
  {
    pads <<= 1; 
    pin = addr[i];
    int bit = (pb >> pin) & 1;
    pads |= bit;
  }    
  return pads;
}

@VonSzarvas
Copy link
Author

VonSzarvas commented Apr 2, 2018 via email

@VonSzarvas
Copy link
Author

@AndyLindsay @MatzElectronics

Andy, yes the code changed for BadgeWX. Maybe it could be improved, but I can confirm it works great as is. Matt might have crafted these edits on the original badge code?

  • for now, all I can see needs doing is the hard-coded pin numbers changed to the define names so that it will work with RevA2 and RevA (as some pins changed from RevA1).

Impact note:
Removing IO2 low will break compatibility with RevA1 boards for the touchpads, but I'd suggest we are past the point to concern with that. (Especially considering- RevA1 code can be compiled in SimpleIDE with overrides if needed)

@MatzElectronics
Copy link
Contributor

Should be fixed now. This can be closed.

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

No branches or pull requests

4 participants