You are using staging server - a separate instance of the ESP Component Registry that allows you to try distribution tools and processes without affecting the real registry.

romr/pt2258_ctrl

0.1.0

Latest
uploaded 6 hours ago
ESP-IDF volume manager for PT2258 6-channel electronic volume controller

Readme

[![Component Registry](https://components.espressif.com/components/romr/pt2258_ctrl/badge.svg)](https://components.espressif.com/components/romr/pt2258_ctrl)

# PT2258 Controller

An ESP-IDF volume management engine for the PT2258 IC, featuring logarithmic scaling, channel masking, per-channel balance offsets, and internal state caching.

## Features

- **Master volume control**: 0-100% volume with logarithmic LUT or linear (optional) scaling
- **Volume stepping**: Increment/decrement volume by percentage steps
- **Per-channel offsets**: Adjust individual channel levels relative to master volume
- **Global mute**: Chip-level mute control for all channels
- **Offset limits**: Configurable range for channel offsets
- **State tracking**: Maintains internal state for volume, offsets, and mute status
- **Channel Masking**: Initialize only the channels you actually wired on your PCB layout.

## Usage example

```c
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "i2c_bus.h"
#include "pt2258.h"
#include "pt2258_ctrl.h"

static const char *TAG = "main";

void app_main(void)
{
    // 0. Wait at least 200ms after Power-ON to ensure PT2258 stability
    vTaskDelay(pdMS_TO_TICKS(200));

    // 1. Initialize your I2C master bus
    i2c_bus_handle_t i2c_bus_handle = /* Your I2C bus initialization logic */;

    // 2. Configure and create PT2258 device
    pt2258_i2c_config_t pt2258_cfg = {
        .i2c_bus = i2c_bus_handle,
        .i2c_addr = PT2258_ADDRESS_2
    };

    pt2258_dev_handle_t pt2258_handle = NULL;
    esp_err_t ret = pt2258_create(&pt2258_cfg, &pt2258_handle);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to initialize PT2258");
        return;
    }

    // 3. Configure PT2258 controller
    // Enable channels 1, 2, and 3 (stereo setup)
    pt2258_ctrl_config_t ctrl_cfg = {
        .pt2258 = pt2258_handle,
        .active_channels_mask = PT2258_CH1_ENABLE | PT2258_CH2_ENABLE | PT2258_CH3_ENABLE,
        .init_volume = 50,              // Start at 50% volume
        .offset_limits = 20,            // Allow +/- 20 dB offset per channel
        .use_linear_volume = false      // Use logarithmic volume scaling (false = LUT, true = linear)
    };

    pt2258_ctrl_handle_t ctrl_handle = NULL;
    ret = pt2258_ctrl_create(&ctrl_cfg, &ctrl_handle);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to initialize PT2258 controller");
        pt2258_delete(&pt2258_handle);
        return;
    }

    // 4. Adjust channel offsets for balance
    // Boost channel 1 by +5 dB, reduce channel 2 by -3 dB
    pt2258_ctrl_set_offset(ctrl_handle, 1, 5);
    pt2258_ctrl_set_offset(ctrl_handle, 2, -3);

    // 5. Set master volume to 70%
    pt2258_ctrl_set_master_volume(ctrl_handle, 70);

    // 6. Unmute to enable audio output
    pt2258_ctrl_set_mute(ctrl_handle, false);

    // 7. Volume control examples
    // Increase volume by 10%
    pt2258_ctrl_volume_step_up(ctrl_handle, 10);
    
    // Decrease volume by 5%
    pt2258_ctrl_volume_step_down(ctrl_handle, 5);

    // 8. Get current state
    uint8_t current_volume;
    pt2258_ctrl_get_master_volume(ctrl_handle, &current_volume);
    ESP_LOGI(TAG, "Current volume: %d%%", current_volume);

    int16_t ch1_offset;
    pt2258_ctrl_get_offset(ctrl_handle, 1, &ch1_offset);
    ESP_LOGI(TAG, "Channel 1 offset: %d dB", ch1_offset);

    uint8_t ch1_attenuation;
    pt2258_ctrl_get_attenuation(ctrl_handle, 1, &ch1_attenuation);
    ESP_LOGI(TAG, "Channel 1 attenuation: %d dB", ch1_attenuation);

    // ... your application logic ...

    // 9. Clean up resources when done
    pt2258_ctrl_delete(&ctrl_handle);
    pt2258_delete(&pt2258_handle);
}
```

Links

Supports all targets

To add this component to your project, run:

idf.py add-dependency "romr/pt2258_ctrl^0.1.0"

download archive

Stats

  • Archive size
    Archive size ~ 6.77 KB
  • Downloaded in total
    Downloaded in total 0 times
  • Downloaded this version
    This version: 0 times

Badge

romr/pt2258_ctrl version: 0.1.0
|