Skip to content

Commit 9e49310

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 <[email protected]>
1 parent 8d57426 commit 9e49310

File tree

12 files changed

+567
-0
lines changed

12 files changed

+567
-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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*******************************************************************************
2+
* @file common_data.c
3+
* @brief Defines common data to be used by ltc2378 examples.
4+
* @author Cherrence Sarip ([email protected])
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+
37+
struct no_os_uart_init_param uip = {
38+
.device_id = UART_DEVICE_ID,
39+
.irq_id = UART_IRQ_ID,
40+
.asynchronous_rx = true,
41+
.baud_rate = UART_BAUDRATE,
42+
.size = NO_OS_UART_CS_8,
43+
.parity = NO_OS_UART_PAR_NO,
44+
.stop = NO_OS_UART_STOP_1_BIT,
45+
.platform_ops = UART_OPS,
46+
.extra = UART_EXTRA,
47+
};
48+
49+
const struct no_os_spi_init_param ltc2378_spi_ip = {
50+
.device_id = SPI_DEVICE_ID,
51+
.max_speed_hz = SPI_MAX_SPEED,
52+
.chip_select = SPI_CS,
53+
.mode = NO_OS_SPI_MODE_0,
54+
.bit_order = NO_OS_SPI_BIT_ORDER_MSB_FIRST,
55+
.platform_ops = SPI_OPS,
56+
.extra = SPI_EXTRA,
57+
.parent = NULL,
58+
};
59+
60+
const struct no_os_gpio_init_param ltc2378_gpio_cnv = {
61+
.port = GPIO_CNV_PORT_NUM,
62+
.number = GPIO_CNV_PIN_NUM,
63+
.platform_ops = GPIO_OPS,
64+
.extra = GPIO_EXTRA
65+
};
66+
67+
const struct no_os_gpio_init_param ltc2378_gpio_busy = {
68+
.port = GPIO_BUSY_PORT_NUM,
69+
.number = GPIO_BUSY_PIN_NUM,
70+
.platform_ops = GPIO_OPS,
71+
.extra = GPIO_EXTRA
72+
};
73+
74+
struct ltc2378_init_param ltc2378_ip = {
75+
.spi_init = &ltc2378_spi_ip,
76+
.gpio_cnv_init = &ltc2378_gpio_cnv,
77+
.gpio_busy_init = &ltc2378_gpio_busy,
78+
.vref_uv = 2500000,
79+
.input_mode = LTC2378_UNIPOLAR
80+
};
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 ([email protected])
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 struct ltc2378_init_param ltc2378_ip;
47+
48+
#endif /* __COMMON_DATA_H__ */
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*******************************************************************************
2+
* @file basic_example.c
3+
* @brief Basic example code for ltc2378 project
4+
* @author Cherrence Sarip ([email protected])
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 <stdlib.h>
42+
#include "no_os_gpio.h"
43+
#include "maxim_gpio.h"
44+
45+
/*****************************************************************************
46+
* @brief Basic example main execution.
47+
*
48+
* @return ret - Result of the example execution. If working correctly, will
49+
* execute continuously the while(1) loop and will not return.
50+
*******************************************************************************/
51+
52+
int example_main()
53+
{
54+
struct ltc2378_dev *dev;
55+
int ret;
56+
57+
pr_info("Enter basic example \n");
58+
59+
struct no_os_uart_desc *uart_desc;
60+
61+
ret = no_os_uart_init(&uart_desc, &uip);
62+
if (ret)
63+
return ret;
64+
65+
no_os_uart_stdio(uart_desc);
66+
67+
ret = ltc2378_init(&dev, &ltc2378_ip);
68+
if (ret) {
69+
pr_info("Init failed: %d\n", ret);
70+
return ret;
71+
}
72+
73+
pr_info("VREF: %lu uV, Mode: %s\n",
74+
dev->vref_uv,
75+
(dev->input_mode == LTC2378_UNIPOLAR) ? "Unipolar" : "Bipolar");
76+
77+
while (1) {
78+
uint32_t raw;
79+
int32_t voltage_uv;
80+
81+
ret = ltc2378_read_raw(dev, &raw);
82+
if (ret) {
83+
pr_info("Read failed: %d\n", ret);
84+
continue;
85+
}
86+
87+
ret = ltc2378_raw_to_uv(dev, raw, &voltage_uv);
88+
if (ret) {
89+
pr_info("Convert failed: %d\n", ret);
90+
continue;
91+
}
92+
93+
pr_info("Raw: %lu, Voltage: %ld uV\n", raw, voltage_uv);
94+
95+
no_os_mdelay(500);
96+
}
97+
98+
return 0;
99+
}
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 ([email protected])
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)