Hallo, ich habe folgende Funktion (geklaut von https://github.com/strawberryhacker/led-strip-driver - unnötige "#if"-Teile entfernt, damit das hier nicht zu lang wird.
1 | void __attribute__((noinline)) update_led_strip(color* colors, uint16_t number_of_leds) |
2 | {
|
3 | LED_PORT.DIRSET = (1 << LED_PIN); |
4 | uint8_t* led_strip_port_pointer; |
5 | led_strip_port_pointer = (uint8_t*)(&LED_PORT); |
6 | |
7 | uint8_t pin = (1 << LED_PIN); |
8 | |
9 | cli(); |
10 | while(number_of_leds--) |
11 | {
|
12 | asm volatile( |
13 | |
14 | //send red component
|
15 | "ld __tmp_reg__, %a0+ \n\t" |
16 | "ld __tmp_reg__, %a0 \n\t" |
17 | "rcall send_byte%= \n\t" |
18 | |
19 | //send green component
|
20 | "ld __tmp_reg__, -%a0 \n\t" |
21 | "rcall send_byte%= \n\t" |
22 | |
23 | //send blue component
|
24 | "ld __tmp_reg__, %a0+ \n\t" |
25 | "ld __tmp_reg__, %a0+ \n\t" |
26 | "ld __tmp_reg__, %a0+ \n\t" |
27 | "rcall send_byte%= \n\t" |
28 | "rjmp asm_end%= \n\t" |
29 | |
30 | //send byte subroutine
|
31 | "send_byte%=: \n\t" |
32 | "rcall send_bit%= \n\t" |
33 | "rcall send_bit%= \n\t" |
34 | "rcall send_bit%= \n\t" |
35 | "rcall send_bit%= \n\t" |
36 | "rcall send_bit%= \n\t" |
37 | "rcall send_bit%= \n\t" |
38 | "rcall send_bit%= \n\t" |
39 | "rcall send_bit%= \n\t" |
40 | "ret \n\t" |
41 | |
42 | //send bit subroutine
|
43 | "send_bit%=: \n\t" |
44 | |
45 | "rol __tmp_reg__ \n\t" |
46 | //set outout high
|
47 | "std Y+5, %[led_strip_pin] \n\t" |
48 | "brcs .+2 \n\t" |
49 | //set outout low
|
50 | "std Y+6, %[led_strip_pin] \n\t" |
51 | "nop \n\t" |
52 | "nop \n\t" |
53 | "brcc .+2 \n\t" |
54 | //set outout low
|
55 | "std Y+6, %[led_strip_pin] \n\t" |
56 | |
57 | "ret \n" |
58 | "asm_end%=:"
|
59 | |
60 | //constraints
|
61 | : "=b" (colors) //output operands |
62 | : "0" (colors), [led_strip_pin] "r" (pin), "y" (led_strip_port_pointer)); //input operands |
63 | }
|
64 | |
65 | //enable interrupt
|
66 | sei(); |
67 | |
68 | //send reset pulse
|
69 | _delay_us(80); |
70 | }
|
Da ich nur eine einzige LED ansteuern möchte, hätte ich die Funktion gerne geändert. Ungefähr so: "update_led(uint8_t red, uint8_t green, uint8_t blue)" Ich habs jetzt schon ne Weile versucht, aber ich bekomme es einfach nicht hin. Kenne mich mit Assembler leider überhaupt nicht aus. Klar könnte ich die Funktion auch mit number_of_leds=1 aufrufen. Aber ich würd ja gern wissen WIE das funktioniert :) Ich hoffe mir kann jemand helfen. 😊