BlocklyProp icon indicating copy to clipboard operation
BlocklyProp copied to clipboard

Wait for pin block

Open PropGit opened this issue 7 years ago • 7 comments

The Other project type has a System category with a Wait until block.

Following the same theme, we should also add a Wait for pin block (or make Wait until automatically morph somehow) to support waitpeq and waitpne functionality.

PropGit avatar Sep 18 '18 17:09 PropGit

Point to consider: In practice, WAITPEQ and WAITPNE are used to halt the cog until a single pin equals or differs from a given state; however, they both allow any number of I/O pins to be specified.

Should we support that capability in BlocklyProp? I'd hate to make the block appear more complicated, but I'd also hate to disallow an intrinsic system function that someone will inevitably want. Maybe the multi-pin option can be a separate block, so we have Wait for pin and also Wait for pins?

PropGit avatar Sep 25 '18 17:09 PropGit

The block allows for either a single pin to be selected, or for a mask to be used. Keeps the block simple while allowing it's full feature set.

MatzElectronics avatar Sep 30 '18 06:09 MatzElectronics

That sounds wonderful!

PropGit avatar Sep 30 '18 13:09 PropGit

Needs to be added to Learn reference to be eligible for next push.

Steph-Parallax avatar Oct 25 '18 23:10 Steph-Parallax

Not verified.

The block can not operate properly as coded. Each field of the Propeller's WAITPEQ and WAITPNE instruction is a 32-bit field that indicates pin bit states and bit masks. The current block is only shifting the mask and not the state. Ex: image

generates this code:

waitpeq(0, (1 << 2));

but should generate this instead:

waitpeq((0 << 2), (1 << 2));

Note however, when set to pin mask mode, it does indeed generate the right code (which doesn't require shifting anywhere): image

waitpne(state, mask);

PropGit avatar Oct 30 '18 21:10 PropGit

@MatzElectronics - Sorry for not being clear enough; this can be a confusing instruction.

I've made a better example with symbols here.

In the PIN mode, the wait until block should (for state) shift the LogicLevel by the PinNumber in order to make a state pattern whose PinNumber bit is 1 or 0, and (for mask) should shift a 1 by the PinNumber to make a mask pattern whose PinNumber bit is 1.

image

  PinNumber = 2;
  LogicLevel = 1;
  waitpeq((LogicLevel << PinNumber), (1 << PinNumber));

The current implementation is not generating the right code (though it is close).

In the PIN MASK mode, the wait until block should (for state) just use the raw LogicLevels value, and (for mask) should just use the raw PinNumbers value.

image

  PinNumbers = (0b0101);
  LogicLevels = (0b0100);
  waitpeq(LogicLevels, PinNumbers);

The current implementation is already generating the right code. In this case, it will wait for pins 2 and 0 to be equal to 1 (high) and 0 (low), respectively.

And, of course, in either case if the is is change to an is not, the instruction changes to a waitpne instead of a waitpeq. The current implementation is already generating the right code.

PropGit avatar Oct 31 '18 19:10 PropGit

Where are the docs for this feature? Please send me a PM if it's not in this project. @PropGit - Can you test this again to verify it?

zfi avatar Nov 28 '18 00:11 zfi