| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC1674A.ino
Go to the documentation of this file.
1 /*!
2 LTC4155: Dual-Input Power Manager / 3.5A Li-Ion Battery Charger with I²C Control and USB OTG
3
4 @verbatim
5 The LTC®4155 is a 15 watt I²C controlled power manager with PowerPath™ instant-
6 on operation, high efficiency switching battery charging and USB compatibility.
7 The LTC4155 seamlessly manages power distribution from two 5V sources, such as a
8 USB port and a wall adapter, to a single-cell rechargeable Lithium-Ion/Polymer
9 battery and a system load.
10 @endverbatim
11
12 http://www.linear.com/product/LTC4155
13
14 http://www.linear.com/product/LTC4155#demoboards
15
16
17 Copyright 2018(c) Analog Devices, Inc.
18
19 All rights reserved.
20
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions are met:
23 - Redistributions of source code must retain the above copyright
24 notice, this list of conditions and the following disclaimer.
25 - Redistributions in binary form must reproduce the above copyright
26 notice, this list of conditions and the following disclaimer in
27 the documentation and/or other materials provided with the
28 distribution.
29 - Neither the name of Analog Devices, Inc. nor the names of its
30 contributors may be used to endorse or promote products derived
31 from this software without specific prior written permission.
32 - The use of this software may or may not infringe the patent rights
33 of one or more patent holders. This license does not release you
34 from the requirement that you obtain separate licenses from these
35 patent holders to use this software.
36 - Use of the software either in source or binary form, must be run
37 on or directly connected to an Analog Devices Inc. component.
38
39 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
40 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
41 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
43 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
45 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
50 Generated on: 2016-01-19
51 */
52
53
54
55 /*! @file
56 * @ingroup LTC4155
57 * @brief Arduino Example
58 *
59 * This is an example sketch to demonstrate use of the API with the Linduino.
60 * In addition to the sketch, the following files are required::
61 * LTC4155.c
62 * LTC4155.h
63 * LTC4155_reg_defs.h
64 */
65
66 #include "LTC4155.h"
67 #include <Arduino.h>
68 #include "Linduino.h"
69
70 #include "UserInterface.h"
71 #include "LT_I2CBus.h"
72 #include "LT_SMBusNoPec.h"
73
74 static LT_SMBus *smbus = new LT_SMBusNoPec();
75
76 int read_register(uint8_t addr,uint8_t command_code, uint8_t *data, port_configuration_t *port_configuration);
77 int write_register(uint8_t addr,uint8_t command_code, uint8_t data, port_configuration_t *port_configuration);
78
79 LTC4155_chip_cfg_t cfg =
80 {
81 LTC4155_ADDR_09, //.addr (7-bit)
82 read_register, //.read_register
83 write_register, //.write_register
84 0 //.port_configuration not used
85 };
86
87
88 LTC4155 chip;
89 uint8_t data;
90
91 void setup()
92 {
93 Serial.begin(115200); //! Initialize the serial port to the PC
94 while (!Serial); //! Wait for serial port to be opened in the case of Leonardo USB Serial
95 Serial.println(F("Initializing LTC4155"));
96 chip = LTC4155_init(&cfg);
97 }
98
99 void loop()
100 {
101 /* the API functions can be used to read and write individual bit fields within a command code */
102 Serial.println(F("Press any key to arm ship-and-store mode."));
103 while (Serial.available() == 0);
104 while (Serial.available() > 0)
105 Serial.read();
106 LTC4155_write_register(chip, LTC4155_ARM_SHIPMODE, LTC4155_ARM_SHIPMODE_PRESET_ARM);
107 Serial.println(F("Ship-and-store mode armed.\n"));
108
109 Serial.println(F("Press any key to disarm ship-and-store mode."));
110 while (Serial.available() == 0);
111 while (Serial.available() > 0)
112 Serial.read();
113 LTC4155_read_register(chip, LTC4155_REG6, &data);
114 LTC4155_write_register(chip, LTC4155_REG6, data); // Write to register 6 to clear ship-mode without changing its contents.
115 Serial.println(F("Ship-and-store mode disarmed.\n"));
116 }
117
118 /*! read_register function wraps C++ method LT_SMBus::readByte and places the returned data in *data.*/
119 int read_register(uint8_t addr, uint8_t command_code, uint8_t *data, port_configuration_t *port_configuration)
120 {
121 //virtual uint8_t LT_SMBus::readByte(uint8_t address,uint8_t command);
122 *data = smbus->readByte(addr, command_code);
123 return 0;
124 }
125
126 /*! write_register function wraps C++ method LT_SMBus::writeByte.*/
127 int write_register(uint8_t addr, uint8_t command_code, uint8_t data, port_configuration_t *port_configuration)
128 {
129 //virtual void LT_SMBus::writeByte(uint8_t address,uint8_t command,uint8_t data);
130 smbus->writeByte(addr, command_code, data);
131 return 0;
132 }
133
LTC4155_ADDR_09
#define LTC4155_ADDR_09
LTC4155 I2C address in 7-bit format.
Definition: LTC4155_reg_defs.h:77
LTC4155_read_register
int LTC4155_read_register(LTC4155 chip_handle, uint16_t registerinfo, uint8_t *data)
Retrieves a bit field data into *data.
Definition: LTC4155.c:164
LTC4155
void * LTC4155
Definition: LTC4155.h:102
Linduino.h
Header File for Linduino Libraries and Demo Code.
LT_SMBusNoPec
Definition: LT_SMBusNoPec.h:60
LTC4155_ARM_SHIPMODE_PRESET_ARM
#define LTC4155_ARM_SHIPMODE_PRESET_ARM
Definition: LTC4155_reg_defs.h:1037
LTC4155_init
LTC4155 LTC4155_init(LTC4155_chip_cfg_t *cfg)
Returns a pointer to a LTC4155 structure used by LTC4155_write_register and LTC4155_read_register.
Definition: LTC4155.c:112
read_register
static int read_register(uint8_t addr, uint8_t command_code, uint8_t *data, port_configuration_t *port_configuration)
read_register function wraps C++ method LT_SMBus::readByte and places the returned data in *data...
Definition: DC1674A.ino:119
LTC4155_chip_cfg_t
Information required to access hardware SMBus port.
Definition: LTC4155.h:104
LTC4155_REG6
#define LTC4155_REG6
Definition: LTC4155_reg_defs.h:829
write_register
static int write_register(uint8_t addr, uint8_t command_code, uint8_t data, port_configuration_t *port_configuration)
write_register function wraps C++ method LT_SMBus::writeByte.
Definition: DC1674A.ino:127
LT_SMBus
Definition: LT_SMBus.h:61
data
static uint8_t data
Definition: DC1674A.ino:89
LTC4155_ARM_SHIPMODE
#define LTC4155_ARM_SHIPMODE
Definition: LTC4155_reg_defs.h:1036
cfg
LTC4155_chip_cfg_t cfg
Definition: DC1674A.ino:79
setup
static void setup()
Definition: DC1674A.ino:91
loop
static void loop()
Definition: DC1674A.ino:99
chip
LTC4155 chip
Definition: DC1674A.ino:88
LT_I2CBus.h
LT_I2CBus: Routines to communicate to I2C by Wire Library.
LTC4155_write_register
int LTC4155_write_register(LTC4155 chip_handle, uint16_t registerinfo, uint8_t data)
Function to modify a bit field within a register while preserving the unaddressed bit fields...
Definition: LTC4155.c:147
LT_SMBus::writeByte
virtual void writeByte(uint8_t address, uint8_t command, uint8_t data)=0
SMBus write byte command.
LT_SMBus::readByte
virtual uint8_t readByte(uint8_t address, uint8_t command)=0
SMBus read byte command.
LTC4155.h
LTC4155: Dual-Input Power Manager / 3.5A Li-Ion Battery Charger with I²C Control and USB OTG...
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
UserInterface.h
port_configuration_t
Hardware port information.
Definition: LTC4155.h:86
smbus
static LT_SMBus * smbus
Definition: DC1674A.ino:74