From 2344903b89108967bc70b7c99944c2f6fef4bdc2 Mon Sep 17 00:00:00 2001 From: lyon Date: Mon, 21 Nov 2022 16:37:52 +0800 Subject: [PATCH] update PikaStdDevice to port/linux use unused as defult enum --- package/PikaStdDevice/pika_hal.h | 14 +- .../PikaStdDevice/PikaStdDevice_GPIO.c | 61 ++++++-- .../pikascript-lib/PikaStdDevice/pika_hal.c | 29 ++-- .../pikascript-lib/PikaStdDevice/pika_hal.h | 142 ++++++++++++------ .../PikaStdDevice/pika_hal_table_rule.h | 127 +++++++++------- 5 files changed, 238 insertions(+), 135 deletions(-) diff --git a/package/PikaStdDevice/pika_hal.h b/package/PikaStdDevice/pika_hal.h index a89409912..09064c7af 100644 --- a/package/PikaStdDevice/pika_hal.h +++ b/package/PikaStdDevice/pika_hal.h @@ -24,7 +24,7 @@ typedef enum { typedef enum { PIKA_HAL_GPIO_DIR_IN, PIKA_HAL_GPIO_DIR_OUT, - PIKA_HAL_GPIO_DIR_DEFAULT = 0, + _PIKA_HAL_GPIO_DIR_UNUSED = 0, _PIKA_HAL_GPIO_DIR_MAX, } PIKA_HAL_GPIO_DIR; @@ -32,7 +32,7 @@ typedef enum { PIKA_HAL_GPIO_PULL_NONE, PIKA_HAL_GPIO_PULL_UP, PIKA_HAL_GPIO_PULL_DOWN, - PIKA_HAL_GPIO_PULL_DEFAULT = 0, + _PIKA_HAL_GPIO_PULL_UNUSED = 0, _PIKA_HAL_GPIO_PULL_MAX, } PIKA_HAL_GPIO_PULL; @@ -50,14 +50,14 @@ typedef struct { typedef enum { PIKA_HAL_SPI_LSB, PIKA_HAL_SPI_MSB, - PIKA_HAL_SPI_LSB_OR_MSB_DEFAULT = 0, + _PIKA_HAL_SPI_LSB_OR_MSB_UNUSED = 0, _PIKA_HAL_SPI_LSB_OR_MSB_MAX, } PIKA_HAL_SPI_LSB_OR_MSB; typedef enum { PIKA_HAL_SPI_MASTER, PIKA_HAL_SPI_SLAVE, - PIKA_HAL_SPI_MASTER_OR_SLAVE_DEFAULT = 0, + _PIKA_HAL_SPI_MASTER_OR_SLAVE_UNUSED = 0, _PIKA_HAL_SPI_MASTER_OR_SLAVE_MAX, } PIKA_HAL_SPI_MASTER_OR_SLAVE; @@ -66,14 +66,14 @@ typedef enum { PIKA_HAL_SPI_MODE_1, PIKA_HAL_SPI_MODE_2, PIKA_HAL_SPI_MODE_3, - PIKA_HAL_SPI_MODE_DEFAULT = 0, + _PIKA_HAL_SPI_MODE_UNUSED = 0, _PIKA_HAL_SPI_MODE_MAX, } PIKA_HAL_SPI_MODE; typedef enum { PIKA_HAL_SPI_DATA_WIDTH_8BIT, PIKA_HAL_SPI_DATA_WIDTH_16BIT, - PIKA_HAL_SPI_DATA_DEFAULT = 0, + _PIKA_HAL_SPI_DATA_UNUSED = 0, _PIKA_HAL_SPI_DATA_WIDTH_MAX, } PIKA_HAL_SPI_DATA_WIDTH; @@ -82,7 +82,7 @@ typedef enum { PIKA_HAL_SPI_SPEED_MEDIUM, PIKA_HAL_SPI_SPEED_HIGH, PIKA_HAL_SPI_SPEED_VERY_HIGH, - PIKA_HAL_SPI_SPEED_DEFAULT = 0, + _PIKA_HAL_SPI_SPEED_UNUSED = 0, _PIKA_HAL_SPI_SPEED_MAX, } PIKA_HAL_SPI_SPEED; diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_GPIO.c b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_GPIO.c index 321f61cf8..921e85ff8 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_GPIO.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_GPIO.c @@ -9,6 +9,7 @@ void PikaStdDevice_GPIO_init(PikaObj* self) { obj_setInt(self, "isOn", 0); obj_setStr(self, "pull", "none"); obj_setInt(self, "id", -999); + obj_setPtr(self, "pika_dev", NULL); } int PikaStdDevice_GPIO_getId(PikaObj* self) { @@ -76,38 +77,70 @@ void PikaStdDevice_GPIO_setPull(PikaObj* self, char* pull) { } } +static pika_dev* _get_dev(PikaObj* self){ + pika_dev* dev = obj_getPtr(self, "pika_dev"); + if(NULL != dev){ + return dev; + } + dev = pika_hal_open(PIKA_HAL_GPIO, obj_getStr(self, "pin")); + if(NULL == dev){ + __platform_printf("Error: open GPIO '%s' failed.\r\n", obj_getStr(self, "pin")); + } + obj_setPtr(self, "pika_dev", dev); + return dev; +} + void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) { obj_setStr(self, "pin", pinName); } void PikaStdDevice_GPIO_platformDisable(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); + pika_dev* dev = _get_dev(self); + pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE); } void PikaStdDevice_GPIO_platformEnable(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); + pika_dev* dev = _get_dev(self); + pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE); } void PikaStdDevice_GPIO_platformLow(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); + pika_dev* dev = _get_dev(self); + uint32_t val = 0; + pika_hal_write(dev, &val, sizeof(val)); } void PikaStdDevice_GPIO_platformHigh(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); + pika_dev* dev = _get_dev(self); + uint32_t val = 1; + pika_hal_write(dev, &val, sizeof(val)); } void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); -} - -void PikaStdDevice_GPIO_platformOff(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); -} - -void PikaStdDevice_GPIO_platformOn(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); + char* mode = obj_getStr(self, "mode"); + pika_hal_GPIO_config cfg = {0}; + if(strEqu(mode, "in")){ + cfg.dir = PIKA_HAL_GPIO_DIR_IN; + }else{ + cfg.dir = PIKA_HAL_GPIO_DIR_OUT; + } + pika_dev* dev = _get_dev(self); + char* pull = obj_getStr(self, "pull"); + if (strEqu(pull, "up")){ + cfg.pull = PIKA_HAL_GPIO_PULL_UP; + } + if (strEqu(pull, "down")){ + cfg.pull = PIKA_HAL_GPIO_PULL_DOWN; + } + if (strEqu(pull, "none")) { + cfg.pull = PIKA_HAL_GPIO_PULL_NONE; + } + pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg); } void PikaStdDevice_GPIO_platformRead(PikaObj* self) { - ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(); + pika_dev* dev = _get_dev(self); + uint32_t val = 0; + pika_hal_read(dev, &val, sizeof(val)); + obj_setInt(self, "readBuff", val); } diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c index 39cad705d..777aa118e 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c @@ -4,24 +4,26 @@ #define PIKA_HAL_TABLE_FILE_API #include "pika_hal_table.h" -static const pika_dev_impl pika_dev_impl_list[_PIKA_DEV_TYPE_MAX] = { +static const pika_dev_impl pika_dev_impl_list[] = { #define PIKA_HAL_TABLE_IMPL #include "pika_hal_table.h" }; -static pika_dev_impl* _pika_dev_get_impl(pika_dev_type type) { +static pika_dev_impl* _pika_dev_get_impl(PIKA_HAL_DEV_TYPE type) { if (type >= _PIKA_DEV_TYPE_MAX) { return NULL; } return (pika_dev_impl*)&pika_dev_impl_list[type]; } -pika_dev* pika_hal_open(pika_dev_type dev_type, char* name) { +pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name) { if (dev_type >= _PIKA_DEV_TYPE_MAX) { + __platform_printf("Error: dev_type invalied.\r\n"); return NULL; } pika_dev_impl* impl = _pika_dev_get_impl(dev_type); if (impl->open == NULL) { + __platform_printf("Error: dev_open_impl not implamented.\r\n"); return NULL; } pika_dev* dev = (pika_dev*)pikaMalloc(sizeof(pika_dev)); @@ -29,8 +31,9 @@ pika_dev* pika_hal_open(pika_dev_type dev_type, char* name) { return NULL; } dev->type = dev_type; - if (impl->open(dev) != 0) { + if (impl->open(dev, name) != 0) { pikaFree(dev, sizeof(pika_dev)); + __platform_printf("Error: dev_open failed.\r\n"); return NULL; } return dev; @@ -49,7 +52,7 @@ int pika_hal_close(pika_dev* dev) { return ret; } -int pika_hal_read(pika_dev* dev, uint8_t* buf, size_t len) { +int pika_hal_read(pika_dev* dev, void* buf, size_t len) { if (dev == NULL) { return -1; } @@ -60,7 +63,7 @@ int pika_hal_read(pika_dev* dev, uint8_t* buf, size_t len) { return impl->read(dev, buf, len); } -int pika_hal_write(pika_dev* dev, uint8_t* buf, size_t len) { +int pika_hal_write(pika_dev* dev, void* buf, size_t len) { if (dev == NULL) { return -1; } @@ -71,20 +74,20 @@ int pika_hal_write(pika_dev* dev, uint8_t* buf, size_t len) { return impl->write(dev, buf, len); } -static const int _pika_hal_cmd_arg_cnt[_PIKA_DEV_CMD_MAX] = { - [PIKA_DEV_CMD_ENABLE] = 0, - [PIKA_DEV_CMD_DISABLE] = 0, - [PIKA_DEV_CMD_CONFIG] = 1, +static const int _pika_hal_cmd_arg_cnt[_PIKA_HAL_IOCTL_MAX] = { + [PIKA_HAL_IOCTL_ENABLE] = 0, + [PIKA_HAL_IOCTL_DISABLE] = 0, + [PIKA_HAL_IOCTL_CONFIG] = 1, }; -static int _pika_hal_get_arg_cnt(pika_dev_cmd cmd) { - if (cmd >= _PIKA_DEV_CMD_MAX) { +static int _pika_hal_get_arg_cnt(PIKA_HAL_IOCTL_CMD cmd) { + if (cmd >= _PIKA_HAL_IOCTL_MAX) { return -1; } return _pika_hal_cmd_arg_cnt[cmd]; } -int pika_hal_ioctl(pika_dev* dev, pika_dev_cmd cmd, ...) { +int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) { if (dev == NULL) { return -1; } diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h index 73e1989f8..09064c7af 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h @@ -4,74 +4,124 @@ #include /* - * pika_dev_hal is a C HAL lib for PikaScript modules. - * the api of pika_dev_hal is similar to the api of posix file API. + * pika_hal is a C Device HAL lib for PikaScript modules. + * the API of pika_hal is similar to the posix file API. */ -typedef enum pika_dev_type { +typedef enum { #define PIKA_HAL_TABLE_DEV_TYPE #include "pika_hal_table.h" _PIKA_DEV_TYPE_MAX, -} pika_dev_type; +} PIKA_HAL_DEV_TYPE; -typedef enum pika_dev_cmd { - PIKA_DEV_CMD_ENABLE, - PIKA_DEV_CMD_DISABLE, - PIKA_DEV_CMD_CONFIG, - _PIKA_DEV_CMD_MAX, -} pika_dev_cmd; +typedef enum { + PIKA_HAL_IOCTL_ENABLE, + PIKA_HAL_IOCTL_DISABLE, + PIKA_HAL_IOCTL_CONFIG, + _PIKA_HAL_IOCTL_MAX, +} PIKA_HAL_IOCTL_CMD; -typedef enum pika_gpio_dir { - PIKA_GPIO_DIR_IN, - PIKA_GPIO_DIR_OUT, - _PIKA_GPIO_DIR_MAX, -} pika_gpio_dir; +typedef enum { + PIKA_HAL_GPIO_DIR_IN, + PIKA_HAL_GPIO_DIR_OUT, + _PIKA_HAL_GPIO_DIR_UNUSED = 0, + _PIKA_HAL_GPIO_DIR_MAX, +} PIKA_HAL_GPIO_DIR; -typedef enum pika_gpio_pull { - PIKA_GPIO_PULL_NONE, - PIKA_GPIO_PULL_UP, - PIKA_GPIO_PULL_DOWN, - _PIKA_GPIO_PULL_MAX, -} pika_gpio_pull; +typedef enum { + PIKA_HAL_GPIO_PULL_NONE, + PIKA_HAL_GPIO_PULL_UP, + PIKA_HAL_GPIO_PULL_DOWN, + _PIKA_HAL_GPIO_PULL_UNUSED = 0, + _PIKA_HAL_GPIO_PULL_MAX, +} PIKA_HAL_GPIO_PULL; -typedef struct pika_GPIO_config { - pika_gpio_dir dir; - pika_gpio_pull pull; -} pika_GPIO_config; +typedef struct { + PIKA_HAL_GPIO_DIR dir; + PIKA_HAL_GPIO_PULL pull; +} pika_hal_GPIO_config; -typedef struct pika_UART_config { -} pika_UART_config; +typedef struct { +} pika_hal_UART_config; -typedef struct pika_I2C_config { -} pika_I2C_config; +typedef struct { +} pika_hal_I2C_config; -typedef struct pika_SPI_config { -} pika_SPI_config; +typedef enum { + PIKA_HAL_SPI_LSB, + PIKA_HAL_SPI_MSB, + _PIKA_HAL_SPI_LSB_OR_MSB_UNUSED = 0, + _PIKA_HAL_SPI_LSB_OR_MSB_MAX, +} PIKA_HAL_SPI_LSB_OR_MSB; -typedef struct pika_ADC_config { -} pika_ADC_config; +typedef enum { + PIKA_HAL_SPI_MASTER, + PIKA_HAL_SPI_SLAVE, + _PIKA_HAL_SPI_MASTER_OR_SLAVE_UNUSED = 0, + _PIKA_HAL_SPI_MASTER_OR_SLAVE_MAX, +} PIKA_HAL_SPI_MASTER_OR_SLAVE; -typedef struct pika_PWM_config { -} pika_PWM_config; +typedef enum { + PIKA_HAL_SPI_MODE_0, + PIKA_HAL_SPI_MODE_1, + PIKA_HAL_SPI_MODE_2, + PIKA_HAL_SPI_MODE_3, + _PIKA_HAL_SPI_MODE_UNUSED = 0, + _PIKA_HAL_SPI_MODE_MAX, +} PIKA_HAL_SPI_MODE; -typedef struct pika_dev { - pika_dev_type type; - void* user_data; +typedef enum { + PIKA_HAL_SPI_DATA_WIDTH_8BIT, + PIKA_HAL_SPI_DATA_WIDTH_16BIT, + _PIKA_HAL_SPI_DATA_UNUSED = 0, + _PIKA_HAL_SPI_DATA_WIDTH_MAX, +} PIKA_HAL_SPI_DATA_WIDTH; + +typedef enum { + PIKA_HAL_SPI_SPEED_LOW, + PIKA_HAL_SPI_SPEED_MEDIUM, + PIKA_HAL_SPI_SPEED_HIGH, + PIKA_HAL_SPI_SPEED_VERY_HIGH, + _PIKA_HAL_SPI_SPEED_UNUSED = 0, + _PIKA_HAL_SPI_SPEED_MAX, +} PIKA_HAL_SPI_SPEED; + +typedef struct { + PIKA_HAL_SPI_LSB_OR_MSB lsb_or_msb; + PIKA_HAL_SPI_MASTER_OR_SLAVE master_or_slave; + PIKA_HAL_SPI_MODE mode; + PIKA_HAL_SPI_DATA_WIDTH data_width; + PIKA_HAL_SPI_SPEED speed; +} pika_hal_SPI_config; + +typedef struct { +} pika_hal_ADC_config; + +typedef struct { +} pika_hal_PWM_config; + +typedef struct { + PIKA_HAL_DEV_TYPE type; + void* platform_data; } pika_dev; typedef struct pika_dev_impl { - int (*open)(pika_dev* dev); + int (*open)(pika_dev* dev, char* name); int (*close)(pika_dev* dev); - int (*read)(pika_dev* dev, uint8_t* buf, size_t count); - int (*write)(pika_dev* dev, uint8_t* buf, size_t count); - int (*ioctl)(pika_dev* dev, pika_dev_cmd cmd, uintptr_t cfg); + int (*read)(pika_dev* dev, void* buf, size_t count); + int (*write)(pika_dev* dev, void* buf, size_t count); + int (*ioctl)(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, uintptr_t cfg); } pika_dev_impl; /* posix file like API */ -pika_dev* pika_hal_open(pika_dev_type dev_type, char* name); +pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name); int pika_hal_close(pika_dev* dev); -int pika_hal_read(pika_dev* dev, uint8_t* buf, size_t len); -int pika_hal_write(pika_dev* dev, uint8_t* buf, size_t len); -int PIKA_HAL_TABLE_FILE_API(pika_dev* dev, pika_dev_cmd cmd, ...); +int pika_hal_read(pika_dev* dev, void* buf, size_t len); +int pika_hal_write(pika_dev* dev, void* buf, size_t len); +int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...); + +/* platform API */ +#define PIKA_HAL_TABLE_PLATFORM_API +#include "pika_hal_table.h" #endif diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h index ade488069..064c913eb 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h @@ -1,53 +1,55 @@ #undef pika_hal_table_add #if defined(PIKA_HAL_TABLE_FILE_API) -#define pika_hal_table_add(dev_name) \ - PIKA_WEAK int pika_##dev_name##_open(pika_dev* dev) { \ - WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ - return -1; \ - } \ - PIKA_WEAK int pika_##dev_name##_close(pika_dev* dev) { \ - WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ - return -1; \ - } \ - PIKA_WEAK int pika_##dev_name##_read(pika_dev* dev, uint8_t* buf, \ - size_t len) { \ - WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ - return -1; \ - } \ - PIKA_WEAK int pika_##dev_name##_write(pika_dev* dev, uint8_t* buf, \ - size_t len) { \ - WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ - return -1; \ - } \ - PIKA_WEAK int pika_##dev_name##_ioctl_enable(pika_dev* dev) { \ - WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ - return -1; \ - } \ - PIKA_WEAK int pika_##dev_name##_ioctl_disable(pika_dev* dev) { \ - WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ - return -1; \ - } \ - PIKA_WEAK int pika_##dev_name##_ioctl_config( \ - pika_dev* dev, pika_##dev_name##_config* cfg) { \ - WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ - return -1; \ - } \ - int pika_##dev_name##_ioctl(pika_dev* dev, pika_dev_cmd cmd, \ - uintptr_t arg) { \ - if (NULL == dev) { \ - return -1; \ - } \ - switch (cmd) { \ - case PIKA_DEV_CMD_ENABLE: \ - return pika_##dev_name##_ioctl_enable(dev); \ - case PIKA_DEV_CMD_DISABLE: \ - return pika_##dev_name##_ioctl_disable(dev); \ - case PIKA_DEV_CMD_CONFIG: \ - return pika_##dev_name##_ioctl_config( \ - dev, (pika_##dev_name##_config*)arg); \ - default: \ - return -1; \ - } \ +#define pika_hal_table_add(dev_name) \ + PIKA_WEAK int pika_hal_platform_##dev_name##_open(pika_dev* dev, \ + char* name) { \ + WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ + return -1; \ + } \ + PIKA_WEAK int pika_hal_platform_##dev_name##_close(pika_dev* dev) { \ + WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ + return -1; \ + } \ + PIKA_WEAK int pika_hal_platform_##dev_name##_read(pika_dev* dev, \ + void* buf, size_t len) { \ + WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ + return -1; \ + } \ + PIKA_WEAK int pika_hal_platform_##dev_name##_write( \ + pika_dev* dev, void* buf, size_t len) { \ + WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ + return -1; \ + } \ + PIKA_WEAK int pika_hal_platform_##dev_name##_ioctl_enable(pika_dev* dev) { \ + WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ + return -1; \ + } \ + PIKA_WEAK int pika_hal_platform_##dev_name##_ioctl_disable( \ + pika_dev* dev) { \ + WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ + return -1; \ + } \ + PIKA_WEAK int pika_hal_platform_##dev_name##_ioctl_config( \ + pika_dev* dev, pika_hal_##dev_name##_config* cfg) { \ + WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \ + return -1; \ + } \ + int pika_hal_##dev_name##_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, \ + uintptr_t arg) { \ + if (NULL == dev) { \ + return -1; \ + } \ + switch (cmd) { \ + case PIKA_HAL_IOCTL_ENABLE: \ + return pika_hal_platform_##dev_name##_ioctl_enable(dev); \ + case PIKA_HAL_IOCTL_DISABLE: \ + return pika_hal_platform_##dev_name##_ioctl_disable(dev); \ + case PIKA_HAL_IOCTL_CONFIG: \ + return pika_hal_platform_##dev_name##_ioctl_config( \ + dev, (pika_hal_##dev_name##_config*)arg); \ + default: \ + return -1; \ + } \ } #endif @@ -57,16 +59,31 @@ #endif #if defined(PIKA_HAL_TABLE_IMPL) -#define pika_hal_table_add(dev_name) \ - [PIKA_HAL_##dev_name] = { \ - .open = pika_##dev_name##_open, \ - .close = pika_##dev_name##_close, \ - .read = pika_##dev_name##_read, \ - .write = pika_##dev_name##_write, \ - .ioctl = pika_##dev_name##_ioctl, \ +#define pika_hal_table_add(dev_name) \ + [PIKA_HAL_##dev_name] = { \ + .open = pika_hal_platform_##dev_name##_open, \ + .close = pika_hal_platform_##dev_name##_close, \ + .read = pika_hal_platform_##dev_name##_read, \ + .write = pika_hal_platform_##dev_name##_write, \ + .ioctl = pika_hal_##dev_name##_ioctl, \ }, #endif +#if defined(PIKA_HAL_TABLE_PLATFORM_API) +#define pika_hal_table_add(dev_name) \ + int pika_hal_platform_##dev_name##_open(pika_dev* dev, char* name); \ + int pika_hal_platform_##dev_name##_close(pika_dev* dev); \ + int pika_hal_platform_##dev_name##_read(pika_dev* dev, void* buf, \ + size_t len); \ + int pika_hal_platform_##dev_name##_write(pika_dev* dev, void* buf, \ + size_t len); \ + int pika_hal_platform_##dev_name##_ioctl_enable(pika_dev* dev); \ + int pika_hal_platform_##dev_name##_ioctl_disable(pika_dev* dev); \ + int pika_hal_platform_##dev_name##_ioctl_config( \ + pika_dev* dev, pika_hal_##dev_name##_config* cfg); +#endif + #undef PIKA_HAL_TABLE_FILE_API #undef PIKA_HAL_TABLE_DEV_TYPE #undef PIKA_HAL_TABLE_IMPL +#undef PIKA_HAL_TABLE_PLATFORM_API