DGUS LCD Library  1
/github/workspace/dgus.h File Reference

DGUS II LCD Driver. More...

#include "dgus_reg.h"
#include "dgus_util.h"
#include "dgus_config.h"
Include dependency graph for dgus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PACKET_OK   -1
 A "OK" ACK packet was received from dgus_packet_recv()
 
#define ACK_MODE_OK_DISABLED   0
 Set when the firmware does NOT have ACK (OK packets) enabled.
 
#define ACK_MODE_OK_WAIT   1
 Wait for OK packets on send.
 

Typedefs

typedef 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.
 
typedef char(* ser_recv_handler_cb) (void)
 recv a single char from the usart
 
typedef 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)
 
typedef 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 arduino, this maybe > 1. Most other devices will return byte by byte.
 
typedef struct dgus_packet dgus_packet
 Opaque reference to a packet.
 

Functions

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. More...
 
int dgus_recv_data ()
 Receive and process data from the serial port. Call this in your main loop. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
DGUS_RETURN send_data (enum command cmd, dgus_packet *p)
 actually send the packet p with write cmd More...
 
DGUS_RETURN dgus_request_var (uint16_t addr, uint8_t len)
 Async request a variable It is up to you to read the response. More...
 
DGUS_RETURN dgus_get_var (uint16_t addr, uint16_t *buf, uint8_t len)
 Read len bytes into buf at address addr. More...
 
DGUS_RETURN dgus_set_var (uint16_t addr, uint32_t data)
 Set data variable into addr on the DGUS. More...
 
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. More...
 
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. More...
 
dgus_packetdgus_packet_init ()
 Manually initialise the packet sending buffer. More...
 
void dgus_packet_set_len (dgus_packet *p, uint16_t len)
 Override a packets current length. More...
 
uint8_t * dgus_packet_get_recv_buffer ()
 Get a pointer the current data recv buffer. More...
 
uint8_t _polling_wait ()
 Wait for the OK to return or data to arrive. More...
 
DGUS_RETURN _polling_read_16 (uint8_t *buf, uint8_t len)
 Poll and read a 16 bit return value. More...
 
DGUS_RETURN dgus_set_cmd (uint16_t addr, uint8_t *data, uint8_t len)
 Set data in the cmd area of the configuration. More...
 
DGUS_RETURN dgus_get_cmd (uint16_t addr, uint8_t *data, uint8_t len)
 Get data from the cmd registers. More...
 

Detailed Description

DGUS II LCD Driver.

Author
Barry Carter
Date
01 Jan 2021

Function Documentation

◆ _polling_read_16()

DGUS_RETURN _polling_read_16 ( uint8_t *  buf,
uint8_t  len 
)

Poll and read a 16 bit return value.

Parameters
buf
len
Returns
Response such as DGUS_TIMEOUT

◆ _polling_wait()

uint8_t _polling_wait ( )

Wait for the OK to return or data to arrive.

Returns
uint8_t

◆ buffer_u16()

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.

Parameters
pdgus_packet packet
datadata to write
lenlength of data bytes to write

◆ buffer_u32()

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.

Parameters
pdgus_packet packet
datadata to write
lenlength of data bytes to write

◆ buffer_u32_1()

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.

Parameters
pdgus_packet packet
datadata to write

◆ buffer_u8()

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.

Parameters
pdgus_packet packet
datadata to write
lenlength of data bytes to write

◆ dgus_get_cmd()

DGUS_RETURN dgus_get_cmd ( uint16_t  addr,
uint8_t *  data,
uint8_t  len 
)

Get data from the cmd registers.

Parameters
addr
data
len
Returns
Response such as DGUS_TIMEOUT

◆ dgus_get_var()

DGUS_RETURN dgus_get_var ( uint16_t  addr,
uint16_t *  buf,
uint8_t  len 
)

Read len bytes into buf at address addr.

Parameters
addr
buf
len
Returns
Response such as DGUS_TIMEOUT

◆ dgus_get_var8()

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.

Parameters
addr
buf
len
Returns
Response such as DGUS_TIMEOUT

◆ dgus_init()

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.

Callbacks allow platform independance. On Arduino like platforms, avail would be "SerialPort.available()"

Parameters
availser_available_handler_cb callback for the amount of bytes available
recvfunction that receives bytes from the serial port
sendfunction that sends bytes over the serial port
packet_handlerfunction that should be called when the lcd has sent a packet to be processed

◆ dgus_packet_get_recv_buffer()

uint8_t* dgus_packet_get_recv_buffer ( )

Get a pointer the current data recv buffer.

Returns
uint8_t*

◆ dgus_packet_init()

dgus_packet* dgus_packet_init ( )

Manually initialise the packet sending buffer.

Returns
dgus_packet* Opaque pointer to the packet buffer

◆ dgus_packet_set_data()

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.

Parameters
pdgus_packet packet
offsetwhere in the buffer to write
datadata to write
lenlength of data bytes to write

◆ dgus_packet_set_len()

void dgus_packet_set_len ( dgus_packet p,
uint16_t  len 
)

Override a packets current length.

Parameters
p
len

◆ dgus_recv_data()

int dgus_recv_data ( )

Receive and process data from the serial port. Call this in your main loop.

Returns
int returns < 1 error, 0 for no data

◆ dgus_request_var()

DGUS_RETURN dgus_request_var ( uint16_t  addr,
uint8_t  len 
)

Async request a variable It is up to you to read the response.

Parameters
addrVAR Addres to read from
lennumber of bytes to read
Returns
Response such as DGUS_TIMEOUT

◆ dgus_set_cmd()

DGUS_RETURN dgus_set_cmd ( uint16_t  addr,
uint8_t *  data,
uint8_t  len 
)

Set data in the cmd area of the configuration.

Warning
writing here is super dangerous
Parameters
addr
data
len
Returns
Response such as DGUS_TIMEOUT

◆ dgus_set_var()

DGUS_RETURN dgus_set_var ( uint16_t  addr,
uint32_t  data 
)

Set data variable into addr on the DGUS.

Parameters
addraddress of the VAR data in word (u16) format
datadata to send
Returns
Response such as DGUS_TIMEOUT

◆ dgus_set_var8()

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.

Parameters
addr
data
len
Returns
Response such as DGUS_TIMEOUT

◆ send_data()

DGUS_RETURN send_data ( enum command  cmd,
dgus_packet p 
)

actually send the packet p with write cmd

Parameters
cmdcommand type such as DGUS_CMD_VAR_W
ppacket handle
Returns
Response such as DGUS_TIMEOUT