Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
Revision 13:66c8e4ce4ff1, committed 2016-04-29
- Comitter:
- Adrian Suciu
- Date:
- Fri Apr 29 16:19:00 2016 +0300
- Parent:
- 11:2e67c719ce37
- Child:
- 14:ca5bf41ced84
- Commit message:
- Added driver for AD7791 and example for CN0216
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/cn0216_example/Makefile Fri Apr 29 16:19:00 2016 +0300 @@ -0,0 +1,90 @@ +# This file was automagically generated by mbed.org. For more information, +# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded + +GCC_BIN = +PROJECT = CN0216-MBED +ADI_LIBRARIES_PATH = ../../libraries +MBED_LIBRARIES_PATH = ../../mbed +OBJECTS = ./main.o $(ADI_LIBRARIES_PATH)/AD7791/AD7791.o $(ADI_LIBRARIES_PATH)/CN0216/CN0216.o +SYS_OBJECTS = $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/board.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/cmsis_nvic.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/hal_tick.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/mbed_overrides.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/retarget.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/startup_stm32f411xe.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_can.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cec.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cortex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_crc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma2d.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dsi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_eth.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_msp_template.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_gpio.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hcd.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2s.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2s_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_irda.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_iwdg.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_lptim.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_ltdc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_ltdc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_smartcard.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_nand.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_nor.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pccard.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pcd.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pcd_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pwr.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pwr_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_qspi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rcc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rcc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rng.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rtc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rtc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sai.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sai_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sd.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sdram.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_spdifrx.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_spi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sram.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_tim.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_tim_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_uart.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_usart.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_wwdg.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_fmc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_fsmc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_sdmmc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_usb.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/system_stm32f4xx.o +INCLUDE_PATHS = -I. -I$(MBED_LIBRARIES_PATH) -I$(ADI_LIBRARIES_PATH) -I$(ADI_LIBRARIES_PATH)/ad5270 -I$(ADI_LIBRARIES_PATH)/ad7791 -I$(ADI_LIBRARIES_PATH)/cn0216 -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM/TARGET_STM32F4 -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM +LIBRARY_PATHS = -L$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM +LIBRARIES = -lmbed +LINKER_SCRIPT = $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/STM32F411XE.ld + +############################################################################### +AS = $(GCC_BIN)arm-none-eabi-as +CC = $(GCC_BIN)arm-none-eabi-gcc +CPP = $(GCC_BIN)arm-none-eabi-g++ +LD = $(GCC_BIN)arm-none-eabi-gcc +OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy +OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump +SIZE = $(GCC_BIN)arm-none-eabi-size + +ifeq ($(HARDFP),1) + FLOAT_ABI = hard +else + FLOAT_ABI = softfp +endif + + +CPU = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=$(FLOAT_ABI) +CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -MMD -MP +CC_SYMBOLS = -DTARGET_RTOS_M4_M7 -DTARGET_FF_ARDUINO -DTOOLCHAIN_GCC_ARM -DTARGET_NUCLEO_F411RE -D__CORTEX_M4 -DTARGET_LIKE_MBED -DTARGET_CORTEX_M -D__FPU_PRESENT=1 -DTARGET_LIKE_CORTEX_M4 -DMBED_BUILD_TIMESTAMP=1458639619.11 -DTARGET_M4 -D__MBED__=1 -DTARGET_STM -DTARGET_STM32F4 -DTARGET_FF_MORPHO -DTOOLCHAIN_GCC -DTARGET_STM32F411RE -DARM_MATH_CM4 + +LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main -Wl,-Map=$(PROJECT).map,--cref +LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys + + +ifeq ($(DEBUG), 1) + CC_FLAGS += -DDEBUG -O0 +else + CC_FLAGS += -DNDEBUG -Os +endif + +.PHONY: all clean lst size + +all: $(PROJECT).bin $(PROJECT).hex size + + +clean: + rm -f $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS) $(DEPS) + + +.asm.o: + $(CC) $(CPU) -c -x assembler-with-cpp -o $@ $< +.s.o: + $(CC) $(CPU) -c -x assembler-with-cpp -o $@ $< +.S.o: + $(CC) $(CPU) -c -x assembler-with-cpp -o $@ $< + +.c.o: + $(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $< + +.cpp.o: + $(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 -fno-rtti $(INCLUDE_PATHS) -o $@ $< + + + +$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) + $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS) + + +$(PROJECT).bin: $(PROJECT).elf + $(OBJCOPY) -O binary $< $@ + +$(PROJECT).hex: $(PROJECT).elf + @$(OBJCOPY) -O ihex $< $@ + +$(PROJECT).lst: $(PROJECT).elf + @$(OBJDUMP) -Sdh $< > $@ + +lst: $(PROJECT).lst + +size: $(PROJECT).elf + $(SIZE) $(PROJECT).elf + +DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d) +-include $(DEPS) + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/cn0216_example/main.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,118 @@
+/**
+* @file main.cpp
+* @brief Main file for the CN0357-example project
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* Product: www.analog.com/EVAL-CN0357-ARDZ
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 "mbed.h"
+#include "CN0216.h"
+
+const float CAL_WEIGHT = (150.0);
+
+Serial pc(USBTX, USBRX); ///< Serial interface to the pc
+
+void flush_serial_buffer(void)
+{
+ while (pc.readable()) pc.getc();
+ return;
+}
+
+void display_data(uint32_t data, float weight)
+{
+ pc.printf("\r\nADC Input Voltage input = %f V", data); /* Send valid voltage input value */
+ pc.printf("\r\nSensor Input Weight = %f grams", weight); /* Send valid grams value */
+ pc.printf("\r\n");
+}
+
+/**
+ * Project entry-point - initializes the CN0357 shield, reads the data when the ADC is ready and outputs the sensor
+ * value in PPM
+ */
+
+//#define SINGLE_CONVERSION
+#define CONTINOUS_CONVERSION
+
+int main()
+{
+ /* Main variables */
+ CN0216 cn0216;
+#ifdef SINGLE_CONVERSION
+ cn0216.init(CAL_WEIGHT);
+#elif defined CONTINOUS_CONVERSION
+ cn0216.init(CAL_WEIGHT, 0x00, 0x07);
+#else
+#error define SINGLE_CONVERSION or CONTINOUS_CONVERSION, but not both
+#endif
+ /* Calibration sequence */
+
+ pc.printf("\r\n Calibrating zero scale. Remove all weights from scale. Press any key to begin ..");
+ while(!pc.readable());
+ flush_serial_buffer();
+ pc.printf("\r\n Calibrating . . . ");
+ cn0216.calibrate(CN0216::ZERO_SCALE_CALIBRATION);
+ pc.printf("done ! ");
+
+ pc.printf("\r\n Calibrating full scale. Put calibration weight on scale. Press any key to begin ..");
+ while(!pc.readable());
+ flush_serial_buffer();
+ pc.printf("\r\n Calibrating . . . ");
+ cn0216.calibrate(CN0216::FULL_SCALE_CALIBRATION);
+ pc.printf("done ! ");
+
+ pc.printf("\r\n Calibration successful ");
+ cn0216.calibrate(CN0216::COMPUTE_GRAM_PER_BIT);
+
+ /* Infinite loop */
+ while (1) {
+ wait_ms(1000);
+ {
+ uint32_t data = cn0216.read_u32();
+ float weight = cn0216.compute_weight(data); // Convert ADC data to voltage
+ display_data(data, weight); // Display data thru UART
+ }
+ }
+
+
+ /* Infinite loop, never returns. */
+}
+
--- a/examples/drvdiag/Makefile Thu Apr 21 18:01:41 2016 +0300 +++ b/examples/drvdiag/Makefile Fri Apr 29 16:19:00 2016 +0300 @@ -6,9 +6,9 @@ ADI_LIBRARIES_PATH = ../../libraries MBED_LIBRARIES_PATH = ../../mbed DRIVER_WRAPPER_PATH = ./driver_wrapper -OBJECTS = ./main.o $(DRIVER_WRAPPER_PATH)/cn0357_diag.o $(DRIVER_WRAPPER_PATH)/ad7790_diag.o $(DRIVER_WRAPPER_PATH)/ad5270_diag.o $(ADI_LIBRARIES_PATH)/AD7790/AD7790.o $(ADI_LIBRARIES_PATH)//AD5270/AD5270.o $(ADI_LIBRARIES_PATH)//cn0357/cn0357.o +OBJECTS = ./main.o $(DRIVER_WRAPPER_PATH)/cn0357_diag.o $(DRIVER_WRAPPER_PATH)/cn0216_diag.o $(DRIVER_WRAPPER_PATH)/ad7790_diag.o $(DRIVER_WRAPPER_PATH)/ad7791_diag.o $(DRIVER_WRAPPER_PATH)/ad5270_diag.o $(ADI_LIBRARIES_PATH)/AD7790/AD7790.o $(ADI_LIBRARIES_PATH)/AD7791/AD7791.o $(ADI_LIBRARIES_PATH)/AD5270/AD5270.o $(ADI_LIBRARIES_PATH)/cn0357/CN0357.o $(ADI_LIBRARIES_PATH)/cn0216/CN0216.o SYS_OBJECTS = $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/board.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/cmsis_nvic.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/hal_tick.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/mbed_overrides.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/retarget.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/startup_stm32f411xe.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_can.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cec.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cortex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_crc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma2d.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dsi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_eth.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_msp_template.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_gpio.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hcd.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2s.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2s_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_irda.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_iwdg.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_lptim.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_ltdc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_ltdc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_smartcard.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_nand.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_nor.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pccard.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pcd.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pcd_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pwr.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pwr_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_qspi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rcc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rcc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rng.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rtc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rtc_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sai.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sai_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sd.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sdram.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_spdifrx.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_spi.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sram.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_tim.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_tim_ex.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_uart.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_usart.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_wwdg.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_fmc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_fsmc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_sdmmc.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_usb.o $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/system_stm32f4xx.o -INCLUDE_PATHS = -I. -I$(MBED_LIBRARIES_PATH) -I$(ADI_LIBRARIES_PATH) -I$(ADI_LIBRARIES_PATH)/ad5270 -I$(ADI_LIBRARIES_PATH)/ad7790 -I$(ADI_LIBRARIES_PATH)/cn0357 -I$(DRIVER_WRAPPER_PATH) -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM/TARGET_STM32F4 -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM +INCLUDE_PATHS = -I. -I$(MBED_LIBRARIES_PATH) -I$(ADI_LIBRARIES_PATH) -I$(ADI_LIBRARIES_PATH)/ad5270 -I$(ADI_LIBRARIES_PATH)/ad7790 -I$(ADI_LIBRARIES_PATH)/ad7791 -I$(ADI_LIBRARIES_PATH)/cn0357 -I$(ADI_LIBRARIES_PATH)/cn0216 -I$(DRIVER_WRAPPER_PATH) -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM/TARGET_STM32F4 -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE -I$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM LIBRARY_PATHS = -L$(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM LIBRARIES = -lmbed LINKER_SCRIPT = $(MBED_LIBRARIES_PATH)/TARGET_NUCLEO_F411RE/TOOLCHAIN_GCC_ARM/STM32F411XE.ld
--- a/examples/drvdiag/config.h Thu Apr 21 18:01:41 2016 +0300 +++ b/examples/drvdiag/config.h Fri Apr 29 16:19:00 2016 +0300 @@ -45,24 +45,36 @@ * ********************************************************************************/ -#define AD7790_PRESENT -#define AD5270_PRESENT -#define CN0357_PRESENT +#define AD7791_PRESENT +#define CN0216_PRESENT +//#define AD7790_PRESENT +//#define AD5270_PRESENT +//#define CN0357_PRESENT #define SPI_LOW_LEVEL +#ifdef AD7791_PRESENT +#include "AD7791.h" +#include "ad7791_diag.h" +#endif + +#ifdef CN0216_PRESENT +#include "CN0216.h" +#include "cn0216_diag.h" +#endif + #ifdef AD7790_PRESENT #include "AD7790.h" -#include "AD7790_diag.h" +#include "ad7790_diag.h" #endif #ifdef AD5270_PRESENT #include "AD5270.h" -#include "AD5270_diag.h" +#include "ad5270_diag.h" #endif #ifdef CN0357_PRESENT #include "CN0357.h" -#include "CN0357_diag.h" +#include "cn0357_diag.h" #endif using namespace std; @@ -77,6 +89,17 @@ SPI spibus(SPI_MOSI, SPI_MISO, SPI_SCK); #endif +#ifdef AD7791_PRESENT +AD7791 ad7791(1.2, D8); +AD7791_Diag ad7791diag(ad7791); +#endif + +#ifdef CN0216_PRESENT +CN0216 cn0216; +CN0216_Diag cn0216diag(cn0216); +#endif + + #ifdef AD7790_PRESENT AD7790 ad7790(1.2, D8); AD7790_Diag ad7790diag(ad7790); @@ -90,4 +113,4 @@ #ifdef CN0357_PRESENT CN0357 cn0357; CN0357_Diag cn0357diag(cn0357); -#endif \ No newline at end of file +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/ad5270_diag.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,143 @@
+/**
+* @file ad5270_diag.cpp
+* @brief Source file for the AD5270 wrapper used by the driver diag
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 "ad5270_diag.h"
+
+#include "mbed.h"
+#include <stdio.h>
+#include <vector>
+#include <string>
+
+extern Serial pc;
+extern vector<string> cmdbuffer;
+
+AD5270_Diag::AD5270_Diag(AD5270& ad) : dut(ad)
+{
+
+}
+void AD5270_Diag::enable_50TP_programming()
+{
+ dut.enable_50TP_programming();
+ pc.printf("Enabled 50TP prog");
+
+}
+void AD5270_Diag::store_50TP()
+{
+ dut.store_50TP();
+ pc.printf("50TP stored");
+}
+void AD5270_Diag::disable_50TP_programming()
+{
+ dut.disable_50TP_programming();
+ pc.printf("Disabled 50TP prog");
+}
+
+void AD5270_Diag::write_RDAC()
+{
+ float res = strtof(cmdbuffer[1].c_str(), NULL);
+ dut.write_RDAC(res);
+ pc.printf("Wrote %f", res);
+}
+void AD5270_Diag::read_RDAC()
+{
+ pc.printf("Read %f", dut.read_RDAC());
+}
+void AD5270_Diag::write_cmd()
+{
+ uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ uint8_t regVal = strtol(cmdbuffer[2].c_str(), NULL, 16);
+ pc.printf("Returned %x: ", dut.write_cmd(reg, regVal));
+}
+
+void AD5270_Diag::set_HiZ()
+{
+ pc.printf("SDO set to HiZ");
+ dut.set_SDO_HiZ();
+}
+
+void AD5270_Diag::read_50TP_last_address(void)
+{
+ pc.printf("Returned %x:", dut.read_50TP_last_address());
+}
+void AD5270_Diag::read_50TP_memory(void)
+{
+ uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ pc.printf("Returned %x", dut.read_50TP_memory(reg));
+}
+
+void AD5270_Diag::write_ctrl_reg(void)
+{
+ uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.write_ctrl_reg(val);
+ pc.printf("Wrote %x to ctrl_reg", val );
+}
+void AD5270_Diag::read_ctrl_reg(void)
+{
+ pc.printf("Read %x from ctrl_reg", dut.read_ctrl_reg());
+}
+
+void AD5270_Diag::reset_RDAC(void)
+{
+ dut.reset_RDAC();
+ pc.printf("Resetted rdac");
+}
+void AD5270_Diag::change_mode(void)
+{
+ uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.change_mode(static_cast<AD5270::AD5270Modes_t>(val));
+ pc.printf("Changed mode to %x", val);
+}
+
+void AD5270_Diag::write_wiper_reg(void)
+{
+ uint16_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.write_wiper_reg(val);
+ pc.printf("Wrote %x to wiper", val);
+}
+void AD5270_Diag::read_wiper_reg(void)
+{
+ pc.printf("Read %x from wiper", dut.read_wiper_reg());
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/ad5270_diag.h Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,81 @@
+/**
+* @file ad5270_diag.h
+* @brief Header file for the AD5270 wrapper used by the driver diag
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 AD5270_DIAG_H_
+#define AD5270_DIAG_H_
+#include "AD5270.h"
+
+class AD5270_Diag
+{
+public:
+ AD5270_Diag(AD5270& ad);
+ void enable_50TP_programming(void);
+ void store_50TP(void);
+ void disable_50TP_programming(void);
+
+ void write_RDAC(void);
+ void read_RDAC(void);
+ void write_cmd(void);
+ void set_HiZ(void);
+
+ void read_50TP_last_address(void);
+ void read_50TP_memory(void);
+
+ void write_ctrl_reg(void);
+ void read_ctrl_reg(void);
+
+ void reset_RDAC(void);
+ void change_mode(void);
+
+ void write_wiper_reg(void);
+ void read_wiper_reg(void);
+
+private:
+ AD5270& dut;
+};
+
+
+#endif /* AD5270_DIAG_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/ad7790_diag.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,128 @@
+/**
+* @file ad7790_diag.cpp
+* @brief Source file for the AD7790 wrapper used by the driver diag
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 "mbed.h"
+#include <stdio.h>
+#include <vector>
+#include <string>
+#include "AD7790_diag.h"
+
+extern Serial pc;
+extern vector<string> cmdbuffer;
+
+AD7790_Diag::AD7790_Diag(AD7790& ad) : dut(ad)
+{
+
+}
+
+void AD7790_Diag::init()
+{
+
+}
+void AD7790_Diag::reset()
+{
+ dut.reset();
+ pc.printf("Reseted AD7790");
+}
+
+void AD7790_Diag::write_mode()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.write_mode_reg(regVal);
+ pc.printf("Wrote mode");
+}
+void AD7790_Diag::read_mode()
+{
+ pc.printf("Mode reg: %x ", dut.read_mode_reg());
+}
+
+void AD7790_Diag::write_filter()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.write_filter_reg(regVal);
+ pc.printf("Wrote filter");
+}
+void AD7790_Diag::read_filter()
+{
+ pc.printf("Returned: %x ", dut.read_filter_reg());
+}
+void AD7790_Diag::read_data()
+{
+ pc.printf("Data reg: %x ", dut.read_data_reg());
+}
+
+void AD7790_Diag::read_status()
+{
+ pc.printf("Status reg: %x ", dut.read_status_reg());
+}
+
+void AD7790_Diag::read_u16()
+{
+ pc.printf("Data reg: %x ", dut.read_u16());
+}
+void AD7790_Diag::read_voltage()
+{
+ pc.printf("Voltage: %f ", dut.read_voltage());
+}
+void AD7790_Diag::set_continous_mode()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.set_conversion_mode(static_cast<AD7790::AD7790Mode_t>(regVal));
+ pc.printf("Mode set to %d", regVal);
+}
+void AD7790_Diag::set_reference_voltage()
+{
+ float ref = strtof(cmdbuffer[1].c_str(), NULL);
+ dut.set_reference_voltage(ref);
+ pc.printf("Reference Voltage set to %f", ref);
+}
+
+void AD7790_Diag::set_channel()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.set_channel(static_cast<AD7790::AD7790Channel_t>(regVal));
+ pc.printf("Mode set to %d", regVal);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/ad7791_diag.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,134 @@
+/**
+* @file AD7791_diag.cpp
+* @brief Source file for the AD7791 wrapper used by the driver diag
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 "mbed.h"
+#include <stdio.h>
+#include <vector>
+#include <string>
+#include "AD7791_diag.h"
+
+extern Serial pc;
+extern vector<string> cmdbuffer;
+
+AD7791_Diag::AD7791_Diag(AD7791& ad) : dut(ad)
+{
+
+}
+
+void AD7791_Diag::init()
+{
+
+}
+void AD7791_Diag::reset()
+{
+ dut.reset();
+ pc.printf("Reseted AD7791");
+}
+
+void AD7791_Diag::write_mode()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.write_mode_reg(regVal);
+ pc.printf("Wrote mode");
+}
+void AD7791_Diag::read_mode()
+{
+ pc.printf("Mode reg: %x ", dut.read_mode_reg());
+}
+
+void AD7791_Diag::write_filter()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.write_filter_reg(regVal);
+ pc.printf("Wrote filter");
+}
+void AD7791_Diag::read_filter()
+{
+ pc.printf("Returned: %x ", dut.read_filter_reg());
+}
+void AD7791_Diag::read_data()
+{
+ pc.printf("Data reg: %x ", dut.read_data_reg());
+}
+
+void AD7791_Diag::read_status()
+{
+ pc.printf("Status reg: %x ", dut.read_status_reg());
+}
+
+void AD7791_Diag::read_u16()
+{
+ pc.printf("Data reg: %x ", dut.read_u16());
+}
+
+void AD7791_Diag::read()
+{
+ pc.printf("Data reg: %x ", dut.read_u32());
+}
+
+void AD7791_Diag::read_voltage()
+{
+ pc.printf("Voltage: %f ", dut.read_voltage());
+}
+void AD7791_Diag::set_continous_mode()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.set_conversion_mode(static_cast<AD7791::AD7791Mode_t>(regVal));
+ pc.printf("Mode set to %d", regVal);
+}
+void AD7791_Diag::set_reference_voltage()
+{
+ float ref = strtof(cmdbuffer[1].c_str(), NULL);
+ dut.set_reference_voltage(ref);
+ pc.printf("Reference Voltage set to %f", ref);
+}
+
+void AD7791_Diag::set_channel()
+{
+ uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ dut.set_channel(static_cast<AD7791::AD7791Channel_t>(regVal));
+ pc.printf("Mode set to %d", regVal);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/ad7791_diag.h Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,81 @@
+/**
+* @file ad7791_diag.h
+* @brief Header file for the AD7791 wrapper used by the driver diag
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 AD7791_DIAG_H_
+#define AD7791_DIAG_H_
+
+#include "AD7791.h"
+
+class AD7791_Diag
+{
+
+public:
+ AD7791_Diag(AD7791& ad);
+ void init(void);
+ void reset(void);
+ void write_mode(void);
+ void write_filter(void);
+ void read_mode(void);
+ void read_filter(void);
+ void read_data(void);
+ void read_status(void);
+ void read_u16(void);
+ void read();
+ void read_voltage(void);
+ void set_continous_mode(void);
+ void set_reference_voltage(void);
+ void set_channel(void);
+
+private:
+ AD7791& dut;
+};
+
+/*
+
+*/
+
+
+
+#endif /* AD7790_DIAG_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/cn0216_diag.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,35 @@
+#include "mbed.h"
+#include <stdio.h>
+#include <vector>
+#include <string>
+
+#include "cn0216_diag.h"
+
+extern Serial pc;
+extern vector<string> cmdbuffer;
+
+CN0216_Diag::CN0216_Diag(CN0216& cn) : dut(cn)
+{
+
+}
+
+void CN0216_Diag::init(void)
+{
+ uint16_t weight = strtol(cmdbuffer[1].c_str(), NULL, 10);
+ pc.printf("CN0216 initialized with %d calibration weight",weight);
+ dut.init(weight);
+}
+
+void CN0216_Diag::calibrate(void)
+{
+ uint8_t step = strtol(cmdbuffer[1].c_str(), NULL, 16);
+ pc.printf("Calibrating step %d ..",step);
+ dut.calibrate(static_cast<CN0216::CalibrationStep_t>(step));
+ pc.printf(".. DONE",step);
+}
+
+void CN0216_Diag::read_weight(void)
+{
+ pc.printf("Read weight is %f", dut.read_weight());
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/cn0216_diag.h Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,21 @@
+
+#ifndef CN0216_DIAG_H_
+#define CN0216_DIAG_H_
+#include "CN0216.h"
+
+class CN0216_Diag
+{
+public:
+ CN0216_Diag(CN0216& cn);
+
+ void init(void);
+ void calibrate(void);
+ void read_weight(void);
+
+
+private:
+ CN0216& dut;
+};
+
+
+#endif /* CN0216_DIAG_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/drvdiag/driver_wrapper/cn0357_diag.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,78 @@
+/**
+* @file cn0357_diag.cpp
+* @brief Source file for the CN0357 wrapper used by the driver diag
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 "mbed.h"
+#include <stdio.h>
+#include <vector>
+#include <string>
+#include "CN0357_diag.h"
+
+extern Serial pc;
+extern vector<string> cmdbuffer;
+
+CN0357_Diag::CN0357_Diag(CN0357& cn) : dut(cn)
+{
+
+}
+void CN0357_Diag::set_RDAC()
+{
+ float res = strtof(cmdbuffer[1].c_str(), NULL);
+ dut.set_RDAC_value(res);
+ pc.printf("Wrote %f", res);
+
+}
+void CN0357_Diag::read_ppm(void)
+{
+ pc.printf("Wrote %f", dut.read_ppm());
+}
+
+void CN0357_Diag::set_sensor_param(void)
+{
+ float range = strtof(cmdbuffer[1].c_str(), NULL);
+ float sens = strtof(cmdbuffer[2].c_str(), NULL);
+ sens = sens * pow(10, -9);
+ pc.printf("Suggested RDAC val: %f ", dut.set_sensor_parameters(range, sens));
+}
--- a/examples/drvdiag/driver_wrapper/cn0357_diag.h Thu Apr 21 18:01:41 2016 +0300 +++ b/examples/drvdiag/driver_wrapper/cn0357_diag.h Fri Apr 29 16:19:00 2016 +0300 @@ -63,4 +63,4 @@ }; -#endif /* AD5270_DIAG_H_ */ +#endif /* CN0357_DIAG_H_ */
--- a/examples/drvdiag/main.cpp Thu Apr 21 18:01:41 2016 +0300
+++ b/examples/drvdiag/main.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -83,7 +83,28 @@
pc.printf("writing 0x%x to SPI", spibyte);
pc.printf("\r\nreturned: 0x%x ", spibus.write(spibyte)); }},
#endif
- /* #### AD7790 #### */
+
+#ifdef AD7791_PRESENT
+ {"adrst", 0, [](){ad7791diag.reset();}},
+ {"adwrm", 1, [](){ad7791diag.write_mode();}},
+ {"adrdm", 0, [](){ad7791diag.read_mode();}},
+ {"adwrf", 1, [](){ad7791diag.write_filter();}},
+ {"adrdf", 0, [](){ad7791diag.read_filter();}},
+ {"adrdd", 0, [](){ad7791diag.read_data();}},
+ {"adrds", 0, [](){ad7791diag.read_status();}},
+ {"adread32", 0, [](){ad7791diag.read();}},
+ {"adread", 0, [](){ad7791diag.read_u16();}},
+ {"adreadv", 0, [](){ad7791diag.read_voltage();}},
+ {"adsetc", 1, [](){ad7791diag.set_continous_mode();}},
+ {"adsetref", 1, [](){ad7791diag.set_reference_voltage();}},
+ {"adsetch", 1, [](){ad7791diag.set_channel();}},
+#endif
+
+#ifdef CN0216_PRESENT
+ {"cninit" , 1, [](){cn0216diag.init();}},
+ {"cncal" , 1, [](){cn0216diag.calibrate();}},
+ {"cnrdw" , 0, [](){cn0216diag.read_weight();}},
+#endif
#ifdef AD7790_PRESENT
{"adrst", 0, [](){ad7790diag.reset();}},
@@ -180,9 +201,11 @@
}
int main()
-{
+{
+ ad7791.frequency(100000);
pc.printf("\r\n#### DrvDiag ####\r\n");
+
while(1) {
pc.printf("\r\nTX> ");
read_from_console();
--- a/libraries/ad7790/AD7790.cpp Thu Apr 21 18:01:41 2016 +0300
+++ b/libraries/ad7790/AD7790.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -61,7 +61,7 @@
PinName MOSI,
PinName MISO,
PinName SCK) :
- ad7790(MOSI, MISO, SCK), cs(CS), miso(MISO), _vref(reference_voltage), _PGA_gain(1)
+ miso(MISO), ad7790(MOSI, MISO, SCK), cs(CS), _vref(reference_voltage), _PGA_gain(1)
{
cs = true; // cs is active low
ad7790.format(8, _SPI_MODE);
--- a/libraries/ad7790/AD7790.h Thu Apr 21 18:01:41 2016 +0300
+++ b/libraries/ad7790/AD7790.h Fri Apr 29 16:19:00 2016 +0300
@@ -147,9 +147,10 @@
#endif
private:
+ DigitalIn miso;///< DigitalIn must be initialized before SPI to prevent pin MUX overwrite
SPI ad7790; ///< SPI instance of the AD7790
DigitalOut cs; ///< DigitalOut instance for the chipselect of the AD7790
- DigitalIn miso;
+
float _vref;
uint8_t _PGA_gain;
bool _continous_conversion;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libraries/ad7791/AD7791.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,393 @@
+/**
+* @file AD7791.cpp
+* @brief Source file for AD7791 ADC
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* Product: http://www.analog.com/ad7791
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 <stdint.h>
+#include "mbed.h"
+#include "AD7791.h"
+
+/**
+ * @brief AD7791 constructor, sets CS pin and SPI format
+ * @param CS - (optional)chip select of the AD7791
+ * @param MOSI - (optional)pin of the SPI interface
+ * @param MISO - (optional)pin of the SPI interface
+ * @param SCK - (optional)pin of the SPI interface
+ */
+AD7791::AD7791(float reference_voltage,
+ PinName CS,
+ PinName MOSI,
+ PinName MISO,
+ PinName SCK) :
+ miso(MISO), ad7791(MOSI, MISO, SCK), cs(CS), _vref(reference_voltage)
+{
+ cs = true; // cs is active low
+ ad7791.format(8, _SPI_MODE);
+ _continous_conversion = true;
+ _channel = DIFFERENTIAL;
+}
+
+/**
+ * @brief Set AD7791 SPI frequency
+ * @param hz - SPI bus frequency in hz
+ * @return none
+ */
+void AD7791::frequency(int hz)
+{
+ ad7791.frequency(hz);
+}
+
+/**
+ * @brief Resets the AD7791
+ * @return none
+ */
+void AD7791::reset()
+{
+ ad7791.format(8, _SPI_MODE);
+ cs = false;
+ wait_us(_DELAY_TIMING);
+ ad7791.write(_RESET);
+ ad7791.write(_RESET);
+ ad7791.write(_RESET);
+ ad7791.write(_RESET);
+ wait_us(_DELAY_TIMING);
+ cs = true;
+ _continous_conversion = true;
+}
+
+/**
+ * Sets the mode register. Also sets continous mode and range based on the value
+ * written in reg_val
+ * @param reg_val
+ */
+void AD7791::write_mode_reg(uint8_t reg_val)
+{
+ write_reg(MODE_REG, reg_val);
+ uint8_t continous_mode = (reg_val & 0xC0);
+ if(continous_mode == 0x00) {
+ _continous_conversion = true;
+ } else {
+ _continous_conversion = false;
+ }
+/* uint8_t range = (reg_val & 0x30);
+ _PGA_gain = 1 << (range >> 4);*/
+
+}
+
+/**
+ * Reads the mode register and returns its value
+ * @return value of the mode register
+ */
+uint8_t AD7791::read_mode_reg()
+{
+ return read_reg(MODE_REG);
+}
+
+/**
+ * Writes the filter register
+ * @param regValue value to be written.
+ */
+void AD7791::write_filter_reg(uint8_t reg_val)
+{
+ write_reg(FILTER_REG, reg_val);
+}
+
+/**
+ * Reads the filter register and returns its value
+ * @return the value of the filter register
+ */
+uint8_t AD7791::read_filter_reg()
+{
+ return read_reg(FILTER_REG);
+}
+
+/**
+ * Reads the data register and returns its value
+ * @return value of the data register
+ */
+uint32_t AD7791::read_data_reg()
+{
+ uint32_t data_result;
+ ad7791.format(8, _SPI_MODE);
+ cs = false;
+ ad7791.write(_DATA_READ | (static_cast<uint8_t>(_channel)));
+ data_result = ((ad7791.write(_DUMMY_BYTE)) << 16);
+ data_result |= ((ad7791.write(_DUMMY_BYTE)) << 8 );
+ data_result |= (ad7791.write(_DUMMY_BYTE));
+ cs = true;
+ return data_result;
+}
+
+/**
+ * Reads the status register of the ADC and returns its value
+ * @return value of the status reg
+ */
+uint8_t AD7791::read_status_reg()
+{
+ return read_reg(STATUS_REG);
+}
+
+
+/**
+ * @brief Enables/disables continous_conversion mode
+ * In Single Conversion mode, read_u16 method will read the MODE register of the ADC,
+ * then write the Start single conversion bit and wait for the DOUT/RDY pin to go low,
+ * When the pin is driven low, data register is read back from the ADC.
+ *
+ * In Continous conversion mode, read_u16 method will poll the DOUT/RDY pin, if it is low,
+ * the data register is read back from the ADC.
+ *
+ * @param mode
+ * true - continous conversion mode enabled
+ * false - single conversion mode enabled
+ */
+void AD7791::set_conversion_mode(AD7791Mode_t mode)
+{
+ uint8_t mode_reg_val;
+ mode_reg_val = read_mode_reg() & 0x3F;
+ mode_reg_val = mode_reg_val | (static_cast<uint8_t>(mode));
+ write_mode_reg(mode);
+}
+
+/**
+ * - From mbed AnalogIn API -
+ * @brief Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
+ * Depending on the conversion mode, this method will have different behavior. Conversion mode is set using
+ * set_continous_conversion_mode(bool).
+ *
+ * In Single Conversion mode, read_u16 method will read the MODE register of the ADC,
+ * then write the Start single conversion bit and wait for the DOUT/RDY pin to go low,
+ * When the pin is driven low, data register is read back from the ADC.
+ *
+ * In Continous conversion mode, read_u16 method will poll the DOUT/RDY pin, if it is low,
+ * the data register is read back from the ADC.
+ *
+ * @return 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
+ * returns -1 (0xFFFF) along with a debug message if conversion failed.
+ */
+uint32_t AD7791::read_u32(void)
+{
+ uint32_t data_result = 0;
+ ad7791.format(8, _SPI_MODE);
+ cs = false;
+ uint16_t timeout_cnt = 0;
+ if(_continous_conversion == false) {
+
+ uint8_t mode_reg = read_mode_reg();
+ wait_us(_DELAY_TIMING);
+
+ cs = false;
+ mode_reg = (mode_reg & 0x3F) | MD1; // mask single conversion bits
+ ad7791.write((MODE_REG << 4) | (static_cast<uint8_t>(_channel))); // start single conversion
+ ad7791.write(mode_reg);
+ timeout_cnt = _SINGLE_CONVERSION_TIMEOUT; // starts timeout
+ } else {
+ timeout_cnt = _CONTINOUS_CONVERSION_TIMEOUT; // starts timeout
+ }
+
+ while(miso) { // wait for the MISO pin to go low.
+ if(timeout_cnt) {
+ timeout_cnt--;
+ } else {
+ cs = true;
+#ifdef AD7791_DEBUG_MODE
+ printf("timeout occurred reading the AD7791. "); // error, MISO line didn't toggle
+#endif
+ return -1; // ERROR
+ }
+ wait_us(10);
+ }
+
+ ad7791.write(_DATA_READ | (static_cast<uint8_t>(_channel)));
+ data_result = ((ad7791.write(_DUMMY_BYTE)) << 16);
+ data_result |= ((ad7791.write(_DUMMY_BYTE)) << 8 );
+ data_result |= (ad7791.write(_DUMMY_BYTE));
+ cs = true;
+ return data_result;
+}
+
+uint16_t AD7791::read_u16(void)
+{
+ uint32_t data = read_u32();
+ return static_cast<uint16_t>((data & 0xffff00) >> 8);
+}
+
+/**
+ * @brief Reads a register of the AD7791
+ * @param address - address of the register
+ * @return value of the register
+ */
+uint16_t AD7791::read_reg(AD7791Register_t address)
+{
+ uint16_t data = address << 12;
+ data |= _DUMMY_BYTE;
+ data |= _READ_FLAG;
+ data |= (static_cast<uint8_t>(_channel) << 8);
+ return write_spi(data);
+}
+
+/**
+ * @brief Writes a register of the AD7791
+ * @param address - address of the register
+ * @param reg_val - value to be written
+ * @return none
+ *
+ */
+void AD7791::write_reg(AD7791Register_t address, uint8_t reg_val)
+{
+ uint16_t spi_data = address << 12;
+ spi_data |= reg_val;
+ spi_data |= (static_cast<uint8_t>(_channel) << 8);
+ write_spi(spi_data);
+}
+
+/**
+ * @brief Writes 16bit data to the AD7791 SPI interface
+ * @param reg_val to be written
+ * @return data returned by the AD7791
+ */
+uint16_t AD7791::write_spi(uint16_t reg_val)
+{
+ uint16_t data_result;
+ uint8_t upper_byte = (reg_val >> 8) & 0xFF;
+ uint8_t lower_byte = reg_val & 0xFF;
+ ad7791.format(8, _SPI_MODE);
+ cs = false;
+ data_result = (ad7791.write(upper_byte) << 8);
+ data_result |= ad7791.write(lower_byte);
+ cs = true;
+ return data_result;
+}
+
+/**
+ * Sets the reference voltage of the AD7790
+ * @param ref reference voltage to be set
+ */
+void AD7791::set_reference_voltage(float ref)
+{
+ _vref = ref;
+}
+
+/**
+ * Gets the reference voltage of the AD7790
+ * @return reference voltage
+ */
+float AD7791::get_reference_voltage(void)
+{
+ return _vref;
+}
+
+/**
+ * Reads the data register of the ADC and converts the result to volts
+ * Gain needs to be correctly set using set_gain in order to get accurate results
+ * @return voltage of the ADC input
+ */
+float AD7791::read_voltage(void)
+{
+ return data_to_voltage(read_u32());
+}
+
+/**
+ * Converts an uint16_t to voltage.
+ * Gain needs to be correctly set using set_gain in order to get accurate results
+ * @param data in uint16_t format
+ * @return float value of voltage (in V)
+ */
+float AD7791::data_to_voltage(uint32_t data)
+{
+ return ((data / static_cast<float>(_RESOLUTION / 2)) - 1) * (_vref );
+}
+
+/**
+ * Converts voltage to an uint16_t.
+ * Gain needs to be correctly set using set_gain in order to get accurate results
+ * @param voltage to be converted
+ * @return data in uint16_t format
+ */
+uint32_t AD7791::voltage_to_data(float voltage)
+{
+ return (((voltage / _vref) + 1) * static_cast<float>(_RESOLUTION / 2));
+}
+
+/**
+ * Sets the conversion channel.
+ * @param channel
+ */
+void AD7791::set_channel(AD7791Channel_t channel)
+{
+ _channel = channel;
+}
+
+/**
+ * - From mbed AnalogIn API -
+ * Read the input voltage, represented as a float in the range [0.0, 1.0] - uses the read_u16 method
+ * @returns A floating-point value representing the current input voltage, measured as a percentage
+ * returns 1.0 along with a debug message if the conversion failed
+ */
+float AD7791::read(void)
+{
+ float percent;
+ uint32_t data;
+ data = read_u32();
+ percent = (data / static_cast<float>(_RESOLUTION) ); // translate bipolar conversion to [0.0, 1.0] domain
+ return percent;
+}
+
+#ifdef MBED_OPERATORS
+
+/**
+ * - From mbed AnalogIn API -
+ * An operator shorthand for read()
+ * The float() operator can be used as a shorthand for read() to simplify common code sequences
+ */
+AD7791::operator float()
+{
+ return read();
+}
+
+#endif
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libraries/ad7791/AD7791.h Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,176 @@
+/**
+* @file AD7791.h
+* @brief Header file for AD7791 ADC
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* Product: http://www.analog.com/ad7791
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 AD7791_H
+#define AD7791_H
+
+#include "mbed.h"
+
+/**
+ * Comment this line if you want to turn off the debug mode.
+ * The debug mode will send a message if an exception occurs within AD7791 driver
+ */
+
+#define AD7791_DEBUG_MODE
+
+/**
+ * @brief Analog Devices AD7791 SPI 16-bit Buffered Sigma-Delta ADC
+ */
+class AD7791
+{
+public:
+ /// AD7791 registers
+ typedef enum {
+ COMMUNICATION_REG = 0, ///< Communication register
+ STATUS_REG = 0, ///< Status register
+ MODE_REG, ///< Mode register
+ FILTER_REG, ///< Filter Register
+ DATA_REG ///< Data register
+ } AD7791Register_t;
+
+ /// AD7791 channel configuration
+ typedef enum {
+ DIFFERENTIAL = 0, ///< AIN(+)-AIN(-)
+ RESERVED, ///< reserved
+ SHORT, ///< AIN(-)-AIN(-)
+ VDDMONITOR ///< Monitor VDD
+ } AD7791Channel_t;
+
+ typedef enum {
+ CONTINOUS_CONVERSION_MODE = 0,
+ SINGLE_CONVERSION_MODE = 0x80,
+ SHUTDOWN_MODE = 0xC0
+ } AD7791Mode_t;
+
+ typedef enum {
+ MD1 = 0x80, ///< Mode Select Bit 1
+ MD0 = 0x40, ///< Mode Select Bit 0
+// G1 = 0x20, ///< Range bit 1
+// G0 = 0x10, ///< Range bit 0
+ BO = 0x08, ///< Burnout Current Enable bit
+ UB = 0x04, ///< Unipolar/Bipolar bit
+ BUF = 0x02, ///< Buffered mode bit
+ } ModeRegisterBits_t;
+
+ typedef enum {
+ CLKDIV1 = 0x40, ///< Clock divider bit 1
+ CLKDIV0 = 0x20, ///< Clock divider bit 0
+ FS2 = 0x04, ///< Update rate bit 2
+ FS1 = 0x02, ///< Update rate bit 1
+ FS0 = 0x01, ///< Update rate bit 0
+ } FilterRegisterBits_t;
+
+/* typedef enum {
+ RANGE_VREF = 0,
+ RANGE_VREF_DIV_2,
+ RANGE_VREF_DIV_4,
+ RANGE_VREF_DIV_8,
+ } AnalogInputRange_t;
+*/
+ /** SPI configuration & constructor */
+ AD7791( float reference_voltage, PinName CS = SPI_CS, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK);
+ void frequency(int hz);
+
+ /** Low level SPI bus comm methods */
+ void reset(void);
+
+ /** Register access methods*/
+ void set_channel(AD7791Channel_t channel);
+ void set_conversion_mode(AD7791Mode_t mode);
+ uint32_t read_data_reg();
+ uint8_t read_status_reg(void);
+ void write_filter_reg(uint8_t regVal);
+ uint8_t read_filter_reg(void);
+ void write_mode_reg(uint8_t regVal);
+ uint8_t read_mode_reg(void);
+// void set_range(AnalogInputRange_t range);
+// AnalogInputRange_t get_range(void);
+
+ /** Reference voltage methods */
+ void set_reference_voltage(float ref);
+ float get_reference_voltage(void);
+
+ /** Voltage read methods */
+ float read_voltage(void);
+ float data_to_voltage(uint32_t data);
+ uint32_t voltage_to_data(float voltage);
+
+ /** AnalogIn API */
+ float read(void);
+ uint32_t read_u32(void);
+ uint16_t read_u16(void);
+
+#ifdef MBED_OPERATORS
+ operator float();
+#endif
+
+private:
+ DigitalIn miso;
+ SPI ad7791; ///< SPI instance of the AD7791
+ DigitalOut cs; ///< DigitalOut instance for the chipselect of the AD7791
+
+ float _vref;
+// uint8_t _PGA_gain;
+ bool _continous_conversion;
+ AD7791Channel_t _channel;
+
+ void write_reg(AD7791Register_t regAddress, uint8_t regValue);
+ uint16_t write_spi(uint16_t data);
+ uint16_t read_reg (AD7791Register_t regAddress);
+
+ const static uint16_t _SINGLE_CONVERSION_TIMEOUT = 0xFFFF; // in 10us = 100ms
+ const static uint16_t _CONTINOUS_CONVERSION_TIMEOUT = 0xFFFF;
+ const static uint32_t _RESOLUTION = 0xFFFFFF;
+ const static uint8_t _RESET = 0xFF;
+ const static uint8_t _DUMMY_BYTE = 0xFF;
+ const static uint16_t _READ_FLAG = 0x0800;
+ const static uint8_t _DATA_READ = 0x38; // Read from the Data Register
+ const static uint8_t _DELAY_TIMING = 0x02;
+ const static uint8_t _SPI_MODE = 3;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libraries/cn0216/CN0216.cpp Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,130 @@
+/**
+* @file cn0216.cpp
+* @brief Source file for CN0216
+* @author Analog Devices Inc.
+*
+* For support please go to:
+* Github: https://github.com/analogdevicesinc/mbed-adi
+* Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
+* Product: www.analog.com/EVAL-CN0216-ARDZ
+* More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
+
+********************************************************************************
+* Copyright 2016(c) Analog Devices, Inc.
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - 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.
+* - 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.
+* - The use of this software may or may not infringe the patent rights
+* of one or more patent holders. This license does not release you
+* from the requirement that you obtain separate licenses from these
+* patent holders to use this software.
+* - Use of the software either in source or binary form, must be run
+* on or directly connected to an Analog Devices Inc. component.
+*
+* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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 "mbed.h"
+#include "AD7791.h"
+#include "CN0216.h"
+extern Serial pc;
+
+ CN0216::CN0216(PinName CSAD7791, PinName MOSI, PinName MISO, PinName SCK) : ad7791(1.2, CSAD7791, MOSI, MISO, SCK)
+ {
+ _cal_weight = 0;
+ _zero_scale_value = 0;
+ _full_scale_value = 0;
+ _grams_per_bit = 0;
+
+ }
+ void CN0216::init(float cal_weight, uint8_t mode_val, uint8_t filter_val)
+ {
+ _cal_weight = cal_weight;
+ ad7791.frequency(500000);
+ wait_ms(50);
+ ad7791.reset();
+ wait_ms(50);
+ ad7791.write_mode_reg(mode_val);
+ wait_us(2);
+ ad7791.write_filter_reg(filter_val);
+ wait_ms(50);
+ }
+
+ void CN0216::calibrate(CalibrationStep_t cal)
+ {
+ uint64_t sum = 0;
+ uint32_t min = 0xFFFFFFFF;
+ uint32_t sample = 0;
+ switch(cal)
+ {
+ case ZERO_SCALE_CALIBRATION:
+ case FULL_SCALE_CALIBRATION:
+ for(int i = 0;i < _NUMBER_OF_SAMPLES;i++)
+ {
+ sample = ad7791.read_u32();
+ min = (min<sample) ? min : sample;
+ sum += ad7791.read_u32();
+ wait_us(5);
+ }
+ if(cal == ZERO_SCALE_CALIBRATION)
+ {
+ // pc.printf("ZERO SCALE VALUE = %x",sum);
+ _zero_scale_value = min;
+ }
+ else
+ {
+ // pc.printf("FULL SCALE VALUE = %x",sum);
+ sum = sum / _NUMBER_OF_SAMPLES;
+ _full_scale_value = sum;
+ }
+ break;
+
+ case COMPUTE_GRAM_PER_BIT:
+ _grams_per_bit = _cal_weight / (static_cast<float> (_full_scale_value - _zero_scale_value)); /* Calculate number of grams per LSB */
+ // pc.printf("GRAMS/LSB = %f", _grams_per_bit);
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ float CN0216::compute_weight(uint32_t data)
+ {
+// pc.printf("\r\nFULL_SCALE_VALUE = %x\r\nZERO_SCALE_VALUE = %x\r\nDATA READ = %x\r\nGRAMS/LSB = %f\r\n",_full_scale_value,data,_zero_scale_value,_grams_per_bit);
+ if(data<_zero_scale_value)
+ data = _zero_scale_value; // clamp data to 0
+ float weight_in_grams = (static_cast<float>((data) - _zero_scale_value)) * _grams_per_bit; /* Calculate weight */
+ return weight_in_grams;
+ }
+ uint32_t CN0216::read_u32()
+ {
+ return ad7791.read_u32();
+ }
+ float CN0216::read_weight()
+ {
+ uint32_t weight = read_u32();
+ return compute_weight(weight);
+ }
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libraries/cn0216/CN0216.h Fri Apr 29 16:19:00 2016 +0300
@@ -0,0 +1,40 @@
+
+#include "mbed.h"
+#include "AD7791.h"
+
+#ifndef CN0216_H_
+#define CN0216_H_
+
+class CN0216
+{
+public:
+ typedef enum
+ {
+ ZERO_SCALE_CALIBRATION,
+ FULL_SCALE_CALIBRATION,
+ COMPUTE_GRAM_PER_BIT
+ } CalibrationStep_t;
+
+ CN0216(PinName CSAD7791 = D8, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK);
+ void init(float cal_weight = _DEFAULT_CAL_WEIGHT, uint8_t mode_val = _DEFAULT_MODE_VAL, uint8_t filter_val = _DEFAULT_FILTER_VAL);
+ void calibrate(CalibrationStep_t cal);
+ float compute_weight(uint32_t data);
+ uint32_t read_u32();
+ float read_weight() ;
+
+private:
+
+ const static int _DEFAULT_MODE_VAL = AD7791::MD1 | AD7791::MD0; // POWERDOWN MODE
+ const static int _DEFAULT_FILTER_VAL = AD7791::FS0 | AD7791::FS1 | AD7791::FS2;
+ const static int _NUMBER_OF_SAMPLES = 50;
+ const static int _DEFAULT_CAL_WEIGHT = 1000.0;
+
+ AD7791 ad7791;
+ float _cal_weight;
+ uint32_t _zero_scale_value;
+ uint32_t _full_scale_value;
+ float _grams_per_bit;
+
+};
+
+#endif
CN0357 - Toxic gas measurement
CN0216 - Weight Scale