Skip to content

Commit 9086bd3

Browse files
committed
projects: admt4000: add examples for ADMT4000
Add initial project files and IIO example for ADMT4000. Signed-off-by: Louijie Compo <louijie.compo@analog.com>
1 parent e884890 commit 9086bd3

File tree

11 files changed

+669
-0
lines changed

11 files changed

+669
-0
lines changed

projects/admt4000/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# # Select the example measurement flows to include / enable
2+
# ADMT4000_BASIC = n # Basic Angles and Turns Measurement
3+
# ADMT4000_DIAG = n # Diagnostic Loop (i.e., temp, reference resistor etc.)
4+
# ADMT4000_TEST = n # Functional Configuration Test
5+
# ADMT4000_ECC = n # Demonstrate ECC computation flow
6+
ADMT4000_IIO = y # IIO compatible firmware (i.e., iio oscilloscope)
7+
8+
PLATFORM = mbed
9+
10+
EXAMPLE ?= iio_example
11+
12+
include ../../tools/scripts/generic_variables.mk
13+
14+
include ../../tools/scripts/examples.mk
15+
16+
include src.mk
17+
18+
include ../../tools/scripts/generic.mk

projects/admt4000/src.mk

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#############################################################################
2+
# #
3+
# Shared variables: #
4+
# - DRIVERS #
5+
# - INCLUDE #
6+
# - PLATFORM_DRIVERS #
7+
# - NO-OS #
8+
# #
9+
#############################################################################
10+
11+
include $(PROJECT)/src/app_src.mk
12+
13+
INCS += $(INCLUDE)/no_os_delay.h \
14+
$(INCLUDE)/no_os_dma.h \
15+
$(INCLUDE)/no_os_error.h \
16+
$(INCLUDE)/no_os_gpio.h \
17+
$(INCLUDE)/no_os_print_log.h \
18+
$(INCLUDE)/no_os_spi.h \
19+
$(INCLUDE)/no_os_irq.h \
20+
$(INCLUDE)/no_os_list.h \
21+
$(INCLUDE)/no_os_uart.h \
22+
$(INCLUDE)/no_os_lf256fifo.h \
23+
$(INCLUDE)/no_os_util.h \
24+
$(INCLUDE)/no_os_units.h \
25+
$(INCLUDE)/no_os_alloc.h \
26+
$(INCLUDE)/no_os_mutex.h \
27+
$(PROJECT)/src/platform/platform_includes.h
28+
29+
SRCS += $(DRIVERS)/api/no_os_dma.c \
30+
$(DRIVERS)/api/no_os_gpio.c \
31+
$(NO-OS)/util/no_os_lf256fifo.c \
32+
$(DRIVERS)/api/no_os_irq.c \
33+
$(DRIVERS)/api/no_os_spi.c \
34+
$(DRIVERS)/api/no_os_uart.c \
35+
$(NO-OS)/util/no_os_list.c \
36+
$(NO-OS)/util/no_os_util.c \
37+
$(NO-OS)/util/no_os_alloc.c \
38+
$(NO-OS)/util/no_os_mutex.c
39+
40+
INCS += $(DRIVERS)/magnetometer/admt4000/admt4000.h
41+
SRCS += $(DRIVERS)/magnetometer/admt4000/admt4000.c

