HAL Interface

#include <eglib/hal.h>

HAL drivers implement hal_struct and can accept a configuration (eglib_GetHalConfig()), both which are passed to eglib_Init().

Types

enum hal_dc_t

Type of bytes transmitted

HAL_COMMAND

Command

HAL_DATA

Data

enum hal_bit_numbering_t

Endianness

HAL_LSB_FIRST

Big-endian (most significant bit first)

HAL_MSB_FIRST

Little-endian (least significant bit first)

enum hal_i2c_speed_t

I2C Speed.

See also

hal_i2c_config_t.

HAL_I2C_100KHZ

100kHz

HAL_I2C_400KHZ

400kHz

Display Configuration

These are configuration definitions required by the HAL driver hal_struct and that are provided by display the driver display_struct.

4-Wire SPI

hal_four_wire_spi_config_t

4-Wire SPI configuration.

See also

display_struct.

See also

eglib_GetHalFourWireSpiConfigComm().

uint8_t mode
SPI Mode:
  • 0: CPOL=0, CPHA=0

  • 1: CPOL=0, CPHA=1

  • 2: CPOL=1, CPHA=0

  • 3: CPOL=1, CPHA=1

enum hal_bit_numbering_t bit_numbering

Endianness

uint32_t cs_setup_ns

Delay after CS asserted

uint32_t cs_hold_ns

Delay before de-asserting CS

uint32_t cs_disable_ns

Delay after de-asserting CS

uint32_t dc_setup_ns

Delay before changing DC

uint32_t dc_hold_ns

Delay after changing DC

uint32_t sck_cycle_ns

SCK Period (1/frequency*10^9)

I2C

hal_i2c_config_t

I2C Configuration.

See also

display_struct.

See also

eglib_GetHalI2cConfigComm().

enum hal_i2c_speed_t speed

I2C Speed

uint8_t (*)(eglib_t *, enum hal_dc_t) get_7bit_slave_addr

Pointer to a function that returns the 7-bit slave address of the display.

Some displays have fixed addresses, others have addresses configurable depending on the state of its I/O pins and some have different addresses whether command or data is being sent.

This function delegates this definition to each display driver and is called by HAL drivers hal_struct via eglib_GetI2c7bitSlaveAddr() when needed.

Parameters
  • eglibeglib_t handle.

  • dc – Whether address command or data (hal_dc_t).

Returns

7-bit slave address.

See also

hal_dc_t.

void (*)(eglib_t *, void (*)(eglib_t *, uint8_t), enum hal_dc_t, uint8_t *, uint32_t) send

Pointer to a function that sends I2C bytes.

Each display driver has its own particular way of encoding bytes sent via I2C, depending on data or command being sent, number of bytes etc.

This function delegates this encoding to display drivers and is called by HAL drivers hal_struct via eglib_I2cSend() when needed.

Some examples of what may be required by a display:

  • First send a byte informing whether the following bytes are data or command.

  • Issue an I2C restart at the end of transmission (by calling eglib_CommBegin()).

Parameters
  • eglibeglib_t handle.

  • i2c_write – Pointer to a function that sends the passed byte via I2C.

  • dc – Whether bytes are command or data (hal_dc_t).

  • bytes – Pointer to an array of bytes to send.

  • length – Number of bytes to send.

Parallel 8-bit 8080

hal_parallel_8_bit_8080_config_t

Parallel 8-bit 8080 configuration.

See also

display_struct.

See also

eglib_GetHalParallel8bit8080ConfigComm().

uint32_t csx_setup_ns

Delay after CSX asserted.

uint32_t csx_hold_ns

Delay before de-asserting CSX.

uint32_t csx_disable_ns

Delay after de-asserting CSX.

uint32_t dcx_setup_ns

Delay after D/CX set.

uint32_t wrx_cycle_ns

Write cycle duration

uint32_t wrx_high_ns

Write cycle high duration.

