├── README.md ├── examples └── fade_in_out │ └── fade_in_out.ino ├── include ├── ws2812.h ├── ws2812_defs.h ├── ws2812_dma.h └── ws2812_gamma.h ├── keywords.txt ├── library.properties └── src ├── ws2812_dma.c ├── ws2812_gamma.cpp ├── ws2812_i2s.cpp └── ws2812_i2s.h /README.md: -------------------------------------------------------------------------------- 1 | # esp8266_ws2812_i2s 2 | ESP8266 Library for driving WS2812 led-strip using the I2S output. Use within the Arduino IDE 3 | -------------------------------------------------------------------------------- /examples/fade_in_out/fade_in_out.ino: -------------------------------------------------------------------------------- 1 | // fade_in_out.ino 2 | // 3 | // small demonstrator for ws2812_i2s library 4 | // created by JoDa 5 | 6 | #include 7 | 8 | #define NUM_LEDS 100 9 | 10 | static WS2812 ledstrip; 11 | static Pixel_t pixels[NUM_LEDS]; 12 | 13 | 14 | void setup() 15 | { 16 | Serial.begin(115200); 17 | Serial.println("ws2812 i2s library demo sketch"); 18 | 19 | ledstrip.init(NUM_LEDS); 20 | } 21 | 22 | 23 | void loop() 24 | { 25 | uint8_t i; 26 | static uint8_t c = 0; 27 | static uint8_t d = 1; 28 | 29 | for(i=0; i 9 | 10 | // include file from project folder 11 | #include "ws2812.h" 12 | 13 | // ----------------------------------------------------- 14 | 15 | // Helper macro's 16 | 17 | #define NUM_RGB_BYTES (num_leds * 3) 18 | #define NUM_I2S_PIXEL_BYTES (num_leds * 3 * 4) // (#leds) * (RGB) * (4 i2s bits) 19 | #define NUM_I2S_PIXEL_WORDS (num_leds * 3) 20 | 21 | // ----------------------------------------------------- 22 | 23 | // I2S timing parameters 24 | 25 | // Creates an I2S SR of 93,750 Hz, or 3 MHz Bitclock (.333us/sample) 26 | // Measured on scope : 4 bitclock-ticks every 1200ns --> 300ns bitclock ??? 27 | // 12000000L/(div*bestbck*2) 28 | 29 | #define WS_I2S_BCK (17) 30 | #define WS_I2S_DIV (4) 31 | #define NUM_I2S_ZERO_BYTES (28) // WS2812 LED Treset = 67us (must be >50us) 32 | #define NUM_I2S_ZERO_WORDS (NUM_I2S_ZERO_BYTES / 4) 33 | 34 | // ----------------------------------------------------- 35 | 36 | #ifndef i2c_bbpll 37 | #define i2c_bbpll 0x67 38 | #define i2c_bbpll_en_audio_clock_out 4 39 | #define i2c_bbpll_en_audio_clock_out_msb 7 40 | #define i2c_bbpll_en_audio_clock_out_lsb 7 41 | #define i2c_bbpll_hostid 4 42 | #endif 43 | 44 | // ----------------------------------------------------- 45 | 46 | #define i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) rom_i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) 47 | #define i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) rom_i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) 48 | #define i2c_writeReg_Mask_def(block, reg_add, indata) i2c_writeReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb, indata) 49 | #define i2c_readReg_Mask_def(block, reg_add) i2c_readReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb) 50 | 51 | // ----------------------------------------------------- 52 | 53 | #ifndef ETS_SLC_INUM 54 | #define ETS_SLC_INUM 1 55 | #endif 56 | 57 | // ----------------------------------------------------- 58 | 59 | // from i2s_reg.h 60 | 61 | #define DR_REG_I2S_BASE (0x60000e00) 62 | 63 | #define I2STXFIFO (DR_REG_I2S_BASE + 0x0000) 64 | #define I2SRXFIFO (DR_REG_I2S_BASE + 0x0004) 65 | #define I2SCONF (DR_REG_I2S_BASE + 0x0008) 66 | #define I2S_BCK_DIV_NUM 0x0000003F 67 | #define I2S_BCK_DIV_NUM_S 22 68 | #define I2S_CLKM_DIV_NUM 0x0000003F 69 | #define I2S_CLKM_DIV_NUM_S 16 70 | #define I2S_BITS_MOD 0x0000000F 71 | #define I2S_BITS_MOD_S 12 72 | #define I2S_RECE_MSB_SHIFT (BIT(11)) 73 | #define I2S_TRANS_MSB_SHIFT (BIT(10)) 74 | #define I2S_I2S_RX_START (BIT(9)) 75 | #define I2S_I2S_TX_START (BIT(8)) 76 | #define I2S_MSB_RIGHT (BIT(7)) 77 | #define I2S_RIGHT_FIRST (BIT(6)) 78 | #define I2S_RECE_SLAVE_MOD (BIT(5)) 79 | #define I2S_TRANS_SLAVE_MOD (BIT(4)) 80 | #define I2S_I2S_RX_FIFO_RESET (BIT(3)) 81 | #define I2S_I2S_TX_FIFO_RESET (BIT(2)) 82 | #define I2S_I2S_RX_RESET (BIT(1)) 83 | #define I2S_I2S_TX_RESET (BIT(0)) 84 | #define I2S_I2S_RESET_MASK 0xf 85 | 86 | #define I2SINT_RAW (DR_REG_I2S_BASE + 0x000c) 87 | #define I2S_I2S_TX_REMPTY_INT_RAW (BIT(5)) 88 | #define I2S_I2S_TX_WFULL_INT_RAW (BIT(4)) 89 | #define I2S_I2S_RX_REMPTY_INT_RAW (BIT(3)) 90 | #define I2S_I2S_RX_WFULL_INT_RAW (BIT(2)) 91 | #define I2S_I2S_TX_PUT_DATA_INT_RAW (BIT(1)) 92 | #define I2S_I2S_RX_TAKE_DATA_INT_RAW (BIT(0)) 93 | 94 | #define I2SINT_ST (DR_REG_I2S_BASE + 0x0010) 95 | #define I2S_I2S_TX_REMPTY_INT_ST (BIT(5)) 96 | #define I2S_I2S_TX_WFULL_INT_ST (BIT(4)) 97 | #define I2S_I2S_RX_REMPTY_INT_ST (BIT(3)) 98 | #define I2S_I2S_RX_WFULL_INT_ST (BIT(2)) 99 | #define I2S_I2S_TX_PUT_DATA_INT_ST (BIT(1)) 100 | #define I2S_I2S_RX_TAKE_DATA_INT_ST (BIT(0)) 101 | 102 | #define I2SINT_ENA (DR_REG_I2S_BASE + 0x0014) 103 | #define I2S_I2S_TX_REMPTY_INT_ENA (BIT(5)) 104 | #define I2S_I2S_TX_WFULL_INT_ENA (BIT(4)) 105 | #define I2S_I2S_RX_REMPTY_INT_ENA (BIT(3)) 106 | #define I2S_I2S_RX_WFULL_INT_ENA (BIT(2)) 107 | #define I2S_I2S_TX_PUT_DATA_INT_ENA (BIT(1)) 108 | #define I2S_I2S_RX_TAKE_DATA_INT_ENA (BIT(0)) 109 | 110 | #define I2SINT_CLR (DR_REG_I2S_BASE + 0x0018) 111 | #define I2S_I2S_TX_REMPTY_INT_CLR (BIT(5)) 112 | #define I2S_I2S_TX_WFULL_INT_CLR (BIT(4)) 113 | #define I2S_I2S_RX_REMPTY_INT_CLR (BIT(3)) 114 | #define I2S_I2S_RX_WFULL_INT_CLR (BIT(2)) 115 | #define I2S_I2S_PUT_DATA_INT_CLR (BIT(1)) 116 | #define I2S_I2S_TAKE_DATA_INT_CLR (BIT(0)) 117 | 118 | #define I2STIMING (DR_REG_I2S_BASE + 0x001c) 119 | #define I2S_TRANS_BCK_IN_INV (BIT(22)) 120 | #define I2S_RECE_DSYNC_SW (BIT(21)) 121 | #define I2S_TRANS_DSYNC_SW (BIT(20)) 122 | #define I2S_RECE_BCK_OUT_DELAY 0x00000003 123 | #define I2S_RECE_BCK_OUT_DELAY_S 18 124 | #define I2S_RECE_WS_OUT_DELAY 0x00000003 125 | #define I2S_RECE_WS_OUT_DELAY_S 16 126 | #define I2S_TRANS_SD_OUT_DELAY 0x00000003 127 | #define I2S_TRANS_SD_OUT_DELAY_S 14 128 | #define I2S_TRANS_WS_OUT_DELAY 0x00000003 129 | #define I2S_TRANS_WS_OUT_DELAY_S 12 130 | #define I2S_TRANS_BCK_OUT_DELAY 0x00000003 131 | #define I2S_TRANS_BCK_OUT_DELAY_S 10 132 | #define I2S_RECE_SD_IN_DELAY 0x00000003 133 | #define I2S_RECE_SD_IN_DELAY_S 8 134 | #define I2S_RECE_WS_IN_DELAY 0x00000003 135 | #define I2S_RECE_WS_IN_DELAY_S 6 136 | #define I2S_RECE_BCK_IN_DELAY 0x00000003 137 | #define I2S_RECE_BCK_IN_DELAY_S 4 138 | #define I2S_TRANS_WS_IN_DELAY 0x00000003 139 | #define I2S_TRANS_WS_IN_DELAY_S 2 140 | #define I2S_TRANS_BCK_IN_DELAY 0x00000003 141 | #define I2S_TRANS_BCK_IN_DELAY_S 0 142 | 143 | #define I2S_FIFO_CONF (DR_REG_I2S_BASE + 0x0020) 144 | #define I2S_I2S_RX_FIFO_MOD 0x00000007 145 | #define I2S_I2S_RX_FIFO_MOD_S 16 146 | #define I2S_I2S_TX_FIFO_MOD 0x00000007 147 | #define I2S_I2S_TX_FIFO_MOD_S 13 148 | #define I2S_I2S_DSCR_EN (BIT(12)) 149 | #define I2S_I2S_TX_DATA_NUM 0x0000003F 150 | #define I2S_I2S_TX_DATA_NUM_S 6 151 | #define I2S_I2S_RX_DATA_NUM 0x0000003F 152 | #define I2S_I2S_RX_DATA_NUM_S 0 153 | 154 | #define I2SRXEOF_NUM (DR_REG_I2S_BASE + 0x0024) 155 | #define I2S_I2S_RX_EOF_NUM 0xFFFFFFFF 156 | #define I2S_I2S_RX_EOF_NUM_S 0 157 | 158 | #define I2SCONF_SIGLE_DATA (DR_REG_I2S_BASE + 0x0028) 159 | #define I2S_I2S_SIGLE_DATA 0xFFFFFFFF 160 | #define I2S_I2S_SIGLE_DATA_S 0 161 | 162 | #define I2SCONF_CHAN (DR_REG_I2S_BASE + 0x002c) 163 | #define I2S_RX_CHAN_MOD 0x00000003 164 | #define I2S_RX_CHAN_MOD_S 3 165 | #define I2S_TX_CHAN_MOD 0x00000007 166 | #define I2S_TX_CHAN_MOD_S 0 167 | 168 | // ----------------------------------------------------- 169 | 170 | #endif 171 | 172 | // end of file 173 | -------------------------------------------------------------------------------- /include/ws2812_dma.h: -------------------------------------------------------------------------------- 1 | // ws2812_dma.h 2 | 3 | #ifndef __WS2812_DMA_H__ 4 | #define __WS2812_DMA_H__ 5 | 6 | // type definition taken from : sdio_slv.h 7 | 8 | typedef struct 9 | { 10 | uint32_t blocksize:12; 11 | uint32_t datalen:12; 12 | uint32_t unused:5; 13 | uint32_t sub_sof:1; 14 | uint32_t eof:1; 15 | uint32_t owner:1; 16 | uint32_t buf_ptr; 17 | uint32_t next_link_ptr; 18 | } sdio_queue_t; 19 | 20 | // ----------------------------------------------------- 21 | 22 | extern void ws2812_dma(sdio_queue_t *); 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /include/ws2812_gamma.h: -------------------------------------------------------------------------------- 1 | // ws2812_gamma.h 2 | 3 | #ifndef __WS2812_GAMMA_H__ 4 | #define __WS2812_GAMMA_H__ 5 | 6 | #include 7 | #include "ws2812.h" 8 | 9 | extern const uint8_t *gamma_dither[WS2812_DITHER_NUM]; 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | WS2812 KEYWORD1 2 | Pixel_t KEYWORD1 3 | init KEYWORD2 4 | show KEYWORD2 5 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ws2812_i2s 2 | version=0.1 3 | author=JoDa 4 | maintainer=JoDa 5 | sentence=Control ws2812 leds on an ESP8266 using i2s. 6 | paragraph=Control ws2812 leds on an ESP8266 using i2s. 7 | category=Display 8 | url=http://github 9 | architectures=esp8266 -------------------------------------------------------------------------------- /src/ws2812_dma.c: -------------------------------------------------------------------------------- 1 | // ws2812_init.c 2 | 3 | // C-based helper function for initilalizing 4 | // the I2S system 5 | 6 | #include 7 | #include "slc_register.h" 8 | #include "user_interface.h" 9 | #include "../include/ws2812_defs.h" 10 | #include "../include/ws2812_dma.h" 11 | 12 | 13 | #if WS2812_USE_INTERRUPT == 1 14 | // for debugging purposes 15 | static volatile uint32_t interrupt_count = 0; 16 | 17 | static void ws2812_isr(void) 18 | { 19 | //clear all intr flags 20 | WRITE_PERI_REG(SLC_INT_CLR, 0xffffffff);//slc_intr_status); 21 | 22 | interrupt_count++; 23 | } 24 | #endif 25 | 26 | 27 | void ws2812_dma(sdio_queue_t *i2s_pixels_queue) 28 | { 29 | // Reset DMA 30 | SET_PERI_REG_MASK(SLC_CONF0, SLC_RXLINK_RST); //|SLC_TXLINK_RST); 31 | CLEAR_PERI_REG_MASK(SLC_CONF0, SLC_RXLINK_RST); //|SLC_TXLINK_RST); 32 | 33 | // Clear DMA int flags 34 | SET_PERI_REG_MASK(SLC_INT_CLR, 0xffffffff); 35 | CLEAR_PERI_REG_MASK(SLC_INT_CLR, 0xffffffff); 36 | 37 | // Enable and configure DMA 38 | CLEAR_PERI_REG_MASK(SLC_CONF0,(SLC_MODE< 6 | #include "../include/ws2812_gamma.h" 7 | 8 | // TODO : use pre-processor to map in/out gamma sections depending on WS2812_DITHER_NUM 9 | 10 | static const uint8_t gamma0[] = { 11 | 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12 | 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 13 | 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 14 | 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 15 | 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25, 16 | 26, 26, 27, 28, 28, 29, 30, 30, 31, 32, 32, 33, 34, 34, 35, 36, 17 | 37, 37, 38, 39, 40, 41, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 18 | 50, 51, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 19 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 20 | 82, 83, 84, 85, 86, 88, 89, 90, 91, 92, 94, 95, 96, 97, 98, 100, 21 | 101, 102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 119, 121, 22 | 122, 123, 125, 126, 128, 129, 130, 132, 133, 135, 136, 138, 139, 141, 142, 144, 23 | 145, 147, 148, 150, 151, 153, 154, 156, 157, 159, 161, 162, 164, 165, 167, 169, 24 | 170, 172, 173, 175, 177, 178, 180, 182, 183, 185, 187, 189, 190, 192, 194, 196, 25 | 197, 199, 201, 203, 204, 206, 208, 210, 212, 213, 215, 217, 219, 221, 223, 225, 26 | 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 255 }; 27 | 28 | static const uint8_t gamma1[] = { 29 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 30 | 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 31 | 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 32 | 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 33 | 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 34 | 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 32, 32, 33, 34, 35, 35, 35 | 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 36 | 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 37 | 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 38 | 81, 82, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 97, 98, 99, 39 | 100, 102, 103, 104, 105, 107, 108, 109, 111, 112, 113, 115, 116, 117, 119, 120, 40 | 121, 123, 124, 126, 127, 128, 130, 131, 133, 134, 136, 137, 139, 140, 142, 143, 41 | 145, 146, 148, 149, 151, 152, 154, 155, 157, 158, 160, 162, 163, 165, 166, 168, 42 | 170, 171, 173, 175, 176, 178, 180, 181, 183, 185, 186, 188, 190, 192, 193, 195, 43 | 197, 199, 200, 202, 204, 206, 207, 209, 211, 213, 215, 217, 218, 220, 222, 224, 44 | 226, 228, 230, 232, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 }; 45 | 46 | static const uint8_t gamma2[] = { 47 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 48 | 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 49 | 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 50 | 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 51 | 16, 17, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 24, 24, 25, 52 | 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 53 | 36, 37, 38, 39, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 54 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 55 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 56 | 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 96, 97, 98, 99, 57 | 101, 102, 103, 104, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 119, 120, 58 | 122, 123, 125, 126, 127, 129, 130, 132, 133, 134, 136, 137, 139, 140, 142, 143, 59 | 145, 146, 148, 149, 151, 152, 154, 156, 157, 159, 160, 162, 163, 165, 167, 168, 60 | 170, 172, 173, 175, 177, 178, 180, 182, 183, 185, 187, 188, 190, 192, 194, 195, 61 | 197, 199, 201, 202, 204, 206, 208, 210, 211, 213, 215, 217, 219, 221, 222, 224, 62 | 226, 228, 230, 232, 234, 236, 238, 240, 241, 243, 245, 247, 249, 251, 253, 255 }; 63 | 64 | static const uint8_t gamma3[] = { 65 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 66 | 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 67 | 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 68 | 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 69 | 16, 16, 17, 17, 18, 18, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 70 | 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 34, 35, 71 | 36, 37, 37, 38, 39, 40, 41, 41, 42, 43, 44, 45, 45, 46, 47, 48, 72 | 49, 50, 51, 52, 53, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 73 | 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, 74 | 81, 82, 83, 84, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 98, 99, 75 | 100, 101, 103, 104, 105, 107, 108, 109, 110, 112, 113, 114, 116, 117, 118, 120, 76 | 121, 123, 124, 125, 127, 128, 130, 131, 133, 134, 135, 137, 138, 140, 141, 143, 77 | 144, 146, 147, 149, 150, 152, 153, 155, 157, 158, 160, 161, 163, 165, 166, 168, 78 | 169, 171, 173, 174, 176, 178, 179, 181, 183, 184, 186, 188, 190, 191, 193, 195, 79 | 197, 198, 200, 202, 204, 205, 207, 209, 211, 213, 214, 216, 218, 220, 222, 224, 80 | 226, 228, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 }; 81 | 82 | static const uint8_t gamma4[] = { 83 | 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 84 | 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 85 | 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 86 | 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 87 | 16, 17, 17, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, 88 | 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 89 | 37, 37, 38, 39, 40, 40, 41, 42, 43, 44, 44, 45, 46, 47, 48, 49, 90 | 50, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 91 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 81, 92 | 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 95, 96, 97, 98, 100, 93 | 101, 102, 103, 105, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 119, 120, 94 | 122, 123, 125, 126, 127, 129, 130, 132, 133, 135, 136, 138, 139, 140, 142, 143, 95 | 145, 146, 148, 149, 151, 153, 154, 156, 157, 159, 160, 162, 164, 165, 167, 168, 96 | 170, 172, 173, 175, 177, 178, 180, 182, 183, 185, 187, 188, 190, 192, 194, 195, 97 | 197, 199, 201, 202, 204, 206, 208, 210, 211, 213, 215, 217, 219, 221, 223, 224, 98 | 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 245, 247, 249, 251, 253, 255 }; 99 | 100 | static const uint8_t gamma5[] = { 101 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 102 | 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 103 | 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 104 | 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15, 105 | 16, 16, 17, 17, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 106 | 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 32, 32, 33, 34, 35, 35, 107 | 36, 37, 38, 38, 39, 40, 41, 41, 42, 43, 44, 45, 46, 46, 47, 48, 108 | 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 109 | 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 110 | 81, 82, 83, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 111 | 100, 102, 103, 104, 105, 107, 108, 109, 111, 112, 113, 115, 116, 117, 119, 120, 112 | 121, 123, 124, 126, 127, 128, 130, 131, 133, 134, 136, 137, 138, 140, 141, 143, 113 | 144, 146, 147, 149, 151, 152, 154, 155, 157, 158, 160, 161, 163, 165, 166, 168, 114 | 170, 171, 173, 174, 176, 178, 179, 181, 183, 185, 186, 188, 190, 191, 193, 195, 115 | 197, 198, 200, 202, 204, 206, 207, 209, 211, 213, 215, 216, 218, 220, 222, 224, 116 | 226, 228, 230, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 }; 117 | 118 | static const uint8_t gamma6[] = { 119 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 120 | 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 121 | 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 122 | 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 16, 123 | 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 124 | 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 125 | 36, 37, 38, 39, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, 48, 126 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 58, 59, 60, 61, 62, 63, 127 | 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 128 | 81, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 96, 97, 98, 99, 129 | 101, 102, 103, 104, 106, 107, 108, 109, 111, 112, 113, 115, 116, 117, 119, 120, 130 | 122, 123, 124, 126, 127, 129, 130, 131, 133, 134, 136, 137, 139, 140, 142, 143, 131 | 145, 146, 148, 149, 151, 152, 154, 155, 157, 159, 160, 162, 163, 165, 167, 168, 132 | 170, 171, 173, 175, 176, 178, 180, 181, 183, 185, 186, 188, 190, 192, 193, 195, 133 | 197, 199, 200, 202, 204, 206, 208, 209, 211, 213, 215, 217, 219, 220, 222, 224, 134 | 226, 228, 230, 232, 234, 236, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 }; 135 | 136 | static const uint8_t gamma7[] = { 137 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 138 | 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 139 | 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 140 | 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 141 | 16, 16, 17, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 142 | 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 143 | 36, 37, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 45, 46, 47, 48, 144 | 49, 50, 51, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 145 | 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 146 | 81, 82, 83, 84, 86, 87, 88, 89, 90, 91, 93, 94, 95, 96, 98, 99, 147 | 100, 101, 103, 104, 105, 106, 108, 109, 110, 112, 113, 114, 116, 117, 118, 120, 148 | 121, 122, 124, 125, 127, 128, 130, 131, 132, 134, 135, 137, 138, 140, 141, 143, 149 | 144, 146, 147, 149, 150, 152, 153, 155, 156, 158, 160, 161, 163, 164, 166, 168, 150 | 169, 171, 173, 174, 176, 178, 179, 181, 183, 184, 186, 188, 189, 191, 193, 195, 151 | 196, 198, 200, 202, 203, 205, 207, 209, 211, 213, 214, 216, 218, 220, 222, 224, 152 | 226, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 }; 153 | 154 | 155 | const uint8_t *gamma_dither[WS2812_DITHER_NUM] = {gamma0,gamma1,gamma2,gamma3,gamma4,gamma5,gamma6,gamma7}; 156 | 157 | // end of file 158 | -------------------------------------------------------------------------------- /src/ws2812_i2s.cpp: -------------------------------------------------------------------------------- 1 | // ws2812_lib.cpp 2 | // 3 | // main library file / contains class implementation 4 | // 5 | // Need to give credits to Charles Lohr (https://github.com/cnlohr due 6 | // to his work on his software for driving ws2812 led-strips using 7 | // the i2s interface of the ESP8266. 8 | // 9 | // This inspired me to create an ESP8266 library for the Arduino IDE 10 | // I've added temporal dithering & gamma-correction 11 | // for a 'more natural' light intensity profile. 12 | // 13 | // No pin-definitions/mapings are required/possible as the library used the I2S 14 | // output-pin. This pin in it's turn is shared with GPIO3 & RXD0 15 | // 16 | 17 | #include 18 | #include 19 | #include "ws2812_i2s.h" 20 | #include "../include/ws2812_defs.h" 21 | #include "../include/ws2812_gamma.h" 22 | 23 | // include C-style header 24 | extern "C" 25 | { 26 | #include "../include/ws2812_dma.h" 27 | }; 28 | 29 | // class constructor 30 | WS2812::WS2812(void) 31 | { 32 | // empty for now 33 | } 34 | 35 | // class de-constructor 36 | WS2812::~WS2812(void) 37 | { 38 | // empty for now 39 | // TODO : should implement switching of DMA 40 | } 41 | 42 | // Init led-string / memory buffers etc. 43 | void WS2812::init(uint16_t _num_leds) 44 | { 45 | uint8_t i; 46 | uint16_t j; 47 | 48 | num_leds = _num_leds; 49 | 50 | // clear zero buffer 51 | for(j=0; j>4) & 0x0f ]; 164 | } 165 | } 166 | 167 | } 168 | 169 | // end of file 170 | -------------------------------------------------------------------------------- /src/ws2812_i2s.h: -------------------------------------------------------------------------------- 1 | // ws2812_lib.h 2 | 3 | #ifndef __WS2812_I2S_H__ 4 | #define __WS2812_I2S_H__ 5 | 6 | #include 7 | #include "../include/ws2812_defs.h" 8 | 9 | // include C-style header 10 | extern "C" 11 | { 12 | #include "../include/ws2812_dma.h" 13 | }; 14 | 15 | typedef struct 16 | { 17 | uint8_t G; // G,R,B order is determined by WS2812B 18 | uint8_t R; 19 | uint8_t B; 20 | } Pixel_t; 21 | 22 | 23 | class WS2812 24 | { 25 | public: 26 | WS2812(void); 27 | ~WS2812(void); 28 | void init(uint16_t num_leds); 29 | void show(Pixel_t *); 30 | 31 | private: 32 | uint16_t num_leds; 33 | uint32_t *i2s_pixels_buffer[WS2812_DITHER_NUM]; 34 | uint32_t i2s_zeros_buffer[NUM_I2S_ZERO_WORDS]; 35 | sdio_queue_t i2s_zeros_queue[WS2812_DITHER_NUM]; 36 | sdio_queue_t i2s_pixels_queue[WS2812_DITHER_NUM]; 37 | }; 38 | 39 | #endif 40 | 41 | // end of file 42 | --------------------------------------------------------------------------------