Software Reference Manual 9.2.2
Library for Pervasive Displays e-paper screens, extension boards and development kits
hV_HAL_Peripherals.h File Reference

Light hardware abstraction layer for peripherals. More...

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
Include dependency graph for hV_HAL_Peripherals.h:
This graph shows which files directly or indirectly include this file:

Macros

#define hV_HAL_PERIPHERALS_RELEASE   922
 Release. More...
 
#define hV_HAL_Serial   Serial
 SDK library. More...
 
#define mySerial   hV_HAL_Serial
 Serial port, synonym.
 
Time
#define hV_HAL_delayMilliseconds(X)   (delay(X))
 
#define hV_HAL_delayMicroseconds(X)   (delayMicroseconds(X))
 
#define hV_HAL_getMilliseconds()   (millis())
 
Log system
#define LEVEL_CRITICAL   0x0001
 Log level messages. More...
 
#define LEVEL_INFO   0x0008
 . Information
 
#define LEVEL_DEBUG   0x0010
 - Debug
 
#define LEVEL_SYSTEM   0x0020
 = System
 

Functions

void hV_HAL_log (uint16_t level, const char *format,...)
 Send debug message to console. More...
 
General
void hV_HAL_begin ()
 General initialisation. More...
 
void hV_HAL_exit (uint8_t code=0)
 General exit. More...
 
Serial console

Formatted output to hV_HAL_Serial

Note
Console already initialised at 115200 by hV_HAL_begin() (6.0.7)
void hV_HAL_Serial_crlf (void)
 Print carriage-return line-feed.
 
SPI bus
Warning
SPI.begin()
  • Arduino: no parameters
  • ESP32: required parameters for SCK, MOSI and MISO
void hV_HAL_SPI_begin (uint32_t speed=8000000)
 Configure and start SPI. More...
 
void hV_HAL_SPI_end ()
 End SPI. More...
 
uint8_t hV_HAL_SPI_transfer (uint8_t data)
 Combined write and read of a single byte. More...
 
3-wire SPI
void hV_HAL_SPI3_begin ()
 Configure 3-wire SPI. More...
 
void hV_HAL_SPI3_end ()
 End 3-wire SPI. More...
 
void hV_HAL_SPI3_define (uint8_t pinClock=SCK, uint8_t pinData=MOSI)
 Set the 3-wire SPI pins. More...
 
uint8_t hV_HAL_SPI3_read ()
 Read a single byte. More...
 
void hV_HAL_SPI3_write (uint8_t value)
 Write a single byte. More...
 
Wire bus
void hV_HAL_Wire_begin ()
 Configure and start Wire bus. More...
 
void hV_HAL_Wire_end ()
 End Wire bus. More...
 
uint8_t hV_HAL_Wire_transfer (uint8_t address, uint8_t *dataWrite, size_t sizeWrite, uint8_t *dataRead=0, size_t sizeRead=0, uint32_t us=0)
 Combined write and read with optional delay. More...
 

GPIO

Warning
  • Arduino: GPIO requires pin number, example 4
  • Mbed: GPIO requires pin name, example D4 or PB_5
  • Mbed: GPIO is created at call
  • Mbed: GPIO not suitable for interrupts
  • Viewer: For compatibility only, GPIO not implemented in Linux
#define hV_HAL_GPIO_define(X, Y)   (pinMode(X, Y))
 Undefine GPIO. More...
 
#define hV_HAL_GPIO_set(X)   (digitalWrite(X, HIGH))
 Undefine GPIO. More...
 
#define hV_HAL_GPIO_clear(X)   (digitalWrite(X, LOW))
 Undefine GPIO. More...
 
#define hV_HAL_GPIO_get(X)   (digitalRead(X))
 Undefine GPIO. More...
 
#define hV_HAL_GPIO_write(X, Y)   (digitalWrite(X, Y))
 Undefine GPIO. More...
 
#define hV_HAL_GPIO_read(X)   (digitalRead(X))
 Undefine GPIO. More...
 
void hV_HAL_GPIO_begin (void)
 Undefine GPIO. More...
 
void hV_HAL_GPIO_undefine (uint8_t pin)
 Undefine GPIO. More...
 
void hV_HAL_GPIO_waitFor (uint8_t pin, uint8_t state)
 Wait for GPIO. More...
 

Miscellaneous

#define hV_HAL_min(a, b)   ((a) < (b) ? (a) : (b))
 Minimum of two numbers. More...
 
