Skip to content

Commit

Permalink
Share the temperature readings between boards v2 to v5
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeprag committed May 22, 2022
1 parent 0623c84 commit 7fd6d8c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 108 deletions.
1 change: 1 addition & 0 deletions src/epd_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(app_sources "epd_driver.c"
"rmt_pulse.c"
"highlevel.c"
"epd_temperature.c"
"board/epd_board_common.c"
"board/epd_board_lilygo_t5_47.c"
"board/epd_board_v2_v3.c"
"board/epd_board_v4.c"
Expand Down
35 changes: 35 additions & 0 deletions src/epd_driver/board/epd_board_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "../epd_board.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "esp_log.h"

static const adc1_channel_t channel = ADC1_CHANNEL_7;
static esp_adc_cal_characteristics_t adc_chars;

#define NUMBER_OF_SAMPLES 100

void epd_board_temperature_init_v2() {
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(
ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, 1100, &adc_chars
);
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
ESP_LOGI("epd_temperature", "Characterized using Two Point Value\n");
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
ESP_LOGI("esp_temperature", "Characterized using eFuse Vref\n");
} else {
ESP_LOGI("esp_temperature", "Characterized using Default Vref\n");
}
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(channel, ADC_ATTEN_DB_6);
}

float epd_board_ambient_temperature_v2() {
uint32_t value = 0;
for (int i = 0; i < NUMBER_OF_SAMPLES; i++) {
value += adc1_get_raw(channel);
}
value /= NUMBER_OF_SAMPLES;
// voltage in mV
float voltage = esp_adc_cal_raw_to_voltage(value, &adc_chars);
return (voltage - 500.0) / 10.0;
}
8 changes: 8 additions & 0 deletions src/epd_driver/board/epd_board_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @file "epd_board_common.h"
* @brief Common board functions shared between boards.
*/
#pragma once

void epd_board_temperature_init_v2();
float epd_board_ambient_temperature_v2();
39 changes: 3 additions & 36 deletions src/epd_driver/board/epd_board_v2_v3.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "epd_board.h"

#include "epd_board_common.h"
#include "../display_ops.h"
#include "../i2s_data_bus.h"
#include "../rmt_pulse.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "esp_log.h"

#define CFG_DATA GPIO_NUM_23
#define CFG_CLK GPIO_NUM_18
Expand All @@ -26,11 +24,6 @@
/* Edges */
#define CKH GPIO_NUM_5

static const adc1_channel_t channel = ADC1_CHANNEL_7;
static esp_adc_cal_characteristics_t adc_chars;

#define NUMBER_OF_SAMPLES 100

typedef struct {
bool power_disable : 1;
bool pos_power_enable : 1;
Expand Down Expand Up @@ -155,39 +148,13 @@ static void epd_board_poweroff(epd_ctrl_state_t *state) {
// END POWEROFF
}

static void epd_board_temperature_init() {
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(
ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, 1100, &adc_chars
);
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
ESP_LOGI("epd_temperature", "Characterized using Two Point Value\n");
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
ESP_LOGI("esp_temperature", "Characterized using eFuse Vref\n");
} else {
ESP_LOGI("esp_temperature", "Characterized using Default Vref\n");
}
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(channel, ADC_ATTEN_DB_6);
}

static float epd_board_ambient_temperature() {
uint32_t value = 0;
for (int i = 0; i < NUMBER_OF_SAMPLES; i++) {
value += adc1_get_raw(channel);
}
value /= NUMBER_OF_SAMPLES;
// voltage in mV
float voltage = esp_adc_cal_raw_to_voltage(value, &adc_chars);
return (voltage - 500.0) / 10.0;
}

const EpdBoardDefinition epd_board_v2_v3 = {
.init = epd_board_init,
.deinit = NULL,
.set_ctrl = epd_board_set_ctrl,
.poweron = epd_board_poweron,
.poweroff = epd_board_poweroff,

.temperature_init = epd_board_temperature_init,
.ambient_temperature = epd_board_ambient_temperature,
.temperature_init = epd_board_temperature_init_v2,
.ambient_temperature = epd_board_ambient_temperature_v2,
};
39 changes: 3 additions & 36 deletions src/epd_driver/board/epd_board_v4.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "epd_board.h"

