adp.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. /**
  2. * \file
  3. *
  4. * \brief ADP service implementation
  5. *
  6. * Copyright (C) 2015 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. /*
  44. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  45. */
  46. #ifndef ADP_H_INCLUDED
  47. #define ADP_H_INCLUDED
  48. #include <compiler.h>
  49. /** Version of ADP implemented here */
  50. #define ADP_VERSION 1
  51. /** Start token for ADP data */
  52. #define ADP_TOKEN 0xFF
  53. /** Maximum number of streams from PC to target */
  54. #define ADP_MAX_INCOMMING_STREAMS 5
  55. /** Maximum number of streams from target to PC */
  56. #define ADP_MAX_OUTGOING_STREAMS 5
  57. /** Maximum number of bytes target can request from PC in one request */
  58. #define ADP_MAX_BYTE_REQUEST 20
  59. /** Length of ADP packet header: Token, Message ID, Data Length */
  60. #define ADP_LENGTH_PACKET_HEADER 4
  61. /** Maximum number of bytes in data part of ADP packet */
  62. #define ADP_MAX_PACKET_DATA_SIZE 254
  63. /** Maximum number of all bytes in ADP packet */
  64. #define ADP_MAX_PACKET_LENGTH (ADP_LENGTH_PACKET_HEADER + ADP_MAX_PACKET_DATA_SIZE)
  65. /** Key used to identify proper handshake message */
  66. #define ADP_HANDSHAKE_KEY {0x58, 0x99, 0xAB, 0xC9, 0x0F, 0xE2, 0xF7, 0xAA}
  67. /** ADP RGB color definitions. Other RGB values can be used as well */
  68. #define ADP_COLOR_WHITE 0xFF, 0xFF, 0xFF
  69. #define ADP_COLOR_BLACK 0x00, 0x00, 0x00
  70. #define ADP_COLOR_SILVER 0xC0, 0xC0, 0xC0
  71. #define ADP_COLOR_GRAY 0x80, 0x80, 0x80
  72. #define ADP_COLOR_MAROON 0x80, 0x00, 0x00
  73. #define ADP_COLOR_RED 0xFF, 0x00, 0x00
  74. #define ADP_COLOR_PURPLE 0x80, 0x00, 0x80
  75. #define ADP_COLOR_FUCHSIA 0xFF, 0x00, 0xFF
  76. #define ADP_COLOR_GREEN 0x00, 0x80, 0x00
  77. #define ADP_COLOR_LIME 0x00, 0xFF, 0x00
  78. #define ADP_COLOR_OLIVE 0x80, 0x80, 0x00
  79. #define ADP_COLOR_YELLOW 0xFF, 0xFF, 0x00
  80. #define ADP_COLOR_NAVY 0x00, 0x00, 0x80
  81. #define ADP_COLOR_BLUE 0x00, 0x00, 0xFF
  82. #define ADP_COLOR_TEAL 0x00, 0x80, 0x80
  83. #define ADP_COLOR_AQUA 0x00, 0xFF, 0xFF
  84. #define ADP_COLOR_ORANGE 0xFF, 0xA5, 0x00
  85. /** States in receive state machine */
  86. enum rx_state_e {
  87. /** We are idle, waiting for a new packet */
  88. RX_STATE_IDLE,
  89. /** Start symbol received, waiting for Message ID */
  90. RX_STATE_WAIT_MSG_ID,
  91. /** Message ID received, waiting for data length */
  92. RX_STATE_WAIT_LENGTH_LSB,
  93. /** Message ID received, waiting for data length */
  94. RX_STATE_WAIT_LENGTH_MSB,
  95. /** Length received; we are receiving packet data */
  96. RX_STATE_GET_DATA,
  97. /** Start symbol received */
  98. RX_STATE_GOT_SYMBOL,
  99. };
  100. /** Max length of labels */
  101. #define ADP_CONF_MAX_LABEL 20
  102. static inline void adp_set_color(uint8_t* struct_member, uint8_t c_red, uint8_t c_green, uint8_t c_blue)
  103. {
  104. struct_member[0] = c_red;
  105. struct_member[1] = c_green;
  106. struct_member[2] = c_blue;
  107. }
  108. #define adp_set_string(struct_member, string) \
  109. Assert(sizeof(struct_member)); \
  110. strncpy(struct_member, string, sizeof(struct_member)); \
  111. struct_member[sizeof(struct_member)-1] = '\0';
  112. /* MESSAGE FORMAT */
  113. SHORTENUM struct adp_msg_format {
  114. /* Start token for ADP data */
  115. uint8_t protocol_token;
  116. /* Describes what data is sent */
  117. uint8_t protocol_msg_id;
  118. /* Length of data packet */
  119. uint16_t data_length;
  120. /* Data packet for the message */
  121. uint8_t data[ADP_MAX_PACKET_DATA_SIZE];
  122. };
  123. /* MSG_REQ_HANDSHAKE */
  124. #define MSG_REQ_HANDSHAKE 0x00
  125. #define MSQ_REQ_HANDSHAKE_LEN 10
  126. enum adp_handshake_options {
  127. /* Use GPIO */
  128. ADP_HANDSHAKE_OPTIONS_GPIO,
  129. /* Lock configuration */
  130. ADP_HANDSHAKE_OPTIONS_LOCK,
  131. };
  132. SHORTENUM struct adp_msg_request_handshake {
  133. /* Version of protocol on target */
  134. uint8_t protocol_version;
  135. /* Is GPIO in use in this app?
  136. * Can user change configuration on PC side?
  137. */
  138. uint8_t options;
  139. /* Token used to verify ADP protocol */
  140. uint8_t key[8];
  141. };
  142. /* MSG_RES_HANDSHAKE */
  143. #define MSG_RES_HANDSHAKE 0x10
  144. enum adp_handshake_status {
  145. /* Handshake accepted */
  146. ADP_HANDSHAKE_ACCEPTED,
  147. /* Handshake rejected. Invalid protocol version */
  148. ADP_HANDSHAKE_REJECTED_PROTOCOL,
  149. /* Handshake rejected. Other reason */
  150. ADP_HANDSHAKE_REJECTED_OTHER,
  151. };
  152. SHORTENUM struct adp_msg_response_handshake {
  153. enum adp_handshake_status status;
  154. };
  155. enum adp_handshake_status adp_wait_for_handshake(void);
  156. /* MSG_REQ_STATUS */
  157. #define MSG_REQ_STATUS 0x02
  158. #define MSG_REQ_STATUS_LEN 0
  159. /* This message has no data */
  160. /* MSG_RES_STATUS */
  161. #define MSG_RES_STATUS 0x12
  162. enum adp_status_code {
  163. /* Invalid packet received */
  164. ADP_STATUS_INVALID_PACKET,
  165. /* Invalid configuration data received */
  166. ADP_STATUS_INVALID_CONFIGURATION,
  167. /* Data ready to be transmitted to target */
  168. ADP_STATUS_DATA_READY,
  169. /* Invalid stream request (req_data) */
  170. ADP_STATUS_INVALID_REQUEST,
  171. /* No data available on stream (req_data) */
  172. ADP_STATUS_NO_DATA,
  173. /* Request target software reset */
  174. ADP_STATUS_RESET,
  175. };
  176. SHORTENUM struct adp_msg_response_status {
  177. enum adp_status_code status;
  178. };
  179. enum adp_status_code adp_request_status(void);
  180. /* MSG_RES_DATA */
  181. #define MSG_RES_DATA 0x14
  182. #define MSG_RES_DATA_MAX_LEN (ADP_MAX_BYTE_REQUEST + 4)
  183. SHORTENUM struct adp_msg_response_data {
  184. /* ID of stream */
  185. uint8_t stream_id;
  186. /* Number of bytes in packet.
  187. * If the target has requested data from an unknown stream, or if stream
  188. * has no data to send, this field should be set to 0 and the appropriate
  189. * status flag should be set.
  190. */
  191. uint8_t bytes_sent;
  192. /* The data */
  193. uint8_t data[ADP_MAX_BYTE_REQUEST];
  194. };
  195. void adp_request_data(uint8_t stream_id, uint8_t bytes_to_send, struct adp_msg_response_data *response);
  196. #define MSG_RES_PACKET_DATA_MAX_LEN (ADP_MAX_BYTE_REQUEST + 2)
  197. SHORTENUM struct adp_msg_packet_data {
  198. uint16_t stream_id;
  199. uint8_t bytes_sent;
  200. uint8_t data[ADP_MAX_BYTE_REQUEST];
  201. };
  202. bool adp_receive_packet_data(uint8_t *receive_buf);
  203. /* MSG_CONF_STREAM */
  204. enum adp_stream_type {
  205. ADP_STREAM_EVENT,
  206. ADP_STREAM_STRING,
  207. ADP_STREAM_UINT_8,
  208. ADP_STREAM_INT_8,
  209. ADP_STREAM_UINT_16,
  210. ADP_STREAM_INT_16,
  211. ADP_STREAM_UINT_32,
  212. ADP_STREAM_INT_32,
  213. ADP_STREAM_XY_8,
  214. ADP_STREAM_XY_16,
  215. ADP_STREAM_XY_32,
  216. ADP_STREAM_BOOL,
  217. ADP_STREAM_FLOAT,
  218. };
  219. enum adp_stream_state {
  220. ADP_STREAM_OFF,
  221. ADP_STREAM_ON,
  222. };
  223. enum adp_stream_mode {
  224. /* Incoming (normal) */
  225. ADP_STREAM_IN,
  226. /* Incoming (single value) */
  227. ADP_STREAM_IN_SINGLE,
  228. /* Outgoing */
  229. ADP_STREAM_OUT,
  230. };
  231. #define MSG_CONF_ACK 0x30
  232. #define ADP_ACK_NOT_OK 0
  233. #define ADP_ACK_OK 1
  234. #define MSG_CONF_INFO 0x28
  235. #define MSG_CONF_INFO_LEN
  236. bool adp_configure_info(const char* title, const char* description);
  237. #define MSG_CONF_STREAM 0x20
  238. #define MSG_CONF_STREAM_LEN 5
  239. SHORTENUM struct adp_msg_configure_stream {
  240. /* ID of stream */
  241. uint16_t stream_id;
  242. /* Stream type */
  243. enum adp_stream_type type;
  244. /* Stream mode/direction */
  245. enum adp_stream_mode mode;
  246. /* Stream state */
  247. enum adp_stream_state state;
  248. };
  249. static inline void adp_configure_stream_get_defaults(struct adp_msg_configure_stream *const config)
  250. {
  251. Assert(config);
  252. config->stream_id = 0;
  253. config->type = ADP_STREAM_UINT_8;
  254. config->mode = ADP_STREAM_OUT;
  255. config->state = ADP_STREAM_ON;
  256. }
  257. bool adp_configure_stream(struct adp_msg_configure_stream *const config, const char* label);
  258. /* MSG_CONF_TOGGLE_STREAM */
  259. #define MSG_CONF_TOGGLE_STREAM 0x21
  260. #define MSG_CONF_TOGGLE_STREAM_LEN 3
  261. SHORTENUM struct adp_msg_toggle_stream {
  262. uint16_t stream_id;
  263. enum adp_stream_state state;
  264. };
  265. bool adp_toggle_stream(struct adp_msg_toggle_stream *const config);
  266. /* MSG_CONF_GRAPH */
  267. #define MSG_CONF_GRAPH 0x22
  268. #define MSG_CONF_GRAPH_LEN 23
  269. enum adp_graph_scale_mode {
  270. ADP_GRAPH_SCALE_OFF,
  271. ADP_GRAPH_SCALE_AUTO
  272. };
  273. enum adp_graph_scroll_mode {
  274. /* No scrolling */
  275. ADP_GRAPH_SCROLL_OFF,
  276. /* Stepping */
  277. ADP_GRAPH_SCROLL_STEP,
  278. /* Scroll */
  279. ADP_GRAPH_SCROLL_SCROLL,
  280. /* Circular/sweep */
  281. ADP_GRAPH_SCROLL_CIRCULAR
  282. };
  283. SHORTENUM struct adp_msg_configure_graph {
  284. /* ID of new graph */
  285. uint8_t graph_id;
  286. /* Range Xmin value */
  287. uint32_t x_min;
  288. /* Range Xmax value */
  289. uint32_t x_max;
  290. /* Xscale numerator */
  291. uint32_t x_scale_numerator;
  292. /* X range scale value. Set to 0 to enable auto range */
  293. uint32_t x_scale_denominator;
  294. /* Vertical scaling */
  295. enum adp_graph_scale_mode scale_mode;
  296. /* RGB background color */
  297. uint8_t background_color[3];
  298. /* Horizontal scrolling */
  299. enum adp_graph_scroll_mode scroll_mode;
  300. };
  301. static inline void adp_configure_graph_get_defaults(struct adp_msg_configure_graph *const config)
  302. {
  303. Assert(config);
  304. config->graph_id = 0;
  305. config->x_min = 0;
  306. config->x_max = 0;
  307. config->x_scale_numerator = 0;
  308. config->x_scale_denominator = 0;
  309. config->scale_mode = ADP_GRAPH_SCALE_OFF;
  310. adp_set_color(config->background_color, ADP_COLOR_WHITE);
  311. config->scroll_mode = ADP_GRAPH_SCROLL_SCROLL;
  312. }
  313. bool adp_configure_graph(struct adp_msg_configure_graph *const config, \
  314. const char* graph_label, const char* x_label);
  315. /* MSG_CONF_AXIS */
  316. #define MSG_CONF_AXIS 0x29
  317. #define MSG_CONF_AXIS_LEN 24
  318. SHORTENUM struct adp_msg_conf_axis {
  319. /* ID of new axis */
  320. uint16_t axis_id;
  321. /* ID of graph */
  322. uint16_t graph_id;
  323. /* Range Ymin value */
  324. int32_t y_min;
  325. /* Range Ymax value */
  326. int32_t y_max;
  327. /* X range scale value. Set to 0 to enable auto range */
  328. uint32_t x_scale_numerator;
  329. /* X range scale value. Set to 0 to enable auto range */
  330. uint32_t x_scale_denominator;
  331. /* Mode */
  332. uint8_t mode; // TODO
  333. /* RGB color */
  334. uint8_t color[3];
  335. };
  336. static inline void adp_add_axis_to_graph_get_defaults(struct adp_msg_conf_axis *const config)
  337. {
  338. Assert(config);
  339. config->axis_id = 0;
  340. config->graph_id = 0;
  341. config->y_min = 0;
  342. config->y_max = 0;
  343. config->x_scale_numerator = 0;
  344. config->x_scale_denominator = 0;
  345. config->mode = 0;
  346. adp_set_color(config->color, ADP_COLOR_BLACK);
  347. }
  348. bool adp_add_axis_to_graph(struct adp_msg_conf_axis *const config, const char* label);
  349. /* MSG_CONF_ADD_STREAM_TO_GRAPH */
  350. #define MSG_CONF_ADD_STREAM_TO_AXIS 0x23
  351. #define MSG_CONF_ADD_STREAM_TO_AXIS_LEN 32
  352. #define ADP_AXIS_LINE_bm 0x01
  353. #define ADP_AXIS_POINTS_bm 0x02
  354. SHORTENUM struct adp_msg_add_stream_to_axis {
  355. /* ID of graph */
  356. uint16_t graph_id;
  357. /* ID of new axis */
  358. uint16_t axis_id;
  359. /* ID of stream */
  360. uint16_t stream_id;
  361. /* Sample rate of stream, set to 0 if NA */
  362. uint32_t sample_rate_numerator;
  363. /* Sample rate of stream, set to 0 if NA */
  364. uint32_t sample_rate_denominator;
  365. /* Range Ymin value */
  366. uint32_t y_scale_numerator;
  367. /* Range Ymax value */
  368. uint32_t y_scale_denominator;
  369. /* Offset of values */
  370. uint32_t y_offset;
  371. /* Adjust the transparency */
  372. uint8_t transparency;
  373. /* For graphs: bit 0 = line on/off
  374. * bit 1 = points on/off
  375. * For text: bit 0 = flag
  376. * bit 1 = text
  377. */
  378. uint8_t mode; // TODO
  379. /* Thickness of line */
  380. uint8_t line_thickness;
  381. /* RGB color of line */
  382. uint8_t line_color[3];
  383. };
  384. static inline void adp_add_stream_to_axis_get_defaults(struct adp_msg_add_stream_to_axis *const config)
  385. {
  386. Assert(config);
  387. config->graph_id = 0;
  388. config->axis_id = 0;
  389. config->stream_id = 0;
  390. config->sample_rate_numerator = 0;
  391. config->sample_rate_denominator = 0;
  392. config->y_scale_numerator = 0;
  393. config->y_scale_denominator = 0;
  394. config->y_offset = 0;
  395. config->transparency = 0;
  396. config->mode = ADP_AXIS_LINE_bm;
  397. config->line_thickness = 1;
  398. adp_set_color(config->line_color, ADP_COLOR_BLACK);
  399. }
  400. bool adp_add_stream_to_axis(struct adp_msg_add_stream_to_axis *const config);
  401. /* MSG_CONF_CURSOR_TO_GRAPH */
  402. #define MSG_CONF_CURSOR_TO_GRAPH 0x24
  403. #define MSG_CONF_CURSOR_TO_GRAPH_LEN 35
  404. SHORTENUM struct adp_msg_add_cursor_to_graph {
  405. /* ID of streama */
  406. uint16_t stream_id;
  407. /* ID of graph */
  408. uint16_t graph_id;
  409. /* ID of axis */
  410. uint16_t axis_id;
  411. /* Thickness of line */
  412. uint8_t thickness;
  413. /* RGB color of cursor */
  414. uint8_t color[3];
  415. /* Starting point of cursor */
  416. uint32_t initial_value;
  417. /* Minimum allowed value */
  418. uint32_t minimum_value;
  419. /* Maximum */
  420. uint32_t maximum_value;
  421. /* Numerator of scaling value */
  422. uint32_t scale_numerator;
  423. /* Denominator of scaling value */
  424. uint32_t scale_denominator;
  425. /* Offset of value */
  426. uint32_t scale_offset;
  427. /* The style of line: Solid, dashed, dotted.. */
  428. uint8_t line_style; // TODO
  429. };
  430. static inline void adp_add_cursor_to_graph_get_defaults(struct adp_msg_add_cursor_to_graph *const config)
  431. {
  432. Assert(config);
  433. config->stream_id = 0;
  434. config->graph_id = 0;
  435. config->axis_id = 0;
  436. config->thickness = 1;
  437. adp_set_color(config->color, ADP_COLOR_WHITE);
  438. config->initial_value = 0;
  439. config->minimum_value = 0;
  440. config->maximum_value = 0;
  441. config->scale_numerator = 0;
  442. config->scale_denominator = 0;
  443. config->scale_offset = 0;
  444. config->line_style = 0;
  445. }
  446. bool adp_add_cursor_to_graph(struct adp_msg_add_cursor_to_graph *const config, const char* label);
  447. /* MSG_CONF_GPIO_TO_GRAPH */
  448. #define MSG_CONF_GPIO_TO_GRAPH 0x25
  449. #define MSG_CONF_GPIO_TO_GRAPH_LEN 15
  450. SHORTENUM struct adp_msg_conf_gpio_to_graph {
  451. /* ID of graph */
  452. uint16_t graph_id;
  453. /* GPIO number to add to graph. Bit 0: GPIO0. bit 1: GPIO1 etc. */
  454. uint8_t gpio_number;
  455. /* Used to group graphs and cursors to the same scale */
  456. uint8_t group_id;
  457. /* Adjust the transparency */
  458. uint8_t transparency;
  459. /* Mode */
  460. uint16_t mode; // TODO
  461. /* Thickness of line */
  462. uint8_t line_thickness;
  463. /* RGB color of line when GPIO pin is high */
  464. uint8_t line_color_high_state[3];
  465. /* RGB color of line when GPIO pin is low */
  466. uint8_t line_color_low_state[3];
  467. /* The style of line */
  468. uint8_t line_style;
  469. };
  470. static inline void adp_gpio_to_graph_get_defaults(struct adp_msg_conf_gpio_to_graph *const config)
  471. {
  472. Assert(config);
  473. config->graph_id = 0;
  474. config->gpio_number = 0;
  475. config->group_id = 0;
  476. config->transparency = 0;
  477. config->mode = 0;
  478. config->line_thickness = 1;
  479. adp_set_color(config->line_color_high_state, ADP_COLOR_WHITE);
  480. adp_set_color(config->line_color_low_state, ADP_COLOR_WHITE);
  481. config->line_style = 0;
  482. }
  483. bool adp_add_gpio_to_graph(struct adp_msg_conf_gpio_to_graph *const config, \
  484. const char* tag_high_state, const char* tag_low_state);
  485. /* MSG_CONF_TERMINAL */
  486. #define MSG_CONF_TERMINAL 0x26
  487. #define MSG_CONF_TERMINAL_LEN 10
  488. SHORTENUM struct adp_msg_conf_terminal {
  489. /* ID of terminal */
  490. uint16_t terminal_id;
  491. /* Number of characters wide */
  492. uint8_t width;
  493. /* Number of characters high */
  494. uint8_t height;
  495. /* RGB background color */
  496. uint8_t background_color[3];
  497. /* RGB background color */
  498. uint8_t foreground_color[3];
  499. };
  500. static inline void adp_configure_terminal_get_defaults(struct adp_msg_conf_terminal *const config)
  501. {
  502. Assert(config);
  503. config->terminal_id = 0;
  504. config->width = 80;
  505. config->height = 25;
  506. adp_set_color(config->background_color, ADP_COLOR_WHITE);
  507. adp_set_color(config->foreground_color, ADP_COLOR_BLACK);
  508. }
  509. bool adp_configure_terminal(struct adp_msg_conf_terminal *const config, const char* label);
  510. /* MSG_CONF_ADD_TO_TERMINAL */
  511. #define MSG_CONF_ADD_TO_TERMINAL 0x27
  512. #define MSG_CONF_ADD_TO_TERMINAL_LEN 11
  513. SHORTENUM struct adp_msg_add_stream_to_terminal {
  514. /* ID of Terminal */
  515. uint16_t terminal_id;
  516. /* ID of stream */
  517. uint16_t stream_id;
  518. /* 0bx x x N T S F F
  519. * N = implicit newline in incoming text
  520. * T = enable tag
  521. * S = timestamped
  522. * F = format (Hex, decimal, binary, ascii)
  523. */
  524. uint8_t mode; // TODO
  525. /* RGB color of the text stream received */
  526. uint8_t text_color[3];
  527. /* RGB color of the tag text */
  528. uint8_t tag_text_color[3];
  529. };
  530. static inline void adp_add_stream_to_terminal_get_defaults(struct adp_msg_add_stream_to_terminal *const config)
  531. {
  532. Assert(config);
  533. config->terminal_id = 0;
  534. config->stream_id = 0;
  535. config->mode = 0;
  536. adp_set_color(config->text_color, ADP_COLOR_BLACK);
  537. adp_set_color(config->tag_text_color, ADP_COLOR_BLACK);
  538. }
  539. bool adp_add_stream_to_terminal(struct adp_msg_add_stream_to_terminal *const config, const char* tag_text);
  540. /* MSG_CONF_DASHBOARD */
  541. #define MSG_CONF_DASHBOARD 0x2A
  542. #define MSG_CONF_DASHBOARD_LEN 7
  543. SHORTENUM struct adp_msg_conf_dashboard {
  544. uint16_t dashboard_id;
  545. uint8_t color[3];
  546. uint16_t height;
  547. };
  548. static inline void adp_conf_dashboard_get_defaults(struct adp_msg_conf_dashboard *const config)
  549. {
  550. Assert(config);
  551. config->dashboard_id = 0;
  552. adp_set_color(config->color, ADP_COLOR_BLACK);
  553. config->height = 100;
  554. }
  555. bool adp_add_dashboard(struct adp_msg_conf_dashboard *const config, const char* label);
  556. /* MSG_CONF_DASHBOARD_ELEMENT */
  557. #define MSG_CONF_DASHBOARD_ELEMENT 0x2B
  558. enum adp_dashboard_element_type {
  559. ADP_ELEMENT_TYPE_LABEL,
  560. ADP_ELEMENT_TYPE_BUTTON,
  561. ADP_ELEMENT_TYPE_SLIDER,
  562. ADP_ELEMENT_TYPE_PROGRESS,
  563. ADP_ELEMENT_TYPE_SIGNAL,
  564. ADP_ELEMENT_TYPE_SEGMENT,
  565. ADP_ELEMENT_TYPE_GRAPH,
  566. ADP_ELEMENT_TYPE_TEXT,
  567. ADP_ELEMENT_TYPE_RADIO,
  568. ADP_ELEMENT_TYPE_PIE,
  569. };
  570. #define MSG_CONF_DASHBOARD_COMMON_LEN 14
  571. #define ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS \
  572. uint16_t dashboard_id; \
  573. uint16_t element_id; \
  574. uint8_t z_index; \
  575. uint16_t x; \
  576. uint16_t y; \
  577. uint16_t width; \
  578. uint16_t height; \
  579. enum adp_dashboard_element_type element_type
  580. SHORTENUM struct adp_msg_conf_dashboard_element_common {
  581. /* Dashboard ID */
  582. uint16_t dashboard_id;
  583. /* Unique ID of element */
  584. uint16_t element_id;
  585. /* Order index */
  586. uint8_t z_index;
  587. /* X-coordinate of element location. 0 is leftmost position on dashboard */
  588. uint16_t x;
  589. /* Y-coordinate of element location. 0 is topmost position on dashboard */
  590. uint16_t y;
  591. /* Width of element */
  592. uint16_t width;
  593. /* Height of element */
  594. uint16_t height;
  595. /* See each element type below */
  596. enum adp_dashboard_element_type element_type;
  597. };
  598. static inline void adp_conf_dashboard_element_get_defaults(struct adp_msg_conf_dashboard_element_common *const config)
  599. {
  600. Assert(config);
  601. config->dashboard_id = 0;
  602. config->element_id = 0;
  603. config->z_index = 0;
  604. config->x = 0;
  605. config->y = 0;
  606. config->width = 0;
  607. config->height = 0;
  608. }
  609. enum adp_label_attribute_alignment {
  610. BOLD_OFF_ITALIC_OFF,
  611. BOLD_ON_ITALIC_OFF,
  612. BOLD_OFF_ITALIC_ON,
  613. BOLD_ON_ITALIC_ON,
  614. };
  615. enum adp_label_horisontal_alignment {
  616. HORISONTAL_ALIGNMENT_LEFT,
  617. HORISONTAL_ALIGNMENT_CENTER,
  618. HORISONTAL_ALIGNMENT_RIGHT,
  619. };
  620. enum adp_label_vertical_alignment {
  621. VERTICAL_ALIGNMENT_TOP,
  622. VERTICAL_ALIGNMENT_CENTER,
  623. VERTICAL_ALIGNMENT_BOTTOM,
  624. };
  625. #define ADP_ELEMENT_TYPE_LABEL_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 12)
  626. SHORTENUM struct adp_msg_conf_dashboard_element_label {
  627. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  628. uint8_t font_size;
  629. uint8_t attribute; // TODO
  630. enum adp_label_horisontal_alignment horisontal_alignment;
  631. enum adp_label_vertical_alignment vertical_alignment;
  632. uint8_t background_transparency;
  633. uint8_t background_color[3];
  634. uint8_t foreground_transparency;
  635. uint8_t foreground_color[3];
  636. };
  637. static inline void adp_conf_dashboard_label_get_defaults(struct adp_msg_conf_dashboard_element_label *const config)
  638. {
  639. adp_conf_dashboard_element_get_defaults((struct adp_msg_conf_dashboard_element_common*)config);
  640. config->element_type = ADP_ELEMENT_TYPE_LABEL;
  641. config->font_size = 10;
  642. config->attribute = 0;
  643. config->horisontal_alignment = HORISONTAL_ALIGNMENT_LEFT;
  644. config->vertical_alignment = VERTICAL_ALIGNMENT_CENTER;
  645. config->background_transparency = 0;
  646. adp_set_color(config->background_color, ADP_COLOR_BLACK);
  647. config->foreground_transparency = 0;
  648. adp_set_color(config->foreground_color, ADP_COLOR_BLACK);
  649. }
  650. bool adp_add_label_to_dashboard(struct adp_msg_conf_dashboard_element_label *const config, const char* label);
  651. #define ADP_ELEMENT_TYPE_BUTTON_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 1)
  652. SHORTENUM struct adp_msg_conf_dashboard_element_button {
  653. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  654. uint8_t font_size;
  655. };
  656. static inline void adp_conf_dashboard_button_get_defaults(struct adp_msg_conf_dashboard_element_button *const config)
  657. {
  658. adp_conf_dashboard_element_get_defaults((struct adp_msg_conf_dashboard_element_common*)config);
  659. config->element_type = ADP_ELEMENT_TYPE_BUTTON;
  660. config->font_size = 10;
  661. }
  662. bool adp_add_button_to_dashboard(struct adp_msg_conf_dashboard_element_button *const config, const char* label);
  663. #define ADP_ELEMENT_TYPE_SLIDER_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 12)
  664. SHORTENUM struct adp_msg_conf_dashboard_element_slider {
  665. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  666. uint32_t minimum_value;
  667. uint32_t maximum_value;
  668. uint32_t initial_value;
  669. };
  670. static inline void adp_conf_dashboard_slider_get_defaults(struct adp_msg_conf_dashboard_element_slider *const config)
  671. {
  672. adp_conf_dashboard_element_get_defaults((struct adp_msg_conf_dashboard_element_common*)config);
  673. config->element_type = ADP_ELEMENT_TYPE_SLIDER;
  674. config->minimum_value = 0;
  675. config->maximum_value = 100;
  676. config->initial_value = 0;
  677. }
  678. bool adp_add_slider_to_dashboard(struct adp_msg_conf_dashboard_element_slider *const config);
  679. #define ADP_ELEMENT_TYPE_SIGNAL_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 8)
  680. SHORTENUM struct adp_msg_conf_dashboard_element_signal {
  681. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  682. uint8_t on_transparency;
  683. uint8_t on_color[3];
  684. uint8_t off_transparency;
  685. uint8_t off_color[3];
  686. };
  687. static inline void adp_conf_dashboard_signal_get_defaults(struct adp_msg_conf_dashboard_element_signal *const config)
  688. {
  689. adp_conf_dashboard_element_get_defaults((struct adp_msg_conf_dashboard_element_common*)config);
  690. config->element_type = ADP_ELEMENT_TYPE_SIGNAL;
  691. config->on_transparency = 0;
  692. adp_set_color(config->on_color, ADP_COLOR_WHITE);
  693. config->off_transparency = 0;
  694. adp_set_color(config->off_color, ADP_COLOR_BLACK);
  695. }
  696. bool adp_add_signal_to_dashboard(struct adp_msg_conf_dashboard_element_signal *const config);
  697. #define ADP_ELEMENT_TYPE_PROGRESS_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 15)
  698. SHORTENUM struct adp_msg_conf_dashboard_element_progress {
  699. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  700. uint32_t minimum_value;
  701. uint32_t maximum_value;
  702. uint32_t initial_value;
  703. uint8_t color[3];
  704. };
  705. static inline void adp_conf_dashboard_progress_get_defaults(struct adp_msg_conf_dashboard_element_progress *const config)
  706. {
  707. adp_conf_dashboard_element_get_defaults((struct adp_msg_conf_dashboard_element_common*)config);
  708. config->element_type = ADP_ELEMENT_TYPE_PROGRESS;
  709. config->minimum_value = 0;
  710. config->maximum_value = 100;
  711. config->initial_value = 0;
  712. adp_set_color(config->color, ADP_COLOR_BLACK);
  713. }
  714. bool adp_add_progress_to_dashboard(struct adp_msg_conf_dashboard_element_progress *const config);
  715. #define ADP_ELEMENT_TYPE_SEGMENT_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 6)
  716. SHORTENUM struct adp_msg_conf_dashboard_element_segment {
  717. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  718. /* Values: 1 ~ 20 */
  719. uint8_t segment_count;
  720. /* Values: 2 ~ 16*/
  721. uint8_t base;
  722. uint8_t transparency;
  723. uint8_t color[3];
  724. };
  725. static inline void adp_conf_dashboard_segment_get_defaults(struct adp_msg_conf_dashboard_element_segment *const config)
  726. {
  727. adp_conf_dashboard_element_get_defaults((struct adp_msg_conf_dashboard_element_common*)config);
  728. config->element_type = ADP_ELEMENT_TYPE_SEGMENT;
  729. config->segment_count = 1;
  730. config->base = 10;
  731. config->transparency = 0;
  732. adp_set_color(config->color, ADP_COLOR_BLACK);
  733. }
  734. bool adp_add_segment_to_dashboard(struct adp_msg_conf_dashboard_element_segment *const config);
  735. /* MSG_CONF_ADD_GRAPH_TO_ELEMENT */
  736. #define ADP_ELEMENT_TYPE_GRAPH_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 27)
  737. typedef union {
  738. struct {
  739. uint8_t mouse:1;
  740. uint8_t fit_graph:1;
  741. uint8_t :6;
  742. } bit;
  743. uint8_t reg;
  744. } mode_type;
  745. SHORTENUM struct adp_msg_conf_dashboard_element_graph {
  746. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  747. uint8_t title_color[3];
  748. uint8_t background_color[3];
  749. uint8_t graph_background_color[3];
  750. uint8_t plot_count;
  751. float x_min;
  752. float x_max;
  753. float y_min;
  754. float y_max;
  755. mode_type mode;
  756. };
  757. static inline void adp_conf_dashboard_graph_get_defaults(struct adp_msg_conf_dashboard_element_graph *const config)
  758. {
  759. adp_conf_dashboard_element_get_defaults((struct adp_msg_conf_dashboard_element_common*)config);
  760. config->element_type = ADP_ELEMENT_TYPE_GRAPH;
  761. adp_set_color(config->title_color, ADP_COLOR_WHITE);
  762. adp_set_color(config->background_color, ADP_COLOR_BLACK);
  763. adp_set_color(config->graph_background_color, ADP_COLOR_BLACK);
  764. config->plot_count = 1;
  765. config->x_min = 0;
  766. config->x_max = 10;
  767. config->y_min = 0;
  768. config->y_max = 5;
  769. config->mode.bit.fit_graph = 1;
  770. config->mode.bit.mouse = 0;
  771. }
  772. bool adp_add_graph_to_dashboard(struct adp_msg_conf_dashboard_element_graph *const config, const char* title);
  773. /* MSG_CONF_ADD_TEXT_TO_ELEMENT */
  774. #define ADP_ELEMENT_TYPE_TEXT_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 12)
  775. SHORTENUM struct adp_msg_conf_dashboard_element_text {
  776. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  777. uint8_t minimum[4];
  778. uint8_t maximum[4];
  779. uint8_t value[4];
  780. };
  781. bool adp_add_text_to_dashboard(struct adp_msg_conf_dashboard_element_text *const config);
  782. /* MSG_CONF_ADD_RADIO_TO_ELEMENT */
  783. #define ADP_ELEMENT_TYPE_RADIO_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 3)
  784. enum adp_radio_orientation {
  785. HORIZONTAL,
  786. VERTICAL,
  787. };
  788. SHORTENUM struct adp_msg_conf_dashboard_element_radio {
  789. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  790. uint8_t font_size;
  791. uint8_t number_items;
  792. enum adp_radio_orientation orientation;
  793. };
  794. bool adp_add_radio_to_dashboard(struct adp_msg_conf_dashboard_element_radio *const config, const char* text);
  795. /* MSG_CONF_ADD_PIE_TO_ELEMENT */
  796. #define ADP_ELEMENT_TYPE_PIE_LEN (MSG_CONF_DASHBOARD_COMMON_LEN + 7)
  797. SHORTENUM struct adp_msg_conf_dashboard_element_pie {
  798. ADP_DASHBOARD_ELEMENT_COMMON_MEMBERS;
  799. uint8_t background_color[3];
  800. uint8_t title_color[3];
  801. uint8_t number_slices;
  802. };
  803. bool adp_add_pie_to_dashboard(struct adp_msg_conf_dashboard_element_pie *const config, const char* title);
  804. /* MSG_CONF_ADD_STREAM_TO_ELEMENT */
  805. #define MSG_CONF_ADD_STREAM_TO_ELEMENT 0x2C
  806. #define MSG_CONF_ADD_STREAM_TO_ELEMENT_LEN 6
  807. SHORTENUM struct adp_conf_add_stream_to_element {
  808. uint16_t dashboard_id;
  809. uint16_t element_id;
  810. uint16_t stream_id;
  811. };
  812. bool adp_add_stream_to_element(struct adp_conf_add_stream_to_element *const config);
  813. /* MSG_DATA_STREAM */
  814. #define MSG_DATA_STREAM 0x40
  815. SHORTENUM struct adp_msg_data_stream_data {
  816. uint16_t stream_id;
  817. uint8_t data_size;
  818. uint8_t *data;
  819. };
  820. SHORTENUM struct adp_msg_data_stream {
  821. uint8_t number_of_streams;
  822. struct adp_msg_data_stream_data stream[ADP_MAX_OUTGOING_STREAMS];
  823. };
  824. bool adp_send_stream(struct adp_msg_data_stream *const stream_data, uint8_t* receive_buf);
  825. bool adp_send_single_stream(uint8_t stream_id, uint8_t* data, uint8_t data_size, uint8_t* receive_buf);
  826. bool adp_transceive_stream(struct adp_msg_data_stream *const stream_data, uint8_t *receive_buf);
  827. bool adp_transceive_single_stream(uint16_t stream_id, uint8_t* data, uint8_t data_size, uint8_t* receive_buf);
  828. /* Init SPI/TWI interface used. And some other misc init */
  829. void adp_init(void);
  830. uint16_t adp_add_send_byte(uint8_t* buffer, uint8_t index, uint8_t* data, uint16_t length);
  831. #endif