Skip to content

Commit

Permalink
projects: ltc7841: Add project for LTC7841
Browse files Browse the repository at this point in the history
Add initial project files for both basic and IIO examples for LTC7841.
  • Loading branch information
MCabuena committed Jan 23, 2025
1 parent f8cb0d1 commit 1e50ae5
Show file tree
Hide file tree
Showing 12 changed files with 507 additions and 0 deletions.
8 changes: 8 additions & 0 deletions projects/ltc7841/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include ../../tools/scripts/generic_variables.mk

EXAMPLE := iio_example
include ../../tools/scripts/examples.mk

include src.mk

include ../../tools/scripts/generic.mk
10 changes: 10 additions & 0 deletions projects/ltc7841/builds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"maxim": {
"basic_example_max32690": {
"flags" : "EXAMPLE=basic TARGET=max32690"
},
"iio_example_max32690": {
"flags" : "EXAMPLE=iio_example TARGET=max32690"
}
}
}
19 changes: 19 additions & 0 deletions projects/ltc7841/src.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
NO_OS_INC_DIRS += \
$(INCLUDE) \
$(PROJECT)/src/ \
$(DRIVERS)/power/ltc7841 \

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

SRCS += $(DRIVERS)/power/ltc7841/ltc7841.c
56 changes: 56 additions & 0 deletions projects/ltc7841/src/common/common_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/***************************************************************************//**
* @file common_data.c
* @brief Defines common data to be used by ltc7841 examples.
* @author Marvin Cabuenas ([email protected])
********************************************************************************
* Copyright 2024(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"

struct no_os_uart_init_param uart_ip = {
.device_id = 2,
.asynchronous_rx = false,
.baud_rate = 115200,
.size = NO_OS_UART_CS_8,
.parity = NO_OS_UART_PAR_NO,
.stop = NO_OS_UART_STOP_1_BIT,
.extra = &uart_extra_ip,
.platform_ops = UART_OPS,
};

struct no_os_i2c_init_param ltc7841_i2c_ip = {
.device_id = LTC7841_I2C_DEVICE_ID,
.max_speed_hz = LTC7841_I2C_CLK_SPEED,
.slave_address = LTC7841_I2C_ADDR,
.platform_ops = I2C_OPS,
.extra = &ltc7841_i2c_extra,
};

struct ltc7841_init_param ltc7841_ip = {
.comm_param = &ltc7841_i2c_ip,
};
46 changes: 46 additions & 0 deletions projects/ltc7841/src/common/common_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/***************************************************************************//**
* @file common_data.h
* @brief Defines common data to be used by ltc7841 examples.
* @author Marvin Cabuenas ([email protected])
********************************************************************************
* Copyright 2024(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 "no_os_uart.h"
#include "no_os_util.h"
#include "no_os_delay.h"
#include "ltc7841.h"
#include "parameters.h"

extern struct no_os_uart_init_param uart_ip;

extern struct ltc7841_init_param ltc7841_ip;

#endif /* __COMMON_DATA_H__ */
124 changes: 124 additions & 0 deletions projects/ltc7841/src/examples/basic/basic_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/***************************************************************************//**
* @file basic_example.c
* @brief Basic example source file for ltp8800 project.
* @author Marvin Neil Cabuenas ([email protected])
********************************************************************************
* Copyright 2024(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 "no_os_delay.h"
#include "no_os_print_log.h"
#include "ltc7841.h"

int example_main(void)
{
uint8_t value[2];
int error;
struct ltc7841_desc *ltc7841_desc;
struct no_os_uart_desc *uart_desc;

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

no_os_uart_stdio(uart_desc);

error = ltc7841_init(&ltc7841_desc, NULL);
if (error != E_NO_ERROR) {
return error;
}
while (1) {
error = ltc7841_mfr_clear_peaks(ltc7841_desc);
if (error)
return error;
error = ltc7841_clear_status_word_bits(ltc7841_desc);
if (error)
return error;
/* read every readable register for checking*/
error = ltc7841_reg_read(ltc7841_desc, LTC7841_OPERATION, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_VOUT_MODE, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_STATUS_WORD, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_READ_VIN, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_READ_IIN, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_READ_VOUT, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_READ_IOUT, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_READ_TEMPERATURE_1, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_PMBUS_REVISION, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_IOUT_PEAK, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_VOUT_PEAK, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_VIN_PEAK, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_TEMEPRATURE1_PEAK, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_IIN_PEAK, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_VOUT_MARGIN_HIGH, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_SPECIAL_ID, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_VOUT_COMMAND, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_CONFIG, value);
if (error)
return error;
error = ltc7841_reg_read(ltc7841_desc, LTC7841_MFR_VOUT_MARGIN_LOW, value);
if (error)
return error;
no_os_mdelay(500);
}

return E_NO_ERROR;
}
81 changes: 81 additions & 0 deletions projects/ltc7841/src/examples/iio_example/iio_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/***************************************************************************//**
* @file iio_example.c
* @brief IIO example source file for ltc7841 project.
* @author Marvin Cabuenas ([email protected])
********************************************************************************
* Copyright 2024(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 "iio_app.h"
#include "iio_ltc7841.h"
#include "common_data.h"
#include "no_os_print_log.h"
#include "iio_app.h"

int example_main(void)
{
int ret;
struct ltc7841_iio_desc *ltc7841_iio_desc;
struct ltc7841_iio_desc_init_param ltc7841_iio_ip = {
.ltc7841_init_param = &ltc7841_ip,
.LTC7841_rsense_value = RSENSE_VALUE_DC2798A
};
struct iio_app_desc *app;
struct iio_app_init_param app_init_param = { 0 };

ret = ltc7841_iio_init(&ltc7841_iio_desc, &ltc7841_iio_ip);
if (ret)
goto exit;

struct iio_app_device iio_devices[] = {
{
.name = "ltc7841",
.dev = ltc7841_iio_desc,
.dev_descriptor = ltc7841_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 = uart_ip;

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

ret = iio_app_run(app);

iio_app_remove(app);

remove_iio_ltc7841:
ltc7841_iio_remove(ltc7841_iio_desc);
exit:
if (ret)
pr_err("Error!\n");

return ret;
}

4 changes: 4 additions & 0 deletions projects/ltc7841/src/examples/iio_example/iio_example.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IIOD=y

INCS += $(DRIVERS)/power/ltc7841/iio_ltc7841.h
SRCS += $(DRIVERS)/power/ltc7841/iio_ltc7841.c \
Loading

0 comments on commit 1e50ae5

Please sign in to comment.