Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions projects/ltc2378/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
EXAMPLE ?= basic

include ../../tools/scripts/generic_variables.mk

include ../../tools/scripts/examples.mk

include src.mk

include ../../tools/scripts/generic.mk
10 changes: 10 additions & 0 deletions projects/ltc2378/builds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"maxim": {
"basic_example": {
"flags": "EXAMPLE=basic TARGET=max32665"
},
"iio": {
"flags": "EXAMPLE=iio_example TARGET=max32665"
}
}
}
28 changes: 28 additions & 0 deletions projects/ltc2378/src.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
INCS += $(INCLUDE)/no_os_delay.h \
$(INCLUDE)/no_os_error.h \
$(INCLUDE)/no_os_gpio.h \
$(INCLUDE)/no_os_print_log.h \
$(INCLUDE)/no_os_spi.h \
$(INCLUDE)/no_os_alloc.h \
$(INCLUDE)/no_os_irq.h \
$(INCLUDE)/no_os_list.h \
$(INCLUDE)/no_os_dma.h \
$(INCLUDE)/no_os_uart.h \
$(INCLUDE)/no_os_lf256fifo.h \
$(INCLUDE)/no_os_util.h \
$(INCLUDE)/no_os_units.h \
$(INCLUDE)/no_os_mutex.h

SRCS += $(DRIVERS)/api/no_os_gpio.c \
$(NO-OS)/util/no_os_lf256fifo.c \
$(DRIVERS)/api/no_os_irq.c \
$(DRIVERS)/api/no_os_spi.c \
$(DRIVERS)/api/no_os_uart.c \
$(DRIVERS)/api/no_os_dma.c \
$(NO-OS)/util/no_os_list.c \
$(NO-OS)/util/no_os_util.c \
$(NO-OS)/util/no_os_alloc.c \
$(NO-OS)/util/no_os_mutex.c

INCS += $(DRIVERS)/adc/ltc2378/ltc2378.h
SRCS += $(DRIVERS)/adc/ltc2378/ltc2378.c
81 changes: 81 additions & 0 deletions projects/ltc2378/src/common/common_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* @file common_data.c
* @brief Defines common data to be used by ltc2378 examples.
* @author Cherrence Sarip ([email protected])
********************************************************************************
* Copyright 2025(c) Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include "common_data.h"
#include <stdbool.h>
#include "parameters.h"

struct no_os_uart_init_param uip = {
.device_id = UART_DEVICE_ID,
.irq_id = UART_IRQ_ID,
.asynchronous_rx = true,
.baud_rate = UART_BAUDRATE,
.size = NO_OS_UART_CS_8,
.parity = NO_OS_UART_PAR_NO,
.stop = NO_OS_UART_STOP_1_BIT,
.platform_ops = UART_OPS,
.extra = UART_EXTRA,
};

const struct no_os_spi_init_param ltc2378_spi_ip = {
.device_id = SPI_DEVICE_ID,
.max_speed_hz = SPI_MAX_SPEED,
.chip_select = SPI_CS,
.mode = NO_OS_SPI_MODE_0,
.bit_order = NO_OS_SPI_BIT_ORDER_MSB_FIRST,
.platform_ops = SPI_OPS,
.extra = SPI_EXTRA,
.parent = NULL,
};

const struct no_os_gpio_init_param ltc2378_gpio_cnv = {
.port = GPIO_CNV_PORT_NUM,
.number = GPIO_CNV_PIN_NUM,
.platform_ops = GPIO_OPS,
.extra = GPIO_EXTRA
};

const struct no_os_gpio_init_param ltc2378_gpio_busy = {
.port = GPIO_BUSY_PORT_NUM,
.number = GPIO_BUSY_PIN_NUM,
.platform_ops = GPIO_OPS,
.extra = GPIO_EXTRA
};

const struct ltc2378_init_param ltc2378_ip = {
.spi_init = &ltc2378_spi_ip,
.gpio_cnv_init = &ltc2378_gpio_cnv,
.gpio_busy_init = &ltc2378_gpio_busy,
.vref_uv = LTC2378_DEFAULT_VREF_UV,
.input_mode = LTC2378_UNIPOLAR
};
48 changes: 48 additions & 0 deletions projects/ltc2378/src/common/common_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* @file common_data.h
* @brief Defines common data to be used by ltc2378 examples.
* @author Cherrence Sarip ([email protected])
********************************************************************************
* Copyright 2025(c) Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef __COMMON_DATA_H__
#define __COMMON_DATA_H__

#include "parameters.h"
#include "ltc2378.h"
#include "no_os_spi.h"
#include "iio_ltc2378.h"

extern struct no_os_uart_init_param uip;

extern const struct no_os_spi_init_param ltc2378_spi_ip;
extern const struct no_os_gpio_init_param ltc2378_gpio_cnv;
extern const struct no_os_gpio_init_param ltc2378_gpio_busy;
extern const struct ltc2378_init_param ltc2378_ip;

#endif /* __COMMON_DATA_H__ */
100 changes: 100 additions & 0 deletions projects/ltc2378/src/examples/basic/basic_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* @file basic_example.c
* @brief Basic example code for ltc2378 project
* @author Cherrence Sarip ([email protected])
********************************************************************************
* Copyright 2025(c) Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include "no_os_delay.h"
#include "no_os_print_log.h"
#include "no_os_spi.h"
#include "no_os_util.h"
#include "no_os_error.h"
#include "common_data.h"
#include "ltc2378.h"
#include "parameters.h"
#include <stdlib.h>
#include "no_os_gpio.h"
#include "maxim_gpio.h"

/*****************************************************************************
* @brief Basic example main execution.
*
* @return ret - Result of the example execution. If working correctly, will
* execute continuously the while(1) loop and will not return.
*******************************************************************************/

int example_main()
{
struct ltc2378_dev *dev;
int ret;

pr_info("Enter basic example \n");

struct no_os_uart_desc *uart_desc;

ret = no_os_uart_init(&uart_desc, &uip);
if (ret)
return ret;

no_os_uart_stdio(uart_desc);

ret = ltc2378_init(&dev, &ltc2378_ip);
if (ret) {
pr_info("Init failed: %d\n", ret);
return ret;
}

pr_info("VREF: %lu uV, Mode: %s\n",
dev->vref_uv,
(dev->input_mode == LTC2378_UNIPOLAR) ? "Unipolar" : "Bipolar");

while (1) {
uint32_t raw;
int32_t voltage_uv;

ret = ltc2378_read_raw(dev, &raw);
if (ret) {
pr_info("Read failed: %d\n", ret);
continue;
}

ret = ltc2378_raw_to_uv(dev, raw, &voltage_uv);
if (ret) {
pr_info("Convert failed: %d\n", ret);
continue;
}

pr_info("Raw: %lu, Voltage: %ld uV\n", raw, voltage_uv);

no_os_mdelay(BASIC_EXAMPLE_DELAY_MS);
}

return 0;
}
96 changes: 96 additions & 0 deletions projects/ltc2378/src/examples/iio_example/iio_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/********************************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the src/examples/iio_example folder to src/examples/iio

* @file iio_example.c
* @brief IIO example code for the ltc2378 project
* @author Cherrence Sarip ([email protected])
********************************************************************************
* Copyright 2025(c) Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "no_os_alloc.h"
#include "no_os_error.h"
#include "no_os_units.h"
#include "no_os_util.h"
#include "no_os_print_log.h"

#include "ltc2378.h"
#include "iio_ltc2378.h"
#include "iio_app.h"
#include "common_data.h"

/*******************************************************************************
* @brief IIO example main execution.
*
* @return ret - Result of the example execution. If working correctly, will
* execute continuously function iio_app_run and will not return.
*******************************************************************************/
int example_main()
{
int ret;

struct ltc2378_iio_desc *ltc2378_iio_desc;
struct ltc2378_iio_desc_init_param ltc2378_iio_ip = {
.ltc2378_init_param = &ltc2378_ip,
};

struct iio_app_desc *app;
struct iio_app_init_param app_init_param = { 0 };

ret = ltc2378_iio_init(&ltc2378_iio_desc, &ltc2378_iio_ip);
if (ret)
goto exit;

struct iio_app_device iio_devices[] = {
{
.name = "ltc2378-20",
.dev = ltc2378_iio_desc,
.dev_descriptor = ltc2378_iio_desc->iio_dev,
},
};

app_init_param.devices = iio_devices;
app_init_param.nb_devices = NO_OS_ARRAY_SIZE(iio_devices);
app_init_param.uart_init_params = uip;

ret = iio_app_init(&app, app_init_param);
if (ret)
goto remove_iio_ltc2378;

ret = iio_app_run(app);

iio_app_remove(app);

remove_iio_ltc2378:
ltc2378_iio_remove(ltc2378_iio_desc);
exit:
if (ret)
pr_info("Error!\n");
return ret;
}
3 changes: 3 additions & 0 deletions projects/ltc2378/src/examples/iio_example/iio_example.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IIOD = y
INCS += $(DRIVERS)/adc/ltc2378/iio_ltc2378.h
SRCS += $(DRIVERS)/adc/ltc2378/iio_ltc2378.c
Loading