Skip to content

Commit fee49e2

Browse files
committed
led_strip extension module
this is to be used as a replacement example for the neopixel class handling Sad to say that this cannot be used because micropython's internal handling of the RMT conflicts with this extension modules. But it is here for example purposes.
1 parent 21a17d3 commit fee49e2

File tree

5 files changed

+871
-0
lines changed

5 files changed

+871
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
| Name | Bit 0 | Bit 0 | Bit 1 | Bit 1 | Reset | Color |
3+
| | Duration 1 | Duration 2 | Duration 1 | Duration 2 | Duration | Order |
4+
|:--------|:----------:|:----------:|:----------:|:----------:|:---------:|:-----:|
5+
| APA105 | 300 | -900 | 600 | -600 | -80000 | GRB |
6+
| APA109 | 300 | -900 | 600 | -600 | -80000 | GRB |
7+
| SK6805 | 300 | -900 | 600 | -600 | -80000 | GRB |
8+
| SK6812 | 300 | -900 | 600 | -600 | -80000 | GRB |
9+
| SK6818 | 300 | -900 | 600 | -600 | -80000 | GRB |
10+
| WS2813 | 300 | -300 | 750 | -300 | -300000 | GRB |
11+
| APA104 | 350 | -1360 | 1360 | -350 | -24000 | RGB |
12+
| SK6822 | 350 | -1360 | 1360 | -350 | -50000 | RGB |
13+
| WS2812 | 350 | -800 | 700 | -600 | -50000 | GRB |
14+
| WS2818A | 220 | -580 | 580 | -220 | -280000 | RGB |
15+
| WS2818B | 220 | -580 | 580 | -220 | -280000 | RGB |
16+
| WS2851 | 220 | -580 | 580 | -220 | -280000 | RGB |
17+
| WS2815B | 220 | -580 | 580 | -220 | -280000 | RGB |
18+
| WS2815 | 220 | -580 | 580 | -220 | -280000 | RGB |
19+
| WS2811 | 220 | -580 | 580 | -220 | -280000 | RGB |
20+
| WS2814 | 220 | -580 | 580 | -220 | -280000 | RGB |
21+
| WS2818 | 220 | -750 | 750 | -220 | -300000 | RGB |
22+
| WS2816A | 220 | -580 | 580 | -580 | -280000 | GRB |
23+
| WS2816B | 200 | -800 | 520 | -480 | -280000 | GRB |
24+
| WS2816C | 200 | -800 | 520 | -480 | -280000 | GRB |
25+
| WS2812B | 400 | -850 | 800 | -450 | -50000 | GRB |
26+
| SK6813 | 240 | -800 | 740 | -200 | -80000 | GRB |
27+
*/
28+
29+
#ifndef __LED_STRIP_H__
30+
#define __LED_STRIP_H__
31+
32+
#include "driver/rmt_tx.h"
33+
#include "led_strip_encoder.h"
34+
35+
#include "freertos/FreeRTOS.h"
36+
#include "freertos/task.h"
37+
#include "freertos/semphr.h"
38+
#include "freertos/idf_additions.h"
39+
40+
// micropython includes
41+
#include "py/obj.h"
42+
#include "py/runtime.h"
43+
#include "py/objarray.h"
44+
45+
typedef enum _led_strip_ic_t {
46+
CUSTOM = 0,
47+
48+
APA105 = 1,
49+
APA109 = 1,
50+
SK6805 = 1,
51+
SK6812 = 1,
52+
SK6818 = 1,
53+
54+
WS2813 = 2,
55+
APA104 = 3,
56+
SK6822 = 4,
57+
WS2812 = 5,
58+
59+
WS2818A = 6,
60+
WS2818B = 6,
61+
WS2851 = 6,
62+
WS2815B = 6,
63+
WS2815 = 6,
64+
WS2811 = 6,
65+
WS2814 = 6,
66+
67+
WS2818 = 7,
68+
WS2816A = 8,
69+
70+
WS2816B = 9,
71+
WS2816C = 9,
72+
73+
WS2812B = 10,
74+
SK6813 = 11,
75+
76+
} led_strip_ic_t;
77+
78+
typedef struct {
79+
SemaphoreHandle_t handle;
80+
StaticSemaphore_t buffer;
81+
} lock_t;
82+
83+
typedef struct _mp_led_strip_obj_t {
84+
mp_obj_base_t base;
85+
86+
mp_obj_t callback;
87+
88+
mp_obj_array_t **buffers;
89+
uint8_t buffer_count: 4;
90+
91+
mp_obj_array_t **buffers_in_queue;
92+
uint8_t queue_buffer_count: 4;
93+
94+
uint16_t num_pixels: 12;
95+
uint16_t is_init: 1;
96+
uint16_t bpp: 3;
97+
98+
rmt_encoder_handle_t encoder_handle;
99+
rmt_channel_handle_t channel_handle;
100+
led_strip_encoder_config_t encoder_config;
101+
rmt_tx_channel_config_t channel_config;
102+
lock_t tx_lock;
103+
lock_t task_lock;
104+
TaskHandle_t task_handle;
105+
106+
} mp_led_strip_obj_t;
107+
108+
extern const mp_obj_type_t mp_led_strip_type;
109+
110+
#endif
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#include <stdint.h>
9+
#include "driver/rmt_encoder.h"
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
typedef enum _led_strip_color_order_t {
16+
LED_STRIP_RGB,
17+
LED_STRIP_GRB,
18+
LED_STRIP_RGBW,
19+
LED_STRIP_GRBW
20+
} led_strip_color_order_t;
21+
22+
typedef enum _led_strip_byte_order_t {
23+
LED_STRIP_LSB,
24+
LED_STRIP_MSB
25+
} led_strip_byte_order_t;
26+
27+
28+
/**
29+
* @brief Type of led strip encoder configuration
30+
*/
31+
typedef struct {
32+
uint32_t resolution; /*!< Encoder resolution, in Hz */
33+
int32_t bit0_duration0;
34+
int32_t bit0_duration1;
35+
int32_t bit1_duration0;
36+
int32_t bit1_duration1;
37+
int32_t reset_duration;
38+
led_strip_color_order_t color_order;
39+
led_strip_byte_order_t byte_order;
40+
} led_strip_encoder_config_t;
41+
42+
/**
43+
* @brief Create RMT encoder for encoding LED strip pixels into RMT symbols
44+
*
45+
* @param[in] config Encoder configuration
46+
* @param[out] ret_encoder Returned encoder handle
47+
* @return
48+
* - ESP_ERR_INVALID_ARG for any invalid arguments
49+
* - ESP_ERR_NO_MEM out of memory when creating led strip encoder
50+
* - ESP_OK if creating encoder successfully
51+
*/
52+
esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder);
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif

0 commit comments

Comments
 (0)