#include "epd_board_common.h"
#include "../display_ops.h"
#include "../i2s_data_bus.h"
#include "../rmt_pulse.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "esp_log.h"

#define CFG_DATA GPIO_NUM_23
#define CFG_CLK GPIO_NUM_18
Expand All @@ -28,11 +26,6 @@
/* Edges */
#define CKH GPIO_NUM_5

static const adc1_channel_t channel = ADC1_CHANNEL_7;
static esp_adc_cal_characteristics_t adc_chars;

#define NUMBER_OF_SAMPLES 100

typedef struct {
bool power_disable : 1;
bool power_enable_vpos : 1;
Expand Down Expand Up @@ -177,39 +170,13 @@ static void epd_board_poweroff(epd_ctrl_state_t *state) {
// END POWEROFF
}

static void epd_board_temperature_init() {
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(
ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, 1100, &adc_chars
);
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
ESP_LOGI("epd_temperature", "Characterized using Two Point Value\n");
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
ESP_LOGI("esp_temperature", "Characterized using eFuse Vref\n");
} else {
ESP_LOGI("esp_temperature", "Characterized using Default Vref\n");
}
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(channel, ADC_ATTEN_DB_6);
}

static float epd_board_ambient_temperature() {
uint32_t value = 0;
for (int i = 0; i < NUMBER_OF_SAMPLES; i++) {
value += adc1_get_raw(channel);
}
value /= NUMBER_OF_SAMPLES;
// voltage in mV
float voltage = esp_adc_cal_raw_to_voltage(value, &adc_chars);
return (voltage - 500.0) / 10.0;
}

const EpdBoardDefinition epd_board_v4 = {
.init = epd_board_init,
.deinit = NULL,
.set_ctrl = epd_board_set_ctrl,
.poweron = epd_board_poweron,
.poweroff = epd_board_poweroff,

.temperature_init = epd_board_temperature_init,
.ambient_temperature = epd_board_ambient_temperature,
.temperature_init = epd_board_temperature_init_v2,
.ambient_temperature = epd_board_ambient_temperature_v2,
};
39 changes: 3 additions & 36 deletions src/epd_driver/board/epd_board_v5.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "epd_board.h"

#include "epd_board_common.h"
#include "driver/rtc_io.h"
#include "../display_ops.h"
#include "../i2s_data_bus.h"
#include "../rmt_pulse.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "esp_log.h"

#define CFG_DATA GPIO_NUM_33
#define CFG_CLK GPIO_NUM_32
Expand All @@ -29,11 +27,6 @@
/* Edges */
#define CKH GPIO_NUM_15

static const adc1_channel_t channel = ADC1_CHANNEL_7;
static esp_adc_cal_characteristics_t adc_chars;

#define NUMBER_OF_SAMPLES 100

typedef struct {
bool power_enable : 1;
bool power_enable_vpos : 1;
Expand Down Expand Up @@ -178,39 +171,13 @@ static void epd_board_poweroff(epd_ctrl_state_t *state) {
// END POWEROFF
}

static void epd_board_temperature_init() {
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(
ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, 1100, &adc_chars
);
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
ESP_LOGI("epd_temperature", "Characterized using Two Point Value\n");
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
ESP_LOGI("esp_temperature", "Characterized using eFuse Vref\n");
} else {
ESP_LOGI("esp_temperature", "Characterized using Default Vref\n");
}
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(channel, ADC_ATTEN_DB_6);
}

static float epd_board_ambient_temperature() {
uint32_t value = 0;
for (int i = 0; i < NUMBER_OF_SAMPLES; i++) {
value += adc1_get_raw(channel);
}
value /= NUMBER_OF_SAMPLES;
// voltage in mV
float voltage = esp_adc_cal_raw_to_voltage(value, &adc_chars);
return (voltage - 500.0) / 10.0;
}

const EpdBoardDefinition epd_board_v5 = {
.init = epd_board_init,
.deinit = NULL,
.set_ctrl = epd_board_set_ctrl,
.poweron = epd_board_poweron,
.poweroff = epd_board_poweroff,

.temperature_init = epd_board_temperature_init,
.ambient_temperature = epd_board_ambient_temperature,
.temperature_init = epd_board_temperature_init_v2,
.ambient_temperature = epd_board_ambient_temperature_v2,
};

0 comments on commit 7fd6d8c

Please sign in to comment.