Skip to content
Open
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
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SRCS
"./bap/bap_uart.c"
"./bap/bap_handlers.c"
"./bap/bap_subscription.c"
"device_pins.c"
"device_config.c"
"task_monitor.c"
"./http_server/http_server.c"
Expand Down
32 changes: 20 additions & 12 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,34 @@ menu "Bitaxe Configuration"
GPIO pin for DC barrel (PLUG_SENSE), sense pin of DC power jack socket.

config GPIO_I2C_SDA
int "I2C SDA Pin"
default 47
int "I2C SDA Pin Override (-1 to use board default)"
default -1
help
GPIO pin for I2C clock line (SDA).
GPIO pin override for I2C SDA line. Set to -1 to use board default.

config GPIO_I2C_SCL
int "I2C SCL Pin"
default 48
int "I2C SCL Pin Override (-1 to use board default)"
default -1
help
GPIO pin for I2C clock line (SCL).
GPIO pin override for I2C SCL line. Set to -1 to use board default.

config ENABLE_BAP
bool "Enable BAP (Bitaxe Accessory Protocol)"
default y
help
Enable or disable Bitaxe Accessory Protocol (BAP) UART communication.

config GPIO_BAP_RX
int "I2C BAP Pin"
default 40
int "BAP RX Pin Override (-1 to use board default)"
default -1
help
GPIO pin for BAP receiving line.
GPIO pin override for BAP receiving line. Set to -1 to use board default.

config GPIO_BAP_TX
int "I2C BAP Pin"
default 39
int "BAP TX Pin Override (-1 to use board default)"
default -1
help
GPIO pin for BAP transmitting line.
GPIO pin override for BAP transmitting line. Set to -1 to use board default.

endmenu

Expand Down
5 changes: 5 additions & 0 deletions main/bap/bap.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ esp_err_t BAP_init(GlobalState *state) {
ESP_LOGE(TAG, "Invalid global state pointer");
return ESP_ERR_INVALID_ARG;
}

if (state->DEVICE_CONFIG.pins.bap == NULL) {
ESP_LOGW(TAG, "BAP UART disabled on %s", state->DEVICE_CONFIG.family.name);
return ESP_OK;
}

bap_global_state = state;

Expand Down
8 changes: 5 additions & 3 deletions main/bap/bap_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ Device: $BAP,STA,status,restarting*5E\r\n

## Configuration

BAP uses the following GPIO pins for UART communication:
- **RX**: Configurable via `CONFIG_GPIO_BAP_RX`
- **TX**: Configurable via `CONFIG_GPIO_BAP_TX`
BAP UART pin assignments are defined per board revision in `DeviceConfig.pins.bap`:
- **Default Pins**: RX (GPIO 40), TX (GPIO 39)
- **Kconfig Enable/Disable**: Configurable via `CONFIG_ENABLE_BAP` (default `y`). Setting to `n` disables BAP.
- **Kconfig Pin Overrides**: Optionally configurable via `CONFIG_GPIO_BAP_RX` and `CONFIG_GPIO_BAP_TX` (set to `-1` to use board defaults).
- **Board Support**: If `pins.bap` is set to `NULL` for a board configuration or via `CONFIG_ENABLE_BAP=n`, BAP UART is automatically disabled.

UART settings:
- Baud rate: 115200
Expand Down
14 changes: 5 additions & 9 deletions main/bap/bap_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "esp_log.h"
#include "esp_err.h"
#include "device_config.h"
#include "global_state.h"
#include "bap_uart.h"
#include "bap_protocol.h"
#include "bap.h"
Expand All @@ -25,9 +26,6 @@
#define UART_SEND_TIMEOUT_MS 1000
#define UART_BUFFER_THRESHOLD (BAP_BUF_SIZE / 2)

#define GPIO_BAP_RX CONFIG_GPIO_BAP_RX
#define GPIO_BAP_TX CONFIG_GPIO_BAP_TX

static const char *TAG = "BAP_UART";

