-
Notifications
You must be signed in to change notification settings - Fork 1.8k
drivers:adc:ltc2378: Add support for LTC2378-20 #2794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
csarip
wants to merge
5
commits into
analogdevicesinc:main
Choose a base branch
from
csarip:dev/ltc2378-20
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5d1e43
drivers: adc: ltc2378: Add driver support for LTC2378
csarip 9e9bd76
drivers: adc: ltc2378: Add IIO support for LTC2378
csarip f21f6b3
drivers: adc: ltc2378: Add README documentation for LTC2378
csarip 96499a6
projects: ltc2378: Add project for LTC2378
csarip de506dc
projects: ltc2378: Add README documentation for project
csarip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = <c2378_spi_ip, | ||
| .gpio_cnv_init = <c2378_gpio_cnv, | ||
| .gpio_busy_init = <c2378_gpio_busy, | ||
| .vref_uv = LTC2378_DEFAULT_VREF_UV, | ||
| .input_mode = LTC2378_UNIPOLAR | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, <c2378_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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /******************************************************************************** | ||
| * @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 = <c2378_ip, | ||
| }; | ||
|
|
||
| struct iio_app_desc *app; | ||
| struct iio_app_init_param app_init_param = { 0 }; | ||
|
|
||
| ret = ltc2378_iio_init(<c2378_iio_desc, <c2378_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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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