NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ledstrip.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Copyright: collective.
5  * Cleanup: Martin Schröder <mkschreder.uk@gmail.com>
6  * Original source from Cleanflight.
7  *
8  * Ninjaflight is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Ninjaflight is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include "../common/color.h"
25 
26 #define LED_SPECIAL_COLOR_COUNT 8
27 #define LED_DIRECTION_COUNT 6
28 #define LED_MAX_STRIP_LENGTH 32
29 #define LED_CONFIGURABLE_COLOR_COUNT 16
30 #define LED_MODE_COUNT 6
31 #define LED_FUNCTION_COUNT 10
32 
33 #define LED_DIRECTION_BIT_OFFSET 0
34 #define LED_FUNCTION_BIT_OFFSET LED_DIRECTION_COUNT
35 
36 // These are used by configuration defaults
37 #define LED_X_BIT_OFFSET 4
38 #define LED_Y_BIT_OFFSET 0
39 #define LED_XY_MASK 0x0F
40 #define CALCULATE_LED_XY(x, y) ((((x) & LED_XY_MASK) << LED_X_BIT_OFFSET) | (((y) & LED_XY_MASK) << LED_Y_BIT_OFFSET))
41 
42 typedef enum {
51 
52 typedef enum {
62 
63 
64 // TODO: this should be named led_color_t or something
65 typedef enum {
80 } colorId_e;
81 
82 typedef enum {
90 
91 #define LED_FLAG_DIRECTION(directionId) (1 << (LED_DIRECTION_BIT_OFFSET + (directionId)))
92 // generate direction bit, used in initializers
93 #define LED_FLAG_DIRECTION_MASK (((1 << LED_DIRECTION_COUNT) - 1) << LED_DIRECTION_BIT_OFFSET)
94 
95 typedef enum {
107 
108 #define LED_FLAG_FUNCTION(functionId) (1 << (LED_FUNCTION_BIT_OFFSET + (functionId)))
109 // generate direction bit, used in initializers
110 #define LED_FLAG_FUNCTION_MASK (((1 << LED_FUNCTION_COUNT) - 1) << LED_FUNCTION_BIT_OFFSET)
111 
114 } __attribute__((packed)) ;
115 
118 } __attribute__((packed)) ;
119 
120 struct led_config {
121  uint8_t xy; // see LED_X/Y_MASK defines
122  uint8_t color; // see colors (config_master)
123  uint16_t flags; // see LED_FLAG_FUNCTION + LED_FLAG_DIRECTION
124 } __attribute__((packed)) ;
125 
131 } __attribute__((packed)) ;
132 
133 bool ledstrip_config_set_color(struct ledstrip_config *self, int index, const char *colorConfig);
Definition: ledstrip.h:47
Definition: ledstrip.h:67
uint16_t flags
Definition: ledstrip.h:123
Definition: ledstrip.h:44
uint8_t xy
Definition: ledstrip.h:121
Definition: ledstrip.h:98
Definition: ledstrip.h:43
Definition: ledstrip.h:71
Definition: ledstrip.h:96
Definition: ledstrip.h:126
struct led_spc_color_indices spcColors[1]
Definition: ledstrip.h:130
Definition: ledstrip.h:73
#define LED_MAX_STRIP_LENGTH
Definition: ledstrip.h:28
Definition: ledstrip.h:69
uint8_t color[LED_DIRECTION_COUNT]
Definition: ledstrip.h:117
Definition: ledstrip.h:84
Definition: ledstrip.h:45
Definition: ledstrip.h:60
struct led_mode_color_indices modeColors[LED_MODE_COUNT]
Definition: ledstrip.h:129
Definition: ledstrip.h:120
Definition: ledstrip.h:48
typedef __attribute__
Definition: ledstrip.h:76
Definition: ledstrip.h:68
Definition: ledstrip.h:101
Definition: ledstrip.h:70
Definition: ledstrip.h:59
Definition: ledstrip.h:46
ledSpecialColorIds_e
Definition: ledstrip.h:52
#define LED_SPECIAL_COLOR_COUNT
Definition: ledstrip.h:26
ledModeIndex_e
Definition: ledstrip.h:42
Definition: ledstrip.h:66
Definition: ledstrip.h:104
Definition: ledstrip.h:86
Definition: ledstrip.h:105
Definition: ledstrip.h:74
Definition: ledstrip.h:57
Definition: ledstrip.h:87
Definition: ledstrip.h:112
#define LED_DIRECTION_COUNT
Definition: ledstrip.h:27
uint8_t color[LED_SPECIAL_COLOR_COUNT]
Definition: ledstrip.h:113
Definition: ledstrip.h:54
Definition: ledstrip.h:103
Definition: ledstrip.h:72
Definition: ledstrip.h:97
#define LED_MODE_COUNT
Definition: ledstrip.h:30
#define LED_CONFIGURABLE_COLOR_COUNT
Definition: ledstrip.h:29
Definition: ledstrip.h:77
Definition: ledstrip.h:49
ledDirectionId_e
Definition: ledstrip.h:82
Definition: ledstrip.h:100
Definition: ledstrip.h:99
Definition: ledstrip.h:116
Definition: ledstrip.h:79
struct led_config leds[LED_MAX_STRIP_LENGTH]
Definition: ledstrip.h:127
bool ledstrip_config_set_color(struct ledstrip_config *self, int index, const char *colorConfig)
Definition: ledstrip.c:8
Definition: ledstrip.h:85
colorId_e
Definition: ledstrip.h:65
struct hsvColor_s colors[LED_CONFIGURABLE_COLOR_COUNT]
Definition: ledstrip.h:128
Definition: ledstrip.h:75
Definition: ledstrip.h:102
Definition: ledstrip.h:58
ledFunctionId_e
Definition: ledstrip.h:95
Definition: ledstrip.h:55
Definition: ledstrip.h:53
Definition: ledstrip.h:78
Definition: ledstrip.h:88
Definition: color.h:49
Definition: ledstrip.h:56
Definition: ledstrip.h:83
uint8_t color
Definition: ledstrip.h:122