projects/admt4000/src/app_src.mk

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
ifeq (y,$(strip $(ADMT4000_IIO)))
2+
IIOD=y
3+
CFLAGS += -DADMT4000_IIO=1
4+
SRCS += $(PROJECT)/src/examples/iio_example/iio_example.c
5+
INCS += $(PROJECT)/src/examples/iio_example/iio_example.h
6+
endif
7+
8+
ifeq (y,$(strip $(IIOD)))
9+
SRC_DIRS += $(NO-OS)/iio/iio_app
10+
INCS += $(DRIVERS)/magnetometer/admt4000/iio_admt4000.h
11+
SRCS += $(DRIVERS)/magnetometer/admt4000/iio_admt4000.c
12+
13+
INCS += $(INCLUDE)/no_os_list.h \
14+
$(PLATFORM_DRIVERS)/$(PLATFORM)_uart.h
15+
16+
endif
17+
18+
ifeq (y,$(strip $(ADMT4000_TEST)))
19+
CFLAGS += -DADMT4000_TEST=1
20+
SRCS += $(ADMT_EXAMPLES)/test/admt4000_function_test.c
21+
INCS += $(ADMT_EXAMPLES)/test/admt4000_function_test.h
22+
endif
23+
24+
ifeq (y,$(strip $(ADMT4000_BASIC)))
25+
CFLAGS += -DADMT4000_BASIC=1
26+
SRCS += $(ADMT_EXAMPLES)/basic_example/admt4000_basic.c
27+
INCS += $(ADMT_EXAMPLES)/basic_example/admt4000_basic.h
28+
endif
29+
30+
ifeq (y,$(strip $(ADMT4000_DIAG)))
31+
CFLAGS += -DADMT4000_DIAG=1
32+
SRCS += $(ADMT_EXAMPLES)/diagnostic_example/admt4000_diag_example.c
33+
INCS += $(ADMT_EXAMPLES)/diagnostic_example/admt4000_diag_example.h
34+
endif
35+
36+
ifeq (y,$(strip $(ADMT4000_ECC)))
37+
CFLAGS += -DADMT4000_ECC=1
38+
SRCS += $(ADMT_EXAMPLES)/ecc_example/admt4000_ecc.c
39+
INCS += $(ADMT_EXAMPLES)/ecc_example/admt4000_ecc.h
40+
endif
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
IIOD=y
2+
INCS += $(DRIVERS)/magnetometer/admt4000/iio_admt4000.h
3+
SRCS += $(DRIVERS)/magnetometer/admt4000/iio_admt4000.c
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/***************************************************************************//**
2+
* @file iio_example.c
3+
* @brief Source file for iio example.
4+
* @author Jose Ramon San Buenaventura (jose.sanbuenaventura@analog.com)
5+
* @author Louijie Compo (louijie.compo@analog.com)
6+
********************************************************************************
7+
* Copyright 2020(c) Analog Devices, Inc.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
*
15+
* 2. Redistributions in binary form must reproduce the above copyright notice,
16+
* this list of conditions and the following disclaimer in the documentation
17+
* and/or other materials provided with the distribution.
18+
*
19+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
20+
* contributors may be used to endorse or promote products derived from this
21+
* software without specific prior written permission.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
24+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
27+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
29+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
*******************************************************************************/
34+
#include "iio_example.h"
35+
#include "iio_admt4000.h"
36+
#include "platform_includes.h"
37+
#include "no_os_print_log.h"
38+
#include "iio_app.h"
39+
#include "no_os_util.h"
40+
41+
int iio_example_main()
42+
{
43+
int ret;
44+
45+
/** IIO descriptor and initialization parameter. */
46+
struct admt4000_iio_dev *admt4000_iio_desc;
47+
48+
struct admt4000_iio_dev_init_param admt4000_iio_ip = {
49+
.admt4000_dev_init = &admt_ip,
50+
};
51+
52+
/** IIO app. */
53+
struct iio_app_desc *app;
54+
struct iio_app_init_param app_init_param = { 0 };
55+
56+
ret = admt4000_iio_init(&admt4000_iio_desc, &admt4000_iio_ip);
57+
if (ret)
58+
goto exit;
59+
60+
/** Declaring iio_devices structure */
61+
struct iio_app_device iio_devices[] = {
62+
{
63+
.name = "admt4000",
64+
.dev = admt4000_iio_desc,
65+
.dev_descriptor = admt4000_iio_desc->iio_dev,
66+
},
67+
};
68+
69+
/** Initializing IIO app init param. */
70+
app_init_param.devices = iio_devices;
71+
app_init_param.nb_devices = NO_OS_ARRAY_SIZE(iio_devices);
72+
app_init_param.uart_init_params = uart_ip;
73+
74+
/** Initializing IIO app. */
75+
ret = iio_app_init(&app, app_init_param);
76+
if (ret)
77+
goto iio_admt4000_remove;
78+
79+
/** Running the IIO app (use iio_info or osc in terminal). */
80+
ret = iio_app_run(app);
81+
82+
iio_app_remove(app);
83+
84+
iio_admt4000_remove:
85+
admt4000_iio_remove(admt4000_iio_desc);
86+
exit:
87+
if (ret)
88+
pr_info("Error!\n");
89+
return ret;
90+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************//**
2+
* @file iio_example.h
3+
* @brief Header file for iio example.
4+
* @author JSanbuen(jose.sanbuenaventura@analog.com)
5+
* @author Louijie Compo (louijie.compo@analog.com)
6+
********************************************************************************
7+
* Copyright 2020(c) Analog Devices, Inc.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
*
15+
* 2. Redistributions in binary form must reproduce the above copyright notice,
16+
* this list of conditions and the following disclaimer in the documentation
17+
* and/or other materials provided with the distribution.
18+
*
19+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
20+
* contributors may be used to endorse or promote products derived from this
21+
* software without specific prior written permission.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
24+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
27+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
29+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
*******************************************************************************/
34+
#ifndef __IIO_EXAMPLE_H__
35+
#define __IIO_EXAMPLE_H__
36+
37+
int iio_example_main();
38+
39+
#endif /* __IIO_EXAMPLE_H__ */
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/***************************************************************************//**
2+
* @file main.c
3+
* @brief Main file for Mbed platform of admt4000 project
4+
* @author Jose Ramon San Buenaventura (jose.sanbuenaventura@analog.com)
5+
* Louijie Compo (louijie.compo@analog.com)
6+
********************************************************************************
7+
* Copyright 2024(c) Analog Devices, Inc.
8+
*
9+
* All rights reserved.
10+
*
11+
* Redistribution and use in source and binary forms, with or without
12+
* modification, are permitted provided that the following conditions are met:
13+
* - Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* - Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
* - Neither the name of Analog Devices, Inc. nor the names of its
20+
* contributors may be used to endorse or promote products derived
21+
* from this software without specific prior written permission.
22+
* - The use of this software may or may not infringe the patent rights
23+
* of one or more patent holders. This license does not release you
24+
* from the requirement that you obtain separate licenses from these
25+
* patent holders to use this software.
26+
* - Use of the software either in source or binary form, must be run
27+
* on or directly connected to an Analog Devices Inc. component.
28+
*
29+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
30+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
31+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32+
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
33+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34+
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
35+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
*******************************************************************************/
40+
41+
/******************************************************************************/
42+
/***************************** Include Files **********************************/
43+
/******************************************************************************/
44+
#include "platform_includes.h"
45+
#include "parameters.h"
46+
#include "no_os_delay.h"
47+
#include "no_os_print_log.h"
48+
#include "no_os_error.h"
49+
#include "admt4000.h"
50+
51+
#if (ADMT4000_BASIC)
52+
#include "admt4000_basic.h"
53+
#endif
54+
55+
#if (ADMT4000_DIAG)
56+
#include "admt4000_diag_example.h"
57+
#endif
58+
59+
#if (ADMT4000_ECC)
60+
#include "admt4000_ecc.h"
61+
#endif
62+
63+
#if (ADMT4000_TEST)
64+
#include "admt4000_function_test.h"
65+
#endif
66+
67+
#if (ADMT4000_IIO)
68+
#include "iio_example.h"
69+
#include "iio_app.h"
70+
#endif
71+
72+
/******************************************************************************/
73+
/********************** Macros and Constants Definitions **********************/
74+
/******************************************************************************/
75+
76+
/******************************************************************************/
77+
/************************ Functions Declarations ******************************/
78+
/******************************************************************************/
79+
80+
/***************************************************************************//**
81+
* @brief App main execution.
82+
*
83+
* @return ret - Result of the example execution. If working correctly, will
84+
* execute continuously the chosen example and will not return.
85+
*******************************************************************************/
86+
int main()
87+
{
88+
struct admt4000_dev *admt;
89+
struct no_os_uart_desc *uart_desc;
90+
struct no_os_spi_desc *spi_desc;
91+
int ret;
92+
uint8_t sw_cfg[1] = {0xff};
93+
94+
#if (ADMT4000_BASIC + ADMT4000_DIAG + ADMT4000_TEST + ADMT4000_ECC + ADMT4000_IIO > 1)
95+
#error Please enable only 1 example at a time.
96+
#elif (ADMT4000_BASIC + ADMT4000_DIAG + ADMT4000_TEST + ADMT4000_ECC + ADMT4000_IIO == 0)
97+
#error Please enable 1 example from the Makefile.
98+
#endif
99+
100+
/* Initialize SPI for switch configuration */
101+
ret = no_os_spi_init(&spi_desc, &spi_sel_b_spi_ip);
102+
if (ret)
103+
return ret;
104+
105+
/* Configure ADG714 over SPI using SPI_SEL_B_N pin */
106+
ret = no_os_spi_write_and_read(spi_desc, sw_cfg, 1);
107+
if (ret)
108+
return ret;
109+
110+
#if (ADMT4000_IIO)
111+
ret = iio_example_main();
112+
if (ret)
113+
goto error;
114+
#endif
115+
116+
no_os_mdelay(100);
117+
118+
/* Initialize UART */
119+
ret = no_os_uart_init(&uart_desc, &uart_ip);
120+
if (ret)
121+
return ret;
122+
123+
no_os_uart_stdio(uart_desc);
124+
125+
pr_info("\n SPI switch configured\n");
126+
127+
/* Initialize ADMT */
128+
ret = admt4000_init(&admt, admt_ip);
129+
if (ret)
130+
return ret;
131+
132+
#if (ADMT4000_BASIC)
133+
ret = basic_meas(admt);
134+
135+
#elif (ADMT4000_DIAG)
136+
ret = diag_meas(admt);
137+
138+
#elif (ADMT4000_ECC)
139+
ret = ecc_main(admt);
140+
141+
#elif (ADMT4000_TEST)
142+
ret = function_test(admt);
143+
#endif
144+
145+
error:
146+
#ifndef ADMT4000_IIO
147+
no_os_uart_remove(uart_desc);
148+
#endif
149+
admt4000_remove(admt);
150+
151+
return ret;
152+
}

0 commit comments

Comments
 (0)