Skip to content

Instantly share code, notes, and snippets.

@rutles
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rutles/e75eb592937835c6224e to your computer and use it in GitHub Desktop.
Save rutles/e75eb592937835c6224e to your computer and use it in GitHub Desktop.
DW2811 Handler. LPC810 @ 24MHz only.
@ ws2811.s - ws2811 handler
@ LPC810@24MHz
@ void ws2811Write(const uint8_t *data, uint8_t count)
.cpu cortex-m0plus
.thumb
.syntax unified
.file "ws2811.s"
.text
.align 1
.global ws2811Write
.thumb_func
.type ws2811Write, %function
ws2811Write:
push {r4, r5, r6, lr} @ save registers
movs r2, 0x04 @ load r2, P0_2 bit location
ldr r3, =0xa0002200 @ load r3, &LPC_GPIO_PORT->SET[0]
ldr r4, =0xa0002280 @ load r4, &LPC_GPIO_PORT->CLR[0]
.loop_byte:
movs r5, 0x80 @ 28: load r5, bit mask
ldrb r6, [r0, 0] @ 29, 30: load r6, data
.loop_bit:
str r2, [r3, 0] @ 1: P0_2 set
b .+2 @ 2, 3:
tst r6, r5 @ 4: check bit
bne .skip @ 5(6):
str r2, [r4, 0] @ 6: if bit == 0 P0_2 clear
.skip:
b .+2 @ 7, 8:
b .+2 @ 9,10:
b .+2 @ 11,12:
b .+2 @ 13,14:
str r2, [r4, 0] @ 15: P0_2 (re)clear
nop @ 16:
b .+2 @ 17, 18:
b .+2 @ 19, 20:
lsrs r5, r5, 1 @ 21: shift bit mask
beq .next_byte @ 22, (23):
nop @ 23:
b .+2 @ 24, 25:
b .+2 @ 26, 27:
b .loop_bit @ 29, 30:
.next_byte:
adds r0, 1 @ 24: increment address
subs r1, 1 @ 25: decrement count
bne .loop_byte @ 26, 27:
pop {r4, r5, r6, pc} @ restore registers
.size ws2811Write, .-ws2811Write
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment