Skip to content

Commit 96499a6

Browse files
committed
projects: ltc2378: Add project for LTC2378
Add initial project files for both basic and IIO examples for LTC2378. Signed-off-by: Cherrence Sarip <cherrence.sarip@analog.com>
1 parent f21f6b3 commit 96499a6

File tree

12 files changed

+571
-0
lines changed

12 files changed

+571
-0
lines changed

projects/ltc2378/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
EXAMPLE ?= basic
2+
3+
include ../../tools/scripts/generic_variables.mk
4+
5+
include ../../tools/scripts/examples.mk
6+
7+
include src.mk
8+
9+
include ../../tools/scripts/generic.mk

projects/ltc2378/builds.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"maxim": {
3+
"basic_example": {
4+
"flags": "EXAMPLE=basic TARGET=max32665"
5+
},
6+
"iio": {
7+
"flags": "EXAMPLE=iio_example TARGET=max32665"
8+
}
9+
}
10+
}

projects/ltc2378/src.mk

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
INCS += $(INCLUDE)/no_os_delay.h \
2+
$(INCLUDE)/no_os_error.h \
3+
$(INCLUDE)/no_os_gpio.h \
4+
$(INCLUDE)/no_os_print_log.h \
5+
$(INCLUDE)/no_os_spi.h \
6+
$(INCLUDE)/no_os_alloc.h \
7+
$(INCLUDE)/no_os_irq.h \
8+
$(INCLUDE)/no_os_list.h \
9+
$(INCLUDE)/no_os_dma.h \
10+
$(INCLUDE)/no_os_uart.h \
11+
$(INCLUDE)/no_os_lf256fifo.h \
12+
$(INCLUDE)/no_os_util.h \
13+
$(INCLUDE)/no_os_units.h \
14+
$(INCLUDE)/no_os_mutex.h
15+
16+
SRCS += $(DRIVERS)/api/no_os_gpio.c \
17+
$(NO-OS)/util/no_os_lf256fifo.c \
18+
$(DRIVERS)/api/no_os_irq.c \
19+
$(DRIVERS)/api/no_os_spi.c \
20+
$(DRIVERS)/api/no_os_uart.c \
21+
$(DRIVERS)/api/no_os_dma.c \
22+
$(NO-OS)/util/no_os_list.c \
23+
$(NO-OS)/util/no_os_util.c \
24+
$(NO-OS)/util/no_os_alloc.c \
25+
$(NO-OS)/util/no_os_mutex.c
26+
27+
INCS += $(DRIVERS)/adc/ltc2378/ltc2378.h
28+
SRCS += $(DRIVERS)/adc/ltc2378/ltc2378.c
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*******************************************************************************
2+
* @file common_data.c
3+
* @brief Defines common data to be used by ltc2378 examples.
4+
* @author Cherrence Sarip (cherrence.sarip@analog.com)
5+
********************************************************************************
6+
* Copyright 2025(c) Analog Devices, Inc.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
19+
* contributors may be used to endorse or promote products derived from this
20+
* software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*******************************************************************************/
33+
34+
#include "common_data.h"
35+
#include <stdbool.h>
36+
#include "parameters.h"
37+
38+
struct no_os_uart_init_param uip = {
39+
.device_id = UART_DEVICE_ID,
40+
.irq_id = UART_IRQ_ID,
41+
.asynchronous_rx = true,
42+
.baud_rate = UART_BAUDRATE,
43+
.size = NO_OS_UART_CS_8,
44+
.parity = NO_OS_UART_PAR_NO,
45+
.stop = NO_OS_UART_STOP_1_BIT,
46+
.platform_ops = UART_OPS,
47+
.extra = UART_EXTRA,
48+
};
49+
50+
const struct no_os_spi_init_param ltc2378_spi_ip = {
51+
.device_id = SPI_DEVICE_ID,
52+
.max_speed_hz = SPI_MAX_SPEED,
53+
.chip_select = SPI_CS,
54+
.mode = NO_OS_SPI_MODE_0,
55+
.bit_order = NO_OS_SPI_BIT_ORDER_MSB_FIRST,
56+
.platform_ops = SPI_OPS,
57+
.extra = SPI_EXTRA,
58+
.parent = NULL,
59+
};
60+
61+
const struct no_os_gpio_init_param ltc2378_gpio_cnv = {
62+
.port = GPIO_CNV_PORT_NUM,
63+
.number = GPIO_CNV_PIN_NUM,
64+
.platform_ops = GPIO_OPS,
65+
.extra = GPIO_EXTRA
66+
};
67+
68+
const struct no_os_gpio_init_param ltc2378_gpio_busy = {
69+
.port = GPIO_BUSY_PORT_NUM,
70+
.number = GPIO_BUSY_PIN_NUM,
71+
.platform_ops = GPIO_OPS,
72+
.extra = GPIO_EXTRA
73+
};
74+
75+
const struct ltc2378_init_param ltc2378_ip = {
76+
.spi_init = &ltc2378_spi_ip,
77+
.gpio_cnv_init = &ltc2378_gpio_cnv,
78+
.gpio_busy_init = &ltc2378_gpio_busy,
79+
.vref_uv = LTC2378_DEFAULT_VREF_UV,
80+
.input_mode = LTC2378_UNIPOLAR
81+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*******************************************************************************
2+
* @file common_data.h
3+
* @brief Defines common data to be used by ltc2378 examples.
4+
* @author Cherrence Sarip (cherrence.sarip@analog.com)
5+
********************************************************************************
6+
* Copyright 2025(c) Analog Devices, Inc.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
19+
* contributors may be used to endorse or promote products derived from this
20+
* software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*******************************************************************************/
33+
#ifndef __COMMON_DATA_H__
34+
#define __COMMON_DATA_H__
35+
36+
#include "parameters.h"
37+
#include "ltc2378.h"
38+
#include "no_os_spi.h"
39+
#include "iio_ltc2378.h"
40+
41+
extern struct no_os_uart_init_param uip;
42+
43+
extern const struct no_os_spi_init_param ltc2378_spi_ip;
44+
extern const struct no_os_gpio_init_param ltc2378_gpio_cnv;
45+
extern const struct no_os_gpio_init_param ltc2378_gpio_busy;
46+
extern const struct ltc2378_init_param ltc2378_ip;
47+
48+
#endif /* __COMMON_DATA_H__ */
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*******************************************************************************
2+
* @file basic_example.c
3+
* @brief Basic example code for ltc2378 project
4+
* @author Cherrence Sarip (cherrence.sarip@analog.com)
5+
********************************************************************************
6+
* Copyright 2025(c) Analog Devices, Inc.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
19+
* contributors may be used to endorse or promote products derived from this
20+
* software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*******************************************************************************/
33+
34+
#include "no_os_delay.h"
35+
#include "no_os_print_log.h"
36+
#include "no_os_spi.h"
37+
#include "no_os_util.h"
38+
#include "no_os_error.h"
39+
#include "common_data.h"
40+
#include "ltc2378.h"
41+
#include "parameters.h"
42+
#include <stdlib.h>
43+
#include "no_os_gpio.h"
44+
#include "maxim_gpio.h"
45+
46+
/*****************************************************************************
47+
* @brief Basic example main execution.
48+
*
49+
* @return ret - Result of the example execution. If working correctly, will
50+
* execute continuously the while(1) loop and will not return.
51+
*******************************************************************************/
52+
53+
int example_main()
54+
{
55+
struct ltc2378_dev *dev;
56+
int ret;
57+
58+
pr_info("Enter basic example \n");
59+
60+
struct no_os_uart_desc *uart_desc;
61+
62+
ret = no_os_uart_init(&uart_desc, &uip);
63+
if (ret)
64+
return ret;
65+
66+
no_os_uart_stdio(uart_desc);
67+
68+
ret = ltc2378_init(&dev, &ltc2378_ip);
69+
if (ret) {
70+
pr_info("Init failed: %d\n", ret);
71+
return ret;
72+
}
73+
74+
pr_info("VREF: %lu uV, Mode: %s\n",
75+
dev->vref_uv,
76+
(dev->input_mode == LTC2378_UNIPOLAR) ? "Unipolar" : "Bipolar");
77+
78+
while (1) {
79+
uint32_t raw;
80+
int32_t voltage_uv;
81+
82+
ret = ltc2378_read_raw(dev, &raw);
83+
if (ret) {
84+
pr_info("Read failed: %d\n", ret);
85+
continue;
86+
}
87+
88+
ret = ltc2378_raw_to_uv(dev, raw, &voltage_uv);
89+
if (ret) {
90+
pr_info("Convert failed: %d\n", ret);
91+
continue;
92+
}
93+
94+
pr_info("Raw: %lu, Voltage: %ld uV\n", raw, voltage_uv);
95+
96+
no_os_mdelay(BASIC_EXAMPLE_DELAY_MS);
97+
}
98+
99+
return 0;
100+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/********************************************************************************
2+
* @file iio_example.c
3+
* @brief IIO example code for the ltc2378 project
4+
* @author Cherrence Sarip (cherrence.sarip@analog.com)
5+
********************************************************************************
6+
* Copyright 2025(c) Analog Devices, Inc.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
19+
* contributors may be used to endorse or promote products derived from this
20+
* software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*******************************************************************************/
33+
34+
#include <stdlib.h>
35+
#include <stdio.h>
36+
#include <string.h>
37+
#include "no_os_alloc.h"
38+
#include "no_os_error.h"
39+
#include "no_os_units.h"
40+
#include "no_os_util.h"
41+
#include "no_os_print_log.h"
42+
43+
#include "ltc2378.h"
44+
#include "iio_ltc2378.h"
45+
#include "iio_app.h"
46+
#include "common_data.h"
47+
48+
/*******************************************************************************
49+
* @brief IIO example main execution.
50+
*
51+
* @return ret - Result of the example execution. If working correctly, will
52+
* execute continuously function iio_app_run and will not return.
53+
*******************************************************************************/
54+
int example_main()
55+
{
56+
int ret;
57+
58+
struct ltc2378_iio_desc *ltc2378_iio_desc;
59+
struct ltc2378_iio_desc_init_param ltc2378_iio_ip = {
60+
.ltc2378_init_param = &ltc2378_ip,
61+
};
62+
63+
struct iio_app_desc *app;
64+
struct iio_app_init_param app_init_param = { 0 };
65+
66+
ret = ltc2378_iio_init(&ltc2378_iio_desc, &ltc2378_iio_ip);
67+
if (ret)
68+
goto exit;
69+
70+
struct iio_app_device iio_devices[] = {
71+
{
72+
.name = "ltc2378-20",
73+
.dev = ltc2378_iio_desc,
74+
.dev_descriptor = ltc2378_iio_desc->iio_dev,
75+
},
76+
};
77+
78+
app_init_param.devices = iio_devices;
79+
app_init_param.nb_devices = NO_OS_ARRAY_SIZE(iio_devices);
80+
app_init_param.uart_init_params = uip;
81+
82+
ret = iio_app_init(&app, app_init_param);
83+
if (ret)
84+
goto remove_iio_ltc2378;
85+
86+
ret = iio_app_run(app);
87+
88+
iio_app_remove(app);
89+
90+
remove_iio_ltc2378:
91+
ltc2378_iio_remove(ltc2378_iio_desc);
92+
exit:
93+
if (ret)
94+
pr_info("Error!\n");
95+
return ret;
96+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
IIOD = y
2+
INCS += $(DRIVERS)/adc/ltc2378/iio_ltc2378.h
3+
SRCS += $(DRIVERS)/adc/ltc2378/iio_ltc2378.c

0 commit comments

Comments
 (0)