bugfixes i2c bus access
This commit is contained in:
parent
ab5cd0b0a2
commit
e7a416cd7a
@ -40,7 +40,7 @@
|
||||
#define SCREEN_MODE (0x80)
|
||||
|
||||
// I2C bus access control
|
||||
#define I2C_MUTEX_LOCK() xSemaphoreTake(I2Caccess, (DISPLAYREFRESH_MS / portTICK_PERIOD_MS)) == pdTRUE
|
||||
#define I2C_MUTEX_LOCK() xSemaphoreTake(I2Caccess, (3 * DISPLAYREFRESH_MS / portTICK_PERIOD_MS)) == pdTRUE
|
||||
#define I2C_MUTEX_UNLOCK() xSemaphoreGive(I2Caccess)
|
||||
|
||||
// Struct holding devices's runtime configuration
|
||||
|
@ -59,6 +59,9 @@ void DisplayKey(const uint8_t *key, uint8_t len, bool lsb) {
|
||||
|
||||
void init_display(const char *Productname, const char *Version) {
|
||||
|
||||
// block i2c bus access
|
||||
if (I2C_MUTEX_LOCK()) {
|
||||
|
||||
// show startup screen
|
||||
uint8_t buf[32];
|
||||
u8x8.begin();
|
||||
@ -69,14 +72,14 @@ void init_display(const char *Productname, const char *Version) {
|
||||
u8x8.draw2x2String(0, 0, Productname);
|
||||
u8x8.setInverseFont(0);
|
||||
u8x8.draw2x2String(2, 2, Productname);
|
||||
delay(1500);
|
||||
delay(500);
|
||||
u8x8.clear();
|
||||
u8x8.setFlipMode(1);
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.draw2x2String(0, 0, Productname);
|
||||
u8x8.setInverseFont(0);
|
||||
u8x8.draw2x2String(2, 2, Productname);
|
||||
delay(1500);
|
||||
delay(500);
|
||||
|
||||
u8x8.setFlipMode(0);
|
||||
u8x8.clear();
|
||||
@ -94,7 +97,8 @@ void init_display(const char *Productname, const char *Version) {
|
||||
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
|
||||
u8x8.printf("ESP Rev.%d\n", chip_info.revision);
|
||||
u8x8.printf("%dMB %s Flash\n", spi_flash_get_chip_size() / (1024 * 1024),
|
||||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "int." : "ext.");
|
||||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "int."
|
||||
: "ext.");
|
||||
#endif // VERBOSE
|
||||
|
||||
u8x8.print(Productname);
|
||||
@ -105,9 +109,8 @@ void init_display(const char *Productname, const char *Version) {
|
||||
u8x8.println("DEVEUI:");
|
||||
os_getDevEui((u1_t *)buf);
|
||||
DisplayKey(buf, 8, true);
|
||||
#endif // HAS_LORA
|
||||
|
||||
delay(3000);
|
||||
#endif // HAS_LORA
|
||||
u8x8.clear();
|
||||
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
||||
u8x8.draw2x2String(0, 0, "PAX:0");
|
||||
@ -120,6 +123,9 @@ void init_display(const char *Productname, const char *Version) {
|
||||
u8x8.setCursor(0, 5);
|
||||
u8x8.printf(!cfg.rssilimit ? "RLIM:off " : "RLIM:%d", cfg.rssilimit);
|
||||
|
||||
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
||||
}
|
||||
|
||||
} // init_display
|
||||
|
||||
void refreshtheDisplay() {
|
||||
|
@ -95,12 +95,15 @@ int if482_init(void) {
|
||||
IF482.begin(HAS_IF482);
|
||||
|
||||
// use external rtc 1Hz clock for triggering IF482 telegram
|
||||
if (I2C_MUTEX_LOCK()) {
|
||||
Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
|
||||
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
|
||||
I2C_MUTEX_UNLOCK();
|
||||
} else {
|
||||
ESP_LOGE(TAG, "I2c bus busy - IF482 initialization error");
|
||||
return 0;
|
||||
}
|
||||
pinMode(RTC_INT, INPUT_PULLUP);
|
||||
|
||||
ESP_LOGI(TAG, "IF482 generator initialized");
|
||||
|
||||
return 1;
|
||||
|
||||
} // if482_init
|
||||
|
58
src/main.cpp
58
src/main.cpp
@ -92,13 +92,9 @@ void setup() {
|
||||
|
||||
char features[100] = "";
|
||||
|
||||
if (I2Caccess == NULL) // Check that semaphore has not already been created
|
||||
{
|
||||
I2Caccess = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use
|
||||
// to manage the i2c bus
|
||||
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
||||
if ((I2Caccess) != NULL)
|
||||
xSemaphoreGive((I2Caccess)); // Flag the i2c bus available for use
|
||||
}
|
||||
|
||||
// disable brownout detection
|
||||
#ifdef DISABLE_BROWNOUT
|
||||
@ -188,31 +184,6 @@ void setup() {
|
||||
0); // CPU core
|
||||
#endif
|
||||
|
||||
// initialize RTC
|
||||
#ifdef HAS_RTC
|
||||
strcat_P(features, " RTC");
|
||||
assert(rtc_init());
|
||||
setSyncProvider(&get_rtctime);
|
||||
if (timeStatus() != timeSet)
|
||||
ESP_LOGI(TAG, "Unable to sync system time with RTC");
|
||||
else
|
||||
ESP_LOGI(TAG, "RTC has set the system time");
|
||||
setSyncInterval(TIME_SYNC_INTERVAL_RTC * 60);
|
||||
#endif // HAS_RTC
|
||||
|
||||
#ifdef HAS_IF482
|
||||
strcat_P(features, " IF482");
|
||||
assert(if482_init());
|
||||
ESP_LOGI(TAG, "Starting IF482 Generator...");
|
||||
xTaskCreatePinnedToCore(if482_loop, // task function
|
||||
"if482loop", // name of task
|
||||
2048, // stack size of task
|
||||
(void *)1, // parameter of the task
|
||||
3, // priority of the task
|
||||
&IF482Task, // task handle
|
||||
0); // CPU core
|
||||
#endif // HAS_IF482
|
||||
|
||||
// initialize wifi antenna
|
||||
#ifdef HAS_ANTENNA_SWITCH
|
||||
strcat_P(features, " ANT");
|
||||
@ -312,7 +283,7 @@ void setup() {
|
||||
#ifdef HAS_DISPLAY
|
||||
strcat_P(features, " OLED");
|
||||
DisplayState = cfg.screenon;
|
||||
init_display(PRODUCTNAME, PROGVERSION);
|
||||
init_display(PRODUCTNAME, PROGVERSION); // note: blocking call
|
||||
|
||||
// setup display refresh trigger IRQ using esp32 hardware timer
|
||||
// https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
|
||||
@ -350,6 +321,18 @@ void setup() {
|
||||
strcat_P(features, " LPPPKD");
|
||||
#endif
|
||||
|
||||
// initialize RTC
|
||||
#ifdef HAS_RTC
|
||||
strcat_P(features, " RTC");
|
||||
assert(rtc_init());
|
||||
setSyncProvider(&get_rtctime);
|
||||
if (timeStatus() != timeSet)
|
||||
ESP_LOGI(TAG, "Unable to sync system time with RTC");
|
||||
else
|
||||
ESP_LOGI(TAG, "RTC has set the system time");
|
||||
setSyncInterval(TIME_SYNC_INTERVAL_RTC * 60);
|
||||
#endif // HAS_RTC
|
||||
|
||||
// show compiled features
|
||||
ESP_LOGI(TAG, "Features:%s", features);
|
||||
|
||||
@ -436,11 +419,20 @@ void setup() {
|
||||
setSyncInterval(TIME_SYNC_INTERVAL_GPS * 60);
|
||||
#endif
|
||||
|
||||
// start RTC interrupt
|
||||
#if defined HAS_IF482 && defined RTC_INT
|
||||
strcat_P(features, " IF482");
|
||||
assert(if482_init());
|
||||
ESP_LOGI(TAG, "Starting IF482 Generator...");
|
||||
xTaskCreatePinnedToCore(if482_loop, // task function
|
||||
"if482loop", // name of task
|
||||
2048, // stack size of task
|
||||
(void *)1, // parameter of the task
|
||||
3, // priority of the task
|
||||
&IF482Task, // task handle
|
||||
0); // CPU core
|
||||
|
||||
// setup external interupt for active low RTC INT pin
|
||||
assert(IF482Task != NULL); // has if482loop task started?
|
||||
ESP_LOGI(TAG, "Starting IF482 output...");
|
||||
attachInterrupt(digitalPinToInterrupt(RTC_INT), IF482IRQ, FALLING);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user