chore: snapshot before shared RS485 bus integration
This commit is contained in:
0
components/peripherals/CMakeLists.txt
Executable file → Normal file
0
components/peripherals/CMakeLists.txt
Executable file → Normal file
0
components/peripherals/include/ac_relay.h
Executable file → Normal file
0
components/peripherals/include/ac_relay.h
Executable file → Normal file
3
components/peripherals/include/adc.h
Executable file → Normal file
3
components/peripherals/include/adc.h
Executable file → Normal file
@@ -11,4 +11,7 @@ extern adc_cali_handle_t adc_cali_handle;
|
||||
|
||||
void adc_init(void);
|
||||
|
||||
void adc_lock(void);
|
||||
void adc_unlock(void);
|
||||
|
||||
#endif /* ADC_H_ */
|
||||
0
components/peripherals/include/adc121s021_dma.h
Executable file → Normal file
0
components/peripherals/include/adc121s021_dma.h
Executable file → Normal file
0
components/peripherals/include/lm75a.h
Executable file → Normal file
0
components/peripherals/include/lm75a.h
Executable file → Normal file
0
components/peripherals/include/ntc_sensor.h
Executable file → Normal file
0
components/peripherals/include/ntc_sensor.h
Executable file → Normal file
0
components/peripherals/include/peripherals.h
Executable file → Normal file
0
components/peripherals/include/peripherals.h
Executable file → Normal file
0
components/peripherals/include/proximity.h
Executable file → Normal file
0
components/peripherals/include/proximity.h
Executable file → Normal file
0
components/peripherals/include/rcm.h
Executable file → Normal file
0
components/peripherals/include/rcm.h
Executable file → Normal file
0
components/peripherals/include/socket_lock.h
Executable file → Normal file
0
components/peripherals/include/socket_lock.h
Executable file → Normal file
0
components/peripherals/include/temp_sensor.h
Executable file → Normal file
0
components/peripherals/include/temp_sensor.h
Executable file → Normal file
0
components/peripherals/src/ac_relay.c
Executable file → Normal file
0
components/peripherals/src/ac_relay.c
Executable file → Normal file
34
components/peripherals/src/adc.c
Executable file → Normal file
34
components/peripherals/src/adc.c
Executable file → Normal file
@@ -1,5 +1,7 @@
|
||||
#include "adc.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
const static char* TAG = "adc";
|
||||
|
||||
@@ -7,8 +9,40 @@ adc_oneshot_unit_handle_t adc_handle;
|
||||
|
||||
adc_cali_handle_t adc_cali_handle;
|
||||
|
||||
static SemaphoreHandle_t s_adc_mutex;
|
||||
|
||||
static void adc_mutex_init(void)
|
||||
{
|
||||
if (!s_adc_mutex)
|
||||
{
|
||||
s_adc_mutex = xSemaphoreCreateMutex();
|
||||
ESP_ERROR_CHECK(s_adc_mutex ? ESP_OK : ESP_ERR_NO_MEM);
|
||||
}
|
||||
}
|
||||
|
||||
void adc_lock(void)
|
||||
{
|
||||
adc_mutex_init();
|
||||
xSemaphoreTake(s_adc_mutex, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void adc_unlock(void)
|
||||
{
|
||||
if (s_adc_mutex)
|
||||
{
|
||||
xSemaphoreGive(s_adc_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
void adc_init(void)
|
||||
{
|
||||
adc_mutex_init();
|
||||
if (adc_handle)
|
||||
{
|
||||
ESP_LOGD(TAG, "ADC já inicializado");
|
||||
return;
|
||||
}
|
||||
|
||||
adc_oneshot_unit_init_cfg_t conf = {
|
||||
.unit_id = ADC_UNIT_1
|
||||
};
|
||||
|
||||
0
components/peripherals/src/adc121s021_dma.c
Executable file → Normal file
0
components/peripherals/src/adc121s021_dma.c
Executable file → Normal file
0
components/peripherals/src/lm75a.c
Executable file → Normal file
0
components/peripherals/src/lm75a.c
Executable file → Normal file
8
components/peripherals/src/ntc_sensor.c
Executable file → Normal file
8
components/peripherals/src/ntc_sensor.c
Executable file → Normal file
@@ -19,7 +19,11 @@ static void ntc_sensor_task_func(void *param)
|
||||
float t;
|
||||
while (true)
|
||||
{
|
||||
if (ntc_dev_get_temperature(ntc, &t) == ESP_OK)
|
||||
adc_lock();
|
||||
esp_err_t err = ntc_dev_get_temperature(ntc, &t);
|
||||
adc_unlock();
|
||||
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
portENTER_CRITICAL(&temp_mux);
|
||||
temp = t;
|
||||
@@ -59,7 +63,9 @@ void ntc_sensor_init(void)
|
||||
|
||||
// Leitura inicial para log
|
||||
float t0 = 0.0f;
|
||||
adc_lock();
|
||||
esp_err_t err = ntc_dev_get_temperature(ntc, &t0);
|
||||
adc_unlock();
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
portENTER_CRITICAL(&temp_mux);
|
||||
|
||||
0
components/peripherals/src/peripherals.c
Executable file → Normal file
0
components/peripherals/src/peripherals.c
Executable file → Normal file
19
components/peripherals/src/proximity.c
Executable file → Normal file
19
components/peripherals/src/proximity.c
Executable file → Normal file
@@ -19,9 +19,22 @@ void proximity_init(void)
|
||||
|
||||
uint8_t proximity_get_max_current(void)
|
||||
{
|
||||
int voltage;
|
||||
adc_oneshot_read(adc_handle, board_config.proximity_adc_channel, &voltage);
|
||||
adc_cali_raw_to_voltage(adc_cali_handle, voltage, &voltage);
|
||||
int raw = 0;
|
||||
int voltage = 0;
|
||||
|
||||
adc_lock();
|
||||
esp_err_t err = adc_oneshot_read(adc_handle, board_config.proximity_adc_channel, &raw);
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
err = adc_cali_raw_to_voltage(adc_cali_handle, raw, &voltage);
|
||||
}
|
||||
adc_unlock();
|
||||
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ESP_LOGW(TAG, "Erro ao ler/converter ADC proximity: %s", esp_err_to_name(err));
|
||||
return 32;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Measured: %dmV", voltage);
|
||||
|
||||
|
||||
0
components/peripherals/src/rcm.c
Executable file → Normal file
0
components/peripherals/src/rcm.c
Executable file → Normal file
0
components/peripherals/src/socket_lock.c
Executable file → Normal file
0
components/peripherals/src/socket_lock.c
Executable file → Normal file
0
components/peripherals/src/temp_sensor.c
Executable file → Normal file
0
components/peripherals/src/temp_sensor.c
Executable file → Normal file
Reference in New Issue
Block a user