├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── changelog.md ├── components ├── axp192 │ ├── CHANGELOG.md │ ├── CMakeLists.txt │ ├── Kconfig │ ├── LICENSE.txt │ ├── README.md │ ├── axp192.c │ ├── axp192.h │ ├── axp192_config.h │ ├── component.mk │ └── sdkconfig │ │ └── m5stickc.defaults ├── axp202 │ ├── CMakeLists.txt │ ├── Kconfig │ ├── LICENSE.txt │ ├── README.md │ ├── axp202.c │ ├── axp202.h │ ├── axp202_config.h │ ├── component.mk │ └── sdkconfig │ │ └── t-watch-2020.defaults ├── esp_i2c_helper │ ├── CMakeLists.txt │ ├── Kconfig │ ├── component.mk │ ├── i2c_helper.c │ └── i2c_helper.h ├── hagl │ ├── CHANGELOG.md │ ├── CMakeLists.txt │ ├── CODING_STANDARDS.md │ ├── Kconfig │ ├── LICENSE │ ├── README.md │ ├── component.mk │ ├── include │ │ ├── aps.h │ │ ├── config.h │ │ ├── font5x7.h │ │ ├── font5x8.h │ │ ├── font6x9.h │ │ ├── fontx.h │ │ ├── fps.h │ │ ├── hagl.h │ │ ├── hagl │ │ │ ├── backend.h │ │ │ ├── bitmap.h │ │ │ ├── blit.h │ │ │ ├── char.h │ │ │ ├── circle.h │ │ │ ├── clip.h │ │ │ ├── color.h │ │ │ ├── ellipse.h │ │ │ ├── hline.h │ │ │ ├── image.h │ │ │ ├── line.h │ │ │ ├── pixel.h │ │ │ ├── polygon.h │ │ │ ├── rectangle.h │ │ │ ├── surface.h │ │ │ ├── triangle.h │ │ │ ├── vline.h │ │ │ └── window.h │ │ ├── hsl.h │ │ ├── rgb332.h │ │ ├── rgb565.h │ │ ├── rgb888.h │ │ └── tjpgd.h │ └── src │ │ ├── bitmap.c │ │ ├── fontx.c │ │ ├── hagl.c │ │ ├── hagl_blit.c │ │ ├── hagl_char.c │ │ ├── hagl_circle.c │ │ ├── hagl_clip.c │ │ ├── hagl_color.c │ │ ├── hagl_ellipse.c │ │ ├── hagl_hline.c │ │ ├── hagl_image.c │ │ ├── hagl_line.c │ │ ├── hagl_pixel.c │ │ ├── hagl_polygon.c │ │ ├── hagl_rectangle.c │ │ ├── hagl_triangle.c │ │ ├── hagl_vline.c │ │ ├── hsl.c │ │ ├── rgb565.c │ │ ├── rgb888.c │ │ └── tjpgd.c ├── hagl_hal │ ├── CMakeLists.txt │ ├── Kconfig │ ├── LICENSE │ ├── README.md │ ├── component.mk │ ├── include │ │ ├── hagl_hal.h │ │ ├── hagl_hal_color.h │ │ ├── mipi_dcs.h │ │ └── mipi_display.h │ ├── sdkconfig │ │ ├── m5stack-core2.defaults │ │ ├── m5stack.defaults │ │ ├── m5stickc-landscape.defaults │ │ ├── m5stickc-plus-landscape.defaults │ │ ├── m5stickc-plus-portrait.defaults │ │ ├── m5stickc-portrait.defaults │ │ ├── ttgo-t-display.defaults │ │ └── ttgo-t4-v13.defaults │ └── src │ │ ├── hagl_hal_double.c │ │ ├── hagl_hal_single.c │ │ ├── hagl_hal_triple.c │ │ └── mipi_display.c ├── htool_api │ ├── CMakeLists.txt │ ├── htool_api.c │ └── include │ │ └── htool_api.h ├── htool_ble │ ├── CMakeLists.txt │ ├── htool_ble.c │ └── include │ │ └── htool_ble.h ├── htool_display │ ├── CMakeLists.txt │ ├── htool_display.c │ └── include │ │ └── htool_display.h ├── htool_modbus │ ├── CMakeLists.txt │ ├── htool_modbus.c │ └── include │ │ └── htool_modbus.h ├── htool_netman │ ├── CMakeLists.txt │ ├── htool_netman.c │ └── include │ │ └── htool_netman.h ├── htool_nvsm │ ├── CMakeLists.txt │ ├── htool_nvsm.c │ └── include │ │ └── htool_nvsm.h ├── htool_pn532_spi │ ├── CMakeLists.txt │ ├── htool_pn532_spi.c │ └── include │ │ └── htool_pn532_spi.h ├── htool_spi │ ├── CMakeLists.txt │ ├── htool_spi.c │ └── include │ │ └── htool_spi.h ├── htool_system │ ├── CMakeLists.txt │ ├── htool_system.c │ └── include │ │ └── htool_system.h ├── htool_uart │ ├── CMakeLists.txt │ ├── htool_uart.c │ └── include │ │ └── htool_uart.h └── htool_wifi │ ├── CMakeLists.txt │ ├── captive_portals │ ├── apple │ │ └── apple.html │ ├── facebook │ │ └── facebook.html │ ├── google │ │ └── google.html │ ├── mcdonalds │ │ └── mcdonalds.html │ └── router │ │ ├── 1_1.html │ │ ├── a1.html │ │ ├── asus.html │ │ ├── att.html │ │ ├── fritzbox.html │ │ ├── globe.html │ │ ├── huawei.html │ │ ├── magenta.html │ │ ├── netgear.html │ │ ├── o2.html │ │ ├── pldt.html │ │ ├── router.html │ │ ├── swisscom.html │ │ ├── tplink.html │ │ ├── verizon.html │ │ └── vodafone.html │ ├── htool_wifi.c │ └── include │ └── htool_wifi.h ├── main ├── CMakeLists.txt └── hackingtool.c ├── partitions.csv ├── precompiled_files ├── bootloader.bin ├── hackingtool.bin └── partition-table.bin └── sdkconfig /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-detectable=false 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about build system see 2 | # https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html 3 | # The following five lines of boilerplate have to be in your project's 4 | # CMakeLists in this exact order for cmake to work correctly 5 | cmake_minimum_required(VERSION 3.5) 6 | 7 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 8 | project(hackingtool) 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Kl0ibi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | [24.12.2023] 2 | - added ble spoof 3 | - now all esp32 with atleast 4mb of flash are supported 4 | - added command line interface 5 | - fixed some bugs 6 | - did some refactoring 7 | 8 | [23.1.2023] 9 | - Implemented functions to get the target uid from a nfc chip 10 | - Provided bootloader and partition table bin files now its ready for flashing with esptool 11 | 12 | [16.1.2023] 13 | - implented function to get version revision of the pn532 (check that my spi functions are working) 14 | - implented basic functions, send ack, waitReady ... 15 | 16 | [15.1.2023] 17 | - started with implementation of the nfc module (pn532) 18 | - started with implementation of basic low level spi functions 19 | 20 | [7.1.2023] 21 | - added multiple new router captive portals for evil twin attack (there will be added more in the future) 22 | - added facebook and apple shop captive portal (there will be added more in the future) 23 | - added 2 new beacon spammer modes (duplicate wifi with same ssid and same/random mac) may be a good way to confuse devices 24 | - added custom partition table 25 | - fixed some bugs 26 | - did some refactoring 27 | -------------------------------------------------------------------------------- /components/axp192/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file, in reverse chronological order by release. 4 | 5 | ## [0.6.0](https://github.com/tuupola/axp192/compare/0.5.0...0.6.0) - 2021-12-17 6 | 7 | ### Fixed 8 | - All outputs are now enabled by default ([#35](https://github.com/tuupola/axp192/pull/35)) 9 | 10 | ### Added 11 | 12 | - Support for reading raw register values ([#24](https://github.com/tuupola/axp192/pull/24)) 13 | - Support for manually setting the rail voltages ([#27](https://github.com/tuupola/axp192/pull/27)) 14 | - Support for manually enablind and disabling DCDC1 ([#29](https://github.com/tuupola/axp192/pull/29)) 15 | - Support for manually enablind and disabling DCDC2 ([#30](https://github.com/tuupola/axp192/pull/30)) 16 | - Support for manually enablind and disabling EXTEN ([#31](https://github.com/tuupola/axp192/pull/31)) 17 | - Support for manually enablind and disabling LDOIO0 ([#32](https://github.com/tuupola/axp192/pull/32)) 18 | - Support for writing a raw byte directly to a register([#33](https://github.com/tuupola/axp192/pull/33)) 19 | 20 | ### Removed 21 | 22 | - All moot ioctl commands ([#25](https://github.com/tuupola/axp192/pull/25)). 23 | ```c 24 | /* Removed */ 25 | axp192_ioctl(&axp, AXP192_READ_POWER_STATUS, &power); 26 | axp192_ioctl(&axp, AXP192_READ_CHARGE_STATUS, &charge); 27 | 28 | /* Use this instead. */ 29 | axp192_read(&axp, AXP192_POWER_STATUS, &power); 30 | axp192_read(&axp, AXP192_CHARGE_STATUS, &charge); 31 | ``` 32 | 33 | ### Changed 34 | 35 | - Using menuconfig is now optional ([#28](https://github.com/tuupola/axp192/pull/28)). 36 | - Third parameter of `axp192_ioctl()` is now optional ([#26](https://github.com/tuupola/axp192/pull/26)). 37 | - Splitted AXP192_LDO2_SET_CONTROL to separate commands ([#26](https://github.com/tuupola/axp192/pull/26)). 38 | ```c 39 | axp192_ioctl(&axp, AXP192_LDO2_ENABLE); 40 | axp192_ioctl(&axp, AXP192_LDO2_DISABLE); 41 | ``` 42 | - Splitted AXP192_LDO3_SET_CONTROL to separate commands ([#26](https://github.com/tuupola/axp192/pull/26)). 43 | ```c 44 | axp192_ioctl(&axp, AXP192_LDO3_ENABLE); 45 | axp192_ioctl(&axp, AXP192_LDO3_DISABLE); 46 | ``` 47 | - Splitted AXP192_DCDC3_SET_CONTROL to separate commands ([#26](https://github.com/tuupola/axp192/pull/26)). 48 | ```c 49 | axp192_ioctl(&axp, AXP192_DCDC3_ENABLE); 50 | axp192_ioctl(&axp, AXP192_DCDC3_DISABLE); 51 | ``` 52 | 53 | 54 | ## [0.5.0](https://github.com/tuupola/axp192/compare/0.4.0...0.5.0) - 2021-09-03 55 | 56 | This version adds features needed for using with M5STack Core2. 57 | 58 | ### Added 59 | 60 | - IOCTL support for setting GPIO0 level ([#20](https://github.com/tuupola/axp192/issues/20)) 61 | - IOCTL support for setting GPIO2 level ([#19](https://github.com/tuupola/axp192/issues/19)) 62 | - IOCTL support to enable and disable LDO2 ([#19](https://github.com/tuupola/axp192/issues/18)) 63 | - IOCTL support to enable and disable DCDC3 ([#17](https://github.com/tuupola/axp192/issues/17)) 64 | - IOCTL support for setting GPIO4 level ([#15](https://github.com/tuupola/axp192/issues/15)) 65 | - IOCTL support for setting GPIO4 level ([#13](https://github.com/tuupola/axp192/issues/13)) 66 | - IOCTL support for setting GPIO1 level ([#12](https://github.com/tuupola/axp192/issues/12)) 67 | - IOCTL support to enable and disable LDO3 ([#11](https://github.com/tuupola/axp192/issues/11)) 68 | - Support for AXP192_GPIO43_FUNCTION_CONTROL ([#10](https://github.com/tuupola/axp192/issues/10)) 69 | - Support for AXP192_GPIO2_CONTROL ([#9](https://github.com/tuupola/axp192/issues/9)) 70 | - Support for AXP192_GPIO1_CONTROL ([#8](https://github.com/tuupola/axp192/issues/8)) 71 | - Support for AXP192_DCDC3_VOLTAGE ([#6](https://github.com/tuupola/axp192/issues/6)) 72 | - Support for AXP192_DCDC1_VOLTAGE ([#5](https://github.com/tuupola/axp192/issues/5)) 73 | - Support for AXP192_BATTERY_CHARGE_CONTROL ([#4](https://github.com/tuupola/axp192/issues/4)) 74 | 75 | ### Changed 76 | 77 | - `AXP192_GPIO40_FUNCTION_CONTROL` is now `AXP192_GPIO43_FUNCTION_CONTROL` 78 | - `AXP192_GPIO40_SIGNAL_STATUS` is now `AXP192_GPIO43_SIGNAL_STATUS` 79 | 80 | ## [0.4.0](https://github.com/tuupola/axp192/compare/0.3.0...0.4.0) - 2020-11-09 81 | 82 | ### Added 83 | 84 | - DOIO0, LDO23 and charge control default values in menuconfig ([#2](https://github.com/tuupola/axp192/issues/2)) 85 | 86 | ## [0.3.0](https://github.com/tuupola/axp192/compare/0.2.0...0.3.0) - 2020-05-20 87 | ### Added 88 | 89 | - Optional handle parameter for the I2C HAL ([#1](https://github.com/tuupola/axp192/issues/1)) 90 | 91 | ### Changed 92 | 93 | - `AXP192_ERROR_OK` is now `AXP192_OK` 94 | - All LDO output defaults to 3V0 in menuconfig 95 | 96 | ## [0.2.0](https://github.com/tuupola/axp192/compare/0.1.0...0.2.0) - 2020-04-21 97 | ### Changed 98 | 99 | - I2C HAL config is now a struct 100 | 101 | ```c 102 | axp192_t axp; 103 | 104 | axp.read = &i2c_read; 105 | axp.write = &i2c_write; 106 | 107 | axp192_init(&axp); 108 | ``` 109 | 110 | ## 0.1.0 - 2020-04-12 111 | 112 | Initial realese. 113 | -------------------------------------------------------------------------------- /components/axp192/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (ESP_PLATFORM) 2 | idf_component_register( 3 | SRCS "axp192.c" 4 | INCLUDE_DIRS "." 5 | ) 6 | add_definitions("-DAXP192_INCLUDE_SDKCONFIG_H") 7 | endif() 8 | -------------------------------------------------------------------------------- /components/axp192/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2021 Mika Tuupola 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /components/axp192/axp192_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019-2021 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of hardware agnostic I2C driver for AXP192: 28 | https://github.com/tuupola/axp192 29 | 30 | SPDX-License-Identifier: MIT 31 | Version: 0.6.0 32 | 33 | */ 34 | 35 | #ifndef _AXP192_CONFIG_H 36 | #define _AXP192_CONFIG_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #ifdef AXP192_INCLUDE_SDKCONFIG_H 43 | #include "sdkconfig.h" 44 | 45 | /* This requires you to run menuconfig first. */ 46 | 47 | #define CONFIG_AXP192_EXTEN_DCDC2_CONTROL ( \ 48 | CONFIG_AXP192_EXTEN_DCDC2_CONTROL_BIT2 | \ 49 | CONFIG_AXP192_EXTEN_DCDC2_CONTROL_BIT0 \ 50 | ) 51 | 52 | #define CONFIG_AXP192_DCDC13_LDO23_CONTROL ( \ 53 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT6 | \ 54 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT4 | \ 55 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT3 | \ 56 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT2 | \ 57 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT1 | \ 58 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT0 \ 59 | ) 60 | 61 | #define CONFIG_AXP192_LDO23_VOLTAGE ( \ 62 | CONFIG_AXP192_LDO23_VOLTAGE_BIT74 | \ 63 | CONFIG_AXP192_LDO23_VOLTAGE_BIT30 \ 64 | ) 65 | 66 | #define CONFIG_AXP192_DCDC1_VOLTAGE ( \ 67 | CONFIG_AXP192_DCDC1_VOLTAGE_BIT60 \ 68 | ) 69 | 70 | #define CONFIG_AXP192_DCDC3_VOLTAGE ( \ 71 | CONFIG_AXP192_DCDC3_VOLTAGE_BIT60 \ 72 | ) 73 | 74 | #define CONFIG_AXP192_ADC_ENABLE_1 ( \ 75 | CONFIG_AXP192_ADC_ENABLE_1_BIT7 | \ 76 | CONFIG_AXP192_ADC_ENABLE_1_BIT6 | \ 77 | CONFIG_AXP192_ADC_ENABLE_1_BIT5 | \ 78 | CONFIG_AXP192_ADC_ENABLE_1_BIT4 | \ 79 | CONFIG_AXP192_ADC_ENABLE_1_BIT3 | \ 80 | CONFIG_AXP192_ADC_ENABLE_1_BIT2 | \ 81 | CONFIG_AXP192_ADC_ENABLE_1_BIT1 | \ 82 | CONFIG_AXP192_ADC_ENABLE_1_BIT0 \ 83 | ) 84 | 85 | #define CONFIG_AXP192_CHARGE_CONTROL_1 ( \ 86 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT7 | \ 87 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT65 | \ 88 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT4 | \ 89 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT30 \ 90 | ) 91 | 92 | #define CONFIG_AXP192_BATTERY_CHARGE_CONTROL ( \ 93 | CONFIG_AXP192_BATTERY_CHARGE_CONTROL_BIT7 | \ 94 | CONFIG_AXP192_BATTERY_CHARGE_CONTROL_BIT65 | \ 95 | CONFIG_AXP192_BATTERY_CHARGE_CONTROL_BIT10 \ 96 | ) 97 | 98 | #define CONFIG_AXP192_GPIO0_CONTROL ( \ 99 | CONFIG_AXP192_GPIO0_CONTROL_BIT20 \ 100 | ) 101 | 102 | #define CONFIG_AXP192_GPIO1_CONTROL ( \ 103 | CONFIG_AXP192_GPIO1_CONTROL_BIT20 \ 104 | ) 105 | 106 | #define CONFIG_AXP192_GPIO2_CONTROL ( \ 107 | CONFIG_AXP192_GPIO2_CONTROL_BIT20 \ 108 | ) 109 | 110 | #define CONFIG_AXP192_GPIO43_FUNCTION_CONTROL ( \ 111 | CONFIG_AXP192_GPIO43_FUNCTION_CONTROL_BIT7 | \ 112 | CONFIG_AXP192_GPIO43_FUNCTION_CONTROL_BIT32 | \ 113 | CONFIG_AXP192_GPIO43_FUNCTION_CONTROL_BIT10 \ 114 | ) 115 | 116 | #define CONFIG_AXP192_GPIO0_LDOIO0_VOLTAGE ( \ 117 | CONFIG_AXP192_GPIO0_LDOIO0_VOLTAGE_BIT74 \ 118 | ) 119 | 120 | #endif /* AXP192_INCLUDE_SDKCONFIG_H */ 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | #endif 126 | -------------------------------------------------------------------------------- /components/axp192/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS:=./ 2 | COMPONENT_ADD_INCLUDEDIRS:=./ 3 | CFLAGS += -DAXP192_INCLUDE_SDKCONFIG_H 4 | -------------------------------------------------------------------------------- /components/axp192/sdkconfig/m5stickc.defaults: -------------------------------------------------------------------------------- 1 | # This file contains default settings for M5StickC 2 | # 3 | # https://www.banggood.com/custlink/GmDKBVm6t9 4 | # http://s.click.aliexpress.com/e/3DmuIePq 5 | # https://m5stack.com/collections/m5-core/products/stick-c 6 | # 7 | # To use it copy it to your project root before running menuconfig. 8 | # 9 | # $ cp components/axp192/sdkconfig/m5stickc.defaults sdkconfig.defaults 10 | # $ make menuconfig 11 | 12 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT6_SELECTED=y 13 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT4_SELECTED=y 14 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT3_SELECTED=y 15 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT2_SELECTED=y 16 | CONFIG_AXP192_GPIO0_CONTROL_LDOIO0_SELECTED=y 17 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT1_SELECTED=y 18 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT0_SELECTED=y 19 | CONFIG_AXP192_EXTEN_DCDC2_CONTROL_BIT2=0x04 20 | CONFIG_AXP192_EXTEN_DCDC2_CONTROL_BIT0=0x01 21 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT6=0x40 22 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT4=0x10 23 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT3=0x08 24 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT2=0x04 25 | CONFIG_AXP192_GPIO0_CONTROL_BIT20=0x02 26 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT1=0x02 27 | CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT0=0x01 28 | CONFIG_AXP192_GPIO0_LDOIO0_VOLTAGE_BIT74_3V3=y 29 | CONFIG_AXP192_GPIO0_LDOIO0_VOLTAGE_BIT74=0xf0 30 | CONFIG_AXP192_LDO23_VOLTAGE_BIT74_2V8=y 31 | CONFIG_AXP192_LDO23_VOLTAGE_BIT74=0xa0 32 | CONFIG_AXP192_LDO23_VOLTAGE_BIT30_3V0=y 33 | CONFIG_AXP192_LDO23_VOLTAGE_BIT30=0x0c 34 | CONFIG_AXP192_ADC_ENABLE_1_BIT7_SELECTED=y 35 | CONFIG_AXP192_ADC_ENABLE_1_BIT6_SELECTED=y 36 | CONFIG_AXP192_ADC_ENABLE_1_BIT5_SELECTED=y 37 | CONFIG_AXP192_ADC_ENABLE_1_BIT4_SELECTED=y 38 | CONFIG_AXP192_ADC_ENABLE_1_BIT3_SELECTED=y 39 | CONFIG_AXP192_ADC_ENABLE_1_BIT2_SELECTED=y 40 | CONFIG_AXP192_ADC_ENABLE_1_BIT1_SELECTED=y 41 | CONFIG_AXP192_ADC_ENABLE_1_BIT0_SELECTED=y 42 | CONFIG_AXP192_ADC_ENABLE_1_BIT7=0x80 43 | CONFIG_AXP192_ADC_ENABLE_1_BIT6=0x40 44 | CONFIG_AXP192_ADC_ENABLE_1_BIT5=0x20 45 | CONFIG_AXP192_ADC_ENABLE_1_BIT4=0x10 46 | CONFIG_AXP192_ADC_ENABLE_1_BIT3=0x08 47 | CONFIG_AXP192_ADC_ENABLE_1_BIT2=0x04 48 | CONFIG_AXP192_ADC_ENABLE_1_BIT1=0x02 49 | CONFIG_AXP192_ADC_ENABLE_1_BIT0=0x01 50 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT7_SELECTED=y 51 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT7=0x80 52 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT65_42_SELECTED=y 53 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT65=0x40 54 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT30_100_SELECTED=y 55 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT30=0x00 56 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT4_15_SELECTED=y 57 | CONFIG_AXP192_CHARGE_CONTROL_1_BIT4=0x10 58 | -------------------------------------------------------------------------------- /components/axp202/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register( 2 | SRCS "axp202.c" 3 | INCLUDE_DIRS "." 4 | ) -------------------------------------------------------------------------------- /components/axp202/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mika Tuupola 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /components/axp202/README.md: -------------------------------------------------------------------------------- 1 | # Platform agnostic I2C driver for AXP202 PMU 2 | 3 | To use this library you must to provide functions for both reading and writing the I2C bus. Function definitions must be the following. 4 | 5 | ```c 6 | int32_t i2c_read(void *handle, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size); 7 | int32_t i2c_write(void *handle, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size); 8 | ``` 9 | 10 | Where `address` is the I2C address, `reg` is the register to read or write, `buffer` holds the data to write or read into and `size` is the amount of data to read or write. The `handle` parameter is an optional customizable argument. You can use it if your I2C implementation requires any additional information such has number of the hardware I2C driver. For example HAL implementation see [ESP I2C helper](https://github.com/tuupola/esp_i2c_helper). For working example see [TTGO T-Watch 2020 kitchen sink](https://github.com/tuupola/esp_twatch2020). 11 | 12 | ## Usage 13 | 14 | ``` 15 | $ make menuconfig 16 | ``` 17 | 18 | ```c 19 | #include "axp202.h" 20 | #include "user_i2c.h" 21 | 22 | float vacin, iacin, vvbus, ivbus, vts, vgpio0, vgpio1, temp, pbat; 23 | float vbat, icharge, idischarge, ipsout, cbat, fuel; 24 | uint8_t power, charge; 25 | axp202_t axp; 26 | 27 | /* Add pointers to HAL functions. */ 28 | axp.read = &user_i2c_read; 29 | axp.write = &user_i2c_write; 30 | 31 | /* You could set the handle here. It can be pointer to anything. */ 32 | axp.handle = NULL; 33 | 34 | axp202_init(&axp); 35 | 36 | axp202_read(&axp, AXP202_ACIN_VOLTAGE, &vacin); 37 | axp202_read(&axp, AXP202_ACIN_CURRENT, &iacin); 38 | axp202_read(&axp, AXP202_VBUS_VOLTAGE, &vvbus); 39 | axp202_read(&axp, AXP202_VBUS_CURRENT, &ivbus); 40 | axp202_read(&axp, AXP202_TEMP, &temp); 41 | axp202_read(&axp, AXP202_TS_INPUT, &vts); 42 | axp202_read(&axp, AXP202_GPIO0_VOLTAGE, &vgpio0); 43 | axp202_read(&axp, AXP202_GPIO1_VOLTAGE, &vgpio1); 44 | axp202_read(&axp, AXP202_BATTERY_POWER, &pbat); 45 | axp202_read(&axp, AXP202_BATTERY_VOLTAGE, &vbat); 46 | axp202_read(&axp, AXP202_CHARGE_CURRENT, &icharge); 47 | axp202_read(&axp, AXP202_DISCHARGE_CURRENT, &idischarge); 48 | axp202_read(&axp, AXP202_IPSOUT_VOLTAGE, &ipsout); 49 | axp202_read(&axp, AXP202_COULOMB_COUNTER, &cbat); 50 | axp202_read(&axp, AXP202_FUEL_GAUGE, &fuel); 51 | 52 | 53 | printf( 54 | "vacin: %.2fV iacin: %.2fA vvbus: %.2fV ivbus: %.2fA vts: %.2fV temp: %.0fC " 55 | "vgpio0: %.2fV vgpio1: %.2fV pbat: %.2fmW vbat: %.2fV icharge: %.2fA " 56 | "idischarge: %.2fA, ipsout: %.2fV cbat: %.2fmAh fuel: %.0f%%", 57 | vacin, iacin, vvbus, ivbus, vts, temp, vgpio0, vgpio1, pbat, vbat, icharge, 58 | idischarge, ipsout, cbat, fuel 59 | ); 60 | 61 | axp202_ioctl(&axp, AXP202_READ_POWER_STATUS, &power); 62 | axp202_ioctl(&axp, AXP202_READ_CHARGE_STATUS, &charge); 63 | 64 | printf("power: 0x%02x charge: 0x%02x", power, charge); 65 | 66 | axp202_ioctl(&axp, AXP202_COULOMB_COUNTER_ENABLE, NULL); 67 | axp202_read(&axp, AXP202_COULOMB_COUNTER, &cbat); 68 | 69 | printf("cbat: %.2fmAh", cbat); 70 | ``` -------------------------------------------------------------------------------- /components/axp202/axp202_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of hardware agnostic I2C driver for AXP202: 28 | https://github.com/tuupola/axp202 29 | 30 | SPDX-License-Identifier: MIT 31 | 32 | */ 33 | 34 | #ifndef _AXP202_CONFIG_H 35 | #define _AXP202_CONFIG_H 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include "sdkconfig.h" 42 | 43 | /* This requires you to run menuconfig first. */ 44 | 45 | #define CONFIG_AXP202_DCDC23_LDO234_EXTEN_CONTROL ( \ 46 | CONFIG_AXP202_DCDC23_LDO234_EXTEN_CONTROL_BIT6 | \ 47 | CONFIG_AXP202_DCDC23_LDO234_EXTEN_CONTROL_BIT4 | \ 48 | CONFIG_AXP202_DCDC23_LDO234_EXTEN_CONTROL_BIT3 | \ 49 | CONFIG_AXP202_DCDC23_LDO234_EXTEN_CONTROL_BIT2 | \ 50 | CONFIG_AXP202_DCDC23_LDO234_EXTEN_CONTROL_BIT1 | \ 51 | CONFIG_AXP202_DCDC23_LDO234_EXTEN_CONTROL_BIT0 \ 52 | ) 53 | 54 | #define CONFIG_AXP202_DCDC2_VOLTAGE ( \ 55 | CONFIG_AXP202_DCDC2_VOLTAGE_BIT50 \ 56 | ) 57 | 58 | #define CONFIG_AXP202_DCDC3_VOLTAGE ( \ 59 | CONFIG_AXP202_DCDC3_VOLTAGE_BIT60 \ 60 | ) 61 | 62 | #define CONFIG_AXP202_LDO24_VOLTAGE ( \ 63 | CONFIG_AXP202_LDO24_VOLTAGE_BIT74 | \ 64 | CONFIG_AXP202_LDO24_VOLTAGE_BIT30 \ 65 | ) 66 | 67 | #define CONFIG_AXP202_LDO3_VOLTAGE ( \ 68 | CONFIG_AXP202_LDO3_VOLTAGE_BIT60 \ 69 | ) 70 | 71 | #define CONFIG_AXP202_ADC_ENABLE_1 ( \ 72 | CONFIG_AXP202_ADC_ENABLE_1_BIT7 | \ 73 | CONFIG_AXP202_ADC_ENABLE_1_BIT6 | \ 74 | CONFIG_AXP202_ADC_ENABLE_1_BIT5 | \ 75 | CONFIG_AXP202_ADC_ENABLE_1_BIT4 | \ 76 | CONFIG_AXP202_ADC_ENABLE_1_BIT3 | \ 77 | CONFIG_AXP202_ADC_ENABLE_1_BIT2 | \ 78 | CONFIG_AXP202_ADC_ENABLE_1_BIT1 | \ 79 | CONFIG_AXP202_ADC_ENABLE_1_BIT0 \ 80 | ) 81 | 82 | #define CONFIG_AXP202_ADC_ENABLE_2 ( \ 83 | CONFIG_AXP202_ADC_ENABLE_2_BIT7 | \ 84 | CONFIG_AXP202_ADC_ENABLE_2_BIT3 | \ 85 | CONFIG_AXP202_ADC_ENABLE_2_BIT2 \ 86 | ) 87 | 88 | #ifdef CONFIG_AXP202_CHARGE_CONTROL_1_BIT7_SELECTED 89 | #define CONFIG_AXP202_CHARGE_CONTROL_1 ( \ 90 | CONFIG_AXP202_CHARGE_CONTROL_1_BIT7 | \ 91 | CONFIG_AXP202_CHARGE_CONTROL_1_BIT65 | \ 92 | CONFIG_AXP202_CHARGE_CONTROL_1_BIT4 | \ 93 | CONFIG_AXP202_CHARGE_CONTROL_1_BIT30 \ 94 | ) 95 | #else 96 | #define CONFIG_AXP202_CHARGE_CONTROL_1 (0x00) 97 | #endif 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | #endif 103 | -------------------------------------------------------------------------------- /components/axp202/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS:=./ 2 | COMPONENT_ADD_INCLUDEDIRS:=./ -------------------------------------------------------------------------------- /components/esp_i2c_helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register( 2 | SRCS "i2c_helper.c" 3 | INCLUDE_DIRS "." 4 | ) 5 | -------------------------------------------------------------------------------- /components/esp_i2c_helper/Kconfig: -------------------------------------------------------------------------------- 1 | menu "ESP I2C helper" 2 | 3 | menu "Port 0" 4 | config I2C_HELPER_MASTER_0_SDA 5 | default 21 6 | int "SDA" 7 | config I2C_HELPER_MASTER_0_SCL 8 | default 22 9 | int "SCL" 10 | config I2C_HELPER_MASTER_0_FREQ_HZ 11 | default 1000000 12 | int "FREQ" 13 | endmenu 14 | 15 | menu "Port 1" 16 | config I2C_HELPER_MASTER_1_SDA 17 | default 21 18 | int "SDA" 19 | config I2C_HELPER_MASTER_1_SCL 20 | default 22 21 | int "SCL" 22 | config I2C_HELPER_MASTER_1_FREQ_HZ 23 | default 1000000 24 | int "FREQ" 25 | endmenu 26 | 27 | endmenu 28 | -------------------------------------------------------------------------------- /components/esp_i2c_helper/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS:=./ 2 | COMPONENT_ADD_INCLUDEDIRS:=./ -------------------------------------------------------------------------------- /components/esp_i2c_helper/i2c_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | SPDX-License-Identifier: MIT 4 | 5 | MIT License 6 | 7 | Copyright (c) 2019-2020 Mika Tuupola 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | */ 28 | 29 | #ifndef _I2C_HELPER_H 30 | #define _I2C_HELPER_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | 39 | #include "sdkconfig.h" 40 | 41 | #define I2C_HELPER_MASTER_RX_BUF_LEN (0) 42 | #define I2C_HELPER_MASTER_TX_BUF_LEN (0) 43 | 44 | #define I2C_HELPER_MASTER_0_SDA (CONFIG_I2C_HELPER_MASTER_0_SDA) 45 | #define I2C_HELPER_MASTER_0_SCL (CONFIG_I2C_HELPER_MASTER_0_SCL) 46 | #define I2C_HELPER_MASTER_0_FREQ_HZ (CONFIG_I2C_HELPER_MASTER_0_FREQ_HZ) 47 | 48 | #define I2C_HELPER_MASTER_1_SDA (CONFIG_I2C_HELPER_MASTER_1_SDA) 49 | #define I2C_HELPER_MASTER_1_SCL (CONFIG_I2C_HELPER_MASTER_1_SCL) 50 | #define I2C_HELPER_MASTER_1_FREQ_HZ (CONFIG_I2C_HELPER_MASTER_1_FREQ_HZ) 51 | 52 | int32_t i2c_init(i2c_port_t port); 53 | int32_t i2c_read(void *port, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size); 54 | int32_t i2c_write(void *port, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size); 55 | int32_t i2c_close(i2c_port_t port); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | #endif 61 | -------------------------------------------------------------------------------- /components/hagl/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file, in reverse chronological order by release. 4 | 5 | ## [0.6.0-dev](https://github.com/tuupola/hagl/compare/0.5.0...master) 6 | 7 | ### Changed 8 | - The fps counter was refactored ([#69](https://github.com/tuupola/hagl/pull/69)). 9 | - The aps counter was refactored ([#69](https://github.com/tuupola/hagl/pull/70)). 10 | 11 | ## 0.5.0 - 2022-05-19 12 | 13 | Initial release. 14 | -------------------------------------------------------------------------------- /components/hagl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (ESP_PLATFORM) 2 | 3 | idf_component_register( 4 | SRCS 5 | "src/hagl.c" 6 | "src/hagl_blit.c" 7 | "src/hagl_char.c" 8 | "src/hagl_circle.c" 9 | "src/hagl_clip.c" 10 | "src/hagl_color.c" 11 | "src/hagl_ellipse.c" 12 | "src/hagl_hline.c" 13 | "src/hagl_image.c" 14 | "src/hagl_line.c" 15 | "src/hagl_pixel.c" 16 | "src/hagl_polygon.c" 17 | "src/hagl_rectangle.c" 18 | "src/hagl_triangle.c" 19 | "src/hagl_vline.c" 20 | "src/bitmap.c" 21 | "src/fontx.c" 22 | "src/hsl.c" 23 | "src/rgb565.c" 24 | "src/rgb888.c" 25 | "src/tjpgd.c" 26 | INCLUDE_DIRS "./include" 27 | REQUIRES hagl_hal 28 | ) 29 | add_definitions("-DHAGL_INCLUDE_SDKCONFIG_H") 30 | 31 | else() 32 | 33 | add_library(hagl INTERFACE) 34 | 35 | target_sources(hagl INTERFACE 36 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl.c 37 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_blit.c 38 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_char.c 39 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_circle.c 40 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_clip.c 41 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_color.c 42 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_ellipse.c 43 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_hline.c 44 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_image.c 45 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_line.c 46 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_pixel.c 47 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_polygon.c 48 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_rectangle.c 49 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_triangle.c 50 | ${CMAKE_CURRENT_LIST_DIR}/src/hagl_vline.c 51 | ${CMAKE_CURRENT_LIST_DIR}/src/bitmap.c 52 | ${CMAKE_CURRENT_LIST_DIR}/src/fontx.c 53 | ${CMAKE_CURRENT_LIST_DIR}/src/hsl.c 54 | ${CMAKE_CURRENT_LIST_DIR}/src/rgb565.c 55 | ${CMAKE_CURRENT_LIST_DIR}/src/rgb888.c 56 | ${CMAKE_CURRENT_LIST_DIR}/src/tjpgd.c 57 | ) 58 | 59 | target_include_directories(hagl INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) 60 | 61 | target_link_libraries(hagl INTERFACE hagl_hal) 62 | 63 | endif() 64 | -------------------------------------------------------------------------------- /components/hagl/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Hardware Agnostic Graphics Library (HAGL)" 2 | 3 | config HAGL_TJPGD_NEEDS_BYTESWAP 4 | bool "Swap TJPGD output bytes" 5 | default y 6 | help 7 | If JPG file colours seems wrong change this setting. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /components/hagl/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2022 Mika Tuupola 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/hagl/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS:=./src 2 | COMPONENT_ADD_INCLUDEDIRS:=./include 3 | CFLAGS += -DHAGL_INCLUDE_SDKCONFIG_H 4 | -------------------------------------------------------------------------------- /components/hagl/include/aps.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_APS_H 36 | #define _HAGL_APS_H 37 | 38 | #include 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | 45 | typedef struct { 46 | clock_t start; 47 | uint64_t value; 48 | float smoothing; 49 | float current; 50 | } aps_instance_t; 51 | 52 | /** 53 | * Initialize the given anything per second counter instance 54 | */ 55 | static inline void 56 | aps_init(aps_instance_t *aps) { 57 | aps->start = clock() - 1; 58 | aps->value = 0; 59 | aps->current = 0.0; 60 | 61 | /* Larger value is less smoothing. */ 62 | if (!aps->smoothing) { 63 | aps->smoothing = 0.98; 64 | } 65 | } 66 | 67 | /** 68 | * Update the given anything per second counter instance 69 | * 70 | * Use to measure the rendering speed. Should be called always 71 | * after flushing the back buffer. 72 | * 73 | * @return current aps 74 | */ 75 | static inline float 76 | aps_update(aps_instance_t *aps, uint32_t add) 77 | { 78 | 79 | 80 | float measured = 0.0; 81 | clock_t ticks = clock() - aps->start;; 82 | 83 | aps->value += add; 84 | 85 | measured = aps->value / (float) ticks * CLOCKS_PER_SEC; 86 | aps->current = (measured * aps->smoothing) + (aps->current * (1.0 - aps->smoothing)); 87 | 88 | return aps->current; 89 | } 90 | 91 | /** 92 | * Reset the given anything per second counter instance 93 | */ 94 | static inline void 95 | aps_reset(aps_instance_t *aps) { 96 | aps->start = clock() - 1; 97 | aps->value = 0; 98 | aps->current = 0; 99 | } 100 | 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif /* __cplusplus */ 105 | 106 | #endif /* _HAGL_APS_H */ -------------------------------------------------------------------------------- /components/hagl/include/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifdef HAGL_INCLUDE_SDKCONFIG_H 36 | #include "sdkconfig.h" 37 | 38 | #ifdef CONFIG_HAGL_TJPGD_NEEDS_BYTESWAP 39 | #define TJPGD_NEEDS_BYTESWAP 40 | #endif /* CONFIG_HAGL_TJPGD_NEEDS_BYTESWAP */ 41 | 42 | # else 43 | 44 | /* If you don't use menuconfig change the settings here. */ 45 | #define TJPGD_NEEDS_BYTESWAP 46 | 47 | #endif /* HAGL_INCLUDE_SDKCONFIG_H */ 48 | -------------------------------------------------------------------------------- /components/hagl/include/fontx.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2012 ChaN 6 | Copyright (c) 2020-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | Adapted from the blog post by ChaN: 32 | http://elm-chan.org/docs/dosv/fontx_e.html 33 | 34 | SPDX-License-Identifier: MIT 35 | 36 | */ 37 | 38 | #ifndef _HAGL_FONTX_H 39 | #define _HAGL_FONTX_H 40 | 41 | #include 42 | #include 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif /* __cplusplus */ 47 | 48 | #define FONTX_OK (0) 49 | #define FONTX_ERR_GLYPH_NOT_FOUND (1) 50 | #define FONTX_NAME (6) 51 | #define FONTX_WIDTH (14) 52 | #define FONTX_HEIGHT (15) 53 | #define FONTX_TYPE (16) 54 | #define FONTX_TYPE_SBCS (0) 55 | #define FONTX_TYPE_DBCS (1) 56 | #define FONTX_GLYPH_DATA_START (17) 57 | #define FONTX_BLOCK_TABLE_SIZE (17) 58 | #define FONTX_BLOCK_TABLE_START (18) 59 | 60 | /* Pitch is bytes per row. Size is size in bytes. */ 61 | typedef struct{ 62 | uint8_t width; 63 | uint8_t height; 64 | uint8_t size; 65 | uint8_t pitch; 66 | const uint8_t *buffer; 67 | } fontx_glyph_t; 68 | 69 | typedef struct{ 70 | char name[9]; 71 | uint8_t width; 72 | uint8_t height; 73 | uint8_t type; 74 | } fontx_meta_t; 75 | 76 | uint8_t fontx_meta(fontx_meta_t *meta, const uint8_t *font); 77 | uint8_t fontx_glyph(fontx_glyph_t *glyph, wchar_t code, const uint8_t *font); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif /* __cplusplus */ 82 | 83 | #endif /* _HAGL_FONTX_H */ 84 | -------------------------------------------------------------------------------- /components/hagl/include/fps.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_FPS_H 36 | #define _HAGL_FPS_H 37 | 38 | #include 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | 45 | typedef struct { 46 | clock_t start; 47 | uint32_t frames; 48 | float smoothing; 49 | float current; 50 | } fps_instance_t; 51 | 52 | /** 53 | * Initialize the given FPS counter instance 54 | */ 55 | static inline void 56 | fps_init(fps_instance_t *fps) { 57 | fps->start = clock() - 1; 58 | fps->frames = 0; 59 | fps->current = 0.0; 60 | 61 | /* Larger value is less smoothing. */ 62 | if (!fps->smoothing) { 63 | fps->smoothing = 0.98; 64 | } 65 | } 66 | 67 | /** 68 | * Update the given FPS counter instance 69 | * 70 | * Use to measure the rendering speed. Should be called always 71 | * after flushing the back buffer. 72 | * 73 | * @return current fps 74 | */ 75 | static inline float 76 | fps_update(fps_instance_t *fps) 77 | { 78 | float measured = 0.0; 79 | clock_t ticks = clock() - fps->start;; 80 | 81 | fps->frames++; 82 | 83 | measured = fps->frames / (float) ticks * CLOCKS_PER_SEC; 84 | fps->current = (measured * fps->smoothing) + (fps->current * (1.0 - fps->smoothing)); 85 | 86 | return fps->current; 87 | } 88 | 89 | /** 90 | * Reset the given FPS counter instance 91 | */ 92 | static inline void 93 | fps_reset(fps_instance_t *fps) { 94 | fps->start = clock() - 1; 95 | fps->frames = 0; 96 | fps->current = 0; 97 | } 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif /* __cplusplus */ 102 | 103 | #endif /* HAGL_FPS_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_H 36 | #define _HAGL_H 37 | 38 | #include 39 | #include 40 | 41 | #include "hagl/pixel.h" 42 | #include "hagl/surface.h" 43 | #include "hagl/backend.h" 44 | #include "hagl_hal.h" 45 | #include "hagl/bitmap.h" 46 | #include "hagl/clip.h" 47 | #include "hagl/line.h" 48 | #include "hagl/hline.h" 49 | #include "hagl/vline.h" 50 | #include "hagl/rectangle.h" 51 | #include "hagl/circle.h" 52 | #include "hagl/ellipse.h" 53 | #include "hagl/polygon.h" 54 | #include "hagl/triangle.h" 55 | #include "hagl/image.h" 56 | #include "hagl/blit.h" 57 | #include "hagl/char.h" 58 | 59 | #ifdef __cplusplus 60 | extern "C" { 61 | #endif /* __cplusplus */ 62 | 63 | #define ABS(x) ((x) > 0 ? (x) : -(x)) 64 | 65 | #define HAGL_CHAR_BUFFER_SIZE (16 * 16 * DISPLAY_DEPTH / 2) 66 | 67 | #define HAGL_OK (0) 68 | #define HAGL_ERR_GENERAL (1) 69 | #define HAGL_ERR_FILE_IO (2) 70 | 71 | /** 72 | * Clear area of the current clip window 73 | */ 74 | void hagl_clear_clip_window(); 75 | 76 | hagl_backend_t *hagl_init(void); 77 | size_t hagl_flush(hagl_backend_t *backend); 78 | void hagl_close(hagl_backend_t *backend); 79 | 80 | void hagl_clear(void *surface); 81 | 82 | 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif /* __cplusplus */ 87 | 88 | #endif /* _HAGL_H */ 89 | -------------------------------------------------------------------------------- /components/hagl/include/hagl/backend.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_BACKEND_H 36 | #define _HAGL_BACKEND_H 37 | 38 | #include 39 | 40 | #include "hagl/bitmap.h" 41 | #include "hagl/window.h" 42 | #include "hagl/color.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif /* __cplusplus */ 47 | 48 | typedef struct { 49 | /* Common to all surfaces. */ 50 | int16_t width; 51 | int16_t height; 52 | uint8_t depth; 53 | hagl_window_t clip; 54 | void (*put_pixel)(void *self, int16_t x0, int16_t y0, color_t color); 55 | color_t (*get_pixel)(void *self, int16_t x0, int16_t y0); 56 | color_t (*color)(void *self, uint8_t r, uint8_t g, uint8_t b); 57 | void (*blit)(void *self, int16_t x0, int16_t y0, hagl_bitmap_t *src); 58 | void (*scale_blit)(void *self, uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, hagl_bitmap_t *src); 59 | void (*hline)(void *self, int16_t x0, int16_t y0, uint16_t width, color_t color); 60 | void (*vline)(void *self, int16_t x0, int16_t y0, uint16_t height, color_t color); 61 | 62 | /* Specific to backend. */ 63 | size_t (*flush)(void *self); 64 | void (*close)(void *self); 65 | uint8_t *buffer; 66 | uint8_t *buffer2; 67 | } hagl_backend_t; 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif /* __cplusplus */ 72 | 73 | #endif /* _HAGL_BACKEND_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/bitmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | SPDX-License-Identifier: MIT 31 | 32 | */ 33 | 34 | #ifndef _BITMAP_H 35 | #define _BITMAP_H 36 | 37 | #include 38 | 39 | #include "hagl/window.h" 40 | #include "hagl/color.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif /* __cplusplus */ 45 | 46 | #define BITMAP_SIZE(width, height, depth) (width * (depth / 8) * height) 47 | 48 | /* 49 | Pitch is bytes per row. Depth is number of bits per pixel. Size is size 50 | in bytes. 51 | */ 52 | typedef struct { 53 | int16_t width; 54 | int16_t height; 55 | uint8_t depth; 56 | hagl_window_t clip; 57 | void (*put_pixel)(void *self, int16_t x0, int16_t y0, color_t color); 58 | color_t (*get_pixel)(void *self, int16_t x0, int16_t y0); 59 | color_t (*color)(void *self, uint8_t r, uint8_t g, uint8_t b); 60 | void (*blit)(void *self, int16_t x0, int16_t y0, void *src); 61 | void (*scale_blit)(void *self, int16_t x0, int16_t y0, uint16_t w, uint16_t h, void *src); 62 | void (*hline)(void *self, int16_t x0, int16_t y0, uint16_t width, color_t color); 63 | void (*vline)(void *self, int16_t x0, int16_t y0, uint16_t height, color_t color); 64 | 65 | uint16_t pitch; 66 | uint32_t size; 67 | uint8_t *buffer; 68 | } hagl_bitmap_t; 69 | 70 | uint32_t bitmap_size(hagl_bitmap_t *bitmap); 71 | void bitmap_init(hagl_bitmap_t *bitmap, uint8_t *buffer); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif /* __cplusplus */ 76 | 77 | #endif /* _BITMAP_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/blit.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_BLIT_H 37 | #define _HAGL_BLIT_H 38 | 39 | #include 40 | 41 | #include "hagl/bitmap.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Blit a bitmap to the display 49 | * 50 | * Output will be clipped to the current clip window. 51 | * 52 | * @param surface 53 | * @param x0 54 | * @param y0 55 | * @param source pointer to a bitmap 56 | */ 57 | void 58 | hagl_blit(void const *surface, int16_t x0, int16_t y0, hagl_bitmap_t *source); 59 | 60 | /** 61 | * Blit and scale a bitmap to the display 62 | * 63 | * Output will be clipped to the current clip window. 64 | * 65 | * @param surface 66 | * @param x0 67 | * @param y0 68 | * @param w target width 69 | * @param h target height 70 | * @param source pointer to a bitmap 71 | */ 72 | void 73 | hagl_scale_blit(void const *surface, uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, hagl_bitmap_t *source); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif /* __cplusplus */ 78 | 79 | #endif /* _HAGL_BLIT_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/char.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_CHAR_H 37 | #define _HAGL_CHAR_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Draw a single character 49 | * 50 | * Output will be clipped to the current clip window. Library itself 51 | * includes only a couple of fonts. You can find more fonts at: 52 | * 53 | * https://github.com/tuupola/embedded-fonts 54 | * 55 | * @param surface 56 | * @param code unicode code point 57 | * @param x0 58 | * @param y0 59 | * @param color 60 | * @param font pointer to a FONTX font 61 | * @return width of the drawn character 62 | */ 63 | uint8_t 64 | hagl_put_char(void const *surface, wchar_t code, int16_t x0, int16_t y0, color_t color, const unsigned char *font); 65 | 66 | /** 67 | * Draw a string 68 | * 69 | * Output will be clipped to the current clip window. Library itself 70 | * includes only a couple of fonts. You can find more fonts at: 71 | * 72 | * https://github.com/tuupola/embedded-fonts 73 | * 74 | * @param surface 75 | * @param str pointer to an wide char string 76 | * @param x0 77 | * @param y0 78 | * @param color 79 | * @param font pointer to a FONTX font 80 | * @return width of the drawn string 81 | */ 82 | uint16_t 83 | hagl_put_text(void const *surface, const wchar_t *str, int16_t x0, int16_t y0, color_t color, const unsigned char *font); 84 | 85 | /** 86 | * Extract a glyph into a bitmap 87 | * 88 | * This can be used for example for extracting game sprites from fontsets 89 | * such as UNSCII. 90 | * 91 | * @param surface 92 | * @param code Unicode code point 93 | * @param color 94 | * @param bitmap Pointer to a bitmap 95 | * @param font Pointer to a FONTX font 96 | * @return Width of the drawn string 97 | */ 98 | uint8_t 99 | hagl_get_glyph(void const *surface, wchar_t code, color_t color, hagl_bitmap_t *bitmap, const uint8_t *font); 100 | 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif /* __cplusplus */ 105 | 106 | #endif /* _HAGL_CHAR_H */ 107 | -------------------------------------------------------------------------------- /components/hagl/include/hagl/circle.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_CIRCLE_H 37 | #define _HAGL_CIRCLE_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Draw a circle 49 | * 50 | * Output will be clipped to the current clip window. 51 | * 52 | * @param x0 center X 53 | * @param y0 center Y 54 | * @param r radius 55 | * @param color 56 | */ 57 | void 58 | hagl_draw_circle(void const *surface, int16_t x0, int16_t y0, int16_t r, color_t color); 59 | 60 | /** 61 | * Draw a filled circle 62 | * 63 | * Output will be clipped to the current clip window. 64 | * 65 | * @param x0 center X 66 | * @param y0 center Y 67 | * @param r radius 68 | * @param color 69 | */ 70 | void 71 | hagl_fill_circle(void const *surface, int16_t x0, int16_t y0, int16_t r, color_t color); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif /* __cplusplus */ 76 | 77 | #endif /* _HAGL_CIRCLE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/clip.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_CLIP_H 36 | #define _HAGL_CLIP_H 37 | 38 | #include 39 | #include 40 | 41 | #include "hagl/window.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | bool hagl_clip_line(int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, hagl_window_t window); 48 | 49 | /** 50 | * Set the clip window 51 | * 52 | * Clip windows restricts the drawable area. It does not affect 53 | * the coordinates. 54 | * 55 | * @param surface 56 | * @param x0 57 | * @param y0 58 | * @param x1 59 | * @param y1 60 | */ 61 | void 62 | hagl_set_clip_window(void *surface, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif /* __cplusplus */ 67 | 68 | #endif /* _HAGL_CLIP_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/color.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_COLOR_H 37 | #define _HAGL_COLOR_H 38 | 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | 45 | /** 46 | * Convert RGB to color 47 | * 48 | * Returns color type defined by the HAL. Most often it is an 49 | * uint16_t RGB565 color. 50 | * 51 | * @param surface 52 | * @return color 53 | */ 54 | color_t 55 | hagl_color(void const *surface, uint8_t r, uint8_t g, uint8_t b); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif /* __cplusplus */ 60 | 61 | #endif /* _HAGL_COLOR_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/ellipse.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_ELLIPSE_H 37 | #define _HAGL_ELLIPSE_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Draw an ellipse 49 | * 50 | * Output will be clipped to the current clip window. 51 | * 52 | * @param surface 53 | * @param x0 center X 54 | * @param y0 center Y 55 | * @param a vertical radius 56 | * @param b horizontal radius 57 | * @param color 58 | */ 59 | void 60 | hagl_draw_ellipse(void const *surface, int16_t x0, int16_t y0, int16_t a, int16_t b, color_t color); 61 | 62 | /** 63 | * Draw a filled ellipse 64 | * 65 | * Output will be clipped to the current clip window. 66 | * 67 | * @param surface 68 | * @param x0 center X 69 | * @param y0 center Y 70 | * @param a vertical radius 71 | * @param b horizontal radius 72 | * @param color 73 | */ 74 | void 75 | hagl_fill_ellipse(void const *surface, int16_t x0, int16_t y0, int16_t a, int16_t b, color_t color); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif /* __cplusplus */ 80 | 81 | #endif /* _HAGL_ELLIPSE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/hline.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_HLINE_H 37 | #define _HAGL_HLINE_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Draw a horizontal line 49 | * 50 | * Output will be clipped to the current clip window. 51 | * 52 | * @param surface 53 | * @param x0 54 | * @param y0 55 | * @param width 56 | * @param color 57 | */ 58 | 59 | void 60 | hagl_draw_hline(void const *surface, int16_t x0, int16_t y0, uint16_t width, color_t color); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif /* __cplusplus */ 65 | 66 | #endif /* _HAGL_HLINE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/image.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_PIXEL_H 37 | #define _HAGL_PIXEL_H 38 | 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | 45 | #define HAGL_ERR_TJPGD (100) 46 | 47 | /** 48 | * Load an image 49 | * 50 | * Output will be clipped to the current clip window. Does not do 51 | * any scaling. Currently supports only baseline jpg images. 52 | * 53 | * @param surface 54 | * @param x0 55 | * @param y0 56 | * @param x1 57 | * @param y1 58 | * @param color 59 | */ 60 | uint32_t 61 | hagl_load_image(void const *surface, int16_t x0, int16_t y0, const char *filename); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif /* __cplusplus */ 66 | 67 | #endif /* _HAGL_PIXEL_H */ 68 | -------------------------------------------------------------------------------- /components/hagl/include/hagl/line.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_LINE_H 37 | #define _HAGL_LINE_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Draw a line 49 | * 50 | * Output will be clipped to the current clip window. 51 | * 52 | * @param surface 53 | * @param x0 54 | * @param y0 55 | * @param x1 56 | * @param y1 57 | * @param color 58 | */ 59 | void 60 | hagl_draw_line(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif /* __cplusplus */ 65 | 66 | #endif /* _HAGL_LINE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/pixel.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_PIXEL_H 37 | #define _HAGL_PIXEL_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Put a single pixel 49 | * 50 | * Output will be clipped to the current clip window. 51 | * 52 | * @param surface 53 | * @param x0 54 | * @param y0 55 | * @param color 56 | */ 57 | void 58 | hagl_put_pixel(void const *surface, int16_t x0, int16_t y0, color_t color); 59 | 60 | /** 61 | * Get a single pixel 62 | * 63 | * Input will be clipped to the current clip window. In case of 64 | * error or if HAL does not support this feature returns black. 65 | * 66 | * @param surface 67 | * @param x0 68 | * @param y0 69 | * @return color at the given location 70 | */ 71 | color_t 72 | hagl_get_pixel(void const *surface, int16_t x0, int16_t y0); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif /* __cplusplus */ 77 | 78 | #endif /* _HAGL_PIXEL_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/polygon.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_POLYGON_H 37 | #define _HAGL_POLYGON_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Draw a polygon 49 | * 50 | * Output will be clipped to the current clip window. Polygon does 51 | * not need to be convex. They can also be concave or complex. 52 | * 53 | * color_t color = hagl_color(0, 255, 0); 54 | * int16_t vertices[10] = {x0, y0, x1, y1, x2, y2, x3, y3, x4, y4}; 55 | * hagl_draw_polygon(5, vertices, color); 56 | * 57 | * @param surface 58 | * @param amount number of vertices 59 | * @param vertices pointer to (an array) of vertices 60 | * @param color 61 | */ 62 | void 63 | hagl_draw_polygon(void const *surface, int16_t amount, int16_t *vertices, color_t color); 64 | 65 | /** 66 | * Draw a filled polygon 67 | * 68 | * Output will be clipped to the current clip window. Polygon does 69 | * not need to be convex. They can also be concave or complex. 70 | * 71 | * color_t color = hagl_color(0, 255, 0); 72 | * int16_t vertices[10] = {x0, y0, x1, y1, x2, y2, x3, y3, x4, y4}; 73 | * hagl_draw_polygon(5, vertices, color); 74 | * 75 | * @param surface 76 | * @param amount number of vertices 77 | * @param vertices pointer to (an array) of vertices 78 | * @param color 79 | */ 80 | void 81 | hagl_fill_polygon(void const *surface, int16_t amount, int16_t *vertices, color_t color); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif /* __cplusplus */ 86 | 87 | #endif /* _HAGL_POLYGON_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/rectangle.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | MIT License 5 | 6 | Copyright (c) 2018-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | SPDX-License-Identifier: MIT 33 | 34 | */ 35 | 36 | #ifndef _HAGL_RECTANGLE_H 37 | #define _HAGL_RECTANGLE_H 38 | 39 | #include 40 | 41 | #include "hagl/color.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif /* __cplusplus */ 46 | 47 | /** 48 | * Draw a rectangle 49 | * 50 | * Output will be clipped to the current clip window. 51 | * 52 | * @param surface 53 | * @param x0 54 | * @param y0 55 | * @param x1 56 | * @param y1 57 | * @param color 58 | */ 59 | void 60 | hagl_draw_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color); 61 | 62 | /** 63 | * Draw a filled rectangle 64 | * 65 | * Output will be clipped to the current clip window. 66 | * 67 | * @param surface 68 | * @param x0 69 | * @param y0 70 | * @param x1 71 | * @param y1 72 | * @param color 73 | */ 74 | void 75 | hagl_fill_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color); 76 | 77 | /** 78 | * Draw a rounded rectangle 79 | * 80 | * Output will be clipped to the current clip window. 81 | * 82 | * @param surface 83 | * @param x0 84 | * @param y0 85 | * @param x0 86 | * @param y0 87 | * @param r corner radius 88 | * @param color 89 | */ 90 | void 91 | hagl_draw_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, color_t color); 92 | 93 | /** 94 | * Draw a filled rounded rectangle 95 | * 96 | * Output will be clipped to the current clip window. 97 | * 98 | * @param surface 99 | * @param x0 100 | * @param y0 101 | * @param x1 102 | * @param y1 103 | * @param r corner radius 104 | * @param color 105 | */ 106 | void 107 | hagl_fill_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, color_t color); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif /* __cplusplus */ 112 | 113 | #endif /* _HAGL_RECTANGLE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/surface.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_SURFACE_H 36 | #define _HAGL_SURFACE_H 37 | 38 | #include "hagl/bitmap.h" 39 | #include "hagl/window.h" 40 | #include "hagl/color.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif /* __cplusplus */ 45 | 46 | typedef struct { 47 | int16_t width; 48 | int16_t height; 49 | uint8_t depth; 50 | hagl_window_t clip; 51 | void (*put_pixel)(void *self, int16_t x0, int16_t y0, color_t color); 52 | color_t (*get_pixel)(void *self, int16_t x0, int16_t y0); 53 | color_t (*color)(void *self, uint8_t r, uint8_t g, uint8_t b); 54 | void (*blit)(void *self, uint16_t x0, uint16_t y0, hagl_bitmap_t *src); 55 | void (*scale_blit)(void *self, uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, hagl_bitmap_t *src); 56 | void (*hline)(void *self, int16_t x0, int16_t y0, uint16_t width, color_t color); 57 | void (*vline)(void *self, int16_t x0, int16_t y0, uint16_t height, color_t color); 58 | } hagl_surface_t; 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif /* __cplusplus */ 63 | 64 | #endif /* _HAGL_SURFACE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/triangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_TRIANGLE_H 36 | #define _HAGL_TRIANGLE_H 37 | 38 | #include 39 | 40 | #include "hagl/color.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif /* __cplusplus */ 45 | 46 | /** 47 | * Draw a triangle 48 | * 49 | * Output will be clipped to the current clip window. Internally 50 | * uses hagl_draw_polygon() to draw the triangle. 51 | * 52 | * @param surface 53 | * @param x0 54 | * @param y0 55 | * @param x1 56 | * @param y1 57 | * @param x2 58 | * @param y3 59 | * @param color 60 | */ 61 | void 62 | hagl_draw_triangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, color_t color); 63 | 64 | /** 65 | * Draw a filled triangle 66 | * 67 | * Output will be clipped to the current clip window. Internally 68 | * uses hagl_fill_polygon() to draw the triangle. 69 | * 70 | * @param surface 71 | * @param x0 72 | * @param y0 73 | * @param x1 74 | * @param y1 75 | * @param x2 76 | * @param y3 77 | * @param color 78 | */ 79 | void 80 | hagl_fill_triangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, color_t color); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif /* __cplusplus */ 85 | 86 | #endif /* _HAGL_TRIANGLE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/vline.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_VLINE_H 36 | #define _HAGL_VLINE_H 37 | 38 | #include 39 | 40 | #include "hagl/color.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif /* __cplusplus */ 45 | 46 | /** 47 | * Draw a vertical line 48 | * 49 | * Output will be clipped to the current clip window. 50 | * 51 | * @param x0 52 | * @param y0 53 | * @param height 54 | * @param color 55 | */ 56 | void 57 | hagl_draw_vline(void const *surface, int16_t x0, int16_t y0, uint16_t height, color_t color); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif /* __cplusplus */ 62 | 63 | #endif /* _HAGL_VLINE_H */ -------------------------------------------------------------------------------- /components/hagl/include/hagl/window.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_WINDOW_H 36 | #define _HAGL_WINDOW_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif /* __cplusplus */ 41 | 42 | typedef struct { 43 | uint16_t x0; 44 | uint16_t y0; 45 | uint16_t x1; 46 | uint16_t y1; 47 | } hagl_window_t; 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif /* __cplusplus */ 52 | 53 | #endif /* _HAGL_WINDOW_H */ -------------------------------------------------------------------------------- /components/hagl/include/hsl.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HSL_H 36 | #define _HSL_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif /* __cplusplus */ 41 | 42 | typedef struct { 43 | double h; 44 | double s; 45 | double l; 46 | } hsl_t; 47 | 48 | #include "rgb888.h" 49 | 50 | rgb_t hsl_to_rgb888(hsl_t *hsl); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif /* __cplusplus */ 55 | 56 | #endif /* _HSL_H */ 57 | -------------------------------------------------------------------------------- /components/hagl/include/rgb332.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _HAGL_RGB332_H 36 | #define _HAGL_RGB332_H 37 | 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | static inline uint8_t rgb332(uint8_t r, uint8_t g, uint8_t b) 45 | { 46 | uint8_t r3 = ((r >> 4) & 0b00000110) | (r & 0b00000001); 47 | uint8_t g3 = ((g >> 4) & 0b00000110) | (g & 0b00000001); 48 | uint8_t b3 = ((b >> 4) & 0b00000110) | (b & 0b00000001); 49 | return (r3 << 5) | (g3 << 2) | (b3); 50 | } 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif /* __cplusplus */ 55 | 56 | #endif /* _HAGL_RGB332_H */ -------------------------------------------------------------------------------- /components/hagl/include/rgb565.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | #ifndef _RGB565_H 35 | #define _RGB565_H 36 | 37 | #include 38 | 39 | #include "rgb888.h" 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | 45 | uint16_t rgb565(uint8_t r, uint8_t g, uint8_t b); 46 | rgb_t rgb565_to_rgb888(uint16_t *input); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif /* __cplusplus */ 51 | 52 | #endif /* _RGB565_H */ 53 | -------------------------------------------------------------------------------- /components/hagl/include/rgb888.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #ifndef _RGB888_H 36 | #define _RGB888_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif /* __cplusplus */ 41 | 42 | typedef struct { 43 | uint8_t r; 44 | uint8_t g; 45 | uint8_t b; 46 | } rgb_t; 47 | 48 | #include "hsl.h" 49 | 50 | hsl_t rgb888_to_hsl(rgb_t *rgb); 51 | uint16_t rgb888_to_rgb565(rgb_t *input); 52 | 53 | static inline int min(int a, int b) { 54 | if (a > b) { 55 | return b; 56 | }; 57 | return a; 58 | } 59 | 60 | static inline int max(int a, int b) { 61 | if (a > b) { 62 | return a; 63 | } 64 | return b; 65 | } 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif /* __cplusplus */ 70 | 71 | #endif /* _RGB888_H */ 72 | -------------------------------------------------------------------------------- /components/hagl/include/tjpgd.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------/ 2 | / TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2019 3 | /----------------------------------------------------------------------------*/ 4 | #ifndef DEF_TJPGDEC 5 | #define DEF_TJPGDEC 6 | /*---------------------------------------------------------------------------*/ 7 | /* System Configurations */ 8 | 9 | #define JD_SZBUF 512 /* Size of stream input buffer */ 10 | #define JD_FORMAT 1 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */ 11 | #define JD_USE_SCALE 1 /* Use descaling feature for output */ 12 | #define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */ 13 | 14 | /*---------------------------------------------------------------------------*/ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if defined(_WIN32) /* Main development platform */ 21 | typedef unsigned char uint8_t; 22 | typedef unsigned short uint16_t; 23 | typedef short int16_t; 24 | typedef unsigned long uint32_t; 25 | typedef long int32_t; 26 | #else 27 | #include "stdint.h" 28 | #endif 29 | 30 | /* Error code */ 31 | typedef enum { 32 | JDR_OK = 0, /* 0: Succeeded */ 33 | JDR_INTR, /* 1: Interrupted by output function */ 34 | JDR_INP, /* 2: Device error or wrong termination of input stream */ 35 | JDR_MEM1, /* 3: Insufficient memory pool for the image */ 36 | JDR_MEM2, /* 4: Insufficient stream input buffer */ 37 | JDR_PAR, /* 5: Parameter error */ 38 | JDR_FMT1, /* 6: Data format error (may be damaged data) */ 39 | JDR_FMT2, /* 7: Right format but not supported */ 40 | JDR_FMT3 /* 8: Not supported JPEG standard */ 41 | } JRESULT; 42 | 43 | 44 | 45 | /* Rectangular structure */ 46 | typedef struct { 47 | uint16_t left, right, top, bottom; 48 | } JRECT; 49 | 50 | 51 | 52 | /* Decompressor object structure */ 53 | typedef struct JDEC JDEC; 54 | struct JDEC { 55 | uint16_t dctr; /* Number of bytes available in the input buffer */ 56 | uint8_t* dptr; /* Current data read ptr */ 57 | uint8_t* inbuf; /* Bit stream input buffer */ 58 | uint8_t dmsk; /* Current bit in the current read byte */ 59 | uint8_t scale; /* Output scaling ratio */ 60 | uint8_t msx, msy; /* MCU size in unit of block (width, height) */ 61 | uint8_t qtid[3]; /* Quantization table ID of each component */ 62 | int16_t dcv[3]; /* Previous DC element of each component */ 63 | uint16_t nrst; /* Restart inverval */ 64 | uint16_t width, height; /* Size of the input image (pixel) */ 65 | uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */ 66 | uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */ 67 | uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */ 68 | int32_t* qttbl[4]; /* Dequantizer tables [id] */ 69 | void* workbuf; /* Working buffer for IDCT and RGB output */ 70 | uint8_t* mcubuf; /* Working buffer for the MCU */ 71 | void* pool; /* Pointer to available memory pool */ 72 | uint16_t sz_pool; /* Size of momory pool (bytes available) */ 73 | uint16_t (*infunc)(JDEC*, uint8_t*, uint16_t);/* Pointer to jpeg stream input function */ 74 | void* device; /* Pointer to I/O device identifiler for the session */ 75 | }; 76 | 77 | 78 | 79 | /* TJpgDec API functions */ 80 | JRESULT jd_prepare (JDEC*, uint16_t(*)(JDEC*,uint8_t*,uint16_t), void*, uint16_t, void*); 81 | JRESULT jd_decomp (JDEC*, uint16_t(*)(JDEC*,void*,JRECT*), uint8_t); 82 | 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* _TJPGDEC */ 89 | -------------------------------------------------------------------------------- /components/hagl/src/fontx.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2012 ChaN 6 | Copyright (c) 2020-2022 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This file is part of the HAGL graphics library: 29 | https://github.com/tuupola/hagl 30 | 31 | 32 | Adapted from the blog post by ChaN: 33 | http://elm-chan.org/docs/dosv/fontx_e.html 34 | 35 | SPDX-License-Identifier: MIT 36 | 37 | */ 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #include "fontx.h" 44 | 45 | uint8_t fontx_meta(fontx_meta_t *meta, const uint8_t *font) { 46 | 47 | memcpy(meta->name, &font[FONTX_NAME], 8); 48 | meta->width = font[FONTX_WIDTH]; 49 | meta->height = font[FONTX_HEIGHT]; 50 | meta->type = font[FONTX_TYPE]; 51 | 52 | return 0; 53 | } 54 | 55 | 56 | uint8_t fontx_glyph(fontx_glyph_t *glyph, wchar_t code, const uint8_t* font) { 57 | uint32_t nc, bc, sb, eb; 58 | uint8_t status; 59 | const uint8_t *block_table; 60 | fontx_meta_t meta; 61 | 62 | status = fontx_meta(&meta, font); 63 | if (0 != status) { 64 | return status; 65 | } 66 | 67 | glyph->width = meta.width; 68 | glyph->height = meta.height; 69 | glyph->pitch = (meta.width + 7) / 8; 70 | glyph->size = glyph->pitch * meta.height; 71 | 72 | if (FONTX_TYPE_SBCS == meta.type) { 73 | if (code < 0x100) { 74 | glyph->buffer = &font[FONTX_GLYPH_DATA_START + code * glyph->size]; 75 | return FONTX_OK; 76 | } 77 | } else { 78 | block_table = &font[FONTX_BLOCK_TABLE_START]; 79 | nc = 0; 80 | bc = font[FONTX_BLOCK_TABLE_SIZE]; 81 | while (bc--) { 82 | /* Get range of the code block_table. */ 83 | sb = block_table[0] + block_table[1] * 0x100; 84 | eb = block_table[2] + block_table[3] * 0x100; 85 | 86 | /* Check if in the code block_table. */ 87 | if (code >= sb && code <= eb) { 88 | /* Number of codes from top of the block_table. */ 89 | nc += code - sb; 90 | glyph->buffer = &font[ 91 | FONTX_BLOCK_TABLE_START + 92 | 4 * font[FONTX_BLOCK_TABLE_SIZE] + 93 | nc * glyph->size 94 | ]; 95 | return FONTX_OK; 96 | } 97 | /* Number of codes in the previous block_tables. */ 98 | nc += eb - sb + 1; 99 | /* Next code block_table. */ 100 | block_table += 4; 101 | } 102 | } 103 | 104 | return FONTX_ERR_GLYPH_NOT_FOUND; 105 | } -------------------------------------------------------------------------------- /components/hagl/src/hagl.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "rgb332.h" 43 | #include "rgb565.h" 44 | #include "fontx.h" 45 | #include "hagl/bitmap.h" 46 | #include "hagl/clip.h" 47 | #include "hagl/window.h" 48 | 49 | #include "hagl.h" 50 | #include "hagl_hal.h" 51 | 52 | void hagl_clear(void *_surface) { 53 | hagl_surface_t *surface = _surface; 54 | 55 | uint16_t x0 = surface->clip.x0; 56 | uint16_t y0 = surface->clip.y0; 57 | uint16_t x1 = surface->clip.x1; 58 | uint16_t y1 = surface->clip.y1; 59 | 60 | hagl_set_clip_window(surface, 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT -1); 61 | hagl_fill_rectangle(surface, 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT -1, 0x00); 62 | hagl_set_clip_window(surface, x0, y0, x1, y1); 63 | } 64 | 65 | void hagl_clear_clip_window(hagl_surface_t *surface) { 66 | hagl_fill_rectangle( 67 | surface, 68 | surface->clip.x0, surface->clip.y0, surface->clip.x1, surface->clip.y1, 69 | 0x00 70 | ); 71 | } 72 | 73 | hagl_backend_t *hagl_init(void) { 74 | static hagl_backend_t backend; 75 | memset(&backend, 0, sizeof(hagl_backend_t)); 76 | 77 | hagl_hal_init(&backend); 78 | hagl_set_clip_window(&backend, 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1); 79 | return &backend; 80 | }; 81 | 82 | size_t hagl_flush(hagl_backend_t *backend) { 83 | if (backend->flush) { 84 | return backend->flush(backend); 85 | } 86 | return 0; 87 | }; 88 | 89 | void hagl_close(hagl_backend_t *backend) { 90 | if (backend->close) { 91 | backend->close(backend); 92 | } 93 | }; 94 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_blit.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | 37 | #include "hagl/color.h" 38 | #include "hagl/pixel.h" 39 | #include "hagl/bitmap.h" 40 | #include "hagl/surface.h" 41 | 42 | void 43 | hagl_blit(void const *_surface, int16_t x0, int16_t y0, hagl_bitmap_t *source) { 44 | const hagl_surface_t *surface = _surface; 45 | 46 | if (surface->blit) { 47 | /* Check if bitmap is inside clip windows bounds */ 48 | if ( 49 | (x0 < surface->clip.x0) || 50 | (y0 < surface->clip.y0) || 51 | (x0 + source->width > surface->clip.x1) || 52 | (y0 + source->height > surface->clip.y1) 53 | ) { 54 | /* Out of bounds, use local putpixel fallback. */ 55 | color_t color; 56 | color_t *ptr = (color_t *) source->buffer; 57 | 58 | for (uint16_t y = 0; y < source->height; y++) { 59 | for (uint16_t x = 0; x < source->width; x++) { 60 | color = *(ptr++); 61 | hagl_put_pixel(surface, x0 + x, y0 + y, color); 62 | } 63 | } 64 | } else { 65 | /* Inside of bounds, can use HAL provided blit. */ 66 | surface->blit(&surface, x0, y0, source); 67 | } 68 | } else { 69 | color_t color; 70 | color_t *ptr = (color_t *) source->buffer; 71 | 72 | for (uint16_t y = 0; y < source->height; y++) { 73 | for (uint16_t x = 0; x < source->width; x++) { 74 | color = *(ptr++); 75 | hagl_put_pixel(surface, x0 + x, y0 + y, color); 76 | } 77 | } 78 | } 79 | }; 80 | 81 | void 82 | hagl_scale_blit(void const *_surface, uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, hagl_bitmap_t *source) { 83 | const hagl_surface_t *surface = _surface; 84 | 85 | if (surface->scale_blit) { 86 | surface->scale_blit(&surface, x0, y0, w, h, source); 87 | } else { 88 | color_t color; 89 | color_t *ptr = (color_t *) source->buffer; 90 | uint32_t x_ratio = (uint32_t)((source->width << 16) / w); 91 | uint32_t y_ratio = (uint32_t)((source->height << 16) / h); 92 | 93 | for (uint16_t y = 0; y < h; y++) { 94 | for (uint16_t x = 0; x < w; x++) { 95 | uint16_t px = ((x * x_ratio) >> 16); 96 | uint16_t py = ((y * y_ratio) >> 16); 97 | color = ptr[(uint8_t)((py * source->width) + px)]; 98 | hagl_put_pixel(surface, x0 + x, y0 + y, color); 99 | } 100 | } 101 | } 102 | }; 103 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_char.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include "hagl/color.h" 36 | #include "hagl/bitmap.h" 37 | #include "hagl/blit.h" 38 | #include "hagl.h" 39 | #include "fontx.h" 40 | 41 | uint8_t 42 | hagl_get_glyph(void const *surface, wchar_t code, color_t color, hagl_bitmap_t *bitmap, const uint8_t *font) 43 | { 44 | uint8_t status, set; 45 | fontx_glyph_t glyph; 46 | 47 | status = fontx_glyph(&glyph, code, font); 48 | 49 | if (0 != status) { 50 | return status; 51 | } 52 | 53 | /* Initialise bitmap dimensions. */ 54 | bitmap->depth = DISPLAY_DEPTH, 55 | bitmap->width = glyph.width, 56 | bitmap->height = glyph.height, 57 | bitmap->pitch = bitmap->width * (bitmap->depth / 8); 58 | bitmap->size = bitmap->pitch * bitmap->height; 59 | 60 | color_t *ptr = (color_t *) bitmap->buffer; 61 | 62 | for (uint8_t y = 0; y < glyph.height; y++) { 63 | for (uint8_t x = 0; x < glyph.width; x++) { 64 | set = *(glyph.buffer) & (0x80 >> (x % 8)); 65 | if (set) { 66 | *(ptr++) = color; 67 | } else { 68 | *(ptr++) = 0x0000; 69 | } 70 | } 71 | glyph.buffer += glyph.pitch; 72 | } 73 | 74 | return 0; 75 | } 76 | 77 | uint8_t 78 | hagl_put_char(void const *surface, wchar_t code, int16_t x0, int16_t y0, color_t color, const uint8_t *font) 79 | { 80 | uint8_t set, status; 81 | color_t buffer[HAGL_CHAR_BUFFER_SIZE]; 82 | hagl_bitmap_t bitmap; 83 | fontx_glyph_t glyph; 84 | 85 | status = fontx_glyph(&glyph, code, font); 86 | 87 | if (0 != status) { 88 | return 0; 89 | } 90 | 91 | bitmap.width = glyph.width, 92 | bitmap.height = glyph.height, 93 | bitmap.depth = DISPLAY_DEPTH, 94 | 95 | bitmap_init(&bitmap, (uint8_t *)buffer); 96 | 97 | color_t *ptr = (color_t *) bitmap.buffer; 98 | 99 | for (uint8_t y = 0; y < glyph.height; y++) { 100 | for (uint8_t x = 0; x < glyph.width; x++) { 101 | set = *(glyph.buffer + x / 8) & (0x80 >> (x % 8)); 102 | if (set) { 103 | *(ptr++) = color; 104 | } else { 105 | *(ptr++) = 0x0000; 106 | } 107 | } 108 | glyph.buffer += glyph.pitch; 109 | } 110 | 111 | hagl_blit(surface, x0, y0, &bitmap); 112 | 113 | return bitmap.width; 114 | } 115 | 116 | /* 117 | * Write a string of text by calling hagl_put_char() repeadetly. CR and LF 118 | * continue from the next line. 119 | */ 120 | 121 | uint16_t 122 | hagl_put_text(void const *surface, const wchar_t *str, int16_t x0, int16_t y0, color_t color, const unsigned char *font) 123 | { 124 | wchar_t temp; 125 | uint8_t status; 126 | uint16_t original = x0; 127 | fontx_meta_t meta; 128 | 129 | status = fontx_meta(&meta, font); 130 | if (0 != status) { 131 | return 0; 132 | } 133 | 134 | do { 135 | temp = *str++; 136 | if (13 == temp || 10 == temp) { 137 | x0 = 0; 138 | y0 += meta.height; 139 | } else { 140 | x0 += hagl_put_char(surface, temp, x0, y0, color, font); 141 | } 142 | } while (*str != 0); 143 | 144 | return x0 - original; 145 | } 146 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_circle.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | 37 | #include "hagl/color.h" 38 | #include "hagl/pixel.h" 39 | #include "hagl/hline.h" 40 | 41 | void hagl_draw_circle(void const *surface, int16_t xc, int16_t yc, int16_t r, color_t color) { 42 | int16_t x = 0; 43 | int16_t y = r; 44 | int16_t d = 3 - 2 * r; 45 | 46 | hagl_put_pixel(surface, xc + x, yc + y, color); 47 | hagl_put_pixel(surface, xc - x, yc + y, color); 48 | hagl_put_pixel(surface, xc + x, yc - y, color); 49 | hagl_put_pixel(surface, xc - x, yc - y, color); 50 | hagl_put_pixel(surface, xc + y, yc + x, color); 51 | hagl_put_pixel(surface, xc - y, yc + x, color); 52 | hagl_put_pixel(surface, xc + y, yc - x, color); 53 | hagl_put_pixel(surface, xc - y, yc - x, color); 54 | 55 | while (y >= x) { 56 | x++; 57 | 58 | if (d > 0) { 59 | y--; 60 | d = d + 4 * (x - y) + 10; 61 | } else { 62 | d = d + 4 * x + 6; 63 | } 64 | 65 | hagl_put_pixel(surface, xc + x, yc + y, color); 66 | hagl_put_pixel(surface, xc - x, yc + y, color); 67 | hagl_put_pixel(surface, xc + x, yc - y, color); 68 | hagl_put_pixel(surface, xc - x, yc - y, color); 69 | hagl_put_pixel(surface, xc + y, yc + x, color); 70 | hagl_put_pixel(surface, xc - y, yc + x, color); 71 | hagl_put_pixel(surface, xc + y, yc - x, color); 72 | hagl_put_pixel(surface, xc - y, yc - x, color); 73 | } 74 | } 75 | 76 | void hagl_fill_circle(void const *surface, int16_t x0, int16_t y0, int16_t r, color_t color) { 77 | int16_t x = 0; 78 | int16_t y = r; 79 | int16_t d = 3 - 2 * r; 80 | 81 | while (y >= x) { 82 | hagl_draw_hline(surface, x0 - x, y0 + y, x * 2, color); 83 | hagl_draw_hline(surface, x0 - x, y0 - y, x * 2, color); 84 | hagl_draw_hline(surface, x0 - y, y0 + x, y * 2, color); 85 | hagl_draw_hline(surface, x0 - y, y0 - x, y * 2, color); 86 | x++; 87 | 88 | if (d > 0) { 89 | y--; 90 | d = d + 4 * (x - y) + 10; 91 | } else { 92 | d = d + 4 * x + 6; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_clip.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm 34 | 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | #include "hagl/surface.h" 41 | #include "hagl/window.h" 42 | 43 | static const uint8_t INSIDE = 0b0000; 44 | static const uint8_t LEFT = 0b0001; 45 | static const uint8_t RIGHT = 0b0010; 46 | static const uint8_t BOTTOM = 0b0100; 47 | static const uint8_t TOP = 0b1000; 48 | 49 | static 50 | uint8_t code(int16_t x0, int16_t y0, hagl_window_t window) 51 | { 52 | uint8_t code = INSIDE; 53 | 54 | if (x0 < window.x0) { 55 | code |= LEFT; 56 | } else if (x0 > window.x1) { 57 | code |= RIGHT; 58 | } if (y0 < window.y0) { 59 | code |= BOTTOM; 60 | } else if (y0 > window.y1) { 61 | code |= TOP; 62 | } 63 | 64 | return code; 65 | } 66 | 67 | bool 68 | hagl_clip_line(int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, hagl_window_t window) 69 | { 70 | uint8_t code0 = code(*x0, *y0, window); 71 | uint8_t code1 = code(*x1, *y1, window); 72 | 73 | bool accept = false; 74 | 75 | while (true) { 76 | if (!(code0 | code1)) { 77 | /* Both endpoints inside clipping window, trivial accept. */ 78 | accept = true; 79 | break; 80 | } else if (code0 & code1) { 81 | /* Both endpoints outside clipping window, trivial reject. */ 82 | break; 83 | } else { 84 | /* Part of line inside clipping window, nontrivial situation. */ 85 | 86 | int16_t x = 0; 87 | int16_t y = 0; 88 | uint8_t code3 = code0 ? code0 : code1; 89 | 90 | /* Find intersection point. */ 91 | /* slope = (y1 - y0) / (x1 - x0) */ 92 | /* x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax */ 93 | /* y = y0 + slope * (xm - x0), where xm is xmin or xmax */ 94 | if (code3 & TOP) { 95 | x = *x0 + (*x1 - *x0) * (window.y1 - *y0) / (*y1 - *y0); 96 | y = window.y1; 97 | } else if (code3 & BOTTOM) { 98 | x = *x0 + (*x1 - *x0) * (window.y0 - *y0) / (*y1 - *y0); 99 | y = window.y0; 100 | } else if (code3 & RIGHT) { 101 | y = *y0 + (*y1 - *y0) * (window.x1 - *x0) / (*x1 - *x0); 102 | x = window.x1; 103 | } else if (code3 & LEFT) { 104 | y = *y0 + (*y1 - *y0) * (window.x0 - *x0) / (*x1 - *x0); 105 | x = window.x0; 106 | } 107 | 108 | /* Replace the outside point with the intersection point. */ 109 | if (code3 == code0) { 110 | *x0 = x; 111 | *y0 = y; 112 | code0 = code(*x0, *y0, window); 113 | } else { 114 | *x1 = x; 115 | *y1 = y; 116 | code1 = code(*x1, *y1, window); 117 | } 118 | } 119 | } 120 | 121 | return accept; 122 | } 123 | 124 | void 125 | hagl_set_clip_window(void *_surface, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) 126 | { 127 | hagl_surface_t *surface = _surface; 128 | 129 | surface->clip.x0 = x0; 130 | surface->clip.y0 = y0; 131 | surface->clip.x1 = x1; 132 | surface->clip.y1 = y1; 133 | } 134 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_color.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | */ 33 | 34 | #include 35 | 36 | #include "hagl/surface.h" 37 | #include "rgb565.h" 38 | 39 | color_t 40 | hagl_color(void const *_surface, uint8_t r, uint8_t g, uint8_t b) 41 | { 42 | const hagl_surface_t *surface = _surface; 43 | 44 | if (surface->color) { 45 | return surface->color(&surface, r, g, b); 46 | } 47 | return rgb565(r, g, b); 48 | } 49 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_ellipse.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include "hagl/color.h" 36 | #include "hagl/pixel.h" 37 | #include "hagl/hline.h" 38 | 39 | void 40 | hagl_draw_ellipse(void const *surface, int16_t x0, int16_t y0, int16_t a, int16_t b, color_t color) { 41 | int16_t wx, wy; 42 | int32_t xa, ya; 43 | int32_t t; 44 | int32_t asq = a * a; 45 | int32_t bsq = b * b; 46 | 47 | hagl_put_pixel(surface, x0, y0 + b, color); 48 | hagl_put_pixel(surface, x0, y0 - b, color); 49 | 50 | wx = 0; 51 | wy = b; 52 | xa = 0; 53 | ya = asq * 2 * b; 54 | t = asq / 4 - asq * b; 55 | 56 | while (1) { 57 | t += xa + bsq; 58 | 59 | if (t >= 0) { 60 | ya -= asq * 2; 61 | t -= ya; 62 | wy--; 63 | } 64 | 65 | xa += bsq * 2; 66 | wx++; 67 | 68 | if (xa >= ya) { 69 | break; 70 | } 71 | 72 | hagl_put_pixel(surface, x0 + wx, y0 - wy, color); 73 | hagl_put_pixel(surface, x0 - wx, y0 - wy, color); 74 | hagl_put_pixel(surface, x0 + wx, y0 + wy, color); 75 | hagl_put_pixel(surface, x0 - wx, y0 + wy, color); 76 | } 77 | 78 | hagl_put_pixel(surface, x0 + a, y0, color); 79 | hagl_put_pixel(surface, x0 - a, y0, color); 80 | 81 | wx = a; 82 | wy = 0; 83 | xa = bsq * 2 * a; 84 | 85 | ya = 0; 86 | t = bsq / 4 - bsq * a; 87 | 88 | while (1) { 89 | t += ya + asq; 90 | 91 | if (t >= 0) { 92 | xa -= bsq * 2; 93 | t = t - xa; 94 | wx--; 95 | } 96 | 97 | ya += asq * 2; 98 | wy++; 99 | 100 | if (ya > xa) { 101 | break; 102 | } 103 | 104 | hagl_put_pixel(surface, x0 + wx, y0 - wy, color); 105 | hagl_put_pixel(surface, x0 - wx, y0 - wy, color); 106 | hagl_put_pixel(surface, x0 + wx, y0 + wy, color); 107 | hagl_put_pixel(surface, x0 - wx, y0 + wy, color); 108 | } 109 | } 110 | 111 | void 112 | hagl_fill_ellipse(void const *surface, int16_t x0, int16_t y0, int16_t a, int16_t b, color_t color) { 113 | int16_t wx, wy; 114 | int32_t xa, ya; 115 | int32_t t; 116 | int32_t asq = a * a; 117 | int32_t bsq = b * b; 118 | 119 | hagl_put_pixel(surface, x0, y0 + b, color); 120 | hagl_put_pixel(surface, x0, y0 - b, color); 121 | 122 | wx = 0; 123 | wy = b; 124 | xa = 0; 125 | ya = asq * 2 * b; 126 | t = asq / 4 - asq * b; 127 | 128 | while (1) { 129 | t += xa + bsq; 130 | 131 | if (t >= 0) { 132 | ya -= asq * 2; 133 | t -= ya; 134 | wy--; 135 | } 136 | 137 | xa += bsq * 2; 138 | wx++; 139 | 140 | if (xa >= ya) { 141 | break; 142 | } 143 | 144 | hagl_draw_hline(surface, x0 - wx, y0 - wy, wx * 2, color); 145 | hagl_draw_hline(surface, x0 - wx, y0 + wy, wx * 2, color); 146 | } 147 | 148 | hagl_draw_hline(surface, x0 - a, y0, a * 2, color); 149 | 150 | wx = a; 151 | wy = 0; 152 | xa = bsq * 2 * a; 153 | 154 | ya = 0; 155 | t = bsq / 4 - bsq * a; 156 | 157 | while (1) { 158 | t += ya + asq; 159 | 160 | if (t >= 0) { 161 | xa -= bsq * 2; 162 | t = t - xa; 163 | wx--; 164 | } 165 | 166 | ya += asq * 2; 167 | wy++; 168 | 169 | if (ya > xa) { 170 | break; 171 | } 172 | 173 | hagl_draw_hline(surface, x0 - wx, y0 - wy, wx * 2, color); 174 | hagl_draw_hline(surface, x0 - wx, y0 + wy, wx * 2, color); 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_hline.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include "hagl/color.h" 36 | #include "hagl/hline.h" 37 | #include "hagl/line.h" 38 | #include "hagl/surface.h" 39 | 40 | void 41 | hagl_draw_hline(void const *_surface, int16_t x0, int16_t y0, uint16_t w, color_t color) { 42 | const hagl_surface_t *surface = _surface; 43 | 44 | if (surface->hline) { 45 | int16_t width = w; 46 | 47 | /* x0 or y0 is over the edge, nothing to do. */ 48 | if ((x0 > surface->clip.x1) || (y0 > surface->clip.y1) || (y0 < surface->clip.y0)) { 49 | return; 50 | } 51 | 52 | /* x0 is left of clip window, ignore start part. */ 53 | if (x0 < surface->clip.x0) { 54 | width = width + x0; 55 | x0 = surface->clip.x0; 56 | } 57 | 58 | /* Everything outside clip window, nothing to do. */ 59 | if (width < 0) { 60 | return; 61 | } 62 | 63 | /* Cut anything going over right edge of clip window. */ 64 | if (((x0 + width) > surface->clip.x1)) { 65 | width = width - (x0 + width - surface->clip.x1); 66 | } 67 | 68 | surface->hline(&surface, x0, y0, width, color); 69 | } else { 70 | hagl_draw_line(surface, x0, y0, x0 + w, y0, color); 71 | } 72 | } -------------------------------------------------------------------------------- /components/hagl/src/hagl_image.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include "hagl/image.h" 39 | #include "hagl/surface.h" 40 | #include "hagl.h" 41 | #include "tjpgd.h" 42 | 43 | typedef struct { 44 | FILE *fp; 45 | int16_t x0; 46 | int16_t y0; 47 | const hagl_surface_t *surface; 48 | } tjpgd_iodev_t; 49 | 50 | static uint16_t tjpgd_data_reader(JDEC *decoder, uint8_t *buffer, uint16_t size) 51 | { 52 | tjpgd_iodev_t *device = (tjpgd_iodev_t *)decoder->device; 53 | 54 | if (buffer) { 55 | /* Read bytes from input stream. */ 56 | return (uint16_t)fread(buffer, 1, size, device->fp); 57 | } else { 58 | /* Skip bytes from input stream. */ 59 | return fseek(device->fp, size, SEEK_CUR) ? 0 : size; 60 | } 61 | } 62 | 63 | static uint16_t tjpgd_data_writer(JDEC* decoder, void* bitmap, JRECT* rectangle) 64 | { 65 | tjpgd_iodev_t *device = (tjpgd_iodev_t *)decoder->device; 66 | uint8_t width = (rectangle->right - rectangle->left) + 1; 67 | uint8_t height = (rectangle->bottom - rectangle->top) + 1; 68 | 69 | hagl_bitmap_t block = { 70 | .width = width, 71 | .height = height, 72 | .depth = DISPLAY_DEPTH, 73 | .pitch = width * (DISPLAY_DEPTH / 8), 74 | .size = width * (DISPLAY_DEPTH / 8) * height, 75 | .buffer = (uint8_t *)bitmap 76 | }; 77 | 78 | hagl_blit(device->surface, rectangle->left + device->x0, rectangle->top + device->y0, &block); 79 | 80 | return 1; 81 | } 82 | 83 | uint32_t hagl_load_image(void const *surface, int16_t x0, int16_t y0, const char *filename) 84 | { 85 | uint8_t work[3100]; 86 | JDEC decoder; 87 | JRESULT result; 88 | tjpgd_iodev_t device; 89 | 90 | device.x0 = x0; 91 | device.y0 = y0; 92 | device.fp = fopen(filename, "rb"); 93 | device.surface = surface; 94 | 95 | if (!device.fp) { 96 | return HAGL_ERR_FILE_IO; 97 | } 98 | result = jd_prepare(&decoder, tjpgd_data_reader, work, 3100, (void *)&device); 99 | if (result == JDR_OK) { 100 | result = jd_decomp(&decoder, tjpgd_data_writer, 0); 101 | if (JDR_OK != result) { 102 | fclose(device.fp); 103 | return HAGL_ERR_TJPGD + result; 104 | } 105 | } else { 106 | fclose(device.fp); 107 | return HAGL_ERR_TJPGD + result; 108 | } 109 | 110 | fclose(device.fp); 111 | return HAGL_OK; 112 | } 113 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_line.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | 37 | #include "hagl/color.h" 38 | #include "hagl/surface.h" 39 | #include "hagl/line.h" 40 | #include "hagl/clip.h" 41 | #include "hagl.h" 42 | 43 | void 44 | hagl_draw_line(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color) 45 | { 46 | const hagl_surface_t *surface = _surface; 47 | 48 | /* Clip coordinates to fit clip window. */ 49 | if (false == hagl_clip_line(&x0, &y0, &x1, &y1, surface->clip)) { 50 | return; 51 | } 52 | 53 | int16_t dx; 54 | int16_t sx; 55 | int16_t dy; 56 | int16_t sy; 57 | int16_t err; 58 | int16_t e2; 59 | 60 | dx = ABS(x1 - x0); 61 | sx = x0 < x1 ? 1 : -1; 62 | dy = ABS(y1 - y0); 63 | sy = y0 < y1 ? 1 : -1; 64 | err = (dx > dy ? dx : -dy) / 2; 65 | 66 | while (1) { 67 | hagl_put_pixel(surface, x0, y0, color); 68 | 69 | if (x0 == x1 && y0 == y1) { 70 | break; 71 | }; 72 | 73 | e2 = err + err; 74 | 75 | if (e2 > -dx) { 76 | err -= dy; 77 | x0 += sx; 78 | } 79 | 80 | if (e2 < dy) { 81 | err += dx; 82 | y0 += sy; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_pixel.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | 37 | #include "hagl/color.h" 38 | #include "hagl/surface.h" 39 | 40 | void 41 | hagl_put_pixel(void const *_surface, int16_t x0, int16_t y0, color_t color) 42 | { 43 | const hagl_surface_t *surface = _surface; 44 | 45 | /* x0 or y0 is before the edge, nothing to do. */ 46 | if ((x0 < surface->clip.x0) || (y0 < surface->clip.y0)) { 47 | return; 48 | } 49 | 50 | /* x0 or y0 is after the edge, nothing to do. */ 51 | if ((x0 > surface->clip.x1) || (y0 > surface->clip.y1)) { 52 | return; 53 | } 54 | 55 | /* If still in bounds set the pixel. */ 56 | surface->put_pixel(&surface, x0, y0, color); 57 | } 58 | 59 | color_t 60 | hagl_get_pixel(void const *_surface, int16_t x0, int16_t y0) 61 | { 62 | const hagl_surface_t *surface = _surface; 63 | /* x0 or y0 is before the edge, nothing to do. */ 64 | if ((x0 < surface->clip.x0) || (y0 < surface->clip.y0)) { 65 | return hagl_color(surface, 0, 0, 0); 66 | } 67 | 68 | /* x0 or y0 is after the edge, nothing to do. */ 69 | if ((x0 > surface->clip.x1) || (y0 > surface->clip.y1)) { 70 | return hagl_color(surface, 0, 0, 0); 71 | } 72 | 73 | if (surface->get_pixel) { 74 | return surface->get_pixel(&surface, x0, y0); 75 | } 76 | 77 | return hagl_color(surface, 0, 0, 0); 78 | } 79 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_polygon.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | 37 | #include "hagl/color.h" 38 | #include "hagl/hline.h" 39 | /* TODO: remove after getting DISPLAY_HEIGHT from surface */ 40 | #include "hagl.h" 41 | 42 | void 43 | hagl_draw_polygon(void const *surface, int16_t amount, int16_t *vertices, color_t color) { 44 | 45 | for(int16_t i = 0; i < amount - 1; i++) { 46 | hagl_draw_line( 47 | surface, 48 | vertices[(i << 1 ) + 0], 49 | vertices[(i << 1 ) + 1], 50 | vertices[(i << 1 ) + 2], 51 | vertices[(i << 1 ) + 3], 52 | color 53 | ); 54 | } 55 | hagl_draw_line( 56 | surface, 57 | vertices[0], 58 | vertices[1], 59 | vertices[(amount <<1 ) - 2], 60 | vertices[(amount <<1 ) - 1], 61 | color 62 | ); 63 | } 64 | 65 | /* Adapted from http://alienryderflex.com/polygon_fill/ */ 66 | void 67 | hagl_fill_polygon(void const *surface, int16_t amount, int16_t *vertices, color_t color) { 68 | uint16_t nodes[64]; 69 | int16_t y; 70 | 71 | float x0; 72 | float y0; 73 | float x1; 74 | float y1; 75 | 76 | int16_t miny = DISPLAY_HEIGHT; 77 | int16_t maxy = 0; 78 | 79 | for (uint8_t i = 0; i < amount; i++) { 80 | if (miny > vertices[(i << 1) + 1]) { 81 | miny = vertices[(i << 1) + 1]; 82 | } 83 | if (maxy < vertices[(i << 1) + 1]) { 84 | maxy = vertices[(i << 1) + 1]; 85 | } 86 | } 87 | 88 | /* Loop through the rows of the image. */ 89 | for (y = miny; y < maxy; y++) { 90 | 91 | /* Build a list of nodes. */ 92 | int16_t count = 0; 93 | int16_t j = amount - 1; 94 | 95 | for (int16_t i = 0; i < amount; i++) { 96 | x0 = vertices[(i << 1) + 0]; 97 | y0 = vertices[(i << 1) + 1]; 98 | x1 = vertices[(j << 1) + 0]; 99 | y1 = vertices[(j << 1) + 1]; 100 | 101 | if ( 102 | (y0 < (float)y && y1 >= (float)y) || 103 | (y1 < (float)y && y0 >= (float)y) 104 | ) { 105 | nodes[count] = (int16_t)(x0 + (y - y0) / (y1 - y0) * (x1 - x0)); 106 | count++; 107 | } 108 | j = i; 109 | } 110 | 111 | /* Sort the nodes, via a simple “Bubble” sort. */ 112 | int16_t i = 0; 113 | while (i < count - 1) { 114 | if (nodes[i] > nodes[i + 1]) { 115 | int16_t swap = nodes[i]; 116 | nodes[i] = nodes[i + 1]; 117 | nodes[i + 1] = swap; 118 | if (i) { 119 | i--; 120 | } 121 | } else { 122 | i++; 123 | } 124 | } 125 | 126 | /* Draw lines between nodes. */ 127 | for (int16_t i = 0; i < count; i += 2) { 128 | int16_t width = nodes[i + 1] - nodes[i]; 129 | hagl_draw_hline(surface, nodes[i], y, width, color); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /components/hagl/src/hagl_triangle.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | 37 | #include "hagl/color.h" 38 | #include "hagl/polygon.h" 39 | 40 | void hagl_draw_triangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, color_t color) { 41 | int16_t vertices[6] = {x0, y0, x1, y1, x2, y2}; 42 | hagl_draw_polygon(surface, 3, vertices, color); 43 | }; 44 | 45 | void hagl_fill_triangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, color_t color) { 46 | int16_t vertices[6] = {x0, y0, x1, y1, x2, y2}; 47 | hagl_fill_polygon(surface, 3, vertices, color); 48 | } -------------------------------------------------------------------------------- /components/hagl/src/hagl_vline.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include "hagl/vline.h" 36 | #include "hagl/line.h" 37 | #include "hagl/surface.h" 38 | #include "hagl/color.h" 39 | 40 | void 41 | hagl_draw_vline(void const *_surface, int16_t x0, int16_t y0, uint16_t h, color_t color) { 42 | const hagl_surface_t *surface = _surface; 43 | 44 | if (surface->vline) { 45 | int16_t height = h; 46 | 47 | /* x0 or y0 is over the edge, nothing to do. */ 48 | if ((x0 > surface->clip.x1) || (x0 < surface->clip.x0) || (y0 > surface->clip.y1)) { 49 | return; 50 | } 51 | 52 | /* y0 is top of clip window, ignore start part. */ 53 | if (y0 < surface->clip.y0) { 54 | height = height + y0; 55 | y0 = surface->clip.y0; 56 | } 57 | 58 | /* Everything outside clip window, nothing to do. */ 59 | if (height < 0) { 60 | return; 61 | } 62 | 63 | /* Cut anything going over right edge. */ 64 | if (((y0 + height) > surface->clip.y1)) { 65 | height = height - (y0 + height - surface->clip.y1); 66 | } 67 | 68 | surface->vline(&surface, x0, y0, height, color); 69 | } else { 70 | hagl_draw_line(surface, x0, y0, x0, y0 + h, color); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /components/hagl/src/hsl.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2004-2007, Lode Vandevenne 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -cut- 30 | 31 | This file is part of the HAGL graphics library: 32 | https://github.com/tuupola/hagl 33 | 34 | 35 | SPDX-License-Identifier: BSD-2-Clause 36 | 37 | */ 38 | 39 | #include 40 | 41 | #include "hsl.h" 42 | 43 | rgb_t hsl_to_rgb888(hsl_t *hsl) 44 | { 45 | rgb_t rgb; 46 | float r, g, b, h, s, l; 47 | float temp1, temp2, tempr, tempg, tempb; 48 | 49 | h = hsl->h / 256.0; 50 | s = hsl->s / 256.0; 51 | l = hsl->l / 256.0; 52 | 53 | /* Saturation 0 means shade of grey. */ 54 | if(s == 0) { 55 | r = g = b = l; 56 | } else { 57 | if (l < 0.5) { 58 | temp2 = l * (1 + s); 59 | } else { 60 | temp2 = (l + s) - (l * s); 61 | } 62 | temp1 = 2 * l - temp2; 63 | tempr = h + 1.0 / 3.0; 64 | if (tempr > 1) { 65 | tempr--; 66 | } 67 | tempg = h; 68 | tempb = h - 1.0 / 3.0; 69 | if (tempb < 0) { 70 | tempb++; 71 | } 72 | 73 | /* Red */ 74 | if (tempr < 1.0 / 6.0) { 75 | r = temp1 + (temp2 - temp1) * 6.0 * tempr; 76 | } else if (tempr < 0.5) { 77 | r = temp2; 78 | } else if (tempr < 2.0 / 3.0) { 79 | r = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempr) * 6.0; 80 | } else { r = temp1; } 81 | 82 | /* Green */ 83 | if (tempg < 1.0 / 6.0) { 84 | g = temp1 + (temp2 - temp1) * 6.0 * tempg; 85 | } else if (tempg < 0.5) { 86 | g = temp2; 87 | } else if (tempg < 2.0 / 3.0) { 88 | g = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempg) * 6.0; 89 | } else { 90 | g = temp1; 91 | } 92 | 93 | /* Blue */ 94 | if (tempb < 1.0 / 6.0) { 95 | b = temp1 + (temp2 - temp1) * 6.0 * tempb; 96 | } else if (tempb < 0.5) { 97 | b = temp2; 98 | } else if (tempb < 2.0 / 3.0) { 99 | b = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempb) * 6.0; 100 | } else { 101 | b = temp1; 102 | } 103 | } 104 | 105 | rgb.r = (uint8_t)(r * 255.0); 106 | rgb.g = (uint8_t)(g * 255.0); 107 | rgb.b = (uint8_t)(b * 255.0); 108 | 109 | return rgb; 110 | } 111 | -------------------------------------------------------------------------------- /components/hagl/src/rgb565.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the HAGL graphics library: 28 | https://github.com/tuupola/hagl 29 | 30 | 31 | SPDX-License-Identifier: MIT 32 | 33 | */ 34 | 35 | #include 36 | 37 | #include "rgb565.h" 38 | 39 | uint16_t rgb565(uint8_t r, uint8_t g, uint8_t b) 40 | { 41 | uint16_t rgb; 42 | 43 | rgb = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3); 44 | rgb = (((rgb) << 8) & 0xFF00) | (((rgb) >> 8) & 0xFF); 45 | 46 | return rgb; 47 | } 48 | 49 | rgb_t rgb565_to_rgb888(uint16_t *input) 50 | { 51 | rgb_t rgb; 52 | 53 | uint8_t r5 = (*input & 0xf800) >> 8; // 1111100000000000 54 | uint8_t g6 = (*input & 0x07e0) >> 3; // 0000011111100000 55 | uint8_t b5 = (*input & 0x001f) << 3; // 0000000000011111 56 | 57 | rgb.r = (r5 * 527 + 23) >> 6; 58 | rgb.g = (g6 * 259 + 33) >> 6; 59 | rgb.b = (b5 * 527 + 23) >> 6; 60 | 61 | return rgb; 62 | } -------------------------------------------------------------------------------- /components/hagl/src/rgb888.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2004-2007, Lode Vandevenne 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -cut- 30 | 31 | This file is part of the HAGL graphics library: 32 | https://github.com/tuupola/hagl 33 | 34 | 35 | SPDX-License-Identifier: BSD-2-Clause 36 | 37 | */ 38 | 39 | #include 40 | 41 | #include "rgb888.h" 42 | 43 | hsl_t rgb888_to_hsl(rgb_t *rgb) 44 | { 45 | hsl_t hsl; 46 | float r, g, b, h, s, l; 47 | r = rgb->r / 256.0; 48 | g = rgb->g / 256.0; 49 | b = rgb->b / 256.0; 50 | 51 | float maxColor = max(r, max(g, b)); 52 | float minColor = min(r, min(g, b)); 53 | 54 | /* R == G == B, so it's a shade of gray. */ 55 | if (minColor == maxColor) { 56 | h = 0.0; 57 | s = 0.0; 58 | l = r; 59 | } else { 60 | l = (minColor + maxColor) / 2; 61 | 62 | if (l < 0.5) { 63 | s = (maxColor - minColor) / (maxColor + minColor); 64 | } else { 65 | s = (maxColor - minColor) / (2.0 - maxColor - minColor); 66 | } 67 | 68 | if (r == maxColor) { 69 | h = (g - b) / (maxColor - minColor); 70 | } else if (g == maxColor) { 71 | h = 2.0 + (b - r) / (maxColor - minColor); 72 | } else { 73 | h = 4.0 + (r - g) / (maxColor - minColor); 74 | } 75 | 76 | h /= 6; /* To bring it to a number between 0 and 1. */ 77 | if (h < 0) { 78 | h++; 79 | } 80 | 81 | } 82 | 83 | hsl.h = (uint8_t)(h * 255.0); 84 | hsl.s = (uint8_t)(s * 255.0); 85 | hsl.l = (uint8_t)(l * 255.0); 86 | 87 | return hsl; 88 | } 89 | 90 | uint16_t rgb888_to_rgb565(rgb_t *input) { 91 | uint16_t r5 = (input->r * 249 + 1014 ) >> 11; 92 | uint16_t g6 = (input->g * 253 + 505) >> 10; 93 | uint16_t b5 = (input->b * 249 + 1014) >> 11; 94 | 95 | return (r5 | g6 | b5); 96 | } -------------------------------------------------------------------------------- /components/hagl_hal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register( 2 | SRCS "src/hagl_hal_single.c" "src/hagl_hal_double.c" "src/hagl_hal_triple.c" "src/mipi_display.c" 3 | INCLUDE_DIRS "./include" 4 | REQUIRES hagl 5 | ) -------------------------------------------------------------------------------- /components/hagl_hal/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2021 Mika Tuupola 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/hagl_hal/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS:=./src 2 | COMPONENT_ADD_INCLUDEDIRS:=./include -------------------------------------------------------------------------------- /components/hagl_hal/include/hagl_hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019-2021 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the MIPI DCS HAL for HAGL graphics library: 28 | https://github.com/tuupola/hagl_esp_mipi/ 29 | 30 | SPDX-License-Identifier: MIT 31 | 32 | */ 33 | 34 | #ifndef _HAGL_HAL_H 35 | #define _HAGL_HAL_H 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include 42 | #include 43 | 44 | #include "sdkconfig.h" 45 | 46 | #ifdef CONFIG_MIPI_DCS_PIXEL_FORMAT_24BIT_SELECTED 47 | typedef uint32_t color_t; 48 | #endif 49 | 50 | #ifdef CONFIG_MIPI_DCS_PIXEL_FORMAT_18BIT_SELECTED 51 | typedef uint32_t color_t; 52 | #endif 53 | 54 | #ifdef CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED 55 | /* Currently only this, ie. RGB565 is properly tested. */ 56 | typedef uint16_t color_t; 57 | #endif 58 | 59 | #ifdef CONFIG_MIPI_DCS_PIXEL_FORMAT_12BIT_SELECTED 60 | typedef uint16_t color_t; 61 | #endif 62 | 63 | #ifdef CONFIG_MIPI_DCS_PIXEL_FORMAT_8BIT_SELECTED 64 | typedef uint8_t color_t; 65 | #endif 66 | 67 | #ifdef CONFIG_MIPI_DCS_PIXEL_FORMAT_3BIT_SELECTED 68 | typedef uint8_t color_t; 69 | #endif 70 | 71 | 72 | #ifdef CONFIG_HAGL_HAL_USE_DOUBLE_BUFFERING 73 | #define HAGL_HAS_HAL_BACK_BUFFER 74 | #endif 75 | 76 | #ifdef CONFIG_HAGL_HAL_USE_TRIPLE_BUFFERING 77 | #define HAGL_HAS_HAL_BACK_BUFFER 78 | #endif 79 | 80 | #ifdef CONFIG_HAGL_HAL_NO_BUFFERING 81 | #undef HAGL_HAS_HAL_BACK_BUFFER 82 | #endif 83 | 84 | #define DISPLAY_WIDTH (CONFIG_MIPI_DISPLAY_WIDTH) 85 | #define DISPLAY_HEIGHT (CONFIG_MIPI_DISPLAY_HEIGHT) 86 | #define DISPLAY_DEPTH (CONFIG_MIPI_DISPLAY_DEPTH) 87 | #define MIPI_DISPLAY_WIDTH (CONFIG_MIPI_DISPLAY_WIDTH) 88 | #define MIPI_DISPLAY_HEIGHT (CONFIG_MIPI_DISPLAY_HEIGHT) 89 | #define MIPI_DISPLAY_DEPTH (CONFIG_MIPI_DISPLAY_DEPTH) 90 | 91 | /** 92 | * Initialize the HAL 93 | */ 94 | void hagl_hal_init(hagl_backend_t *backend); 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | #endif /* _HAGL_HAL_H */ -------------------------------------------------------------------------------- /components/hagl_hal/include/hagl_hal_color.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019-2022 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the Raspberry Pi Pico MIPI DCS backend for the HAGL 28 | graphics library: https://github.com/tuupola/hagl_pico_mipi 29 | 30 | SPDX-License-Identifier: MIT 31 | 32 | */ 33 | 34 | #ifndef _HAGL_PICO_HAL_COLOR_H 35 | #define _HAGL_PICO_HAL_COLOR_H 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include 42 | 43 | typedef uint16_t color_t; 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | #endif /* _HAGL_PICO_HAL_COLOR_H */ -------------------------------------------------------------------------------- /components/hagl_hal/include/mipi_display.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2017-2018 Espressif Systems (Shanghai) PTE LTD 6 | Copyright (c) 2019-2021 Mika Tuupola 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -cut- 27 | 28 | This code is based on Espressif provided SPI Master example which was 29 | released to Public Domain: https://goo.gl/ksC2Ln 30 | 31 | This file is part of the MIPI DCS Display Driver: 32 | https://github.com/tuupola/esp_mipi 33 | 34 | SPDX-License-Identifier: MIT 35 | 36 | */ 37 | 38 | #ifndef _MIPI_DISPLAY_H 39 | #define _MIPI_DISPLAY_H 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | #include 46 | #include 47 | 48 | #include "sdkconfig.h" 49 | #include "hagl_hal.h" 50 | 51 | // #define DISPLAY_WIDTH (CONFIG_MIPI_DISPLAY_WIDTH) 52 | // #define DISPLAY_HEIGHT (CONFIG_MIPI_DISPLAY_HEIGHT) 53 | // #define DISPLAY_DEPTH (CONFIG_MIPI_DISPLAY_DEPTH) 54 | 55 | #define SPI_MAX_TRANSFER_SIZE (DISPLAY_WIDTH * DISPLAY_HEIGHT * DISPLAY_DEPTH) 56 | 57 | #define MIPI_DISPLAY_ADDRESS_MODE ( \ 58 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y | \ 59 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X | \ 60 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY | \ 61 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X | \ 62 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y | \ 63 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR \ 64 | ) 65 | 66 | void mipi_display_init(spi_device_handle_t *spi); 67 | size_t mipi_display_write(spi_device_handle_t spi, uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, uint8_t *buffer); 68 | void mipi_display_ioctl(spi_device_handle_t spi, uint8_t command, uint8_t *data, size_t size); 69 | void mipi_display_close(spi_device_handle_t spi); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | #endif /* _MIPI_DISPLAY_H */ -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/m5stack-core2.defaults: -------------------------------------------------------------------------------- 1 | # This file contains working settings for M5Stack Core2 (320x240 ILI9342C) 2 | # 3 | # https://shop.m5stack.com/collections/stack-series 4 | # 5 | # To use it copy it to your project root before running menuconfig. 6 | # 7 | # $ cat components/hagl_hal/sdkconfig/m5stack-core2.defaults >> sdkconfig.defaults 8 | # $ idf.py menuconfig 9 | 10 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x00 11 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x00 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x00 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 15 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 16 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 17 | CONFIG_MIPI_DISPLAY_DEPTH=16 18 | CONFIG_MIPI_DISPLAY_WIDTH=320 19 | CONFIG_MIPI_DISPLAY_HEIGHT=240 20 | CONFIG_MIPI_DISPLAY_OFFSET_X=0 21 | CONFIG_MIPI_DISPLAY_OFFSET_Y=0 22 | CONFIG_MIPI_DISPLAY_INVERT=y 23 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR_SELECTED=y 24 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x08 25 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=40000000 26 | CONFIG_MIPI_DISPLAY_SPI_MODE=0 27 | CONFIG_MIPI_DISPLAY_SPI_HOST=0x01 28 | CONFIG_MIPI_DISPLAY_PIN_MISO=38 29 | CONFIG_MIPI_DISPLAY_PIN_MOSI=23 30 | CONFIG_MIPI_DISPLAY_PIN_CLK=18 31 | CONFIG_MIPI_DISPLAY_PIN_CS=5 32 | CONFIG_MIPI_DISPLAY_PIN_DC=15 33 | CONFIG_MIPI_DISPLAY_PIN_RST=-1 34 | CONFIG_MIPI_DISPLAY_PIN_BL=-1 35 | CONFIG_MIPI_DISPLAY_PWM_BL=-1 36 | -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/m5stack.defaults: -------------------------------------------------------------------------------- 1 | # This file contains working settings for M5Stack (320x240 ILI9341) 2 | # 3 | # https://www.banggood.com/custlink/DDvGgFKe52 4 | # http://s.click.aliexpress.com/e/qcq9nYW4 5 | # https://m5stack.com/collections/m5-core 6 | # 7 | # To use it copy it to your project root before running menuconfig. 8 | # 9 | # $ cp components/hagl_hal/sdkconfig/m5stack.defaults sdkconfig.defaults 10 | # $ make menuconfig 11 | 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x00 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x00 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x00 15 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 16 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 17 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 18 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 19 | CONFIG_MIPI_DISPLAY_WIDTH=320 20 | CONFIG_MIPI_DISPLAY_HEIGHT=240 21 | CONFIG_MIPI_DISPLAY_OFFSET_X=0 22 | CONFIG_MIPI_DISPLAY_OFFSET_Y=0 23 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR_SELECTED=y 24 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x08 25 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=40000000 26 | CONFIG_MIPI_DISPLAY_PIN_MISO=-1 27 | CONFIG_MIPI_DISPLAY_PIN_MOSI=23 28 | CONFIG_MIPI_DISPLAY_PIN_CLK=18 29 | CONFIG_MIPI_DISPLAY_PIN_CS=14 30 | CONFIG_MIPI_DISPLAY_PIN_DC=27 31 | CONFIG_MIPI_DISPLAY_PIN_RST=33 32 | CONFIG_MIPI_DISPLAY_PIN_BL=32 -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/m5stickc-landscape.defaults: -------------------------------------------------------------------------------- 1 | # This file contains working settings for M5StickC (160x80 ST7735S). 2 | # 3 | # https://www.banggood.com/custlink/GmDKBVm6t9 4 | # http://s.click.aliexpress.com/e/3DmuIePq 5 | # https://m5stack.com/collections/m5-core/products/stick-c 6 | # 7 | # To use it copy it to your project root before running menuconfig. 8 | # 9 | # $ cp components/hagl_hal/sdkconfig/m5stickc-landscape.defaults sdkconfig.defaults 10 | # $ make menuconfig 11 | 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X_SELECTED=y 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY_SELECTED=y 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x00 15 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x40 16 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x20 17 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 18 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 19 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 20 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 21 | CONFIG_MIPI_DISPLAY_WIDTH=160 22 | CONFIG_MIPI_DISPLAY_HEIGHT=80 23 | CONFIG_MIPI_DISPLAY_OFFSET_X=0 24 | CONFIG_MIPI_DISPLAY_OFFSET_Y=26 25 | CONFIG_MIPI_DISPLAY_INVERT=y 26 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR_SELECTED=y 27 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x08 28 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=20000000 29 | CONFIG_MIPI_DISPLAY_PIN_MISO=-1 30 | CONFIG_MIPI_DISPLAY_PIN_MOSI=15 31 | CONFIG_MIPI_DISPLAY_PIN_CLK=13 32 | CONFIG_MIPI_DISPLAY_PIN_CS=5 33 | CONFIG_MIPI_DISPLAY_PIN_DC=23 34 | CONFIG_MIPI_DISPLAY_PIN_RST=18 35 | CONFIG_MIPI_DISPLAY_PIN_BL=-1 36 | -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/m5stickc-plus-landscape.defaults: -------------------------------------------------------------------------------- 1 | # This file contains working settings for M5StickC Plus (240x135 ST7789V2). 2 | # 3 | # https://m5stack.com/collections/m5-core/products/m5stickc-plus-esp32-pico-mini-iot-development-kit 4 | # https://www.banggood.com/custlink/mKmh9lhfWr 5 | # 6 | # To use it copy it to your project root before running menuconfig. 7 | # 8 | # $ cp components/hagl_hal/sdkconfig/m5stickc-plus-landscape.defaults sdkconfig.defaults 9 | # $ make menuconfig 10 | 11 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X_SELECTED=y 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY_SELECTED=y 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x00 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x40 15 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x20 16 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 17 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 18 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 19 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 20 | CONFIG_MIPI_DISPLAY_DEPTH=16 21 | CONFIG_HAGL_HAL_USE_DOUBLE_BUFFERING=y 22 | CONFIG_MIPI_DISPLAY_WIDTH=240 23 | CONFIG_MIPI_DISPLAY_HEIGHT=135 24 | CONFIG_MIPI_DISPLAY_OFFSET_X=40 25 | CONFIG_MIPI_DISPLAY_OFFSET_Y=53 26 | CONFIG_MIPI_DISPLAY_INVERT=y 27 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x00 28 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=40000000 29 | CONFIG_MIPI_DISPLAY_PIN_MISO=-1 30 | CONFIG_MIPI_DISPLAY_PIN_MOSI=15 31 | CONFIG_MIPI_DISPLAY_PIN_CLK=13 32 | CONFIG_MIPI_DISPLAY_PIN_CS=5 33 | CONFIG_MIPI_DISPLAY_PIN_DC=23 34 | CONFIG_MIPI_DISPLAY_PIN_RST=18 35 | CONFIG_MIPI_DISPLAY_PIN_BL=-1 36 | CONFIG_MIPI_DISPLAY_PWM_BL=-1 37 | -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/m5stickc-plus-portrait.defaults: -------------------------------------------------------------------------------- 1 | # This file contains working settings for M5StickC Plus (135x240 ST7789V2). 2 | # 3 | # https://m5stack.com/collections/m5-core/products/m5stickc-plus-esp32-pico-mini-iot-development-kit 4 | # https://www.banggood.com/custlink/mKmh9lhfWr 5 | # 6 | # To use it copy it to your project root before running menuconfig. 7 | # 8 | # $ cp components/hagl_hal/sdkconfig/m5stickc-plus-portrait.defaults sdkconfig.defaults 9 | # $ make menuconfig 10 | 11 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y_SELECTED=y 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X_SELECTED=y 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x80 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x40 15 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x00 16 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 17 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 18 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 19 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 20 | CONFIG_MIPI_DISPLAY_DEPTH=16 21 | CONFIG_HAGL_HAL_USE_DOUBLE_BUFFERING=y 22 | CONFIG_MIPI_DISPLAY_WIDTH=135 23 | CONFIG_MIPI_DISPLAY_HEIGHT=240 24 | CONFIG_MIPI_DISPLAY_OFFSET_X=53 25 | CONFIG_MIPI_DISPLAY_OFFSET_Y=40 26 | CONFIG_MIPI_DISPLAY_INVERT=y 27 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x00 28 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=40000000 29 | CONFIG_MIPI_DISPLAY_PIN_MISO=-1 30 | CONFIG_MIPI_DISPLAY_PIN_MOSI=15 31 | CONFIG_MIPI_DISPLAY_PIN_CLK=13 32 | CONFIG_MIPI_DISPLAY_PIN_CS=5 33 | CONFIG_MIPI_DISPLAY_PIN_DC=23 34 | CONFIG_MIPI_DISPLAY_PIN_RST=18 35 | CONFIG_MIPI_DISPLAY_PIN_BL=-1 36 | CONFIG_MIPI_DISPLAY_PWM_BL=-1 37 | -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/m5stickc-portrait.defaults: -------------------------------------------------------------------------------- 1 | # This file contains working settings for M5StickC (80x160 ST7735S). 2 | # 3 | # https://www.banggood.com/custlink/GmDKBVm6t9 4 | # http://s.click.aliexpress.com/e/3DmuIePq 5 | # https://m5stack.com/collections/m5-core/products/stick-c 6 | # 7 | # To use it copy it to your project root before running menuconfig. 8 | # 9 | # $ cp components/hagl_hal/sdkconfig/m5stickc-portrait.defaults sdkconfig.defaults 10 | # $ make menuconfig 11 | 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y_SELECTED=y 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X_SELECTED=y 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x80 15 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x40 16 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x00 17 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 18 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 19 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 20 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 21 | CONFIG_MIPI_DISPLAY_WIDTH=80 22 | CONFIG_MIPI_DISPLAY_HEIGHT=160 23 | CONFIG_MIPI_DISPLAY_OFFSET_X=26 24 | CONFIG_MIPI_DISPLAY_OFFSET_Y=1 25 | CONFIG_MIPI_DISPLAY_INVERT=y 26 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR_SELECTED=y 27 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x08 28 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=20000000 29 | CONFIG_MIPI_DISPLAY_PIN_MISO=-1 30 | CONFIG_MIPI_DISPLAY_PIN_MOSI=15 31 | CONFIG_MIPI_DISPLAY_PIN_CLK=13 32 | CONFIG_MIPI_DISPLAY_PIN_CS=5 33 | CONFIG_MIPI_DISPLAY_PIN_DC=23 34 | CONFIG_MIPI_DISPLAY_PIN_RST=18 35 | CONFIG_MIPI_DISPLAY_PIN_BL=-1 36 | -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/ttgo-t-display.defaults: -------------------------------------------------------------------------------- 1 | # This file contains tested settings for TTGO T-Display (IPS ST7789V). 2 | # 3 | # https://www.banggood.com/custlink/vv33B5G0WM 4 | # http://s.click.aliexpress.com/e/erQs14Wc 5 | # https://github.com/Xinyuan-LilyGO/TTGO-T-Display 6 | # 7 | # To use it copy it to your project root before running menuconfig. 8 | # 9 | # $ cp components/hagl_hal/sdkconfig/ttgo-t-display.defaults sdkconfig.defaults 10 | # $ make menuconfig 11 | 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x00 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x00 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x00 15 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 16 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 17 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 18 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 19 | CONFIG_MIPI_DISPLAY_WIDTH=135 20 | CONFIG_MIPI_DISPLAY_HEIGHT=240 21 | CONFIG_MIPI_DISPLAY_OFFSET_X=52 22 | CONFIG_MIPI_DISPLAY_OFFSET_Y=40 23 | CONFIG_MIPI_DISPLAY_INVERT=y 24 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x00 25 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=40000000 26 | CONFIG_MIPI_DISPLAY_PIN_MISO=-1 27 | CONFIG_MIPI_DISPLAY_PIN_MOSI=19 28 | CONFIG_MIPI_DISPLAY_PIN_CLK=18 29 | CONFIG_MIPI_DISPLAY_PIN_CS=5 30 | CONFIG_MIPI_DISPLAY_PIN_DC=16 31 | CONFIG_MIPI_DISPLAY_PIN_RST=23 32 | CONFIG_MIPI_DISPLAY_PIN_BL=4 -------------------------------------------------------------------------------- /components/hagl_hal/sdkconfig/ttgo-t4-v13.defaults: -------------------------------------------------------------------------------- 1 | # This file contains tested settings for TTGO T4 V13 (240x320 ILI9341). 2 | # 3 | # http://s.click.aliexpress.com/e/t8kx4frS 4 | # https://github.com/Xinyuan-LilyGO/TTGO-T4-T10-TestCode 5 | # 6 | # To use it copy it to your project root before running menuconfig. 7 | # 8 | # $ cp components/hagl_hal/sdkconfig/ttgo-t4-v13.defaults sdkconfig.defaults 9 | # $ make menuconfig 10 | 11 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X_SELECTED=y 12 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_Y=0x00 13 | CONFIG_MIPI_DCS_ADDRESS_MODE_MIRROR_X=0x40 14 | CONFIG_MIPI_DCS_ADDRESS_MODE_SWAP_XY=0x00 15 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_X=0x00 16 | CONFIG_MIPI_DCS_ADDRESS_MODE_FLIP_Y=0x00 17 | CONFIG_MIPI_DCS_PIXEL_FORMAT_16BIT_SELECTED=y 18 | CONFIG_MIPI_DISPLAY_PIXEL_FORMAT=0x55 19 | CONFIG_MIPI_DISPLAY_WIDTH=240 20 | CONFIG_MIPI_DISPLAY_HEIGHT=320 21 | CONFIG_MIPI_DISPLAY_OFFSET_X=0 22 | CONFIG_MIPI_DISPLAY_OFFSET_Y=0 23 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR_SELECTED=y 24 | CONFIG_MIPI_DCS_ADDRESS_MODE_BGR=0x08 25 | CONFIG_MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=40000000 26 | CONFIG_MIPI_DISPLAY_PIN_MISO=12 27 | CONFIG_MIPI_DISPLAY_PIN_MOSI=23 28 | CONFIG_MIPI_DISPLAY_PIN_CLK=18 29 | CONFIG_MIPI_DISPLAY_PIN_CS=27 30 | CONFIG_MIPI_DISPLAY_PIN_DC=32 31 | CONFIG_MIPI_DISPLAY_PIN_RST=5 32 | CONFIG_MIPI_DISPLAY_PIN_BL=4 33 | -------------------------------------------------------------------------------- /components/hagl_hal/src/hagl_hal_single.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019-2021 Mika Tuupola 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -cut- 26 | 27 | This file is part of the MIPI DCS HAL for HAGL graphics library: 28 | https://github.com/tuupola/hagl_esp_mipi/ 29 | 30 | SPDX-License-Identifier: MIT 31 | 32 | -cut- 33 | 34 | This is the HAL used when buffering is disabled. I call this single buffered 35 | since I consider the GRAM of the display driver chip to be the framebuffer. 36 | 37 | Note that all coordinates are already clipped in the main library itself. 38 | HAL does not need to validate the coordinates, they can alway be assumed 39 | valid. 40 | 41 | */ 42 | 43 | #include "sdkconfig.h" 44 | #include "hagl_hal.h" 45 | 46 | #ifdef CONFIG_HAGL_HAL_NO_BUFFERING 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | 58 | static spi_device_handle_t spi; 59 | static const char *TAG = "hagl_esp_mipi"; 60 | 61 | static void 62 | put_pixel(void *self, int16_t x0, int16_t y0, color_t color) 63 | { 64 | mipi_display_write(spi, x0, y0, 1, 1, (uint8_t *) &color); 65 | } 66 | 67 | static void 68 | blit(void *self, int16_t x0, int16_t y0, hagl_bitmap_t *src) 69 | { 70 | mipi_display_write(spi, x0, y0, src->width, src->height, (uint8_t *) src->buffer); 71 | } 72 | 73 | static void 74 | hline(void *self, int16_t x0, int16_t y0, uint16_t width, color_t color) 75 | { 76 | static color_t line[DISPLAY_WIDTH]; 77 | color_t *ptr = line; 78 | uint16_t height = 1; 79 | 80 | for (uint16_t x = 0; x < width; x++) { 81 | *(ptr++) = color; 82 | } 83 | 84 | mipi_display_write(spi, x0, y0, width, height, (uint8_t *) line); 85 | } 86 | 87 | static void 88 | vline(void *self, int16_t x0, int16_t y0, uint16_t height, color_t color) 89 | { 90 | static color_t line[DISPLAY_HEIGHT]; 91 | color_t *ptr = line; 92 | uint16_t width = 1; 93 | 94 | for (uint16_t x = 0; x < height; x++) { 95 | *(ptr++) = color; 96 | } 97 | 98 | mipi_display_write(spi, x0, y0, width, height, (uint8_t *) line); 99 | } 100 | 101 | void 102 | hagl_hal_init(hagl_backend_t *backend) 103 | { 104 | mipi_display_init(&spi); 105 | 106 | backend->width = MIPI_DISPLAY_WIDTH; 107 | backend->height = MIPI_DISPLAY_HEIGHT; 108 | backend->depth = MIPI_DISPLAY_DEPTH; 109 | backend->put_pixel = put_pixel; 110 | // backend->get_pixel = get_pixel; 111 | backend->hline = hline; 112 | backend->vline = vline; 113 | backend->blit = blit; 114 | } 115 | #endif /* CONFIG_HAGL_HAL_NO_BUFFERING */ 116 | -------------------------------------------------------------------------------- /components/htool_api/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_api.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES htool_wifi htool_display esp_http_server htool_pn532_spi console htool_uart htool_ble 4 | ) 5 | -------------------------------------------------------------------------------- /components/htool_api/include/htool_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #ifndef HTOOL_API_H 23 | #define HTOOL_API_H 24 | 25 | #include 26 | #include "esp_wifi.h" 27 | 28 | #define HTOOL_OK 0 29 | #define HTOOL_BASE 100 30 | #define HTOOL_ERR_GENERAL (HTOOL_BASE + 1) 31 | #define HTOOL_ERR_TIMEOUT (HTOOL_BASE + 2) 32 | #define HTOOL_ERR_BUSY (HTOOL_BASE + 3) 33 | #define HTOOL_ERR_CONNECTION_FAILED (HTOOL_BASE + 4) 34 | #define HTOOL_ERR_WIFI_NOT_CONNECT (HTOOL_BASE + 5) ///< No WiFi network connected 35 | #define HTOOL_ERR_TOO_HIGH_NETWORK_ID (HTOOL_BASE + 6) ///< The network id is higher than the HTOOL_MAX_WIFI_NETWORK_SLOTS 36 | #define HTOOL_ERR_WIFI_HANDLING_TASK_ALREADY_RUNNING (HTOOL_BASE + 7) 37 | #define HTOOL_ERR_WIFI_HANDLING_TASK_START_FAILED (HTOOL_BASE + 8) 38 | #define HTOOL_ERR_POINTER_NULL (HTOOL_BASE + 9) 39 | #define HTOOL_ERR_MEMORY (HTOOL_BASE + 10) 40 | #define HTOOL_ERR_ID_NOT_FOUND (HTOOL_BASE + 11) 41 | #define HTOOL_ERR_MAX_SLOTS_CONFIGURED (HTOOL_BASE + 12) 42 | #define HTOOL_ERR_CLIENT (HTOOL_BASE + 13) 43 | #define HTOOL_ERR_NO_CONFIGURED_NETWORKS (HTOOL_BASE + 14) 44 | #define HTOOL_ERR_INVALID_CREDENTIALS (HTOOL_BASE + 15) 45 | #define HTOOL_ERR_ALREADY_INITIALIZED (HTOOL_BASE + 16) 46 | 47 | #define FREE_MEM(x) x ? free(x) : 0 48 | 49 | typedef struct { 50 | uint8_t beacon_index; 51 | } beacon_task_args_t; 52 | 53 | typedef struct { 54 | bool is_evil_twin; 55 | uint8_t ssid_index; 56 | uint8_t cp_index; 57 | } captive_portal_task_args_t; 58 | 59 | extern captive_portal_task_args_t captive_portal_task_args; 60 | 61 | extern beacon_task_args_t beacon_task_args; 62 | 63 | extern wifi_ap_record_t *global_scans; 64 | 65 | extern uint8_t global_scans_count; 66 | 67 | 68 | bool htool_api_ble_adv_running(); 69 | 70 | void htool_api_ble_stop_adv(); 71 | 72 | void htool_api_ble_start_adv(); 73 | 74 | void htool_api_set_ble_adv(uint8_t i); 75 | 76 | uint8_t htool_api_ble_deinit(); 77 | 78 | uint8_t htool_api_ble_init(); 79 | 80 | 81 | void htool_api_send_disassociate_frame(uint8_t index, bool is_station); 82 | 83 | void htool_api_send_deauth_frame(uint8_t index, bool is_station); 84 | 85 | 86 | bool htool_api_is_evil_twin_running(); 87 | 88 | void htool_api_start_evil_twin(uint8_t ssid_index, uint8_t cp_index); 89 | 90 | void htool_api_stop_evil_twin(); 91 | 92 | 93 | bool htool_api_is_captive_portal_running(); 94 | 95 | void htool_api_start_captive_portal(uint8_t cp_index); 96 | 97 | void htool_api_stop_captive_portal(); 98 | 99 | 100 | 101 | bool htool_api_is_beacon_spammer_running(); 102 | 103 | void htool_api_start_beacon_spammer(uint8_t beacon_index); 104 | 105 | void htool_api_stop_beacon_spammer(); 106 | 107 | 108 | bool htool_api_is_deauther_running(); 109 | 110 | void htool_api_start_deauther(); 111 | 112 | void htool_api_stop_deauther(); 113 | 114 | 115 | void htool_api_start_passive_scan(); 116 | 117 | void htool_api_start_active_scan(); 118 | 119 | bool htool_api_is_wifi_connected(); 120 | 121 | uint8_t htool_api_connect_to_wifi(); 122 | 123 | void htool_api_setup_station(uint8_t ssid_input, char *password); 124 | 125 | 126 | void htool_api_init(); 127 | 128 | void htool_api_start(); 129 | 130 | #endif 131 | 132 | -------------------------------------------------------------------------------- /components/htool_ble/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_ble.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES bt) 4 | -------------------------------------------------------------------------------- /components/htool_ble/include/htool_ble.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | 25 | #define HTOOL_BLE_OK 0 26 | #define HTOOL_BLE_ERR 1 27 | 28 | 29 | typedef enum { 30 | ADV_APPLE_RANDOM = 0, 31 | ADV_APPLE_AIRPODS = 1, 32 | ADV_APPLE_AIRPODS_PRO = 2, 33 | ADV_APPLE_AIRPODS_MAX = 3, 34 | ADV_APPLE_AIRPODS_GEN2 = 4, 35 | ADV_APPLE_AIRPODS_GEN3 = 5, 36 | ADV_APPLE_AIRPODS_PRO_GEN2 = 6, 37 | ADV_APPLE_POWER_BEATS = 7, 38 | ADV_APPLE_POWERBEATSPRO = 8, 39 | ADV_APPLE_BEATSSOLOPRO = 9, 40 | ADV_APPLE_BEATSSTUDIOBUDS = 10, 41 | ADV_APPLE_BEATSFLEX = 11, 42 | ADV_APPLE_BEATSX = 12, 43 | ADV_APPLE_BEATSSOLO3 = 13, 44 | ADV_APPLE_BEATSSTUDIO3 = 14, 45 | ADV_APPLE_BEATSSTUDIOPRO = 15, 46 | ADV_APPLE_BEATSFITPRO = 16, 47 | ADV_APPLE_BEATSSTUDIOBUDSPLUS = 17, 48 | ADV_APPLE_APPLETVSETUP = 18, 49 | ADV_APPLE_APPLETVPAIR = 19, 50 | ADV_APPLE_APPLETVNEWUSER = 20, 51 | ADV_APPLE_APPLETVAPPLEIDSETUP = 21, 52 | ADV_APPLE_APPLETVWIRELESSAUDIOSYNC = 22, 53 | ADV_APPLE_APPLETVHOMEKITSETUP = 23, 54 | ADV_APPLE_APPLETVKEYBOARD = 24, 55 | ADV_APPLE_APPLETVCONNECTINGTONETWORK = 25, 56 | ADV_APPLE_HOMEPODSETUP = 26, 57 | ADV_APPLE_SETUPNEWPHONE = 27, 58 | ADV_APPLE_TRANSFERNUMBER = 28, 59 | ADV_APPLE_TVCOLORBALANCE = 29, 60 | ADV_GOOGLE = 30, 61 | ADV_SAMSUNG_RANDOM = 31, 62 | ADV_SAMSUNG_WATCH4 = 32, 63 | ADV_SAMSUNG_FRENCH_WATCH4 = 33, 64 | ADV_SAMSUNG_FOX_WATCH5 = 34, 65 | ADV_SAMSUNG_WATCH5 = 35, 66 | ADV_SAMSUNG_WATCH5_PRO = 36, 67 | ADV_SAMSUNG_WATCH6 = 37, 68 | ADV_MICROSOFT = 38, 69 | ADV_RANDOM = 39, 70 | } adv_t; 71 | 72 | 73 | bool htool_ble_adv_running(); 74 | 75 | 76 | void htool_ble_stop_adv(); 77 | 78 | 79 | void htool_ble_start_adv(); 80 | 81 | 82 | void htool_ble_set_adv_data(adv_t index); 83 | 84 | 85 | uint8_t htool_ble_deinit(); 86 | 87 | 88 | uint8_t htool_ble_init(); 89 | -------------------------------------------------------------------------------- /components/htool_display/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_display.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES htool_api hagl esp_i2c_helper hagl_hal htool_wifi 4 | ) 5 | -------------------------------------------------------------------------------- /components/htool_display/include/htool_display.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #ifndef HTOOL_DISPLAY_H 23 | #define HTOOL_DISPLAY_H 24 | 25 | #include 26 | 27 | uint8_t menu_cnt = 0; 28 | 29 | bool scan_started = false; 30 | 31 | bool deauth_all = false; 32 | 33 | typedef enum { 34 | ST_MENU = 0, 35 | ST_SCAN, 36 | ST_DEAUTH, 37 | ST_BEACON, 38 | ST_C_PORTAL, 39 | ST_EVIL_TWIN, 40 | ST_BLE_SPOOF, 41 | ST_STARTUP, 42 | ST_BEACON_SUBMENU, 43 | ST_EVIL_TWIN_SUBMENU, 44 | ST_BLE_SPOOF_SUBMENU1, 45 | ST_BLE_SPOOF_SUBMENU2, 46 | } display_states; 47 | 48 | void htool_display_init(); 49 | 50 | void htool_display_start(); 51 | #endif 52 | -------------------------------------------------------------------------------- /components/htool_modbus/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_modbus.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES htool_modbus htool_system) 4 | -------------------------------------------------------------------------------- /components/htool_modbus/include/htool_modbus.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | 25 | #define MODBUS_OK (1) 26 | #define MODBUS_ERR (-1) 27 | 28 | int32_t modbus_tcp_client_read_str(int32_t sock, uint8_t unit_id, uint16_t start_reg, uint8_t num_regs, bool reversed, char **data, uint8_t *len); 29 | 30 | int32_t modbus_tcp_client_read(int32_t sock, uint8_t unit_id, uint16_t start_reg, uint8_t num_regs, bool big_endian, uint8_t *data); 31 | 32 | int32_t modbus_tcp_client_read_raw(int32_t sock, uint8_t unit_id, uint16_t start_reg, uint8_t num_regs, uint8_t *data); 33 | 34 | int32_t modbus_tcp_client_connect(const char *host, const uint16_t *port); 35 | 36 | int32_t modbus_tcp_client_disconnect(int32_t sock); 37 | -------------------------------------------------------------------------------- /components/htool_netman/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_netman.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES htool_api htool_wifi json esp_http_client htool_system htool_modbus) 4 | -------------------------------------------------------------------------------- /components/htool_netman/include/htool_netman.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | 25 | typedef void (*htool_netman_print_cb)(char *string); 26 | 27 | void htool_netman_do_nothing(); 28 | 29 | void htool_netman_handle_request(char *data, uint16_t len, char **response_json, uint32_t *resp_len, htool_netman_print_cb print_cb); -------------------------------------------------------------------------------- /components/htool_nvsm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_nvsm.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES nvs_flash) 4 | -------------------------------------------------------------------------------- /components/htool_nvsm/include/htool_nvsm.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | int nvsm_get_str(const char *key, char *out_value, size_t *length); 23 | 24 | 25 | int nvsm_set_str(const char *key, const char *value); 26 | 27 | 28 | int nvsm_get_u8(const char *key, uint8_t *out_value); 29 | 30 | 31 | int nvsm_set_u8(const char *key, uint8_t value); 32 | 33 | 34 | int nvsm_get_i8(const char *key, int8_t *out_value); 35 | 36 | 37 | int nvsm_set_i8(const char *key, int8_t value); 38 | 39 | 40 | __attribute__((unused)) __attribute__((unused)) int nvsm_get_i16(const char *key, int16_t *out_value); 41 | 42 | 43 | __attribute__((unused)) __attribute__((unused)) int nvsm_set_i16(const char *key, int16_t value); 44 | 45 | 46 | __attribute__((unused)) __attribute__((unused)) int nvsm_get_u16(const char *key, uint16_t *out_value); 47 | 48 | 49 | __attribute__((unused)) __attribute__((unused)) int nvsm_set_u16(const char *key, uint16_t value); 50 | 51 | 52 | int nvsm_get_i32(const char *key, int32_t *out_value); 53 | 54 | 55 | int nvsm_set_i32(const char *key, int32_t value); 56 | 57 | 58 | int nvsm_get_u32(const char *key, uint32_t *out_value); 59 | 60 | 61 | int nvsm_set_u32(const char *key, uint32_t value); 62 | 63 | 64 | __attribute__((unused)) __attribute__((unused)) int nvsm_get_i64(const char *key, int64_t *out_value); 65 | 66 | 67 | __attribute__((unused)) __attribute__((unused)) int nvsm_set_i64(const char *key, int64_t value); 68 | 69 | 70 | __attribute__((unused)) int nvsm_set_i64(const char *key, int64_t value); 71 | 72 | 73 | int nvsm_get_u64( const char *key, uint64_t *out_value); 74 | 75 | 76 | int nvsm_set_u64( const char *key, uint64_t value); 77 | 78 | 79 | int nvsm_set_float(const char *key, float value); 80 | 81 | 82 | int nvsm_get_float(const char *key, float *out_value); 83 | 84 | 85 | int nvsm_init(); 86 | 87 | 88 | int nvsm_deinit(); 89 | -------------------------------------------------------------------------------- /components/htool_pn532_spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_pn532_spi.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES htool_spi) 4 | -------------------------------------------------------------------------------- /components/htool_pn532_spi/include/htool_pn532_spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | typedef enum { 24 | PN532_NORMAL = 0x01, 25 | PN532_VIRTUAL_CARD = 0x02, 26 | PN532_WIRED_CARD = 0x03, 27 | PN532_DUAL_CARD = 0x04, 28 | } pn532_sam_config_type_t; 29 | 30 | typedef enum { 31 | PN532_BAUD_TYPE_ISO14443A = 0x00, 32 | PN532_BAUD_TYPE_FELICA_212 = 0x01, 33 | PN532_BAUD_TYPE_FELICA_424 = 0x02, 34 | PN532_BAUD_TYPE_ISO14443B = 0x03, 35 | PN532_BAUD_TYPE_JEWEL = 0x04, 36 | } pn532_baud_type_t; 37 | 38 | void htool_pn532_spi_start(); 39 | 40 | void htool_pn532_spi_init(uint8_t miso, uint8_t mosi, uint8_t sck, uint8_t ss); 41 | -------------------------------------------------------------------------------- /components/htool_spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_spi.c" 2 | INCLUDE_DIRS "include" 3 | ) 4 | -------------------------------------------------------------------------------- /components/htool_spi/htool_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include 23 | #include "driver/gpio.h" 24 | #include "freertos/FreeRTOS.h" 25 | #include "freertos/task.h" 26 | 27 | // region global pin definitions 28 | //display uses standard SPI pins 29 | uint8_t gpio_miso = 27; 30 | uint8_t gpio_mosi = 26; 31 | uint8_t gpio_sck = 25; 32 | uint8_t gpio_ss = 33; 33 | // endregion 34 | 35 | void htool_spi_master_ss(uint8_t level) { 36 | gpio_set_level(gpio_ss, level); 37 | } 38 | 39 | void htool_spi_master_write(uint8_t data) { 40 | gpio_set_level(gpio_sck, 1); 41 | vTaskDelay(pdMS_TO_TICKS(10)); 42 | //printf("write:\n"); //DEBUG 43 | for (uint8_t i = 0; i < 8; i++) { 44 | gpio_set_level(gpio_mosi, (data >> (i)) & 0x01); 45 | //printf("%d", (data >> i) & 0x01); //DEBUG 46 | gpio_set_level(gpio_sck, 0); 47 | gpio_set_level(gpio_sck, 1); 48 | } 49 | //printf("\n"); //DEBUG 50 | } 51 | 52 | uint8_t htool_spi_master_read() { 53 | int8_t byte = 0x00; 54 | 55 | for (uint8_t i = 0; i < 8; i++) { 56 | byte |= (gpio_get_level(gpio_miso) << i); // read bit 57 | gpio_set_level(gpio_sck, 0); // clock high 58 | gpio_set_level(gpio_sck, 1); // clock low 59 | } 60 | //printf("read: %d", byte); //DEBUG 61 | 62 | return byte; 63 | } 64 | 65 | void htool_spi_master_init(uint8_t miso, uint8_t mosi, uint8_t sck, uint8_t ss) { 66 | gpio_pad_select_gpio(miso); 67 | gpio_pad_select_gpio(mosi); 68 | gpio_pad_select_gpio(sck); 69 | gpio_pad_select_gpio(ss); 70 | 71 | gpio_set_direction(miso, GPIO_MODE_INPUT); 72 | gpio_set_direction(mosi, GPIO_MODE_OUTPUT); 73 | gpio_set_direction(sck, GPIO_MODE_OUTPUT); 74 | gpio_set_direction(ss, GPIO_MODE_OUTPUT); 75 | 76 | gpio_set_level(ss, 1); // Deselect 77 | 78 | gpio_miso = miso; 79 | gpio_mosi = mosi; 80 | gpio_sck = sck; 81 | gpio_ss = ss; 82 | } 83 | -------------------------------------------------------------------------------- /components/htool_spi/include/htool_spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | 25 | void htool_spi_master_ss(uint8_t level); 26 | 27 | void htool_spi_master_write(uint8_t data); 28 | 29 | uint8_t htool_spi_master_read(); 30 | 31 | void htool_spi_master_init(uint8_t miso, uint8_t mosi, uint8_t sck, uint8_t ss); 32 | -------------------------------------------------------------------------------- /components/htool_system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_system.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES htool_system) 4 | -------------------------------------------------------------------------------- /components/htool_system/include/htool_system.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | #include 25 | 26 | void htool_system_memcpy_reverse(void *d, void *s, uint8_t size); 27 | 28 | char *htool_system_escape_quotes(char *string, uint32_t size); 29 | 30 | void htool_system_hex_string_to_byte_array(char *hex_string, uint8_t **byte_array, uint32_t *array_size); 31 | 32 | uint32_t htool_system_extract_number_from_string(const char *str, uint16_t factor); 33 | -------------------------------------------------------------------------------- /components/htool_uart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_uart.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES console htool_nvsm htool_api htool_netman) 4 | -------------------------------------------------------------------------------- /components/htool_uart/include/htool_uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | void htool_uart_cli_start(); 23 | 24 | void htool_uart_cli_init(); -------------------------------------------------------------------------------- /components/htool_wifi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "htool_wifi.c" 2 | INCLUDE_DIRS "include" 3 | REQUIRES htool_api htool_display htool_nvsm 4 | EMBED_FILES captive_portals/google/google.html captive_portals/mcdonalds/mcdonalds.html captive_portals/router/router.html captive_portals/router/1_1.html captive_portals/router/a1.html captive_portals/router/asus.html captive_portals/router/att.html 5 | captive_portals/router/fritzbox.html captive_portals/router/globe.html captive_portals/router/huawei.html captive_portals/router/magenta.html captive_portals/router/netgear.html captive_portals/router/o2.html captive_portals/router/pldt.html 6 | captive_portals/router/swisscom.html captive_portals/router/tplink.html captive_portals/router/verizon.html captive_portals/router/vodafone.html captive_portals/facebook/facebook.html captive_portals/apple/apple.html 7 | ) 8 | set_source_files_properties(htool_wifi.c 9 | PROPERTIES COMPILE_FLAGS 10 | -Wl,-allow-multiple-definition 11 | ) 12 | -------------------------------------------------------------------------------- /components/htool_wifi/include/htool_wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #ifndef HTOOL_WIFI_H 23 | #define HTOOL_WIFI_H 24 | 25 | #include "freertos/FreeRTOS.h" 26 | #include "freertos/event_groups.h" 27 | #include "freertos/task.h" 28 | #include 29 | #include 30 | #include 31 | #include "esp_event.h" 32 | #include 33 | #include "esp_wifi.h" 34 | #include "esp_log.h" 35 | 36 | 37 | typedef struct htool_wifi_client { 38 | bool connection_in_progress; ///< Provides information if a connection is currently in progress (true) or not (false). 39 | bool scan_in_progress; ///< Provides information if a scan is currently in progress (true) or not (false). 40 | bool wifi_station_active; ///< Provides information whether an WIFI Station is connected (true) or not connected (false). 41 | bool wifi_connected; 42 | bool wifi_handler_active; ///< Is the wifi handler currently running (true) or not running (false). 43 | esp_netif_t *esp_netif; ///< Initialized networking interface. 44 | EventGroupHandle_t status_bits; ///< Event group for BIT management. 45 | char hostname[30]; 46 | } htool_wifi_client_t; 47 | 48 | 49 | void htool_wifi_reset_creds(); 50 | 51 | char *htool_wifi_get_pw_cred(); 52 | 53 | char *htool_wifi_get_user_cred(); 54 | 55 | uint32_t htool_wifi_get_pw_cred_len(); 56 | 57 | uint32_t htool_wifi_get_user_cred_len(); 58 | 59 | void htool_wifi_captive_portal_stop(); 60 | 61 | void htool_wifi_captive_portal_start(); 62 | 63 | void htool_wifi_send_deauth_frame(uint8_t ssid_index, bool is_station); 64 | 65 | void htool_wifi_send_disassociate_frame(uint8_t ssid_index, bool is_station); 66 | 67 | bool htool_wifi_is_wifi_connected(); 68 | 69 | uint8_t htool_wifi_connect(); 70 | 71 | void htool_wifi_disconnect(); 72 | 73 | void htool_wifi_setup_station(uint8_t ssid_index, char* password); 74 | 75 | void htool_wifi_start_active_scan(); 76 | 77 | void htool_wifi_start_passive_scan(); 78 | 79 | esp_netif_t *htool_wifi_get_current_netif(); 80 | 81 | void htool_wifi_deinit(); 82 | 83 | int htool_wifi_init(); 84 | 85 | void htool_wifi_start(); 86 | 87 | void htool_wifi_start_beacon_spammer(); 88 | 89 | void htool_wifi_start_deauth(); 90 | 91 | void htool_set_wifi_sta_config(); 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "hackingtool.c" 2 | ) 3 | target_link_libraries(${COMPONENT_LIB} -Wl,-zmuldefs) 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /main/hackingtool.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 kl0ibi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include "sdkconfig.h" 23 | #include 24 | #include "esp_event.h" 25 | #include "esp_partition.h" 26 | #include "htool_api.h" 27 | #include "htool_netman.h" 28 | 29 | 30 | 31 | 32 | static void initialize_esp_modules() { 33 | ESP_ERROR_CHECK(esp_event_loop_create_default()); 34 | ESP_ERROR_CHECK(esp_netif_init()); 35 | } 36 | 37 | void app_main(void) { 38 | printf("Start HackingTool\r\n"); 39 | initialize_esp_modules(); 40 | 41 | htool_netman_do_nothing(); // fix linker error 42 | 43 | htool_api_init(); 44 | 45 | htool_api_start(); 46 | 47 | printf("HackingTool Startup completed\r\n"); 48 | } 49 | -------------------------------------------------------------------------------- /partitions.csv: -------------------------------------------------------------------------------- 1 | # Espressif ESP32 Partition Table 2 | # Name, Type, SubType, Offset, Size, Flags 3 | nvs, data, nvs, 0x10000, 0x10000, 4 | factory, app, factory, 0x20000, 3M 5 | -------------------------------------------------------------------------------- /precompiled_files/bootloader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kl0ibi/esp32_hackingtool/c6122463bf8d74986d4a199be40c573273632723/precompiled_files/bootloader.bin -------------------------------------------------------------------------------- /precompiled_files/hackingtool.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kl0ibi/esp32_hackingtool/c6122463bf8d74986d4a199be40c573273632723/precompiled_files/hackingtool.bin -------------------------------------------------------------------------------- /precompiled_files/partition-table.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kl0ibi/esp32_hackingtool/c6122463bf8d74986d4a199be40c573273632723/precompiled_files/partition-table.bin --------------------------------------------------------------------------------