Skip to content

Commit

Permalink
Merge pull request #631 from kuba2k2/feature/pc-port
Browse files Browse the repository at this point in the history
Improve PC port feature support (Win32/Linux)
  • Loading branch information
fvanroie authored Feb 22, 2024
2 parents d3b5658 + 6a8bbce commit 837061b
Show file tree
Hide file tree
Showing 54 changed files with 1,982 additions and 864 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
- name: Enable Linux platform from platformio_override.ini
run: |
sed 's/; user_setups\/linux/user_setups\/linux/g' platformio_override-template.ini > platformio_override.ini
mkdir -p .pio/libdeps/linux_sdl_64bits/paho/src
mkdir -p .pio/libdeps/linux_sdl/paho/src
- name: Install SDL2 library
run: |
sudo apt-get update
Expand All @@ -168,10 +168,10 @@ jobs:
- name: Enable Linux platform from platformio_override.ini
run: |
sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini
mkdir -p .pio/libdeps/linux_sdl_64bits/paho/src
mkdir -p .pio/libdeps/linux_sdl/paho/src
- name: Install SDL2 library
run: |
sudo apt-get update
sudo apt-get install libsdl2-dev
- name: Run PlatformIO
run: pio run -e linux_sdl_64bits
run: pio run -e linux_sdl
4 changes: 2 additions & 2 deletions .github/workflows/build_linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
environments:
- linux_sdl_64bits
- linux_sdl

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Enable Linux platform from platformio_override.ini
run: |
sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini
mkdir -p .pio/libdeps/linux_sdl_64bits/paho/src
mkdir -p .pio/libdeps/linux_sdl/paho/src
- name: Install SDL2 library
run: |
sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Enable Linux platform from platformio_override.ini
run: |
sed -i 's/; user_setups\/linux/user_setups\/linux/g' platformio_override.ini
mkdir -p .pio/libdeps/linux_sdl_64bits/paho/src
mkdir -p .pio/libdeps/linux_sdl/paho/src
- name: Install SDL2 library
run: |
sudo apt-get update
Expand Down
2 changes: 2 additions & 0 deletions hal/sdl2/app_hal.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if USE_MONITOR
#include <unistd.h>
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
#include <SDL2/SDL.h>
Expand Down Expand Up @@ -53,3 +54,4 @@ void hal_loop(void)
// lv_task_handler();
// }
}
#endif
102 changes: 66 additions & 36 deletions include/hasp_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

#define HASP_USE_APP 1

/* Validate that build target was specified */
#if HASP_TARGET_ARDUINO + HASP_TARGET_PC != 1
#error "Build target invalid! Set *one* of: HASP_TARGET_ARDUINO, HASP_TARGET_PC"
#endif

#ifndef HASP_USE_DEBUG
#define HASP_USE_DEBUG 1
#endif
Expand Down Expand Up @@ -65,6 +70,10 @@
#define HASP_USE_MQTT (HASP_HAS_NETWORK)
#endif

#ifndef HASP_USE_MQTT_ASYNC
#define HASP_USE_MQTT_ASYNC (HASP_TARGET_PC)
#endif

#ifndef HASP_USE_WIREGUARD
#define HASP_USE_WIREGUARD (HASP_HAS_NETWORK)
#endif
Expand Down Expand Up @@ -190,6 +199,46 @@

#define HASP_OBJECT_NOTATION "p%ub%u"

#ifndef HASP_ATTRIBUTE_FAST_MEM
#define HASP_ATTRIBUTE_FAST_MEM
#endif

#ifndef IRAM_ATTR
#define IRAM_ATTR
#endif

#ifndef FPSTR
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper*>(pstr_pointer))
#endif

#ifndef PGM_P
#define PGM_P const char*
#endif

/* Workarounds for PC build */
#if HASP_TARGET_PC
#ifndef __FlashStringHelper
typedef char __FlashStringHelper;
#endif

#if defined(__cplusplus) && !defined(String)
#include <iostream>
using String = std::string;
#endif

#ifndef F
#define F(x) (x)
#endif

#ifndef PSTR
#define PSTR(x) x
#endif

#ifndef PROGMEM
#define PROGMEM
#endif
#endif

/* Includes */
#ifdef WINDOWS
#include "winsock2.h"
Expand Down Expand Up @@ -281,7 +330,7 @@ static WiFiSpiClass WiFi;
#if HASP_USE_MQTT > 0
#include "mqtt/hasp_mqtt.h"