#define hV_HAL_max(a, b)   ((a) > (b) ? (a) : (b))
 Maximum of two numbers. More...
 
#define hV_HAL_swap(x, y)   do { __typeof__(x) WORK = x; x = y; y = WORK; } while (0)
 Swap numbers. More...
 
long hV_HAL_map (long x, long in_min, long in_max, long out_min, long out_max)
 Rescale a value. More...
 

Detailed Description

Light hardware abstraction layer for peripherals.

Based on highView technology

Date
21 Oct 2025
Version
922
  • Basic edition: for hobbyists and for basic usage
    Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
    See also
    https://creativecommons.org/licenses/by-sa/4.0/

    Consider the Evaluation or Commercial editions for professionals or organisations and for commercial usage
  • Evaluation edition: for professionals or organisations, evaluation only, no commercial usage
    All rights reserved
  • Commercial edition: for professionals or organisations, commercial usage
    All rights reserved
  • Viewer edition: for professionals or organisations
    All rights reserved
  • Documentation
    All rights reserved

Macro Definition Documentation

◆ hV_HAL_GPIO_clear

#define hV_HAL_GPIO_clear (   X)    (digitalWrite(X, LOW))

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_GPIO_define

#define hV_HAL_GPIO_define (   X,
 
)    (pinMode(X, Y))

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_GPIO_get

#define hV_HAL_GPIO_get (   X)    (digitalRead(X))

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_GPIO_read

#define hV_HAL_GPIO_read (   X)    (digitalRead(X))

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_GPIO_set

#define hV_HAL_GPIO_set (   X)    (digitalWrite(X, HIGH))

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_GPIO_write

#define hV_HAL_GPIO_write (   X,
 
)    (digitalWrite(X, Y))

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_max

#define hV_HAL_max (   a,
 
)    ((a) > (b) ? (a) : (b))

Maximum of two numbers.

Parameters
afirst number
bsecond number
Returns
maximum of a and b
Note
Macro more robust than bugged implementation on some platforms

◆ hV_HAL_min

#define hV_HAL_min (   a,
 
)    ((a) < (b) ? (a) : (b))

Minimum of two numbers.

Parameters
afirst number
bsecond number
Returns
minimum of a and b
Note
Macro more robust than bugged implementation on some platforms

◆ hV_HAL_PERIPHERALS_RELEASE

#define hV_HAL_PERIPHERALS_RELEASE   922

Release.

Deprecated:
Removed synonyms for GPIO (7.0.0)
Deprecated:
Removed synonyms for Time (7.0.0)
  • hV_HAL_delay() is removed. Use hV_HAL_delayMilliseconds() instead (7.0.0)
Deprecated:
Removed synonyms for Serial (7.0.0)
  • hV_HAL_printf() is removed. Use hV_HAL_Serial_printf() instead (7.0.0)
  • hV_HAL_crlf() is removed. Use hV_HAL_Serial_crlf() instead (7.0.0)
  • hV_HAL_Serial_print() and hV_HAL_Serial_println() are not recommended. Use hV_HAL_Serial_printf() and hV_HAL_Serial_crlf() instead (7.0.0)
Deprecated:
Removed synonyms for SPI (7.0.0)
Deprecated:
Removed synonyms for Wire (7.0.0)

◆ hV_HAL_Serial

#define hV_HAL_Serial   Serial

SDK library.

See also
References

SDK other libraries

Other libraries

Serial port

Serial or Serial1

◆ hV_HAL_swap

#define hV_HAL_swap (   x,
 
)    do { __typeof__(x) WORK = x; x = y; y = WORK; } while (0)

Swap numbers.

Parameters
[out]xfirst number
[out]ysecond number
Note
Macro more robust than template for some platforms
template <typename T> T
hV_HAL_swap(T &x, T &y)
{
T w = x;
x = y;
y = w;
}
#define hV_HAL_swap(x, y)
Swap numbers.
Definition: hV_HAL_Peripherals.h:389
Note
__typeof__ recommended over typeof

◆ LEVEL_CRITICAL

#define LEVEL_CRITICAL   0x0001

Log level messages.

* Non-handled error, stop or exit

Function Documentation

◆ hV_HAL_begin()

void hV_HAL_begin ( )

General initialisation.

hV_HAL_Serial initialised at hV_HAL_Serial_Speed

◆ hV_HAL_exit()

