DGUS LCD Library  1
/github/workspace/dgus.h
Go to the documentation of this file.
1 #pragma once
9 #include "dgus_reg.h"
10 #include "dgus_util.h"
11 
12 
16 #define PACKET_OK -1
17 
21 #define ACK_MODE_OK_DISABLED 0
25 #define ACK_MODE_OK_WAIT 1
26 
27 
28 /* Callback for a packet received */
32 typedef void (*packet_handler_cb)(char *data, uint8_t cmd, uint8_t len, uint16_t addr, uint8_t bytelen);
33 
37 typedef char (*ser_recv_handler_cb)(void);
38 
42 typedef void (*ser_send_handler_cb)(char *data, size_t len);
43 
47 typedef uint8_t (*ser_available_handler_cb)(void);
48 
49 
53 typedef struct dgus_packet dgus_packet;
54 
67 
74 int dgus_recv_data();
75 
83 void buffer_u8(dgus_packet *p, uint8_t *data, size_t len);
84 
92 void buffer_u16(dgus_packet *p, uint16_t *data, size_t len);
93 
101 void buffer_u32(dgus_packet *p, uint32_t *data, size_t len);
102 
109 void buffer_u32_1(dgus_packet *p, uint32_t data);
110 
119 void dgus_packet_set_data(dgus_packet *p, uint8_t offset, uint8_t *data, uint8_t len);
120 
129 
130 /* Var commands */
131 /* Request the variable and immediately return.
132  * your own handler implementation should deal directly with the data
133  */
134 
142 DGUS_RETURN dgus_request_var(uint16_t addr, uint8_t len);
143 
152 DGUS_RETURN dgus_get_var(uint16_t addr, uint16_t *buf, uint8_t len);
153 
161 DGUS_RETURN dgus_set_var(uint16_t addr, uint32_t data);
162 
171 DGUS_RETURN dgus_get_var8(uint16_t addr, uint8_t *buf, uint8_t len);
172 
181 DGUS_RETURN dgus_set_var8(uint16_t addr, uint8_t *data, uint8_t len);
182 
189 
190 
191 
192 /* internal utility */
199 void dgus_packet_set_len(dgus_packet *p, uint16_t len);
200 
206 uint8_t *dgus_packet_get_recv_buffer();
207 
213 uint8_t _polling_wait();
214 
222 DGUS_RETURN _polling_read_16(uint8_t *buf, uint8_t len);
223 
233 DGUS_RETURN dgus_set_cmd(uint16_t addr, uint8_t *data, uint8_t len);
234 
243 DGUS_RETURN dgus_get_cmd(uint16_t addr, uint8_t *data, uint8_t len);
244 
245 #include "dgus_config.h"
void buffer_u8(dgus_packet *p, uint8_t *data, size_t len)
Append 1 byte len bytes to the send buffer in 8 bit format.
Definition: dgus_lcd.c:218
void dgus_init(ser_available_handler_cb avail, ser_recv_handler_cb recv, ser_send_handler_cb send, packet_handler_cb packet_handler)
Initialise the DGUS LCD interface.
Definition: dgus_lcd.c:72
void dgus_packet_set_len(dgus_packet *p, uint16_t len)
Override a packets current length.
Definition: dgus_lcd.c:355
DGUS_RETURN dgus_set_var(uint16_t addr, uint32_t data)
Set data variable into addr on the DGUS.
Definition: dgus_lcd.c:315
DGUS_RETURN _polling_read_16(uint8_t *buf, uint8_t len)
Poll and read a 16 bit return value.
Definition: dgus_lcd.c:363
char(* ser_recv_handler_cb)(void)
recv a single char from the usart
Definition: dgus.h:37
DGUS_RETURN dgus_set_var8(uint16_t addr, uint8_t *data, uint8_t len)
Set len 8 bit bytes to the device. no encoding is applied.
Definition: dgus_lcd.c:322
dgus_packet * dgus_packet_init()
Manually initialise the packet sending buffer.
Definition: dgus_lcd.c:255
DGUS_RETURN send_data(enum command cmd, dgus_packet *p)
actually send the packet p with write cmd
Definition: dgus_lcd.c:133
uint8_t(* ser_available_handler_cb)(void)
Emount of bytes of serial data is available to be read. For devices with abacking buffer such as ardu...
Definition: dgus.h:47
struct dgus_packet dgus_packet
Opaque reference to a packet.
Definition: dgus.h:53
void(* packet_handler_cb)(char *data, uint8_t cmd, uint8_t len, uint16_t addr, uint8_t bytelen)
Packet Parsing handler. When a valid packet is recieved, this callback is invoked.
Definition: dgus.h:32
DGUS_RETURN dgus_get_cmd(uint16_t addr, uint8_t *data, uint8_t len)
Get data from the cmd registers.
Definition: dgus_lcd.c:336
void buffer_u32(dgus_packet *p, uint32_t *data, size_t len)
Append 4 bytes len bytes to the send buffer in 2x word format.
Definition: dgus_lcd.c:234
void buffer_u32_1(dgus_packet *p, uint32_t data)
Append 4 bytes 1 long of data to the send buffer in 8 bit format.
Definition: dgus_lcd.c:243
DGUS_RETURN dgus_request_var(uint16_t addr, uint8_t len)
Async request a variable It is up to you to read the response.
Definition: dgus_lcd.c:266
DGUS_RETURN dgus_set_cmd(uint16_t addr, uint8_t *data, uint8_t len)
Set data in the cmd area of the configuration.
Definition: dgus_lcd.c:329
int dgus_recv_data()
Receive and process data from the serial port. Call this in your main loop.
Definition: dgus_lcd.c:154
uint8_t _polling_wait()
Wait for the OK to return or data to arrive.
Definition: dgus_lcd.c:118
DGUS_RETURN dgus_get_var8(uint16_t addr, uint8_t *buf, uint8_t len)
Get len 8 bit bytes from the device. no encoding is applied.
Definition: dgus_lcd.c:277
uint8_t * dgus_packet_get_recv_buffer()
Get a pointer the current data recv buffer.
Definition: dgus_lcd.c:359
DGUS_RETURN dgus_get_var(uint16_t addr, uint16_t *buf, uint8_t len)
Read len bytes into buf at address addr.
Definition: dgus_lcd.c:296
void(* ser_send_handler_cb)(char *data, size_t len)
Send Handler. On platforms such as Arduino, this would likely be SERIALx.write(p, sz)
Definition: dgus.h:42
void dgus_packet_set_data(dgus_packet *p, uint8_t offset, uint8_t *data, uint8_t len)
Write 8 bites of data at position n in the buffer.
Definition: dgus_lcd.c:262
void buffer_u16(dgus_packet *p, uint16_t *data, size_t len)
Append 2 bytes len bytes to the send buffer in 16 bit format.
Definition: dgus_lcd.c:224
DGUS II LCD Driver. Register and cointrol definitions.
#define DGUS_RETURN
Definition: dgus_reg.h:33
command
Addresses of the command and variables.
Definition: dgus_reg.h:25
DGUS II LCD Driver Utility functions.