|
| 1 | +/***************************************************************************//** |
| 2 | + * @file basic_example.c |
| 3 | + * @brief Basic example source file for adp1055 project. |
| 4 | + * @author Ivan Gil Mercano ([email protected]) |
| 5 | +******************************************************************************** |
| 6 | + * Copyright 2024(c) Analog Devices, Inc. |
| 7 | + * |
| 8 | + * Redistribution and use in source and binary forms, with or without |
| 9 | + * modification, are permitted provided that the following conditions are met: |
| 10 | + * |
| 11 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 12 | + * this list of conditions and the following disclaimer. |
| 13 | + * |
| 14 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | + * this list of conditions and the following disclaimer in the documentation |
| 16 | + * and/or other materials provided with the distribution. |
| 17 | + * |
| 18 | + * 3. Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | + * contributors may be used to endorse or promote products derived from this |
| 20 | + * software without specific prior written permission. |
| 21 | + * |
| 22 | + * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR |
| 23 | + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 24 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 25 | + * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 28 | + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 31 | + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | +*******************************************************************************/ |
| 33 | +#include "common_data.h" |
| 34 | +#include "no_os_delay.h" |
| 35 | +#include "no_os_i2c.h" |
| 36 | +#include "no_os_print_log.h" |
| 37 | +#include "no_os_util.h" |
| 38 | +#include "no_os_pwm.h" |
| 39 | +#include "adp1055.h" |
| 40 | + |
| 41 | +int example_main() |
| 42 | +{ |
| 43 | + int ret; |
| 44 | + |
| 45 | + struct adp1055_desc *adp1055_desc; |
| 46 | + uint8_t data = 120; |
| 47 | + uint8_t data2[2]; |
| 48 | + uint16_t vout; |
| 49 | + int16_t val; |
| 50 | + |
| 51 | + pr_info("INIT: "); |
| 52 | + ret = adp1055_init(&adp1055_desc, &adp1055_ip); |
| 53 | + if (ret) |
| 54 | + pr_info("Fail \n"); |
| 55 | + else |
| 56 | + pr_info("Pass \n"); |
| 57 | + |
| 58 | + pr_info("VOUT SCALE: "); |
| 59 | + ret = adp1055_vout_scale(adp1055_desc, -12, 341); |
| 60 | + if (ret) |
| 61 | + pr_info("Fail \n"); |
| 62 | + else |
| 63 | + pr_info("Pass \n"); |
| 64 | + |
| 65 | + pr_info("VOUT VALUE: "); |
| 66 | + ret = adp1055_vout_value(adp1055_desc, 0x3000, 0x5000); |
| 67 | + if (ret) |
| 68 | + pr_info("Fail \n"); |
| 69 | + else |
| 70 | + pr_info("Pass \n"); |
| 71 | + |
| 72 | + pr_info("PWM CONFIG: "); |
| 73 | + ret = adp1055_pwm_config(adp1055_desc, 0x00DE, 0x000E, 0, 0, ADP1055_OUTA); |
| 74 | + if (ret) |
| 75 | + pr_info("Fail \n"); |
| 76 | + else |
| 77 | + pr_info("Pass \n"); |
| 78 | + |
| 79 | + pr_info("SET PWM: "); |
| 80 | + ret = adp1055_set_pwm(adp1055_desc, ADP1055_OUTA, -4, 782); |
| 81 | + if (ret) |
| 82 | + pr_info("Fail \n"); |
| 83 | + else |
| 84 | + pr_info("Pass \n"); |
| 85 | + |
| 86 | + pr_info("READ VALUE: "); |
| 87 | + ret = adp1055_read_value(adp1055_desc, ADP1055_VALUE_DUTY_CYCLE, &vout, &data); |
| 88 | + if (ret) |
| 89 | + pr_info("Fail \n"); |
| 90 | + else |
| 91 | + pr_info("Pass \n"); |
| 92 | + |
| 93 | + /* Checking statuses. */ |
| 94 | + pr_info("READ STAT VOUT: "); |
| 95 | + ret = adp1055_read(adp1055_desc, ADP1055_STATUS_VOUT, &data, 1); |
| 96 | + if (ret) |
| 97 | + pr_info("Fail \n"); |
| 98 | + else |
| 99 | + pr_info("Pass \n"); |
| 100 | + |
| 101 | + pr_info("READ STAT INPUT: "); |
| 102 | + ret = adp1055_read(adp1055_desc, ADP1055_STATUS_INPUT, &data, 1); |
| 103 | + if (ret) |
| 104 | + pr_info("Fail \n"); |
| 105 | + else |
| 106 | + pr_info("Pass \n"); |
| 107 | + |
| 108 | + pr_info("READ STAT CML: "); |
| 109 | + ret = adp1055_read(adp1055_desc, ADP1055_STATUS_CML, &data, 1); |
| 110 | + if (ret) |
| 111 | + pr_info("Fail \n"); |
| 112 | + else |
| 113 | + pr_info("Pass \n"); |
| 114 | + |
| 115 | + pr_info("READ STAT WORD: "); |
| 116 | + ret = adp1055_read(adp1055_desc, ADP1055_STATUS_WORD, data2, 2); |
| 117 | + if (ret) |
| 118 | + pr_info("Fail \n"); |
| 119 | + else |
| 120 | + pr_info("Pass \n"); |
| 121 | + |
| 122 | +exit: |
| 123 | + if (ret) |
| 124 | + pr_info("Error!\n"); |
| 125 | + adp1055_remove(adp1055_desc); |
| 126 | + return ret; |
| 127 | +} |
0 commit comments