resistor switching

This commit is contained in:
leo 2023-06-13 10:38:29 +02:00
commit 4c2cfee6f2
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
7 changed files with 1718 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.cache
build

8
CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(power_profiler)

3
main/CMakeLists.txt Normal file
View File

@ -0,0 +1,3 @@
idf_component_register(SRCS "power_profiler.c" "resistor_ranges.c"
INCLUDE_DIRS "."
REQUIRES "driver")

41
main/power_profiler.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdio.h>
#include "driver/gpio.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/portmacro.h"
#include "resistor_ranges.h"
#define TAG "main"
enum ranges {R1, R10, R100, R_NUM};
resistor_range ranges[] = {
[R1] = {
.pin = GPIO_NUM_6,
.resistance = 1,
},
[R10] = {
.pin = GPIO_NUM_7,
.resistance = 10,
},
[R100] = {
.pin = GPIO_NUM_NC,
.resistance = 100,
},
};
unsigned int r_ind = 0;
void app_main(void){
set_resistor_gpio(ranges, R100);
while(1){
ESP_LOGI(TAG, "RANGE : %d", r_ind);
activate_range(ranges, r_ind, R100);
vTaskDelay(5000 / portTICK_PERIOD_MS);
r_ind = (r_ind + 1) % R_NUM;
}
}

31
main/resistor_ranges.c Normal file
View File

@ -0,0 +1,31 @@
#include "driver/gpio.h"
#include "hal/gpio_types.h"
#include "esp_log.h"
#include "resistor_ranges.h"
// set all required pins as output
void set_resistor_gpio(resistor_range ranges[], int range_num){
uint64_t pin_mask = 0;
for(int i = 0; i < range_num; i++){
pin_mask |= 1ULL << ranges[i].pin;
}
gpio_config_t conf = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = pin_mask,
.pull_down_en = 0,
.pull_up_en = 0,
};
ESP_ERROR_CHECK(gpio_config(&conf));
}
void activate_range(resistor_range ranges[], int index, int range_num){
for(int i = 0; i < range_num; i++){
ESP_LOGI("RES_RANGE", "%d %d", ranges[i].pin, i==index);
ESP_ERROR_CHECK(gpio_set_level(ranges[i].pin, i == index));
}
}

9
main/resistor_ranges.h Normal file
View File

@ -0,0 +1,9 @@
#include "hal/gpio_types.h"
typedef struct {
gpio_num_t pin;
unsigned int resistance; // milliohm
} resistor_range;
void set_resistor_gpio(resistor_range ranges[], int range_num);
void activate_range(resistor_range ranges[], int index, int range_num);

1624
sdkconfig Normal file

File diff suppressed because it is too large Load Diff