Skip to content

Commit 976f640

Browse files
committed
Driver for TPS63101X added
1 parent c6da185 commit 976f640

File tree

18 files changed

+694
-1
lines changed

18 files changed

+694
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ or [GitLab examples](https://gitlab.com/UncleRus/esp-idf-lib/tree/master/example
240240
| **rda5807m** | Driver for single-chip broadcast FM radio tuner RDA5807M | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
241241
| **tca9548** | Driver for TCA9548A/PCA9548A low-voltage 8-channel I2C switch | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
242242
| **tda74xx** | Driver for TDA7439/TDA7439DS/TDA7440D audioprocessors | MIT | esp32, esp8266, esp32s2, esp32c3 | yes |
243+
| **tps63101x** | Driver for Texas Instruments TPS631012 and TPS631013 1.6-V to 5.5-V Input Voltage 1.5-A Buck-boost Converter with I2C | BSD-3-Clause | esp32, esp32s2, esp32c3 | yes |
243244
| **ultrasonic** | Driver for ultrasonic range meters, e.g. HC-SR04, HY-SRF05 | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | no |
244245
| **wiegand** | Wiegand protocol receiver | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | no |
245246

@@ -330,7 +331,7 @@ or [GitLab examples](https://gitlab.com/UncleRus/esp-idf-lib/tree/master/example
330331
- [jsuiker](https://github.com/jsuiker): `dht`
331332
- [Julian Doerner](https://github.com/juliandoerner): `tsl2591`
332333
- [Lucio Tarantino](https://github.com/dianlight): `ads111x`
333-
- [Manuel Markwort](https://github.com/mmarkwort): `mp2660`
334+
- [Manuel Markwort](https://github.com/mmarkwort): `mp2660` `tps63101x`
334335
- [Marc Luehr](https://github.com/th3link): `veml7700`
335336
- [Nate Usher](https://github.com/nated0g): `scd30`
336337
- Pavel Merzlyakov: `ds1302`

components/tps63101x/.eil.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: tps63101x
2+
description: Driver for Texas Instruments TPS631012 and TPS631013 1.6-V to 5.5-V Input Voltage 1.5-A Buck-boost Converter with I2C
3+
version: 1.0.0
4+
groups:
5+
- misc
6+
code_owners:
7+
- mmarkwort
8+
depends:
9+
- i2cdev
10+
- esp_idf_lib_helpers
11+
thread_safe: yes
12+
targets:
13+
- esp32
14+
- esp32s2
15+
- esp32c3
16+
license: BSD-3
17+
copyrights:
18+
- name: mmarkwort
19+
year: 2024

components/tps63101x/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
idf_component_register(
2+
SRCS tps63101x.c
3+
INCLUDE_DIRS .
4+
REQUIRES i2cdev esp_idf_lib_helpers
5+
)

components/tps63101x/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2024 Manuel Markwort (https://github.com/mmarkwort)
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice,
7+
this list of conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
3. Neither the name of the copyright holder nor the names of itscontributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

components/tps63101x/component.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
COMPONENT_ADD_INCLUDEDIRS = .
2+
COMPONENT_DEPENDS = i2cdev esp_idf_lib_helpers

components/tps63101x/tps63101x.c

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Copyright (c) 2024 Manuel Markwort <https://github.com/mmarkwort>
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimer in the documentation
11+
* and/or other materials provided with the distribution.
12+
* 3. Neither the name of the copyright holder nor the names of itscontributors
13+
* may be used to endorse or promote products derived from this software without
14+
* specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
/**
29+
* @file tps63101x.c
30+
*
31+
* ESP-IDF driver for Texas Instruments TPS631012 and TPS631013 1.6-V to 5.5-V Input Voltage 1.5-A Buck-boost Converter with I2C
32+
*
33+
* Copyright (c) 2024 Manuel Markwort <https://github.com/mmarkwort>\n
34+
*
35+
* BSD Licensed as described in the file LICENSE
36+
*/
37+
38+
#include <esp_idf_lib_helpers.h>
39+
#include "tps63101x.h"
40+
41+
#define I2C_FREQ_HZ 400000 //!< 400kHz bus speed
42+
43+
#define TPS63101X_CONTROL_1_REG_ADDR 0x02 //!< Address of Control 1 register
44+
#define TPS63101X_VOUT_REG_ADDR 0x03 //!< Address of VOUT register
45+
#define TPS63101X_CONTROL_2_REG_ADDR 0x05 //!< Address of Control 2 register
46+
47+
#define CHECK_ARG(VAL) do { if (!(VAL)) return ESP_ERR_INVALID_ARG; } while (0)
48+
49+
esp_err_t tps63101x_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
50+
{
51+
CHECK_ARG(dev);
52+
53+
dev->port = port;
54+
dev->addr = TPS63101X_I2C_ADDR;
55+
dev->cfg.sda_io_num = sda_gpio;
56+
dev->cfg.scl_io_num = scl_gpio;
57+
#if HELPER_TARGET_IS_ESP32
58+
dev->cfg.master.clk_speed = I2C_FREQ_HZ;
59+
#endif
60+
61+
return i2c_dev_create_mutex(dev);
62+
}
63+
64+
esp_err_t tps63101x_free_desc(i2c_dev_t *dev)
65+
{
66+
CHECK_ARG(dev);
67+
68+
return i2c_dev_delete_mutex(dev);
69+
}
70+
71+
esp_err_t tps63101x_read(i2c_dev_t *dev, uint8_t addr, void* data)
72+
{
73+
CHECK_ARG(dev);
74+
75+
I2C_DEV_TAKE_MUTEX(dev);
76+
I2C_DEV_CHECK(dev, i2c_dev_read_reg(dev, addr, data, 1));
77+
I2C_DEV_GIVE_MUTEX(dev);
78+
79+
return ESP_OK;
80+
}
81+
82+
esp_err_t tps63101x_write(i2c_dev_t *dev, uint8_t addr, void* data)
83+
{
84+
CHECK_ARG(dev);
85+
86+
I2C_DEV_TAKE_MUTEX(dev);
87+
I2C_DEV_CHECK(dev, i2c_dev_write_reg(dev, addr, data, 1));
88+
I2C_DEV_GIVE_MUTEX(dev);
89+
90+
return ESP_OK;
91+
}
92+
93+
esp_err_t tps63101x_get_control_1(i2c_dev_t *dev, tps63101x_control_1_t* control_1)
94+
{
95+
return tps63101x_read(dev, TPS63101X_CONTROL_1_REG_ADDR, control_1);
96+
}
97+
98+
esp_err_t tps63101x_set_control_1(i2c_dev_t *dev, tps63101x_control_1_t* control_1)
99+
{
100+
return tps63101x_write(dev, TPS63101X_CONTROL_1_REG_ADDR, control_1);
101+
}
102+
103+
esp_err_t tps63101x_get_vout(i2c_dev_t *dev, tps63101x_vout_t* vout)
104+
{
105+
return tps63101x_read(dev, TPS63101X_VOUT_REG_ADDR, vout);
106+
}
107+
108+
esp_err_t tps63101x_set_vout(i2c_dev_t *dev, tps63101x_vout_t* vout)
109+
{
110+
return tps63101x_write(dev, TPS63101X_VOUT_REG_ADDR, vout);
111+
}
112+
113+
esp_err_t tps63101x_get_control_2(i2c_dev_t *dev, tps63101x_control_2_t* control_2)
114+
{
115+
return tps63101x_read(dev, TPS63101X_CONTROL_2_REG_ADDR, control_2);
116+
}
117+
118+
esp_err_t tps63101x_set_control_2(i2c_dev_t *dev, tps63101x_control_2_t* control_2)
119+
{
120+
return tps63101x_write(dev, TPS63101X_CONTROL_2_REG_ADDR, control_2);
121+
}
122+
123+
esp_err_t tps63101x_reset(i2c_dev_t *dev)
124+
{
125+
esp_err_t err;
126+
127+
tps63101x_control_1_t control_1;
128+
tps63101x_vout_t vout;
129+
tps63101x_control_2_t control_2;
130+
131+
control_1.register_data.reg = TPS63101X_CONTROL_1_DEFAULT;
132+
vout.register_data.reg = TPS63101X_VOUT_DEFAULT;
133+
control_2.register_data.reg = TPS63101X_CONTROL_2_DEFAULT;
134+
135+
err = tps63101x_set_control_1(dev, &control_1);
136+
if(err != ESP_OK)
137+
{
138+
return err;
139+
}
140+
141+
vTaskDelay(pdMS_TO_TICKS(1500));
142+
143+
err = tps63101x_set_control_2(dev, &control_2);
144+
if(err != ESP_OK)
145+
{
146+
return err;
147+
}
148+
149+
vTaskDelay(pdMS_TO_TICKS(1500));
150+
151+
err = tps63101x_set_vout(dev, &vout);
152+
if(err != ESP_OK)
153+
{
154+
return err;
155+
}
156+
157+
return err;
158+
}
159+
160+
uint8_t tps63101x_to_register_voltage(float voltage)
161+
{
162+
if(voltage < 1.0f || voltage > 5.5f)
163+
{
164+
return 0xff;
165+
}
166+
167+
return (voltage - 1.0f) / 0.025;
168+
}

0 commit comments

Comments
 (0)