In most cases h2pas can only convert simple header files without manual work. So it is to be expected that you need to adapt several parts of the converted unit.
For your unit:
For instance, sometimes it cannot convert things automatically and you've to convert it like
/**
* @brief Open a gpiochip by path.
* @param path Path to the gpiochip device file.
* @return GPIO chip handle or NULL if an error occurred.
*/
struct gpiod_chip *gpiod_chip_open(const char *path);
just gives
(* error
struct gpiod_chip *gpiod_chip_open(const char *path);
in declaration at line 81 *)
so you need to adapt it to
function gpiod_chip_open(path:Pchar): Pgpiod_chip;
h2pas also seems to have issues with lines breaks/functions declarations over multiple lines (maybe it's also just because of the return type) as following functions are also not converted:
struct gpiod_line *
gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset);
struct gpiod_line_bulk *
gpiod_chip_get_lines(struct gpiod_chip *chip, unsigned int *offsets,
unsigned int num_offsets);
the converted unit just contains:
(* error
struct gpiod_line *
in declaration at line 117 *)
(* error
struct gpiod_line_bulk *
in declaration at line 128 *)
It also fails at converting the enums
/**
* @brief Possible direction settings.
*/
enum {
GPIOD_LINE_DIRECTION_INPUT = 1,
/**< Direction is input - we're reading the state of a GPIO line. */
GPIOD_LINE_DIRECTION_OUTPUT,
/**< Direction is output - we're driving the GPIO line. */
};
which should probably be a
const in Pascal (or an enumerated type depending on what you favour) and converts the macro
GPIOD_BIT into a function
function GPIOD_BIT(nr : longint) : longint;
begin
GPIOD_BIT:=1 shl nr;
end;
instead of using it to calculate the appropriate numbers used in the C enum.
PS: I used
h2pas -e -p -pr -s gpiod.h with the
gpiod.h from the kernel git for the above examples.