kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Add I2C_Mutex
rodzic
6e51d2b506
commit
11a90da716
|
@ -171,15 +171,15 @@ void vTaskDISP(void* pvParameters)
|
||||||
// #endif
|
// #endif
|
||||||
{ switch(DISP_Page)
|
{ switch(DISP_Page)
|
||||||
{ case 2: OLED_DrawGPS (&U8G2_OLED, GPS); break;
|
{ case 2: OLED_DrawGPS (&U8G2_OLED, GPS); break;
|
||||||
case 3: OLED_DrawRF (&U8G2_OLED); break;
|
case 3: OLED_DrawRF (&U8G2_OLED, GPS); break;
|
||||||
case 4: OLED_DrawBaro (&U8G2_OLED, GPS); break;
|
case 4: OLED_DrawBaro (&U8G2_OLED, GPS); break;
|
||||||
case 1: OLED_DrawID (&U8G2_OLED); break;
|
case 1: OLED_DrawID (&U8G2_OLED, GPS); break;
|
||||||
case 5: OLED_DrawSystem(&U8G2_OLED); break;
|
case 5: OLED_DrawSystem(&U8G2_OLED, GPS); break;
|
||||||
// case 6: OLED_DrawRelay (&U8G2_OLED, GPS); break;
|
// case 6: OLED_DrawRelay (&U8G2_OLED, GPS); break;
|
||||||
// case 7: OLED_DrawLookout(&U8G2_OLED, GPS); break;
|
// case 7: OLED_DrawLookout(&U8G2_OLED, GPS); break;
|
||||||
case 0: OLED_DrawBattery(&U8G2_OLED); break;
|
case 0: OLED_DrawBattery(&U8G2_OLED, GPS); break;
|
||||||
#ifdef WITH_U8G2_LISTS
|
#ifdef WITH_U8G2_LISTS
|
||||||
case 6: OLED_DrawRelay (&U8G2_OLED, GPS); break;
|
case 6: OLED_DrawRelay (&U8G2_OLED, GPS); break;
|
||||||
case 7: OLED_DrawLookout(&U8G2_OLED, GPS); break;
|
case 7: OLED_DrawLookout(&U8G2_OLED, GPS); break;
|
||||||
case 9: OLED_DrawTrafWarn(&U8G2_OLED, GPS); break;
|
case 9: OLED_DrawTrafWarn(&U8G2_OLED, GPS); break;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1281,7 +1281,9 @@ static uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int
|
||||||
break; }
|
break; }
|
||||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||||
{ i2c_master_stop(U8G2_Cmd);
|
{ i2c_master_stop(U8G2_Cmd);
|
||||||
|
xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||||
i2c_master_cmd_begin(I2C_BUS, U8G2_Cmd, 10);
|
i2c_master_cmd_begin(I2C_BUS, U8G2_Cmd, 10);
|
||||||
|
xSemaphoreGive(I2C_Mutex);
|
||||||
i2c_cmd_link_delete(U8G2_Cmd);
|
i2c_cmd_link_delete(U8G2_Cmd);
|
||||||
break; }
|
break; }
|
||||||
}
|
}
|
||||||
|
@ -1907,7 +1909,7 @@ int SPIFFS_Info(size_t &Total, size_t &Used, const char *Label)
|
||||||
|
|
||||||
// ======================================================================================================
|
// ======================================================================================================
|
||||||
|
|
||||||
// SemaphoreHandle_t I2C_Mutex;
|
SemaphoreHandle_t I2C_Mutex;
|
||||||
|
|
||||||
uint8_t I2C_Read(uint8_t Bus, uint8_t Addr, uint8_t Reg, uint8_t *Data, uint8_t Len, uint8_t Wait)
|
uint8_t I2C_Read(uint8_t Bus, uint8_t Addr, uint8_t Reg, uint8_t *Data, uint8_t Len, uint8_t Wait)
|
||||||
{ i2c_cmd_handle_t Cmd = i2c_cmd_link_create();
|
{ i2c_cmd_handle_t Cmd = i2c_cmd_link_create();
|
||||||
|
@ -1918,7 +1920,9 @@ uint8_t I2C_Read(uint8_t Bus, uint8_t Addr, uint8_t Reg, uint8_t *Data, uint8_t
|
||||||
i2c_master_write_byte(Cmd, (Addr<<1) | I2C_MASTER_READ, I2C_MASTER_ACK);
|
i2c_master_write_byte(Cmd, (Addr<<1) | I2C_MASTER_READ, I2C_MASTER_ACK);
|
||||||
i2c_master_read(Cmd, Data, Len, I2C_MASTER_LAST_NACK);
|
i2c_master_read(Cmd, Data, Len, I2C_MASTER_LAST_NACK);
|
||||||
i2c_master_stop(Cmd);
|
i2c_master_stop(Cmd);
|
||||||
|
xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||||
esp_err_t Ret = i2c_master_cmd_begin((i2c_port_t)Bus, Cmd, Wait);
|
esp_err_t Ret = i2c_master_cmd_begin((i2c_port_t)Bus, Cmd, Wait);
|
||||||
|
xSemaphoreGive(I2C_Mutex);
|
||||||
i2c_cmd_link_delete(Cmd);
|
i2c_cmd_link_delete(Cmd);
|
||||||
return Ret; }
|
return Ret; }
|
||||||
|
|
||||||
|
@ -1929,7 +1933,9 @@ uint8_t I2C_Write(uint8_t Bus, uint8_t Addr, uint8_t Reg, uint8_t *Data, uint8_t
|
||||||
i2c_master_write_byte(Cmd, Reg , I2C_MASTER_ACK);
|
i2c_master_write_byte(Cmd, Reg , I2C_MASTER_ACK);
|
||||||
i2c_master_write(Cmd, Data, Len, I2C_MASTER_NACK);
|
i2c_master_write(Cmd, Data, Len, I2C_MASTER_NACK);
|
||||||
i2c_master_stop(Cmd);
|
i2c_master_stop(Cmd);
|
||||||
|
xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||||
esp_err_t Ret = i2c_master_cmd_begin((i2c_port_t)Bus, Cmd, Wait);
|
esp_err_t Ret = i2c_master_cmd_begin((i2c_port_t)Bus, Cmd, Wait);
|
||||||
|
xSemaphoreGive(I2C_Mutex);
|
||||||
i2c_cmd_link_delete(Cmd);
|
i2c_cmd_link_delete(Cmd);
|
||||||
return Ret; }
|
return Ret; }
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ extern uint8_t MAV_Seq; // sequence number for MAVlink messag
|
||||||
// ============================================================================================================
|
// ============================================================================================================
|
||||||
|
|
||||||
extern SemaphoreHandle_t CONS_Mutex; // console port Mutex
|
extern SemaphoreHandle_t CONS_Mutex; // console port Mutex
|
||||||
// extern SemaphoreHandle_t I2C_Mutex; // I2C port Mutex (OLED and Baro)
|
extern SemaphoreHandle_t I2C_Mutex; // I2C port Mutex (OLED and Baro)
|
||||||
|
|
||||||
uint64_t getUniqueID(void); // get some unique ID of the CPU/chip
|
uint64_t getUniqueID(void); // get some unique ID of the CPU/chip
|
||||||
uint32_t getUniqueAddress(void); // get unique 24-bit address for the transmitted IF
|
uint32_t getUniqueAddress(void); // get unique 24-bit address for the transmitted IF
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "proc.h" // GPS/RF process taskk
|
#include "proc.h" // GPS/RF process taskk
|
||||||
#include "gps.h" // GPS control data acquisiton
|
#include "gps.h" // GPS control data acquisiton
|
||||||
#include "sens.h"
|
#include "sens.h"
|
||||||
|
#include "imu.h"
|
||||||
#include "ctrl.h" // Control task
|
#include "ctrl.h" // Control task
|
||||||
#include "log.h" // Data logging task
|
#include "log.h" // Data logging task
|
||||||
#include "knob.h" // potentiometer as rotary encoder
|
#include "knob.h" // potentiometer as rotary encoder
|
||||||
|
@ -29,7 +30,7 @@ void app_main(void)
|
||||||
// printf("OGN Tracker on ESP32\n");
|
// printf("OGN Tracker on ESP32\n");
|
||||||
|
|
||||||
CONS_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the writing to the console
|
CONS_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the writing to the console
|
||||||
// I2C_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the I2C bus
|
I2C_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the I2C bus
|
||||||
|
|
||||||
NVS_Init(); // initialize Non-Volatile-Storage in Flash and read the tracker parameters
|
NVS_Init(); // initialize Non-Volatile-Storage in Flash and read the tracker parameters
|
||||||
|
|
||||||
|
@ -75,6 +76,9 @@ void app_main(void)
|
||||||
#if defined(WITH_BMP180) || defined(WITH_BMP280) || defined(WITH_BME280) || defined(WITH_MS5607) || defined(WITH_MS5611)
|
#if defined(WITH_BMP180) || defined(WITH_BMP280) || defined(WITH_BME280) || defined(WITH_MS5607) || defined(WITH_MS5611)
|
||||||
xTaskCreate(vTaskSENS, "SENS", 2048, 0, tskIDLE_PRIORITY+4, 0);
|
xTaskCreate(vTaskSENS, "SENS", 2048, 0, tskIDLE_PRIORITY+4, 0);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WITH_BMX055
|
||||||
|
xTaskCreate(vTaskIMU, "IMU", 2048, 0, tskIDLE_PRIORITY+4, 0);
|
||||||
|
#endif
|
||||||
#ifdef WITH_KNOB
|
#ifdef WITH_KNOB
|
||||||
xTaskCreate(vTaskKNOB, "KNOB", 2048, 0, tskIDLE_PRIORITY+3, 0);
|
xTaskCreate(vTaskKNOB, "KNOB", 2048, 0, tskIDLE_PRIORITY+3, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -97,7 +97,7 @@ static Delay<int32_t, 8> PressDelay; // 4-second delay for long-term clim
|
||||||
|
|
||||||
static char Line[96]; // line to prepare the barometer NMEA sentence
|
static char Line[96]; // line to prepare the barometer NMEA sentence
|
||||||
|
|
||||||
static uint8_t InitBaro()
|
static uint8_t InitBaro(void)
|
||||||
{ // xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
{ // xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||||
Baro.Bus=BARO_I2C;
|
Baro.Bus=BARO_I2C;
|
||||||
uint8_t Err=Baro.CheckID();
|
uint8_t Err=Baro.CheckID();
|
||||||
|
|
Ładowanie…
Reference in New Issue