{ Prop2 WS2812 demo using smartpins Version 0.5 ozpropdev Feb 17th 2019 Multi lane demo (6 lanes = 6 smartpins) } con sys_clk = 25_000_000 'rcfast ~25MHz us = sys_clk / 1_000_000 ws2812_load = 50 * us _200ns = us * 200 / 1000 lanes = 6 lane_length = 60 ws2812_4 = clk-3 ws2812_5 = clk-2 ws2812_6 = clk-1 clk = 20 ws2812_1 = clk+1 ws2812_2 = clk+2 ws2812_3 = clk+3 '************************************************************************* dat org hubset #0 wrpin #%1_00101_0,#clk 'transition mode wxpin ##_200ns,#clk dirh #clk 'initialize sync tx smartpins init_smartpins mov pa,#pins 'pin list rep @.loop,#lanes alts pa,autoinc mov pin,0-0 'get pin mov temp,#clk sub temp,pin and temp,#7 shl temp,#24 'B pin offset to clk pin or temp,#%1_11100_0 'sync tx mode wrpin temp,pin wxpin #%1_00000 | 23,pin 'start/stop mode 24 bits dirh pin 'enable smartpin .loop 'build ws812 waveform data into lut for each byte 'e.g. byte $8c becomes %001_001_011_011_001_001_001_011 mov index,#0 build mov count,#8 'number of bits mov pa,index mov pb,#0 .loop testb pa,#7 wc shl pb,#3 or pb,#1 '0 = %100 (1/3 t) if_c or pb,#%10 '1 = %110 (2/3 t) shl pa,#1 djnz count,#.loop shl pb,#32-24 rev pb 'prepare for msb shifted first wrlut pb,index incmod index,#255 wz if_nz jmp #build getct time addct1 time,delay 'Main loop ############################################################## 'send data to ws2812 devices (6 lanes) update_ws2812 mov altx,cfg 'initialize pointers rep @.loop,#lanes alti altx,#%111_111 mov 0-0,0-0 .loop mov leds,#lane_length mov lane,#lanes next_led mov altx,cfg2 'get color data from hub rep @.loop,#lanes alti altx,#%111_111 rdlong 0-0,0-0 .loop mov count,#3 '3 colors per led mov index,#0 next_color alts index,#rgb1 getbyte pb,0-0,#2 'get color byte altd index,#rgb1 shl 0-0,#8 rdlut pa,pb alts index,#pins 'cobvet byte to waveform mov pin,0-0 wypin pa,pin 'load sync tx incmod index,#lanes-1 wz if_nz jmp #next_color wypin #48,#clk 'start 48 clock transitions busy testp #clk wc 'wait for smartpin completion if_nc jmp #busy akpin #clk 'clear smartpin djnz count,#next_color mov altx,##ptr1 'adjust pointers rep @.loop,#lanes altd altx,autoinc add 0-0,#4 .loop djnz leds,#next_led waitx ##ws2812_load 'data low for >50uS = reset '############################################################################ 'shift led patterns in led buffers pollct1 wc if_nc jmp #update_ws2812 addct1 time,delay shift_all mov index,#buffer1 mov count,#lanes .loop alts index,autoinc mov ptra,0-0 call #shift djnz count,#.loop jmp #update_ws2812 shift mov ptrb,ptra add ptrb,#4 rdlong pb,ptra rep @.loop,#59 rdlong pa,ptrb++ wrlong pa,ptra++ .loop wrlong pb,ptra ret cfg long ptr1 << 9 | buffer1 cfg2 long rgb1 << 9 | ptr1 altx long 0 autoinc long 1 << 9 time long 0 delay long sys_clk / 20 count long 0 index long 0 rgb long 0 leds long 0 lut long 0 lane long 0 pin long 0 temp long 0 buffer1 long @led_buffer1 'list of buffer start addresses long @led_buffer2 long @led_buffer3 long @led_buffer4 long @led_buffer5 long @led_buffer6 ptr1 long 0[6] rgb1 long 0[6] pins long ws2812_1 'pin list long ws2812_2 long ws2812_3 long ws2812_4 long ws2812_5 long ws2812_6 '************************************************************************ '************************************************************************ orgh $400 led_buffer1 long $00_00_7f_00 'red long $00_2f_00_00 'green long $00_1f_00_00 'green long $00_0f_00_00 'green long $00_08_00_00 'green long $00_04_00_00 'green long $00_04_00_00 'green long $00_00_00_04 'blue orgh $500 led_buffer2 long 0[5] long $00_1f_00_00[5] 'green long $00_00_1f_00[5] 'red long $00_00_00_1f[5] 'blue long $00_00_1f_1f[5] 'magenta long $00_1f_00_1f[5] 'cyan long $00_1f_1f_00[5] 'yellow long $00_1f_1f_1f[5] 'yehite long $00_1f_00_00[5] 'green long $00_00_1f_00[5] 'red long $00_00_00_1f[5] 'blue long $00_00_1f_1f[5] 'magenta orgh $600 led_buffer3 long $00_00_1f_00[19] 'red long $7f0000 long $00_1f_00_00[19] 'green long $7f long $00_00_00_1f[19] 'blue long $7f00 orgh $700 led_buffer4 long $00_7f_7f_00 'yellow long 0[14] long $00_7f_7f_00 'yellow long 0[14] long $00_7f_7f_00 'yellow long 0[14] long $00_7f_7f_00 'yellow long 0[14] orgh $800 led_buffer5 long $00_00_ff_00 'red long 0[19] long $00_ff_00_00 'green long 0[19] long $00_00_00_ff 'blue long 0[19] orgh $900 led_buffer6 long $00_00_ff_00[5] 'red long 0[15] long $00_ff_00_00[5] 'green long 0[15] long $00_00_00_ff[5] 'blue long 0[15]