uint32_t wrx_low_ns

Write cycle low duration.

HAL Driver

struct hal_struct

HAL driver definition.

Aliased as hal_t.

void (*)(eglib_t *) init

Pointer to a function that initializes the peripheral based on:

void (*)(eglib_t *) sleep_in

Pointer to a function that puts the peripheral in sleep mode.

See also

eglib_SleepIn().

void (*)(eglib_t *) sleep_out

Pointer to a function that puts the peripheral out of sleep mode

See also

eglib_SleepOut().

void (*)(eglib_t *, uint32_t) delay_ns

Pointer to a function that delays for given amount of nanoseconds.

See also

eglib_DelayNs().

void (*)(eglib_t *, _Bool) set_reset

Pointer to a function that sets the reset pin to given state.

See also

eglib_SetReset().

_Bool (*)(eglib_t *) get_busy

Pointer to a function that gets the busy line state.

See also

eglib_GetBusy().

void (*)(eglib_t *) comm_begin

Pointer to a function that begins communication. The meaning of this function varies depending on the bus:

  • 4-Wire SPI: asserts CS.

  • I2C: sends start condition.

  • When called more than one time before ending communication (eglib_CommEnd()) sends restart condition.

See also

eglib_CommBegin().

void (*)(eglib_t *, enum hal_dc_t, uint8_t *, uint32_t) send

Sends data. Depending on the bus, additional things must happen prior to sending the data:

Parameters
  • eglibeglib_t handle.

  • dc – Whether bytes are command or data (hal_dc_t).

  • bytes – Pointer to an array of bytes to send.

  • length – Number of bytes to send.

See also

eglib_Send().

void (*)(eglib_t *) comm_end

Ends communication. The meaning of this function varies depending on the bus:

  • 4-Wire SPI: de-asserts CS.

  • I2C: sends stop condition.

See also

eglib_CommEnd().

HAL Driver Helper Functions

The following functions can be used from HAL driver hal_struct functions.

eglib_GetHalConfig(eglib)

Returns a pointer to the HAL driver configuration that was passed to eglib_Init().

eglib_IsCommActive(eglib)

Whether in between calls to eglib_CommBegin() and eglib_CommEnd().

eglib_ShouldSendI2cSlaveAddr(eglib)

Whether I2C slave address should be sent.

Display driver HAL interface functions

The following functions can be used by display drivers display_struct to interface with HAL.

Delay

eglib_DelayNs(eglib, ns)

Delay for given number of nanoseconds

eglib_DelayUs(eglib, us)

Delay for given number of microseconds

eglib_DelayMs(eglib, ms)

Delay for given number of milliseconds

void eglib_DelayS(eglib_t * eglib, uint32_t s)

Delay for given number of seconds

I/O

eglib_SetReset(eglib, state)

Set reset line to given state.

eglib_GetBusy(eglib)

Get the value of th busy data line, often found in e-ink / e-paper displays.

Communication

void eglib_CommBegin(eglib_t * eglib)

Initiates communication. Must be called before eglib_Send().

void eglib_Send(eglib_t * eglib, enum hal_dc_t dc, uint8_t * bytes, uint32_t length)

Sends data. Must be called after eglib_CommBegin().

Parameters
  • eglibeglib_t handle.

  • dc – Whether bytes are command or data (hal_dc_t).

  • bytes – Pointer to an array of bytes to send.

  • length – Number of bytes to send.

eglib_SendData(eglib, bytes, length)

Sends data.

See also

eglib_Send().

eglib_SendDataByte(eglib, bytes)

Sends a single data byte.

See also

eglib_Send().

eglib_SendCommands(eglib, bytes, length)

Sends commands.

See also

eglib_Send().

eglib_SendCommandByte(eglib, bytes)

Sends a single command byte.

See also

eglib_Send().

void eglib_CommEnd(eglib_t * eglib)

Ends communication.