├── .cproject
├── .gitignore
├── .mxproject
├── .project
├── .settings
├── com.atollic.truestudio.debug.hardware_device.prefs
├── language.settings.xml
└── org.eclipse.cdt.managedbuilder.core.prefs
├── Drivers
├── CMSIS
│ ├── Device
│ │ └── ST
│ │ │ └── STM32F4xx
│ │ │ └── Include
│ │ │ ├── stm32f407xx.h
│ │ │ ├── stm32f4xx.h
│ │ │ └── system_stm32f4xx.h
│ └── Include
│ │ ├── arm_common_tables.h
│ │ ├── arm_const_structs.h
│ │ ├── arm_math.h
│ │ ├── cmsis_armcc.h
│ │ ├── cmsis_armcc_V6.h
│ │ ├── cmsis_gcc.h
│ │ ├── core_cm0.h
│ │ ├── core_cm0plus.h
│ │ ├── core_cm3.h
│ │ ├── core_cm4.h
│ │ ├── core_cm7.h
│ │ ├── core_cmFunc.h
│ │ ├── core_cmInstr.h
│ │ ├── core_cmSimd.h
│ │ ├── core_sc000.h
│ │ └── core_sc300.h
└── STM32F4xx_HAL_Driver
│ ├── Inc
│ ├── Legacy
│ │ └── stm32_hal_legacy.h
│ ├── stm32f4xx_hal.h
│ ├── stm32f4xx_hal_cortex.h
│ ├── stm32f4xx_hal_def.h
│ ├── stm32f4xx_hal_dma.h
│ ├── stm32f4xx_hal_dma_ex.h
│ ├── stm32f4xx_hal_flash.h
│ ├── stm32f4xx_hal_flash_ex.h
│ ├── stm32f4xx_hal_flash_ramfunc.h
│ ├── stm32f4xx_hal_gpio.h
│ ├── stm32f4xx_hal_gpio_ex.h
│ ├── stm32f4xx_hal_i2c.h
│ ├── stm32f4xx_hal_i2c_ex.h
│ ├── stm32f4xx_hal_pwr.h
│ ├── stm32f4xx_hal_pwr_ex.h
│ ├── stm32f4xx_hal_rcc.h
│ ├── stm32f4xx_hal_rcc_ex.h
│ ├── stm32f4xx_hal_spi.h
│ ├── stm32f4xx_hal_tim.h
│ └── stm32f4xx_hal_tim_ex.h
│ └── Src
│ ├── stm32f4xx_hal.c
│ ├── stm32f4xx_hal_cortex.c
│ ├── stm32f4xx_hal_dma.c
│ ├── stm32f4xx_hal_dma_ex.c
│ ├── stm32f4xx_hal_flash.c
│ ├── stm32f4xx_hal_flash_ex.c
│ ├── stm32f4xx_hal_flash_ramfunc.c
│ ├── stm32f4xx_hal_gpio.c
│ ├── stm32f4xx_hal_i2c.c
│ ├── stm32f4xx_hal_i2c_ex.c
│ ├── stm32f4xx_hal_pwr.c
│ ├── stm32f4xx_hal_pwr_ex.c
│ ├── stm32f4xx_hal_rcc.c
│ ├── stm32f4xx_hal_rcc_ex.c
│ ├── stm32f4xx_hal_spi.c
│ ├── stm32f4xx_hal_tim.c
│ └── stm32f4xx_hal_tim_ex.c
├── Inc
├── main.h
├── stm32f4xx_hal_conf.h
└── stm32f4xx_it.h
├── README.md
├── STM32F407VG_FLASH.ld
├── STM32F4_HAL_U8G2_OLED.elf.launch
├── STM32F4_HAL_U8G2_OLED.ioc
├── Src
├── main.c
├── stm32f4xx_hal_msp.c
├── stm32f4xx_it.c
├── system_stm32f4xx.c
├── u8g2
│ ├── u8g2.h
│ ├── u8g2_bitmap.c
│ ├── u8g2_box.c
│ ├── u8g2_buffer.c
│ ├── u8g2_circle.c
│ ├── u8g2_cleardisplay.c
│ ├── u8g2_d_memory.c
│ ├── u8g2_d_setup.c
│ ├── u8g2_font.c
│ ├── u8g2_fonts.c
│ ├── u8g2_hvline.c
│ ├── u8g2_input_value.c
│ ├── u8g2_intersection.c
│ ├── u8g2_kerning.c
│ ├── u8g2_line.c
│ ├── u8g2_ll_hvline.c
│ ├── u8g2_message.c
│ ├── u8g2_polygon.c
│ ├── u8g2_selection_list.c
│ ├── u8g2_setup.c
│ ├── u8log.c
│ ├── u8log_u8g2.c
│ ├── u8log_u8x8.c
│ ├── u8x8.h
│ ├── u8x8_8x8.c
│ ├── u8x8_byte.c
│ ├── u8x8_cad.c
│ ├── u8x8_d_a2printer.c
│ ├── u8x8_d_il3820_296x128.c
│ ├── u8x8_d_ist3020.c
│ ├── u8x8_d_ks0108.c
│ ├── u8x8_d_lc7981.c
│ ├── u8x8_d_ld7032_60x32.c
│ ├── u8x8_d_ls013b7dh03.c
│ ├── u8x8_d_max7219.c
│ ├── u8x8_d_pcd8544_84x48.c
│ ├── u8x8_d_pcf8812.c
│ ├── u8x8_d_pcf8814_hx1230.c
│ ├── u8x8_d_sbn1661.c
│ ├── u8x8_d_sed1330.c
│ ├── u8x8_d_sh1106_64x32.c
│ ├── u8x8_d_sh1106_72x40.c
│ ├── u8x8_d_sh1107.c
│ ├── u8x8_d_sh1108.c
│ ├── u8x8_d_sh1122.c
│ ├── u8x8_d_ssd1305.c
│ ├── u8x8_d_ssd1306_128x32.c
│ ├── u8x8_d_ssd1306_128x64_noname.c
│ ├── u8x8_d_ssd1306_48x64.c
│ ├── u8x8_d_ssd1306_64x32.c
│ ├── u8x8_d_ssd1306_64x48.c
│ ├── u8x8_d_ssd1306_96x16.c
│ ├── u8x8_d_ssd1309.c
│ ├── u8x8_d_ssd1317.c
│ ├── u8x8_d_ssd1318.c
│ ├── u8x8_d_ssd1322.c
│ ├── u8x8_d_ssd1325.c
│ ├── u8x8_d_ssd1326.c
│ ├── u8x8_d_ssd1327.c
│ ├── u8x8_d_ssd1329.c
│ ├── u8x8_d_ssd1606_172x72.c
│ ├── u8x8_d_ssd1607_200x200.c
│ ├── u8x8_d_st75256.c
│ ├── u8x8_d_st7565.c
│ ├── u8x8_d_st7567.c
│ ├── u8x8_d_st7586s_erc240160.c
│ ├── u8x8_d_st7586s_s028hn118a.c
│ ├── u8x8_d_st7588.c
│ ├── u8x8_d_st7920.c
│ ├── u8x8_d_stdio.c
│ ├── u8x8_d_t6963.c
│ ├── u8x8_d_uc1601.c
│ ├── u8x8_d_uc1604.c
│ ├── u8x8_d_uc1608.c
│ ├── u8x8_d_uc1610.c
│ ├── u8x8_d_uc1611.c
│ ├── u8x8_d_uc1617.c
│ ├── u8x8_d_uc1638.c
│ ├── u8x8_d_uc1701_dogs102.c
│ ├── u8x8_d_uc1701_mini12864.c
│ ├── u8x8_debounce.c
│ ├── u8x8_display.c
│ ├── u8x8_fonts.c
│ ├── u8x8_gpio.c
│ ├── u8x8_input_value.c
│ ├── u8x8_message.c
│ ├── u8x8_selection_list.c
│ ├── u8x8_setup.c
│ ├── u8x8_string.c
│ ├── u8x8_u16toa.c
│ └── u8x8_u8toa.c
└── u8g2_stm32f4.c
├── startup
└── startup_stm32f407xx.s
└── u8g2.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | /Debug/
2 |
--------------------------------------------------------------------------------
/.mxproject:
--------------------------------------------------------------------------------
1 | [PreviousGenFiles]
2 | HeaderPath=F:/Workspace/GitHub/STM32F4_HAL_EXAMPLES/STM32F4_HAL_U8G2_OLED/Inc
3 | HeaderFiles=stm32f4xx_it.h;stm32f4xx_hal_conf.h;main.h;
4 | SourcePath=F:/Workspace/GitHub/STM32F4_HAL_EXAMPLES/STM32F4_HAL_U8G2_OLED/Src
5 | SourceFiles=stm32f4xx_it.c;stm32f4xx_hal_msp.c;main.c;
6 |
7 | [PreviousLibFiles]
8 | LibFiles=Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/arm_common_tables.h;Drivers/CMSIS/Include/arm_const_structs.h;Drivers/CMSIS/Include/arm_math.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armcc_V6.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cmFunc.h;Drivers/CMSIS/Include/core_cmInstr.h;Drivers/CMSIS/Include/core_cmSimd.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_sc300.h;
9 |
10 | [PreviousUsedTStudioFiles]
11 | SourceFiles=..\Src\main.c;..\Src\stm32f4xx_it.c;..\Src\stm32f4xx_hal_msp.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;../\Src/system_stm32f4xx.c;../Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;null;
12 | HeaderPath=..\Drivers\STM32F4xx_HAL_Driver\Inc;..\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32F4xx\Include;..\Drivers\CMSIS\Include;..\Inc;
13 | CDefines=__weak:__attribute__((weak));__packed:__attribute__((__packed__));
14 |
15 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | STM32F4_HAL_U8G2_OLED
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 | ?children?
14 | ?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\||
15 |
16 |
17 | ?name?
18 |
19 |
20 |
21 | org.eclipse.cdt.make.core.append_environment
22 | true
23 |
24 |
25 | org.eclipse.cdt.make.core.buildArguments
26 |
27 |
28 |
29 | org.eclipse.cdt.make.core.buildCommand
30 | make
31 |
32 |
33 | org.eclipse.cdt.make.core.buildLocation
34 | ${workspace_loc:/STM32100B-EVAL/Debug}
35 |
36 |
37 | org.eclipse.cdt.make.core.contents
38 | org.eclipse.cdt.make.core.activeConfigSettings
39 |
40 |
41 | org.eclipse.cdt.make.core.enableAutoBuild
42 | false
43 |
44 |
45 | org.eclipse.cdt.make.core.enableCleanBuild
46 | true
47 |
48 |
49 | org.eclipse.cdt.make.core.enableFullBuild
50 | true
51 |
52 |
53 | org.eclipse.cdt.make.core.stopOnError
54 | true
55 |
56 |
57 | org.eclipse.cdt.make.core.useDefaultBuildCmd
58 | true
59 |
60 |
61 |
62 |
63 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
64 |
65 |
66 |
67 |
68 |
69 | org.eclipse.cdt.core.cnature
70 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
71 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/.settings/com.atollic.truestudio.debug.hardware_device.prefs:
--------------------------------------------------------------------------------
1 | BOARD=None
2 | CODE_LOCATION=FLASH
3 | ENDIAN=Little-endian
4 | MCU=STM32F407VG
5 | MCU_VENDOR=STMicroelectronics
6 | MODEL=Lite
7 | PROBE=ST-LINK
8 | PROJECT_FORMAT_VERSION=2
9 | TARGET=ARM\u00AE
10 | VERSION=4.1.0
11 | eclipse.preferences.version=1
12 |
--------------------------------------------------------------------------------
/.settings/language.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.cdt.managedbuilder.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.1518366166/CPATH/delimiter=;
3 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.1518366166/CPATH/operation=remove
4 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.1518366166/C_INCLUDE_PATH/delimiter=;
5 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.1518366166/C_INCLUDE_PATH/operation=remove
6 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.1518366166/append=true
7 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.1518366166/appendContributed=true
8 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.1518366166/LIBRARY_PATH/delimiter=;
9 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.1518366166/LIBRARY_PATH/operation=remove
10 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.1518366166/append=true
11 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.1518366166/appendContributed=true
12 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eziya/STM32_HAL_U8G2_OLED/cec4c5ceac4937fb9d6c65c932ef5553c3821841/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file system_stm32f4xx.h
4 | * @author MCD Application Team
5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | *
© COPYRIGHT(c) 2017 STMicroelectronics
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | *
33 | ******************************************************************************
34 | */
35 |
36 | /** @addtogroup CMSIS
37 | * @{
38 | */
39 |
40 | /** @addtogroup stm32f4xx_system
41 | * @{
42 | */
43 |
44 | /**
45 | * @brief Define to prevent recursive inclusion
46 | */
47 | #ifndef __SYSTEM_STM32F4XX_H
48 | #define __SYSTEM_STM32F4XX_H
49 |
50 | #ifdef __cplusplus
51 | extern "C" {
52 | #endif
53 |
54 | /** @addtogroup STM32F4xx_System_Includes
55 | * @{
56 | */
57 |
58 | /**
59 | * @}
60 | */
61 |
62 |
63 | /** @addtogroup STM32F4xx_System_Exported_types
64 | * @{
65 | */
66 | /* This variable is updated in three ways:
67 | 1) by calling CMSIS function SystemCoreClockUpdate()
68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq()
69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
70 | Note: If you use this function to configure the system clock; then there
71 | is no need to call the 2 first functions listed above, since SystemCoreClock
72 | variable is updated automatically.
73 | */
74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
75 |
76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */
77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */
78 |
79 | /**
80 | * @}
81 | */
82 |
83 | /** @addtogroup STM32F4xx_System_Exported_Constants
84 | * @{
85 | */
86 |
87 | /**
88 | * @}
89 | */
90 |
91 | /** @addtogroup STM32F4xx_System_Exported_Macros
92 | * @{
93 | */
94 |
95 | /**
96 | * @}
97 | */
98 |
99 | /** @addtogroup STM32F4xx_System_Exported_Functions
100 | * @{
101 | */
102 |
103 | extern void SystemInit(void);
104 | extern void SystemCoreClockUpdate(void);
105 | /**
106 | * @}
107 | */
108 |
109 | #ifdef __cplusplus
110 | }
111 | #endif
112 |
113 | #endif /*__SYSTEM_STM32F4XX_H */
114 |
115 | /**
116 | * @}
117 | */
118 |
119 | /**
120 | * @}
121 | */
122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
123 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/arm_common_tables.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------
2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3 | *
4 | * $Date: 19. October 2015
5 | * $Revision: V.1.4.5 a
6 | *
7 | * Project: CMSIS DSP Library
8 | * Title: arm_common_tables.h
9 | *
10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions
11 | *
12 | * Target Processor: Cortex-M4/Cortex-M3
13 | *
14 | * Redistribution and use in source and binary forms, with or without
15 | * modification, are permitted provided that the following conditions
16 | * are met:
17 | * - Redistributions of source code must retain the above copyright
18 | * notice, this list of conditions and the following disclaimer.
19 | * - Redistributions in binary form must reproduce the above copyright
20 | * notice, this list of conditions and the following disclaimer in
21 | * the documentation and/or other materials provided with the
22 | * distribution.
23 | * - Neither the name of ARM LIMITED nor the names of its contributors
24 | * may be used to endorse or promote products derived from this
25 | * software without specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 | * POSSIBILITY OF SUCH DAMAGE.
39 | * -------------------------------------------------------------------- */
40 |
41 | #ifndef _ARM_COMMON_TABLES_H
42 | #define _ARM_COMMON_TABLES_H
43 |
44 | #include "arm_math.h"
45 |
46 | extern const uint16_t armBitRevTable[1024];
47 | extern const q15_t armRecipTableQ15[64];
48 | extern const q31_t armRecipTableQ31[64];
49 | /* extern const q31_t realCoefAQ31[1024]; */
50 | /* extern const q31_t realCoefBQ31[1024]; */
51 | extern const float32_t twiddleCoef_16[32];
52 | extern const float32_t twiddleCoef_32[64];
53 | extern const float32_t twiddleCoef_64[128];
54 | extern const float32_t twiddleCoef_128[256];
55 | extern const float32_t twiddleCoef_256[512];
56 | extern const float32_t twiddleCoef_512[1024];
57 | extern const float32_t twiddleCoef_1024[2048];
58 | extern const float32_t twiddleCoef_2048[4096];
59 | extern const float32_t twiddleCoef_4096[8192];
60 | #define twiddleCoef twiddleCoef_4096
61 | extern const q31_t twiddleCoef_16_q31[24];
62 | extern const q31_t twiddleCoef_32_q31[48];
63 | extern const q31_t twiddleCoef_64_q31[96];
64 | extern const q31_t twiddleCoef_128_q31[192];
65 | extern const q31_t twiddleCoef_256_q31[384];
66 | extern const q31_t twiddleCoef_512_q31[768];
67 | extern const q31_t twiddleCoef_1024_q31[1536];
68 | extern const q31_t twiddleCoef_2048_q31[3072];
69 | extern const q31_t twiddleCoef_4096_q31[6144];
70 | extern const q15_t twiddleCoef_16_q15[24];
71 | extern const q15_t twiddleCoef_32_q15[48];
72 | extern const q15_t twiddleCoef_64_q15[96];
73 | extern const q15_t twiddleCoef_128_q15[192];
74 | extern const q15_t twiddleCoef_256_q15[384];
75 | extern const q15_t twiddleCoef_512_q15[768];
76 | extern const q15_t twiddleCoef_1024_q15[1536];
77 | extern const q15_t twiddleCoef_2048_q15[3072];
78 | extern const q15_t twiddleCoef_4096_q15[6144];
79 | extern const float32_t twiddleCoef_rfft_32[32];
80 | extern const float32_t twiddleCoef_rfft_64[64];
81 | extern const float32_t twiddleCoef_rfft_128[128];
82 | extern const float32_t twiddleCoef_rfft_256[256];
83 | extern const float32_t twiddleCoef_rfft_512[512];
84 | extern const float32_t twiddleCoef_rfft_1024[1024];
85 | extern const float32_t twiddleCoef_rfft_2048[2048];
86 | extern const float32_t twiddleCoef_rfft_4096[4096];
87 |
88 |
89 | /* floating-point bit reversal tables */
90 | #define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
91 | #define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
92 | #define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
93 | #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
94 | #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
95 | #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
96 | #define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
97 | #define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
98 | #define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
99 |
100 | extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH];
101 | extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH];
102 | extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH];
103 | extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH];
104 | extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH];
105 | extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH];
106 | extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH];
107 | extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH];
108 | extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH];
109 |
110 | /* fixed-point bit reversal tables */
111 | #define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 )
112 | #define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 )
113 | #define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 )
114 | #define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
115 | #define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
116 | #define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
117 | #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
118 | #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
119 | #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
120 |
121 | extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
122 | extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
123 | extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
124 | extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
125 | extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
126 | extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
127 | extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
128 | extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
129 | extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
130 |
131 | /* Tables for Fast Math Sine and Cosine */
132 | extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
133 | extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
134 | extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
135 |
136 | #endif /* ARM_COMMON_TABLES_H */
137 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/arm_const_structs.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------
2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3 | *
4 | * $Date: 19. March 2015
5 | * $Revision: V.1.4.5
6 | *
7 | * Project: CMSIS DSP Library
8 | * Title: arm_const_structs.h
9 | *
10 | * Description: This file has constant structs that are initialized for
11 | * user convenience. For example, some can be given as
12 | * arguments to the arm_cfft_f32() function.
13 | *
14 | * Target Processor: Cortex-M4/Cortex-M3
15 | *
16 | * Redistribution and use in source and binary forms, with or without
17 | * modification, are permitted provided that the following conditions
18 | * are met:
19 | * - Redistributions of source code must retain the above copyright
20 | * notice, this list of conditions and the following disclaimer.
21 | * - Redistributions in binary form must reproduce the above copyright
22 | * notice, this list of conditions and the following disclaimer in
23 | * the documentation and/or other materials provided with the
24 | * distribution.
25 | * - Neither the name of ARM LIMITED nor the names of its contributors
26 | * may be used to endorse or promote products derived from this
27 | * software without specific prior written permission.
28 | *
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
33 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
39 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 | * POSSIBILITY OF SUCH DAMAGE.
41 | * -------------------------------------------------------------------- */
42 |
43 | #ifndef _ARM_CONST_STRUCTS_H
44 | #define _ARM_CONST_STRUCTS_H
45 |
46 | #include "arm_math.h"
47 | #include "arm_common_tables.h"
48 |
49 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16;
50 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32;
51 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64;
52 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128;
53 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256;
54 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512;
55 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024;
56 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048;
57 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096;
58 |
59 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16;
60 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32;
61 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64;
62 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128;
63 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256;
64 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512;
65 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024;
66 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048;
67 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096;
68 |
69 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16;
70 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32;
71 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64;
72 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128;
73 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256;
74 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512;
75 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024;
76 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048;
77 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096;
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/core_cmFunc.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file core_cmFunc.h
3 | * @brief CMSIS Cortex-M Core Function Access Header File
4 | * @version V4.30
5 | * @date 20. October 2015
6 | ******************************************************************************/
7 | /* Copyright (c) 2009 - 2015 ARM LIMITED
8 |
9 | All rights reserved.
10 | Redistribution and use in source and binary forms, with or without
11 | modification, are permitted provided that the following conditions are met:
12 | - Redistributions of source code must retain the above copyright
13 | notice, this list of conditions and the following disclaimer.
14 | - Redistributions in binary form must reproduce the above copyright
15 | notice, this list of conditions and the following disclaimer in the
16 | documentation and/or other materials provided with the distribution.
17 | - Neither the name of ARM nor the names of its contributors may be used
18 | to endorse or promote products derived from this software without
19 | specific prior written permission.
20 | *
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 | POSSIBILITY OF SUCH DAMAGE.
32 | ---------------------------------------------------------------------------*/
33 |
34 |
35 | #if defined ( __ICCARM__ )
36 | #pragma system_include /* treat file as system include file for MISRA check */
37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38 | #pragma clang system_header /* treat file as system include file */
39 | #endif
40 |
41 | #ifndef __CORE_CMFUNC_H
42 | #define __CORE_CMFUNC_H
43 |
44 |
45 | /* ########################### Core Function Access ########################### */
46 | /** \ingroup CMSIS_Core_FunctionInterface
47 | \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
48 | @{
49 | */
50 |
51 | /*------------------ RealView Compiler -----------------*/
52 | #if defined ( __CC_ARM )
53 | #include "cmsis_armcc.h"
54 |
55 | /*------------------ ARM Compiler V6 -------------------*/
56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
57 | #include "cmsis_armcc_V6.h"
58 |
59 | /*------------------ GNU Compiler ----------------------*/
60 | #elif defined ( __GNUC__ )
61 | #include "cmsis_gcc.h"
62 |
63 | /*------------------ ICC Compiler ----------------------*/
64 | #elif defined ( __ICCARM__ )
65 | #include
66 |
67 | /*------------------ TI CCS Compiler -------------------*/
68 | #elif defined ( __TMS470__ )
69 | #include
70 |
71 | /*------------------ TASKING Compiler ------------------*/
72 | #elif defined ( __TASKING__ )
73 | /*
74 | * The CMSIS functions have been implemented as intrinsics in the compiler.
75 | * Please use "carm -?i" to get an up to date list of all intrinsics,
76 | * Including the CMSIS ones.
77 | */
78 |
79 | /*------------------ COSMIC Compiler -------------------*/
80 | #elif defined ( __CSMC__ )
81 | #include
82 |
83 | #endif
84 |
85 | /*@} end of CMSIS_Core_RegAccFunctions */
86 |
87 | #endif /* __CORE_CMFUNC_H */
88 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/core_cmInstr.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file core_cmInstr.h
3 | * @brief CMSIS Cortex-M Core Instruction Access Header File
4 | * @version V4.30
5 | * @date 20. October 2015
6 | ******************************************************************************/
7 | /* Copyright (c) 2009 - 2015 ARM LIMITED
8 |
9 | All rights reserved.
10 | Redistribution and use in source and binary forms, with or without
11 | modification, are permitted provided that the following conditions are met:
12 | - Redistributions of source code must retain the above copyright
13 | notice, this list of conditions and the following disclaimer.
14 | - Redistributions in binary form must reproduce the above copyright
15 | notice, this list of conditions and the following disclaimer in the
16 | documentation and/or other materials provided with the distribution.
17 | - Neither the name of ARM nor the names of its contributors may be used
18 | to endorse or promote products derived from this software without
19 | specific prior written permission.
20 | *
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 | POSSIBILITY OF SUCH DAMAGE.
32 | ---------------------------------------------------------------------------*/
33 |
34 |
35 | #if defined ( __ICCARM__ )
36 | #pragma system_include /* treat file as system include file for MISRA check */
37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38 | #pragma clang system_header /* treat file as system include file */
39 | #endif
40 |
41 | #ifndef __CORE_CMINSTR_H
42 | #define __CORE_CMINSTR_H
43 |
44 |
45 | /* ########################## Core Instruction Access ######################### */
46 | /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
47 | Access to dedicated instructions
48 | @{
49 | */
50 |
51 | /*------------------ RealView Compiler -----------------*/
52 | #if defined ( __CC_ARM )
53 | #include "cmsis_armcc.h"
54 |
55 | /*------------------ ARM Compiler V6 -------------------*/
56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
57 | #include "cmsis_armcc_V6.h"
58 |
59 | /*------------------ GNU Compiler ----------------------*/
60 | #elif defined ( __GNUC__ )
61 | #include "cmsis_gcc.h"
62 |
63 | /*------------------ ICC Compiler ----------------------*/
64 | #elif defined ( __ICCARM__ )
65 | #include
66 |
67 | /*------------------ TI CCS Compiler -------------------*/
68 | #elif defined ( __TMS470__ )
69 | #include
70 |
71 | /*------------------ TASKING Compiler ------------------*/
72 | #elif defined ( __TASKING__ )
73 | /*
74 | * The CMSIS functions have been implemented as intrinsics in the compiler.
75 | * Please use "carm -?i" to get an up to date list of all intrinsics,
76 | * Including the CMSIS ones.
77 | */
78 |
79 | /*------------------ COSMIC Compiler -------------------*/
80 | #elif defined ( __CSMC__ )
81 | #include
82 |
83 | #endif
84 |
85 | /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
86 |
87 | #endif /* __CORE_CMINSTR_H */
88 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/core_cmSimd.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file core_cmSimd.h
3 | * @brief CMSIS Cortex-M SIMD Header File
4 | * @version V4.30
5 | * @date 20. October 2015
6 | ******************************************************************************/
7 | /* Copyright (c) 2009 - 2015 ARM LIMITED
8 |
9 | All rights reserved.
10 | Redistribution and use in source and binary forms, with or without
11 | modification, are permitted provided that the following conditions are met:
12 | - Redistributions of source code must retain the above copyright
13 | notice, this list of conditions and the following disclaimer.
14 | - Redistributions in binary form must reproduce the above copyright
15 | notice, this list of conditions and the following disclaimer in the
16 | documentation and/or other materials provided with the distribution.
17 | - Neither the name of ARM nor the names of its contributors may be used
18 | to endorse or promote products derived from this software without
19 | specific prior written permission.
20 | *
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 | POSSIBILITY OF SUCH DAMAGE.
32 | ---------------------------------------------------------------------------*/
33 |
34 |
35 | #if defined ( __ICCARM__ )
36 | #pragma system_include /* treat file as system include file for MISRA check */
37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38 | #pragma clang system_header /* treat file as system include file */
39 | #endif
40 |
41 | #ifndef __CORE_CMSIMD_H
42 | #define __CORE_CMSIMD_H
43 |
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 |
48 |
49 | /* ################### Compiler specific Intrinsics ########################### */
50 | /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
51 | Access to dedicated SIMD instructions
52 | @{
53 | */
54 |
55 | /*------------------ RealView Compiler -----------------*/
56 | #if defined ( __CC_ARM )
57 | #include "cmsis_armcc.h"
58 |
59 | /*------------------ ARM Compiler V6 -------------------*/
60 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
61 | #include "cmsis_armcc_V6.h"
62 |
63 | /*------------------ GNU Compiler ----------------------*/
64 | #elif defined ( __GNUC__ )
65 | #include "cmsis_gcc.h"
66 |
67 | /*------------------ ICC Compiler ----------------------*/
68 | #elif defined ( __ICCARM__ )
69 | #include
70 |
71 | /*------------------ TI CCS Compiler -------------------*/
72 | #elif defined ( __TMS470__ )
73 | #include
74 |
75 | /*------------------ TASKING Compiler ------------------*/
76 | #elif defined ( __TASKING__ )
77 | /*
78 | * The CMSIS functions have been implemented as intrinsics in the compiler.
79 | * Please use "carm -?i" to get an up to date list of all intrinsics,
80 | * Including the CMSIS ones.
81 | */
82 |
83 | /*------------------ COSMIC Compiler -------------------*/
84 | #elif defined ( __CSMC__ )
85 | #include
86 |
87 | #endif
88 |
89 | /*@} end of group CMSIS_SIMD_intrinsics */
90 |
91 |
92 | #ifdef __cplusplus
93 | }
94 | #endif
95 |
96 | #endif /* __CORE_CMSIMD_H */
97 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_dma_ex.h
4 | * @author MCD Application Team
5 | * @brief Header file of DMA HAL extension module.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © COPYRIGHT(c) 2017 STMicroelectronics
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | *
33 | ******************************************************************************
34 | */
35 |
36 | /* Define to prevent recursive inclusion -------------------------------------*/
37 | #ifndef __STM32F4xx_HAL_DMA_EX_H
38 | #define __STM32F4xx_HAL_DMA_EX_H
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | /* Includes ------------------------------------------------------------------*/
45 | #include "stm32f4xx_hal_def.h"
46 |
47 | /** @addtogroup STM32F4xx_HAL_Driver
48 | * @{
49 | */
50 |
51 | /** @addtogroup DMAEx
52 | * @{
53 | */
54 |
55 | /* Exported types ------------------------------------------------------------*/
56 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types
57 | * @brief DMAEx Exported types
58 | * @{
59 | */
60 |
61 | /**
62 | * @brief HAL DMA Memory definition
63 | */
64 | typedef enum
65 | {
66 | MEMORY0 = 0x00U, /*!< Memory 0 */
67 | MEMORY1 = 0x01U /*!< Memory 1 */
68 | }HAL_DMA_MemoryTypeDef;
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /* Exported functions --------------------------------------------------------*/
75 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
76 | * @brief DMAEx Exported functions
77 | * @{
78 | */
79 |
80 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions
81 | * @brief Extended features functions
82 | * @{
83 | */
84 |
85 | /* IO operation functions *******************************************************/
86 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength);
87 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength);
88 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory);
89 |
90 | /**
91 | * @}
92 | */
93 | /**
94 | * @}
95 | */
96 |
97 | /* Private functions ---------------------------------------------------------*/
98 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions
99 | * @brief DMAEx Private functions
100 | * @{
101 | */
102 | /**
103 | * @}
104 | */
105 |
106 | /**
107 | * @}
108 | */
109 |
110 | /**
111 | * @}
112 | */
113 |
114 | #ifdef __cplusplus
115 | }
116 | #endif
117 |
118 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/
119 |
120 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
121 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_flash_ramfunc.h
4 | * @author MCD Application Team
5 | * @brief Header file of FLASH RAMFUNC driver.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © COPYRIGHT(c) 2017 STMicroelectronics
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | *
33 | ******************************************************************************
34 | */
35 |
36 | /* Define to prevent recursive inclusion -------------------------------------*/
37 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H
38 | #define __STM32F4xx_FLASH_RAMFUNC_H
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\
44 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx)
45 |
46 | /* Includes ------------------------------------------------------------------*/
47 | #include "stm32f4xx_hal_def.h"
48 |
49 | /** @addtogroup STM32F4xx_HAL_Driver
50 | * @{
51 | */
52 |
53 | /** @addtogroup FLASH_RAMFUNC
54 | * @{
55 | */
56 |
57 | /* Exported types ------------------------------------------------------------*/
58 | /* Exported macro ------------------------------------------------------------*/
59 | /* Exported functions --------------------------------------------------------*/
60 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions
61 | * @{
62 | */
63 |
64 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1
65 | * @{
66 | */
67 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void);
68 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void);
69 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void);
70 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void);
71 | /**
72 | * @}
73 | */
74 |
75 | /**
76 | * @}
77 | */
78 |
79 | /**
80 | * @}
81 | */
82 |
83 | /**
84 | * @}
85 | */
86 |
87 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
88 | #ifdef __cplusplus
89 | }
90 | #endif
91 |
92 |
93 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */
94 |
95 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
96 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_i2c_ex.h
4 | * @author MCD Application Team
5 | * @brief Header file of I2C HAL Extension module.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © COPYRIGHT(c) 2017 STMicroelectronics
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | *
33 | ******************************************************************************
34 | */
35 |
36 | /* Define to prevent recursive inclusion -------------------------------------*/
37 | #ifndef __STM32F4xx_HAL_I2C_EX_H
38 | #define __STM32F4xx_HAL_I2C_EX_H
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
45 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) ||\
46 | defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
47 | /* Includes ------------------------------------------------------------------*/
48 | #include "stm32f4xx_hal_def.h"
49 |
50 | /** @addtogroup STM32F4xx_HAL_Driver
51 | * @{
52 | */
53 |
54 | /** @addtogroup I2CEx
55 | * @{
56 | */
57 |
58 | /* Exported types ------------------------------------------------------------*/
59 | /* Exported constants --------------------------------------------------------*/
60 | /** @defgroup I2CEx_Exported_Constants I2C Exported Constants
61 | * @{
62 | */
63 |
64 | /** @defgroup I2CEx_Analog_Filter I2C Analog Filter
65 | * @{
66 | */
67 | #define I2C_ANALOGFILTER_ENABLE 0x00000000U
68 | #define I2C_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF
69 | /**
70 | * @}
71 | */
72 |
73 | /**
74 | * @}
75 | */
76 |
77 | /* Exported macro ------------------------------------------------------------*/
78 | /* Exported functions --------------------------------------------------------*/
79 | /** @addtogroup I2CEx_Exported_Functions
80 | * @{
81 | */
82 |
83 | /** @addtogroup I2CEx_Exported_Functions_Group1
84 | * @{
85 | */
86 | /* Peripheral Control functions ************************************************/
87 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter);
88 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter);
89 | /**
90 | * @}
91 | */
92 |
93 | /**
94 | * @}
95 | */
96 | /* Private types -------------------------------------------------------------*/
97 | /* Private variables ---------------------------------------------------------*/
98 | /* Private constants ---------------------------------------------------------*/
99 | /** @defgroup I2CEx_Private_Constants I2C Private Constants
100 | * @{
101 | */
102 |
103 | /**
104 | * @}
105 | */
106 |
107 | /* Private macros ------------------------------------------------------------*/
108 | /** @defgroup I2CEx_Private_Macros I2C Private Macros
109 | * @{
110 | */
111 | #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \
112 | ((FILTER) == I2C_ANALOGFILTER_DISABLE))
113 | #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU)
114 | /**
115 | * @}
116 | */
117 |
118 | /**
119 | * @}
120 | */
121 |
122 | /**
123 | * @}
124 | */
125 |
126 | #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC ||\
127 | STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx ||\
128 | STM32F413xx || STM32F423xx */
129 |
130 | #ifdef __cplusplus
131 | }
132 | #endif
133 |
134 | #endif /* __STM32F4xx_HAL_I2C_EX_H */
135 |
136 |
137 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
138 |
--------------------------------------------------------------------------------
/Inc/main.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : main.h
4 | * @brief : Header for main.c file.
5 | * This file contains the common defines of the application.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2019 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 |
40 | /* Define to prevent recursive inclusion -------------------------------------*/
41 | #ifndef __MAIN_H__
42 | #define __MAIN_H__
43 |
44 | /* Includes ------------------------------------------------------------------*/
45 |
46 | /* USER CODE BEGIN Includes */
47 |
48 | /* USER CODE END Includes */
49 |
50 | /* Private define ------------------------------------------------------------*/
51 |
52 | #define OLED_CS_Pin GPIO_PIN_9
53 | #define OLED_CS_GPIO_Port GPIOD
54 | #define OLED_DC_Pin GPIO_PIN_10
55 | #define OLED_DC_GPIO_Port GPIOD
56 | #define OLED_RST_Pin GPIO_PIN_11
57 | #define OLED_RST_GPIO_Port GPIOD
58 |
59 | /* ########################## Assert Selection ############################## */
60 | /**
61 | * @brief Uncomment the line below to expanse the "assert_param" macro in the
62 | * HAL drivers code
63 | */
64 | /* #define USE_FULL_ASSERT 1U */
65 |
66 | /* USER CODE BEGIN Private defines */
67 |
68 | /* USER CODE END Private defines */
69 |
70 | #ifdef __cplusplus
71 | extern "C" {
72 | #endif
73 | void _Error_Handler(char *, int);
74 |
75 | #define Error_Handler() _Error_Handler(__FILE__, __LINE__)
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 |
80 | #endif /* __MAIN_H__ */
81 |
82 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
83 |
--------------------------------------------------------------------------------
/Inc/stm32f4xx_it.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_it.h
4 | * @brief This file contains the headers of the interrupt handlers.
5 | ******************************************************************************
6 | *
7 | * COPYRIGHT(c) 2019 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 |
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __STM32F4xx_IT_H
36 | #define __STM32F4xx_IT_H
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | #include "stm32f4xx_hal.h"
44 | #include "main.h"
45 | /* Exported types ------------------------------------------------------------*/
46 | /* Exported constants --------------------------------------------------------*/
47 | /* Exported macro ------------------------------------------------------------*/
48 | /* Exported functions ------------------------------------------------------- */
49 |
50 | void NMI_Handler(void);
51 | void HardFault_Handler(void);
52 | void MemManage_Handler(void);
53 | void BusFault_Handler(void);
54 | void UsageFault_Handler(void);
55 | void SVC_Handler(void);
56 | void DebugMon_Handler(void);
57 | void PendSV_Handler(void);
58 | void SysTick_Handler(void);
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 |
64 | #endif /* __STM32F4xx_IT_H */
65 |
66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # STM32_HAL_U8G2_OLED
2 | Port of U8G2 Library for STM32 HAL
3 |
4 | Reference : https://github.com/olikraus/u8g2
5 | This is a port of u8g2 library written by olikraus.
6 |
7 | Tutorial (Written in Korean) : https://blog.naver.com/eziya76/221501476403
8 |
9 | I followed a porting guide from https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform
10 | Only change I made was writing callback functions for I2C, SPI and delay like below.
11 |
12 | I tested it on STM32F4-DISCO board and it worked for both interfaces.
13 |
14 | 
15 |
16 | [u8g2_stm32f4.c]
17 | ```
18 | #include "main.h"
19 | #include "stm32f4xx_hal.h"
20 | #include "u8g2/u8g2.h"
21 |
22 | #define DEVICE_ADDRESS 0x3C
23 | #define TX_TIMEOUT 100
24 |
25 | extern SPI_HandleTypeDef hspi2;
26 | extern I2C_HandleTypeDef hi2c1;
27 |
28 | uint8_t u8x8_stm32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
29 | {
30 | /* STM32 supports HW SPI, Remove unused cases like U8X8_MSG_DELAY_XXX & U8X8_MSG_GPIO_XXX */
31 | switch(msg)
32 | {
33 | case U8X8_MSG_GPIO_AND_DELAY_INIT:
34 | /* Insert codes for initialization */
35 | break;
36 | case U8X8_MSG_DELAY_MILLI:
37 | /* ms Delay */
38 | HAL_Delay(arg_int);
39 | break;
40 | case U8X8_MSG_GPIO_CS:
41 | /* Insert codes for SS pin control */
42 | HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, arg_int);
43 | break;
44 | case U8X8_MSG_GPIO_DC:
45 | /* Insert codes for DC pin control */
46 | HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, arg_int);
47 | break;
48 | case U8X8_MSG_GPIO_RESET:
49 | /* Insert codes for RST pin control */
50 | HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, arg_int);
51 | break;
52 | }
53 | return 1;
54 | }
55 |
56 | uint8_t u8x8_byte_stm32_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
57 | {
58 | switch(msg) {
59 | case U8X8_MSG_BYTE_SEND:
60 | /* Insert codes to transmit data */
61 | if(HAL_SPI_Transmit(&hspi2, arg_ptr, arg_int, TX_TIMEOUT) != HAL_OK) return 0;
62 | break;
63 | case U8X8_MSG_BYTE_INIT:
64 | /* Insert codes to begin SPI transmission */
65 | break;
66 | case U8X8_MSG_BYTE_SET_DC:
67 | /* Control DC pin, U8X8_MSG_GPIO_DC will be called */
68 | u8x8_gpio_SetDC(u8x8, arg_int);
69 | break;
70 | case U8X8_MSG_BYTE_START_TRANSFER:
71 | /* Select slave, U8X8_MSG_GPIO_CS will be called */
72 | u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
73 | HAL_Delay(1);
74 | break;
75 | case U8X8_MSG_BYTE_END_TRANSFER:
76 | HAL_Delay(1);
77 | /* Insert codes to end SPI transmission */
78 | u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
79 | break;
80 | default:
81 | return 0;
82 | }
83 | return 1;
84 | }
85 |
86 | uint8_t u8x8_byte_stm32_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
87 | {
88 | /* u8g2/u8x8 will never send more than 32 bytes between START_TRANSFER and END_TRANSFER */
89 | static uint8_t buffer[32];
90 | static uint8_t buf_idx;
91 | uint8_t *data;
92 |
93 | switch(msg)
94 | {
95 | case U8X8_MSG_BYTE_SEND:
96 | data = (uint8_t *)arg_ptr;
97 | while( arg_int > 0 )
98 | {
99 | buffer[buf_idx++] = *data;
100 | data++;
101 | arg_int--;
102 | }
103 | break;
104 | case U8X8_MSG_BYTE_INIT:
105 | /* add your custom code to init i2c subsystem */
106 | break;
107 | case U8X8_MSG_BYTE_SET_DC:
108 | break;
109 | case U8X8_MSG_BYTE_START_TRANSFER:
110 | buf_idx = 0;
111 | break;
112 | case U8X8_MSG_BYTE_END_TRANSFER:
113 | if(HAL_I2C_Master_Transmit(&hi2c1, (DEVICE_ADDRESS << 1), buffer, buf_idx, TX_TIMEOUT) != HAL_OK) return 0;
114 | break;
115 | default:
116 | return 0;
117 | }
118 | return 1;
119 | }
120 | ```
121 |
--------------------------------------------------------------------------------
/STM32F407VG_FLASH.ld:
--------------------------------------------------------------------------------
1 | /*
2 | *****************************************************************************
3 | **
4 |
5 | ** File : stm32_flash.ld
6 | **
7 | ** Abstract : Linker script for STM32F407VG Device with
8 | ** 1024KByte FLASH, 128KByte RAM
9 | **
10 | ** Set heap size, stack size and stack location according
11 | ** to application requirements.
12 | **
13 | ** Set memory bank area and size if external memory is used.
14 | **
15 | ** Target : STMicroelectronics STM32
16 | **
17 | ** Environment : Atollic TrueSTUDIO(R)
18 | **
19 | ** Distribution: The file is distributed as is, without any warranty
20 | ** of any kind.
21 | **
22 | ** (c)Copyright Atollic AB.
23 | ** You may use this file as-is or modify it according to the needs of your
24 | ** project. This file may only be built (assembled or compiled and linked)
25 | ** using the Atollic TrueSTUDIO(R) product. The use of this file together
26 | ** with other tools than Atollic TrueSTUDIO(R) is not permitted.
27 | **
28 | *****************************************************************************
29 | */
30 |
31 | /* Entry Point */
32 | ENTRY(Reset_Handler)
33 |
34 | /* Highest address of the user mode stack */
35 | _estack = 0x20020000; /* end of RAM */
36 | /* Generate a link error if heap and stack don't fit into RAM */
37 | _Min_Heap_Size = 0x200; /* required amount of heap */
38 | _Min_Stack_Size = 0x400; /* required amount of stack */
39 |
40 | /* Specify the memory areas */
41 | MEMORY
42 | {
43 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
44 | CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
45 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
46 | }
47 |
48 | /* Define output sections */
49 | SECTIONS
50 | {
51 | /* The startup code goes first into FLASH */
52 | .isr_vector :
53 | {
54 | . = ALIGN(4);
55 | KEEP(*(.isr_vector)) /* Startup code */
56 | . = ALIGN(4);
57 | } >FLASH
58 |
59 | /* The program code and other data goes into FLASH */
60 | .text :
61 | {
62 | . = ALIGN(4);
63 | *(.text) /* .text sections (code) */
64 | *(.text*) /* .text* sections (code) */
65 | *(.glue_7) /* glue arm to thumb code */
66 | *(.glue_7t) /* glue thumb to arm code */
67 | *(.eh_frame)
68 |
69 | KEEP (*(.init))
70 | KEEP (*(.fini))
71 |
72 | . = ALIGN(4);
73 | _etext = .; /* define a global symbols at end of code */
74 | } >FLASH
75 |
76 | /* Constant data goes into FLASH */
77 | .rodata :
78 | {
79 | . = ALIGN(4);
80 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
81 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
82 | . = ALIGN(4);
83 | } >FLASH
84 |
85 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
86 | .ARM : {
87 | __exidx_start = .;
88 | *(.ARM.exidx*)
89 | __exidx_end = .;
90 | } >FLASH
91 |
92 | .preinit_array :
93 | {
94 | PROVIDE_HIDDEN (__preinit_array_start = .);
95 | KEEP (*(.preinit_array*))
96 | PROVIDE_HIDDEN (__preinit_array_end = .);
97 | } >FLASH
98 | .init_array :
99 | {
100 | PROVIDE_HIDDEN (__init_array_start = .);
101 | KEEP (*(SORT(.init_array.*)))
102 | KEEP (*(.init_array*))
103 | PROVIDE_HIDDEN (__init_array_end = .);
104 | } >FLASH
105 | .fini_array :
106 | {
107 | PROVIDE_HIDDEN (__fini_array_start = .);
108 | KEEP (*(SORT(.fini_array.*)))
109 | KEEP (*(.fini_array*))
110 | PROVIDE_HIDDEN (__fini_array_end = .);
111 | } >FLASH
112 |
113 | /* used by the startup to initialize data */
114 | _sidata = LOADADDR(.data);
115 |
116 | /* Initialized data sections goes into RAM, load LMA copy after code */
117 | .data :
118 | {
119 | . = ALIGN(4);
120 | _sdata = .; /* create a global symbol at data start */
121 | *(.data) /* .data sections */
122 | *(.data*) /* .data* sections */
123 |
124 | . = ALIGN(4);
125 | _edata = .; /* define a global symbol at data end */
126 | } >RAM AT> FLASH
127 |
128 | _siccmram = LOADADDR(.ccmram);
129 |
130 | /* CCM-RAM section
131 | *
132 | * IMPORTANT NOTE!
133 | * If initialized variables will be placed in this section,
134 | * the startup code needs to be modified to copy the init-values.
135 | */
136 | .ccmram :
137 | {
138 | . = ALIGN(4);
139 | _sccmram = .; /* create a global symbol at ccmram start */
140 | *(.ccmram)
141 | *(.ccmram*)
142 |
143 | . = ALIGN(4);
144 | _eccmram = .; /* create a global symbol at ccmram end */
145 | } >CCMRAM AT> FLASH
146 |
147 |
148 | /* Uninitialized data section */
149 | . = ALIGN(4);
150 | .bss :
151 | {
152 | /* This is used by the startup in order to initialize the .bss secion */
153 | _sbss = .; /* define a global symbol at bss start */
154 | __bss_start__ = _sbss;
155 | *(.bss)
156 | *(.bss*)
157 | *(COMMON)
158 |
159 | . = ALIGN(4);
160 | _ebss = .; /* define a global symbol at bss end */
161 | __bss_end__ = _ebss;
162 | } >RAM
163 |
164 | /* User_heap_stack section, used to check that there is enough RAM left */
165 | ._user_heap_stack :
166 | {
167 | . = ALIGN(4);
168 | PROVIDE ( end = . );
169 | PROVIDE ( _end = . );
170 | . = . + _Min_Heap_Size;
171 | . = . + _Min_Stack_Size;
172 | . = ALIGN(4);
173 | } >RAM
174 |
175 |
176 |
177 | /* Remove information from the standard libraries */
178 | /DISCARD/ :
179 | {
180 | libc.a ( * )
181 | libm.a ( * )
182 | libgcc.a ( * )
183 | }
184 |
185 | .ARM.attributes 0 : { *(.ARM.attributes) }
186 | }
187 |
188 |
189 |
--------------------------------------------------------------------------------
/STM32F4_HAL_U8G2_OLED.elf.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/STM32F4_HAL_U8G2_OLED.ioc:
--------------------------------------------------------------------------------
1 | #MicroXplorer Configuration settings - do not modify
2 | File.Version=6
3 | I2C1.I2C_Mode=I2C_Standard
4 | I2C1.IPParameters=I2C_Mode
5 | KeepUserPlacement=true
6 | Mcu.Family=STM32F4
7 | Mcu.IP0=I2C1
8 | Mcu.IP1=NVIC
9 | Mcu.IP2=RCC
10 | Mcu.IP3=SPI2
11 | Mcu.IP4=SYS
12 | Mcu.IPNb=5
13 | Mcu.Name=STM32F407V(E-G)Tx
14 | Mcu.Package=LQFP100
15 | Mcu.Pin0=PH0-OSC_IN
16 | Mcu.Pin1=PH1-OSC_OUT
17 | Mcu.Pin2=PB13
18 | Mcu.Pin3=PB15
19 | Mcu.Pin4=PD9
20 | Mcu.Pin5=PD10
21 | Mcu.Pin6=PD11
22 | Mcu.Pin7=PB8
23 | Mcu.Pin8=PB9
24 | Mcu.Pin9=VP_SYS_VS_Systick
25 | Mcu.PinsNb=10
26 | Mcu.ThirdPartyNb=0
27 | Mcu.UserConstants=
28 | Mcu.UserName=STM32F407VGTx
29 | MxCube.Version=4.27.0
30 | MxDb.Version=DB.4.0.270
31 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true
32 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true
33 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true
34 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true
35 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true
36 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:true
37 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0
38 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:true
39 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:true
40 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true
41 | PB13.Locked=true
42 | PB13.Mode=TX_Only_Simplex_Unidirect_Master
43 | PB13.Signal=SPI2_SCK
44 | PB15.Locked=true
45 | PB15.Mode=TX_Only_Simplex_Unidirect_Master
46 | PB15.Signal=SPI2_MOSI
47 | PB8.Locked=true
48 | PB8.Mode=I2C
49 | PB8.Signal=I2C1_SCL
50 | PB9.Locked=true
51 | PB9.Mode=I2C
52 | PB9.Signal=I2C1_SDA
53 | PCC.Checker=false
54 | PCC.Line=STM32F407/417
55 | PCC.MCU=STM32F407V(E-G)Tx
56 | PCC.PartNumber=STM32F407VGTx
57 | PCC.Seq0=0
58 | PCC.Series=STM32F4
59 | PCC.Temperature=25
60 | PCC.Vdd=3.3
61 | PD10.GPIOParameters=GPIO_Label
62 | PD10.GPIO_Label=OLED_DC
63 | PD10.Locked=true
64 | PD10.Signal=GPIO_Output
65 | PD11.GPIOParameters=GPIO_Label
66 | PD11.GPIO_Label=OLED_RST
67 | PD11.Locked=true
68 | PD11.Signal=GPIO_Output
69 | PD9.GPIOParameters=GPIO_Label
70 | PD9.GPIO_Label=OLED_CS
71 | PD9.Locked=true
72 | PD9.Signal=GPIO_Output
73 | PH0-OSC_IN.Mode=HSE-External-Oscillator
74 | PH0-OSC_IN.Signal=RCC_OSC_IN
75 | PH1-OSC_OUT.Mode=HSE-External-Oscillator
76 | PH1-OSC_OUT.Signal=RCC_OSC_OUT
77 | PinOutPanel.RotationAngle=0
78 | ProjectManager.AskForMigrate=true
79 | ProjectManager.BackupPrevious=false
80 | ProjectManager.CompilerOptimize=6
81 | ProjectManager.ComputerToolchain=false
82 | ProjectManager.CoupleFile=false
83 | ProjectManager.CustomerFirmwarePackage=
84 | ProjectManager.DefaultFWLocation=true
85 | ProjectManager.DeletePrevious=true
86 | ProjectManager.DeviceId=STM32F407VGTx
87 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.21.0
88 | ProjectManager.FreePins=false
89 | ProjectManager.HalAssertFull=false
90 | ProjectManager.HeapSize=0x200
91 | ProjectManager.KeepUserCode=true
92 | ProjectManager.LastFirmware=true
93 | ProjectManager.LibraryCopy=1
94 | ProjectManager.MainLocation=Src
95 | ProjectManager.NoMain=false
96 | ProjectManager.PreviousToolchain=TrueSTUDIO
97 | ProjectManager.ProjectBuild=false
98 | ProjectManager.ProjectFileName=STM32F4_HAL_U8G2_OLED.ioc
99 | ProjectManager.ProjectName=STM32F4_HAL_U8G2_OLED
100 | ProjectManager.StackSize=0x400
101 | ProjectManager.TargetToolchain=TrueSTUDIO
102 | ProjectManager.ToolChainLocation=
103 | ProjectManager.UnderRoot=true
104 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_SPI2_Init-SPI2-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true
105 | RCC.48MHZClocksFreq_Value=48000000
106 | RCC.AHBFreq_Value=168000000
107 | RCC.APB1CLKDivider=RCC_HCLK_DIV4
108 | RCC.APB1Freq_Value=42000000
109 | RCC.APB1TimFreq_Value=84000000
110 | RCC.APB2CLKDivider=RCC_HCLK_DIV2
111 | RCC.APB2Freq_Value=84000000
112 | RCC.APB2TimFreq_Value=168000000
113 | RCC.CortexFreq_Value=168000000
114 | RCC.EthernetFreq_Value=168000000
115 | RCC.FCLKCortexFreq_Value=168000000
116 | RCC.FamilyName=M
117 | RCC.HCLKFreq_Value=168000000
118 | RCC.HSE_VALUE=8000000
119 | RCC.HSI_VALUE=16000000
120 | RCC.I2SClocksFreq_Value=96000000
121 | RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,PLLSourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S
122 | RCC.LSE_VALUE=32768
123 | RCC.LSI_VALUE=32000
124 | RCC.MCO2PinFreq_Value=168000000
125 | RCC.PLLCLKFreq_Value=168000000
126 | RCC.PLLM=8
127 | RCC.PLLN=336
128 | RCC.PLLQ=7
129 | RCC.PLLQCLKFreq_Value=48000000
130 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
131 | RCC.RTCFreq_Value=32000
132 | RCC.RTCHSEDivFreq_Value=4000000
133 | RCC.SYSCLKFreq_VALUE=168000000
134 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
135 | RCC.VCOI2SOutputFreq_Value=192000000
136 | RCC.VCOInputFreq_Value=1000000
137 | RCC.VCOOutputFreq_Value=336000000
138 | RCC.VcooutputI2S=96000000
139 | SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8
140 | SPI2.CalculateBaudRate=5.25 MBits/s
141 | SPI2.Direction=SPI_DIRECTION_2LINES
142 | SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler
143 | SPI2.Mode=SPI_MODE_MASTER
144 | SPI2.VirtualType=VM_MASTER
145 | VP_SYS_VS_Systick.Mode=SysTick
146 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick
147 | board=STM32F4DISCOVERY
148 | boardIOC=true
149 |
--------------------------------------------------------------------------------
/Src/stm32f4xx_hal_msp.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : stm32f4xx_hal_msp.c
4 | * Description : This file provides code for the MSP Initialization
5 | * and de-Initialization codes.
6 | ******************************************************************************
7 | ** This notice applies to any and all portions of this file
8 | * that are not between comment pairs USER CODE BEGIN and
9 | * USER CODE END. Other portions of this file, whether
10 | * inserted by the user or by software development tools
11 | * are owned by their respective copyright owners.
12 | *
13 | * COPYRIGHT(c) 2019 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 | /* Includes ------------------------------------------------------------------*/
40 | #include "stm32f4xx_hal.h"
41 | extern void _Error_Handler(char *, int);
42 | /* USER CODE BEGIN 0 */
43 |
44 | /* USER CODE END 0 */
45 | /**
46 | * Initializes the Global MSP.
47 | */
48 | void HAL_MspInit(void)
49 | {
50 | /* USER CODE BEGIN MspInit 0 */
51 |
52 | /* USER CODE END MspInit 0 */
53 |
54 | __HAL_RCC_SYSCFG_CLK_ENABLE();
55 | __HAL_RCC_PWR_CLK_ENABLE();
56 |
57 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
58 |
59 | /* System interrupt init*/
60 | /* MemoryManagement_IRQn interrupt configuration */
61 | HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
62 | /* BusFault_IRQn interrupt configuration */
63 | HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
64 | /* UsageFault_IRQn interrupt configuration */
65 | HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
66 | /* SVCall_IRQn interrupt configuration */
67 | HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0);
68 | /* DebugMonitor_IRQn interrupt configuration */
69 | HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
70 | /* PendSV_IRQn interrupt configuration */
71 | HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
72 | /* SysTick_IRQn interrupt configuration */
73 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
74 |
75 | /* USER CODE BEGIN MspInit 1 */
76 |
77 | /* USER CODE END MspInit 1 */
78 | }
79 |
80 | void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
81 | {
82 |
83 | GPIO_InitTypeDef GPIO_InitStruct;
84 | if(hi2c->Instance==I2C1)
85 | {
86 | /* USER CODE BEGIN I2C1_MspInit 0 */
87 |
88 | /* USER CODE END I2C1_MspInit 0 */
89 |
90 | /**I2C1 GPIO Configuration
91 | PB8 ------> I2C1_SCL
92 | PB9 ------> I2C1_SDA
93 | */
94 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
95 | GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
96 | GPIO_InitStruct.Pull = GPIO_PULLUP;
97 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
98 | GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
99 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
100 |
101 | /* Peripheral clock enable */
102 | __HAL_RCC_I2C1_CLK_ENABLE();
103 | /* USER CODE BEGIN I2C1_MspInit 1 */
104 |
105 | /* USER CODE END I2C1_MspInit 1 */
106 | }
107 |
108 | }
109 |
110 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
111 | {
112 |
113 | if(hi2c->Instance==I2C1)
114 | {
115 | /* USER CODE BEGIN I2C1_MspDeInit 0 */
116 |
117 | /* USER CODE END I2C1_MspDeInit 0 */
118 | /* Peripheral clock disable */
119 | __HAL_RCC_I2C1_CLK_DISABLE();
120 |
121 | /**I2C1 GPIO Configuration
122 | PB8 ------> I2C1_SCL
123 | PB9 ------> I2C1_SDA
124 | */
125 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9);
126 |
127 | /* USER CODE BEGIN I2C1_MspDeInit 1 */
128 |
129 | /* USER CODE END I2C1_MspDeInit 1 */
130 | }
131 |
132 | }
133 |
134 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
135 | {
136 |
137 | GPIO_InitTypeDef GPIO_InitStruct;
138 | if(hspi->Instance==SPI2)
139 | {
140 | /* USER CODE BEGIN SPI2_MspInit 0 */
141 |
142 | /* USER CODE END SPI2_MspInit 0 */
143 | /* Peripheral clock enable */
144 | __HAL_RCC_SPI2_CLK_ENABLE();
145 |
146 | /**SPI2 GPIO Configuration
147 | PB13 ------> SPI2_SCK
148 | PB15 ------> SPI2_MOSI
149 | */
150 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
151 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
152 | GPIO_InitStruct.Pull = GPIO_NOPULL;
153 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
154 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
155 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
156 |
157 | /* USER CODE BEGIN SPI2_MspInit 1 */
158 |
159 | /* USER CODE END SPI2_MspInit 1 */
160 | }
161 |
162 | }
163 |
164 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
165 | {
166 |
167 | if(hspi->Instance==SPI2)
168 | {
169 | /* USER CODE BEGIN SPI2_MspDeInit 0 */
170 |
171 | /* USER CODE END SPI2_MspDeInit 0 */
172 | /* Peripheral clock disable */
173 | __HAL_RCC_SPI2_CLK_DISABLE();
174 |
175 | /**SPI2 GPIO Configuration
176 | PB13 ------> SPI2_SCK
177 | PB15 ------> SPI2_MOSI
178 | */
179 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_15);
180 |
181 | /* USER CODE BEGIN SPI2_MspDeInit 1 */
182 |
183 | /* USER CODE END SPI2_MspDeInit 1 */
184 | }
185 |
186 | }
187 |
188 | /* USER CODE BEGIN 1 */
189 |
190 | /* USER CODE END 1 */
191 |
192 | /**
193 | * @}
194 | */
195 |
196 | /**
197 | * @}
198 | */
199 |
200 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
201 |
--------------------------------------------------------------------------------
/Src/stm32f4xx_it.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_it.c
4 | * @brief Interrupt Service Routines.
5 | ******************************************************************************
6 | *
7 | * COPYRIGHT(c) 2019 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 | /* Includes ------------------------------------------------------------------*/
34 | #include "stm32f4xx_hal.h"
35 | #include "stm32f4xx.h"
36 | #include "stm32f4xx_it.h"
37 |
38 | /* USER CODE BEGIN 0 */
39 |
40 | /* USER CODE END 0 */
41 |
42 | /* External variables --------------------------------------------------------*/
43 |
44 | /******************************************************************************/
45 | /* Cortex-M4 Processor Interruption and Exception Handlers */
46 | /******************************************************************************/
47 |
48 | /**
49 | * @brief This function handles Non maskable interrupt.
50 | */
51 | void NMI_Handler(void)
52 | {
53 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
54 |
55 | /* USER CODE END NonMaskableInt_IRQn 0 */
56 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
57 |
58 | /* USER CODE END NonMaskableInt_IRQn 1 */
59 | }
60 |
61 | /**
62 | * @brief This function handles Hard fault interrupt.
63 | */
64 | void HardFault_Handler(void)
65 | {
66 | /* USER CODE BEGIN HardFault_IRQn 0 */
67 |
68 | /* USER CODE END HardFault_IRQn 0 */
69 | while (1)
70 | {
71 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */
72 | /* USER CODE END W1_HardFault_IRQn 0 */
73 | }
74 | /* USER CODE BEGIN HardFault_IRQn 1 */
75 |
76 | /* USER CODE END HardFault_IRQn 1 */
77 | }
78 |
79 | /**
80 | * @brief This function handles Memory management fault.
81 | */
82 | void MemManage_Handler(void)
83 | {
84 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */
85 |
86 | /* USER CODE END MemoryManagement_IRQn 0 */
87 | while (1)
88 | {
89 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
90 | /* USER CODE END W1_MemoryManagement_IRQn 0 */
91 | }
92 | /* USER CODE BEGIN MemoryManagement_IRQn 1 */
93 |
94 | /* USER CODE END MemoryManagement_IRQn 1 */
95 | }
96 |
97 | /**
98 | * @brief This function handles Pre-fetch fault, memory access fault.
99 | */
100 | void BusFault_Handler(void)
101 | {
102 | /* USER CODE BEGIN BusFault_IRQn 0 */
103 |
104 | /* USER CODE END BusFault_IRQn 0 */
105 | while (1)
106 | {
107 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */
108 | /* USER CODE END W1_BusFault_IRQn 0 */
109 | }
110 | /* USER CODE BEGIN BusFault_IRQn 1 */
111 |
112 | /* USER CODE END BusFault_IRQn 1 */
113 | }
114 |
115 | /**
116 | * @brief This function handles Undefined instruction or illegal state.
117 | */
118 | void UsageFault_Handler(void)
119 | {
120 | /* USER CODE BEGIN UsageFault_IRQn 0 */
121 |
122 | /* USER CODE END UsageFault_IRQn 0 */
123 | while (1)
124 | {
125 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
126 | /* USER CODE END W1_UsageFault_IRQn 0 */
127 | }
128 | /* USER CODE BEGIN UsageFault_IRQn 1 */
129 |
130 | /* USER CODE END UsageFault_IRQn 1 */
131 | }
132 |
133 | /**
134 | * @brief This function handles System service call via SWI instruction.
135 | */
136 | void SVC_Handler(void)
137 | {
138 | /* USER CODE BEGIN SVCall_IRQn 0 */
139 |
140 | /* USER CODE END SVCall_IRQn 0 */
141 | /* USER CODE BEGIN SVCall_IRQn 1 */
142 |
143 | /* USER CODE END SVCall_IRQn 1 */
144 | }
145 |
146 | /**
147 | * @brief This function handles Debug monitor.
148 | */
149 | void DebugMon_Handler(void)
150 | {
151 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */
152 |
153 | /* USER CODE END DebugMonitor_IRQn 0 */
154 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */
155 |
156 | /* USER CODE END DebugMonitor_IRQn 1 */
157 | }
158 |
159 | /**
160 | * @brief This function handles Pendable request for system service.
161 | */
162 | void PendSV_Handler(void)
163 | {
164 | /* USER CODE BEGIN PendSV_IRQn 0 */
165 |
166 | /* USER CODE END PendSV_IRQn 0 */
167 | /* USER CODE BEGIN PendSV_IRQn 1 */
168 |
169 | /* USER CODE END PendSV_IRQn 1 */
170 | }
171 |
172 | /**
173 | * @brief This function handles System tick timer.
174 | */
175 | void SysTick_Handler(void)
176 | {
177 | /* USER CODE BEGIN SysTick_IRQn 0 */
178 |
179 | /* USER CODE END SysTick_IRQn 0 */
180 | HAL_IncTick();
181 | HAL_SYSTICK_IRQHandler();
182 | /* USER CODE BEGIN SysTick_IRQn 1 */
183 |
184 | /* USER CODE END SysTick_IRQn 1 */
185 | }
186 |
187 | /******************************************************************************/
188 | /* STM32F4xx Peripheral Interrupt Handlers */
189 | /* Add here the Interrupt Handlers for the used peripherals. */
190 | /* For the available peripheral interrupt handler names, */
191 | /* please refer to the startup file (startup_stm32f4xx.s). */
192 | /******************************************************************************/
193 |
194 | /* USER CODE BEGIN 1 */
195 |
196 | /* USER CODE END 1 */
197 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
198 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_bitmap.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_bitmap.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 |
39 | void u8g2_SetBitmapMode(u8g2_t *u8g2, uint8_t is_transparent) {
40 | u8g2->bitmap_transparency = is_transparent;
41 | }
42 |
43 | /*
44 | x,y Position on the display
45 | len Length of bitmap line in pixel. Note: This differs from u8glib which had a bytecount here.
46 | b Pointer to the bitmap line.
47 | Only draw pixels which are set.
48 | */
49 |
50 | void u8g2_DrawHorizontalBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
51 | {
52 | uint8_t mask;
53 | uint8_t color = u8g2->draw_color;
54 | uint8_t ncolor = (color == 0 ? 1 : 0);
55 |
56 | #ifdef U8G2_WITH_INTERSECTION
57 | if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
58 | return;
59 | #endif /* U8G2_WITH_INTERSECTION */
60 |
61 | mask = 128;
62 | while(len > 0)
63 | {
64 | if ( *b & mask ) {
65 | u8g2->draw_color = color;
66 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
67 | } else if ( u8g2->bitmap_transparency == 0 ) {
68 | u8g2->draw_color = ncolor;
69 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
70 | }
71 |
72 | x++;
73 | mask >>= 1;
74 | if ( mask == 0 )
75 | {
76 | mask = 128;
77 | b++;
78 | }
79 | len--;
80 | }
81 | u8g2->draw_color = color;
82 | }
83 |
84 |
85 | /* u8glib compatible bitmap draw function */
86 | void u8g2_DrawBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap)
87 | {
88 | u8g2_uint_t w;
89 | w = cnt;
90 | w *= 8;
91 | #ifdef U8G2_WITH_INTERSECTION
92 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
93 | return;
94 | #endif /* U8G2_WITH_INTERSECTION */
95 |
96 | while( h > 0 )
97 | {
98 | u8g2_DrawHorizontalBitmap(u8g2, x, y, w, bitmap);
99 | bitmap += cnt;
100 | y++;
101 | h--;
102 | }
103 | }
104 |
105 |
106 |
107 | void u8g2_DrawHXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
108 | {
109 | uint8_t mask;
110 | uint8_t color = u8g2->draw_color;
111 | uint8_t ncolor = (color == 0 ? 1 : 0);
112 | #ifdef U8G2_WITH_INTERSECTION
113 | if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
114 | return;
115 | #endif /* U8G2_WITH_INTERSECTION */
116 |
117 | mask = 1;
118 | while(len > 0) {
119 | if ( *b & mask ) {
120 | u8g2->draw_color = color;
121 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
122 | } else if ( u8g2->bitmap_transparency == 0 ) {
123 | u8g2->draw_color = ncolor;
124 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
125 | }
126 | x++;
127 | mask <<= 1;
128 | if ( mask == 0 )
129 | {
130 | mask = 1;
131 | b++;
132 | }
133 | len--;
134 | }
135 | u8g2->draw_color = color;
136 | }
137 |
138 |
139 | void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
140 | {
141 | u8g2_uint_t blen;
142 | blen = w;
143 | blen += 7;
144 | blen >>= 3;
145 | #ifdef U8G2_WITH_INTERSECTION
146 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
147 | return;
148 | #endif /* U8G2_WITH_INTERSECTION */
149 |
150 | while( h > 0 )
151 | {
152 | u8g2_DrawHXBM(u8g2, x, y, w, bitmap);
153 | bitmap += blen;
154 | y++;
155 | h--;
156 | }
157 | }
158 |
159 |
160 |
161 |
162 |
163 |
164 | void u8g2_DrawHXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
165 | {
166 | uint8_t mask;
167 | uint8_t color = u8g2->draw_color;
168 | uint8_t ncolor = (color == 0 ? 1 : 0);
169 | #ifdef U8G2_WITH_INTERSECTION
170 | if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
171 | return;
172 | #endif /* U8G2_WITH_INTERSECTION */
173 |
174 | mask = 1;
175 | while(len > 0)
176 | {
177 | if( u8x8_pgm_read(b) & mask ) {
178 | u8g2->draw_color = color;
179 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
180 | } else if( u8g2->bitmap_transparency == 0 ) {
181 | u8g2->draw_color = ncolor;
182 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
183 | }
184 |
185 | x++;
186 | mask <<= 1;
187 | if ( mask == 0 )
188 | {
189 | mask = 1;
190 | b++;
191 | }
192 | len--;
193 | }
194 | u8g2->draw_color = color;
195 | }
196 |
197 |
198 | void u8g2_DrawXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
199 | {
200 | u8g2_uint_t blen;
201 | blen = w;
202 | blen += 7;
203 | blen >>= 3;
204 | #ifdef U8G2_WITH_INTERSECTION
205 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
206 | return;
207 | #endif /* U8G2_WITH_INTERSECTION */
208 |
209 | while( h > 0 )
210 | {
211 | u8g2_DrawHXBMP(u8g2, x, y, w, bitmap);
212 | bitmap += blen;
213 | y++;
214 | h--;
215 | }
216 | }
217 |
218 |
219 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_box.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_box.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | /*
39 | draw a filled box
40 | restriction: does not work for w = 0 or h = 0
41 | */
42 | void u8g2_DrawBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
43 | {
44 | #ifdef U8G2_WITH_INTERSECTION
45 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
46 | return;
47 | #endif /* U8G2_WITH_INTERSECTION */
48 | while( h != 0 )
49 | {
50 | u8g2_DrawHVLine(u8g2, x, y, w, 0);
51 | y++;
52 | h--;
53 | }
54 | }
55 |
56 |
57 | /*
58 | draw a frame (empty box)
59 | restriction: does not work for w = 0 or h = 0
60 | ToDo:
61 | pixel in the corners are drawn twice. This could be optimized.
62 | */
63 | void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
64 | {
65 | u8g2_uint_t xtmp = x;
66 |
67 | #ifdef U8G2_WITH_INTERSECTION
68 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
69 | return;
70 | #endif /* U8G2_WITH_INTERSECTION */
71 |
72 | u8g2_DrawHVLine(u8g2, x, y, w, 0);
73 | u8g2_DrawHVLine(u8g2, x, y, h, 1);
74 | x+=w;
75 | x--;
76 | u8g2_DrawHVLine(u8g2, x, y, h, 1);
77 | y+=h;
78 | y--;
79 | u8g2_DrawHVLine(u8g2, xtmp, y, w, 0);
80 | }
81 |
82 |
83 |
84 |
85 | void u8g2_DrawRBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
86 | {
87 | u8g2_uint_t xl, yu;
88 | u8g2_uint_t yl, xr;
89 |
90 | #ifdef U8G2_WITH_INTERSECTION
91 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
92 | return;
93 | #endif /* U8G2_WITH_INTERSECTION */
94 |
95 | xl = x;
96 | xl += r;
97 | yu = y;
98 | yu += r;
99 |
100 | xr = x;
101 | xr += w;
102 | xr -= r;
103 | xr -= 1;
104 |
105 | yl = y;
106 | yl += h;
107 | yl -= r;
108 | yl -= 1;
109 |
110 | u8g2_DrawDisc(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
111 | u8g2_DrawDisc(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
112 | u8g2_DrawDisc(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
113 | u8g2_DrawDisc(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
114 |
115 | {
116 | u8g2_uint_t ww, hh;
117 |
118 | ww = w;
119 | ww -= r;
120 | ww -= r;
121 | xl++;
122 | yu++;
123 |
124 | if ( ww >= 3 )
125 | {
126 | ww -= 2;
127 | u8g2_DrawBox(u8g2, xl, y, ww, r+1);
128 | u8g2_DrawBox(u8g2, xl, yl, ww, r+1);
129 | }
130 |
131 | hh = h;
132 | hh -= r;
133 | hh -= r;
134 | //h--;
135 | if ( hh >= 3 )
136 | {
137 | hh -= 2;
138 | u8g2_DrawBox(u8g2, x, yu, w, hh);
139 | }
140 | }
141 | }
142 |
143 |
144 | void u8g2_DrawRFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
145 | {
146 | u8g2_uint_t xl, yu;
147 |
148 | #ifdef U8G2_WITH_INTERSECTION
149 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
150 | return;
151 | #endif /* U8G2_WITH_INTERSECTION */
152 |
153 | xl = x;
154 | xl += r;
155 | yu = y;
156 | yu += r;
157 |
158 | {
159 | u8g2_uint_t yl, xr;
160 |
161 | xr = x;
162 | xr += w;
163 | xr -= r;
164 | xr -= 1;
165 |
166 | yl = y;
167 | yl += h;
168 | yl -= r;
169 | yl -= 1;
170 |
171 | u8g2_DrawCircle(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
172 | u8g2_DrawCircle(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
173 | u8g2_DrawCircle(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
174 | u8g2_DrawCircle(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
175 | }
176 |
177 | {
178 | u8g2_uint_t ww, hh;
179 |
180 | ww = w;
181 | ww -= r;
182 | ww -= r;
183 | hh = h;
184 | hh -= r;
185 | hh -= r;
186 |
187 | xl++;
188 | yu++;
189 |
190 | if ( ww >= 3 )
191 | {
192 | ww -= 2;
193 | h--;
194 | u8g2_DrawHLine(u8g2, xl, y, ww);
195 | u8g2_DrawHLine(u8g2, xl, y+h, ww);
196 | }
197 |
198 | if ( hh >= 3 )
199 | {
200 | hh -= 2;
201 | w--;
202 | u8g2_DrawVLine(u8g2, x, yu, hh);
203 | u8g2_DrawVLine(u8g2, x+w, yu, hh);
204 | }
205 | }
206 | }
207 |
208 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_buffer.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_buffer.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 | #include
38 |
39 | /*============================================*/
40 | void u8g2_ClearBuffer(u8g2_t *u8g2)
41 | {
42 | size_t cnt;
43 | cnt = u8g2_GetU8x8(u8g2)->display_info->tile_width;
44 | cnt *= u8g2->tile_buf_height;
45 | cnt *= 8;
46 | memset(u8g2->tile_buf_ptr, 0, cnt);
47 | }
48 |
49 | /*============================================*/
50 |
51 | static void u8g2_send_tile_row(u8g2_t *u8g2, uint8_t src_tile_row, uint8_t dest_tile_row)
52 | {
53 | uint8_t *ptr;
54 | uint16_t offset;
55 | uint8_t w;
56 |
57 | w = u8g2_GetU8x8(u8g2)->display_info->tile_width;
58 | offset = src_tile_row;
59 | ptr = u8g2->tile_buf_ptr;
60 | offset *= w;
61 | offset *= 8;
62 | ptr += offset;
63 | u8x8_DrawTile(u8g2_GetU8x8(u8g2), 0, dest_tile_row, w, ptr);
64 | }
65 |
66 | /*
67 | write the buffer to the display RAM.
68 | For most displays, this will make the content visible to the user.
69 | Some displays (like the SSD1606) require a u8x8_RefreshDisplay()
70 | */
71 | static void u8g2_send_buffer(u8g2_t *u8g2) U8X8_NOINLINE;
72 | static void u8g2_send_buffer(u8g2_t *u8g2)
73 | {
74 | uint8_t src_row;
75 | uint8_t src_max;
76 | uint8_t dest_row;
77 | uint8_t dest_max;
78 |
79 | src_row = 0;
80 | src_max = u8g2->tile_buf_height;
81 | dest_row = u8g2->tile_curr_row;
82 | dest_max = u8g2_GetU8x8(u8g2)->display_info->tile_height;
83 |
84 | do
85 | {
86 | u8g2_send_tile_row(u8g2, src_row, dest_row);
87 | src_row++;
88 | dest_row++;
89 | } while( src_row < src_max && dest_row < dest_max );
90 | }
91 |
92 | /* same as u8g2_send_buffer but also send the DISPLAY_REFRESH message (used by SSD1606) */
93 | void u8g2_SendBuffer(u8g2_t *u8g2)
94 | {
95 | u8g2_send_buffer(u8g2);
96 | u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
97 | }
98 |
99 | /*============================================*/
100 | void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row)
101 | {
102 | u8g2->tile_curr_row = row;
103 | u8g2->cb->update_dimension(u8g2);
104 | u8g2->cb->update_page_win(u8g2);
105 | }
106 |
107 | void u8g2_FirstPage(u8g2_t *u8g2)
108 | {
109 | if ( u8g2->is_auto_page_clear )
110 | {
111 | u8g2_ClearBuffer(u8g2);
112 | }
113 | u8g2_SetBufferCurrTileRow(u8g2, 0);
114 | }
115 |
116 | uint8_t u8g2_NextPage(u8g2_t *u8g2)
117 | {
118 | uint8_t row;
119 | u8g2_send_buffer(u8g2);
120 | row = u8g2->tile_curr_row;
121 | row += u8g2->tile_buf_height;
122 | if ( row >= u8g2_GetU8x8(u8g2)->display_info->tile_height )
123 | {
124 | u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
125 | return 0;
126 | }
127 | if ( u8g2->is_auto_page_clear )
128 | {
129 | u8g2_ClearBuffer(u8g2);
130 | }
131 | u8g2_SetBufferCurrTileRow(u8g2, row);
132 | return 1;
133 | }
134 |
135 |
136 |
137 | /*============================================*/
138 | /*
139 | Description:
140 | Update a sub area of the display, given by tile position, width and height.
141 | The arguments are "tile" coordinates. Any u8g2 rotation is ignored.
142 | This procedure only checks whether full buffer mode is active.
143 | There is no error checking for the arguments: It is the responsibility of the
144 | user to ensure, that the provided arguments are correct.
145 |
146 | Limitations:
147 | - Only available in full buffer mode (will not do anything in page mode)
148 | - Tile positions and sizes (pixel position divided by 8)
149 | - Any display rotation/mirror is ignored
150 | - Only works with displays, which support U8x8 API
151 | - Will not send the e-paper refresh message (will probably not work with e-paper devices)
152 | */
153 | void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th)
154 | {
155 | uint16_t page_size;
156 | uint8_t *ptr;
157 |
158 | /* check, whether we are in full buffer mode */
159 | if ( u8g2->tile_buf_height != u8g2_GetU8x8(u8g2)->display_info->tile_height )
160 | return; /* not in full buffer mode, do nothing */
161 |
162 | page_size = u8g2->pixel_buf_width; /* 8*u8g2->u8g2_GetU8x8(u8g2)->display_info->tile_width */
163 |
164 | ptr = u8g2_GetBufferPtr(u8g2);
165 | ptr += tx*8;
166 | ptr += page_size*ty;
167 |
168 | while( th > 0 )
169 | {
170 | u8x8_DrawTile( u8g2_GetU8x8(u8g2), tx, ty, tw, ptr );
171 | ptr += page_size;
172 | ty++;
173 | th--;
174 | }
175 | }
176 |
177 | /* same as sendBuffer, but does not send the ePaper refresh message */
178 | void u8g2_UpdateDisplay(u8g2_t *u8g2)
179 | {
180 | u8g2_send_buffer(u8g2);
181 | }
182 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_cleardisplay.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_cleardisplay.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 | #include "u8g2.h"
36 |
37 | /* Clear screen buffer & display reliable for all u8g2 displays. */
38 | /* This is done with u8g2 picture loop, because we can not use the u8x8 function in all cases */
39 | void u8g2_ClearDisplay(u8g2_t *u8g2)
40 | {
41 | u8g2_FirstPage(u8g2);
42 | do {
43 | } while ( u8g2_NextPage(u8g2) );
44 | /*
45 | This function is usually called during startup (u8g2.begin()).
46 | However the user might want to use full buffer mode with clear and
47 | send commands.
48 | This will not work because the current tile row is modified by the picture
49 | loop above. To fix this, reset the tile row to 0, issue #370
50 | A workaround would be, that the user sets the current tile row to 0 manually.
51 | */
52 | u8g2_SetBufferCurrTileRow(u8g2, 0);
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_fonts.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eziya/STM32_HAL_U8G2_OLED/cec4c5ceac4937fb9d6c65c932ef5553c3821841/Src/u8g2/u8g2_fonts.c
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_input_value.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_input_value.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | /*
39 | return:
40 | 0: value is not changed (HOME/Break Button pressed)
41 | 1: value has been updated
42 | */
43 |
44 | uint8_t u8g2_UserInterfaceInputValue(u8g2_t *u8g2, const char *title, const char *pre, uint8_t *value, uint8_t lo, uint8_t hi, uint8_t digits, const char *post)
45 | {
46 | uint8_t line_height;
47 | uint8_t height;
48 | u8g2_uint_t pixel_height;
49 | u8g2_uint_t y, yy;
50 | u8g2_uint_t pixel_width;
51 | u8g2_uint_t x, xx;
52 |
53 | uint8_t local_value = *value;
54 | //uint8_t r; /* not used ??? */
55 | uint8_t event;
56 |
57 | /* only horizontal strings are supported, so force this here */
58 | u8g2_SetFontDirection(u8g2, 0);
59 |
60 | /* force baseline position */
61 | u8g2_SetFontPosBaseline(u8g2);
62 |
63 | /* calculate line height */
64 | line_height = u8g2_GetAscent(u8g2);
65 | line_height -= u8g2_GetDescent(u8g2);
66 |
67 |
68 | /* calculate overall height of the input value box */
69 | height = 1; /* value input line */
70 | height += u8x8_GetStringLineCnt(title);
71 |
72 | /* calculate the height in pixel */
73 | pixel_height = height;
74 | pixel_height *= line_height;
75 |
76 |
77 | /* calculate offset from top */
78 | y = 0;
79 | if ( pixel_height < u8g2_GetDisplayHeight(u8g2) )
80 | {
81 | y = u8g2_GetDisplayHeight(u8g2);
82 | y -= pixel_height;
83 | y /= 2;
84 | }
85 |
86 | /* calculate offset from left for the label */
87 | x = 0;
88 | pixel_width = u8g2_GetUTF8Width(u8g2, pre);
89 | pixel_width += u8g2_GetUTF8Width(u8g2, "0") * digits;
90 | pixel_width += u8g2_GetUTF8Width(u8g2, post);
91 | if ( pixel_width < u8g2_GetDisplayWidth(u8g2) )
92 | {
93 | x = u8g2_GetDisplayWidth(u8g2);
94 | x -= pixel_width;
95 | x /= 2;
96 | }
97 |
98 | /* event loop */
99 | for(;;)
100 | {
101 | u8g2_FirstPage(u8g2);
102 | do
103 | {
104 | /* render */
105 | yy = y;
106 | yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title);
107 | xx = x;
108 | xx += u8g2_DrawUTF8(u8g2, xx, yy, pre);
109 | xx += u8g2_DrawUTF8(u8g2, xx, yy, u8x8_u8toa(local_value, digits));
110 | u8g2_DrawUTF8(u8g2, xx, yy, post);
111 | } while( u8g2_NextPage(u8g2) );
112 |
113 | #ifdef U8G2_REF_MAN_PIC
114 | return 0;
115 | #endif
116 |
117 | for(;;)
118 | {
119 | event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
120 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
121 | {
122 | *value = local_value;
123 | return 1;
124 | }
125 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
126 | {
127 | return 0;
128 | }
129 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
130 | {
131 | if ( local_value >= hi )
132 | local_value = lo;
133 | else
134 | local_value++;
135 | break;
136 | }
137 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
138 | {
139 | if ( local_value <= lo )
140 | local_value = hi;
141 | else
142 | local_value--;
143 | break;
144 | }
145 | }
146 | }
147 |
148 | /* never reached */
149 | //return r;
150 | }
151 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_intersection.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_intersection.c
4 |
5 | Intersection calculation, code taken from u8g_clip.c
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8g2.h"
39 |
40 | #ifdef __GNUC__
41 | #define U8G2_ALWAYS_INLINE __inline__ __attribute__((always_inline))
42 | #else
43 | #define U8G2_ALWAYS_INLINE
44 | #endif
45 |
46 |
47 | #if defined(U8G2_WITH_INTERSECTION) || defined(U8G2_WITH_CLIP_WINDOW_SUPPORT)
48 |
49 | #ifdef OLD_VERSION_WITH_SYMETRIC_BOUNDARIES
50 |
51 | /*
52 | intersection assumptions:
53 | a1 <= a2 is always true
54 |
55 | minimized version
56 | ---1----0 1 b1 <= a2 && b1 > b2
57 | -----1--0 1 b2 >= a1 && b1 > b2
58 | ---1-1--- 1 b1 <= a2 && b2 >= a1
59 | */
60 |
61 |
62 | /*
63 | calculate the intersection between a0/a1 and v0/v1
64 | The intersection check returns one if the range of a0/a1 has an intersection with v0/v1.
65 | The intersection check includes the boundary values v1 and a1.
66 |
67 | The following asserts will succeed:
68 | assert( u8g2_is_intersection_decision_tree(4, 6, 7, 9) == 0 );
69 | assert( u8g2_is_intersection_decision_tree(4, 6, 6, 9) != 0 );
70 | assert( u8g2_is_intersection_decision_tree(6, 9, 4, 6) != 0 );
71 | assert( u8g2_is_intersection_decision_tree(7, 9, 4, 6) == 0 );
72 | */
73 |
74 | //static uint8_t U8G2_ALWAYS_INLINE u8g2_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
75 | static uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
76 | {
77 | if ( v0 <= a1 )
78 | {
79 | if ( v1 >= a0 )
80 | {
81 | return 1;
82 | }
83 | else
84 | {
85 | if ( v0 > v1 )
86 | {
87 | return 1;
88 | }
89 | else
90 | {
91 | return 0;
92 | }
93 | }
94 | }
95 | else
96 | {
97 | if ( v1 >= a0 )
98 | {
99 | if ( v0 > v1 )
100 | {
101 | return 1;
102 | }
103 | else
104 | {
105 | return 0;
106 | }
107 | }
108 | else
109 | {
110 | return 0;
111 | }
112 | }
113 | }
114 |
115 | #endif /* OLD_VERSION_WITH_SYMETRIC_BOUNDARIES */
116 |
117 |
118 | /*
119 | version with asymetric boundaries.
120 | a1 and v1 are excluded
121 | v0 == v1 is not support end return 1
122 | */
123 | uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
124 | {
125 | if ( v0 < a1 ) // v0 <= a1
126 | {
127 | if ( v1 > a0 ) // v1 >= a0
128 | {
129 | return 1;
130 | }
131 | else
132 | {
133 | if ( v0 > v1 ) // v0 > v1
134 | {
135 | return 1;
136 | }
137 | else
138 | {
139 | return 0;
140 | }
141 | }
142 | }
143 | else
144 | {
145 | if ( v1 > a0 ) // v1 >= a0
146 | {
147 | if ( v0 > v1 ) // v0 > v1
148 | {
149 | return 1;
150 | }
151 | else
152 | {
153 | return 0;
154 | }
155 | }
156 | else
157 | {
158 | return 0;
159 | }
160 | }
161 | }
162 |
163 |
164 |
165 | /* upper limits are not included (asymetric boundaries) */
166 | uint8_t u8g2_IsIntersection(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t x1, u8g2_uint_t y1)
167 | {
168 | if ( u8g2_is_intersection_decision_tree(u8g2->user_y0, u8g2->user_y1, y0, y1) == 0 )
169 | return 0;
170 |
171 | return u8g2_is_intersection_decision_tree(u8g2->user_x0, u8g2->user_x1, x0, x1);
172 | }
173 |
174 |
175 | #endif /* U8G2_WITH_INTERSECTION */
176 |
177 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_kerning.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_kerning.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | /* this function is used as "u8g2_get_kerning_cb" */
39 | /*
40 | uint8_t u8g2_GetNullKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2)
41 | {
42 | return 0;
43 | }
44 | */
45 |
46 | /* this function is used as "u8g2_get_kerning_cb" */
47 | uint8_t u8g2_GetKerning(U8X8_UNUSED u8g2_t *u8g2, u8g2_kerning_t *kerning, uint16_t e1, uint16_t e2)
48 | {
49 | uint16_t i1, i2, cnt, end;
50 | if ( kerning == NULL )
51 | return 0;
52 |
53 | /* search for the encoding in the first table */
54 | cnt = kerning->first_table_cnt;
55 | cnt--; /* ignore the last element of the table, which is 0x0ffff */
56 | for( i1 = 0; i1 < cnt; i1++ )
57 | {
58 | if ( kerning->first_encoding_table[i1] == e1 )
59 | break;
60 | }
61 | if ( i1 >= cnt )
62 | return 0; /* e1 not part of the kerning table, return 0 */
63 |
64 | /* get the upper index for i2 */
65 | end = kerning->index_to_second_table[i1+1];
66 | for( i2 = kerning->index_to_second_table[i1]; i2 < end; i2++ )
67 | {
68 | if ( kerning->second_encoding_table[i2] == e2 )
69 | break;
70 | }
71 |
72 | if ( i2 >= end )
73 | return 0; /* e2 not part of any pair with e1, return 0 */
74 |
75 | return kerning->kerning_values[i2];
76 | }
77 |
78 | uint8_t u8g2_GetKerningByTable(U8X8_UNUSED u8g2_t *u8g2, const uint16_t *kt, uint16_t e1, uint16_t e2)
79 | {
80 | uint16_t i;
81 | i = 0;
82 | if ( kt == NULL )
83 | return 0;
84 | for(;;)
85 | {
86 | if ( kt[i] == 0x0ffff )
87 | break;
88 | if ( kt[i] == e1 && kt[i+1] == e2 )
89 | return kt[i+2];
90 | i+=3;
91 | }
92 | return 0;
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_line.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_box.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 |
39 | void u8g2_DrawLine(u8g2_t *u8g2, u8g2_uint_t x1, u8g2_uint_t y1, u8g2_uint_t x2, u8g2_uint_t y2)
40 | {
41 | u8g2_uint_t tmp;
42 | u8g2_uint_t x,y;
43 | u8g2_uint_t dx, dy;
44 | u8g2_int_t err;
45 | u8g2_int_t ystep;
46 |
47 | uint8_t swapxy = 0;
48 |
49 | /* no intersection check at the moment, should be added... */
50 |
51 | if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1;
52 | if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1;
53 |
54 | if ( dy > dx )
55 | {
56 | swapxy = 1;
57 | tmp = dx; dx =dy; dy = tmp;
58 | tmp = x1; x1 =y1; y1 = tmp;
59 | tmp = x2; x2 =y2; y2 = tmp;
60 | }
61 | if ( x1 > x2 )
62 | {
63 | tmp = x1; x1 =x2; x2 = tmp;
64 | tmp = y1; y1 =y2; y2 = tmp;
65 | }
66 | err = dx >> 1;
67 | if ( y2 > y1 ) ystep = 1; else ystep = -1;
68 | y = y1;
69 |
70 | #ifndef U8G2_16BIT
71 | if ( x2 == 255 )
72 | x2--;
73 | #else
74 | if ( x2 == 0xffff )
75 | x2--;
76 | #endif
77 |
78 | for( x = x1; x <= x2; x++ )
79 | {
80 | if ( swapxy == 0 )
81 | u8g2_DrawPixel(u8g2, x, y);
82 | else
83 | u8g2_DrawPixel(u8g2, y, x);
84 | err -= (uint8_t)dy;
85 | if ( err < 0 )
86 | {
87 | y += (u8g2_uint_t)ystep;
88 | err += (u8g2_uint_t)dx;
89 | }
90 | }
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/Src/u8g2/u8g2_message.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_message.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | #define SPACE_BETWEEN_BUTTONS_IN_PIXEL 6
39 | #define SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL 3
40 |
41 | uint8_t u8g2_draw_button_line(u8g2_t *u8g2, u8g2_uint_t y, u8g2_uint_t w, uint8_t cursor, const char *s)
42 | {
43 | u8g2_uint_t button_line_width;
44 |
45 | uint8_t i;
46 | uint8_t cnt;
47 | uint8_t is_invert;
48 |
49 | u8g2_uint_t d;
50 | u8g2_uint_t x;
51 |
52 | cnt = u8x8_GetStringLineCnt(s);
53 |
54 |
55 | /* calculate the width of the button line */
56 | button_line_width = 0;
57 | for( i = 0; i < cnt; i++ )
58 | {
59 | button_line_width += u8g2_GetUTF8Width(u8g2, u8x8_GetStringLineStart(i, s));
60 | }
61 | button_line_width += (cnt-1)*SPACE_BETWEEN_BUTTONS_IN_PIXEL; /* add some space between the buttons */
62 |
63 | /* calculate the left offset */
64 | d = 0;
65 | if ( button_line_width < w )
66 | {
67 | d = w;
68 | d -= button_line_width;
69 | d /= 2;
70 | }
71 |
72 | /* draw the buttons */
73 | x = d;
74 | for( i = 0; i < cnt; i++ )
75 | {
76 | is_invert = 0;
77 | if ( i == cursor )
78 | is_invert = 1;
79 |
80 | u8g2_DrawUTF8Line(u8g2, x, y, 0, u8x8_GetStringLineStart(i, s), 1, is_invert);
81 | x += u8g2_GetUTF8Width(u8g2, u8x8_GetStringLineStart(i, s));
82 | x += SPACE_BETWEEN_BUTTONS_IN_PIXEL;
83 | }
84 |
85 | /* return the number of buttons */
86 | return cnt;
87 | }
88 |
89 | /*
90 | title1: Multiple lines,separated by '\n'
91 | title2: A single line/string which is terminated by '\0' or '\n' . "title2" accepts the return value from u8x8_GetStringLineStart()
92 | title3: Multiple lines,separated by '\n'
93 | buttons: one more more buttons separated by '\n' and terminated with '\0'
94 | side effects:
95 | u8g2_SetFontDirection(u8g2, 0);
96 | u8g2_SetFontPosBaseline(u8g2);
97 | */
98 |
99 | uint8_t u8g2_UserInterfaceMessage(u8g2_t *u8g2, const char *title1, const char *title2, const char *title3, const char *buttons)
100 | {
101 | uint8_t height;
102 | uint8_t line_height;
103 | u8g2_uint_t pixel_height;
104 | u8g2_uint_t y, yy;
105 |
106 | uint8_t cursor = 0;
107 | uint8_t button_cnt;
108 | uint8_t event;
109 |
110 | /* only horizontal strings are supported, so force this here */
111 | u8g2_SetFontDirection(u8g2, 0);
112 |
113 | /* force baseline position */
114 | u8g2_SetFontPosBaseline(u8g2);
115 |
116 |
117 | /* calculate line height */
118 | line_height = u8g2_GetAscent(u8g2);
119 | line_height -= u8g2_GetDescent(u8g2);
120 |
121 | /* calculate overall height of the message box in lines*/
122 | height = 1; /* button line */
123 | height += u8x8_GetStringLineCnt(title1);
124 | if ( title2 != NULL )
125 | height++;
126 | height += u8x8_GetStringLineCnt(title3);
127 |
128 | /* calculate the height in pixel */
129 | pixel_height = height;
130 | pixel_height *= line_height;
131 |
132 | /* ... and add the space between the text and the buttons */
133 | pixel_height +=SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL;
134 |
135 | /* calculate offset from top */
136 | y = 0;
137 | if ( pixel_height < u8g2_GetDisplayHeight(u8g2) )
138 | {
139 | y = u8g2_GetDisplayHeight(u8g2);
140 | y -= pixel_height;
141 | y /= 2;
142 | }
143 | y += u8g2_GetAscent(u8g2);
144 |
145 |
146 | for(;;)
147 | {
148 | u8g2_FirstPage(u8g2);
149 | do
150 | {
151 | yy = y;
152 | /* draw message box */
153 |
154 | yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title1);
155 | if ( title2 != NULL )
156 | {
157 | u8g2_DrawUTF8Line(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), title2, 0, 0);
158 | yy+=line_height;
159 | }
160 | yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title3);
161 | yy += SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL;
162 |
163 | button_cnt = u8g2_draw_button_line(u8g2, yy, u8g2_GetDisplayWidth(u8g2), cursor, buttons);
164 |
165 | } while( u8g2_NextPage(u8g2) );
166 |
167 | #ifdef U8G2_REF_MAN_PIC
168 | return 0;
169 | #endif
170 |
171 | for(;;)
172 | {
173 | event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
174 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
175 | return cursor+1;
176 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
177 | return 0;
178 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
179 | {
180 | cursor++;
181 | if ( cursor >= button_cnt )
182 | cursor = 0;
183 | break;
184 | }
185 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
186 | {
187 | if ( cursor == 0 )
188 | cursor = button_cnt;
189 | cursor--;
190 | break;
191 | }
192 | }
193 | }
194 | /* never reached */
195 | //return 0;
196 | }
197 |
198 |
--------------------------------------------------------------------------------
/Src/u8g2/u8log_u8g2.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8log_u8g2.c
4 |
5 |
6 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
7 |
8 | Copyright (c) 2018, olikraus@gmail.com
9 | All rights reserved.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | * Redistributions of source code must retain the above copyright notice, this list
15 | of conditions and the following disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above copyright notice, this
18 | list of conditions and the following disclaimer in the documentation and/or other
19 | materials provided with the distribution.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 | */
36 |
37 | #include "u8g2.h"
38 | /*
39 | Draw the u8log text at the specified x/y position.
40 | x/y position is the reference position of the first char of the first line.
41 | the line height is
42 | u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2) + line_height_offset;
43 | line_height_offset can be set with u8log_SetLineHeightOffset()
44 | Use
45 | u8g2_SetFontRefHeightText(u8g2_t *u8g2);
46 | u8g2_SetFontRefHeightExtendedText(u8g2_t *u8g2);
47 | u8g2_SetFontRefHeightAll(u8g2_t *u8g2);
48 | to change the return values for u8g2_GetAscent and u8g2_GetDescent
49 |
50 | */
51 | void u8g2_DrawLog(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8log_t *u8log)
52 | {
53 | u8g2_uint_t disp_x, disp_y;
54 | uint8_t buf_x, buf_y;
55 | uint8_t c;
56 |
57 | disp_y = y;
58 | u8g2_SetFontDirection(u8g2, 0);
59 | for( buf_y = 0; buf_y < u8log->height; buf_y++ )
60 | {
61 | disp_x = x;
62 | for( buf_x = 0; buf_x < u8log->width; buf_x++ )
63 | {
64 | c = u8log->screen_buffer[buf_y * u8log->width + buf_x];
65 | disp_x += u8g2_DrawGlyph(u8g2, disp_x, disp_y, c);
66 | }
67 | disp_y += u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2);
68 | disp_y += u8log->line_height_offset;
69 | }
70 | }
71 |
72 | /*
73 | u8lib callback for u8g2
74 |
75 | Only font direction 0 is supported: u8g2_SetFontDirection(u8g2, 0)
76 | Use
77 | u8g2_SetFontRefHeightText(u8g2_t *u8g2);
78 | u8g2_SetFontRefHeightExtendedText(u8g2_t *u8g2);
79 | u8g2_SetFontRefHeightAll(u8g2_t *u8g2);
80 | to change the top offset and the line height and
81 | u8log_SetLineHeightOffset(u8log_t *u8log, int8_t line_height_offset)
82 | to change the line height.
83 |
84 | */
85 | void u8log_u8g2_cb(u8log_t * u8log)
86 | {
87 | u8g2_t *u8g2 = (u8g2_t *)(u8log->aux_data);
88 | if ( u8log->is_redraw_line || u8log->is_redraw_all )
89 | {
90 | u8g2_FirstPage(u8g2);
91 | do
92 | {
93 | u8g2_DrawLog( u8g2, 0, u8g2_GetAscent(u8g2), u8log);
94 | }
95 | while( u8g2_NextPage(u8g2) );
96 | }
97 | }
98 |
99 |
--------------------------------------------------------------------------------
/Src/u8g2/u8log_u8x8.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8log_u8x8.c
4 |
5 |
6 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
7 |
8 | Copyright (c) 2018, olikraus@gmail.com
9 | All rights reserved.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | * Redistributions of source code must retain the above copyright notice, this list
15 | of conditions and the following disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above copyright notice, this
18 | list of conditions and the following disclaimer in the documentation and/or other
19 | materials provided with the distribution.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 | */
36 |
37 | #include "u8x8.h"
38 |
39 | static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log) U8X8_NOINLINE;
40 | static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log)
41 | {
42 | uint8_t buf_x;
43 | uint8_t c;
44 | for( buf_x = 0; buf_x < u8log->width; buf_x++ )
45 | {
46 | c = u8log->screen_buffer[buf_y * u8log->width + buf_x];
47 | u8x8_DrawGlyph(u8x8, disp_x, disp_y, c);
48 | disp_x++;
49 | }
50 | }
51 |
52 | void u8x8_DrawLog(u8x8_t *u8x8, uint8_t x, uint8_t y, u8log_t *u8log)
53 | {
54 | uint8_t buf_y;
55 | for( buf_y = 0; buf_y < u8log->height; buf_y++ )
56 | {
57 | u8x8_DrawLogLine(u8x8, x, y, buf_y, u8log);
58 | y++;
59 | }
60 | }
61 |
62 |
63 | void u8log_u8x8_cb(u8log_t * u8log)
64 | {
65 | u8x8_t *u8x8 = (u8x8_t *)(u8log->aux_data);
66 | if ( u8log->is_redraw_all )
67 | {
68 | u8x8_DrawLog(u8x8, 0, 0, u8log);
69 | }
70 | else if ( u8log->is_redraw_line )
71 | {
72 | u8x8_DrawLogLine(u8x8, 0, u8log->redraw_line, u8log->redraw_line, u8log);
73 | }
74 | }
75 |
76 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_d_a2printer.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_a2printer.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | Use DC2 bitmap command of the A2 Micro panel termal printer
36 | double stroke
37 |
38 |
39 | */
40 |
41 |
42 | #include "u8x8.h"
43 |
44 | #define LINE_MIN_DELAY_MS 15
45 | /* higher values improve quality */
46 | /* however if the value is too high (>=5) then form feed does not work any more */
47 | #define LINE_EXTRA_8PIXEL_DELAY_MS 3
48 | /* this must be a power of two and between 1 and 8 */
49 | /* best quality only with 1 */
50 | #define NO_OF_LINES_TO_SEND_WITHOUT_DELAY 1
51 |
52 | /* calculates the delay, based on the number of black pixel */
53 | /* actually only "none-zero" bytes are calculated which is, of course not so accurate, but should be good enough */
54 | uint16_t get_delay_in_milliseconds(uint8_t cnt, uint8_t *data)
55 | {
56 | uint8_t i;
57 | uint16_t time = LINE_MIN_DELAY_MS;
58 | for ( i = 0; i < cnt; i++ )
59 | if ( data[i] != 0 )
60 | time += LINE_EXTRA_8PIXEL_DELAY_MS;
61 | return time;
62 | }
63 |
64 | uint8_t u8x8_d_a2printer_common(u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, void *arg_ptr)
65 | {
66 | uint8_t c, i, j;
67 | uint8_t *ptr;
68 | uint16_t delay_in_milliseconds;
69 | switch(msg)
70 | {
71 | /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */
72 | /*
73 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
74 | break;
75 | */
76 | case U8X8_MSG_DISPLAY_INIT:
77 | u8x8_d_helper_display_init(u8x8);
78 | // no setup required
79 | // u8x8_cad_SendSequence(u8x8, u8x8_d_a2printer_init_seq);
80 | break;
81 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
82 | // no powersave
83 | break;
84 | case U8X8_MSG_DISPLAY_DRAW_TILE:
85 | u8x8_cad_StartTransfer(u8x8);
86 |
87 | u8x8_cad_SendCmd(u8x8, 27); /* ESC */
88 | u8x8_cad_SendCmd(u8x8, 55 ); /* parameter command */
89 | /* increasing the "max printing dots" requires a good power supply, but LINE_EXTRA_8PIXEL_DELAY_MS could be reduced then */
90 | u8x8_cad_SendCmd(u8x8, 0); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1) ... lower values improve, probably my current supply is not sufficient */
91 | u8x8_cad_SendCmd(u8x8, 200); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
92 | u8x8_cad_SendCmd(u8x8, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us) ... does not have much influence */
93 |
94 | //c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */
95 | c = u8x8->display_info->tile_width;
96 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* data ptr to the tiles */
97 |
98 | u8x8_cad_SendCmd(u8x8, 18); /* DC2 */
99 | u8x8_cad_SendCmd(u8x8, 42 ); /* * */
100 | u8x8_cad_SendCmd(u8x8, 8 ); /* height */
101 | u8x8_cad_SendCmd(u8x8, c ); /* c, u8x8->display_info->tile_width */
102 |
103 | for( j = 0; j < 8 / NO_OF_LINES_TO_SEND_WITHOUT_DELAY; j ++ )
104 | {
105 |
106 | delay_in_milliseconds = 0;
107 | for( i = 0; i < NO_OF_LINES_TO_SEND_WITHOUT_DELAY; i++ )
108 | {
109 | u8x8_cad_SendData(u8x8, c, ptr); /* c, note: SendData can not handle more than 255 bytes, send one line of data */
110 | delay_in_milliseconds += get_delay_in_milliseconds(c, ptr);
111 | ptr += c;
112 | }
113 |
114 | while( delay_in_milliseconds > 200 )
115 | {
116 | u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_MILLI, 200, NULL);
117 | delay_in_milliseconds -= 200;
118 | }
119 | u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_MILLI, delay_in_milliseconds, NULL);
120 | }
121 |
122 | /* set parameters back to their default values */
123 | u8x8_cad_SendCmd(u8x8, 27); /* ESC */
124 | u8x8_cad_SendCmd(u8x8, 55 ); /* parameter command */
125 | u8x8_cad_SendCmd(u8x8, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
126 | u8x8_cad_SendCmd(u8x8, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
127 | u8x8_cad_SendCmd(u8x8, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
128 |
129 | u8x8_cad_EndTransfer(u8x8);
130 |
131 | break;
132 | default:
133 | return 0;
134 | }
135 | return 1;
136 | }
137 |
138 |
139 | static const u8x8_display_info_t u8x8_a2printer_384x240_display_info =
140 | {
141 | /* most of the settings are not required, because this is a serial RS232 printer */
142 |
143 | /* chip_enable_level = */ 1,
144 | /* chip_disable_level = */ 0,
145 |
146 | /* post_chip_enable_wait_ns = */ 5,
147 | /* pre_chip_disable_wait_ns = */ 5,
148 | /* reset_pulse_width_ms = */ 1,
149 | /* post_reset_wait_ms = */ 6,
150 | /* sda_setup_time_ns = */ 20,
151 | /* sck_pulse_width_ns = */ 140,
152 | /* sck_clock_hz = */ 1000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
153 | /* spi_mode = */ 0, /* old: sck_takeover_edge, new: active high (bit 1), rising edge (bit 0) */
154 | /* i2c_bus_clock_100kHz = */ 4,
155 | /* data_setup_time_ns = */ 30,
156 | /* write_pulse_width_ns = */ 40,
157 | /* tile_width = */ 48,
158 | /* tile_hight = */ 30,
159 | /* default_x_offset = */ 0,
160 | /* flipmode_x_offset = */ 0,
161 | /* pixel_width = */ 384,
162 | /* pixel_height = */ 240
163 | };
164 |
165 | uint8_t u8x8_d_a2printer_384x240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
166 | {
167 | switch(msg)
168 | {
169 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
170 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_a2printer_384x240_display_info);
171 | break;
172 | default:
173 | return u8x8_d_a2printer_common(u8x8, msg, arg_int, arg_ptr);
174 | }
175 | return 1;
176 | }
177 |
178 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_d_pcd8544_84x48.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_pcd8544_84x48.c (so called "Nokia 5110" displays)
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | */
36 | #include "u8x8.h"
37 |
38 |
39 |
40 |
41 | static const uint8_t u8x8_d_pcd8544_84x48_init_seq[] = {
42 |
43 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
44 |
45 | U8X8_C(0x021), /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
46 | U8X8_C(0x006), /* temp. control: b10 = 2 */
47 | U8X8_C(0x013), /* bias system 1:48 */
48 | U8X8_C(0x0c0), /* medium Vop */
49 |
50 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
51 | U8X8_C(0x008), /* blank */
52 | U8X8_C(0x024), /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
53 |
54 | U8X8_END_TRANSFER(), /* disable chip */
55 | U8X8_END() /* end of sequence */
56 | };
57 |
58 | static const uint8_t u8x8_d_pcd8544_84x48_powersave0_seq[] = {
59 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
60 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
61 | U8X8_C(0x00c), /* display on */
62 | U8X8_END_TRANSFER(), /* disable chip */
63 | U8X8_END() /* end of sequence */
64 | };
65 |
66 | static const uint8_t u8x8_d_pcd8544_84x48_powersave1_seq[] = {
67 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
68 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
69 | U8X8_C(0x008), /* blank */
70 | U8X8_C(0x024), /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
71 | U8X8_END_TRANSFER(), /* disable chip */
72 | U8X8_END() /* end of sequence */
73 | };
74 |
75 |
76 |
77 | static const u8x8_display_info_t u8x8_pcd8544_84x48_display_info =
78 | {
79 | /* chip_enable_level = */ 0,
80 | /* chip_disable_level = */ 1,
81 |
82 | /* post_chip_enable_wait_ns = */ 5,
83 | /* pre_chip_disable_wait_ns = */ 5,
84 | /* reset_pulse_width_ms = */ 2,
85 | /* post_reset_wait_ms = */ 2,
86 | /* sda_setup_time_ns = */ 12,
87 | /* sck_pulse_width_ns = */ 75, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
88 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
89 | /* spi_mode = */ 0, /* active high, rising edge */
90 | /* i2c_bus_clock_100kHz = */ 4,
91 | /* data_setup_time_ns = */ 30,
92 | /* write_pulse_width_ns = */ 40,
93 | /* tile_width = */ 11, /* width of 11*8=88 pixel */
94 | /* tile_hight = */ 6,
95 | /* default_x_offset = */ 0,
96 | /* flipmode_x_offset = */ 0,
97 | /* pixel_width = */ 84,
98 | /* pixel_height = */ 48
99 | };
100 |
101 | uint8_t u8x8_d_pcd8544_84x48(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
102 | {
103 | uint8_t x, c;
104 | uint8_t *ptr;
105 | switch(msg)
106 | {
107 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
108 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcd8544_84x48_display_info);
109 | break;
110 | case U8X8_MSG_DISPLAY_INIT:
111 | u8x8_d_helper_display_init(u8x8);
112 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_init_seq);
113 | break;
114 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
115 | if ( arg_int == 0 )
116 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_powersave0_seq);
117 | else
118 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_powersave1_seq);
119 | break;
120 | // case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
121 | // break; NOT SUPPORTED
122 |
123 | #ifdef U8X8_WITH_SET_CONTRAST
124 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
125 | u8x8_cad_StartTransfer(u8x8);
126 | u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */
127 | u8x8_cad_SendCmd(u8x8, 0x080 | (arg_int >> 1) );
128 | u8x8_cad_EndTransfer(u8x8);
129 | break;
130 | #endif
131 | case U8X8_MSG_DISPLAY_DRAW_TILE:
132 | u8x8_cad_StartTransfer(u8x8);
133 |
134 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
135 | x *= 8;
136 | x += u8x8->x_offset;
137 | u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
138 | u8x8_cad_SendCmd(u8x8, 0x080 | (x) ); /* set X address */
139 | u8x8_cad_SendCmd(u8x8, 0x040 | (((u8x8_tile_t *)arg_ptr)->y_pos) ); /* set Y address */
140 |
141 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
142 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
143 | c *= 8;
144 | do
145 | {
146 | if ( c + x > 84u )
147 | {
148 | if ( x >= 84u )
149 | break;
150 | c = 84u;
151 | c -= x;
152 | }
153 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
154 | x += c;
155 | arg_int--;
156 | } while( arg_int > 0 );
157 |
158 | u8x8_cad_EndTransfer(u8x8);
159 | break;
160 | default:
161 | return 0;
162 | }
163 | return 1;
164 | }
165 |
166 |
167 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_d_pcf8812.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_pcf8812.c
4 |
5 | pcf8812: 65x102
6 | pcf8814: 65x96
7 |
8 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
9 |
10 | Copyright (c) 2017, olikraus@gmail.com
11 | All rights reserved.
12 |
13 | Redistribution and use in source and binary forms, with or without modification,
14 | are permitted provided that the following conditions are met:
15 |
16 | * Redistributions of source code must retain the above copyright notice, this list
17 | of conditions and the following disclaimer.
18 |
19 | * Redistributions in binary form must reproduce the above copyright notice, this
20 | list of conditions and the following disclaimer in the documentation and/or other
21 | materials provided with the distribution.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 |
37 | */
38 |
39 |
40 | #include "u8x8.h"
41 |
42 |
43 |
44 | static const uint8_t u8x8_d_pcf8812_96x65_init_seq[] = {
45 |
46 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
47 |
48 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
49 | U8X8_C(0x008), /* blank display */
50 |
51 | U8X8_C(0x021), /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
52 | U8X8_C(0x006), /* temp. control: b10 = 2 */
53 | U8X8_C(0x013), /* bias system, 0x010..0x07 1:48 */
54 | U8X8_C(0x09f), /* contrast setting, 0..127 */
55 | //U8X8_CA(0x020 | 2, 0x080 | 0), /* contrast setting, pcf8814 */
56 |
57 | U8X8_C(0x024), /* deactivate chip (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
58 |
59 | U8X8_END_TRANSFER(), /* disable chip */
60 | U8X8_END() /* end of sequence */
61 | };
62 |
63 | static const uint8_t u8x8_d_pcf8812_96x65_powersave0_seq[] = {
64 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
65 | U8X8_C(0x020), /* power on */
66 | U8X8_C(0x00c), /* display on */
67 | U8X8_END_TRANSFER(), /* disable chip */
68 | U8X8_END() /* end of sequence */
69 | };
70 |
71 | static const uint8_t u8x8_d_pcf8812_96x65_powersave1_seq[] = {
72 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
73 | U8X8_C(0x020), /* power on */
74 | U8X8_C(0x008), /* blank display */
75 | U8X8_C(0x024), /* power down */
76 | U8X8_END_TRANSFER(), /* disable chip */
77 | U8X8_END() /* end of sequence */
78 | };
79 |
80 |
81 | static uint8_t u8x8_d_pcf8812_96x65_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
82 | {
83 | uint8_t x, c;
84 | uint8_t *ptr;
85 | switch(msg)
86 | {
87 | /* handled by the calling function
88 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
89 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
90 | break;
91 | */
92 | case U8X8_MSG_DISPLAY_INIT:
93 | u8x8_d_helper_display_init(u8x8);
94 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_init_seq);
95 | break;
96 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
97 | if ( arg_int == 0 )
98 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave0_seq);
99 | else
100 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave1_seq);
101 | break;
102 | /*
103 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
104 | if ( arg_int == 0 )
105 | {
106 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip0_seq);
107 | u8x8->x_offset = u8x8->display_info->default_x_offset;
108 | }
109 | else
110 | {
111 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip1_seq);
112 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
113 | }
114 | break;
115 | */
116 | #ifdef U8X8_WITH_SET_CONTRAST
117 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
118 | u8x8_cad_StartTransfer(u8x8);
119 | u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */
120 | u8x8_cad_SendArg(u8x8, (arg_int>>1)|0x80 ); /* 0..127 for contrast */
121 | u8x8_cad_EndTransfer(u8x8);
122 | break;
123 | #endif
124 | case U8X8_MSG_DISPLAY_DRAW_TILE:
125 | u8x8_cad_StartTransfer(u8x8);
126 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
127 | x *= 8;
128 | x += u8x8->x_offset;
129 |
130 | u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
131 | u8x8_cad_SendCmd(u8x8, 0x080 | x);
132 | u8x8_cad_SendCmd(u8x8, 0x040 | ((u8x8_tile_t *)arg_ptr)->y_pos);
133 |
134 | do
135 | {
136 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
137 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
138 | u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
139 | /*
140 | do
141 | {
142 | u8x8_cad_SendData(u8x8, 8, ptr);
143 | ptr += 8;
144 | c--;
145 | } while( c > 0 );
146 | */
147 | arg_int--;
148 | } while( arg_int > 0 );
149 |
150 | u8x8_cad_EndTransfer(u8x8);
151 | break;
152 | default:
153 | return 0;
154 | }
155 | return 1;
156 | }
157 |
158 |
159 | static const u8x8_display_info_t u8x8_pcf8812_96x65_display_info =
160 | {
161 | /* chip_enable_level = */ 0,
162 | /* chip_disable_level = */ 1,
163 |
164 | /* post_chip_enable_wait_ns = */ 100,
165 | /* pre_chip_disable_wait_ns = */ 100,
166 | /* reset_pulse_width_ms = */ 100,
167 | /* post_reset_wait_ms = */ 100,
168 | /* sda_setup_time_ns = */ 100,
169 | /* sck_pulse_width_ns = */ 100,
170 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
171 | /* spi_mode = */ 0, /* active high, rising edge */
172 | /* i2c_bus_clock_100kHz = */ 4,
173 | /* data_setup_time_ns = */ 40,
174 | /* write_pulse_width_ns = */ 150,
175 | /* tile_width = */ 12,
176 | /* tile_hight = */ 9,
177 | /* default_x_offset = */ 0,
178 | /* flipmode_x_offset = */ 0,
179 | /* pixel_width = */ 96,
180 | /* pixel_height = */ 65
181 | };
182 |
183 | uint8_t u8x8_d_pcf8812_96x65(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
184 | {
185 | if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
186 | {
187 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
188 | return 1;
189 | }
190 | return u8x8_d_pcf8812_96x65_generic(u8x8, msg, arg_int, arg_ptr);
191 | }
192 |
193 |
194 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_d_pcf8814_hx1230.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_pcf8814_hc1230.c
4 |
5 | pcf8814: 65x96
6 | hx1230: 68x96
7 |
8 | pcf8814 and hc1230 are almost identical.
9 |
10 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
11 |
12 | Copyright (c) 2017, olikraus@gmail.com
13 | All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without modification,
16 | are permitted provided that the following conditions are met:
17 |
18 | * Redistributions of source code must retain the above copyright notice, this list
19 | of conditions and the following disclaimer.
20 |
21 | * Redistributions in binary form must reproduce the above copyright notice, this
22 | list of conditions and the following disclaimer in the documentation and/or other
23 | materials provided with the distribution.
24 |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 |
39 | */
40 |
41 |
42 | #include "u8x8.h"
43 |
44 |
45 |
46 | static const uint8_t u8x8_d_hx1230_96x68_init_seq[] = {
47 |
48 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
49 |
50 | U8X8_C(0x0ae), /* display off */
51 | U8X8_C(0x020), /* power off */
52 | U8X8_C(0x080), /* contrast setting, 0..31, set to 0 */
53 | U8X8_C(0x0a6), /* not inverted display */
54 | U8X8_C(0x0a4), /* normal display mode */
55 |
56 | U8X8_C(0x0a0), /* */
57 | U8X8_C(0x0c0), /* */
58 |
59 | U8X8_C(0x040), /* start at scanline 0 */
60 |
61 | U8X8_END_TRANSFER(), /* disable chip */
62 | U8X8_END() /* end of sequence */
63 | };
64 |
65 | static const uint8_t u8x8_d_hx1230_96x68_powersave0_seq[] = {
66 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
67 | U8X8_C(0x02f), /* power on */
68 | U8X8_C(0x0af), /* display on */
69 | U8X8_END_TRANSFER(), /* disable chip */
70 | U8X8_END() /* end of sequence */
71 | };
72 |
73 | static const uint8_t u8x8_d_hx1230_96x68_powersave1_seq[] = {
74 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
75 | U8X8_C(0x0ae), /* display off */
76 | U8X8_C(0x0a5), /* All pixels on = powersave */
77 | U8X8_END_TRANSFER(), /* disable chip */
78 | U8X8_END() /* end of sequence */
79 | };
80 |
81 | static const uint8_t u8x8_d_hx1230_96x68_flip0_seq[] = {
82 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
83 | U8X8_C(0x0a0), /* */
84 | U8X8_C(0x0c0), /* */
85 | U8X8_END_TRANSFER(), /* disable chip */
86 | U8X8_END() /* end of sequence */
87 | };
88 |
89 | static const uint8_t u8x8_d_hx1230_96x68_flip1_seq[] = {
90 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
91 | U8X8_C(0x0a1), /* */
92 | U8X8_C(0x0c8), /* */
93 | U8X8_END_TRANSFER(), /* disable chip */
94 | U8X8_END() /* end of sequence */
95 | };
96 |
97 |
98 | static uint8_t u8x8_d_hx1230_96x68_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
99 | {
100 | uint8_t x, c;
101 | uint8_t *ptr;
102 | switch(msg)
103 | {
104 | /* handled by the calling function
105 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
106 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_hx1230_96x68_display_info);
107 | break;
108 | */
109 | case U8X8_MSG_DISPLAY_INIT:
110 | u8x8_d_helper_display_init(u8x8);
111 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_init_seq);
112 | break;
113 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
114 | if ( arg_int == 0 )
115 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_powersave0_seq);
116 | else
117 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_powersave1_seq);
118 | break;
119 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
120 | if ( arg_int == 0 )
121 | {
122 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_flip0_seq);
123 | u8x8->x_offset = u8x8->display_info->default_x_offset;
124 | }
125 | else
126 | {
127 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_flip1_seq);
128 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
129 | }
130 | break;
131 | #ifdef U8X8_WITH_SET_CONTRAST
132 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
133 | u8x8_cad_StartTransfer(u8x8);
134 | u8x8_cad_SendCmd(u8x8, (arg_int>>3)|0x80 ); /* 0..31 for contrast */
135 | u8x8_cad_EndTransfer(u8x8);
136 | break;
137 | #endif
138 | case U8X8_MSG_DISPLAY_DRAW_TILE:
139 | u8x8_cad_StartTransfer(u8x8);
140 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
141 | x *= 8;
142 | x += u8x8->x_offset;
143 |
144 | u8x8_cad_SendCmd(u8x8, x&15);
145 | u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4));
146 | u8x8_cad_SendCmd(u8x8, 0x0b0 | ((u8x8_tile_t *)arg_ptr)->y_pos);
147 |
148 | do
149 | {
150 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
151 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
152 | u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
153 | arg_int--;
154 | } while( arg_int > 0 );
155 |
156 | u8x8_cad_EndTransfer(u8x8);
157 | break;
158 | default:
159 | return 0;
160 | }
161 | return 1;
162 | }
163 |
164 | static const u8x8_display_info_t u8x8_hx1230_96x68_display_info =
165 | {
166 | /* chip_enable_level = */ 0,
167 | /* chip_disable_level = */ 1,
168 |
169 | /* post_chip_enable_wait_ns = */ 100,
170 | /* pre_chip_disable_wait_ns = */ 100,
171 | /* reset_pulse_width_ms = */ 100,
172 | /* post_reset_wait_ms = */ 100,
173 | /* sda_setup_time_ns = */ 100,
174 | /* sck_pulse_width_ns = */ 100,
175 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
176 | /* spi_mode = */ 0, /* active high, rising edge */
177 | /* i2c_bus_clock_100kHz = */ 4,
178 | /* data_setup_time_ns = */ 40,
179 | /* write_pulse_width_ns = */ 150,
180 | /* tile_width = */ 12,
181 | /* tile_hight = */ 9,
182 | /* default_x_offset = */ 0,
183 | /* flipmode_x_offset = */ 0,
184 | /* pixel_width = */ 96,
185 | /* pixel_height = */ 68
186 | };
187 |
188 | uint8_t u8x8_d_hx1230_96x68(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
189 | {
190 | if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
191 | {
192 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_hx1230_96x68_display_info);
193 | return 1;
194 | }
195 | return u8x8_d_hx1230_96x68_generic(u8x8, msg, arg_int, arg_ptr);
196 | }
197 |
198 |
199 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_d_stdio.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_stdio.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8x8.h"
37 |
38 | #include
39 |
40 | #define W 8
41 | #define H 2
42 |
43 | uint8_t bitmap[W*H*8];
44 |
45 | void bitmap_place_tile(uint8_t x, uint8_t y, uint8_t *tile)
46 | {
47 | uint8_t i;
48 | for(i = 0; i < 8; i++ )
49 | bitmap[x*8+y*W*8+i] = tile[i];
50 | }
51 |
52 | void bitmap_show(void)
53 | {
54 | int x, y;
55 | for( y = 0; y < H*8; y++ )
56 | {
57 | for( x = 0; x < W*8; x++ )
58 | {
59 | if ( (bitmap[x+(y/8)*W*8] & (1<<((y&7)))) != 0 )
60 | {
61 | printf("*");
62 | }
63 | else
64 | {
65 | printf(".");
66 | }
67 | }
68 | printf("\n");
69 | }
70 | }
71 |
72 |
73 | uint8_t u8x8_d_stdio(U8X8_UNUSED u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
74 | {
75 | switch(msg)
76 | {
77 | case U8X8_MSG_DISPLAY_INIT:
78 | break;
79 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
80 | if ( arg_int == 0 )
81 | bitmap_show();
82 | break;
83 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
84 | break;
85 | case U8X8_MSG_DISPLAY_DRAW_TILE:
86 | bitmap_place_tile(((u8x8_tile_t *)arg_ptr)->x_pos, ((u8x8_tile_t *)arg_ptr)->y_pos, ((u8x8_tile_t *)arg_ptr)->tile_ptr);
87 | break;
88 | default:
89 | break;
90 | }
91 | return 1;
92 | }
93 |
94 |
95 |
96 | void u8x8_SetupStdio(u8x8_t *u8x8)
97 | {
98 | u8x8_SetupDefaults(u8x8);
99 | u8x8->display_cb = u8x8_d_stdio;
100 | }
101 |
102 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_debounce.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_debounce.c
4 |
5 | Key/button simple debounce algorithm (Addon for u8x8)
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8x8.h"
39 |
40 | static uint8_t u8x8_read_pin_state(u8x8_t *u8x8)
41 | {
42 | uint8_t i;
43 | uint8_t pin_state;
44 |
45 | pin_state = 255; /* be compatible with the setup of the default pin setup, which is 255 */
46 | for( i = 0; i < U8X8_PIN_INPUT_CNT; i++ )
47 | {
48 | pin_state <<= 1;
49 |
50 | /* the callback function should put the return value into this variable */
51 | u8x8->gpio_result = 1;
52 | u8x8_gpio_call(u8x8, U8X8_MSG_GPIO(i+U8X8_PIN_OUTPUT_CNT), 0);
53 | pin_state |= u8x8->gpio_result & 1;
54 | }
55 |
56 | return pin_state;
57 | }
58 |
59 | /*
60 | return 0 to U8X8_PIN_INPUT_CNT-1 if there is a difference
61 | return U8X8_PIN_INPUT_CNT if there is no difference
62 | */
63 | static uint8_t u8x8_find_first_diff(uint8_t a, uint8_t b)
64 | {
65 | uint8_t mask;
66 | uint8_t i;
67 | mask = 1;
68 | i = U8X8_PIN_INPUT_CNT;
69 | do
70 | {
71 | i--;
72 | if ( (a & mask) != (b & mask) )
73 | return i;
74 | mask <<= 1;
75 | } while( i > 0 );
76 | return U8X8_PIN_INPUT_CNT;
77 | }
78 |
79 | /*
80 | State A:
81 | u8x8->debounce_last_pin_state == current_state
82 | --> State A
83 | u8x8->debounce_last_pin_state != current_state
84 | --> u8x8->debounce_last_pin_state = current_state
85 | --> State B + cnt
86 |
87 | State B + cnt
88 | --> state--
89 |
90 | State B
91 | u8x8->debounce_last_pin_state == current_state
92 | --> keypress detected
93 | --> State C
94 | u8x8->debounce_last_pin_state != current_state
95 | --> State A
96 |
97 | State C
98 | u8x8->debounce_last_pin_state == current_state
99 | --> State C
100 | u8x8->debounce_last_pin_state != current_state
101 | --> State A
102 |
103 | */
104 |
105 | #ifdef __unix__xxxxxx_THIS_IS_DISABLED
106 |
107 | #include
108 | #include
109 | uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
110 | {
111 | int c;
112 | c = getc(stdin);
113 | switch(c)
114 | {
115 | case 'n':
116 | return U8X8_MSG_GPIO_MENU_NEXT;
117 | case 'p':
118 | return U8X8_MSG_GPIO_MENU_PREV;
119 | case 's':
120 | return U8X8_MSG_GPIO_MENU_SELECT;
121 | case 'h':
122 | return U8X8_MSG_GPIO_MENU_HOME;
123 | case 'x':
124 | exit(0);
125 | default:
126 | puts("press n, p, s, h or x");
127 | break;
128 | }
129 | return 0;
130 | }
131 |
132 |
133 | #else /* __unix__ */
134 |
135 |
136 | #define U8X8_DEBOUNCE_WAIT 2
137 | /* do debounce and return a GPIO msg which indicates the event */
138 | /* returns 0, if there is no event */
139 | #if defined(__GNUC__) && !defined(__CYGWIN__)
140 | # pragma weak u8x8_GetMenuEvent
141 | #endif
142 | uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
143 | {
144 | uint8_t pin_state;
145 | uint8_t result_msg = 0; /* invalid message, no event */
146 |
147 | pin_state = u8x8_read_pin_state(u8x8);
148 |
149 | /* States A, B, C & D are encoded in the upper 4 bit*/
150 | switch(u8x8->debounce_state)
151 | {
152 | case 0x00: /* State A, default state */
153 | if ( u8x8->debounce_default_pin_state != pin_state )
154 | {
155 | //u8x8->debounce_last_pin_state = pin_state;
156 | u8x8->debounce_state = 0x010 + U8X8_DEBOUNCE_WAIT;
157 | }
158 | break;
159 | case 0x10: /* State B */
160 | //if ( u8x8->debounce_last_pin_state != pin_state )
161 | if ( u8x8->debounce_default_pin_state == pin_state )
162 | {
163 | u8x8->debounce_state = 0x00; /* back to state A */
164 | }
165 | else
166 | {
167 | /* keypress detected */
168 | u8x8->debounce_last_pin_state = pin_state;
169 | //result_msg = U8X8_MSG_GPIO_MENU_NEXT;
170 | u8x8->debounce_state = 0x020 + U8X8_DEBOUNCE_WAIT; /* got to state C */
171 | }
172 | break;
173 |
174 | case 0x20: /* State C */
175 | if ( u8x8->debounce_last_pin_state != pin_state )
176 | {
177 | u8x8->debounce_state = 0x00; /* back to state A */
178 | }
179 | else
180 | {
181 | u8x8->debounce_state = 0x030; /* got to state D */
182 | }
183 | break;
184 |
185 | case 0x30: /* State D */
186 | /* wait until key release */
187 | if ( u8x8->debounce_default_pin_state == pin_state )
188 | {
189 | u8x8->debounce_state = 0x00; /* back to state A */
190 | result_msg = U8X8_MSG_GPIO(u8x8_find_first_diff(u8x8->debounce_default_pin_state, u8x8->debounce_last_pin_state)+U8X8_PIN_OUTPUT_CNT);
191 | }
192 | else
193 | {
194 | //result_msg = U8X8_MSG_GPIO_MENU_NEXT;
195 | // maybe implement autorepeat here
196 | }
197 | break;
198 | default:
199 | u8x8->debounce_state--; /* count down, until there is a valid state */
200 | break;
201 | }
202 | return result_msg;
203 | }
204 |
205 | #endif /* __unix__ */
206 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_display.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_display.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | Abstraction layer for the graphics controller.
36 | Main goal is the placement of a 8x8 pixel block (tile) on the display.
37 |
38 | */
39 |
40 |
41 | #include "u8x8.h"
42 |
43 |
44 | /*==========================================*/
45 | /* internal library function */
46 |
47 | /*
48 | this is a helper function for the U8X8_MSG_DISPLAY_SETUP_MEMORY function.
49 | It can be called within the display callback function to carry out the usual standard tasks.
50 |
51 | */
52 | void u8x8_d_helper_display_setup_memory(u8x8_t *u8x8, const u8x8_display_info_t *display_info)
53 | {
54 | /* 1) set display info struct */
55 | u8x8->display_info = display_info;
56 | u8x8->x_offset = u8x8->display_info->default_x_offset;
57 | }
58 |
59 | /*
60 | this is a helper function for the U8X8_MSG_DISPLAY_INIT function.
61 | It can be called within the display callback function to carry out the usual standard tasks.
62 |
63 | */
64 | void u8x8_d_helper_display_init(u8x8_t *u8x8)
65 | {
66 | /* 2) apply port directions to the GPIO lines and apply default values for the IO lines*/
67 | u8x8_gpio_Init(u8x8);
68 | u8x8_cad_Init(u8x8);
69 |
70 | /* 3) do reset */
71 | u8x8_gpio_SetReset(u8x8, 1);
72 | u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
73 | u8x8_gpio_SetReset(u8x8, 0);
74 | u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
75 | u8x8_gpio_SetReset(u8x8, 1);
76 | u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->post_reset_wait_ms);
77 | }
78 |
79 | /*==========================================*/
80 | /* official functions */
81 |
82 | uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr)
83 | {
84 | u8x8_tile_t tile;
85 | tile.x_pos = x;
86 | tile.y_pos = y;
87 | tile.cnt = cnt;
88 | tile.tile_ptr = tile_ptr;
89 | return u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, 1, (void *)&tile);
90 | }
91 |
92 | /* should be implemented as macro */
93 | void u8x8_SetupMemory(u8x8_t *u8x8)
94 | {
95 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SETUP_MEMORY, 0, NULL);
96 | }
97 |
98 | void u8x8_InitDisplay(u8x8_t *u8x8)
99 | {
100 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_INIT, 0, NULL);
101 | }
102 |
103 | void u8x8_SetPowerSave(u8x8_t *u8x8, uint8_t is_enable)
104 | {
105 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_POWER_SAVE, is_enable, NULL);
106 | }
107 |
108 | void u8x8_SetFlipMode(u8x8_t *u8x8, uint8_t mode)
109 | {
110 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_FLIP_MODE, mode, NULL);
111 | }
112 |
113 | void u8x8_SetContrast(u8x8_t *u8x8, uint8_t value)
114 | {
115 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_CONTRAST, value, NULL);
116 | }
117 |
118 | void u8x8_RefreshDisplay(u8x8_t *u8x8)
119 | {
120 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_REFRESH, 0, NULL);
121 | }
122 |
123 | void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf)
124 | {
125 | u8x8_tile_t tile;
126 | uint8_t h;
127 |
128 | tile.x_pos = 0;
129 | tile.cnt = 1;
130 | tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
131 |
132 | h = u8x8->display_info->tile_height;
133 | tile.y_pos = 0;
134 | do
135 | {
136 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
137 | tile.y_pos++;
138 | } while( tile.y_pos < h );
139 | }
140 |
141 | void u8x8_ClearDisplay(u8x8_t *u8x8)
142 | {
143 | uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
144 | u8x8_ClearDisplayWithTile(u8x8, buf);
145 | }
146 |
147 | void u8x8_FillDisplay(u8x8_t *u8x8)
148 | {
149 | uint8_t buf[8] = { 255, 255, 255, 255, 255, 255, 255, 255 };
150 | u8x8_ClearDisplayWithTile(u8x8, buf);
151 | }
152 |
153 | void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line)
154 | {
155 | uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
156 | u8x8_tile_t tile;
157 | if ( line < u8x8->display_info->tile_height )
158 | {
159 | tile.x_pos = 0;
160 | tile.y_pos = line;
161 | tile.cnt = 1;
162 | tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
163 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
164 | }
165 | }
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_fonts.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eziya/STM32_HAL_U8G2_OLED/cec4c5ceac4937fb9d6c65c932ef5553c3821841/Src/u8g2/u8x8_fonts.c
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_gpio.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_gpio.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 |
37 | #include "u8x8.h"
38 |
39 |
40 | void u8x8_gpio_call(u8x8_t *u8x8, uint8_t msg, uint8_t arg)
41 | {
42 | u8x8->gpio_and_delay_cb(u8x8, msg, arg, NULL);
43 | }
44 |
45 | /*
46 | void u8x8_gpio_Delay(u8x8_t *u8x8, uint8_t msg, uint8_t dly)
47 | {
48 | u8x8->gpio_and_delay_cb(u8x8, msg, dly, NULL);
49 | }
50 | */
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_input_value.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_input_value.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8x8.h"
37 |
38 | /*
39 | return:
40 | 0: value is not changed (HOME/Break Button pressed)
41 | 1: value has been updated
42 | */
43 |
44 | uint8_t u8x8_UserInterfaceInputValue(u8x8_t *u8x8, const char *title, const char *pre, uint8_t *value, uint8_t lo, uint8_t hi, uint8_t digits, const char *post)
45 | {
46 | uint8_t height;
47 | uint8_t y;
48 | uint8_t width;
49 | uint8_t x;
50 | uint8_t local_value = *value;
51 | uint8_t r;
52 | uint8_t event;
53 |
54 | /* calculate overall height of the input value box */
55 | height = 1; /* button line */
56 | height += u8x8_GetStringLineCnt(title);
57 |
58 | /* calculate offset from top */
59 | y = 0;
60 | if ( height < u8x8_GetRows(u8x8) )
61 | {
62 | y = u8x8_GetRows(u8x8);
63 | y -= height;
64 | y /= 2;
65 | }
66 |
67 | /* calculate offset from left for the label */
68 | x = 0;
69 | width = u8x8_GetUTF8Len(u8x8, pre);
70 | width += digits;
71 | width += u8x8_GetUTF8Len(u8x8, post);
72 | if ( width < u8x8_GetCols(u8x8) )
73 | {
74 | x = u8x8_GetCols(u8x8);
75 | x -= width;
76 | x /= 2;
77 | }
78 |
79 | /* render */
80 | u8x8_ClearDisplay(u8x8); /* required, because not everything is filled */
81 | u8x8_SetInverseFont(u8x8, 0);
82 | y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title);
83 | x += u8x8_DrawUTF8(u8x8, x, y, pre);
84 | u8x8_DrawUTF8(u8x8, x+digits, y, post);
85 | u8x8_SetInverseFont(u8x8, 1);
86 |
87 | /* event loop */
88 | u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
89 | for(;;)
90 | {
91 | event = u8x8_GetMenuEvent(u8x8);
92 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
93 | {
94 | *value = local_value;
95 | r = 1;
96 | break;
97 | }
98 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
99 | {
100 | r = 0;
101 | break;
102 | }
103 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
104 | {
105 | if ( local_value >= hi )
106 | local_value = lo;
107 | else
108 | local_value++;
109 | u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
110 | }
111 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
112 | {
113 | if ( local_value <= lo )
114 | local_value = hi;
115 | else
116 | local_value--;
117 | u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
118 | }
119 | }
120 |
121 | u8x8_SetInverseFont(u8x8, 0);
122 | return r;
123 | }
124 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_message.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_message.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8x8.h"
37 |
38 | uint8_t u8x8_draw_button_line(u8x8_t *u8x8, uint8_t y, uint8_t w, uint8_t cursor, const char *s)
39 | {
40 | uint8_t i;
41 | uint8_t cnt;
42 | uint8_t total;
43 | uint8_t d;
44 | uint8_t x;
45 | cnt = u8x8_GetStringLineCnt(s);
46 |
47 | /* calculate the width of the button */
48 | total = 0;
49 | for( i = 0; i < cnt; i++ )
50 | {
51 | total += u8x8_GetUTF8Len(u8x8, u8x8_GetStringLineStart(i, s));
52 | }
53 | total += (cnt-1); /* had one space between the buttons */
54 |
55 | /* calculate the left offset */
56 | d = 0;
57 | if ( total < w )
58 | {
59 | d = w;
60 | d -= total;
61 | d /= 2;
62 | }
63 |
64 | /* draw the buttons */
65 | x = d;
66 | u8x8_SetInverseFont(u8x8, 0);
67 | for( i = 0; i < cnt; i++ )
68 | {
69 | if ( i == cursor )
70 | u8x8_SetInverseFont(u8x8, 1);
71 |
72 | x+=u8x8_DrawUTF8(u8x8, x, y, u8x8_GetStringLineStart(i, s));
73 | u8x8_SetInverseFont(u8x8, 0);
74 | x+=u8x8_DrawUTF8(u8x8, x, y, " ");
75 | }
76 |
77 | /* return the number of buttons */
78 | return cnt;
79 | }
80 |
81 | /*
82 | title1: Multiple lines,separated by '\n'
83 | title2: A single line/string which is terminated by '\0' or '\n' . "title2" accepts the return value from u8x8_GetStringLineStart()
84 | title3: Multiple lines,separated by '\n'
85 | buttons: one more more buttons separated by '\n' and terminated with '\0'
86 | */
87 |
88 | uint8_t u8x8_UserInterfaceMessage(u8x8_t *u8x8, const char *title1, const char *title2, const char *title3, const char *buttons)
89 | {
90 | uint8_t height;
91 | uint8_t y;
92 | uint8_t cursor = 0;
93 | uint8_t button_cnt;
94 | uint8_t event;
95 |
96 | u8x8_SetInverseFont(u8x8, 0);
97 |
98 | /* calculate overall height of the message box */
99 | height = 1; /* button line */
100 | height += u8x8_GetStringLineCnt(title1);
101 | if ( title2 != NULL )
102 | height ++;
103 | height += u8x8_GetStringLineCnt(title3);
104 |
105 | /* calculate offset from top */
106 | y = 0;
107 | if ( height < u8x8_GetRows(u8x8) )
108 | {
109 | y = u8x8_GetRows(u8x8);
110 | y -= height;
111 | y /= 2;
112 | }
113 |
114 | /* draw message box */
115 |
116 | u8x8_ClearDisplay(u8x8); /* required, because not everything is filled */
117 |
118 | y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title1);
119 | if ( title2 != NULL )
120 | {
121 | u8x8_DrawUTF8Line(u8x8, 0, y, u8x8_GetCols(u8x8), title2);
122 | y++;
123 | }
124 | y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title3);
125 |
126 | button_cnt = u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
127 |
128 | for(;;)
129 | {
130 | event = u8x8_GetMenuEvent(u8x8);
131 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
132 | return cursor+1;
133 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
134 | break;
135 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
136 | {
137 | cursor++;
138 | if ( cursor >= button_cnt )
139 | cursor = 0;
140 | u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
141 | }
142 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
143 | {
144 | if ( cursor == 0 )
145 | cursor = button_cnt;
146 | cursor--;
147 | u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
148 | }
149 | }
150 | return 0;
151 | }
152 |
153 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_selection_list.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_selection_list.c
4 |
5 | selection list with scroll option
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8x8.h"
39 |
40 | /*
41 | increase the cursor position
42 | */
43 | void u8sl_Next(u8sl_t *u8sl)
44 | {
45 | u8sl->current_pos++;
46 | if ( u8sl->current_pos >= u8sl->total )
47 | {
48 | u8sl->current_pos = 0;
49 | u8sl->first_pos = 0;
50 | }
51 | else
52 | {
53 | if ( u8sl->first_pos + u8sl->visible <= u8sl->current_pos + 1 )
54 | {
55 | u8sl->first_pos = u8sl->current_pos - u8sl->visible + 1;
56 | }
57 | }
58 | }
59 |
60 | void u8sl_Prev(u8sl_t *u8sl)
61 | {
62 | if ( u8sl->current_pos == 0 )
63 | {
64 | u8sl->current_pos = u8sl->total - 1;
65 | u8sl->first_pos = 0;
66 | if ( u8sl->total > u8sl->visible )
67 | u8sl->first_pos = u8sl->total - u8sl->visible;
68 | }
69 | else
70 | {
71 | u8sl->current_pos--;
72 | if ( u8sl->first_pos > u8sl->current_pos )
73 | u8sl->first_pos = u8sl->current_pos;
74 | }
75 | }
76 |
77 | void u8x8_DrawSelectionList(u8x8_t *u8x8, u8sl_t *u8sl, u8x8_sl_cb sl_cb, const void *aux)
78 | {
79 | uint8_t i;
80 | for( i = 0; i < u8sl->visible; i++ )
81 | {
82 | sl_cb(u8x8, u8sl, i+u8sl->first_pos, aux);
83 | }
84 | }
85 |
86 | /* selection list with string line */
87 | void u8x8_sl_string_line_cb(u8x8_t *u8x8, u8sl_t *u8sl, uint8_t idx, const void *aux)
88 | {
89 | const char *s;
90 | uint8_t row;
91 | /* calculate offset from display upper border */
92 | row = u8sl->y;
93 |
94 | /* calculate target pos */
95 | row += idx;
96 | row -= u8sl->first_pos;
97 |
98 | /* check whether this is the current cursor line */
99 | if ( idx == u8sl->current_pos )
100 | u8x8_SetInverseFont(u8x8, 1);
101 | else
102 | u8x8_SetInverseFont(u8x8, 0);
103 |
104 | /* get the line from the array */
105 | s = u8x8_GetStringLineStart(idx, (const char *)aux);
106 |
107 | /* draw the line */
108 | if ( s == NULL )
109 | s = "";
110 | u8x8_DrawUTF8Line(u8x8, u8sl->x, row, u8x8_GetCols(u8x8), s);
111 | u8x8_SetInverseFont(u8x8, 0);
112 | }
113 |
114 | /*
115 | title: NULL for no title, valid str for title line. Can contain mutliple lines, separated by '\n'
116 | start_pos: default position for the cursor (starts with 1)
117 | sl: string list (list of strings separated by \n)
118 | returns 0 if user has pressed the home key
119 | returns the selected line+1 if user has pressed the select key (e.g. 1 for the first line)
120 | */
121 | uint8_t u8x8_UserInterfaceSelectionList(u8x8_t *u8x8, const char *title, uint8_t start_pos, const char *sl)
122 | {
123 | u8sl_t u8sl;
124 | uint8_t event;
125 | uint8_t title_lines;
126 |
127 | if ( start_pos > 0 )
128 | start_pos--;
129 |
130 | u8sl.visible = u8x8_GetRows(u8x8);
131 | u8sl.total = u8x8_GetStringLineCnt(sl);
132 | u8sl.first_pos = 0;
133 | u8sl.current_pos = start_pos;
134 | u8sl.x = 0;
135 | u8sl.y = 0;
136 |
137 |
138 | //u8x8_ClearDisplay(u8x8); /* not required because all is 100% filled */
139 | u8x8_SetInverseFont(u8x8, 0);
140 |
141 | if ( title != NULL )
142 | {
143 | title_lines = u8x8_DrawUTF8Lines(u8x8, u8sl.x, u8sl.y, u8x8_GetCols(u8x8), title);
144 | u8sl.y+=title_lines;
145 | u8sl.visible-=title_lines;
146 | }
147 |
148 | if ( u8sl.current_pos >= u8sl.total )
149 | u8sl.current_pos = u8sl.total-1;
150 |
151 |
152 | u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
153 |
154 | for(;;)
155 | {
156 | event = u8x8_GetMenuEvent(u8x8);
157 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
158 | return u8sl.current_pos+1;
159 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
160 | return 0;
161 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
162 | {
163 | u8sl_Next(&u8sl);
164 | u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
165 | }
166 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
167 | {
168 | u8sl_Prev(&u8sl);
169 | u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
170 | }
171 | }
172 | }
173 |
174 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_setup.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_setup.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 |
37 | #include "u8x8.h"
38 |
39 | /* universal dummy callback, which will be default for all callbacks */
40 | uint8_t u8x8_dummy_cb(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
41 | {
42 | /* the dummy callback will not handle any message and will fail for all messages */
43 | return 0;
44 | }
45 |
46 |
47 | static const u8x8_display_info_t u8x8_null_display_info =
48 | {
49 | /* chip_enable_level = */ 0,
50 | /* chip_disable_level = */ 1,
51 |
52 | /* post_chip_enable_wait_ns = */ 0,
53 | /* pre_chip_disable_wait_ns = */ 0,
54 | /* reset_pulse_width_ms = */ 0,
55 | /* post_reset_wait_ms = */ 0,
56 | /* sda_setup_time_ns = */ 0,
57 | /* sck_pulse_width_ns = */ 0, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
58 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
59 | /* spi_mode = */ 0, /* active high, rising edge */
60 | /* i2c_bus_clock_100kHz = */ 4,
61 | /* data_setup_time_ns = */ 0,
62 | /* write_pulse_width_ns = */ 0,
63 | /* tile_width = */ 1, /* 8x8 */
64 | /* tile_hight = */ 1,
65 | /* default_x_offset = */ 0,
66 | /* flipmode_x_offset = */ 0,
67 | /* pixel_width = */ 8,
68 | /* pixel_height = */ 8
69 | };
70 |
71 |
72 | /* a special null device */
73 | uint8_t u8x8_d_null_cb(u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
74 | {
75 | switch(msg)
76 | {
77 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
78 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_null_display_info);
79 | break;
80 | case U8X8_MSG_DISPLAY_INIT:
81 | u8x8_d_helper_display_init(u8x8);
82 | break;
83 | }
84 | /* the null device callback will succeed for all messages */
85 | return 1;
86 | }
87 |
88 |
89 | /*
90 | Description:
91 | Setup u8x8
92 | Args:
93 | u8x8 An empty u8x8 structure
94 | */
95 | void u8x8_SetupDefaults(u8x8_t *u8x8)
96 | {
97 | u8x8->display_info = NULL;
98 | u8x8->display_cb = u8x8_dummy_cb;
99 | u8x8->cad_cb = u8x8_dummy_cb;
100 | u8x8->byte_cb = u8x8_dummy_cb;
101 | u8x8->gpio_and_delay_cb = u8x8_dummy_cb;
102 | u8x8->is_font_inverse_mode = 0;
103 | u8x8->device_address = 0;
104 | u8x8->utf8_state = 0; /* also reset by u8x8_utf8_init */
105 | u8x8->bus_clock = 0; /* issue 769 */
106 | u8x8->i2c_address = 255;
107 | u8x8->debounce_default_pin_state = 255; /* assume all low active buttons */
108 |
109 | #ifdef U8X8_USE_PINS
110 | {
111 | uint8_t i;
112 | for( i = 0; i < U8X8_PIN_CNT; i++ )
113 | u8x8->pins[i] = U8X8_PIN_NONE;
114 | }
115 | #endif
116 | }
117 |
118 |
119 | /*
120 | Description:
121 | Setup u8x8 and assign the callback function. The dummy
122 | callback "u8x8_dummy_cb" can be used, if no callback is required.
123 | This setup will not communicate with the display itself.
124 | Use u8x8_InitDisplay() to send the startup code to the Display.
125 | Args:
126 | u8x8 An empty u8x8 structure
127 | display_cb Display/controller specific callback function
128 | cad_cb Display controller specific communication callback function
129 | byte_cb Display controller/communication specific callback funtion
130 | gpio_and_delay_cb Environment specific callback function
131 |
132 | */
133 | void u8x8_Setup(u8x8_t *u8x8, u8x8_msg_cb display_cb, u8x8_msg_cb cad_cb, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
134 | {
135 | /* setup defaults and reset pins to U8X8_PIN_NONE */
136 | u8x8_SetupDefaults(u8x8);
137 |
138 | /* setup specific callbacks */
139 | u8x8->display_cb = display_cb;
140 | u8x8->cad_cb = cad_cb;
141 | u8x8->byte_cb = byte_cb;
142 | u8x8->gpio_and_delay_cb = gpio_and_delay_cb;
143 |
144 | /* setup display info */
145 | u8x8_SetupMemory(u8x8);
146 | }
147 |
148 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_string.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_string.c
4 |
5 | string line procedures
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8x8.h"
39 |
40 | uint8_t u8x8_GetStringLineCnt(const char *str)
41 | {
42 | char e;
43 | uint8_t line_cnt = 1;
44 | if ( str == NULL )
45 | return 0;
46 | for(;;)
47 | {
48 | e = *str;
49 | if ( e == '\0' )
50 | break;
51 | str++;
52 | if ( e == '\n' )
53 | line_cnt++;
54 | }
55 | return line_cnt;
56 | }
57 |
58 |
59 | /*
60 | Assumes strings, separated by '\n' in "str".
61 | Returns the string at index "line_idx". First strng has line_idx = 0
62 | Example:
63 | Returns "xyz" for line_idx = 1 with str = "abc\nxyz"
64 | Support both UTF8 and normal strings.
65 | */
66 | const char *u8x8_GetStringLineStart(uint8_t line_idx, const char *str )
67 | {
68 | char e;
69 | uint8_t line_cnt = 1;
70 |
71 | if ( line_idx == 0 )
72 | return str;
73 |
74 | for(;;)
75 | {
76 | e = *str;
77 | if ( e == '\0' )
78 | break;
79 | str++;
80 | if ( e == '\n' )
81 | {
82 | if ( line_cnt == line_idx )
83 | return str;
84 | line_cnt++;
85 | }
86 | }
87 | return NULL; /* line not found */
88 | }
89 |
90 | /* copy until first '\n' or '\0' in str */
91 | /* Important: There is no string overflow check, ensure */
92 | /* that the destination buffer is large enough */
93 | void u8x8_CopyStringLine(char *dest, uint8_t line_idx, const char *str)
94 | {
95 | if ( dest == NULL )
96 | return;
97 | str = u8x8_GetStringLineStart( line_idx, str );
98 | if ( str != NULL )
99 | {
100 | for(;;)
101 | {
102 | if ( *str == '\n' || *str == '\0' )
103 | break;
104 | *dest = *str;
105 | dest++;
106 | str++;
107 | }
108 | }
109 | *dest = '\0';
110 | }
111 |
112 | /*
113 | Draw a string
114 | Extend the string to size "w"
115 | Center the string within "w"
116 | return the size of the string
117 |
118 | */
119 | uint8_t u8x8_DrawUTF8Line(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t w, const char *s)
120 | {
121 | uint8_t d, lw;
122 | uint8_t cx, dx;
123 |
124 | d = 0;
125 |
126 | lw = u8x8_GetUTF8Len(u8x8, s);
127 | if ( lw < w )
128 | {
129 | d = w;
130 | d -=lw;
131 | d /= 2;
132 | }
133 |
134 | cx = x;
135 | dx = cx + d;
136 | while( cx < dx )
137 | {
138 | u8x8_DrawUTF8(u8x8, cx, y, " ");
139 | cx++;
140 | }
141 | cx += u8x8_DrawUTF8(u8x8, cx, y, s);
142 | dx = x + w;
143 | while( cx < dx )
144 | {
145 | u8x8_DrawUTF8(u8x8, cx, y, " ");
146 | cx++;
147 | }
148 | cx -= x;
149 | return cx;
150 | }
151 |
152 | /*
153 | draw several lines at position x,y.
154 | lines are stored in s and must be separated with '\n'.
155 | lines can be centered with respect to "w"
156 | if s == NULL nothing is drawn and 0 is returned
157 | returns the number of lines in s
158 | */
159 | uint8_t u8x8_DrawUTF8Lines(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t w, const char *s)
160 | {
161 | uint8_t i;
162 | uint8_t cnt;
163 | cnt = u8x8_GetStringLineCnt(s);
164 | for( i = 0; i < cnt; i++ )
165 | {
166 | u8x8_DrawUTF8Line(u8x8, x, y, w, u8x8_GetStringLineStart(i, s));
167 | y++;
168 | }
169 | return cnt;
170 | }
171 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_u16toa.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_u16toa.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | */
36 |
37 |
38 | #include "u8x8.h"
39 |
40 | const char *u8x8_u16toap(char * dest, uint16_t v)
41 | {
42 | uint8_t pos;
43 | uint8_t d;
44 | uint16_t c;
45 | c = 10000;
46 | for( pos = 0; pos < 5; pos++ )
47 | {
48 | d = '0';
49 | while( v >= c )
50 | {
51 | v -= c;
52 | d++;
53 | }
54 | dest[pos] = d;
55 | c /= 10;
56 | }
57 | dest[5] = '\0';
58 | return dest;
59 | }
60 |
61 | /* v = value, d = number of digits */
62 | const char *u8x8_u16toa(uint16_t v, uint8_t d)
63 | {
64 | static char buf[6];
65 | d = 5-d;
66 | return u8x8_u16toap(buf, v) + d;
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/Src/u8g2/u8x8_u8toa.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_u8toa.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 |
37 | #include "u8x8.h"
38 |
39 | static const unsigned char u8x8_u8toa_tab[3] = { 100, 10, 1 } ;
40 | const char *u8x8_u8toap(char * dest, uint8_t v)
41 | {
42 | uint8_t pos;
43 | uint8_t d;
44 | uint8_t c;
45 | for( pos = 0; pos < 3; pos++ )
46 | {
47 | d = '0';
48 | c = *(u8x8_u8toa_tab+pos);
49 | while( v >= c )
50 | {
51 | v -= c;
52 | d++;
53 | }
54 | dest[pos] = d;
55 | }
56 | dest[3] = '\0';
57 | return dest;
58 | }
59 |
60 | /* v = value, d = number of digits */
61 | const char *u8x8_u8toa(uint8_t v, uint8_t d)
62 | {
63 | static char buf[4];
64 | d = 3-d;
65 | return u8x8_u8toap(buf, v) + d;
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/Src/u8g2_stm32f4.c:
--------------------------------------------------------------------------------
1 | /*
2 | * u8g2_stm32f4.c
3 | *
4 | * Created on: 2019. 3. 27.
5 | * Author: KIKI
6 | */
7 |
8 | #include "main.h"
9 | #include "stm32f4xx_hal.h"
10 | #include "u8g2/u8g2.h"
11 |
12 | #define DEVICE_ADDRESS 0x3C
13 | #define TX_TIMEOUT 100
14 |
15 | extern SPI_HandleTypeDef hspi2;
16 | extern I2C_HandleTypeDef hi2c1;
17 |
18 | uint8_t u8x8_stm32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
19 | {
20 | /* STM32 supports HW SPI, Remove unused cases like U8X8_MSG_DELAY_XXX & U8X8_MSG_GPIO_XXX */
21 | switch(msg)
22 | {
23 | case U8X8_MSG_GPIO_AND_DELAY_INIT:
24 | /* Insert codes for initialization */
25 | break;
26 | case U8X8_MSG_DELAY_MILLI:
27 | /* ms Delay */
28 | HAL_Delay(arg_int);
29 | break;
30 | case U8X8_MSG_GPIO_CS:
31 | /* Insert codes for SS pin control */
32 | HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, arg_int);
33 | break;
34 | case U8X8_MSG_GPIO_DC:
35 | /* Insert codes for DC pin control */
36 | HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, arg_int);
37 | break;
38 | case U8X8_MSG_GPIO_RESET:
39 | /* Insert codes for RST pin control */
40 | HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, arg_int);
41 | break;
42 | }
43 | return 1;
44 | }
45 |
46 | uint8_t u8x8_byte_stm32_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
47 | {
48 | switch(msg) {
49 | case U8X8_MSG_BYTE_SEND:
50 | /* Insert codes to transmit data */
51 | if(HAL_SPI_Transmit(&hspi2, arg_ptr, arg_int, TX_TIMEOUT) != HAL_OK) return 0;
52 | break;
53 | case U8X8_MSG_BYTE_INIT:
54 | /* Insert codes to begin SPI transmission */
55 | break;
56 | case U8X8_MSG_BYTE_SET_DC:
57 | /* Control DC pin, U8X8_MSG_GPIO_DC will be called */
58 | u8x8_gpio_SetDC(u8x8, arg_int);
59 | break;
60 | case U8X8_MSG_BYTE_START_TRANSFER:
61 | /* Select slave, U8X8_MSG_GPIO_CS will be called */
62 | u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
63 | HAL_Delay(1);
64 | break;
65 | case U8X8_MSG_BYTE_END_TRANSFER:
66 | HAL_Delay(1);
67 | /* Insert codes to end SPI transmission */
68 | u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
69 | break;
70 | default:
71 | return 0;
72 | }
73 | return 1;
74 | }
75 |
76 | uint8_t u8x8_byte_stm32_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
77 | {
78 | /* u8g2/u8x8 will never send more than 32 bytes between START_TRANSFER and END_TRANSFER */
79 | static uint8_t buffer[32];
80 | static uint8_t buf_idx;
81 | uint8_t *data;
82 |
83 | switch(msg)
84 | {
85 | case U8X8_MSG_BYTE_SEND:
86 | data = (uint8_t *)arg_ptr;
87 | while( arg_int > 0 )
88 | {
89 | buffer[buf_idx++] = *data;
90 | data++;
91 | arg_int--;
92 | }
93 | break;
94 | case U8X8_MSG_BYTE_INIT:
95 | /* add your custom code to init i2c subsystem */
96 | break;
97 | case U8X8_MSG_BYTE_SET_DC:
98 | break;
99 | case U8X8_MSG_BYTE_START_TRANSFER:
100 | buf_idx = 0;
101 | break;
102 | case U8X8_MSG_BYTE_END_TRANSFER:
103 | if(HAL_I2C_Master_Transmit(&hi2c1, (DEVICE_ADDRESS << 1), buffer, buf_idx, TX_TIMEOUT) != HAL_OK) return 0;
104 | break;
105 | default:
106 | return 0;
107 | }
108 | return 1;
109 | }
110 |
--------------------------------------------------------------------------------
/u8g2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eziya/STM32_HAL_U8G2_OLED/cec4c5ceac4937fb9d6c65c932ef5553c3821841/u8g2.jpg
--------------------------------------------------------------------------------