1 #pragma once
2 
3 #include <stdint.h>
4 
5 #define LUX_PACKET_MAX_SIZE 1024
6 
7 enum __attribute__((__packed__)) lux_command {
8     // -------------- General Lux Commands --------------
9 
10     // LUX_CMD_GET_ID: no index, no request payload, varlen data response
11     // - Request: Empty
12     // - Response: A string identifier of the node type, up to 32 characters
13     LUX_CMD_GET_ID = 0x00,
14 
15     // LUX_CMD_GET_DESCRIPTOR: index, no request payload, varlen data response
16     // - Request: Empty
17     // - Response: Index-based slice of the device descriptor buffer
18     LUX_CMD_GET_DESCRIPTOR = 0x01,
19 
20     // LUX_CMD_RESET: no index, 1-byte request payload, ack+crc response
21     // - Request: A single byte "flags". Default is 0x00
22     // - Response: ack+crc
23     // Reboot the node. Flags are node-defined (trigger bootloader, stay off, etc.)
24     LUX_CMD_RESET = 0x02,
25 
26     // -------------- Configuration commands --------------
27     // Any changes made to configuration must be committed to nonvolatile storage with LUX_CMD_COMMIT_CONFIG
28 
29     // LUX_CMD_COMMIT_CONFIG: no index, no request payload, ack+crc response
30     // - Request: Empty
31     // - Response: ack+crc
32     // Commit config changes to nonvolatile storage.
33     LUX_CMD_COMMIT_CONFIG = 0x10,
34 
35     // LUX_CMD_GET_ADDR: no index, no request payload, 72-byte data response
36     // - Request: Empty
37     // - Response: Address configuration, 72 bytes ( u32[1 + 1 + 16] )
38     // { mcast_addr, mcast_mask, unicast[16] }
39     LUX_CMD_GET_ADDR = 0x11,
40 
41     // LUX_CMD_SET_ADDR: no index, 72-byte request payload, ack+crc response
42     // - Request: Address configuration, 72 bytes ( u32[1 + 1 + 16] )
43     // - Response: ack+crc
44     LUX_CMD_SET_ADDR = 0x12,
45 
46     /*
47     LUX_CMD_GET_USERDATA,
48     LUX_CMD_SET_USERDATA,
49     */
50 
51     // LUX_CMD_GET_PKTCNT: no index, no request payload, 20-byte data response
52     // - Request: Empty
53     // - Response: Packet statistics. 20 bytes (u32[5])
54     // { good, malformed, overrun, bad_crc, rx_interrupted }
55     LUX_CMD_GET_PKTCNT = 0x13,
56 
57     // LUX_CMD_RESET_PKTCNT: no index, no request payload, ack+crc response
58     // - Request: Empty
59     // - Response: ack+crc
60     // Resets all packet counts to 0
61     LUX_CMD_RESET_PKTCNT = 0x14,
62 
63     // -------------- Bootloader-specific commands --------------
64 
65     // LUX_CMD_INVALIDATEAPP: no index, no request payload, ack+crc response
66     // - Request: Empty
67     // - Response: ack+crc
68     // Invalidate loaded app. Future resets will boot into bootloader until flashing is done
69     LUX_CMD_INVALIDATEAPP = 0x80,
70 
71     // LUX_CMD_FLASH_BASEADDR: no index, 4-byte request payload, ack+crc response
72     // - Request: Base address, 4 bytes , u32
73     // - Response: ack+crc
74     // Set base address for future FLASH_WRITE commands
75     LUX_CMD_FLASH_BASEADDR = 0x81,
76 
77     // LUX_CMD_FLASH_ERASE: no index, 4-byte request payload, ack+crc response
78     // - Request: Page address, 4 bytes, u32
79     // - Response: ack+crc
80     // Erase page at the given address. Pages must be erased before written to
81     LUX_CMD_FLASH_ERASE = 0x82,
82 
83     // LUX_CMD_FLASH_WRITE: index, varlen request payload, ack+crc response
84     // - Request: Data, to write to ($base_address + 1024 * $index)
85     // - Response: ack+crc
86     // Write data into flash. Page(s) must be erased before written to
87     LUX_CMD_FLASH_WRITE = 0x83,
88 
89     // LUX_CMD_FLASH_READ: no index, 6-byte request payload, varlen response
90     // - Request: Address & length to read from (u32 address, u16 length)
91     // - Response: $length bytes from address $address
92     // Read back data from flash for verification.
93     LUX_CMD_FLASH_READ = 0x84,
94 
95     // -------------- Strip-specific commands --------------
96 
97     // LUX_CMD_FRAME_SYNC[_ACK]: no index, no request payload, no/ack+crc response
98     // - Request: Empty
99     // - Response: None for LUX_CMD_FRAME_SYNC; ack+crc for CMD_FRAME_SYNC_ACK
100     // Flip buffer so frame previously loaded with LUX_CMD_FRAME_HOLD is output.
101     LUX_CMD_SYNC = 0x90,      //TODO
102     LUX_CMD_SYNC_ACK = 0x91,  //TODO
103 
104     // LUX_CMD_FRAME[_HOLD][_ACK]: index, varlen request payload, no/ack+crc response
105     // - Request: LED strip frame data
106     // - Response: None for LUX_CMD_FRAME[_HOLD]; ack+crc for CMD_FRAME[_HOLD]_ACK
107     // LUX_CMD_FRAME: Immediately output; CMD_FRAME_HOLD: store until CMD_FRAME_FLIP command
108     LUX_CMD_FRAME = 0x92,
109     LUX_CMD_FRAME_ACK = 0x93,
110     LUX_CMD_FRAME_HOLD = 0x94,      //TODO
111     LUX_CMD_FRAME_HOLD_ACK = 0x95,  //TODO
112 
113     // LUX_CMD_SET_LED: no index, 1-byte request payload, ack+crc response
114     // - Request: 0x01 for on, 0x00 for off. All other values reserved.
115     // - Response: ack+crc
116     // Status LED
117     LUX_CMD_SET_LED = 0x96,
118 
119     // LUX_CMD_GET_BUTTON_COUNT: no index, no request payload, 4 byte response
120     // - Request: Empty
121     // - Response: Number of times the button has been pushed since startup
122     LUX_CMD_GET_BUTTON_COUNT = 0x97, //TODO (currently "is button pressed?"
123 
124     // Configuration
125     // TODO: Move to descriptors
126     LUX_CMD_SET_LENGTH = 0x9C,
127     LUX_CMD_GET_LENGTH = 0x9D,
128 };
129 
130 // Response format from LUX_CMD_GET_PKTCNT
131 struct __attribute__((__packed__)) lux_stats_payload {
132     uint32_t good_packet;
133     uint32_t malformed_packet;
134     uint32_t packet_overrun;
135     uint32_t bad_checksum;
136     uint32_t rx_interrupted;
137     uint32_t bad_address;
138 };
139 
140