Skip to content

Commit

Permalink
added logic for barrel jack and voltage regulator switch, board version
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-wilson committed Jan 13, 2024
1 parent 174ef21 commit ef344f2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ <h2>Overview</h2>
<td>Version:</td>
<td>{{info.version}}</td>
</tr>
<tr>
<td>Board Version:</td>
<td>{{info.boardVersion}}</td>
</tr>
</table>
</div>
<div class="card">
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/app/services/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class SystemService {
stratumUser: "bc1q99n3pu025yyu0jlywpmwzalyhm36tg5u37w20d.bitaxe-U1",
frequency: 485,
version: "2.0",
boardVersion: "204",
flipscreen: 1,
invertscreen: 0,
invertfanpolarity: 1,
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/models/ISystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ISystemInfo {
stratumUser: string,
frequency: number,
version: string,
boardVersion: string,
invertfanpolarity: number,
autofanspeed: number,
fanspeed: number,
Expand Down
7 changes: 5 additions & 2 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@ static esp_err_t GET_system_info(httpd_req_t * req)
char * ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, CONFIG_ESP_WIFI_SSID);
char * stratumURL = nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL);
char * stratumUser = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER);
char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, 'unknown');

cJSON * root = cJSON_CreateObject();
cJSON * root = cJSON_CreateObject();
cJSON_AddNumberToObject(root, "power", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power);
cJSON_AddNumberToObject(root, "voltage", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.voltage);
cJSON_AddNumberToObject(root, "current", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.current);
Expand All @@ -360,6 +361,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddStringToObject(root, "stratumUser", stratumUser);

cJSON_AddStringToObject(root, "version", esp_app_get_description()->version);
cJSON_AddStringToObject(root, "boardVersion", board_version);
cJSON_AddStringToObject(root, "runningPartition", esp_ota_get_running_partition()->label);

cJSON_AddNumberToObject(root, "flipscreen", nvs_config_get_u16(NVS_CONFIG_FLIP_SCREEN, 1));
Expand All @@ -372,8 +374,9 @@ static esp_err_t GET_system_info(httpd_req_t * req)
free(ssid);
free(stratumURL);
free(stratumUser);
free(board_version);

const char * sys_info = cJSON_Print(root);
const char * sys_info = cJSON_Print(root);
httpd_resp_sendstr(req, sys_info);
free(sys_info);
cJSON_Delete(root);
Expand Down
4 changes: 0 additions & 4 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ static void _init_system(GlobalState * global_state, SystemModule * module)
// ledc_init();
// led_set();

// Playing with BI level
gpio_set_direction(GPIO_NUM_10, GPIO_MODE_OUTPUT);
gpio_set_level(GPIO_NUM_10, 0);

// Init I2C
ESP_ERROR_CHECK(i2c_master_init());
ESP_LOGI(TAG, "I2C initialized successfully");
Expand Down
52 changes: 46 additions & 6 deletions main/tasks/power_management_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "serial.h"
#include <string.h>

#define POLL_RATE 5000
#define POLL_RATE 2000
#define MAX_TEMP 90.0
#define THROTTLE_TEMP 75.0
#define THROTTLE_TEMP_RANGE (MAX_TEMP - THROTTLE_TEMP)
Expand Down Expand Up @@ -42,6 +42,12 @@ void POWER_MANAGEMENT_task(void * pvParameters)

power_management->frequency_multiplier = 1;

char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "unknown");
power_management->HAS_POWER_EN =
(strcmp(board_version, "202") == 1 || strcmp(board_version, "203") == 1 || strcmp(board_version, "204") == 1);
power_management->HAS_PLUG_SENSE = strcmp(board_version, "204") == 1;
free(board_version);

int last_frequency_increase = 0;

bool read_power = INA260_installed();
Expand All @@ -50,6 +56,23 @@ void POWER_MANAGEMENT_task(void * pvParameters)

uint16_t auto_fan_speed = nvs_config_get_u16(NVS_CONFIG_AUTO_FAN_SPEED, 1);

// Configure GPIO12 as input(barrel jack) 1 is plugged in
gpio_config_t barrel_jack_conf = {
.pin_bit_mask = (1ULL << GPIO_NUM_12),
.mode = GPIO_MODE_INPUT,
};
gpio_config(&barrel_jack_conf);
int barrel_jack_plugged_in = gpio_get_level(GPIO_NUM_12);

gpio_set_direction(GPIO_NUM_10, GPIO_MODE_OUTPUT);
if (barrel_jack_plugged_in == 1 || !power_management->HAS_PLUG_SENSE) {
// turn ASIC on
gpio_set_level(GPIO_NUM_10, 0);
} else {
// turn ASIC off
gpio_set_level(GPIO_NUM_10, 1);
}

vTaskDelay(3000 / portTICK_PERIOD_MS);

while (1) {
Expand Down Expand Up @@ -124,11 +147,18 @@ void POWER_MANAGEMENT_task(void * pvParameters)
if (power_management->chip_temp > THROTTLE_TEMP &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
ESP_LOGE(TAG, "OVERHEAT");
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 990);
nvs_config_set_u16(NVS_CONFIG_ASIC_FREQ, 50);
nvs_config_set_u16(NVS_CONFIG_FAN_SPEED, 100);
nvs_config_set_u16(NVS_CONFIG_AUTO_FAN_SPEED, 0);
exit(EXIT_FAILURE);


if (power_management->HAS_POWER_EN) {
gpio_set_level(GPIO_NUM_10, 1);
} else {
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 990);
nvs_config_set_u16(NVS_CONFIG_ASIC_FREQ, 50);
nvs_config_set_u16(NVS_CONFIG_FAN_SPEED, 100);
nvs_config_set_u16(NVS_CONFIG_AUTO_FAN_SPEED, 0);
exit(EXIT_FAILURE);
}

}
}

Expand All @@ -139,6 +169,16 @@ void POWER_MANAGEMENT_task(void * pvParameters)
}
// ESP_LOGI(TAG, "target %f, Freq %f, Volt %f, Power %f", target_frequency, power_management->frequency_value,
// power_management->voltage, power_management->power);

// Read the state of GPIO12
if (power_management->HAS_PLUG_SENSE) {
int gpio12_state = gpio_get_level(GPIO_NUM_12);
if (gpio12_state == 0) {
// turn ASIC off
gpio_set_level(GPIO_NUM_10, 1);
}
}

vTaskDelay(POLL_RATE / portTICK_PERIOD_MS);
}
}
Expand Down
2 changes: 2 additions & 0 deletions main/tasks/power_management_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ typedef struct
float frequency_value;
float power;
float current;
bool HAS_POWER_EN;
bool HAS_PLUG_SENSE;
} PowerManagementModule;

static void automatic_fan_speed(float chip_temp);
Expand Down

0 comments on commit ef344f2

Please sign in to comment.