ws2812 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ #include <stdint.h>
2
+
3
+ extern int board_info_init(void);
4
+ extern uint32_t board_info_peripheral_base_addr(void);
5
+ extern uint32_t board_info_sdram_address(void);
6
+
data/ext/ws2812/clk.h ADDED
@@ -0,0 +1,60 @@
1
+ /*
2
+ * clk.h
3
+ *
4
+ * Copyright (c) 2014 Jeremy Garff <jer @ jers.net>
5
+ *
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without modification, are permitted
9
+ * provided that the following conditions are met:
10
+ *
11
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
12
+ * conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
14
+ * of conditions and the following disclaimer in the documentation and/or other materials
15
+ * provided with the distribution.
16
+ * 3. Neither the name of the owner nor the names of its contributors may be used to endorse
17
+ * or promote products derived from this software without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
22
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ */
29
+
30
+ #ifndef __CLK_H__
31
+ #define __CLK_H__
32
+
33
+
34
+ typedef struct {
35
+ uint32_t ctl;
36
+ #define CM_PWM_CTL_PASSWD (0x5a << 24)
37
+ #define CM_PWM_CTL_MASH(val) ((val & 0x3) << 9)
38
+ #define CM_PWM_CTL_FLIP (1 << 8)
39
+ #define CM_PWM_CTL_BUSY (1 << 7)
40
+ #define CM_PWM_CTL_KILL (1 << 5)
41
+ #define CM_PWM_CTL_ENAB (1 << 4)
42
+ #define CM_PWM_CTL_SRC_GND (0 << 0)
43
+ #define CM_PWM_CTL_SRC_OSC (1 << 0)
44
+ #define CM_PWM_CTL_SRC_TSTDBG0 (2 << 0)
45
+ #define CM_PWM_CTL_SRC_TSTDBG1 (3 << 0)
46
+ #define CM_PWM_CTL_SRC_PLLA (4 << 0)
47
+ #define CM_PWM_CTL_SRC_PLLC (5 << 0)
48
+ #define CM_PWM_CTL_SRC_PLLD (6 << 0)
49
+ #define CM_PWM_CTL_SRC_HDMIAUX (7 << 0)
50
+ uint32_t div;
51
+ #define CM_PWM_DIV_PASSWD (0x5a << 24)
52
+ #define CM_PWM_DIV_DIVI(val) ((val & 0xfff) << 12)
53
+ #define CM_PWM_DIV_DIVF(val) ((val & 0xfff) << 0)
54
+ } __attribute__ ((packed)) cm_pwm_t;
55
+
56
+
57
+ #define CM_PWM_OFFSET (0x001010a0)
58
+
59
+
60
+ #endif /* __CLK_H__ */
data/ext/ws2812/dma.c ADDED
@@ -0,0 +1,79 @@
1
+ /*
2
+ * dma.c
3
+ *
4
+ * Copyright (c) 2014 Jeremy Garff <jer @ jers.net>
5
+ *
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without modification, are permitted
9
+ * provided that the following conditions are met:
10
+ *
11
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
12
+ * conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
14
+ * of conditions and the following disclaimer in the documentation and/or other materials
15
+ * provided with the distribution.
16
+ * 3. Neither the name of the owner nor the names of its contributors may be used to endorse
17
+ * or promote products derived from this software without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
22
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ */
29
+
30
+
31
+ #include <stdint.h>
32
+ #include <stdio.h>
33
+ #include <string.h>
34
+ #include <stdlib.h>
35
+ #include <unistd.h>
36
+
37
+ #include <sys/types.h>
38
+ #include <sys/stat.h>
39
+ #include <sys/mman.h>
40
+
41
+ #include "board_info.h"
42
+ #include "dma.h"
43
+
44
+
45
+ // DMA address mapping by DMA number index
46
+ const static uint32_t dma_offset[] =
47
+ {
48
+ DMA0_OFFSET,
49
+ DMA1_OFFSET,
50
+ DMA2_OFFSET,
51
+ DMA3_OFFSET,
52
+ DMA4_OFFSET,
53
+ DMA5_OFFSET,
54
+ DMA6_OFFSET,
55
+ DMA7_OFFSET,
56
+ DMA8_OFFSET,
57
+ DMA9_OFFSET,
58
+ DMA10_OFFSET,
59
+ DMA11_OFFSET,
60
+ DMA12_OFFSET,
61
+ DMA13_OFFSET,
62
+ DMA14_OFFSET,
63
+ DMA15_OFFSET,
64
+ };
65
+
66
+
67
+ uint32_t dmanum_to_phys(int dmanum)
68
+ {
69
+ int array_size = sizeof(dma_offset) / sizeof(dma_offset[0]);
70
+
71
+ if (dmanum >= array_size)
72
+ {
73
+ return 0;
74
+ }
75
+
76
+ return dma_offset[dmanum] + board_info_peripheral_base_addr();
77
+ }
78
+
79
+
data/ext/ws2812/dma.h ADDED
@@ -0,0 +1,126 @@
1
+ /*
2
+ * dma.h
3
+ *
4
+ * Copyright (c) 2014 Jeremy Garff <jer @ jers.net>
5
+ *
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without modification, are permitted
9
+ * provided that the following conditions are met:
10
+ *
11
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
12
+ * conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
14
+ * of conditions and the following disclaimer in the documentation and/or other materials
15
+ * provided with the distribution.
16
+ * 3. Neither the name of the owner nor the names of its contributors may be used to endorse
17
+ * or promote products derived from this software without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
22
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ */
29
+
30
+ #ifndef __DMA_H__
31
+ #define __DMA_H__
32
+
33
+
34
+ /*
35
+ * DMA Control Block in Main Memory
36
+ *
37
+ * Note: Must start at a 256 byte aligned address.
38
+ * Use corresponding register field definitions.
39
+ */
40
+ typedef struct
41
+ {
42
+ uint32_t ti;
43
+ uint32_t source_ad;
44
+ uint32_t dest_ad;
45
+ uint32_t txfr_len;
46
+ uint32_t stride;
47
+ uint32_t nextconbk;
48
+ uint32_t resvd_0x18[2];
49
+ } __attribute__((packed)) dma_cb_t;
50
+
51
+ /*
52
+ * DMA register set
53
+ */
54
+ typedef struct
55
+ {
56
+ uint32_t cs;
57
+ #define RPI_DMA_CS_RESET (1 << 31)
58
+ #define RPI_DMA_CS_ABORT (1 << 30)
59
+ #define RPI_DMA_CS_DISDEBUG (1 << 29)
60
+ #define RPI_DMA_CS_WAIT_OUTSTANDING_WRITES (1 << 28)
61
+ #define RPI_DMA_CS_PANIC_PRIORITY(val) ((val & 0xf) << 20)
62
+ #define RPI_DMA_CS_PRIORITY(val) ((val & 0xf) << 16)
63
+ #define RPI_DMA_CS_ERROR (1 << 8)
64
+ #define RPI_DMA_CS_WAITING_OUTSTANDING_WRITES (1 << 6)
65
+ #define RPI_DMA_CS_DREQ_STOPS_DMA (1 << 5)
66
+ #define RPI_DMA_CS_PAUSED (1 << 4)
67
+ #define RPI_DMA_CS_DREQ (1 << 3)
68
+ #define RPI_DMA_CS_INT (1 << 2)
69
+ #define RPI_DMA_CS_END (1 << 1)
70
+ #define RPI_DMA_CS_ACTIVE (1 << 0)
71
+ uint32_t conblk_ad;
72
+ uint32_t ti;
73
+ #define RPI_DMA_TI_NO_WIDE_BURSTS (1 << 26)
74
+ #define RPI_DMA_TI_WAITS(val) ((val & 0x1f) << 21)
75
+ #define RPI_DMA_TI_PERMAP(val) ((val & 0x1f) << 16)
76
+ #define RPI_DMA_TI_BURST_LENGTH(val) ((val & 0xf) << 12)
77
+ #define RPI_DMA_TI_SRC_IGNORE (1 << 11)
78
+ #define RPI_DMA_TI_SRC_DREQ (1 << 10)
79
+ #define RPI_DMA_TI_SRC_WIDTH (1 << 9)
80
+ #define RPI_DMA_TI_SRC_INC (1 << 8)
81
+ #define RPI_DMA_TI_DEST_IGNORE (1 << 7)
82
+ #define RPI_DMA_TI_DEST_DREQ (1 << 6)
83
+ #define RPI_DMA_TI_DEST_WIDTH (1 << 5)
84
+ #define RPI_DMA_TI_DEST_INC (1 << 4)
85
+ #define RPI_DMA_TI_WAIT_RESP (1 << 3)
86
+ #define RPI_DMA_TI_TDMODE (1 << 1)
87
+ #define RPI_DMA_TI_INTEN (1 << 0)
88
+ uint32_t source_ad;
89
+ uint32_t dest_ad;
90
+ uint32_t txfr_len;
91
+ #define RPI_DMA_TXFR_LEN_YLENGTH(val) ((val & 0xffff) << 16)
92
+ #define RPI_DMA_TXFR_LEN_XLENGTH(val) ((val & 0xffff) << 0)
93
+ uint32_t stride;
94
+ #define RPI_DMA_STRIDE_D_STRIDE(val) ((val & 0xffff) << 16)
95
+ #define RPI_DMA_STRIDE_S_STRIDE(val) ((val & 0xffff) << 0)
96
+ uint32_t nextconbk;
97
+ uint32_t debug;
98
+ } __attribute__((packed)) dma_t;
99
+
100
+
101
+ #define DMA0_OFFSET (0x00007000)
102
+ #define DMA1_OFFSET (0x00007100)
103
+ #define DMA2_OFFSET (0x00007200)
104
+ #define DMA3_OFFSET (0x00007300)
105
+ #define DMA4_OFFSET (0x00007400)
106
+ #define DMA5_OFFSET (0x00007500)
107
+ #define DMA6_OFFSET (0x00007600)
108
+ #define DMA7_OFFSET (0x00007700)
109
+ #define DMA8_OFFSET (0x00007800)
110
+ #define DMA9_OFFSET (0x00007900)
111
+ #define DMA10_OFFSET (0x00007a00)
112
+ #define DMA11_OFFSET (0x00007b00)
113
+ #define DMA12_OFFSET (0x00007c00)
114
+ #define DMA13_OFFSET (0x00007d00)
115
+ #define DMA14_OFFSET (0x00007e00)
116
+ #define DMA15_OFFSET (0x00e05000)
117
+
118
+
119
+ #define PAGE_SIZE (1 << 12)
120
+ #define PAGE_MASK (~(PAGE_SIZE - 1))
121
+ #define PAGE_OFFSET(page) (page & (PAGE_SIZE - 1))
122
+
123
+
124
+ uint32_t dmanum_to_phys(int dmanum);
125
+
126
+ #endif /* __DMA_H__ */
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mkmf'
4
+ unless FileTest.exists?(File.dirname(__FILE__) + '/lowlevel_wrap.c')
5
+ Dir.chdir(File.dirname(__FILE__)) do
6
+ system *%w[swig2.0 -Wall -ruby -prefix ws2812:: -initname lowlevel lowlevel.i]
7
+ fail "swig failed; perhaps aptitude install swig2.0" unless $?.exitstatus.zero?
8
+ end
9
+ end
10
+
11
+ create_makefile 'ws2812/lowlevel'
12
+
13
+ File.open('Makefile', 'at') do |mk|
14
+ mk.puts <<EOF
15
+ clean: clean-rpilowlevel
16
+ distclean: distclean-rpilowlevel
17
+
18
+ clean-rpilowlevel:
19
+ rm -f Makefile
20
+
21
+ distclean-rpilowlevel:
22
+ rm -f *_wrap.c
23
+ EOF
24
+ end
@@ -0,0 +1,20 @@
1
+ #ifndef GAMMA_H
2
+ #define GAMMA_H
3
+ const unsigned int ws281x_gamma[] = {
4
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5
+ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
6
+ 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
7
+ 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11,
8
+ 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18,
9
+ 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28,
10
+ 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40,
11
+ 40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54,
12
+ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
13
+ 71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89,
14
+ 90, 91, 93, 94, 95, 96, 98, 99,100,102,103,104,106,107,109,110,
15
+ 111,113,114,116,117,119,120,121,123,124,126,128,129,131,132,134,
16
+ 135,137,138,140,142,143,145,146,148,150,151,153,155,157,158,160,
17
+ 162,163,165,167,169,170,172,174,176,178,179,181,183,185,187,189,
18
+ 191,193,194,196,198,200,202,204,206,208,210,212,214,216,218,220,
19
+ 222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255};
20
+ #endif
data/ext/ws2812/gpio.h ADDED
@@ -0,0 +1,108 @@
1
+ /*
2
+ * gpio.h
3
+ *
4
+ * Copyright (c) 2014 Jeremy Garff <jer @ jers.net>
5
+ *
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without modification, are permitted
9
+ * provided that the following conditions are met:
10
+ *
11
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
12
+ * conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
14
+ * of conditions and the following disclaimer in the documentation and/or other materials
15
+ * provided with the distribution.
16
+ * 3. Neither the name of the owner nor the names of its contributors may be used to endorse
17
+ * or promote products derived from this software without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
22
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ */
29
+
30
+ #ifndef __GPIO_H__
31
+ #define __GPIO_H__
32
+
33
+
34
+ typedef struct
35
+ {
36
+ uint32_t fsel[6]; // GPIO Function Select
37
+ uint32_t resvd_0x18;
38
+ uint32_t set[2]; // GPIO Pin Output Set
39
+ uint32_t resvd_0x24;
40
+ uint32_t clr[2]; // GPIO Pin Output Clear
41
+ uint32_t resvd_0x30;
42
+ uint32_t lev[2]; // GPIO Pin Level
43
+ uint32_t resvd_0x3c;
44
+ uint32_t eds[2]; // GPIO Pin Event Detect Status
45
+ uint32_t resvd_0x48;
46
+ uint32_t ren[2]; // GPIO Pin Rising Edge Detect Enable
47
+ uint32_t resvd_0x54;
48
+ uint32_t fen[2]; // GPIO Pin Falling Edge Detect Enable
49
+ uint32_t resvd_0x60;
50
+ uint32_t hen[2]; // GPIO Pin High Detect Enable
51
+ uint32_t resvd_0x6c;
52
+ uint32_t len[2]; // GPIO Pin Low Detect Enable
53
+ uint32_t resvd_0x78;
54
+ uint32_t aren[2]; // GPIO Pin Async Rising Edge Detect
55
+ uint32_t resvd_0x84;
56
+ uint32_t afen[2]; // GPIO Pin Async Falling Edge Detect
57
+ uint32_t resvd_0x90;
58
+ uint32_t pud; // GPIO Pin Pull up/down Enable
59
+ uint32_t pudclk[2]; // GPIO Pin Pull up/down Enable Clock
60
+ uint32_t resvd_0xa0[4];
61
+ uint32_t test;
62
+ } __attribute__((packed)) gpio_t;
63
+
64
+
65
+ #define GPIO_OFFSET (0x00200000)
66
+
67
+
68
+ static inline void gpio_function_set(volatile gpio_t *gpio, uint8_t pin, uint8_t function)
69
+ {
70
+ int regnum = pin / 10;
71
+ int offset = (pin % 10) * 3;
72
+ uint8_t funcmap[] = { 4, 5, 6, 7, 3, 2 }; // See datasheet for mapping
73
+
74
+ if (function > 5)
75
+ {
76
+ return;
77
+ }
78
+
79
+ gpio->fsel[regnum] &= ~(0x7 << offset);
80
+ gpio->fsel[regnum] |= ((funcmap[function]) << offset);
81
+ }
82
+
83
+ static inline void gpio_level_set(volatile gpio_t *gpio, uint8_t pin, uint8_t level)
84
+ {
85
+ int regnum = pin >> 5;
86
+ int offset = (pin & 0x1f);
87
+
88
+ if (level)
89
+ {
90
+ gpio->set[regnum] = (1 << offset);
91
+ }
92
+ else
93
+ {
94
+ gpio->clr[regnum] = (1 << offset);
95
+ }
96
+ }
97
+
98
+ static inline void gpio_output_set(volatile gpio_t *gpio, uint8_t pin, uint8_t output)
99
+ {
100
+ int regnum = pin / 10;
101
+ int offset = (pin % 10) * 3;
102
+ uint8_t function = output ? 1 : 0; // See datasheet for mapping
103
+
104
+ gpio->fsel[regnum] &= ~(0x7 << offset);
105
+ gpio->fsel[regnum] |= ((function & 0x7) << offset);
106
+ }
107
+
108
+ #endif /* __GPIO_H__ */
@@ -0,0 +1,48 @@
1
+ // SWIG interface file to define rpi_ws281x library python wrapper.
2
+ // Author: Tony DiCola (tony@tonydicola.com), Jeremy Garff (jer@jers.net)
3
+ // Modified by: Michal Jirku (box@wejn.org) for Ruby
4
+
5
+ // Define module name lowlevel.
6
+ %module lowlevel
7
+
8
+ // Include standard SWIG types & array support for support of uint32_t
9
+ // parameters and arrays.
10
+ %include "stdint.i"
11
+ %include "carrays.i"
12
+
13
+ // Declare functions which will be exported as anything in the ws2811.h header.
14
+ %{
15
+ #include "ws2811.h"
16
+ %}
17
+
18
+ // Process ws2811.h header and export all included functions.
19
+ %include "ws2811.h"
20
+
21
+ %inline %{
22
+ uint32_t ws2811_led_get(ws2811_channel_t *channel, int lednum)
23
+ {
24
+ if (lednum >= channel->count)
25
+ {
26
+ return -1;
27
+ }
28
+
29
+ return channel->leds[lednum];
30
+ }
31
+
32
+ int ws2811_led_set(ws2811_channel_t *channel, int lednum, uint32_t color)
33
+ {
34
+ if (lednum >= channel->count)
35
+ {
36
+ return -1;
37
+ }
38
+
39
+ channel->leds[lednum] = color;
40
+
41
+ return 0;
42
+ }
43
+
44
+ ws2811_channel_t *ws2811_channel_get(ws2811_t *ws, int channelnum)
45
+ {
46
+ return &ws->channel[channelnum];
47
+ }
48
+ %}