Skip to content

Commit

Permalink
correct initialization of zephyr osal spi and cs
Browse files Browse the repository at this point in the history
  • Loading branch information
vChavezB committed May 17, 2024
1 parent c921ded commit afdf1ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/iol_osal/osal_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 13 additions & 3 deletions src/iol_osal/osal_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@

#include <zephyr/drivers/spi.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <osal_spi.h>

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;
Expand All @@ -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

}

0 comments on commit afdf1ab

Please sign in to comment.