Skip to content

Commit

Permalink
ESP32: made build possible with AC 3.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Oct 9, 2023
1 parent f01895b commit fab9624
Show file tree
Hide file tree
Showing 26 changed files with 269 additions and 32 deletions.
31 changes: 27 additions & 4 deletions software/firmware/source/SkyView/Platform_ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
#include <SD.h>
#endif /* CONFIG_IDF_TARGET_ESP32XX */

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
#include <esp_mac.h>
#include <esp_flash.h>
#endif /* ESP_IDF_VERSION_MAJOR */

#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 28 /* Time ESP32 will go to sleep (in seconds) */

Expand Down Expand Up @@ -371,7 +376,13 @@ static void ESP32_setup()
}
}

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
size_t flash_size;
esp_flash_get_size(NULL, (uint32_t *) &flash_size);
#else
size_t flash_size = spi_flash_get_chip_size();
#endif /* ESP_IDF_VERSION_MAJOR */

size_t min_app_size = flash_size;

esp_partition_iterator_t it;
Expand Down Expand Up @@ -868,13 +879,14 @@ static void ESP32_Battery_setup()
{
#if defined(CONFIG_IDF_TARGET_ESP32)
calibrate_voltage(settings->adapter == ADAPTER_TTGO_T5S ?
ADC1_GPIO35_CHANNEL : ADC1_GPIO36_CHANNEL);
(adc1_channel_t) ADC1_GPIO35_CHANNEL :
(adc1_channel_t) ADC1_GPIO36_CHANNEL);
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
calibrate_voltage(ADC1_GPIO9_CHANNEL); /* TBD */
calibrate_voltage((adc1_channel_t) ADC1_GPIO9_CHANNEL); /* TBD */
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
calibrate_voltage(ADC1_GPIO3_CHANNEL);
calibrate_voltage((adc1_channel_t) ADC1_GPIO3_CHANNEL);
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
calibrate_voltage(ADC1_GPIO1_CHANNEL); /* TBD */
calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL); /* TBD */
#else
#error "This ESP32 family build variant is not supported!"
#endif /* CONFIG_IDF_TARGET_ESP32 */
Expand Down Expand Up @@ -909,7 +921,12 @@ static portMUX_TYPE EPD_ident_mutex;
static ep_model_id ESP32_EPD_ident()
{
ep_model_id rval = EP_GDEW027W3; /* default */

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
spinlock_initialize(&EPD_ident_mutex);
#else
vPortCPUInitializeMutex(&EPD_ident_mutex);
#endif /* ESP_IDF_VERSION_MAJOR */

digitalWrite(SOC_GPIO_PIN_SS_WS, HIGH);
pinMode(SOC_GPIO_PIN_SS_WS, OUTPUT);
Expand Down Expand Up @@ -1125,10 +1142,16 @@ static int ESP32_WiFi_clients_count()
wifi_sta_list_t stations;
ESP_ERROR_CHECK(esp_wifi_ap_get_sta_list(&stations));

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
/* TBD */

return stations.num;
#else
tcpip_adapter_sta_list_t infoList;
ESP_ERROR_CHECK(tcpip_adapter_get_sta_list(&stations, &infoList));

return infoList.num;
#endif /* ESP_IDF_VERSION_MAJOR */
case WIFI_STA:
default:
return -1; /* error */
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/SkyWatch/BluetoothHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ class MyServerCallbacks: public BLEServerCallbacks {

class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
String rxValue = pCharacteristic->getValue();
#else
std::string rxValue = pCharacteristic->getValue();
#endif /* ESP_IDF_VERSION_MAJOR */

if (rxValue.length() > 0) {
BLE_FIFO_RX->write(rxValue.c_str(),
Expand Down
29 changes: 26 additions & 3 deletions software/firmware/source/SkyWatch/Platform_ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#include <esp_bt.h>
#endif /* CONFIG_IDF_TARGET_ESP32S2 */

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
#include <esp_mac.h>
#endif /* ESP_IDF_VERSION_MAJOR */

#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 28 /* Time ESP32 will go to sleep (in seconds) */

Expand Down Expand Up @@ -641,10 +645,14 @@ static void ESP32_WiFi_set_param(int ndx, int value)
ESP_ERROR_CHECK(esp_wifi_set_max_tx_power(ESP32_dBm_to_power_level[value]));
break;
case WIFI_PARAM_DHCP_LEASE_TIME:
#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
/* TBD */
#else
tcpip_adapter_dhcps_option(
(tcpip_adapter_dhcp_option_mode_t) TCPIP_ADAPTER_OP_SET,
(tcpip_adapter_dhcp_option_id_t) TCPIP_ADAPTER_IP_ADDRESS_LEASE_TIME,
(void*) &lt, sizeof(lt));
#endif /* ESP_IDF_VERSION_MAJOR */
break;
default:
break;
Expand All @@ -663,15 +671,20 @@ static void ESP32_WiFiUDP_stopAll()

static IPAddress ESP32_WiFi_get_broadcast()
{
tcpip_adapter_ip_info_t info;
IPAddress broadcastIp;

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
/* TBD */
#else
tcpip_adapter_ip_info_t info;

if (WiFi.getMode() == WIFI_STA) {
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &info);
} else {
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &info);
}
broadcastIp = ~info.netmask.addr | info.ip.addr;
#endif /* ESP_IDF_VERSION_MAJOR */

return broadcastIp;
}
Expand All @@ -696,6 +709,9 @@ static void ESP32_WiFi_transmit_UDP(int port, byte *buf, size_t size)
wifi_sta_list_t stations;
ESP_ERROR_CHECK(esp_wifi_ap_get_sta_list(&stations));

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
/* TBD */
#else
tcpip_adapter_sta_list_t infoList;
ESP_ERROR_CHECK(tcpip_adapter_get_sta_list(&stations, &infoList));

Expand All @@ -706,6 +722,7 @@ static void ESP32_WiFi_transmit_UDP(int port, byte *buf, size_t size)
Uni_Udp.write(buf, size);
Uni_Udp.endPacket();
}
#endif /* ESP_IDF_VERSION_MAJOR */
break;
case WIFI_OFF:
default:
Expand All @@ -728,10 +745,16 @@ static int ESP32_WiFi_clients_count()
wifi_sta_list_t stations;
ESP_ERROR_CHECK(esp_wifi_ap_get_sta_list(&stations));

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
/* TBD */

return stations.num;
#else
tcpip_adapter_sta_list_t infoList;
ESP_ERROR_CHECK(tcpip_adapter_get_sta_list(&stations, &infoList));

return infoList.num;
#endif /* ESP_IDF_VERSION_MAJOR */
case WIFI_STA:
default:
return -1; /* error */
Expand Down Expand Up @@ -782,11 +805,11 @@ static void ESP32_Battery_setup()

} else if (hw_info.model == SOFTRF_MODEL_WEBTOP_USB) {
#if defined(CONFIG_IDF_TARGET_ESP32S2)
calibrate_voltage(ADC1_GPIO9_CHANNEL);
calibrate_voltage((adc1_channel_t) ADC1_GPIO9_CHANNEL);
#endif /* CONFIG_IDF_TARGET_ESP32S2 */
} else if (hw_info.model == SOFTRF_MODEL_WEBTOP_SERIAL) {
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
calibrate_voltage(ADC1_GPIO2_CHANNEL);
calibrate_voltage((adc1_channel_t) ADC1_GPIO2_CHANNEL);
#endif /* CONFIG_IDF_TARGET_ESP32S3 */
}
}
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/SkyWatch/TFTHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ void TFT_backlight_init(void)
int bl_pin = (hw_info.model == SOFTRF_MODEL_WEBTOP_USB) ?
SOC_GPIO_PIN_TDONGLE_TFT_BL : SOC_GPIO_PIN_TWATCH_TFT_BL;

#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
/* TBD */
#else
ledcAttachPin(bl_pin, BACKLIGHT_CHANNEL);
ledcSetup(BACKLIGHT_CHANNEL, 12000, 8);
#endif /* ESP_IDF_VERSION_MAJOR */
}

uint8_t TFT_backlight_getLevel()
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/SoftRF/src/driver/Bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ class MyServerCallbacks: public BLEServerCallbacks {

class UARTCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pUARTCharacteristic) {
#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
String rxValue = pUARTCharacteristic->getValue();
#else
std::string rxValue = pUARTCharacteristic->getValue();
#endif /* ESP_IDF_VERSION_MAJOR */

if (rxValue.length() > 0) {
BLE_FIFO_RX->write(rxValue.c_str(),
Expand Down
Loading

0 comments on commit fab9624

Please sign in to comment.