From 9df0cc9acb33faa5265a34d1c29b480ecdc249d9 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 17 Nov 2024 12:47:42 -0800 Subject: [PATCH] Use -DBOARD_CUSTOM instead of -DCUSTOM_BOARD_INC=boards_defines. This allows a more standard #include "boards.h" and in turn allows vscode to understand all the pin definitions. Now, one can hover the mouse pointer over a symbol like `BSP_BUTTON_0` and number 5 will shown correctly. --- .vscode/c_cpp_properties.json | 2 +- fw/application/.vscode/c_cpp_properties.json | 2 +- fw/application/Makefile | 4 +- .../src/app/settings/scene/settings_scene.c | 19 ++- .../src/app/settings/scene/settings_scene.h | 7 +- .../src/{boards_defines.h => custom_board.h} | 17 ++- fw/application/src/hal/hal_spi_bus.c | 13 +- fw/application/src/hal/hal_spi_flash.c | 88 ++++++------ fw/application/src/mod/vfs/vfs.h | 7 +- fw/application/src/mod/vfs/vfs_driver_lfs.c | 54 ++++---- .../src/mod/vfs/vfs_driver_spiffs.c | 2 +- fw/application/src/mui/mui_u8g2.c | 2 +- fw/bootloader/Makefile | 4 +- fw/bootloader/src/lcd_drv.c | 130 +++++++++--------- 14 files changed, 165 insertions(+), 186 deletions(-) rename fw/application/src/{boards_defines.h => custom_board.h} (59%) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index b3a519e7..04f08af7 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -11,7 +11,7 @@ "${workspaceFolder}/fw/application/config/sdk_config.h" ], "defines": [ - "BOARD_PCA10056", + "BOARD_CUSTOM", "FLOAT_ABI_HARD", "NRF52", "NRF52832_XXAA", diff --git a/fw/application/.vscode/c_cpp_properties.json b/fw/application/.vscode/c_cpp_properties.json index 78ca8a7c..72a57357 100644 --- a/fw/application/.vscode/c_cpp_properties.json +++ b/fw/application/.vscode/c_cpp_properties.json @@ -11,7 +11,7 @@ "${workspaceFolder}/config/sdk_config.h" ], "defines": [ - "BOARD_PCA10056", + "BOARD_CUSTOM", "FLOAT_ABI_HARD", "NRF52", "NRF52832_XXAA", diff --git a/fw/application/Makefile b/fw/application/Makefile index 0cf4c9a5..ade90157 100644 --- a/fw/application/Makefile +++ b/fw/application/Makefile @@ -600,7 +600,7 @@ CFLAGS += $(OPT) CFLAGS += -DAPP_TIMER_V2 CFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED #CFLAGS += -DBOARD_PCA10040 -CFLAGS += -DCUSTOM_BOARD_INC=boards_defines +CFLAGS += -DBOARD_CUSTOM #CFLAGS += -DCONFIG_GPIO_AS_PINRESET CFLAGS += -DFLOAT_ABI_HARD CFLAGS += -DNRF52 @@ -639,7 +639,7 @@ ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 ASMFLAGS += -DAPP_TIMER_V2 ASMFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED # ASMFLAGS += -DBOARD_PCA10040 -ASMFLAGS += -DCUSTOM_BOARD_INC=am_board +ASMFLAGS += -DBOARD_CUSTOM # ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET ASMFLAGS += -DFLOAT_ABI_HARD ASMFLAGS += -DNRF52 diff --git a/fw/application/src/app/settings/scene/settings_scene.c b/fw/application/src/app/settings/scene/settings_scene.c index 43b2dbea..1bf83fb9 100644 --- a/fw/application/src/app/settings/scene/settings_scene.c +++ b/fw/application/src/app/settings/scene/settings_scene.c @@ -1,24 +1,21 @@ #include "mui_scene_dispatcher.h" +#include "boards.h" #include "settings_scene.h" -#include "boards_defines.h" - -#define ADD_SCENE(prefix, name, id) \ - void prefix##_scene_##name##_on_enter(void*); \ - void prefix##_scene_##name##_on_exit(void* context); +#define ADD_SCENE(prefix, name, id) \ + void prefix##_scene_##name##_on_enter(void *); \ + void prefix##_scene_##name##_on_exit(void *context); #include "settings_scene_config.h" #undef ADD_SCENE const mui_scene_t settings_scene_defines[] = { -#define ADD_SCENE(prefix, name, id) \ - { \ - .scene_id = (SETTINGS_SCENE_##id), \ - .enter_cb = prefix##_scene_##name##_on_enter, \ - .exit_cb = prefix##_scene_##name##_on_exit \ - }, \ +#define ADD_SCENE(prefix, name, id) \ + {.scene_id = (SETTINGS_SCENE_##id), \ + .enter_cb = prefix##_scene_##name##_on_enter, \ + .exit_cb = prefix##_scene_##name##_on_exit}, #include "settings_scene_config.h" #undef ADD_SCENE diff --git a/fw/application/src/app/settings/scene/settings_scene.h b/fw/application/src/app/settings/scene/settings_scene.h index f7d4bc26..1925bfa9 100644 --- a/fw/application/src/app/settings/scene/settings_scene.h +++ b/fw/application/src/app/settings/scene/settings_scene.h @@ -1,8 +1,8 @@ #ifndef AMIIBO_SCENE_H #define AMIIBO_SCENE_H +#include "boards.h" #include "mui_scene_dispatcher.h" -#include "boards_defines.h" // Generate scene id and total number #define ADD_SCENE(prefix, name, id) SETTINGS_SCENE_##id, @@ -14,7 +14,4 @@ typedef enum { extern const mui_scene_t settings_scene_defines[]; - - - -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/fw/application/src/boards_defines.h b/fw/application/src/custom_board.h similarity index 59% rename from fw/application/src/boards_defines.h rename to fw/application/src/custom_board.h index d685b39a..48655e17 100644 --- a/fw/application/src/boards_defines.h +++ b/fw/application/src/custom_board.h @@ -1,16 +1,15 @@ /* -* am_board.h -* -* Created on: 2021年8月22日 -* Author: solos -*/ -#ifndef BOARD_DEFINES_H_ -#define BOARD_DEFINES_H_ + * custom_board.h + * + * Created on: 2021年8月22日 + * Author: solos + */ +#ifndef CUSTOM_BOARD_H_ +#define CUSTOM_BOARD_H_ #ifdef __cplusplus extern "C" { #endif - #if defined(BOARD_OLED) #include "boards/board_oled.h" #elif defined(BOARD_LCD) @@ -23,4 +22,4 @@ extern "C" { } #endif -#endif /* AM_BOARD_H_ */ \ No newline at end of file +#endif // CUSTOM_BOARD_H_ \ No newline at end of file diff --git a/fw/application/src/hal/hal_spi_bus.c b/fw/application/src/hal/hal_spi_bus.c index a1ad459c..a88caf1b 100644 --- a/fw/application/src/hal/hal_spi_bus.c +++ b/fw/application/src/hal/hal_spi_bus.c @@ -2,7 +2,7 @@ #include "app_error.h" #include "app_util_platform.h" -#include "boards_defines.h" +#include "boards.h" #include #include @@ -12,12 +12,10 @@ #include "nrf_gpio.h" #include "nrf_log.h" - #define SPI_INSTANCE 0 static const nrfx_spim_t m_spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE); - void hal_spi_bus_init() { ret_code_t err_code; @@ -47,22 +45,19 @@ uint32_t hal_spi_bus_xfer(spi_transaction_t *p_trans) { uint32_t err_code = NRF_SUCCESS; nrfx_spim_xfer_desc_t spim_xfer_desc; - uint32_t max_xfer_bytes = - p_trans->tx_length > p_trans->rx_length ? p_trans->tx_length : p_trans->rx_length; + uint32_t max_xfer_bytes = p_trans->tx_length > p_trans->rx_length ? p_trans->tx_length : p_trans->rx_length; for (uint32_t i = 0; i < max_xfer_bytes; i += 128) { if (i < p_trans->tx_length) { spim_xfer_desc.p_tx_buffer = p_trans->p_tx_buffer + i; - spim_xfer_desc.tx_length = - p_trans->tx_length - i < 128 ? p_trans->tx_length - i : 128; + spim_xfer_desc.tx_length = p_trans->tx_length - i < 128 ? p_trans->tx_length - i : 128; } else { spim_xfer_desc.p_tx_buffer = NULL; spim_xfer_desc.tx_length = 0; } if (i < p_trans->rx_length) { spim_xfer_desc.p_rx_buffer = p_trans->p_rx_buffer + i; - spim_xfer_desc.rx_length = - p_trans->rx_length - i < 128 ? p_trans->rx_length - i : 128; + spim_xfer_desc.rx_length = p_trans->rx_length - i < 128 ? p_trans->rx_length - i : 128; } else { spim_xfer_desc.p_rx_buffer = NULL; spim_xfer_desc.rx_length = 0; diff --git a/fw/application/src/hal/hal_spi_flash.c b/fw/application/src/hal/hal_spi_flash.c index 33a9823f..9eb89e7a 100644 --- a/fw/application/src/hal/hal_spi_flash.c +++ b/fw/application/src/hal/hal_spi_flash.c @@ -8,7 +8,7 @@ #include "nrf_log.h" #include "nrf_log_ctrl.h" -#include "boards_defines.h" +#include "boards.h" #define PAGE_SIZE 256 #define CMD_ADDR_SIZE 4 @@ -41,12 +41,11 @@ #define MTC_W25Q64_DW (0x6017) /* W25Q64DW */ #define MTC_W25Q128_BV (0x4018) /* W25Q128BV */ #define MTC_W25Q256_FV (TBD) /* W25Q256FV */ -#define MTC_MX25L25645_GM2I (0x2019) /* MX25L25645GM2I-10G */ +#define MTC_MX25L25645_GM2I (0x2019) /* MX25L25645GM2I-10G */ static spi_device_t m_dev; -static inline void hal_spi_flash_write_read(uint8_t *tx_data, uint8_t tx_len, - uint8_t *rx_data, uint32_t rx_len) { +static inline void hal_spi_flash_write_read(uint8_t *tx_data, uint8_t tx_len, uint8_t *rx_data, uint32_t rx_len) { hal_spi_bus_aquire(&m_dev); spi_transaction_t trans_tx = { @@ -74,8 +73,7 @@ static inline void hal_spi_flash_write_read(uint8_t *tx_data, uint8_t tx_len, hal_spi_bus_release(&m_dev); } -static inline void hal_spi_flash_write_write(uint8_t *tx_data, uint8_t tx_len, - uint8_t *tx_data2, uint32_t tx_len2) { +static inline void hal_spi_flash_write_write(uint8_t *tx_data, uint8_t tx_len, uint8_t *tx_data2, uint32_t tx_len2) { hal_spi_bus_aquire(&m_dev); spi_transaction_t trans_tx = { @@ -150,47 +148,46 @@ ret_code_t hal_spi_flash_info(flash_info_t *info) { memory_type_capacity = (memory_type_capacity << 8) | rx[2]; switch (memory_type_capacity) { - case MTC_MX25L25645_GM2I: - NRF_LOG_INFO("MX25L25645GM2I-10G detection"); - info->block_count = 8192; - break; - case MTC_W25Q128_BV: - NRF_LOG_INFO("W25Q128BV detection"); - info->block_count = 4096; - break; - case MTC_W25Q64_BV_CV: - NRF_LOG_INFO("W25Q64BV or W25Q64CV detection"); - info->block_count = 2048; - break; - case MTC_W25Q64_DW: - NRF_LOG_INFO("W25Q64DW detection"); - info->block_count = 2048; - break; - case MTC_W25Q32_BV: - NRF_LOG_INFO("W25Q32BV detection"); - info->block_count = 1024; - break; - case MTC_W25Q32_DW: - NRF_LOG_INFO("W25Q32DW detection"); - info->block_count = 1024; - break; - case MTC_W25Q16_BV_CL_CV: - NRF_LOG_INFO("W25Q16BV or W25Q16CL or W25Q16CV detection"); - info->block_count = 512; - break; - case MTC_W25Q16_DW: - NRF_LOG_INFO("W25Q16DW detection"); - info->block_count = 512; - break; - default: - NRF_LOG_INFO("Memory Capacity error! %d", memory_type_capacity); - info->block_count = 0; - return NRF_ERROR_INVALID_PARAM; + case MTC_MX25L25645_GM2I: + NRF_LOG_INFO("MX25L25645GM2I-10G detection"); + info->block_count = 8192; + break; + case MTC_W25Q128_BV: + NRF_LOG_INFO("W25Q128BV detection"); + info->block_count = 4096; + break; + case MTC_W25Q64_BV_CV: + NRF_LOG_INFO("W25Q64BV or W25Q64CV detection"); + info->block_count = 2048; + break; + case MTC_W25Q64_DW: + NRF_LOG_INFO("W25Q64DW detection"); + info->block_count = 2048; + break; + case MTC_W25Q32_BV: + NRF_LOG_INFO("W25Q32BV detection"); + info->block_count = 1024; + break; + case MTC_W25Q32_DW: + NRF_LOG_INFO("W25Q32DW detection"); + info->block_count = 1024; + break; + case MTC_W25Q16_BV_CL_CV: + NRF_LOG_INFO("W25Q16BV or W25Q16CL or W25Q16CV detection"); + info->block_count = 512; + break; + case MTC_W25Q16_DW: + NRF_LOG_INFO("W25Q16DW detection"); + info->block_count = 512; + break; + default: + NRF_LOG_INFO("Memory Capacity error! %d", memory_type_capacity); + info->block_count = 0; + return NRF_ERROR_INVALID_PARAM; } return NRF_SUCCESS; } - ret_code_t hal_spi_flash_read(uint32_t address, void *buffer, size_t size) { uint8_t tx[4]; @@ -241,7 +238,4 @@ ret_code_t hal_spi_flash_erase(uint32_t address) { return NRF_SUCCESS; } - -void hal_spi_flash_sleep(){ - hal_spi_flash_write_cmd(CMD_DP); -} \ No newline at end of file +void hal_spi_flash_sleep() { hal_spi_flash_write_cmd(CMD_DP); } \ No newline at end of file diff --git a/fw/application/src/mod/vfs/vfs.h b/fw/application/src/mod/vfs/vfs.h index b3c8d5b2..d25bef8d 100644 --- a/fw/application/src/mod/vfs/vfs.h +++ b/fw/application/src/mod/vfs/vfs.h @@ -5,7 +5,7 @@ #include #include -#include "boards_defines.h" +#include "boards.h" // Virtual Object Storage @@ -91,8 +91,7 @@ typedef struct { int32_t (*close_file)(vfs_file_t *fd); int32_t (*read_file)(vfs_file_t *fd, void *buff, size_t buff_size); int32_t (*write_file)(vfs_file_t *fd, void *buff, size_t buff_size); - int32_t (*update_file_meta)(const char* file, void* meta, size_t meta_size); - + int32_t (*update_file_meta)(const char *file, void *meta, size_t meta_size); /**short opearation*/ int32_t (*write_file_data)(const char *file, void *buff, size_t buff_size); @@ -105,7 +104,7 @@ typedef struct { bool vfs_drive_enabled(vfs_drive_t drive); vfs_driver_t *vfs_get_driver(vfs_drive_t drive); -vfs_driver_t* vfs_get_default_driver(); +vfs_driver_t *vfs_get_default_driver(); vfs_drive_t vfs_get_default_drive(); #endif \ No newline at end of file diff --git a/fw/application/src/mod/vfs/vfs_driver_lfs.c b/fw/application/src/mod/vfs/vfs_driver_lfs.c index 26e06ddf..3748a870 100644 --- a/fw/application/src/mod/vfs/vfs_driver_lfs.c +++ b/fw/application/src/mod/vfs/vfs_driver_lfs.c @@ -1,5 +1,5 @@ -#include "boards_defines.h" +#include "boards.h" #ifdef VFS_LFS_ENABLE #include "vfs_driver_fs.h" @@ -244,7 +244,7 @@ int32_t vfs_lfs_read_dir_internal(vfs_dir_t *fd, vfs_obj_t *obj) { int32_t vfs_lfs_read_dir(vfs_dir_t *fd, vfs_obj_t *obj) { int32_t err; - //skip . and .. directory + // skip . and .. directory while ((err = vfs_lfs_read_dir_internal(fd, obj)) == VFS_OK) { if (strcmp(obj->name, ".") != 0 && strcmp(obj->name, "..") != 0) { return err; @@ -395,29 +395,29 @@ int32_t vfs_lfs_remove_file(const char *file) { // TODO const vfs_driver_t vfs_driver_fs = {.mount = vfs_lfs_mount, - .umount = vfs_lfs_umount, - .format = vfs_lfs_format, - .mounted = vfs_lfs_mounted, - .stat = vfs_lfs_stat, - - .stat_file = vfs_lfs_stat_file, - - .open_dir = vfs_lfs_open_dir, - .read_dir = vfs_lfs_read_dir, - .close_dir = vfs_lfs_close_dir, - .create_dir = vfs_lfs_create_dir, - .remove_dir = vfs_lfs_remove_dir, - .rename_dir = vfs_lfs_rename_dir, - - .open_file = vfs_lfs_open_file, - .close_file = vfs_lfs_close_file, - .read_file = vfs_lfs_read_file, - .write_file = vfs_lfs_write_file, - .update_file_meta = vfs_lfs_update_file_meta, - - .write_file_data = vfs_lfs_write_file_data, - .read_file_data = vfs_lfs_read_file_data, - - .rename_file = vfs_lfs_rename_file, - .remove_file = vfs_lfs_remove_file}; + .umount = vfs_lfs_umount, + .format = vfs_lfs_format, + .mounted = vfs_lfs_mounted, + .stat = vfs_lfs_stat, + + .stat_file = vfs_lfs_stat_file, + + .open_dir = vfs_lfs_open_dir, + .read_dir = vfs_lfs_read_dir, + .close_dir = vfs_lfs_close_dir, + .create_dir = vfs_lfs_create_dir, + .remove_dir = vfs_lfs_remove_dir, + .rename_dir = vfs_lfs_rename_dir, + + .open_file = vfs_lfs_open_file, + .close_file = vfs_lfs_close_file, + .read_file = vfs_lfs_read_file, + .write_file = vfs_lfs_write_file, + .update_file_meta = vfs_lfs_update_file_meta, + + .write_file_data = vfs_lfs_write_file_data, + .read_file_data = vfs_lfs_read_file_data, + + .rename_file = vfs_lfs_rename_file, + .remove_file = vfs_lfs_remove_file}; #endif \ No newline at end of file diff --git a/fw/application/src/mod/vfs/vfs_driver_spiffs.c b/fw/application/src/mod/vfs/vfs_driver_spiffs.c index 18c875be..3894e688 100644 --- a/fw/application/src/mod/vfs/vfs_driver_spiffs.c +++ b/fw/application/src/mod/vfs/vfs_driver_spiffs.c @@ -1,4 +1,4 @@ -#include "boards_defines.h" +#include "boards.h" #ifdef VFS_SPIFFS_ENABLE diff --git a/fw/application/src/mui/mui_u8g2.c b/fw/application/src/mui/mui_u8g2.c index f023c0dc..9f0ad099 100644 --- a/fw/application/src/mui/mui_u8g2.c +++ b/fw/application/src/mui/mui_u8g2.c @@ -78,7 +78,7 @@ #include "app_pwm.h" -#include "boards_defines.h" +#include "boards.h" u8g2_t u8g2; static spi_device_t m_dev; diff --git a/fw/bootloader/Makefile b/fw/bootloader/Makefile index 81456318..38b60eb9 100644 --- a/fw/bootloader/Makefile +++ b/fw/bootloader/Makefile @@ -184,7 +184,7 @@ CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # keep every function in a separate section, this allows linker to discard unused ones CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing CFLAGS += -fno-builtin -fshort-enums -CFLAGS += -DCUSTOM_BOARD_INC=boards_defines +CFLAGS += -DBOARD_CUSTOM CFLAGS += -DBOARD_$(BOARD) # C++ flags common to all targets @@ -211,7 +211,7 @@ ASMFLAGS += -DuECC_OPTIMIZATION_LEVEL=3 ASMFLAGS += -DuECC_SQUARE_FUNC=0 ASMFLAGS += -DuECC_SUPPORT_COMPRESSED_POINT=0 ASMFLAGS += -DuECC_VLI_NATIVE_LITTLE_ENDIAN=1 -ASMFLAGS += -DCUSTOM_BOARD_INC=boards_defines +ASMFLAGS += -DBOARD_CUSTOM ASMFLAGS += -DBOARD_$(BOARD) # Linker flags diff --git a/fw/bootloader/src/lcd_drv.c b/fw/bootloader/src/lcd_drv.c index 3f894ed6..756a7d9f 100644 --- a/fw/bootloader/src/lcd_drv.c +++ b/fw/bootloader/src/lcd_drv.c @@ -8,20 +8,19 @@ #include "nrf_log.h" #include -#include "boards_defines.h" - +#include "boards.h" #ifdef OLED_TYPE_SH1106 - #define LCD_X_SIZE 132 +#define LCD_X_SIZE 132 #else - #define LCD_X_SIZE 128 +#define LCD_X_SIZE 128 #endif #define LCD_Y_SIZE 64 static bool m_screen_enabled = true; static uint8_t m_display_content[LCD_Y_SIZE / 8][LCD_X_SIZE]; -void delay(unsigned int delay) //锟接迟筹拷锟斤拷 +void delay(unsigned int delay) // 锟接迟筹拷锟斤拷 { unsigned int i, j; @@ -32,54 +31,54 @@ void delay(unsigned int delay) //锟接迟筹拷锟斤拷 void lcd_init(void) { lcd_comm_init(); - lcd_reset(); //硬复位 - #ifdef OLED_TYPE_SH1106 - lcd_write_command(0xAE); /*display off*/ - lcd_write_command(0x02); /*set lower column address*/ - lcd_write_command(0x10); /*set higher column address*/ - lcd_write_command(0x40); /*set display start line*/ - lcd_write_command(0xB0); /*set page address*/ - lcd_write_command(0x81); /*contract control*/ - lcd_write_command(0xcf); /*128*/ - lcd_write_command(0xA1); /*set segment remap*/ - lcd_write_command(0xA6); /*normal / reverse*/ - lcd_write_command(0xA8); /*multiplex ratio*/ - lcd_write_command(0x3F); /*duty = 1/64*/ - lcd_write_command(0xad); /*set charge pump enable*/ - lcd_write_command(0x8b); /* 0x8B ÄÚ¹© VCC */ - lcd_write_command(0x33); /*0X30---0X33 set VPP 9V */ - lcd_write_command(0xC8); /*Com scan direction*/ - lcd_write_command(0xD3); /*set display offset*/ - lcd_write_command(0x00); /* 0x20 */ - lcd_write_command(0xD5); /*set osc division*/ - lcd_write_command(0x80); - lcd_write_command(0xD9); /*set pre-charge period*/ - lcd_write_command(0x1f); /*0x22*/ - lcd_write_command(0xDA); /*set COM pins*/ - lcd_write_command(0x12); - lcd_write_command(0xdb); /*set vcomh*/ - lcd_write_command(0x40); - lcd_clear(); - lcd_write_command(0xAF); /*display ON*/ - - #else - lcd_write_command(0xe2); //软复位 - delay(10); - lcd_write_command(0xa2); //升压电路,电压管理电路 - lcd_write_command(0xa0); //0x20~0x27 为V5电压内部电阻调整设置 - lcd_write_command(0xc8); //设置EV 对比度 - lcd_write_command(0x23); //对比度值 - - lcd_write_command(0x81); //0x01~0x3f电量寄存器设置模式 - - lcd_write_command(0x32); //0xa0为Segment正向, 0xa1为Segment反向 - lcd_write_command(0x2f); //0xc0正向扫描, 0xc8反向扫描 - lcd_write_command(0xb0); //0xa6正向显示, 0xa7反向显示 - lcd_write_command(0xAF); //0xa4正常显示, 0xa5全屏显示 - lcd_write_command(0xA6); //背压比设置 - // lcd_write_command(0x10); //背压比值:0~10 - // lcd_write_command(0xaf); //开显示 - #endif + lcd_reset(); // 硬复位 +#ifdef OLED_TYPE_SH1106 + lcd_write_command(0xAE); /*display off*/ + lcd_write_command(0x02); /*set lower column address*/ + lcd_write_command(0x10); /*set higher column address*/ + lcd_write_command(0x40); /*set display start line*/ + lcd_write_command(0xB0); /*set page address*/ + lcd_write_command(0x81); /*contract control*/ + lcd_write_command(0xcf); /*128*/ + lcd_write_command(0xA1); /*set segment remap*/ + lcd_write_command(0xA6); /*normal / reverse*/ + lcd_write_command(0xA8); /*multiplex ratio*/ + lcd_write_command(0x3F); /*duty = 1/64*/ + lcd_write_command(0xad); /*set charge pump enable*/ + lcd_write_command(0x8b); /* 0x8B ÄÚ¹© VCC */ + lcd_write_command(0x33); /*0X30---0X33 set VPP 9V */ + lcd_write_command(0xC8); /*Com scan direction*/ + lcd_write_command(0xD3); /*set display offset*/ + lcd_write_command(0x00); /* 0x20 */ + lcd_write_command(0xD5); /*set osc division*/ + lcd_write_command(0x80); + lcd_write_command(0xD9); /*set pre-charge period*/ + lcd_write_command(0x1f); /*0x22*/ + lcd_write_command(0xDA); /*set COM pins*/ + lcd_write_command(0x12); + lcd_write_command(0xdb); /*set vcomh*/ + lcd_write_command(0x40); + lcd_clear(); + lcd_write_command(0xAF); /*display ON*/ + +#else + lcd_write_command(0xe2); // 软复位 + delay(10); + lcd_write_command(0xa2); // 升压电路,电压管理电路 + lcd_write_command(0xa0); // 0x20~0x27 为V5电压内部电阻调整设置 + lcd_write_command(0xc8); // 设置EV 对比度 + lcd_write_command(0x23); // 对比度值 + + lcd_write_command(0x81); // 0x01~0x3f电量寄存器设置模式 + + lcd_write_command(0x32); // 0xa0为Segment正向, 0xa1为Segment反向 + lcd_write_command(0x2f); // 0xc0正向扫描, 0xc8反向扫描 + lcd_write_command(0xb0); // 0xa6正向显示, 0xa7反向显示 + lcd_write_command(0xAF); // 0xa4正常显示, 0xa5全屏显示 + lcd_write_command(0xA6); // 背压比设置 + // lcd_write_command(0x10); //背压比值:0~10 + // lcd_write_command(0xaf); //开显示 +#endif } void lcd_uninit() { lcd_comm_uninit(); } @@ -107,14 +106,14 @@ void lcd_show_pic(uint8_t col, uint8_t row, uint8_t width, uint8_t high, const u width > LCD_X_SIZE) return; - int8_t start_row = (row % 8); //页内起始行 - uint8_t stop_row = (row + high) % 8; //页内起始行 - uint8_t page_offset = 0; //页内起始行 - uint8_t start_page = 0; //页内起始行 - uint8_t real_page = 0; //实际页数 - uint8_t str_page = (high + 7) / 8; //字符页数 - uint8_t col_offset = 0; //偏移列 - uint8_t real_width = width; //实际列数 + int8_t start_row = (row % 8); // 页内起始行 + uint8_t stop_row = (row + high) % 8; // 页内起始行 + uint8_t page_offset = 0; // 页内起始行 + uint8_t start_page = 0; // 页内起始行 + uint8_t real_page = 0; // 实际页数 + uint8_t str_page = (high + 7) / 8; // 字符页数 + uint8_t col_offset = 0; // 偏移列 + uint8_t real_width = width; // 实际列数 if (row < 0) { if (start_row) start_row += 8; @@ -141,14 +140,14 @@ void lcd_show_pic(uint8_t col, uint8_t row, uint8_t width, uint8_t high, const u for (uint8_t idx = 0; idx < real_width; idx++) { for (uint8_t num = 0, median = 0; num < real_page; num++) { - uint8_t front_half = 0; //前半部分 - uint8_t lower_half = 0; //后半部分 + uint8_t front_half = 0; // 前半部分 + uint8_t lower_half = 0; // 后半部分 uint16_t real_index = num * real_width + idx; uint16_t str_index = (page_offset + num) * width + col_offset + idx; if (page_offset + num < str_page) { - front_half = data[str_index] << start_row; //前半部分 - lower_half = data[str_index] >> (8 - start_row); //后半部分 + front_half = data[str_index] << start_row; // 前半部分 + lower_half = data[str_index] >> (8 - start_row); // 后半部分 } if (num == 0) { @@ -210,7 +209,6 @@ void lcd_show_font(uint8_t x, uint8_t y, uint8_t t_x, uint8_t t_y, uint8_t *font } } - void lcd_draw_str_0608(uint8_t x, uint8_t y, char *str) { show_str_0608(x, y, (uint8_t *)str, strlen(str)); } void lcd_draw_str_1608(uint8_t x, uint8_t y, char *str) { show_str_1608(x, y, (uint8_t *)str, strlen(str)); } \ No newline at end of file