#if defined(WINDOWS) || defined(POSIX)
#if HASP_TARGET_PC
#define HASP_USE_PAHO
#else
#define HASP_USE_ESP_MQTT
Expand Down Expand Up @@ -326,52 +375,27 @@ static WiFiSpiClass WiFi;
#include "sys/svc/hasp_slave.h"
#endif

#ifndef HASP_ATTRIBUTE_FAST_MEM
#define HASP_ATTRIBUTE_FAST_MEM
#endif

#ifndef IRAM_ATTR
#define IRAM_ATTR
#endif

#ifndef FPSTR
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper*>(pstr_pointer))
#endif

#ifndef PGM_P
#define PGM_P const char*
#endif

#if defined(WINDOWS) || defined(POSIX)
#ifndef __FlashStringHelper
#define __FlashStringHelper char
#endif

#ifndef F
#define F(x) (x)
#endif

#ifndef PSTR
#define PSTR(x) x
#endif

#ifndef PROGMEM
#define PROGMEM
#endif
#endif

#if defined(WINDOWS)
#include <Windows.h>
#define delay Sleep
#endif

#if defined(POSIX)
#ifdef USE_MONITOR
#define delay SDL_Delay
#else
#define delay msleep
#endif
#if defined(WINDOWS) || defined(POSIX)
#endif

#if HASP_TARGET_PC
#include <string.h>
#include <strings.h>
#include <stdio.h>

#if USE_MONITOR
#include <SDL2/SDL.h>
#endif

#define snprintf_P snprintf
#define memcpy_P memcpy
Expand All @@ -380,7 +404,13 @@ static WiFiSpiClass WiFi;
#define strcpy_P strcpy
#define strstr_P strstr
#define halRestartMcu()
#if USE_MONITOR
#define millis SDL_GetTicks
#elif defined(WINDOWS)
#define millis Win32Millis
#elif defined(POSIX)
#define millis PosixMillis
#endif

#define DEC 10
#define HEX 16
Expand Down
6 changes: 3 additions & 3 deletions include/hasp_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
#include "user_config_override.h"
#endif

#if defined(WINDOWS) || defined(POSIX)
#if HASP_TARGET_PC
#define HASP_RANDOM(x) rand() % x
#elif defined(ARDUINO)
#elif HASP_TARGET_ARDUINO
#define HASP_RANDOM(x) random(x)
#else
#define HASP_RANDOM(x) random() % x
#endif

#if defined(WINDOWS) || defined(POSIX)
#if HASP_TARGET_PC
#define LOG_OUTPUT(x, ...) printf(__VA_ARGS__)
#else

Expand Down
2 changes: 2 additions & 0 deletions include/lv_conf_v7.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ typedef void* lv_fs_drv_user_data_t;
//# define LV_FS_IF_SPIFFS '\0' // no internal esp Flash
#endif
#endif /*LV_USE_FS_IF*/
#if HASP_TARGET_ARDUINO
#define LV_FS_PC_PATH "/littlefs"
#endif

#endif

Expand Down
6 changes: 5 additions & 1 deletion include/lv_drv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@
#define USE_WINDOWS 0
#endif

#if USE_WINDOWS
#ifndef USE_WIN32DRV
#define USE_WINDOWS 0
#endif

#if USE_WINDOWS || USE_WIN32DRV
#define WINDOW_HOR_RES 480
#define WINDOW_VER_RES 320
#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/lv_lib_zifont/lv_zifont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* INCLUDES
*********************/

#if !(defined(WINDOWS) || defined(POSIX) || defined(STM32F7xx))
#if !(HASP_TARGET_PC || defined(STM32F7xx))

#include <Arduino.h>
#include <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions platformio_override-template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
[platformio]
extra_configs =
; Uncomment or edit the lines to show more User Setups in the PIO sidebar
; user_setups/darwin_sdl/*.ini
; user_setups/darwin/*.ini
; user_setups/esp32/*.ini
; user_setups/esp32s2/*.ini
; user_setups/esp32s3/*.ini
; user_setups/linux_sdl/*.ini
; user_setups/linux/*.ini
; user_setups/stm32f4xx/*.ini
; user_setups/win32/*.ini

Expand Down
5 changes: 4 additions & 1 deletion src/dev/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Arduino.h"
#endif

#if defined(WINDOWS) || defined(POSIX)
#if HASP_TARGET_PC
#include <cstdint>
#endif
#if defined(POSIX)
Expand All @@ -30,6 +30,9 @@ class BaseDevice {
public:
bool has_battery = false;
bool has_backligth_control = true;
#if HASP_TARGET_PC
bool pc_is_running = true;
#endif

virtual void reboot()
{}
Expand Down
Loading

0 comments on commit 837061b

Please sign in to comment.