HAL Interface¶
Contents
#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_bit_numbering_t
¶ Endianness
-
HAL_LSB_FIRST
¶ Big-endian (most significant bit first)
-
HAL_MSB_FIRST
¶ Little-endian (least significant bit first)
-
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
- See also
-
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
- See also
-
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
viaeglib_GetI2c7bitSlaveAddr()
when needed.
-
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
viaeglib_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()
).
Parallel 8-bit 8080¶
-
hal_parallel_8_bit_8080_config_t
¶ Parallel 8-bit 8080 configuration.
- See also
- See also
-
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:
The HAL driver configuration (
eglib_GetHalConfig()
).The Display driver bus configuration:
4-Wire SPI: (
eglib_GetHalFourWireSpiConfigComm()
).I2C: (
eglib_GetHalI2cConfigComm()
).Parallel 8-bit 8080: (
eglib_GetHalParallel8bit8080ConfigComm()
).
-
void (*)(eglib_t *) sleep_in
Pointer to a function that puts the peripheral in sleep mode.
- See also
-
void (*)(eglib_t *) sleep_out
Pointer to a function that puts the peripheral out of sleep mode
- See also
-
void (*)(eglib_t *, uint32_t) delay_ns
Pointer to a function that delays for given amount of nanoseconds.
- See also
-
void (*)(eglib_t *, _Bool) set_reset
Pointer to a function that sets the reset pin to given
state
.- See also
-
_Bool (*)(eglib_t *) get_busy
Pointer to a function that gets the busy line state.
- See also
-
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
-
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:
4-Wire SPI: Set data or command line.
I2C: if
eglib_ShouldSendI2cSlaveAddr()
returns true then the slave address returned byeglib_GetI2c7bitSlaveAddr()
must be sent. Additionally,eglib_I2cSend()
must be used to send I2C data, so that the required encoding by each display is executed.
- Parameters
- See also
-
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
-
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()
andeglib_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
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()
.
-
eglib_SendData
(eglib, bytes, length)¶ Sends data.
- See also
-
eglib_SendDataByte
(eglib, bytes)¶ Sends a single data byte.
- See also
-
eglib_SendCommands
(eglib, bytes, length)¶ Sends commands.
- See also
-
eglib_SendCommandByte
(eglib, bytes)¶ Sends a single command byte.
- See also