diff --git a/src/iol_osal/osal_irq.c b/src/iol_osal/osal_irq.c index 1e9161e..df59184 100644 --- a/src/iol_osal/osal_irq.c +++ b/src/iol_osal/osal_irq.c @@ -25,11 +25,12 @@ int _iolink_setup_int_zephyr (const struct device * port, gpio_pin_t pin, isr_fu if (!device_is_ready(port)) { return -ENODEV; } - gpio_pin_configure(port, pin, GPIO_ACTIVE_LOW | GPIO_INPUT ); + int rc = gpio_pin_configure(port, pin, GPIO_ACTIVE_LOW | GPIO_INPUT | GPIO_PULL_UP ); struct gpio_cb_data * cb_data = (struct gpio_cb_data *)malloc(sizeof(struct gpio_cb_data)); cb_data->arg = irq_arg; cb_data->isr_func = isr_func; gpio_init_callback(&cb_data->zephyr_data, gpio_cb, BIT(pin)); gpio_add_callback(port, &cb_data->zephyr_data); - return 0; + rc = gpio_pin_interrupt_configure(port,pin,GPIO_INT_EDGE_TO_ACTIVE); + return rc == 0; } \ No newline at end of file diff --git a/src/iol_osal/osal_spi.c b/src/iol_osal/osal_spi.c index c482bf2..69ac520 100644 --- a/src/iol_osal/osal_spi.c +++ b/src/iol_osal/osal_spi.c @@ -4,18 +4,27 @@ #include #include +#include #include +static const struct gpio_dt_spec cs_pin = GPIO_DT_SPEC_GET(DT_ALIAS(iolm_cs), gpios); + +static const struct spi_cs_control iolm_cs_pin={ + cs_pin,0 +}; + // TODO check SPI cfg required for MAX14819 static struct spi_config spi_cfg = { - .frequency = 0U, + .frequency = 20000000U, .operation = {{SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_MASTER}}, .slave = 0U, - .cs = {NULL} + .cs = NULL }; void * _iolink_pl_hw_spi_init (const char * device) { + gpio_pin_configure_dt(&cs_pin,GPIO_OUTPUT); + gpio_pin_set_dt(&cs_pin,0); const struct device * spi_dev = (struct device *) device; if(device_is_ready(spi_dev)!=true) { return NULL; @@ -39,10 +48,11 @@ void _iolink_pl_hw_spi_transfer ( const struct spi_buf rx_buf = {.buf=data_read, .len=n_bytes_to_transfer}; struct spi_buf_set tx_set = {.buffers=&tx_buf, .count=1}; struct spi_buf_set rx_set = {.buffers=&rx_buf, .count=1}; + gpio_pin_set_dt(&cs_pin,1); const int spi_res = spi_transceive(spi_dev, &spi_cfg, &tx_set, &rx_set); + gpio_pin_set_dt(&cs_pin,0); // TODO log error, check how to deal with LOG_DBG - } \ No newline at end of file