\ Dual synchronous serial port (DSSP) dual optical encoder (DOE) interface HEX 46FE R-TOP ! 4700 DUP H ! H-FENCE ! 8080 CONSTANT DSSP_OUT_BUS_BITS 0101 CONSTANT DSSP_IN_BUS_BITS 0002 CONSTANT DSSP_WRITE_EN 0001 CONSTANT DSSP_SCLK_LOW \ 8080 CONSTANT DSSP_FRAME_START 0080 CONSTANT DSSP_FRAME_START \ Used for testing of one optical encoder. \ 4040 CONSTANT DSSP_DATA_VALID 0040 CONSTANT DSSP_DATA_VALID \ Used for testing of one optical encoder. : DSSP_WRITE_BITS ( n -- ) DSSP_OUT_BUS_BITS AND \ Isolate the MSB of both bytes. DSSP_WRITE_EN OR \ Maintain the SSP bus drivers on. DUP \ Make a copy of the data. DSSP_SCLK_LOW OR \ Bring the SSP clock line low. 0018 FOR NEXT \ Extend duration of clock level 1A G! \ Output the data. NOP NOP \ Delay two clock cycles. 1A G! \ Output the data, bring the SSP clock line high. 0018 FOR NEXT \ Extend duration of clock level ; : DSSP_WRITE_BYTES ( n -- ) 7 FOR \ Enter loop to write out eight bits for each byte. DUP \ Make a copy of the data. DSSP_WRITE_BITS \ Write out the MSB of both bytes. 2* \ Shift the data left by one bit. NEXT \ Continue the loop. DROP \ Discard the trash data. ; : DSSP_WRITE_REGISTERS ( data addr -- ) DSSP_WRITE_EN 1A G! \ Output data to turn on the SSP bus drivers. DSSP_WRITE_BYTES \ Output address bytes onto SSP busses. DSSP_WRITE_BYTES \ Output data bytes onto SSP busses. 0000 1A G! \ Output data to turn off the SSP bus drivers. ; : DSSP_READ_BITS ( -- n ) DSSP_SCLK_LOW 1A G! \ Output data to bring the SSP clock line low. 0018 FOR NEXT \ Extend duration of clock level DSSP_IN_BUS_BITS \ Set up mask to isolate the incomming bits. 0000 1A G! \ Output data to bring the SSP clock line high. 0018 FOR NEXT \ Extend duration of clock level 1A G@ \ Input the data. AND \ Isolate the LSB of both bytes. ; : DSSP_READ_BYTES ( -- n ) 0 \ Initially start with an empty bit field. 7 FOR \ Enter loop to read in eight bits for each byte. 2* \ Shift the data left by one bit DSSP_READ_BITS \ Read in bits into LSB bit of both bytes. OR \ Combine new bits with shifted bits. NEXT ; : DSSP_READ_REGISTERS ( addr -- data ) DSSP_WRITE_EN 1A G! \ Output data to turn on the SSP bus drivers. DSSP_WRITE_BYTES \ Output address bytes onto SSP busses. NOP \ Pause for last bit before bus driver shut-off. 0000 1A G! \ Output data to turn off the SSP bus drivers. 00C7 FOR NEXT \ Loop 200 times for delay between write and read. DSSP_READ_BYTES \ Input data bytes from the SSP busses. ; : DOE_RESET ( -- ) 8080 8080 DSSP_WRITE_REGISTERS ; : DOE_POWER_DOWN ( -- ) 4040 8080 DSSP_WRITE_REGISTERS ; : DOE_KEEP_AWAKE ( -- ) 0101 8080 DSSP_WRITE_REGISTERS ; : DOE_LET_SLEEP ( -- ) 0000 8080 DSSP_WRITE_REGISTERS ; : DOE_CONFIG_PORTS ( -- data ) 0000 DSSP_READ_REGISTERS ; : DOE_STATUS ( -- data ) 0101 DSSP_READ_REGISTERS ; : DOE_DELTA_Y ( -- data ) 0202 DSSP_READ_REGISTERS ; : DOE_DELTA_X ( -- data ) 0303 DSSP_READ_REGISTERS ; : DOE_SQUAL ( -- data ) 0404 DSSP_READ_REGISTERS ; : DOE_MAX_PIXEL ( -- data ) 0505 DSSP_READ_REGISTERS ; : DOE_MIN_PIXEL ( -- data ) 0606 DSSP_READ_REGISTERS ; : DOE_PIXEL_SUM ( -- data ) 0707 DSSP_READ_REGISTERS ; : DOE_RESET_PIXEL_DATA ( -- ) 0000 8888 DSSP_WRITE_REGISTERS ; : DOE_READ_PIXEL_DATA ( addr -- code) DOE_RESET_PIXEL_DATA \ Reset the pixel hardware. 0640 FOR NEXT \ Delay loop of 1600 loops. 0143 FOR \ Loop 324 times to read in pixels 0808 \ Address for pixel data. DSSP_READ_REGISTERS \ Read bytes. SWAP \ Bring address to TOS. !+2 \ Write out values and increment by two bytes. NEXT \ Loop if all status bits are true. DROP \ Discard the address. ; : DOE_SHUTTER_UPPER ( -- data ) 0909 DSSP_READ_REGISTERS ; : DOE_SHUTTER_LOWER ( -- data ) 0A0A DSSP_READ_REGISTERS ; : DOE_INV_PRODUCT_ID ( -- data ) 1111 DSSP_READ_REGISTERS ; : CRUDE_FOCUS ( n -- ) 0 DO DOE_SQUAL 00FF AND 2 .H CR LOOP ; : PIXEL-DUMP ( addr -- ) ." {" CR \ Output initial open brace for data. 12 0 DO \ Eighteen rows in the image. ." {" \ Output open brace for row. 12 0 DO \ Eighteen pixels in each row. @+2 \ Read data value and increment pointer by two. SWAP \ Bring data value to TOS. 003F AND \ Mask to clear unused bits. 2* 2* \ Shift left by two to increase dynamic range. ." #" \ Output color triplet indicator DUP 2 .H \ Output first copy of byte for red color. DUP 2 .H \ Output second copy of byte for green color. 2 .H ." " \ Output third copy of byte for blue color. LOOP ." }" CR \ Output close brace for row and newline. LOOP ." }" CR \ Output close brace for data and newline. ; : GET-PIXELS R @ DOE_READ_PIXEL_DATA R @ PIXEL-DUMP ; : RAW-PIXEL-DUMP ( addr -- ) 12 0 DO \ Eighteen rows in the image. 12 0 DO \ Eighteen pixels in each row. @+2 \ Read data value and increment pointer by two. SWAP \ Bring data value to TOS. 00FF AND \ Mask to clear unused bits. 2 .H ." " \ Output byte. LOOP CR \ Output newline. LOOP CR \ Output newline. ; : GET-RAW-PIXELS R @ DOE_READ_PIXEL_DATA R @ RAW-PIXEL-DUMP ;