Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds driver for TPS63101x #630

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ or [GitLab examples](https://gitlab.com/UncleRus/esp-idf-lib/tree/master/example
| **rda5807m** | Driver for single-chip broadcast FM radio tuner RDA5807M | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
| **tca9548** | Driver for TCA9548A/PCA9548A low-voltage 8-channel I2C switch | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
| **tda74xx** | Driver for TDA7439/TDA7439DS/TDA7440D audioprocessors | MIT | esp32, esp8266, esp32s2, esp32c3 | yes |
| **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 |
| **ultrasonic** | Driver for ultrasonic range meters, e.g. HC-SR04, HY-SRF05 | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | no |
| **wiegand** | Wiegand protocol receiver | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | no |

Expand Down Expand Up @@ -330,7 +331,7 @@ or [GitLab examples](https://gitlab.com/UncleRus/esp-idf-lib/tree/master/example
- [jsuiker](https://github.com/jsuiker): `dht`
- [Julian Doerner](https://github.com/juliandoerner): `tsl2591`
- [Lucio Tarantino](https://github.com/dianlight): `ads111x`
- [Manuel Markwort](https://github.com/mmarkwort): `mp2660`
- [Manuel Markwort](https://github.com/mmarkwort): `mp2660` `tps63101x`
- [Marc Luehr](https://github.com/th3link): `veml7700`
- [Nate Usher](https://github.com/nated0g): `scd30`
- Pavel Merzlyakov: `ds1302`
Expand Down
19 changes: 19 additions & 0 deletions components/tps63101x/.eil.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: tps63101x
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
version: 1.0.0
groups:
- misc
code_owners:
- mmarkwort
depends:
- i2cdev
- esp_idf_lib_helpers
thread_safe: yes
targets:
- esp32
- esp32s2
- esp32c3
license: BSD-3
copyrights:
- name: mmarkwort
year: 2024
5 changes: 5 additions & 0 deletions components/tps63101x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
idf_component_register(
SRCS tps63101x.c
INCLUDE_DIRS .
REQUIRES i2cdev esp_idf_lib_helpers
)
26 changes: 26 additions & 0 deletions components/tps63101x/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2024 Manuel Markwort (https://github.com/mmarkwort)

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 the copyright holder nor the names of itscontributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
2 changes: 2 additions & 0 deletions components/tps63101x/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COMPONENT_ADD_INCLUDEDIRS = .
COMPONENT_DEPENDS = i2cdev esp_idf_lib_helpers
168 changes: 168 additions & 0 deletions components/tps63101x/tps63101x.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Copyright (c) 2024 Manuel Markwort <https://github.com/mmarkwort>
*
* 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 the copyright holder nor the names of itscontributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/

/**
* @file tps63101x.c
*
* 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
*
* Copyright (c) 2024 Manuel Markwort <https://github.com/mmarkwort>\n
*
* BSD Licensed as described in the file LICENSE
*/

#include <esp_idf_lib_helpers.h>
#include "tps63101x.h"

#define I2C_FREQ_HZ 400000 //!< 400kHz bus speed

#define TPS63101X_CONTROL_1_REG_ADDR 0x02 //!< Address of Control 1 register
#define TPS63101X_VOUT_REG_ADDR 0x03 //!< Address of VOUT register
#define TPS63101X_CONTROL_2_REG_ADDR 0x05 //!< Address of Control 2 register

#define CHECK_ARG(VAL) do { if (!(VAL)) return ESP_ERR_INVALID_ARG; } while (0)

esp_err_t tps63101x_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
{
CHECK_ARG(dev);

dev->port = port;
dev->addr = TPS63101X_I2C_ADDR;
dev->cfg.sda_io_num = sda_gpio;
dev->cfg.scl_io_num = scl_gpio;
#if HELPER_TARGET_IS_ESP32
dev->cfg.master.clk_speed = I2C_FREQ_HZ;
#endif

return i2c_dev_create_mutex(dev);
}

esp_err_t tps63101x_free_desc(i2c_dev_t *dev)
{
CHECK_ARG(dev);

return i2c_dev_delete_mutex(dev);
}

esp_err_t tps63101x_read(i2c_dev_t *dev, uint8_t addr, void* data)
{
CHECK_ARG(dev);

I2C_DEV_TAKE_MUTEX(dev);
I2C_DEV_CHECK(dev, i2c_dev_read_reg(dev, addr, data, 1));
I2C_DEV_GIVE_MUTEX(dev);

return ESP_OK;
}

esp_err_t tps63101x_write(i2c_dev_t *dev, uint8_t addr, void* data)
{
CHECK_ARG(dev);

I2C_DEV_TAKE_MUTEX(dev);
I2C_DEV_CHECK(dev, i2c_dev_write_reg(dev, addr, data, 1));
I2C_DEV_GIVE_MUTEX(dev);

return ESP_OK;
}

esp_err_t tps63101x_get_control_1(i2c_dev_t *dev, tps63101x_control_1_t* control_1)
{
return tps63101x_read(dev, TPS63101X_CONTROL_1_REG_ADDR, control_1);
}

esp_err_t tps63101x_set_control_1(i2c_dev_t *dev, tps63101x_control_1_t* control_1)
{
return tps63101x_write(dev, TPS63101X_CONTROL_1_REG_ADDR, control_1);
}

esp_err_t tps63101x_get_vout(i2c_dev_t *dev, tps63101x_vout_t* vout)
{
return tps63101x_read(dev, TPS63101X_VOUT_REG_ADDR, vout);
}

esp_err_t tps63101x_set_vout(i2c_dev_t *dev, tps63101x_vout_t* vout)
{
return tps63101x_write(dev, TPS63101X_VOUT_REG_ADDR, vout);
}

esp_err_t tps63101x_get_control_2(i2c_dev_t *dev, tps63101x_control_2_t* control_2)
{
return tps63101x_read(dev, TPS63101X_CONTROL_2_REG_ADDR, control_2);
}

esp_err_t tps63101x_set_control_2(i2c_dev_t *dev, tps63101x_control_2_t* control_2)
{
return tps63101x_write(dev, TPS63101X_CONTROL_2_REG_ADDR, control_2);
}

esp_err_t tps63101x_reset(i2c_dev_t *dev)
{
esp_err_t err;

tps63101x_control_1_t control_1;
tps63101x_vout_t vout;
tps63101x_control_2_t control_2;

control_1.register_data.reg = TPS63101X_CONTROL_1_DEFAULT;
vout.register_data.reg = TPS63101X_VOUT_DEFAULT;
control_2.register_data.reg = TPS63101X_CONTROL_2_DEFAULT;

err = tps63101x_set_control_1(dev, &control_1);
if(err != ESP_OK)
{
return err;
}

vTaskDelay(pdMS_TO_TICKS(1500));

err = tps63101x_set_control_2(dev, &control_2);
if(err != ESP_OK)
{
return err;
}

vTaskDelay(pdMS_TO_TICKS(1500));

err = tps63101x_set_vout(dev, &vout);
if(err != ESP_OK)
{
return err;
}

return err;
}

uint8_t tps63101x_to_register_voltage(float voltage)
{
if(voltage < 1.0f || voltage > 5.5f)
{
return 0xff;
}

return (voltage - 1.0f) / 0.025;
}
Loading
Loading