Merge pull request #310 from Daft-Freak/buttons
Button API improvements
diff --git a/.travis.yml b/.travis.yml
index 6045c8b..40cbd2c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -53,25 +53,24 @@
edge: true
- name: "STM32"
+ dist: focal
env:
- TOOLCHAIN=../32blit.toolchain
- RELEASE_FILE=${TRAVIS_BUILD_DIR}${REPO}-${TRAVIS_TAG}-${TRAVIS_BUILD_NUMBER}-STM32
addons:
apt:
- sources:
- sourceline: "ppa:daft-freak/arm-gcc"
- packages:
- gcc-arm-none-eabi
- libnewlib-arm-none-eabi
- libstdc++-arm-none-eabi-newlib
- python3-pip
- python3-setuptools
- zip
+ gcc-arm-none-eabi
+ libnewlib-arm-none-eabi
+ libstdc++-arm-none-eabi-newlib
+ python2
+ python3-pip
+ python3-setuptools
+ zip
install:
- python3 -m pip install 32blit bitstring construct
after_success:
- curl -O https://raw.githubusercontent.com/danvk/travis-weigh-in/adcc3a3e5bc16b360aa379d0fc23c3a6e1d9b21d/weigh_in.py
- - python weigh_in.py firmware/flash-loader/flash-loader.bin
+ - python2 weigh_in.py firmware/flash-loader/flash-loader.bin
before_deploy:
- make install
- tar -zcf ${RELEASE_FILE}.tar.gz bin/
@@ -100,16 +99,7 @@
python3-setuptools
zip
before_script:
- - |
- if [ ! -f SDL2_image-2.0.5/README.txt ]; then
- curl https://libsdl.org/release/SDL2-devel-2.0.10-mingw.tar.gz -o SDL2.tar.gz
- curl https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-mingw.tar.gz -o SDL2_image.tar.gz
- tar -xf SDL2.tar.gz
- tar -xf SDL2_image.tar.gz
- sed -i "s|/opt/local|$PWD/SDL2-2.0.10|g" ./SDL2-2.0.10/x86_64-w64-mingw32/lib/cmake/SDL2/sdl2-config.cmake
- # copy SDL2_image into SDL2
- cp -r ./SDL2_image-2.0.5/x86_64-w64-mingw32 ./SDL2-2.0.10/
- fi
+ - ci/install_sdl_mingw.sh
- name: "macOS"
os: osx
@@ -118,16 +108,7 @@
- $HOME/Library/Frameworks/SDL2.framework
- $HOME/Library/Frameworks/SDL2_image.framework
before_script:
- - |
- if [ ! -f ~/Library/Frameworks/SDL2_image.framework/SDL2_image ]; then
- curl https://libsdl.org/release/SDL2-2.0.10.dmg -o SDL2.dmg
- curl http://libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.dmg -o SDL2_image.dmg
- hdiutil mount SDL2.dmg
- hdiutil mount SDL2_image.dmg
- mkdir -p ~/Library/Frameworks
- cp -r /Volumes/SDL2/SDL2.framework ~/Library/Frameworks/
- cp -r /Volumes/SDL2_image/SDL2_image.framework ~/Library/Frameworks/
- fi
+ - ci/install_sdl_macos.sh
- name: "Visual Studio (CMake)"
os: windows
@@ -143,16 +124,7 @@
- export PATH=$PATH:"c:\Python38"
- ln -s /c/Python38/python.exe /c/Python38/python3.exe
before_script:
- - |
- if [ ! -f vs/sdl/include/SDL_image.h ]; then
- curl https://libsdl.org/release/SDL2-devel-2.0.10-VC.zip -o SDL2.zip
- curl https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-VC.zip -o SDL2_image.zip
- unzip SDL2.zip -d vs/sdl
- unzip SDL2_image.zip -d vs/sdl
- # move dirs up
- mv vs/sdl/SDL2-2.0.10/* vs/sdl
- cp -r vs/sdl/SDL2_image-2.0.5/* vs/sdl
- fi
+ - ci/install_sdl_vs.sh
before_deploy:
- cmake --build . --target install
- 7z a ${RELEASE_FILE}.zip bin/*
@@ -175,16 +147,7 @@
- ln -s /c/Python38/python.exe /c/Python38/python3.exe
script:
- export PATH=$PATH:"c:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
- - |
- if [ ! -f vs/sdl/include/SDL_image.h ]; then
- curl https://libsdl.org/release/SDL2-devel-2.0.10-VC.zip -o SDL2.zip
- curl https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-VC.zip -o SDL2_image.zip
- unzip SDL2.zip -d vs/sdl
- unzip SDL2_image.zip -d vs/sdl
- # move dirs up
- mv vs/sdl/SDL2-2.0.10/* vs/sdl
- cp -r vs/sdl/SDL2_image-2.0.5/* vs/sdl
- fi
+ - ci/install_sdl_vs.sh
- msbuild.exe vs/32blit.sln
install:
diff --git a/32blit-sdl/File.cpp b/32blit-sdl/File.cpp
index e21a596..62025e1 100644
--- a/32blit-sdl/File.cpp
+++ b/32blit-sdl/File.cpp
@@ -170,3 +170,11 @@
return mkdir((basePath + path).c_str(), 0755) == 0 || errno == EEXIST;
#endif
}
+
+bool rename_file(std::string old_name, std::string new_name) {
+ return rename((basePath + old_name).c_str(), (basePath + new_name).c_str()) == 0;
+}
+
+bool remove_file(std::string path) {
+ return remove((basePath + path).c_str()) == 0;
+}
\ No newline at end of file
diff --git a/32blit-sdl/File.hpp b/32blit-sdl/File.hpp
index f81391d..a086b90 100644
--- a/32blit-sdl/File.hpp
+++ b/32blit-sdl/File.hpp
@@ -16,3 +16,5 @@
bool file_exists(std::string path);
bool directory_exists(std::string path);
bool create_directory(std::string path);
+bool rename_file(std::string old_name, std::string new_name);
+bool remove_file(std::string path);
\ No newline at end of file
diff --git a/32blit-sdl/System.cpp b/32blit-sdl/System.cpp
index 3a0b374..d3c1529 100644
--- a/32blit-sdl/System.cpp
+++ b/32blit-sdl/System.cpp
@@ -155,6 +155,8 @@
blit::api.file_exists = ::file_exists;
blit::api.directory_exists = ::directory_exists;
blit::api.create_directory = ::create_directory;
+ blit::api.rename_file = ::rename_file;
+ blit::api.remove_file = ::remove_file;
blit::api.enable_us_timer = ::enable_us_timer;
blit::api.get_us_timer = ::get_us_timer;
diff --git a/32blit-stm32/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h b/32blit-stm32/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h
index d13bbea..5e0217e 100644
--- a/32blit-stm32/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h
+++ b/32blit-stm32/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h
@@ -23,6 +23,8 @@
#ifdef __cplusplus
extern "C" {
+
+#define register // removed in C++17, has no effect at > -O0 anyway
#endif
/* Includes ------------------------------------------------------------------*/
diff --git a/32blit-stm32/Inc/32blit.h b/32blit-stm32/Inc/32blit.h
index cb70a19..a3dc478 100644
--- a/32blit-stm32/Inc/32blit.h
+++ b/32blit-stm32/Inc/32blit.h
@@ -14,13 +14,6 @@
extern char *get_fr_err_text(FRESULT err);
extern bool blit_sd_detected();
-// LTDC and framebuffer handling
-extern char __ltdc_start;
-extern void blit_swap();
-extern void blit_flip();
-extern blit::Surface &set_screen_mode(blit::ScreenMode new_mode);
-extern void blit_clear_framebuffer();
-
// Blit setup and main loop
extern void blit_tick();
extern void blit_init();
@@ -31,9 +24,6 @@
extern void blit_process_input();
extern void blit_i2c_tick();
-// Audio
-extern void blit_enable_amp();
-
// Switching execution
extern void blit_switch_execution(void);
diff --git a/32blit-stm32/Inc/file.hpp b/32blit-stm32/Inc/file.hpp
index 74f04c4..3c5f921 100644
--- a/32blit-stm32/Inc/file.hpp
+++ b/32blit-stm32/Inc/file.hpp
@@ -15,3 +15,5 @@
bool file_exists(std::string path);
bool directory_exists(std::string path);
bool create_directory(std::string path);
+bool rename_file(std::string old_name, std::string new_name);
+bool remove_file(std::string path);
\ No newline at end of file
diff --git a/32blit-stm32/Src/32blit.c b/32blit-stm32/Src/32blit.c
index 7e06d59..1a0ee0f 100644
--- a/32blit-stm32/Src/32blit.c
+++ b/32blit-stm32/Src/32blit.c
@@ -334,6 +334,8 @@
blit::api.file_exists = ::file_exists;
blit::api.directory_exists = ::directory_exists;
blit::api.create_directory = ::create_directory;
+ blit::api.rename_file = ::rename_file;
+ blit::api.remove_file = ::remove_file;
blit::api.enable_us_timer = ::enable_us_timer;
blit::api.get_us_timer = ::get_us_timer;
diff --git a/32blit-stm32/Src/file.cpp b/32blit-stm32/Src/file.cpp
index 619f160..9ad8201 100644
--- a/32blit-stm32/Src/file.cpp
+++ b/32blit-stm32/Src/file.cpp
@@ -123,4 +123,12 @@
FRESULT r = f_mkdir(path.c_str());
return r == FR_OK || r == FR_EXIST;
+}
+
+bool rename_file(std::string old_name, std::string new_name) {
+ return f_rename(old_name.c_str(), new_name.c_str()) == FR_OK;
+}
+
+bool remove_file(std::string path) {
+ return f_unlink(path.c_str()) == FR_OK;
}
\ No newline at end of file
diff --git a/32blit.toolchain b/32blit.toolchain
index 134821c..610f6da 100644
--- a/32blit.toolchain
+++ b/32blit.toolchain
@@ -44,3 +44,5 @@
set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=nosys.specs -Wl,--gc-sections,--no-wchar-size-warning")
add_definitions(-DTARGET_32BLIT_HW)
+set(32BLIT_HW 1)
+set(32BLIT_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to 32blit.cmake")
\ No newline at end of file
diff --git a/32blit/engine/api_private.hpp b/32blit/engine/api_private.hpp
index 05d9992..2814e39 100644
--- a/32blit/engine/api_private.hpp
+++ b/32blit/engine/api_private.hpp
@@ -44,6 +44,8 @@
bool (*file_exists) (std::string path);
bool (*directory_exists) (std::string path);
bool (*create_directory) (std::string path);
+ bool (*rename_file) (std::string old_name, std::string new_name);
+ bool (*remove_file) (std::string path);
// profiler
void (*enable_us_timer)();
diff --git a/32blit/engine/file.cpp b/32blit/engine/file.cpp
index 9801f51..a2a5d5a 100644
--- a/32blit/engine/file.cpp
+++ b/32blit/engine/file.cpp
@@ -42,6 +42,14 @@
return api.create_directory(path);
}
+ bool rename_file(std::string old_name, std::string new_name) {
+ return api.rename_file(old_name, new_name);
+ }
+
+ bool remove_file(std::string path) {
+ return api.remove_file(path);
+ }
+
bool File::open(std::string file, int mode) {
close();
diff --git a/32blit/engine/file.hpp b/32blit/engine/file.hpp
index b5f7fc0..4f86116 100644
--- a/32blit/engine/file.hpp
+++ b/32blit/engine/file.hpp
@@ -25,6 +25,9 @@
bool directory_exists(std::string path);
bool create_directory(std::string path);
+
+ bool rename_file(std::string old_name, std::string new_name);
+ bool remove_file(std::string path);
class File final {
public:
diff --git a/32blit/graphics/surface.hpp b/32blit/graphics/surface.hpp
index 4ea9c0a..85c639c 100644
--- a/32blit/graphics/surface.hpp
+++ b/32blit/graphics/surface.hpp
@@ -4,6 +4,7 @@
#include <vector>
#include <array>
#include <cstdint>
+#include <string>
#ifdef WIN32
#define __attribute__(A)
@@ -193,4 +194,4 @@
void vertical_scale_span_blit(const point &p, const uint16_t length, surface *texture, const point &st, const point &et);*/
};
-}
\ No newline at end of file
+}
diff --git a/ci/install_sdl_macos.sh b/ci/install_sdl_macos.sh
new file mode 100755
index 0000000..6379cbf
--- /dev/null
+++ b/ci/install_sdl_macos.sh
@@ -0,0 +1,11 @@
+if [ ! -f ~/Library/Frameworks/SDL2_image.framework/SDL2_image ]; then
+ curl https://libsdl.org/release/SDL2-2.0.10.dmg -o SDL2.dmg
+ curl http://libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.dmg -o SDL2_image.dmg
+
+ hdiutil mount SDL2.dmg
+ hdiutil mount SDL2_image.dmg
+
+ mkdir -p ~/Library/Frameworks
+ cp -r /Volumes/SDL2/SDL2.framework ~/Library/Frameworks/
+ cp -r /Volumes/SDL2_image/SDL2_image.framework ~/Library/Frameworks/
+fi
\ No newline at end of file
diff --git a/ci/install_sdl_mingw.sh b/ci/install_sdl_mingw.sh
new file mode 100755
index 0000000..0f37496
--- /dev/null
+++ b/ci/install_sdl_mingw.sh
@@ -0,0 +1,13 @@
+if [ ! -f SDL2_image-2.0.5/README.txt ]; then
+ curl https://libsdl.org/release/SDL2-devel-2.0.10-mingw.tar.gz -o SDL2.tar.gz
+ curl https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-mingw.tar.gz -o SDL2_image.tar.gz
+
+ tar -xf SDL2.tar.gz
+ tar -xf SDL2_image.tar.gz
+
+ # fix the path in the cmake config
+ sed -i "s|/opt/local|$PWD/SDL2-2.0.10|g" ./SDL2-2.0.10/x86_64-w64-mingw32/lib/cmake/SDL2/sdl2-config.cmake
+
+ # copy SDL2_image into SDL2
+ cp -r ./SDL2_image-2.0.5/x86_64-w64-mingw32 ./SDL2-2.0.10/
+fi
\ No newline at end of file
diff --git a/ci/install_sdl_vs.sh b/ci/install_sdl_vs.sh
new file mode 100755
index 0000000..b202e38
--- /dev/null
+++ b/ci/install_sdl_vs.sh
@@ -0,0 +1,11 @@
+if [ ! -f vs/sdl/include/SDL_image.h ]; then
+ curl https://libsdl.org/release/SDL2-devel-2.0.10-VC.zip -o SDL2.zip
+ curl https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-VC.zip -o SDL2_image.zip
+
+ unzip SDL2.zip -d vs/sdl
+ unzip SDL2_image.zip -d vs/sdl
+
+ # move dirs up
+ mv vs/sdl/SDL2-2.0.10/* vs/sdl
+ cp -r vs/sdl/SDL2_image-2.0.5/* vs/sdl
+fi
\ No newline at end of file
diff --git a/examples/audio-test/CMakeLists.txt b/examples/audio-test/CMakeLists.txt
index 81819bc..def6d74 100644
--- a/examples/audio-test/CMakeLists.txt
+++ b/examples/audio-test/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.9)
-project (tilt)
+cmake_minimum_required(VERSION 3.8)
+project (audio-test)
include (../../32blit.cmake)
blit_executable (audio-test audio-test.cpp)
diff --git a/examples/audio-wave/CMakeLists.txt b/examples/audio-wave/CMakeLists.txt
index 24d2df1..5918e25 100644
--- a/examples/audio-wave/CMakeLists.txt
+++ b/examples/audio-wave/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.9)
+cmake_minimum_required(VERSION 3.8)
project (audio-wave)
include (../../32blit.cmake)
blit_executable (audio-wave audio-wave.cpp)
diff --git a/examples/voxel/CMakeLists.txt b/examples/voxel/CMakeLists.txt
index f592d33..937bda2 100644
--- a/examples/voxel/CMakeLists.txt
+++ b/examples/voxel/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.9)
+cmake_minimum_required(VERSION 3.8)
project (voxel)
include (../../32blit.cmake)
blit_executable (voxel voxel.cpp)
diff --git a/template/CMakeLists.txt b/template/CMakeLists.txt
index ac5f4f3..eaec1d5 100644
--- a/template/CMakeLists.txt
+++ b/template/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
-set(32BLIT_PATH "../" CACHE PATH "Path to 32blit.cmake")
project (game)
+set(32BLIT_PATH "../" CACHE PATH "Path to 32blit.cmake")
include (${32BLIT_PATH}/32blit.cmake)
blit_executable (game game.cpp game.hpp)
diff --git a/template/game.vcxproj b/template/game.vcxproj
index f9d08fa..5bbadaf 100644
--- a/template/game.vcxproj
+++ b/template/game.vcxproj
@@ -88,7 +88,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -104,7 +104,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -122,7 +122,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -142,7 +142,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
diff --git a/tools/src/32Blit.cpp b/tools/src/32Blit.cpp
index fd938bb..a0d14e1 100644
--- a/tools/src/32Blit.cpp
+++ b/tools/src/32Blit.cpp
@@ -63,7 +63,6 @@
HANDLE hComm = INVALID_HANDLE_VALUE;
OVERLAPPED osRX = { 0 };
OVERLAPPED osTX = { 0 };
-DWORD dwWritten = 0; // should be in WriteCom() but doesn't work on stack, windows guy needs to look at this
bool bWaitingOnRx = false;
void CloseCom()
@@ -71,6 +70,7 @@
CloseHandle(osRX.hEvent);
CloseHandle(osTX.hEvent);
CloseHandle(hComm);
+ hComm = INVALID_HANDLE_VALUE;
}
bool OpenComPort(const char *pszComPort, bool bTestConnection = false)
@@ -92,11 +92,10 @@
uint32_t WriteCom(char *pBuffer, uint32_t uLen)
{
- if (!WriteFile(hComm, pBuffer, uLen, &dwWritten, &osTX))
- {
- GetOverlappedResult(hComm, &osTX, &dwWritten, TRUE);
- }
- return dwWritten;
+ DWORD dwWritten = 0;
+ if (!WriteFile(hComm, pBuffer, uLen, NULL, &osTX) && GetLastError() == ERROR_IO_PENDING)
+ GetOverlappedResult(hComm, &osTX, &dwWritten, TRUE);
+ return dwWritten;
}
bool GetRXByte(char &rxByte)
diff --git a/vs/examples/voxel/voxel.vcxproj b/vs/examples/voxel/voxel.vcxproj
index 8870eac..c3fbe2f 100644
--- a/vs/examples/voxel/voxel.vcxproj
+++ b/vs/examples/voxel/voxel.vcxproj
@@ -88,7 +88,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -104,7 +104,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -122,7 +122,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -142,7 +142,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp14</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>