void hV_HAL_exit ( uint8_t  code = 0)

General exit.

Parameters
codedefault = 0 = success, otherwise error
Note
Only used on Linux

◆ hV_HAL_GPIO_begin()

void hV_HAL_GPIO_begin ( void  )

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_GPIO_undefine()

void hV_HAL_GPIO_undefine ( uint8_t  pin)

Undefine GPIO.

Parameters
pinpin number or pin name according to SDK

◆ hV_HAL_GPIO_waitFor()

void hV_HAL_GPIO_waitFor ( uint8_t  pin,
uint8_t  state 
)

Wait for GPIO.

Parameters
pinpin number or pin name according to SDK
stateHIGH or LOW

◆ hV_HAL_log()

void hV_HAL_log ( uint16_t  level,
const char *  format,
  ... 
)

Send debug message to console.

Parameters
levelDebug level message
formatsee https://www.cplusplus.com/reference/cstdio/printf/ for tokens
Note
With final CR-LF

◆ hV_HAL_map()

long hV_HAL_map ( long  x,
long  in_min,
long  in_max,
long  out_min,
long  out_max 
)

Rescale a value.

Parameters
xinput value
in_minminimal input value
in_maxmaximum input value
out_minminimum output value
out_maxmaximum output value
Returns
long output value
Note
Formula is
(x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;

◆ hV_HAL_SPI3_begin()

void hV_HAL_SPI3_begin ( )

Configure 3-wire SPI.

Note
Select default SCK as clock and MOSI as data (SDIO)

◆ hV_HAL_SPI3_define()

void hV_HAL_SPI3_define ( uint8_t  pinClock = SCK,
uint8_t  pinData = MOSI 
)

Set the 3-wire SPI pins.

Parameters
pinClockclock, default = SCK
pinDatacombined data, default = MOSI
Note
For manual configuration only
Warning
SCK and MOSI provided by Arduino SDK
  • Some boards require manual configuration

◆ hV_HAL_SPI3_end()

void hV_HAL_SPI3_end ( )

End 3-wire SPI.

Warning
Some platforms require freeing the GPIOs used by 3-wire SPI before starting SPI.

◆ hV_HAL_SPI3_read()

uint8_t hV_HAL_SPI3_read ( )

Read a single byte.

Returns
read byte
Note
Configure the clock pin as output and data pin as input.
Warning
/CS to be managed externally.

◆ hV_HAL_SPI3_write()

void hV_HAL_SPI3_write ( uint8_t  value)

Write a single byte.

Parameters
databyte
Note
Configure the clock and data pins as output.
Warning
/CS to be managed externally.

◆ hV_HAL_SPI_begin()

void hV_HAL_SPI_begin ( uint32_t  speed = 8000000)

Configure and start SPI.

Parameters
speedSPI speed in Hz, 8000000 = default
Note
Other parameters are
  • Bit order: MSBFIRST
  • Data mode: SPI_MODE0
With check for unique initialisation

◆ hV_HAL_SPI_end()

void hV_HAL_SPI_end ( )

End SPI.

Note
With check for unique deinitialisation

◆ hV_HAL_SPI_transfer()

uint8_t hV_HAL_SPI_transfer ( uint8_t  data)

Combined write and read of a single byte.

Parameters
databyte
Returns
read byte
Warning
No check for previous initialisation

◆ hV_HAL_Wire_begin()

void hV_HAL_Wire_begin ( )

Configure and start Wire bus.

Note
Master mode only
With check for unique initialisation

◆ hV_HAL_Wire_end()

void hV_HAL_Wire_end ( )

End Wire bus.

Note
With check for unique deinitialisation

◆ hV_HAL_Wire_transfer()

uint8_t hV_HAL_Wire_transfer ( uint8_t  address,
uint8_t *  dataWrite,
size_t  sizeWrite,
uint8_t *  dataRead = 0,
size_t  sizeRead = 0,
uint32_t  us = 0 
)

Combined write and read with optional delay.

Parameters
[in]addressI2C device address
[in]dataWritebuffer to write
[in]sizeWritenumber of bytes
[out]dataReadbuffer to read
[in]sizeReadnumber of bytes
[in]usdelay in microseconds, default = 0 = no delay
Returns
uint8_t transmission status, RESULT_SUCCESS = 0 or RESULT_ERROR = 1
Note
If sizeRead = 0, no read performed
Warning
No check for previous initialisation