diff --git a/doc/sphinx/source/drivers/led/ltc3208.rst b/doc/sphinx/source/drivers/led/ltc3208.rst new file mode 100644 index 00000000000..5988dc952bc --- /dev/null +++ b/doc/sphinx/source/drivers/led/ltc3208.rst @@ -0,0 +1 @@ +.. include:: ../../../../../drivers/led/ltc3208/README.rst \ No newline at end of file diff --git a/doc/sphinx/source/projects/led/ltc3208.rst b/doc/sphinx/source/projects/led/ltc3208.rst new file mode 100644 index 00000000000..c7f931deddd --- /dev/null +++ b/doc/sphinx/source/projects/led/ltc3208.rst @@ -0,0 +1 @@ +.. include:: ../../../../../projects/ltc3208/README.rst \ No newline at end of file diff --git a/doc/sphinx/source/projects_doc.rst b/doc/sphinx/source/projects_doc.rst index 01730a1ce08..c312ba56d87 100644 --- a/doc/sphinx/source/projects_doc.rst +++ b/doc/sphinx/source/projects_doc.rst @@ -98,4 +98,12 @@ GYROSCOPES :maxdepth: 1 :glob: - projects/gyroscope/* \ No newline at end of file + projects/gyroscope/* + +LED +=== +.. toctree:: + :maxdepth: 1 + :glob: + + projects/led/* diff --git a/drivers/led/ltc3208/README.rst b/drivers/led/ltc3208/README.rst new file mode 100644 index 00000000000..234e8631408 --- /dev/null +++ b/drivers/led/ltc3208/README.rst @@ -0,0 +1,80 @@ +LTC3208 no-OS driver +==================== + +.. no-os-doxygen:: + +Supported Devices +----------------- + +`LTC3208 `_ + +Overview +-------- + +The LTC3208 is a highly integrated multidisplay LED +controller. The part contains a 1A high efficiency, low noise +charge pump to provide power to the MAIN, SUB, RGB, CAM +and AUX LED displays. The LTC3208 requires only small +ceramic capacitors and one current set resistor to form a +complete LED power supply and current controller + +The maximum display currents are set by a single external resistor. +Current for each LED is controlled by a precision internal +current source. Dimming and On/Off for all displays is achieved +via the I2C serial interface. +256 brightness levels are available for the MAIN and SUB displays. +16 levels are available for the RGB and CAM displays. +Four AUX current sources can be independently +assigned via the I2C port to the CAM, SUB, MAIN or AUX +DAC controlled displays. + +Applications +------------ + +* Video/Camera Phones with QVGA + Displays + +LTC3208 Device Configuration +---------------------------- + +Driver Initialization +--------------------- + +In order to be able to use the device, you will have to provide the support for +the communication protocol (I2C) as mentioned above. + +The first API to be called is **ltc3208_init**. Make sure that it returns 0, +which means that the driver was initialized correctly. + +4-bit LED Configuration +----------------------- + +The following pairs share one register each pair to control the current level: + RED and GREEN - GREEN uses the hight bits and RED uses + the low bits. + BLUE and AUX - AUX uses the hight bits and BLUE uses + the low bits. + +The current level for cam is also split between the high current and low with +CAM_HIGH using the hight bits and CAM_LOW using the low bits. + +These current level can be controlled using **ltc3208_set_4_bit_dac**, +where it selects which register to change using an enumeration of the registers. + +8-bit LED Configuration +----------------------- + +The MAIN and SUB LEDS uses 255 levels to control current. + +These current level can be controlled using **ltc3208_set_8_bit_dac**, +where it selects which register to change using an enumeration of the registers. + +Device Options Configuration +---------------------------- + +The device can be forced to operate on a specific charge pump configuration, +enable dropout signal, choose if cam high or low is used, and choose if +ENRGBS pin controls RGB or SUB. This can be set individually via +**ltc3208_set_cpo_2x**, **ltc3208_set_1p5x**, +**ltc3208_set_droupout_enable**, **ltc3208_set_cam_enable**, +**ltc3208_set_sub_enable**, or directly to the register +via **ltc3208_update_options**. diff --git a/drivers/led/ltc3208/ltc3208.c b/drivers/led/ltc3208/ltc3208.c new file mode 100644 index 00000000000..1012da2556a --- /dev/null +++ b/drivers/led/ltc3208/ltc3208.c @@ -0,0 +1,419 @@ +/***************************************************************************//** + * @file ltc3208.c + * @brief Implementation of LTC3208 Driver + * @author Edelweise Escala (edelweise.escala@analog.com) +******************************************************************************** + * Copyright 2025(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 +#include +#include +#include +#include "ltc3208.h" +#include "no_os_i2c.h" +#include "no_os_util.h" +#include "no_os_delay.h" + +/***************************************************************************//** + * @brief Initializes the LTC3208 device structure. + * @param device - The device structure to initialize. + * @param init_param - The initialization parameters. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_init(struct ltc3208_dev **device, + struct ltc3208_init_param init_param) +{ + struct ltc3208_dev *dev; + int ret; + + dev = (struct ltc3208_dev *)no_os_calloc(1, sizeof(*dev)); + if (!dev) + return -ENOMEM; + + ret = no_os_i2c_init(&dev->i2c_desc, &init_param.i2c_init_param); + if (ret) + goto ltc3208_init_err; + + ret = no_os_gpio_get(&dev->gpio_enrgbs_desc, &init_param.gpio_init_param); + if (ret) + goto ltc3208_init_err; + + ret = no_os_gpio_direction_output(dev->gpio_enrgbs_desc, NO_OS_GPIO_HIGH); + if (ret) + goto ltc3208_init_err; + + *device = dev; + + return 0; + +ltc3208_init_err: + ltc3208_remove(dev); + return ret; +} + +/***************************************************************************//** + * @brief Deallocates the resources for the device structure. + * @param device - The device structure. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_remove(struct ltc3208_dev *device) +{ + int ret; + + if (!device) + return -ENODEV; + + if (device->i2c_desc) { + ret = no_os_i2c_remove(device->i2c_desc); + if (ret) + return ret; + + device->i2c_desc = NULL; + } + + if (device->gpio_enrgbs_desc) { + ret = no_os_gpio_remove(device->gpio_enrgbs_desc); + if (ret) + return ret; + + device->gpio_enrgbs_desc = NULL; + } + + no_os_free(device); + + return 0; +} + +/***************************************************************************//** + * @brief Writes to the selected register on the device. + * @param device - The device structure. + * @param reg_addr - The register sub-address. + * @param reg_data - The data to write into the register (8-bits wide) + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_reg_write(struct ltc3208_dev *device, uint8_t reg_addr, + uint8_t reg_data) +{ + uint8_t data_buffer[2] = {0}; + + if (reg_addr > LTC3208_REG_OPTIONS) + return -EINVAL; + + data_buffer[0] = reg_addr; + data_buffer[1] = reg_data; + + return no_os_i2c_write(device->i2c_desc, data_buffer, 2, 1); +} + +/***************************************************************************//** + * @brief Resets all register of the device. + * @param device - The device structure. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_reset(struct ltc3208_dev *device) +{ + int ret; + + ret = ltc3208_set_8_bit_dac(device, MAIN_REG, 0); + if (ret) + return ret; + + ret = ltc3208_set_8_bit_dac(device, SUB_REG, 0); + if (ret) + return ret; + + ret = ltc3208_set_4_bit_dac(device, GREEN_RED_REG, 0, 0); + if (ret) + return ret; + + ret = ltc3208_set_4_bit_dac(device, AUX_BLUE_REG, 0, 0); + if (ret) + return ret; + + ret = ltc3208_set_4_bit_dac(device, CAM_REG, 0, 0); + if (ret) + return ret; + + ret = ltc3208_update_options(device, 0, 0, 0, 0, 0); + if (ret) + return ret; + + return 0; +} + +/***************************************************************************//** + * @brief Sets the selected LED register's current strength + * @param device - The device structure. + * @param reg_selected - The enumeration value of the selected register. + * @param current_level - The current level for the LED group with 256 levels + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_8_bit_dac(struct ltc3208_dev *device, + enum reg_options reg_selected, + uint8_t current_level) +{ + uint8_t data; + uint8_t reg_addr; + + data = no_os_field_prep(LTC3208_8_BIT_MASK, current_level); + + switch (reg_selected) { + case MAIN_REG: + reg_addr = LTC3208_REG_MAIN; + break; + case SUB_REG: + reg_addr = LTC3208_REG_SUB; + break; + default: + return -EINVAL; + } + + return ltc3208_reg_write(device, reg_addr, data); +} + +/***************************************************************************//** + * @brief Sets the selected LED register's current strength + * @param device - The device structure. + * @param reg_selected - The enumeration value of the selected register. + * @param current_level_high - The current level for the high bits with 16 levels + * @param current_level_low - The current level for the low bits with 16 levels + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_4_bit_dac(struct ltc3208_dev *device, + enum reg_options reg_selected, + uint8_t current_level_high, + uint8_t current_level_low) +{ + uint8_t data; + uint8_t reg_addr; + + data = no_os_field_prep(LTC3208_4_BIT_HIGH_MASK, current_level_high) | + no_os_field_prep(LTC3208_4_BIT_LOW_MASK, current_level_low); + + switch (reg_selected) { + case GREEN_RED_REG: + reg_addr = LTC3208_REG_RED_GREEN; + break; + case AUX_BLUE_REG: + reg_addr = LTC3208_REG_BLUE_AUX; + break; + case CAM_REG: + reg_addr = LTC3208_REG_CAM_HIGH_LOW; + break; + default: + return -EINVAL; + } + + return ltc3208_reg_write(device, reg_addr, data); +} + +/***************************************************************************//** + * @brief Sets the DAC settings for each AUX LED + * @param device - The device structure. + * @param aux_dac_1 - The enumeration value of the selected DAC for AUX 1. + * @param aux_dac_2 - The enumeration value of the selected DAC for AUX 2. + * @param aux_dac_3 - The enumeration value of the selected DAC for AUX 3. + * @param aux_dac_4 - The enumeration value of the selected DAC for AUX 4. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_all_aux_led_dac(struct ltc3208_dev *device, + enum dac_options aux_dac_1, + enum dac_options aux_dac_2, + enum dac_options aux_dac_3, + enum dac_options aux_dac_4) +{ + int ret; + uint8_t data; + + data = no_os_field_prep(LTC3208_AUX1_MASK, aux_dac_1) | + no_os_field_prep(LTC3208_AUX2_MASK, aux_dac_2) | + no_os_field_prep(LTC3208_AUX3_MASK, aux_dac_3) | + no_os_field_prep(LTC3208_AUX4_MASK, aux_dac_4); + + ret = ltc3208_reg_write(device, LTC3208_REG_AUX_DAC_SEL, data); + if (ret) + return ret; + + device->aux_dac[3] = aux_dac_4; + device->aux_dac[2] = aux_dac_3; + device->aux_dac[1] = aux_dac_2; + device->aux_dac[0] = aux_dac_1; + return 0; +} + +/***************************************************************************//** + * @brief Sets the DAC settings for a specific AUX LED + * @param device - The device structure. + * @param aux_dac - The enumeration value of the selected DAC for AUX. + * @param aux_index - The auxillary led index (0..3). + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_aux_led_dac(struct ltc3208_dev *device, + enum dac_options aux_dac, + int aux_index) +{ + int i; + + enum dac_options aux_dac_values[4]; + + for (i = 0; i < 4; i++) { + if (i == aux_index) + aux_dac_values[i] = aux_dac; + else + aux_dac_values[i] = device->aux_dac[i]; + } + + return ltc3208_set_all_aux_led_dac(device, aux_dac_values[0], aux_dac_values[1], + aux_dac_values[2], aux_dac_values[3]); +} + +/***************************************************************************//** + * @brief Updates the options set on the device + * @param device - The device's structure. + * @param is_force_2x - Signals the device to use 2x voltage. + * @param is_force_1p5x - Sets the device to use 1.5x voltage. + * @param is_dropout_disable - Sets the device to use dropout. + * @param is_cam_high_enable - Sets the device to enable camera high current. + * @param is_sub_enable - Sets the device to enable rgb. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_update_options(struct ltc3208_dev *device, bool is_force_2x, + bool is_force_1p5x, bool is_dropout_disable, + bool is_cam_high_enable, bool is_sub_enable) +{ + int ret; + uint8_t data; + + data = no_os_field_prep(LTC3208_CPO_2X_BIT, is_force_2x) | + no_os_field_prep(LTC3208_CPO_1P5X_BIT, is_force_1p5x) | + no_os_field_prep(LTC3208_TEST_HOOK_1_MASK, 0) | + no_os_field_prep(LTC3208_TEST_HOOK_2_MASK, 0) | + no_os_field_prep(LTC3208_DROPOUT_BIT, is_dropout_disable) | + no_os_field_prep(LTC3208_CAM_BIT, is_cam_high_enable) | + no_os_field_prep(LTC3208_RGB_BIT, is_sub_enable); + + ret = ltc3208_reg_write(device, LTC3208_REG_OPTIONS, data); + + if (ret) + return ret; + + device->options_cfg.is_force_2x = is_force_2x; + device->options_cfg.is_force_1p5x = is_force_1p5x; + device->options_cfg.is_dropout_disable = is_dropout_disable; + device->options_cfg.is_cam_high = is_cam_high_enable; + device->options_cfg.is_sub_enable = is_sub_enable; + return 0; +} + +/***************************************************************************//** + * @brief Sets the device's charge pump to output 2x of operating voltage + * @param device - The device structure. + * @param is_force_2x - Signals the device to use 2x voltage. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_cpo_2x(struct ltc3208_dev *device, bool is_force_2x) +{ + return ltc3208_update_options(device, + is_force_2x, + device->options_cfg.is_force_1p5x, + device->options_cfg.is_dropout_disable, + device->options_cfg.is_cam_high, + device->options_cfg.is_sub_enable); +} + +/***************************************************************************//** + * @brief Sets the device's charge pump to output 1.5x of operating voltage + * @param device - The device structure. + * @param is_force_1p5x - Sets the device to use 1.5x voltage. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_1p5x(struct ltc3208_dev *device, bool is_force_1p5x) +{ + return ltc3208_update_options(device, + device->options_cfg.is_force_2x, + is_force_1p5x, + device->options_cfg.is_dropout_disable, + device->options_cfg.is_cam_high, + device->options_cfg.is_sub_enable); +} + +/***************************************************************************//** + * @brief Enables RGB and AUX4 dropout signals + * @param device - The device structure. + * @param is_dropout_disable - Sets the device to disable RGB and AUX4 dropout signals. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_droupout_disable(struct ltc3208_dev *device, + bool is_dropout_disable) +{ + return ltc3208_update_options(device, + device->options_cfg.is_force_2x, + device->options_cfg.is_force_1p5x, + is_dropout_disable, + device->options_cfg.is_cam_high, + device->options_cfg.is_sub_enable); +} + +/***************************************************************************//** + * @brief Selects which CAM register to use + * @param device - The device structure. + * @param is_cam_high_enable - Sets the device to enable camera high current. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_cam_high(struct ltc3208_dev *device, bool is_cam_high_enable) +{ + return ltc3208_update_options(device, + device->options_cfg.is_force_2x, + device->options_cfg.is_force_1p5x, + device->options_cfg.is_dropout_disable, + is_cam_high_enable, + device->options_cfg.is_sub_enable); +} + +/***************************************************************************//** + * @brief Selects if RGB or SUB is controled by ENRGBS pin + * @param device - The device structure. + * @param is_sub_enable - Sets the device to enable SUB displays. + * @return 0 in case of success, negative error code otherwise. +*******************************************************************************/ +int ltc3208_set_sub_enable(struct ltc3208_dev *device, bool is_sub_enable) +{ + return ltc3208_update_options(device, + device->options_cfg.is_force_2x, + device->options_cfg.is_force_1p5x, + device->options_cfg.is_dropout_disable, + device->options_cfg.is_cam_high, + is_sub_enable); +} diff --git a/drivers/led/ltc3208/ltc3208.h b/drivers/led/ltc3208/ltc3208.h new file mode 100644 index 00000000000..989c9c64128 --- /dev/null +++ b/drivers/led/ltc3208/ltc3208.h @@ -0,0 +1,256 @@ +/***************************************************************************//** + * @file ltc3208.h + * @brief Header file of LTC3208 Driver + * @author Edelweise Escala (edelweise.escala@analog.com) +******************************************************************************** + * Copyright 2025(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. +*******************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __LTC3208_H__ +#define __LTC3208_H__ + +#include "no_os_i2c.h" +#include "no_os_gpio.h" +#include "no_os_util.h" + +/* ltc3208 register addresses */ +#define LTC3208_REG_RED_GREEN 0x01 +#define LTC3208_REG_BLUE_AUX 0x02 +#define LTC3208_REG_MAIN 0x03 +#define LTC3208_REG_SUB 0X04 +#define LTC3208_REG_AUX_DAC_SEL 0x05 +#define LTC3208_REG_CAM_HIGH_LOW 0x06 +#define LTC3208_REG_OPTIONS 0x07 + +#define LTC3208_8_BIT_MASK NO_OS_GENMASK(7,0) +#define LTC3208_4_BIT_HIGH_MASK NO_OS_GENMASK(7,4) +#define LTC3208_4_BIT_LOW_MASK NO_OS_GENMASK(3,0) + +/* aux dac select register (0x05) */ +#define LTC3208_AUX4_MASK NO_OS_GENMASK(7,6) +#define LTC3208_AUX3_MASK NO_OS_GENMASK(5,4) +#define LTC3208_AUX2_MASK NO_OS_GENMASK(3,2) +#define LTC3208_AUX1_MASK NO_OS_GENMASK(1,0) + +/* options register (0x07) */ +#define LTC3208_CPO_2X_BIT NO_OS_BIT(7) +#define LTC3208_CPO_1P5X_BIT NO_OS_BIT(6) +#define LTC3208_TEST_HOOK_1_MASK NO_OS_BIT(5) +#define LTC3208_TEST_HOOK_2_MASK NO_OS_BIT(4) +#define LTC3208_DROPOUT_BIT NO_OS_BIT(3) +#define LTC3208_CAM_BIT NO_OS_BIT(2) +#define LTC3208_RGB_BIT NO_OS_BIT(1) + +enum dac_options { + AUX, + MAIN, + SUB, + CAM +}; + +enum reg_options { + GREEN_RED_REG, + AUX_BLUE_REG, + MAIN_REG, + SUB_REG, + CAM_REG +}; + +struct ltc3208_options_cfg { + bool is_force_2x; + bool is_force_1p5x; + bool is_dropout_disable; + bool is_cam_high; + bool is_sub_enable; +}; + +struct ltc3208_dev { + enum dac_options aux_dac[4]; + struct no_os_i2c_desc *i2c_desc; + struct no_os_gpio_desc *gpio_enrgbs_desc; + struct ltc3208_options_cfg options_cfg; +}; + +struct ltc3208_init_param { + struct no_os_i2c_init_param i2c_init_param; + struct no_os_gpio_init_param gpio_init_param; +}; + +/** + * @brief Initializes the LTC3208 device structure. + * @param device - The device structure to initialize. + * @param init_param - The initialization parameters. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_init(struct ltc3208_dev **device, + struct ltc3208_init_param init_param); + +/** + * @brief Deallocates the resources for the device structure. + * @param device - The device structure. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_remove(struct ltc3208_dev *device); + +/** + * @brief Writes to the selected register on the device. + * @param device - The device structure. + * @param reg_addr - The register sub-address. + * @param reg_data - The data to write into the register (8-bits wide) + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_reg_write(struct ltc3208_dev *device, uint8_t reg_addr, + uint8_t reg_data); + +/** + * @brief Resets all register of the device. + * @param device - The device structure. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_reset(struct ltc3208_dev *device); + +/** + * @brief Sets the selected 8 bit LED register's current strength + * @param device - The device structure. + * @param reg_selected - The enumeration value of the selected register. + * @param current_level - The current level for the LED group with 256 levels + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_8_bit_dac(struct ltc3208_dev *device, + enum reg_options reg_selected, + uint8_t current_level); + +/** + * @brief Sets the selected 4 bit LED register's current strength + * @param device - The device structure. + * @param reg_selected - The enumeration value of the selected register. + * @param current_level_high - The current level for the high bits with 16 levels + * @param current_level_low - The current level for the low bits with 16 levels + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_4_bit_dac(struct ltc3208_dev *device, + enum reg_options reg_selected, + uint8_t current_level_high, + uint8_t current_level_low); + +/** + * @brief Sets the DAC settings for each AUX LED + * @param device - The device structure. + * @param aux_dac_1 - The enumeration value of the selected DAC for AUX 1. + * @param aux_dac_2 - The enumeration value of the selected DAC for AUX 2. + * @param aux_dac_3 - The enumeration value of the selected DAC for AUX 3. + * @param aux_dac_4 - The enumeration value of the selected DAC for AUX 4. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_all_aux_led_dac(struct ltc3208_dev *device, + enum dac_options aux_dac_1, + enum dac_options aux_dac_2, + enum dac_options aux_dac_3, + enum dac_options aux_dac_4); +/** + * @brief Sets the DAC settings for a specific AUX LED + * @param device - The device structure. + * @param aux_dac - The enumeration value of the selected DAC for AUX. + * @param aux_index - The auxillary led index (0..3). + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_aux_led_dac(struct ltc3208_dev *device, + enum dac_options aux_dac, + int aux_index); + +/** + * @brief Updates the options set on the device + * @param device - The device's structure. + * @param is_force_2x - Signals the device to use 2x voltage. + * @param is_force_1p5x - Sets the device to use 1.5x voltage. + * @param is_dropout_disable - Sets the device to disable RGB and AUX4 dropout signals. + * @param is_cam_high_enable - Sets the device to enable camera high current. + * @param is_sub_enable - Sets the device to enable SUB displays. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_update_options(struct ltc3208_dev *device, bool is_force_2x, + bool is_force_1p5x, bool is_dropout_disable, + bool is_cam_high_enable, bool is_sub_enable); + +/** + * @brief Sets the device's charge pump to output 2x of operating voltage + * @param device - The device structure. + * @param is_force_2x - Signals the device to use 2x voltage. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_cpo_2x(struct ltc3208_dev *device, bool is_force_2x); + +/** + * @brief Sets the device's charge pump to output 1.5x of operating voltage + * @param device - The device structure. + * @param is_force_1p5x - Sets the device to use 1.5x voltage. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_1p5x(struct ltc3208_dev *device, bool is_force_1p5x); + +/** + * @brief Enables RGB and AUX4 dropout signals + * @param device - The device structure. + * @param is_dropout_disable - Sets the device to disable RGB and AUX4 dropout signals. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_droupout_disable(struct ltc3208_dev *device, + bool is_dropout_disable); + +/** + * @brief Selects which CAM register to use + * @param device - The device structure. + * @param is_cam_high_enable - Sets the device to enable camera high current. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_cam_high(struct ltc3208_dev *device, bool is_cam_high_enable); + +/** + * @brief Selects if RGB or SUB is controled by ENRGBS pin + * @param device - The device structure. + * @param is_sub_enable - Sets the device to enable SUB displays. + * @return 0 in case of success, negative error code otherwise. + */ +int ltc3208_set_sub_enable(struct ltc3208_dev *device, bool is_sub_enable); + + +#endif /*__LTC3208_H__*/ + +#ifdef __cplusplus +} +#endif diff --git a/projects/ltc3208/Makefile b/projects/ltc3208/Makefile new file mode 100644 index 00000000000..7c6ad641867 --- /dev/null +++ b/projects/ltc3208/Makefile @@ -0,0 +1,11 @@ +EXAMPLE ?= basic + +PLATFORM ?= maxim + +include ../../tools/scripts/generic_variables.mk + +include ../../tools/scripts/examples.mk + +include src.mk + +include ../../tools/scripts/generic.mk diff --git a/projects/ltc3208/README.rst b/projects/ltc3208/README.rst new file mode 100644 index 00000000000..9c833d2ae18 --- /dev/null +++ b/projects/ltc3208/README.rst @@ -0,0 +1,148 @@ +Evaluating the LTC3208 +====================== + + +Supported Evaluation Boards +--------------------------- + +* DC824A (LTC3208) + + +Overview +-------- + +The LTC3208 is a highly integrated multidisplay LED +controller. The part contains a 1A high efficiency, low noise +charge pump to provide power to the MAIN, SUB, RGB, CAM +and AUX LED displays. The LTC3208 requires only small +ceramic capacitors and one current set resistor to form a +complete LED power supply and current controller + +The maximum display currents are set by a single external resistor. +Current for each LED is controlled by a precision internal +current source. Dimming and On/Off for all displays is achieved +via the I2C serial interface. +256 brightness levels are available for the MAIN and SUB displays. +16 levels are available for the RGB and CAM displays. +Four AUX current sources can be independently +assigned via the I2C port to the CAM, SUB, MAIN or AUX +DAC controlled displays. + +Power Supply Requirements +------------------------- + +A seperate power supply capable of providing 3V. The logic signals used for the I2C protocol +uses 3.3V via the controller as a logic high reference. + +**Pin Description**: + ++-----+-----------+-------------------------------------------+ +| Pin | Name | Description | ++-----+-----------+-------------------------------------------+ +| 1 | CAM1 | Camera Display Current Source Output 1 | ++-----+-----------+-------------------------------------------+ +| 2 | CAM2 | Camera Display Current Source Output 2 | ++-----+-----------+-------------------------------------------+ +| 3 | CAM3 | Camera Display Current Source Output 3 | ++-----+-----------+-------------------------------------------+ +| 4 | CAM4 | Camera Display Current Source Output 4 | ++-----+-----------+-------------------------------------------+ +| 5 | AUX1 | Auxillary Display Current Source Output 1 | ++-----+-----------+-------------------------------------------+ +| 6 | AUX2 | Auxillary Display Current Source Output 2 | ++-----+-----------+-------------------------------------------+ +| 7 | AUX3 | Auxillary Display Current Source Output 3 | ++-----+-----------+-------------------------------------------+ +| 8 | AUX4 | Auxillary Display Current Source Output 4 | ++-----+-----------+-------------------------------------------+ +| 9 | CAMHL | CAM High Input | ++-----+-----------+-------------------------------------------+ +| 10 | SCL | I2C Clock Input | ++-----+-----------+-------------------------------------------+ +| 11 | SDA | I2C Data Input | ++-----+-----------+-------------------------------------------+ +| 12 | VBAT3 | Supply Voltage | ++-----+-----------+-------------------------------------------+ +| 14 | DVCC | Supply Voltage for all Digital I/O Lines | ++-----+-----------+-------------------------------------------+ +| 15 | MAIN1 | Main Display Current Source Output 1 | ++-----+-----------+-------------------------------------------+ +| 16 | MAIN2 | Main Display Current Source Output 2 | ++-----+-----------+-------------------------------------------+ +| 17 | MAIN3 | Main Display Current Source Output 3 | ++-----+-----------+-------------------------------------------+ +| 18 | MAIN4 | Main Display Current Source Output 4 | ++-----+-----------+-------------------------------------------+ +| 19 | SUB2 | Sub Display Current Source Output 2 | ++-----+-----------+-------------------------------------------+ +| 20 | SUB1 | Sub Display Current Source Output 1 | ++-----+-----------+-------------------------------------------+ +| 21 | BLUE | Blue LED Current Source Output | ++-----+-----------+-------------------------------------------+ +| 22 | GRN | Green LED Current Source Output | ++-----+-----------+-------------------------------------------+ +| 23 | RED | Red LED Current Source Output | ++-----+-----------+-------------------------------------------+ +| 24 | VBAT2 | Supply Voltage | ++-----+-----------+-------------------------------------------+ +| 25 | GND | Ground Pad | ++-----+-----------+-------------------------------------------+ +| 28 | ENRGBS | RGB Input | ++-----+-----------+-------------------------------------------+ +| 30 | VBAT1 | Supply Voltage | ++-----+-----------+-------------------------------------------+ +| 32 | CPO | Charge Pump Output | ++-----+-----------+-------------------------------------------+ +| 33 | GND | Ground Pad | ++-----+-----------+-------------------------------------------+ + +No-OS Build Setup +----------------- + +Please see: https://wiki.analog.com/resources/no-os/build + + +No-OS Supported Platforms +------------------------- + +The initialization data used in the examples is taken out from: +`Project Common Data Path `_ + +The macros used in Common data are defined in platfor-specific files found in: +`Project Platform Configuration Path `_ + +Maxim Platform +-------------- + +**Used Hardware** + +* `DC824A `_ + +**Connections**: + ++----------+-----------------------+ +| LTC3208 | MAX32655 Pinouts | ++----------+-----------------------+ +| V_IN | Power Supply | ++----------+-----------------------+ +| V_CC | 3v3 | ++----------+-----------------------+ +| GND | GND | ++----------+-----------------------+ +| I2C_SCL | P0_30 | ++----------+-----------------------+ +| I2C_SDA | P0_31 | ++----------+-----------------------+ + +** Build Command ** + +.. code-block:: bash + + # to delete current build + make reset + + #to build project + make TARGET=max32655 + + # to flash the code to the controller + make TARGET=max32655 run \ No newline at end of file diff --git a/projects/ltc3208/src.mk b/projects/ltc3208/src.mk new file mode 100644 index 00000000000..f4019017788 --- /dev/null +++ b/projects/ltc3208/src.mk @@ -0,0 +1,29 @@ +INCS += $(INCLUDE)/no_os_error.h \ + $(INCLUDE)/no_os_gpio.h \ + $(INCLUDE)/no_os_irq.h \ + $(INCLUDE)/no_os_list.h \ + $(INCLUDE)/no_os_uart.h \ + $(INCLUDE)/no_os_lf256fifo.h\ + $(INCLUDE)/no_os_dma.h \ + $(INCLUDE)/no_os_init.h \ + $(INCLUDE)/no_os_util.h \ + $(INCLUDE)/no_os_i2c.h \ + $(INCLUDE)/no_os_mutex.h \ + $(INCLUDE)/no_os_print_log.h \ + $(INCLUDE)/no_os_alloc.h \ + $(INCLUDE)/no_os_delay.h + +SRCS += $(DRIVERS)/api/no_os_gpio.c \ + $(DRIVERS)/api/no_os_irq.c \ + $(NO-OS)/util/no_os_list.c \ + $(DRIVERS)/api/no_os_uart.c \ + $(NO-OS)/util/no_os_lf256fifo.c \ + $(DRIVERS)/api/no_os_dma.c \ + $(DRIVERS)/api/no_os_i2c.c \ + $(NO-OS)/util/no_os_util.c \ + $(NO-OS)/util/no_os_mutex.c \ + $(NO-OS)/util/no_os_alloc.c + + +INCS += $(DRIVERS)/led/ltc3208/ltc3208.h +SRCS += $(DRIVERS)/led/ltc3208/ltc3208.c diff --git a/projects/ltc3208/src/common/common_data.c b/projects/ltc3208/src/common/common_data.c new file mode 100644 index 00000000000..027830faff9 --- /dev/null +++ b/projects/ltc3208/src/common/common_data.c @@ -0,0 +1,55 @@ +/***************************************************************************//** + * @file common_data.c + * @brief Defines common data to be used by LTC3208 examples. + * @author Edelweise Escala (edelweise.escala@analog.com) +******************************************************************************** + * Copyright 2025(c) Analog Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of Analog Devices, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "common_data.h" + +const struct no_os_i2c_init_param iip = { + .device_id = I2C_DEVICE_ID, + .max_speed_hz = 400000, + .slave_address = DEV_I2C_ADDRESS, + .platform_ops = I2C_OPS, + .extra = <c3208_i2c_extra, +}; + +const struct no_os_gpio_init_param gip = { + .port = GPIO_ENRGBS_PIN_PORT, + .number = GPIO_ENRGBS_PIN_NUM, + .pull = NO_OS_PULL_NONE, + .platform_ops = GPIO_OPS, + .extra = <c3208_gpio_extra, +}; + +struct ltc3208_init_param ltc3208_user_init = { + .i2c_init_param = iip, + .gpio_init_param = gip +}; diff --git a/projects/ltc3208/src/common/common_data.h b/projects/ltc3208/src/common/common_data.h new file mode 100644 index 00000000000..2babdd5bf5c --- /dev/null +++ b/projects/ltc3208/src/common/common_data.h @@ -0,0 +1,43 @@ +/***************************************************************************//** + * @file common_data.h + * @brief Defines common data to be used by LTC3208 examples. + * @author Edelweise Escala (edelweise.escala@analog.com) +******************************************************************************** + * Copyright 2025(c) Analog Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of Analog Devices, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __COMMON_DATA_H__ +#define __COMMON_DATA_H__ + +#include "parameters.h" +#include "ltc3208.h" + +extern const struct no_os_i2c_init_param iip; +extern const struct no_os_gpio_init_param gip; +extern struct ltc3208_init_param ltc3208_user_init; + +#endif /* __COMMON_DATA_H__ */ \ No newline at end of file diff --git a/projects/ltc3208/src/examples/basic/basic_example.c b/projects/ltc3208/src/examples/basic/basic_example.c new file mode 100644 index 00000000000..29ffd7f89e2 --- /dev/null +++ b/projects/ltc3208/src/examples/basic/basic_example.c @@ -0,0 +1,354 @@ +/******************************************************************************* + * @file basic_example.c + * @brief Basic example code for LTC3208 project + * @author Edelweise Escala (edelweise.escala@analog.com) + ******************************************************************************** + * Copyright 2023(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 "basic_example.h" +#include "ltc3208.h" +#include "no_os_delay.h" +#include "no_os_print_log.h" + +/***************************************************************************** + * @brief Basic example RGB LED test. + * + * @return ret - Result of the example execution. If working correctly, will + * execute continuously the while(1) loop and will not return. + *******************************************************************************/ +int test_rgb(struct ltc3208_dev *dev) +{ + int ret; + + ret = ltc3208_set_4_bit_dac(dev, GREEN_RED_REG, 8, 0); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_4_bit_dac(dev, GREEN_RED_REG, 0, 8); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_4_bit_dac(dev, GREEN_RED_REG, 0, 0); + if (ret) + return ret; + + ret = ltc3208_set_4_bit_dac(dev, AUX_BLUE_REG, 0, 8); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_4_bit_dac(dev, GREEN_RED_REG, 8, 8); + if (ret) + return ret; + + return 0; +} + +/***************************************************************************** + * @brief Basic example AUX LED test. + * + * @return ret - Result of the example execution. If working correctly, will + * execute continuously the while(1) loop and will not return. + *******************************************************************************/ +int test_aux(struct ltc3208_dev *dev) +{ + int ret; + + ret = ltc3208_set_4_bit_dac(dev, AUX_BLUE_REG, 8, 8); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_all_aux_led_dac(dev, MAIN, MAIN, MAIN, MAIN); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_all_aux_led_dac(dev, SUB, SUB, SUB, SUB); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_all_aux_led_dac(dev, CAM, CAM, CAM, CAM); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_aux_led_dac(dev, MAIN, 2); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_aux_led_dac(dev, SUB, 1); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_aux_led_dac(dev, AUX, 3); + if (ret) + return ret; + + return 0; +} + +/***************************************************************************** + * @brief Basic example CAM LED test. + * + * @return ret - Result of the example execution. If working correctly, will + * execute continuously the while(1) loop and will not return. + *******************************************************************************/ +int test_cam(struct ltc3208_dev *dev) +{ + int ret; + + ret = ltc3208_set_4_bit_dac(dev, CAM_REG, 14, 1); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_cam_high(dev, true); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_cam_high(dev, false); + if (ret) + return ret; + + no_os_mdelay(1000); + + + return 0; +} + +/***************************************************************************** + * @brief Basic example ENRGBS pin test. + * + * @return ret - Result of the example execution. If working correctly, will + * execute continuously the while(1) loop and will not return. + *******************************************************************************/ +int test_enrgbs(struct ltc3208_dev *dev) +{ + int ret; + + ret = ltc3208_set_sub_enable(dev, false); + if (ret) + return ret; + + ret = no_os_gpio_set_value(dev->gpio_enrgbs_desc, NO_OS_GPIO_LOW); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = no_os_gpio_set_value(dev->gpio_enrgbs_desc, NO_OS_GPIO_HIGH); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_sub_enable(dev, true); + if (ret) + return ret; + + ret = no_os_gpio_set_value(dev->gpio_enrgbs_desc, NO_OS_GPIO_LOW); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = no_os_gpio_set_value(dev->gpio_enrgbs_desc, NO_OS_GPIO_HIGH); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_sub_enable(dev, false); + if (ret) + return ret; + + ret = no_os_gpio_set_value(dev->gpio_enrgbs_desc, NO_OS_GPIO_LOW); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = no_os_gpio_set_value(dev->gpio_enrgbs_desc, NO_OS_GPIO_HIGH); + if (ret) + return ret; + + no_os_mdelay(1000); + + return 0; +} + +/***************************************************************************** + * @brief Basic example Dropout test. + * + * @return ret - Result of the example execution. If working correctly, will + * execute continuously the while(1) loop and will not return. + *******************************************************************************/ +int test_dropout(struct ltc3208_dev *dev) +{ + int ret; + + ret = ltc3208_set_8_bit_dac(dev, SUB_REG, 0); + if (ret) + return ret; + + ret = ltc3208_set_4_bit_dac(dev, CAM_REG, 0, 0); + if (ret) + return ret; + + ret = ltc3208_set_4_bit_dac(dev, AUX_BLUE_REG, 8, 15); + if (ret) + return ret; + + ret = ltc3208_set_droupout_disable(dev, true); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_4_bit_dac(dev, GREEN_RED_REG, 8, 13); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_4_bit_dac(dev, GREEN_RED_REG, 8, 9); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_4_bit_dac(dev, AUX_BLUE_REG, 8, 13); + if (ret) + return ret; + + no_os_mdelay(1000); + + ret = ltc3208_set_all_aux_led_dac(dev, AUX, AUX, AUX, AUX); + if (ret) + return ret; + + ret = ltc3208_set_4_bit_dac(dev, AUX_BLUE_REG, 8, 9); + if (ret) + return ret; + + no_os_mdelay(1000); + + return 0; +} + +/***************************************************************************** + * @brief Basic example main execution. + * + * @return ret - Result of the example execution. If working correctly, will + * execute continuously the while(1) loop and will not return. + *******************************************************************************/ +int example_main() +{ + int ret; + struct ltc3208_dev *dev; + + ret = ltc3208_init(&dev, ltc3208_user_init); + if (ret) + goto error; + + while (1) { + ret = ltc3208_reset(dev); + if (ret) + goto free_dev; + + no_os_mdelay(1000); + + ret = ltc3208_set_8_bit_dac(dev, MAIN_REG, 40); + if (ret) + goto free_dev; + + no_os_mdelay(500); + + ret = ltc3208_set_8_bit_dac(dev, SUB_REG, 20); + if (ret) + goto free_dev; + + no_os_mdelay(500); + + ret = test_cam(dev); + if (ret) + goto free_dev; + + no_os_mdelay(1000); + + ret = test_rgb(dev); + if (ret) + goto free_dev; + + no_os_mdelay(1000); + + ret = test_aux(dev); + if (ret) + goto free_dev; + + no_os_mdelay(1000); + + ret = test_enrgbs(dev); + if (ret) + goto free_dev; + + no_os_mdelay(1000); + + ret = test_dropout(dev); + if (ret) + goto free_dev; + + no_os_mdelay(1000); + } + +free_dev: + ltc3208_remove(dev); +error: + pr_info("Error!\r\n"); + return 0; +} diff --git a/projects/ltc3208/src/examples/basic/basic_example.h b/projects/ltc3208/src/examples/basic/basic_example.h new file mode 100644 index 00000000000..c376da25f17 --- /dev/null +++ b/projects/ltc3208/src/examples/basic/basic_example.h @@ -0,0 +1,38 @@ +/******************************************************************************* + * @file basic_example.h + * @brief Basic example header for ltc3208 project + * @author Edelweise Escala (edelweise.escala@analog.com) + ******************************************************************************** + * Copyright 2023(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 __BASIC_EXAMPLE_H__ +#define __BASIC_EXAMPLE_H__ + +int example_main(); + +#endif /* __BASIC_EXAMPLE_H__ */ diff --git a/projects/ltc3208/src/platform/maxim/main.c b/projects/ltc3208/src/platform/maxim/main.c new file mode 100644 index 00000000000..dec3cf22592 --- /dev/null +++ b/projects/ltc3208/src/platform/maxim/main.c @@ -0,0 +1,47 @@ +/***************************************************************************//** + * @file main.c + * @brief Main file for Maxim platfom of LTC3208 project. + * @author Edelweise Escala (edelweise.escala@analog.com) +******************************************************************************** + * Copyright 2025(c) Analog Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of Analog Devices, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "parameters.h" +#include "common_data.h" + +int example_main(); + +/***************************************************************************//** + * @brief Main function execution for Maxim platform. + * + * @return ret - Result of the enabled examples execution. +*******************************************************************************/ +int main() +{ + return example_main(); +} diff --git a/projects/ltc3208/src/platform/maxim/parameters.c b/projects/ltc3208/src/platform/maxim/parameters.c new file mode 100644 index 00000000000..0910a6a856d --- /dev/null +++ b/projects/ltc3208/src/platform/maxim/parameters.c @@ -0,0 +1,42 @@ +/***************************************************************************//** + * @file parameters.c + * @brief Definition of Maxim platform data used by LTC3208 project + * @author Edelweise Escala (edelweise.escala@analog.com) +******************************************************************************** + * Copyright 2025(c) Analog Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of Analog Devices, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "parameters.h" + +struct max_i2c_init_param ltc3208_i2c_extra = { + .vssel = MXC_GPIO_VSSEL_VDDIOH +}; + +struct max_gpio_init_param ltc3208_gpio_extra = { + .vssel = MXC_GPIO_VSSEL_VDDIOH, +}; \ No newline at end of file diff --git a/projects/ltc3208/src/platform/maxim/parameters.h b/projects/ltc3208/src/platform/maxim/parameters.h new file mode 100644 index 00000000000..7e5c66dd25c --- /dev/null +++ b/projects/ltc3208/src/platform/maxim/parameters.h @@ -0,0 +1,64 @@ +/***************************************************************************//** + * @file parameters.h + * @brief Definition header of Maxim platform data used by LTC3208 project + * @author Edelweise Escala (edelweise.escala@analog.com) +******************************************************************************** + * Copyright 2025(c) Analog Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of Analog Devices, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __PARAMETERS_H__ +#define __PARAMETERS_H__ + +#include "maxim_i2c.h" +#include "maxim_gpio.h" + +#define DEV_I2C_ADDRESS 0x1B + +#if (TARGET_NUM == 32650) || (TARGET_NUM == 78000) +#define I2C_DEVICE_ID 1 +#elif (TARGET_NUM == 32655) +#define I2C_DEVICE_ID 2 +#elif (TARGET_NUM == 32665) || (TARGET_NUM == 32660) || (TARGET_NUM == 32690) +#define I2C_DEVICE_ID 0 +#endif + +#define I2C_OPS &max_i2c_ops + +#define GPIO_OPS &max_gpio_ops + +#if (TARGET_NUM == 32690) +#define GPIO_ENRGBS_PIN_NUM 14 +#define GPIO_ENRGBS_PIN_PORT 0 +#elif (TARGET_NUM == 32655) +#define GPIO_ENRGBS_PIN_NUM 9 +#define GPIO_ENRGBS_PIN_PORT 1 +#endif + +extern struct max_gpio_init_param ltc3208_gpio_extra; +extern struct max_i2c_init_param ltc3208_i2c_extra; + +#endif /* __PARAMETERS_H__ */ \ No newline at end of file diff --git a/projects/ltc3208/src/platform/maxim/platform_src.mk b/projects/ltc3208/src/platform/maxim/platform_src.mk new file mode 100644 index 00000000000..007b87cb6c6 --- /dev/null +++ b/projects/ltc3208/src/platform/maxim/platform_src.mk @@ -0,0 +1,14 @@ +INCS += $(PLATFORM_DRIVERS)/maxim_gpio.h \ + $(PLATFORM_DRIVERS)/maxim_i2c.h \ + $(PLATFORM_DRIVERS)/maxim_irq.h \ + $(PLATFORM_DRIVERS)/../common/maxim_dma.h \ + $(PLATFORM_DRIVERS)/maxim_uart.h \ + $(PLATFORM_DRIVERS)/maxim_uart_stdio.h + +SRCS += $(PLATFORM_DRIVERS)/maxim_delay.c \ + $(PLATFORM_DRIVERS)/maxim_gpio.c \ + $(PLATFORM_DRIVERS)/maxim_i2c.c \ + $(PLATFORM_DRIVERS)/../common/maxim_dma.c \ + $(PLATFORM_DRIVERS)/maxim_irq.c \ + $(PLATFORM_DRIVERS)/maxim_uart.c \ + $(PLATFORM_DRIVERS)/maxim_uart_stdio.c diff --git a/projects/ltc3208/src/platform/platform_includes.h b/projects/ltc3208/src/platform/platform_includes.h new file mode 100644 index 00000000000..e90d3fbc2fa --- /dev/null +++ b/projects/ltc3208/src/platform/platform_includes.h @@ -0,0 +1,40 @@ +/******************************************************************************** + * @file platform_includes.h + * @brief Includes for used platforms used by the LTC3208 project. + * @author Edelweise Escala (edelweise.escala@analog.com) + ******************************************************************************** + * Copyright 2023(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 __PLATFORM_INCLUDES_H__ +#define __PLATFORM_INCLUDES_H__ + +#ifdef MAXIM_PLATFORM +#include "maxim/parameters.h" +#endif + +#endif /* __PLATFORM_INCLUDES_H__ */