From 2878d3aaa2c6ce297a463781d057f9dfe3b8f14b Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 21 Mar 2026 00:40:03 +0100 Subject: [PATCH] sk6812: prepare use of multiple timing types. timing is very tight so we need an extra routine per timing type for sending a byte to the led strip. --- avr/devices/all/modules_include.asm | 1 + avr/modules/sk6812/io.asm | 131 ++++++++++++++++++ avr/modules/sk6812/main.asm | 201 ++++++++-------------------- 3 files changed, 187 insertions(+), 146 deletions(-) create mode 100644 avr/modules/sk6812/io.asm diff --git a/avr/devices/all/modules_include.asm b/avr/devices/all/modules_include.asm index 3b8a6a3..3652425 100644 --- a/avr/devices/all/modules_include.asm +++ b/avr/devices/all/modules_include.asm @@ -228,6 +228,7 @@ #ifdef MODULES_SK6812 .include "modules/sk6812/main.asm" + .include "modules/sk6812/io.asm" #ifdef MODULES_NETWORK .include "modules/sk6812/recv.asm" .include "devices/all/handlevaluemsg.asm" diff --git a/avr/modules/sk6812/io.asm b/avr/modules/sk6812/io.asm new file mode 100644 index 0000000..bf39ad8 --- /dev/null +++ b/avr/modules/sk6812/io.asm @@ -0,0 +1,131 @@ +; *************************************************************************** +; copyright : (C) 2026 by Martin Preuss +; email : martin@libchipcard.de +; +; *************************************************************************** +; * This file is part of the project "AqHome". * +; * Please see toplevel file COPYING of that project for license details. * +; *************************************************************************** + + + + +sk6812JumpTableSendByte: + rjmp sk6812SendByte0 + rjmp sk6812SendByte1 + + + + +; *************************************************************************** +; type 0 + + +.macro SK6812_SENDBIT0 +sk6812SendBit: ; 0 1 + rol r16 ; +1 +1 + brcs sk6812SendBit_send1 ; +1 +2 + ; send 0 + nop ; +1 + sbi SK6812_PORT, SK6812_PINNUM ; +2 + nop ; +1 + nop ; +1 + cbi SK6812_PORT, SK6812_PINNUM ; +2 +; nop ; +1 + nop ; +1 + rjmp sk6812SendBit_end ; +2 +sk6812SendBit_send1: + ; send 1 + sbi SK6812_PORT, SK6812_PINNUM ; +2 + nop ; +1 + nop ; +1 + nop ; +1 + cbi SK6812_PORT, SK6812_PINNUM ; +2 + nop ; +1 + nop ; +1 + nop ; +1 +sk6812SendBit_end: ; 13 13 +.endmacro + + + +; --------------------------------------------------------------------------- +; @routine sk6812SendByte0 +; +; Sends a byte to the LED strip +; @param r16 byte +; @clobbers r16 (r24, r25) + +sk6812SendByte0: + SK6812_SENDBIT0 + SK6812_SENDBIT0 + SK6812_SENDBIT0 + SK6812_SENDBIT0 + + SK6812_SENDBIT0 + SK6812_SENDBIT0 + SK6812_SENDBIT0 + SK6812_SENDBIT0 + ret +; @end + + + + + +; *************************************************************************** +; type 1 + + +.macro SK6812_SENDBIT1 + lsl r16 ; +1 + brcs l_sendOne ; +1 if false, +2 if branch taken + ; send ZERO + nop ; +1 + out SK6812_PORT, r25 ; +1 HIGH + nop ; +1 + nop ; +1 + nop + out SK6812_PORT, r24 ; +1 + nop ; +1 + rjmp l_end ; +2 +l_sendOne: + out SK6812_PORT, r25 ; +1 HIGH + nop ; +1 + nop ; +1 + nop ; +1 + nop ; +1 + nop ; +1 + out SK6812_PORT, r24 ; +1 + nop ; +1 +l_end: +.endmacro + + + +; --------------------------------------------------------------------------- +; @routine sk6812SendByte1 +; +; Sends a byte to the LED strip +; @param r16 byte +; @clobbers r16, r24, r25 + +sk6812SendByte1: + ldi r24, 0 + ldi r25, (1<