Adafruit NeoPixel Library
rp2040_pio.h
1 // -------------------------------------------------- //
2 // This file is autogenerated by pioasm; do not edit! //
3 // -------------------------------------------------- //
4 
5 // Unless you know what you are doing...
6 // Lines 47 and 52 have been edited to set transmit bit count
7 
8 #if !PICO_NO_HARDWARE
9 #include "hardware/pio.h"
10 #endif
11 
12 // ------ //
13 // ws2812 //
14 // ------ //
15 
16 #define ws2812_wrap_target 0
17 #define ws2812_wrap 3
18 
19 #define ws2812_T1 2
20 #define ws2812_T2 5
21 #define ws2812_T3 3
22 
23 static const uint16_t ws2812_program_instructions[] = {
24  // .wrap_target
25  0x6221, // 0: out x, 1 side 0 [2]
26  0x1123, // 1: jmp !x, 3 side 1 [1]
27  0x1400, // 2: jmp 0 side 1 [4]
28  0xa442, // 3: nop side 0 [4]
29  // .wrap
30 };
31 
32 #if !PICO_NO_HARDWARE
33 static const struct pio_program ws2812_program = {
34  .instructions = ws2812_program_instructions,
35  .length = 4,
36  .origin = -1,
37 };
38 
39 static inline pio_sm_config ws2812_program_get_default_config(uint offset) {
40  pio_sm_config c = pio_get_default_sm_config();
41  sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap);
42  sm_config_set_sideset(&c, 1, false, false);
43  return c;
44 }
45 
46 #include "hardware/clocks.h"
47 static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin,
48  float freq, uint bits) {
49  pio_gpio_init(pio, pin);
50  pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
51  pio_sm_config c = ws2812_program_get_default_config(offset);
52  sm_config_set_sideset_pins(&c, pin);
53  sm_config_set_out_shift(&c, false, true,
54  bits); // <----<<< Length changed to "bits"
55  sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
56  int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
57  float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
58  sm_config_set_clkdiv(&c, div);
59  pio_sm_init(pio, sm, offset, &c);
60  pio_sm_set_enabled(pio, sm, true);
61 }
62 
63 #endif