static TaskHandle_t uart_send_task_handle = NULL;
Expand Down Expand Up @@ -227,11 +225,6 @@ esp_err_t BAP_start_uart_receive_task(void) {
esp_err_t BAP_uart_init(void) {
//ESP_LOGI(TAG, "Initializing BAP UART interface");

if (GPIO_BAP_TX > 47 || GPIO_BAP_RX > 47) {
ESP_LOGE(TAG, "Invalid GPIO pins: TX=%d, RX=%d", GPIO_BAP_TX, GPIO_BAP_RX);
return ESP_ERR_INVALID_ARG;
}

uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
Expand All @@ -247,7 +240,10 @@ esp_err_t BAP_uart_init(void) {
return ret;
}

ret = uart_set_pin(BAP_UART_NUM, GPIO_BAP_TX, GPIO_BAP_RX, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
gpio_num_t bap_tx = bap_global_state->DEVICE_CONFIG.pins.bap->tx;
gpio_num_t bap_rx = bap_global_state->DEVICE_CONFIG.pins.bap->rx;

ret = uart_set_pin(BAP_UART_NUM, bap_tx, bap_rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to set UART pins: %d", ret);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions main/device_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ esp_err_t device_config_init(void * pvParameters)
ESP_LOGI(TAG, "ASIC: %dx %s (%d cores)", GLOBAL_STATE->DEVICE_CONFIG.family.asic_count, GLOBAL_STATE->DEVICE_CONFIG.family.asic.name, GLOBAL_STATE->DEVICE_CONFIG.family.asic.core_count);

free(board_version);
return ESP_OK;
return device_pins_init(&GLOBAL_STATE->DEVICE_CONFIG.pins);
}
}

Expand Down Expand Up @@ -78,5 +78,5 @@ esp_err_t device_config_init(void * pvParameters)
free(device_model);
free(asic_model);

return ESP_OK;
return device_pins_init(&GLOBAL_STATE->DEVICE_CONFIG.pins);
}
48 changes: 25 additions & 23 deletions main/device_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "device_pins.h"

#define THERMAL_MAX_SENSORS 2

Expand Down Expand Up @@ -62,6 +63,7 @@ typedef struct {
FamilyConfig family;
bool plug_sense;
bool asic_enable;
DevicePins pins;
bool EMC2101 : 1;
bool EMC2103 : 1;
bool EMC2302 : 1;
Expand Down Expand Up @@ -123,29 +125,29 @@ static const FamilyConfig default_families[] = {
};

static const DeviceConfig default_configs[] = {
{ .board_version = "2.2", .family = FAMILY_MAX, .EMC2101 = true, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "102", .family = FAMILY_MAX, .EMC2101 = true, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "0.11", .family = FAMILY_ULTRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "201", .family = FAMILY_ULTRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "202", .family = FAMILY_ULTRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "203", .family = FAMILY_ULTRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "204", .family = FAMILY_ULTRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .power_consumption_target = 12, },
{ .board_version = "205", .family = FAMILY_ULTRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "207", .family = FAMILY_ULTRA, .EMC2101 = true, .TPS546 = true, .power_consumption_target = 12, },
{ .board_version = "302", .family = FAMILY_HEX, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 40, },
{ .board_version = "303", .family = FAMILY_HEX, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 40, },
{ .board_version = "400", .family = FAMILY_SUPRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "401", .family = FAMILY_SUPRA, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "402", .family = FAMILY_SUPRA, .EMC2101 = true, .TPS546 = true, .power_consumption_target = 8, },
{ .board_version = "403", .family = FAMILY_SUPRA, .EMC2101 = true, .TPS546 = true, .power_consumption_target = 8, },
{ .board_version = "600", .family = FAMILY_GAMMA, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 19, },
{ .board_version = "601", .family = FAMILY_GAMMA, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 19, },
{ .board_version = "602", .family = FAMILY_GAMMA, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 22, },
{ .board_version = "603", .family = FAMILY_GAMMA, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 22, },
{ .board_version = "650", .family = FAMILY_GAMMA_DUO, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 35, },
{ .board_version = "701", .family = FAMILY_SUPRA_HEX, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 90, },
{ .board_version = "702", .family = FAMILY_SUPRA_HEX, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 90, },
{ .board_version = "801", .family = FAMILY_GAMMA_TURBO, .EMC2103 = true, .temp_flip = true, .temp_offset = 0, .TPS546 = true, .power_consumption_target = 36, },
{ .board_version = "2.2", .family = FAMILY_MAX, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "102", .family = FAMILY_MAX, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "0.11", .family = FAMILY_ULTRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "201", .family = FAMILY_ULTRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "202", .family = FAMILY_ULTRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "203", .family = FAMILY_ULTRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "204", .family = FAMILY_ULTRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .power_consumption_target = 12, },
{ .board_version = "205", .family = FAMILY_ULTRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "207", .family = FAMILY_ULTRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .TPS546 = true, .power_consumption_target = 12, },
{ .board_version = "302", .family = FAMILY_HEX, .pins = DEFAULT_DEVICE_PINS, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 40, },
{ .board_version = "303", .family = FAMILY_HEX, .pins = DEFAULT_DEVICE_PINS, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 40, },
{ .board_version = "400", .family = FAMILY_SUPRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "401", .family = FAMILY_SUPRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_internal_temp = true, .temp_offset = 5, .DS4432U = true, .INA260 = true, .plug_sense = true, .asic_enable = true, .power_consumption_target = 12, },
{ .board_version = "402", .family = FAMILY_SUPRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .TPS546 = true, .power_consumption_target = 8, },
{ .board_version = "403", .family = FAMILY_SUPRA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .TPS546 = true, .power_consumption_target = 8, },
{ .board_version = "600", .family = FAMILY_GAMMA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 19, },
{ .board_version = "601", .family = FAMILY_GAMMA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 19, },
{ .board_version = "602", .family = FAMILY_GAMMA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 22, },
{ .board_version = "603", .family = FAMILY_GAMMA, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 22, },
{ .board_version = "650", .family = FAMILY_GAMMA_DUO, .pins = DEFAULT_DEVICE_PINS, .EMC2101 = true, .emc_ideality_factor = 0x24, .emc_beta_compensation = 0x00, .TPS546 = true, .power_consumption_target = 35, },
{ .board_version = "701", .family = FAMILY_SUPRA_HEX, .pins = DEFAULT_DEVICE_PINS, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 90, },
{ .board_version = "702", .family = FAMILY_SUPRA_HEX, .pins = DEFAULT_DEVICE_PINS, .EMC2302 = true, .TMP1075 = true, .temp_offset = 10, .TPS546 = true, .power_consumption_target = 90, },
{ .board_version = "801", .family = FAMILY_GAMMA_TURBO, .pins = DEFAULT_DEVICE_PINS, .EMC2103 = true, .temp_flip = true, .temp_offset = 0, .TPS546 = true, .power_consumption_target = 36, },
};

esp_err_t device_config_init(void * pvParameters);
Expand Down
Loading
Loading