From b07b29c45a28db8b8e7e57c7895b27ce138d6ad9 Mon Sep 17 00:00:00 2001 From: Victor Chavez Date: Thu, 23 May 2024 20:35:53 +0200 Subject: [PATCH] enabled second port --- .../esp32_devkitc_wrover_procpu.overlay | 4 ++-- .../src/iol_master_sample_app.c | 19 +++++++++++++++++-- samples/ifm_sample_app/src/iolink_handler.c | 8 ++++---- samples/ifm_sample_app/src/iolink_smi.c | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/samples/ifm_sample_app/boards/esp32_devkitc_wrover_procpu.overlay b/samples/ifm_sample_app/boards/esp32_devkitc_wrover_procpu.overlay index 9c6c5a1..00bf551 100644 --- a/samples/ifm_sample_app/boards/esp32_devkitc_wrover_procpu.overlay +++ b/samples/ifm_sample_app/boards/esp32_devkitc_wrover_procpu.overlay @@ -4,12 +4,12 @@ compatible = "gpio-leds"; iolm_irq: iolm_irq { status = "okay"; - gpios = <&gpio0 26 (GPIO_ACTIVE_LOW)>; + gpios = <&gpio0 18 (GPIO_ACTIVE_LOW)>; label = "iolm_irq"; }; iolm_cs: iolm_cs { status = "okay"; - gpios = <&gpio0 27 (GPIO_ACTIVE_LOW)>; + gpios = <&gpio0 19 (GPIO_ACTIVE_LOW)>; label = "iolm_cs"; }; }; diff --git a/samples/ifm_sample_app/src/iol_master_sample_app.c b/samples/ifm_sample_app/src/iol_master_sample_app.c index 83095aa..398b301 100644 --- a/samples/ifm_sample_app/src/iol_master_sample_app.c +++ b/samples/ifm_sample_app/src/iol_master_sample_app.c @@ -26,7 +26,7 @@ static const struct device *const spi_dev = DEVICE_DT_GET(DT_ALIAS(iolm_spi)); static const struct gpio_dt_spec irq_dev = GPIO_DT_SPEC_GET(DT_ALIAS(iolm_irq), gpios); #define IOLINK_HANDLER_THREAD_STACK_SIZE (8192) -#define IOLINK_HANDLER_THREAD_PRIO 4 +#define IOLINK_HANDLER_THREAD_PRIO 5 static K_THREAD_STACK_DEFINE(iolm_handler_stack, IOLINK_HANDLER_THREAD_STACK_SIZE); @@ -86,13 +86,25 @@ static iolink_m_cfg_t iolink_cfg = { os_thread_t * iolink_handler_thread; iolink_hw_drv_t * hw[2]; +#define CURR_100MA 0x00 +#define CURR_200MA 0x01 +#define CURR_300MA 0x02 +#define CURR_500MA 0x03 +#define DRVRCURRLIM_CLDIS BIT(5) + +#define CURR_OFF 0x06 + +#define CL_CONF(x) ((x) << CURR_OFF) static const iolink_14819_cfg_t iol_14819_0_cfg = { .chip_address = IOLINK_APP_CHIP0_ADDRESS, .spi_slave_name = spi_dev, .CQCfgA = MAX14819_CQCFG_DRVDIS | MAX14819_CQCFG_SINKSEL(0x2), + .CQCfgB = MAX14819_CQCFG_DRVDIS | MAX14819_CQCFG_SINKSEL(0x2), .LPCnfgA = MAX14819_LPCNFG_LPEN, + .LPCnfgB = MAX14819_LPCNFG_LPEN, .IOStCfgA = MAX14819_IOSTCFG_DICSINK | MAX14819_IOSTCFG_DIEC3TH, - .DrvCurrLim = 0x00, + .IOStCfgB = MAX14819_IOSTCFG_DICSINK | MAX14819_IOSTCFG_DIEC3TH, + .DrvCurrLim = CL_CONF(CURR_300MA), .Clock = MAX14819_CLOCK_XTALEN | MAX14819_CLOCK_TXTXENDIS, }; @@ -142,6 +154,9 @@ int main(void) LOG_INF("Starting app"); hw[0] = main_14819_init("/iolink0", &iol_14819_0_cfg, irq_dev.port, irq_dev.pin); + if (hw[0] == NULL) { + return 0; + } #ifdef IOLINK_APP_CHIP1_SPI hw[1] = main_14819_init("/iolink1", &iol_14819_1_cfg, irq_dev.port, irq_dev.pin); #endif diff --git a/samples/ifm_sample_app/src/iolink_handler.c b/samples/ifm_sample_app/src/iolink_handler.c index ac37893..a2f461a 100644 --- a/samples/ifm_sample_app/src/iolink_handler.c +++ b/samples/ifm_sample_app/src/iolink_handler.c @@ -241,7 +241,7 @@ void generic_app (iolink_app_port_ctx_t * app_port) static uint8_t iolink_start_port (iolink_app_port_ctx_t * app_port) { iolink_app_port_status_t * port_status = &app_port->status; - uint8_t portnumber = app_port->portnumber; + uint8_t portnumber = app_port->portnumber-1; if (get_port_status (app_port) != 0) { @@ -420,7 +420,7 @@ void iolink_handler (iolink_m_cfg_t m_cfg) for (size_t i = 0; i < app_port->pdin.data_len; i++) { sprintf(pdin_data + (i * 2), "%02x", app_port->pdin.data[i]); } - //LOG_INF("Port [%d] PDIN Cnf %s", app_port->portnumber,pdin_data); + LOG_INF("Port [%d] PDIN Cnf %s", app_port->portnumber,pdin_data); } } @@ -520,8 +520,8 @@ static void handle_smi_portevent ( uint8_t portnumber = app_port->portnumber; iolink_app_master_ctx_t * app_master = app_port->app_master; uint8_t port_index = portnumber - 1; - LOG_INF("SMI event"); - LOG_INF("Port event %d : %x",event->event_qualifier,event->event_code); + //LOG_INF("SMI event"); + //LOG_INF("Port [%d] event %d : %x",port_index,event->event_qualifier,event->event_code); if ( ((app_port->type == GOLDEN) || (app_port->type == UNKNOWN)) && event->event_code != IOLINK_EVENTCODE_NO_DEV) diff --git a/samples/ifm_sample_app/src/iolink_smi.c b/samples/ifm_sample_app/src/iolink_smi.c index 8a9adec..ba3bc14 100644 --- a/samples/ifm_sample_app/src/iolink_smi.c +++ b/samples/ifm_sample_app/src/iolink_smi.c @@ -187,7 +187,7 @@ int8_t do_smi_pdin (iolink_app_port_ctx_t * app_port, bool * valid) memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block.id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - SMI_PDIn_req ( + return SMI_PDIn_req ( app_port->portnumber, IOLINK_ARG_BLOCK_ID_PD_IN, sizeof (arg_block_void_t),