Firmware
drv_oreoled.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2013 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
40 #pragma once
41 
42 #include <stdint.h>
43 #include <sys/ioctl.h>
44 
45 /* oreoled device path */
46 #define OREOLED0_DEVICE_PATH "/dev/oreoled0"
47 
48 /*
49  * ioctl() definitions
50  */
51 
52 #define _OREOLEDIOCBASE (0x2d00)
53 #define _OREOLEDIOC(_n) (_IOC(_OREOLEDIOCBASE, _n))
54 
56 #define OREOLED_SET_RGB _OREOLEDIOC(1)
57 
59 #define OREOLED_RUN_MACRO _OREOLEDIOC(2)
60 
62 #define OREOLED_SEND_BYTES _OREOLEDIOC(3)
63 
65 #define OREOLED_SEND_RESET _OREOLEDIOC(4)
66 
68 #define OREOLED_BL_PING _OREOLEDIOC(5)
69 
71 #define OREOLED_BL_VER _OREOLEDIOC(6)
72 
74 #define OREOLED_BL_FLASH _OREOLEDIOC(7)
75 
77 #define OREOLED_BL_APP_VER _OREOLEDIOC(8)
78 
80 #define OREOLED_BL_APP_CRC _OREOLEDIOC(9)
81 
83 #define OREOLED_BL_SET_COLOUR _OREOLEDIOC(10)
84 
86 #define OREOLED_BL_BOOT_APP _OREOLEDIOC(11)
87 
89 #define OREOLED_FORCE_SYNC _OREOLEDIOC(12)
90 
91 /* Oreo LED driver supports up to 4 leds */
92 #define OREOLED_NUM_LEDS 4
93 
94 /* instance of 0xff means apply to all instances */
95 #define OREOLED_ALL_INSTANCES 0xff
96 
97 /* maximum command length that can be sent to LEDs */
98 #define OREOLED_CMD_LENGTH_MAX 70
99 
100 /* maximum command length that can be read from LEDs */
101 #define OREOLED_CMD_READ_LENGTH_MAX 10
102 
103 /* maximum number of commands retries */
104 #define OEROLED_COMMAND_RETRIES 10
105 
106 /* magic number used to verify the software reset is valid */
107 #define OEROLED_RESET_NONCE 0x2A
108 
109 /* microseconds to hold-off between write and reads */
110 #define OREOLED_WRITE_READ_HOLDOFF_US 500
111 
112 /* microseconds to hold-off between retries */
113 #define OREOLED_RETRY_HOLDOFF_US 200
114 
115 #define OEROLED_BOOT_COMMAND_RETRIES 25
116 #define OREOLED_BOOT_FLASH_WAITMS 10
117 
118 #define OREOLED_BOOT_SUPPORTED_VER 0x01
119 
120 #define OREOLED_BOOT_CMD_PING 0x40
121 #define OREOLED_BOOT_CMD_BL_VER 0x41
122 #define OREOLED_BOOT_CMD_APP_VER 0x42
123 #define OREOLED_BOOT_CMD_APP_CRC 0x43
124 #define OREOLED_BOOT_CMD_SET_COLOUR 0x44
125 
126 #define OREOLED_BOOT_CMD_WRITE_FLASH_A 0x50
127 #define OREOLED_BOOT_CMD_WRITE_FLASH_B 0x51
128 #define OREOLED_BOOT_CMD_FINALISE_FLASH 0x55
129 
130 #define OREOLED_BOOT_CMD_BOOT_APP 0x60
131 
132 #define OREOLED_BOOT_CMD_PING_NONCE 0x2A
133 #define OREOLED_BOOT_CMD_BOOT_NONCE 0xA2
134 
135 #define OREOLED_FW_FILE_HEADER_LENGTH 2
136 #define OREOLED_FW_FILE_SIZE_LIMIT 6144
137 #define OREOLED_FW_FILE "/etc/firmware/oreoled.bin"
138 
139 /* enum passed to OREOLED_SET_MODE ioctl()
140  * defined by hardware */
141 enum oreoled_pattern {
142  OREOLED_PATTERN_OFF = 0,
143  OREOLED_PATTERN_SINE = 1,
144  OREOLED_PATTERN_SOLID = 2,
145  OREOLED_PATTERN_SIREN = 3,
146  OREOLED_PATTERN_STROBE = 4,
147  OREOLED_PATTERN_FADEIN = 5,
148  OREOLED_PATTERN_FADEOUT = 6,
149  OREOLED_PATTERN_PARAMUPDATE = 7,
150  OREOLED_PATTERN_ENUM_COUNT
151 };
152 
153 /* enum passed to OREOLED_SET_MODE ioctl()
154  * defined by hardware */
155 enum oreoled_param {
156  OREOLED_PARAM_BIAS_RED = 0,
157  OREOLED_PARAM_BIAS_GREEN = 1,
158  OREOLED_PARAM_BIAS_BLUE = 2,
159  OREOLED_PARAM_AMPLITUDE_RED = 3,
160  OREOLED_PARAM_AMPLITUDE_GREEN = 4,
161  OREOLED_PARAM_AMPLITUDE_BLUE = 5,
162  OREOLED_PARAM_PERIOD = 6,
163  OREOLED_PARAM_REPEAT = 7,
164  OREOLED_PARAM_PHASEOFFSET = 8,
165  OREOLED_PARAM_MACRO = 9,
166  OREOLED_PARAM_RESET = 10,
167  OREOLED_PARAM_APP_CHECKSUM = 11,
168  OREOLED_PARAM_ENUM_COUNT
169 };
170 
171 /* enum of available macros
172  * defined by hardware */
173 enum oreoled_macro {
174  OREOLED_PARAM_MACRO_RESET = 0,
175  OREOLED_PARAM_MACRO_COLOUR_CYCLE = 1,
176  OREOLED_PARAM_MACRO_BREATH = 2,
177  OREOLED_PARAM_MACRO_STROBE = 3,
178  OREOLED_PARAM_MACRO_FADEIN = 4,
179  OREOLED_PARAM_MACRO_FADEOUT = 5,
180  OREOLED_PARAM_MACRO_RED = 6,
181  OREOLED_PARAM_MACRO_GREEN = 7,
182  OREOLED_PARAM_MACRO_BLUE = 8,
183  OREOLED_PARAM_MACRO_YELLOW = 9,
184  OREOLED_PARAM_MACRO_WHITE = 10,
185  OREOLED_PARAM_MACRO_AUTOMOBILE = 11,
186  OREOLED_PARAM_MACRO_AVIATION = 12,
187  OREOLED_PARAM_MACRO_ENUM_COUNT
188 };
189 
190 /*
191  structure passed to OREOLED_SET_RGB ioctl()
192  Note that the driver scales the brightness to 0 to 255, regardless
193  of the hardware scaling
194  */
195 typedef struct {
196  uint8_t instance;
197  oreoled_pattern pattern;
198  uint8_t red;
199  uint8_t green;
200  uint8_t blue;
202 
203 /*
204  structure passed to OREOLED_RUN_MACRO ioctl()
205  */
206 typedef struct {
207  uint8_t instance;
208  oreoled_macro macro;
210 
211 /*
212  structure passed to send_bytes method (only used for testing)
213  */
214 typedef struct {
215  uint8_t led_num;
216  uint8_t num_bytes;
217  uint8_t buff[OREOLED_CMD_LENGTH_MAX];
218 } oreoled_cmd_t;
219 
Definition: drv_oreoled.h:214
Definition: drv_oreoled.h:206
Definition: drv_oreoled.h:195