From d19cf32a70ffd02171cdffc635569ff09df957c3 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 1 May 2024 11:15:53 +0800 Subject: [PATCH] update --- .vscode/settings.json | 20 +- app/app.uvoptx | 356 ++- app/app.uvprojx | 272 +-- app/config/sdk_config.h | 2 +- app/src/app_event.h | 1 - app/src/app_event_distribute.c | 23 - app/src/app_event_distribute.h | 15 - app/src/aproject_config/config.h | 65 + app/src/basic/FIR.c | 38 - app/src/basic/FIR.h | 14 - app/src/basic/HC_Chen_detect.c | 128 -- app/src/basic/HC_Chen_detect.h | 53 - app/src/basic/Pan_Tompkins_detect.c | 373 ---- app/src/basic/Pan_Tompkins_detect.h | 21 - app/src/basic/QRS.h | 30 - app/src/basic/So_Chen_detect.c | 93 - app/src/basic/So_Chen_detect.h | 42 - app/src/basic/adaptive_algorithm.c | 100 - app/src/basic/adaptive_algorithm.h | 41 - app/src/basic/device_version_info_mgr.c | 28 - app/src/basic/device_version_info_mgr.h | 14 - app/src/basic/m24m02/m24m02.c | 0 app/src/basic/m24m02/m24m02.h | 0 app/src/basic/qrs_time_domain_zh.c | 231 -- app/src/basic/qrs_time_domain_zh.h | 19 - app/src/basic/ssd1306/driver_ssd1306.c | 2353 -------------------- app/src/basic/ssd1306/driver_ssd1306.h | 1105 --------- app/src/basic/ssd1306/driver_ssd1306_basic.c | 792 ------- app/src/basic/ssd1306/driver_ssd1306_basic.h | 226 -- app/src/basic/ssd1306/driver_ssd1306_font.h | 350 --- app/src/basic/ssd1306/driver_ssd1306_interface.h | 192 -- app/src/basic/ssd1306/fontlib.c | 83 - app/src/basic/ssd1306/fontlib.h | 41 - app/src/basic/ssd1306/wave_drawer.c | 92 - app/src/basic/ssd1306/wave_drawer.h | 33 - app/src/basic/version.h | 12 - app/src/basic_service/app_event.h | 76 + app/src/basic_service/app_event_distribute.c | 23 + app/src/basic_service/app_event_distribute.h | 15 + app/src/basic_service/device_state.c | 27 + app/src/basic_service/device_state.h | 18 + app/src/basic_service/device_version_info_mgr.c | 27 + app/src/basic_service/device_version_info_mgr.h | 16 + app/src/ble_cmd_process_service.c | 482 ---- app/src/ble_cmd_process_service.h | 17 - app/src/board/ads1291/ads1291.c | 133 ++ app/src/board/ads1291/ads1291.h | 28 + app/src/board/ads1291/ads1291_type.h | 330 +++ app/src/board/ads1291/ads1292r_typ.h | 337 --- app/src/board/board.h | 51 - app/src/board/board_adc_module_ctrl.h | 2 +- app/src/board/board_battery_state.c | 2 +- app/src/board/board_battery_state.h | 2 +- app/src/board/board_beep_ctrl.h | 2 +- app/src/board/board_ecg_sensor.c | 37 +- app/src/board/board_ecg_sensor.h | 2 +- app/src/board/board_eeprom_driver.c | 2 - app/src/board/board_light_ctrl.c | 3 +- app/src/board/board_light_ctrl.h | 2 +- app/src/board/board_ssd1306_interface.c | 6 +- app/src/board/board_ssd1306_interface.h | 4 + app/src/board/ssd1306/driver_ssd1306.c | 2353 ++++++++++++++++++++ app/src/board/ssd1306/driver_ssd1306.h | 1105 +++++++++ app/src/board/ssd1306/driver_ssd1306_basic.c | 792 +++++++ app/src/board/ssd1306/driver_ssd1306_basic.h | 226 ++ app/src/board/ssd1306/driver_ssd1306_font.h | 350 +++ app/src/board/ssd1306/driver_ssd1306_interface.h | 192 ++ app/src/board/ssd1306/fontlib.c | 83 + app/src/board/ssd1306/fontlib.h | 41 + app/src/board/ssd1306/wave_drawer.c | 92 + app/src/board/ssd1306/wave_drawer.h | 33 + app/src/config.h | 3 - app/src/device_controler.c | 0 app/src/device_controler.h | 0 app/src/device_state.c | 27 - app/src/device_state.h | 90 - app/src/display_manager.c | 446 ---- app/src/display_manager.h | 81 - app/src/display_manager_res.h | 5 - app/src/font.h | 275 --- app/src/heart_ware_sample_data_mgr.c | 108 - app/src/heart_ware_sample_data_mgr.h | 9 - app/src/heart_wave_sample_data_pre_process.c | 107 - app/src/heart_wave_sample_data_pre_process.h | 9 - app/src/heart_wave_sample_service.c | 84 - app/src/heart_wave_sample_service.h | 17 - app/src/main.c | 8 +- app/src/one_conduction_main.c | 18 +- app/src/sample_data_manager.c | 91 - app/src/sample_data_manager.h | 46 - .../ble_cmd_processer/ble_cmd_process_service.c | 483 ++++ .../ble_cmd_processer/ble_cmd_process_service.h | 17 + app/src/service/display_mgr/display_manager.c | 443 ++++ app/src/service/display_mgr/display_manager.h | 81 + app/src/service/display_mgr/font.h | 275 +++ .../heart_ware_sample_data_mgr.c | 106 + .../heart_ware_sample_data_mgr.h | 9 + .../heart_wave_sample_data_pre_process.c | 12 + .../heart_wave_sample_data_pre_process.h | 9 + .../heart_wave_sample_service.c | 83 + .../heart_wave_sample_service.h | 17 + app/src/service/storage/sample_data_manager.c | 92 + app/src/service/storage/sample_data_manager.h | 46 + app/src/service/storage/storage_service.h | 3 + app/src/service/storage/zeeprom_fs.c | 572 +++++ app/src/service/storage/zeeprom_fs.h | 108 + app/src/zeeprom_fs.c | 572 ----- app/src/zeeprom_fs.h | 108 - bak/FIR.c | 38 + bak/FIR.h | 14 + bak/HC_Chen_detect.c | 128 ++ bak/HC_Chen_detect.h | 53 + bak/Pan_Tompkins_detect.c | 373 ++++ bak/Pan_Tompkins_detect.h | 21 + bak/QRS.h | 30 + bak/So_Chen_detect.c | 93 + bak/So_Chen_detect.h | 42 + bak/adaptive_algorithm.c | 100 + bak/adaptive_algorithm.h | 41 + bak/qrs_time_domain_zh.c | 231 ++ bak/qrs_time_domain_zh.h | 19 + libznordic | 2 +- sdk | 2 +- 123 files changed, 9860 insertions(+), 9956 deletions(-) delete mode 100644 app/src/app_event.h delete mode 100644 app/src/app_event_distribute.c delete mode 100644 app/src/app_event_distribute.h create mode 100644 app/src/aproject_config/config.h delete mode 100644 app/src/basic/FIR.c delete mode 100644 app/src/basic/FIR.h delete mode 100644 app/src/basic/HC_Chen_detect.c delete mode 100644 app/src/basic/HC_Chen_detect.h delete mode 100644 app/src/basic/Pan_Tompkins_detect.c delete mode 100644 app/src/basic/Pan_Tompkins_detect.h delete mode 100644 app/src/basic/QRS.h delete mode 100644 app/src/basic/So_Chen_detect.c delete mode 100644 app/src/basic/So_Chen_detect.h delete mode 100644 app/src/basic/adaptive_algorithm.c delete mode 100644 app/src/basic/adaptive_algorithm.h delete mode 100644 app/src/basic/device_version_info_mgr.c delete mode 100644 app/src/basic/device_version_info_mgr.h delete mode 100644 app/src/basic/m24m02/m24m02.c delete mode 100644 app/src/basic/m24m02/m24m02.h delete mode 100644 app/src/basic/qrs_time_domain_zh.c delete mode 100644 app/src/basic/qrs_time_domain_zh.h delete mode 100644 app/src/basic/ssd1306/driver_ssd1306.c delete mode 100644 app/src/basic/ssd1306/driver_ssd1306.h delete mode 100644 app/src/basic/ssd1306/driver_ssd1306_basic.c delete mode 100644 app/src/basic/ssd1306/driver_ssd1306_basic.h delete mode 100644 app/src/basic/ssd1306/driver_ssd1306_font.h delete mode 100644 app/src/basic/ssd1306/driver_ssd1306_interface.h delete mode 100644 app/src/basic/ssd1306/fontlib.c delete mode 100644 app/src/basic/ssd1306/fontlib.h delete mode 100644 app/src/basic/ssd1306/wave_drawer.c delete mode 100644 app/src/basic/ssd1306/wave_drawer.h delete mode 100644 app/src/basic/version.h create mode 100644 app/src/basic_service/app_event.h create mode 100644 app/src/basic_service/app_event_distribute.c create mode 100644 app/src/basic_service/app_event_distribute.h create mode 100644 app/src/basic_service/device_state.c create mode 100644 app/src/basic_service/device_state.h create mode 100644 app/src/basic_service/device_version_info_mgr.c create mode 100644 app/src/basic_service/device_version_info_mgr.h delete mode 100644 app/src/ble_cmd_process_service.c delete mode 100644 app/src/ble_cmd_process_service.h create mode 100644 app/src/board/ads1291/ads1291.c create mode 100644 app/src/board/ads1291/ads1291.h create mode 100644 app/src/board/ads1291/ads1291_type.h delete mode 100644 app/src/board/ads1291/ads1292r_typ.h delete mode 100644 app/src/board/board.h create mode 100644 app/src/board/ssd1306/driver_ssd1306.c create mode 100644 app/src/board/ssd1306/driver_ssd1306.h create mode 100644 app/src/board/ssd1306/driver_ssd1306_basic.c create mode 100644 app/src/board/ssd1306/driver_ssd1306_basic.h create mode 100644 app/src/board/ssd1306/driver_ssd1306_font.h create mode 100644 app/src/board/ssd1306/driver_ssd1306_interface.h create mode 100644 app/src/board/ssd1306/fontlib.c create mode 100644 app/src/board/ssd1306/fontlib.h create mode 100644 app/src/board/ssd1306/wave_drawer.c create mode 100644 app/src/board/ssd1306/wave_drawer.h delete mode 100644 app/src/config.h delete mode 100644 app/src/device_controler.c delete mode 100644 app/src/device_controler.h delete mode 100644 app/src/device_state.c delete mode 100644 app/src/device_state.h delete mode 100644 app/src/display_manager.c delete mode 100644 app/src/display_manager.h delete mode 100644 app/src/display_manager_res.h delete mode 100644 app/src/font.h delete mode 100644 app/src/heart_ware_sample_data_mgr.c delete mode 100644 app/src/heart_ware_sample_data_mgr.h delete mode 100644 app/src/heart_wave_sample_data_pre_process.c delete mode 100644 app/src/heart_wave_sample_data_pre_process.h delete mode 100644 app/src/heart_wave_sample_service.c delete mode 100644 app/src/heart_wave_sample_service.h delete mode 100644 app/src/sample_data_manager.c delete mode 100644 app/src/sample_data_manager.h create mode 100644 app/src/service/ble_cmd_processer/ble_cmd_process_service.c create mode 100644 app/src/service/ble_cmd_processer/ble_cmd_process_service.h create mode 100644 app/src/service/display_mgr/display_manager.c create mode 100644 app/src/service/display_mgr/display_manager.h create mode 100644 app/src/service/display_mgr/font.h create mode 100644 app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c create mode 100644 app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h create mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c create mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h create mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_service.c create mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_service.h create mode 100644 app/src/service/storage/sample_data_manager.c create mode 100644 app/src/service/storage/sample_data_manager.h create mode 100644 app/src/service/storage/storage_service.h create mode 100644 app/src/service/storage/zeeprom_fs.c create mode 100644 app/src/service/storage/zeeprom_fs.h delete mode 100644 app/src/zeeprom_fs.c delete mode 100644 app/src/zeeprom_fs.h create mode 100644 bak/FIR.c create mode 100644 bak/FIR.h create mode 100644 bak/HC_Chen_detect.c create mode 100644 bak/HC_Chen_detect.h create mode 100644 bak/Pan_Tompkins_detect.c create mode 100644 bak/Pan_Tompkins_detect.h create mode 100644 bak/QRS.h create mode 100644 bak/So_Chen_detect.c create mode 100644 bak/So_Chen_detect.h create mode 100644 bak/adaptive_algorithm.c create mode 100644 bak/adaptive_algorithm.h create mode 100644 bak/qrs_time_domain_zh.c create mode 100644 bak/qrs_time_domain_zh.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 95c7c53..bd23f72 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -89,9 +89,9 @@ "stdarg.h": "c", "nrf_uarte.h": "c", "heart_rate_sensor_protocol.h": "c", - "ble_cmd_process_service.h": "c", + "service/ble_cmd_processer/ble_cmd_process_service.h": "c", "heart_wave_sample_service.h": "c", - "basic/device_version_info_mgr.h": "c", + "basic_service/device_version_info_mgr.h": "c", "nrf_uart.h": "c", "ads_cfg.h": "c", "sdk_config.h": "c", @@ -103,11 +103,11 @@ "board_battery_state.h": "c", "board_sdcard_driver.h": "c", "board_button.h": "c", - "app_event_distribute.h": "c", + "basic_service/app_event_distribute.h": "c", "board_beep_ctrl.h": "c", "nrf_soc.h": "c", "sample_data_manager_service.h": "c", - "app_event.h": "c", + "basic_service/app_event.h": "c", "compiler_abstraction.h": "c", "ble_nus_c.h": "c", "device_version_info_mgr.h": "c", @@ -115,7 +115,7 @@ "filter.h": "c", "filters.h": "c", "nrfx_rtc.h": "c", - "device_state.h": "c", + "basic_service/device_state.h": "c", "board_adc_module_ctrl.h": "c", "board_ecg_sensor.h": "c", "board_light_ctrl.h": "c", @@ -191,7 +191,15 @@ "heart_ware_sample_data_mgr.h": "c", "time.h": "c", "nrf_gpio.h": "c", - "nrf_drv_clock.h": "c" + "nrf_drv_clock.h": "c", + "ads1291_type.h": "c", + "qrs.h": "c", + "app_event.h": "c", + "app_event_distribute.h": "c", + "nrf_bootloader_info.h": "c", + "ble_cmd_process_service.h": "c", + "storage_service.h": "c", + "board_ssd1306_interface.h": "c" }, "files.encoding": "gbk" } \ No newline at end of file diff --git a/app/app.uvoptx b/app/app.uvoptx index b3d3821..30b741f 100644 --- a/app/app.uvoptx +++ b/app/app.uvoptx @@ -386,8 +386,8 @@ 0 0 0 - .\src\heart_wave_sample_service.c - heart_wave_sample_service.c + .\src\one_conduction_main.c + one_conduction_main.c 0 0 @@ -398,8 +398,8 @@ 0 0 0 - .\src\app_event_distribute.c - app_event_distribute.c + .\src\main.c + main.c 0 0 @@ -410,8 +410,8 @@ 0 0 0 - .\src\basic\m24m02\m24m02.c - m24m02.c + .\src\board\board_beep_ctrl.c + board_beep_ctrl.c 0 0 @@ -422,8 +422,8 @@ 0 0 0 - .\src\basic\ssd1306\driver_ssd1306.c - driver_ssd1306.c + .\src\board\board_adc_module_ctrl.c + board_adc_module_ctrl.c 0 0 @@ -434,8 +434,8 @@ 0 0 0 - .\src\basic\ssd1306\driver_ssd1306_basic.c - driver_ssd1306_basic.c + .\src\board\board_battery_state.c + board_battery_state.c 0 0 @@ -446,8 +446,8 @@ 0 0 0 - .\src\basic\ssd1306\fontlib.c - fontlib.c + .\src\board\board_ecg_sensor.c + board_ecg_sensor.c 0 0 @@ -458,8 +458,8 @@ 0 0 0 - .\src\basic\ssd1306\wave_drawer.c - wave_drawer.c + .\src\board\board_light_ctrl.c + board_light_ctrl.c 0 0 @@ -470,8 +470,8 @@ 0 0 0 - .\src\ble_cmd_process_service.c - ble_cmd_process_service.c + .\src\board\board_ssd1306_interface.c + board_ssd1306_interface.c 0 0 @@ -482,8 +482,8 @@ 0 0 0 - .\src\device_controler.c - device_controler.c + .\src\board\board_eeprom_driver.c + board_eeprom_driver.c 0 0 @@ -494,8 +494,8 @@ 0 0 0 - .\src\device_state.c - device_state.c + .\src\board\board_power_mgr.c + board_power_mgr.c 0 0 @@ -506,8 +506,8 @@ 0 0 0 - .\src\display_manager.c - display_manager.c + .\src\basic_service\device_state.c + device_state.c 0 0 @@ -518,8 +518,8 @@ 0 0 0 - .\src\one_conduction_main.c - one_conduction_main.c + .\src\basic_service\device_version_info_mgr.c + device_version_info_mgr.c 0 0 @@ -530,8 +530,8 @@ 0 0 0 - .\src\sample_data_manager.c - sample_data_manager.c + .\src\board\ssd1306\driver_ssd1306.c + driver_ssd1306.c 0 0 @@ -542,8 +542,8 @@ 0 0 0 - .\src\zeeprom_fs.c - zeeprom_fs.c + .\src\board\ssd1306\driver_ssd1306_basic.c + driver_ssd1306_basic.c 0 0 @@ -554,8 +554,8 @@ 0 0 0 - .\src\basic\device_version_info_mgr.c - device_version_info_mgr.c + .\src\board\ssd1306\fontlib.c + fontlib.c 0 0 @@ -566,8 +566,8 @@ 0 0 0 - .\src\main.c - main.c + .\src\board\ssd1306\wave_drawer.c + wave_drawer.c 0 0 @@ -578,8 +578,8 @@ 0 0 0 - .\src\board\board_beep_ctrl.c - board_beep_ctrl.c + .\src\service\ble_cmd_processer\ble_cmd_process_service.c + ble_cmd_process_service.c 0 0 @@ -590,8 +590,8 @@ 0 0 0 - .\src\board\board_adc_module_ctrl.c - board_adc_module_ctrl.c + .\src\service\display_mgr\display_manager.c + display_manager.c 0 0 @@ -602,8 +602,8 @@ 0 0 0 - .\src\board\board_battery_state.c - board_battery_state.c + .\src\service\heart_wave_sample_service\heart_ware_sample_data_mgr.c + heart_ware_sample_data_mgr.c 0 0 @@ -614,8 +614,8 @@ 0 0 0 - .\src\board\board_ecg_sensor.c - board_ecg_sensor.c + .\src\service\heart_wave_sample_service\heart_wave_sample_data_pre_process.c + heart_wave_sample_data_pre_process.c 0 0 @@ -626,8 +626,8 @@ 0 0 0 - .\src\board\board_light_ctrl.c - board_light_ctrl.c + .\src\service\heart_wave_sample_service\heart_wave_sample_service.c + heart_wave_sample_service.c 0 0 @@ -638,8 +638,8 @@ 0 0 0 - .\src\basic\FIR.c - FIR.c + .\src\service\storage\sample_data_manager.c + sample_data_manager.c 0 0 @@ -650,8 +650,8 @@ 0 0 0 - .\src\basic\HC_Chen_detect.c - HC_Chen_detect.c + .\src\service\storage\zeeprom_fs.c + zeeprom_fs.c 0 0 @@ -662,104 +662,8 @@ 0 0 0 - .\src\basic\So_Chen_detect.c - So_Chen_detect.c - 0 - 0 - - - 1 - 26 - 1 - 0 - 0 - 0 - .\src\basic\adaptive_algorithm.c - adaptive_algorithm.c - 0 - 0 - - - 1 - 27 - 1 - 0 - 0 - 0 - .\src\basic\Pan_Tompkins_detect.c - Pan_Tompkins_detect.c - 0 - 0 - - - 1 - 28 - 1 - 0 - 0 - 0 - .\src\basic\qrs_time_domain_zh.c - qrs_time_domain_zh.c - 0 - 0 - - - 1 - 29 - 1 - 0 - 0 - 0 - .\src\board\board_ssd1306_interface.c - board_ssd1306_interface.c - 0 - 0 - - - 1 - 30 - 1 - 0 - 0 - 0 - .\src\board\board_eeprom_driver.c - board_eeprom_driver.c - 0 - 0 - - - 1 - 31 - 1 - 0 - 0 - 0 - .\src\board\board_power_mgr.c - board_power_mgr.c - 0 - 0 - - - 1 - 32 - 1 - 0 - 0 - 0 - .\src\heart_ware_sample_data_mgr.c - heart_ware_sample_data_mgr.c - 0 - 0 - - - 1 - 33 - 1 - 0 - 0 - 0 - .\src\heart_wave_sample_data_pre_process.c - heart_wave_sample_data_pre_process.c + .\src\basic_service\app_event_distribute.c + app_event_distribute.c 0 0 @@ -773,7 +677,7 @@ 0 2 - 34 + 26 1 0 0 @@ -793,7 +697,7 @@ 0 3 - 35 + 27 1 0 0 @@ -805,7 +709,7 @@ 3 - 36 + 28 1 0 0 @@ -825,7 +729,7 @@ 0 4 - 37 + 29 1 0 0 @@ -845,7 +749,7 @@ 0 5 - 38 + 30 1 0 0 @@ -857,7 +761,7 @@ 5 - 39 + 31 1 0 0 @@ -869,7 +773,7 @@ 5 - 40 + 32 1 0 0 @@ -881,7 +785,7 @@ 5 - 41 + 33 1 0 0 @@ -893,7 +797,7 @@ 5 - 42 + 34 1 0 0 @@ -905,7 +809,7 @@ 5 - 43 + 35 1 0 0 @@ -917,7 +821,7 @@ 5 - 44 + 36 1 0 0 @@ -929,7 +833,7 @@ 5 - 45 + 37 1 0 0 @@ -949,7 +853,7 @@ 0 6 - 46 + 38 1 0 0 @@ -963,13 +867,13 @@ nRF_Drivers - 0 + 1 0 0 0 7 - 47 + 39 1 0 0 @@ -981,7 +885,7 @@ 7 - 48 + 40 1 0 0 @@ -993,7 +897,7 @@ 7 - 49 + 41 1 0 0 @@ -1005,7 +909,7 @@ 7 - 50 + 42 1 0 0 @@ -1017,7 +921,7 @@ 7 - 51 + 43 1 0 0 @@ -1029,7 +933,7 @@ 7 - 52 + 44 1 0 0 @@ -1041,7 +945,7 @@ 7 - 53 + 45 1 0 0 @@ -1053,7 +957,7 @@ 7 - 54 + 46 1 0 0 @@ -1065,7 +969,7 @@ 7 - 55 + 47 1 0 0 @@ -1077,7 +981,7 @@ 7 - 56 + 48 1 0 0 @@ -1089,7 +993,7 @@ 7 - 57 + 49 1 0 0 @@ -1101,7 +1005,7 @@ 7 - 58 + 50 1 0 0 @@ -1113,7 +1017,7 @@ 7 - 59 + 51 1 0 0 @@ -1125,7 +1029,7 @@ 7 - 60 + 52 1 0 0 @@ -1137,7 +1041,7 @@ 7 - 61 + 53 1 0 0 @@ -1149,7 +1053,7 @@ 7 - 62 + 54 1 0 0 @@ -1161,7 +1065,7 @@ 7 - 63 + 55 1 0 0 @@ -1173,7 +1077,7 @@ 7 - 64 + 56 1 0 0 @@ -1185,7 +1089,7 @@ 7 - 65 + 57 1 0 0 @@ -1197,7 +1101,7 @@ 7 - 66 + 58 1 0 0 @@ -1217,7 +1121,7 @@ 0 8 - 67 + 59 1 0 0 @@ -1229,7 +1133,7 @@ 8 - 68 + 60 1 0 0 @@ -1241,7 +1145,7 @@ 8 - 69 + 61 1 0 0 @@ -1253,7 +1157,7 @@ 8 - 70 + 62 1 0 0 @@ -1265,7 +1169,7 @@ 8 - 71 + 63 1 0 0 @@ -1277,7 +1181,7 @@ 8 - 72 + 64 1 0 0 @@ -1289,7 +1193,7 @@ 8 - 73 + 65 1 0 0 @@ -1301,7 +1205,7 @@ 8 - 74 + 66 1 0 0 @@ -1313,7 +1217,7 @@ 8 - 75 + 67 1 0 0 @@ -1325,7 +1229,7 @@ 8 - 76 + 68 1 0 0 @@ -1337,7 +1241,7 @@ 8 - 77 + 69 1 0 0 @@ -1349,7 +1253,7 @@ 8 - 78 + 70 1 0 0 @@ -1361,7 +1265,7 @@ 8 - 79 + 71 1 0 0 @@ -1373,7 +1277,7 @@ 8 - 80 + 72 1 0 0 @@ -1385,7 +1289,7 @@ 8 - 81 + 73 1 0 0 @@ -1397,7 +1301,7 @@ 8 - 82 + 74 1 0 0 @@ -1409,7 +1313,7 @@ 8 - 83 + 75 1 0 0 @@ -1421,7 +1325,7 @@ 8 - 84 + 76 1 0 0 @@ -1433,7 +1337,7 @@ 8 - 85 + 77 1 0 0 @@ -1445,7 +1349,7 @@ 8 - 86 + 78 1 0 0 @@ -1457,7 +1361,7 @@ 8 - 87 + 79 1 0 0 @@ -1469,7 +1373,7 @@ 8 - 88 + 80 1 0 0 @@ -1481,7 +1385,7 @@ 8 - 89 + 81 1 0 0 @@ -1493,7 +1397,7 @@ 8 - 90 + 82 1 0 0 @@ -1505,7 +1409,7 @@ 8 - 91 + 83 1 0 0 @@ -1517,7 +1421,7 @@ 8 - 92 + 84 1 0 0 @@ -1529,7 +1433,7 @@ 8 - 93 + 85 1 0 0 @@ -1549,7 +1453,7 @@ 0 9 - 94 + 86 1 0 0 @@ -1561,7 +1465,7 @@ 9 - 95 + 87 1 0 0 @@ -1573,7 +1477,7 @@ 9 - 96 + 88 1 0 0 @@ -1585,7 +1489,7 @@ 9 - 97 + 89 1 0 0 @@ -1597,7 +1501,7 @@ 9 - 98 + 90 1 0 0 @@ -1609,7 +1513,7 @@ 9 - 99 + 91 1 0 0 @@ -1629,7 +1533,7 @@ 0 10 - 100 + 92 1 0 0 @@ -1641,7 +1545,7 @@ 10 - 101 + 93 1 0 0 @@ -1653,7 +1557,7 @@ 10 - 102 + 94 1 0 0 @@ -1673,7 +1577,7 @@ 0 11 - 103 + 95 1 0 0 @@ -1685,7 +1589,7 @@ 11 - 104 + 96 1 0 0 @@ -1697,7 +1601,7 @@ 11 - 105 + 97 1 0 0 @@ -1717,7 +1621,7 @@ 0 12 - 106 + 98 1 0 0 @@ -1729,7 +1633,7 @@ 12 - 107 + 99 1 0 0 @@ -1741,7 +1645,7 @@ 12 - 108 + 100 1 0 0 @@ -1761,7 +1665,7 @@ 0 13 - 109 + 101 1 0 0 @@ -1773,7 +1677,7 @@ 13 - 110 + 102 1 0 0 @@ -1793,7 +1697,7 @@ 0 14 - 111 + 103 1 0 0 @@ -1805,7 +1709,7 @@ 14 - 112 + 104 1 0 0 @@ -1817,7 +1721,7 @@ 14 - 113 + 105 1 0 0 @@ -1829,7 +1733,7 @@ 14 - 114 + 106 1 0 0 diff --git a/app/app.uvprojx b/app/app.uvprojx index df1da2f..fa261df 100644 --- a/app/app.uvprojx +++ b/app/app.uvprojx @@ -339,7 +339,7 @@ --reduce_paths --diag_suppress=1295 --diag_suppress=1 --diag_suppress=174 BL_SETTINGS_ACCESS_ONLY NRF_DFU_SVCI_ENABLED NRF_DFU_TRANSPORT_BLE=1 CONFIG_NFCT_PINS_AS_GPIOS APP_TIMER_V2 APP_TIMER_V2_RTC1_ENABLED BOARD_PCA10100 FLOAT_ABI_HARD NRF52833_XXAA NRF_SD_BLE_API_VERSION=7 S140 SOFTDEVICE_PRESENT __HEAP_SIZE=5120 __STACK_SIZE=5120 - ..\sdk\config;..\sdk\components;..\sdk\components\ble\ble_advertising;..\sdk\components\ble\ble_dtm;..\sdk\components\ble\ble_link_ctx_manager;..\sdk\components\ble\ble_racp;..\sdk\components\ble\ble_services\ble_ancs_c;..\sdk\components\ble\ble_services\ble_ans_c;..\sdk\components\ble\ble_services\ble_bas;..\sdk\components\ble\ble_services\ble_bas_c;..\sdk\components\ble\ble_services\ble_cscs;..\sdk\components\ble\ble_services\ble_cts_c;..\sdk\components\ble\ble_services\ble_dfu;..\sdk\components\ble\ble_services\ble_dis;..\sdk\components\ble\ble_services\ble_gls;..\sdk\components\ble\ble_services\ble_hids;..\sdk\components\ble\ble_services\ble_hrs;..\sdk\components\ble\ble_services\ble_hrs_c;..\sdk\components\ble\ble_services\ble_hts;..\sdk\components\ble\ble_services\ble_ias;..\sdk\components\ble\ble_services\ble_ias_c;..\sdk\components\ble\ble_services\ble_lbs;..\sdk\components\ble\ble_services\ble_lbs_c;..\sdk\components\ble\ble_services\ble_lls;..\sdk\components\ble\ble_services\ble_nus;..\sdk\components\ble\ble_services\ble_nus_c;..\sdk\components\ble\ble_services\ble_rscs;..\sdk\components\ble\ble_services\ble_rscs_c;..\sdk\components\ble\ble_services\ble_tps;..\sdk\components\ble\common;..\sdk\components\ble\nrf_ble_gatt;..\sdk\components\ble\nrf_ble_qwr;..\sdk\components\ble\peer_manager;..\sdk\components\boards;..\sdk\components\libraries\atomic;..\sdk\components\libraries\atomic_fifo;..\sdk\components\libraries\atomic_flags;..\sdk\components\libraries\balloc;..\sdk\components\libraries\bootloader\ble_dfu;..\sdk\components\libraries\bsp;..\sdk\components\libraries\button;..\sdk\components\libraries\cli;..\sdk\components\libraries\crc16;..\sdk\components\libraries\crc32;..\sdk\components\libraries\crypto;..\sdk\components\libraries\csense;..\sdk\components\libraries\csense_drv;..\sdk\components\libraries\delay;..\sdk\components\libraries\ecc;..\sdk\components\libraries\experimental_section_vars;..\sdk\components\libraries\experimental_task_manager;..\sdk\components\libraries\fds;..\sdk\components\libraries\fifo;..\sdk\components\libraries\fstorage;..\sdk\components\libraries\gfx;..\sdk\components\libraries\gpiote;..\sdk\components\libraries\hardfault;..\sdk\components\libraries\hci;..\sdk\components\libraries\led_softblink;..\sdk\components\libraries\log;..\sdk\components\libraries\log\src;..\sdk\components\libraries\low_power_pwm;..\sdk\components\libraries\mem_manager;..\sdk\components\libraries\memobj;..\sdk\components\libraries\mpu;..\sdk\components\libraries\mutex;..\sdk\components\libraries\pwm;..\sdk\components\libraries\pwr_mgmt;..\sdk\components\libraries\queue;..\sdk\components\libraries\ringbuf;..\sdk\components\libraries\scheduler;..\sdk\components\libraries\sdcard;..\sdk\components\libraries\slip;..\sdk\components\libraries\sortlist;..\sdk\components\libraries\spi_mngr;..\sdk\components\libraries\stack_guard;..\sdk\components\libraries\strerror;..\sdk\components\libraries\svc;..\sdk\components\libraries\timer;..\sdk\components\libraries\twi_mngr;..\sdk\components\libraries\twi_sensor;..\sdk\components\libraries\uart;..\sdk\components\libraries\usbd;..\sdk\components\libraries\usbd\class\audio;..\sdk\components\libraries\usbd\class\cdc;..\sdk\components\libraries\usbd\class\cdc\acm;..\sdk\components\libraries\usbd\class\hid;..\sdk\components\libraries\usbd\class\hid\generic;..\sdk\components\libraries\usbd\class\hid\kbd;..\sdk\components\libraries\usbd\class\hid\mouse;..\sdk\components\libraries\usbd\class\msc;..\sdk\components\libraries\util;..\sdk\components\nfc\ndef\conn_hand_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ac_rec_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ble_oob_advdata_parser;..\sdk\components\nfc\ndef\conn_hand_parser\le_oob_rec_parser;..\sdk\components\nfc\ndef\connection_handover\ac_rec;..\sdk\components\nfc\ndef\connection_handover\ble_oob_advdata;..\sdk\components\nfc\ndef\connection_handover\ble_pair_lib;..\sdk\components\nfc\ndef\connection_handover\ble_pair_msg;..\sdk\components\nfc\ndef\connection_handover\common;..\sdk\components\nfc\ndef\connection_handover\ep_oob_rec;..\sdk\components\nfc\ndef\connection_handover\hs_rec;..\sdk\components\nfc\ndef\connection_handover\le_oob_rec;..\sdk\components\nfc\ndef\generic\message;..\sdk\components\nfc\ndef\generic\record;..\sdk\components\nfc\ndef\launchapp;..\sdk\components\nfc\ndef\parser\message;..\sdk\components\nfc\ndef\parser\record;..\sdk\components\nfc\ndef\text;..\sdk\components\nfc\ndef\uri;..\sdk\components\nfc\platform;..\sdk\components\nfc\t2t_lib;..\sdk\components\nfc\t2t_parser;..\sdk\components\nfc\t4t_lib;..\sdk\components\nfc\t4t_parser\apdu;..\sdk\components\nfc\t4t_parser\cc_file;..\sdk\components\nfc\t4t_parser\hl_detection_procedure;..\sdk\components\nfc\t4t_parser\tlv;..\sdk\components\softdevice\common;..\sdk\components\softdevice\s140\headers;..\sdk\components\softdevice\s140\headers\nrf52;..\sdk\external\fprintf;..\sdk\external\segger_rtt;..\sdk\external\utf_converter;..\sdk\integration\nrfx;..\sdk\integration\nrfx\legacy;..\sdk\modules\nrfx;..\sdk\modules\nrfx\drivers\include;..\sdk\modules\nrfx\hal;.\config\;.\src\;..\libznordic\include;..\sdk\external\fatfs\port;..\sdk\external\fatfs\src;..\sdk\components\libraries\block_dev;..\sdk\components\libraries\block_dev\sdc\;..\sdk\external\protothreads\;..\sdk\external\protothreads\pt-1.4\;..\sdk\components\libraries\scheduler;..\sdk\components\libraries\svc;..\sdk\components\libraries\bootloader\dfu;..\sdk\components\libraries\bootloader\ble_dfu;..\sdk\components\libraries\bootloader\ + ..\sdk\config;..\sdk\components;..\sdk\components\ble\ble_advertising;..\sdk\components\ble\ble_dtm;..\sdk\components\ble\ble_link_ctx_manager;..\sdk\components\ble\ble_racp;..\sdk\components\ble\ble_services\ble_ancs_c;..\sdk\components\ble\ble_services\ble_ans_c;..\sdk\components\ble\ble_services\ble_bas;..\sdk\components\ble\ble_services\ble_bas_c;..\sdk\components\ble\ble_services\ble_cscs;..\sdk\components\ble\ble_services\ble_cts_c;..\sdk\components\ble\ble_services\ble_dfu;..\sdk\components\ble\ble_services\ble_dis;..\sdk\components\ble\ble_services\ble_gls;..\sdk\components\ble\ble_services\ble_hids;..\sdk\components\ble\ble_services\ble_hrs;..\sdk\components\ble\ble_services\ble_hrs_c;..\sdk\components\ble\ble_services\ble_hts;..\sdk\components\ble\ble_services\ble_ias;..\sdk\components\ble\ble_services\ble_ias_c;..\sdk\components\ble\ble_services\ble_lbs;..\sdk\components\ble\ble_services\ble_lbs_c;..\sdk\components\ble\ble_services\ble_lls;..\sdk\components\ble\ble_services\ble_nus;..\sdk\components\ble\ble_services\ble_nus_c;..\sdk\components\ble\ble_services\ble_rscs;..\sdk\components\ble\ble_services\ble_rscs_c;..\sdk\components\ble\ble_services\ble_tps;..\sdk\components\ble\common;..\sdk\components\ble\nrf_ble_gatt;..\sdk\components\ble\nrf_ble_qwr;..\sdk\components\ble\peer_manager;..\sdk\components\boards;..\sdk\components\libraries\atomic;..\sdk\components\libraries\atomic_fifo;..\sdk\components\libraries\atomic_flags;..\sdk\components\libraries\balloc;..\sdk\components\libraries\bootloader\ble_dfu;..\sdk\components\libraries\bsp;..\sdk\components\libraries\button;..\sdk\components\libraries\cli;..\sdk\components\libraries\crc16;..\sdk\components\libraries\crc32;..\sdk\components\libraries\crypto;..\sdk\components\libraries\csense;..\sdk\components\libraries\csense_drv;..\sdk\components\libraries\delay;..\sdk\components\libraries\ecc;..\sdk\components\libraries\experimental_section_vars;..\sdk\components\libraries\experimental_task_manager;..\sdk\components\libraries\fds;..\sdk\components\libraries\fifo;..\sdk\components\libraries\fstorage;..\sdk\components\libraries\gfx;..\sdk\components\libraries\gpiote;..\sdk\components\libraries\hardfault;..\sdk\components\libraries\hci;..\sdk\components\libraries\led_softblink;..\sdk\components\libraries\log;..\sdk\components\libraries\log\src;..\sdk\components\libraries\low_power_pwm;..\sdk\components\libraries\mem_manager;..\sdk\components\libraries\memobj;..\sdk\components\libraries\mpu;..\sdk\components\libraries\mutex;..\sdk\components\libraries\pwm;..\sdk\components\libraries\pwr_mgmt;..\sdk\components\libraries\queue;..\sdk\components\libraries\ringbuf;..\sdk\components\libraries\scheduler;..\sdk\components\libraries\sdcard;..\sdk\components\libraries\slip;..\sdk\components\libraries\sortlist;..\sdk\components\libraries\spi_mngr;..\sdk\components\libraries\stack_guard;..\sdk\components\libraries\strerror;..\sdk\components\libraries\svc;..\sdk\components\libraries\timer;..\sdk\components\libraries\twi_mngr;..\sdk\components\libraries\twi_sensor;..\sdk\components\libraries\uart;..\sdk\components\libraries\usbd;..\sdk\components\libraries\usbd\class\audio;..\sdk\components\libraries\usbd\class\cdc;..\sdk\components\libraries\usbd\class\cdc\acm;..\sdk\components\libraries\usbd\class\hid;..\sdk\components\libraries\usbd\class\hid\generic;..\sdk\components\libraries\usbd\class\hid\kbd;..\sdk\components\libraries\usbd\class\hid\mouse;..\sdk\components\libraries\usbd\class\msc;..\sdk\components\libraries\util;..\sdk\components\nfc\ndef\conn_hand_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ac_rec_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ble_oob_advdata_parser;..\sdk\components\nfc\ndef\conn_hand_parser\le_oob_rec_parser;..\sdk\components\nfc\ndef\connection_handover\ac_rec;..\sdk\components\nfc\ndef\connection_handover\ble_oob_advdata;..\sdk\components\nfc\ndef\connection_handover\ble_pair_lib;..\sdk\components\nfc\ndef\connection_handover\ble_pair_msg;..\sdk\components\nfc\ndef\connection_handover\common;..\sdk\components\nfc\ndef\connection_handover\ep_oob_rec;..\sdk\components\nfc\ndef\connection_handover\hs_rec;..\sdk\components\nfc\ndef\connection_handover\le_oob_rec;..\sdk\components\nfc\ndef\generic\message;..\sdk\components\nfc\ndef\generic\record;..\sdk\components\nfc\ndef\launchapp;..\sdk\components\nfc\ndef\parser\message;..\sdk\components\nfc\ndef\parser\record;..\sdk\components\nfc\ndef\text;..\sdk\components\nfc\ndef\uri;..\sdk\components\nfc\platform;..\sdk\components\nfc\t2t_lib;..\sdk\components\nfc\t2t_parser;..\sdk\components\nfc\t4t_lib;..\sdk\components\nfc\t4t_parser\apdu;..\sdk\components\nfc\t4t_parser\cc_file;..\sdk\components\nfc\t4t_parser\hl_detection_procedure;..\sdk\components\nfc\t4t_parser\tlv;..\sdk\components\softdevice\common;..\sdk\components\softdevice\s140\headers;..\sdk\components\softdevice\s140\headers\nrf52;..\sdk\external\fprintf;..\sdk\external\segger_rtt;..\sdk\external\utf_converter;..\sdk\integration\nrfx;..\sdk\integration\nrfx\legacy;..\sdk\modules\nrfx;..\sdk\modules\nrfx\drivers\include;..\sdk\modules\nrfx\hal;.\config\;.\src\;..\libznordic\include;..\sdk\external\fatfs\port;..\sdk\external\fatfs\src;..\sdk\components\libraries\block_dev;..\sdk\components\libraries\block_dev\sdc\;..\sdk\external\protothreads\;..\sdk\external\protothreads\pt-1.4\;..\sdk\components\libraries\scheduler;..\sdk\components\libraries\svc;..\sdk\components\libraries\bootloader\dfu;..\sdk\components\libraries\bootloader\ble_dfu;..\sdk\components\libraries\bootloader\;..\ @@ -357,7 +357,7 @@ --cpreproc_opts=-DAPP_TIMER_V2,-DAPP_TIMER_V2_RTC1_ENABLED,-DBOARD_PCA10100,-DFLOAT_ABI_HARD,-DNRF52833_XXAA,-DNRF_SD_BLE_API_VERSION=7,-DS140,-DSOFTDEVICE_PRESENT,-D__HEAP_SIZE=2048,-D__STACK_SIZE=2048 APP_TIMER_V2 APP_TIMER_V2_RTC1_ENABLED BOARD_PCA10100 FLOAT_ABI_HARD NRF52833_XXAA NRF_SD_BLE_API_VERSION=7 S140 SOFTDEVICE_PRESENT __HEAP_SIZE=5120 __STACK_SIZE=5120 - ..\sdk\config;..\sdk\components;..\sdk\components\ble\ble_advertising;..\sdk\components\ble\ble_dtm;..\sdk\components\ble\ble_link_ctx_manager;..\sdk\components\ble\ble_racp;..\sdk\components\ble\ble_services\ble_ancs_c;..\sdk\components\ble\ble_services\ble_ans_c;..\sdk\components\ble\ble_services\ble_bas;..\sdk\components\ble\ble_services\ble_bas_c;..\sdk\components\ble\ble_services\ble_cscs;..\sdk\components\ble\ble_services\ble_cts_c;..\sdk\components\ble\ble_services\ble_dfu;..\sdk\components\ble\ble_services\ble_dis;..\sdk\components\ble\ble_services\ble_gls;..\sdk\components\ble\ble_services\ble_hids;..\sdk\components\ble\ble_services\ble_hrs;..\sdk\components\ble\ble_services\ble_hrs_c;..\sdk\components\ble\ble_services\ble_hts;..\sdk\components\ble\ble_services\ble_ias;..\sdk\components\ble\ble_services\ble_ias_c;..\sdk\components\ble\ble_services\ble_lbs;..\sdk\components\ble\ble_services\ble_lbs_c;..\sdk\components\ble\ble_services\ble_lls;..\sdk\components\ble\ble_services\ble_nus;..\sdk\components\ble\ble_services\ble_nus_c;..\sdk\components\ble\ble_services\ble_rscs;..\sdk\components\ble\ble_services\ble_rscs_c;..\sdk\components\ble\ble_services\ble_tps;..\sdk\components\ble\common;..\sdk\components\ble\nrf_ble_gatt;..\sdk\components\ble\nrf_ble_qwr;..\sdk\components\ble\peer_manager;..\sdk\components\boards;..\sdk\components\libraries\atomic;..\sdk\components\libraries\atomic_fifo;..\sdk\components\libraries\atomic_flags;..\sdk\components\libraries\balloc;..\sdk\components\libraries\bootloader\ble_dfu;..\sdk\components\libraries\bsp;..\sdk\components\libraries\button;..\sdk\components\libraries\cli;..\sdk\components\libraries\crc16;..\sdk\components\libraries\crc32;..\sdk\components\libraries\crypto;..\sdk\components\libraries\csense;..\sdk\components\libraries\csense_drv;..\sdk\components\libraries\delay;..\sdk\components\libraries\ecc;..\sdk\components\libraries\experimental_section_vars;..\sdk\components\libraries\experimental_task_manager;..\sdk\components\libraries\fds;..\sdk\components\libraries\fifo;..\sdk\components\libraries\fstorage;..\sdk\components\libraries\gfx;..\sdk\components\libraries\gpiote;..\sdk\components\libraries\hardfault;..\sdk\components\libraries\hci;..\sdk\components\libraries\led_softblink;..\sdk\components\libraries\log;..\sdk\components\libraries\log\src;..\sdk\components\libraries\low_power_pwm;..\sdk\components\libraries\mem_manager;..\sdk\components\libraries\memobj;..\sdk\components\libraries\mpu;..\sdk\components\libraries\mutex;..\sdk\components\libraries\pwm;..\sdk\components\libraries\pwr_mgmt;..\sdk\components\libraries\queue;..\sdk\components\libraries\ringbuf;..\sdk\components\libraries\scheduler;..\sdk\components\libraries\sdcard;..\sdk\components\libraries\slip;..\sdk\components\libraries\sortlist;..\sdk\components\libraries\spi_mngr;..\sdk\components\libraries\stack_guard;..\sdk\components\libraries\strerror;..\sdk\components\libraries\svc;..\sdk\components\libraries\timer;..\sdk\components\libraries\twi_mngr;..\sdk\components\libraries\twi_sensor;..\sdk\components\libraries\uart;..\sdk\components\libraries\usbd;..\sdk\components\libraries\usbd\class\audio;..\sdk\components\libraries\usbd\class\cdc;..\sdk\components\libraries\usbd\class\cdc\acm;..\sdk\components\libraries\usbd\class\hid;..\sdk\components\libraries\usbd\class\hid\generic;..\sdk\components\libraries\usbd\class\hid\kbd;..\sdk\components\libraries\usbd\class\hid\mouse;..\sdk\components\libraries\usbd\class\msc;..\sdk\components\libraries\util;..\sdk\components\nfc\ndef\conn_hand_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ac_rec_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ble_oob_advdata_parser;..\sdk\components\nfc\ndef\conn_hand_parser\le_oob_rec_parser;..\sdk\components\nfc\ndef\connection_handover\ac_rec;..\sdk\components\nfc\ndef\connection_handover\ble_oob_advdata;..\sdk\components\nfc\ndef\connection_handover\ble_pair_lib;..\sdk\components\nfc\ndef\connection_handover\ble_pair_msg;..\sdk\components\nfc\ndef\connection_handover\common;..\sdk\components\nfc\ndef\connection_handover\ep_oob_rec;..\sdk\components\nfc\ndef\connection_handover\hs_rec;..\sdk\components\nfc\ndef\connection_handover\le_oob_rec;..\sdk\components\nfc\ndef\generic\message;..\sdk\components\nfc\ndef\generic\record;..\sdk\components\nfc\ndef\launchapp;..\sdk\components\nfc\ndef\parser\message;..\sdk\components\nfc\ndef\parser\record;..\sdk\components\nfc\ndef\text;..\sdk\components\nfc\ndef\uri;..\sdk\components\nfc\platform;..\sdk\components\nfc\t2t_lib;..\sdk\components\nfc\t2t_parser;..\sdk\components\nfc\t4t_lib;..\sdk\components\nfc\t4t_parser\apdu;..\sdk\components\nfc\t4t_parser\cc_file;..\sdk\components\nfc\t4t_parser\hl_detection_procedure;..\sdk\components\nfc\t4t_parser\tlv;..\sdk\components\softdevice\common;..\sdk\components\softdevice\s140\headers;..\sdk\components\softdevice\s140\headers\nrf52;..\sdk\external\fprintf;..\sdk\external\segger_rtt;..\sdk\external\utf_converter;..\sdk\integration\nrfx;..\sdk\integration\nrfx\legacy;..\sdk\modules\nrfx;..\sdk\modules\nrfx\drivers\include;..\sdk\modules\nrfx\hal;.\config\ + ..\sdk\config;..\sdk\components;..\sdk\components\ble\ble_advertising;..\sdk\components\ble\ble_dtm;..\sdk\components\ble\ble_link_ctx_manager;..\sdk\components\ble\ble_racp;..\sdk\components\ble\ble_services\ble_ancs_c;..\sdk\components\ble\ble_services\ble_ans_c;..\sdk\components\ble\ble_services\ble_bas;..\sdk\components\ble\ble_services\ble_bas_c;..\sdk\components\ble\ble_services\ble_cscs;..\sdk\components\ble\ble_services\ble_cts_c;..\sdk\components\ble\ble_services\ble_dfu;..\sdk\components\ble\ble_services\ble_dis;..\sdk\components\ble\ble_services\ble_gls;..\sdk\components\ble\ble_services\ble_hids;..\sdk\components\ble\ble_services\ble_hrs;..\sdk\components\ble\ble_services\ble_hrs_c;..\sdk\components\ble\ble_services\ble_hts;..\sdk\components\ble\ble_services\ble_ias;..\sdk\components\ble\ble_services\ble_ias_c;..\sdk\components\ble\ble_services\ble_lbs;..\sdk\components\ble\ble_services\ble_lbs_c;..\sdk\components\ble\ble_services\ble_lls;..\sdk\components\ble\ble_services\ble_nus;..\sdk\components\ble\ble_services\ble_nus_c;..\sdk\components\ble\ble_services\ble_rscs;..\sdk\components\ble\ble_services\ble_rscs_c;..\sdk\components\ble\ble_services\ble_tps;..\sdk\components\ble\common;..\sdk\components\ble\nrf_ble_gatt;..\sdk\components\ble\nrf_ble_qwr;..\sdk\components\ble\peer_manager;..\sdk\components\boards;..\sdk\components\libraries\atomic;..\sdk\components\libraries\atomic_fifo;..\sdk\components\libraries\atomic_flags;..\sdk\components\libraries\balloc;..\sdk\components\libraries\bootloader\ble_dfu;..\sdk\components\libraries\bsp;..\sdk\components\libraries\button;..\sdk\components\libraries\cli;..\sdk\components\libraries\crc16;..\sdk\components\libraries\crc32;..\sdk\components\libraries\crypto;..\sdk\components\libraries\csense;..\sdk\components\libraries\csense_drv;..\sdk\components\libraries\delay;..\sdk\components\libraries\ecc;..\sdk\components\libraries\experimental_section_vars;..\sdk\components\libraries\experimental_task_manager;..\sdk\components\libraries\fds;..\sdk\components\libraries\fifo;..\sdk\components\libraries\fstorage;..\sdk\components\libraries\gfx;..\sdk\components\libraries\gpiote;..\sdk\components\libraries\hardfault;..\sdk\components\libraries\hci;..\sdk\components\libraries\led_softblink;..\sdk\components\libraries\log;..\sdk\components\libraries\log\src;..\sdk\components\libraries\low_power_pwm;..\sdk\components\libraries\mem_manager;..\sdk\components\libraries\memobj;..\sdk\components\libraries\mpu;..\sdk\components\libraries\mutex;..\sdk\components\libraries\pwm;..\sdk\components\libraries\pwr_mgmt;..\sdk\components\libraries\queue;..\sdk\components\libraries\ringbuf;..\sdk\components\libraries\scheduler;..\sdk\components\libraries\sdcard;..\sdk\components\libraries\slip;..\sdk\components\libraries\sortlist;..\sdk\components\libraries\spi_mngr;..\sdk\components\libraries\stack_guard;..\sdk\components\libraries\strerror;..\sdk\components\libraries\svc;..\sdk\components\libraries\timer;..\sdk\components\libraries\twi_mngr;..\sdk\components\libraries\twi_sensor;..\sdk\components\libraries\uart;..\sdk\components\libraries\usbd;..\sdk\components\libraries\usbd\class\audio;..\sdk\components\libraries\usbd\class\cdc;..\sdk\components\libraries\usbd\class\cdc\acm;..\sdk\components\libraries\usbd\class\hid;..\sdk\components\libraries\usbd\class\hid\generic;..\sdk\components\libraries\usbd\class\hid\kbd;..\sdk\components\libraries\usbd\class\hid\mouse;..\sdk\components\libraries\usbd\class\msc;..\sdk\components\libraries\util;..\sdk\components\nfc\ndef\conn_hand_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ac_rec_parser;..\sdk\components\nfc\ndef\conn_hand_parser\ble_oob_advdata_parser;..\sdk\components\nfc\ndef\conn_hand_parser\le_oob_rec_parser;..\sdk\components\nfc\ndef\connection_handover\ac_rec;..\sdk\components\nfc\ndef\connection_handover\ble_oob_advdata;..\sdk\components\nfc\ndef\connection_handover\ble_pair_lib;..\sdk\components\nfc\ndef\connection_handover\ble_pair_msg;..\sdk\components\nfc\ndef\connection_handover\common;..\sdk\components\nfc\ndef\connection_handover\ep_oob_rec;..\sdk\components\nfc\ndef\connection_handover\hs_rec;..\sdk\components\nfc\ndef\connection_handover\le_oob_rec;..\sdk\components\nfc\ndef\generic\message;..\sdk\components\nfc\ndef\generic\record;..\sdk\components\nfc\ndef\launchapp;..\sdk\components\nfc\ndef\parser\message;..\sdk\components\nfc\ndef\parser\record;..\sdk\components\nfc\ndef\text;..\sdk\components\nfc\ndef\uri;..\sdk\components\nfc\platform;..\sdk\components\nfc\t2t_lib;..\sdk\components\nfc\t2t_parser;..\sdk\components\nfc\t4t_lib;..\sdk\components\nfc\t4t_parser\apdu;..\sdk\components\nfc\t4t_parser\cc_file;..\sdk\components\nfc\t4t_parser\hl_detection_procedure;..\sdk\components\nfc\t4t_parser\tlv;..\sdk\components\softdevice\common;..\sdk\components\softdevice\s140\headers;..\sdk\components\softdevice\s140\headers\nrf52;..\sdk\external\fprintf;..\sdk\external\segger_rtt;..\sdk\external\utf_converter;..\sdk\integration\nrfx;..\sdk\integration\nrfx\legacy;..\sdk\modules\nrfx;..\sdk\modules\nrfx\drivers\include;..\sdk\modules\nrfx\hal;.\config\;..\..\ @@ -389,164 +389,124 @@ .\config\sdk_config.h - heart_wave_sample_service.c - 1 - .\src\heart_wave_sample_service.c - - - app_event_distribute.c - 1 - .\src\app_event_distribute.c - - - m24m02.c - 1 - .\src\basic\m24m02\m24m02.c - - - driver_ssd1306.c + one_conduction_main.c 1 - .\src\basic\ssd1306\driver_ssd1306.c + .\src\one_conduction_main.c - driver_ssd1306_basic.c + main.c 1 - .\src\basic\ssd1306\driver_ssd1306_basic.c + .\src\main.c - fontlib.c + board_beep_ctrl.c 1 - .\src\basic\ssd1306\fontlib.c + .\src\board\board_beep_ctrl.c - wave_drawer.c + board_adc_module_ctrl.c 1 - .\src\basic\ssd1306\wave_drawer.c + .\src\board\board_adc_module_ctrl.c - ble_cmd_process_service.c + board_battery_state.c 1 - .\src\ble_cmd_process_service.c + .\src\board\board_battery_state.c - device_controler.c + board_ecg_sensor.c 1 - .\src\device_controler.c + .\src\board\board_ecg_sensor.c - device_state.c + board_light_ctrl.c 1 - .\src\device_state.c + .\src\board\board_light_ctrl.c - display_manager.c + board_ssd1306_interface.c 1 - .\src\display_manager.c + .\src\board\board_ssd1306_interface.c - one_conduction_main.c + board_eeprom_driver.c 1 - .\src\one_conduction_main.c + .\src\board\board_eeprom_driver.c - sample_data_manager.c + board_power_mgr.c 1 - .\src\sample_data_manager.c + .\src\board\board_power_mgr.c - zeeprom_fs.c + device_state.c 1 - .\src\zeeprom_fs.c + .\src\basic_service\device_state.c device_version_info_mgr.c 1 - .\src\basic\device_version_info_mgr.c - - - main.c - 1 - .\src\main.c - - - board_beep_ctrl.c - 1 - .\src\board\board_beep_ctrl.c - - - board_adc_module_ctrl.c - 1 - .\src\board\board_adc_module_ctrl.c - - - board_battery_state.c - 1 - .\src\board\board_battery_state.c - - - board_ecg_sensor.c - 1 - .\src\board\board_ecg_sensor.c + .\src\basic_service\device_version_info_mgr.c - board_light_ctrl.c + driver_ssd1306.c 1 - .\src\board\board_light_ctrl.c + .\src\board\ssd1306\driver_ssd1306.c - FIR.c + driver_ssd1306_basic.c 1 - .\src\basic\FIR.c + .\src\board\ssd1306\driver_ssd1306_basic.c - HC_Chen_detect.c + fontlib.c 1 - .\src\basic\HC_Chen_detect.c + .\src\board\ssd1306\fontlib.c - So_Chen_detect.c + wave_drawer.c 1 - .\src\basic\So_Chen_detect.c + .\src\board\ssd1306\wave_drawer.c - adaptive_algorithm.c + ble_cmd_process_service.c 1 - .\src\basic\adaptive_algorithm.c + .\src\service\ble_cmd_processer\ble_cmd_process_service.c - Pan_Tompkins_detect.c + display_manager.c 1 - .\src\basic\Pan_Tompkins_detect.c + .\src\service\display_mgr\display_manager.c - qrs_time_domain_zh.c + heart_ware_sample_data_mgr.c 1 - .\src\basic\qrs_time_domain_zh.c + .\src\service\heart_wave_sample_service\heart_ware_sample_data_mgr.c - board_ssd1306_interface.c + heart_wave_sample_data_pre_process.c 1 - .\src\board\board_ssd1306_interface.c + .\src\service\heart_wave_sample_service\heart_wave_sample_data_pre_process.c - board_eeprom_driver.c + heart_wave_sample_service.c 1 - .\src\board\board_eeprom_driver.c + .\src\service\heart_wave_sample_service\heart_wave_sample_service.c - board_power_mgr.c + sample_data_manager.c 1 - .\src\board\board_power_mgr.c + .\src\service\storage\sample_data_manager.c - heart_ware_sample_data_mgr.c + zeeprom_fs.c 1 - .\src\heart_ware_sample_data_mgr.c + .\src\service\storage\zeeprom_fs.c - heart_wave_sample_data_pre_process.c + app_event_distribute.c 1 - .\src\heart_wave_sample_data_pre_process.c + .\src\basic_service\app_event_distribute.c @@ -4318,164 +4278,124 @@ .\config\sdk_config.h - heart_wave_sample_service.c - 1 - .\src\heart_wave_sample_service.c - - - app_event_distribute.c - 1 - .\src\app_event_distribute.c - - - m24m02.c - 1 - .\src\basic\m24m02\m24m02.c - - - driver_ssd1306.c + one_conduction_main.c 1 - .\src\basic\ssd1306\driver_ssd1306.c + .\src\one_conduction_main.c - driver_ssd1306_basic.c + main.c 1 - .\src\basic\ssd1306\driver_ssd1306_basic.c + .\src\main.c - fontlib.c + board_beep_ctrl.c 1 - .\src\basic\ssd1306\fontlib.c + .\src\board\board_beep_ctrl.c - wave_drawer.c + board_adc_module_ctrl.c 1 - .\src\basic\ssd1306\wave_drawer.c + .\src\board\board_adc_module_ctrl.c - ble_cmd_process_service.c + board_battery_state.c 1 - .\src\ble_cmd_process_service.c + .\src\board\board_battery_state.c - device_controler.c + board_ecg_sensor.c 1 - .\src\device_controler.c + .\src\board\board_ecg_sensor.c - device_state.c + board_light_ctrl.c 1 - .\src\device_state.c + .\src\board\board_light_ctrl.c - display_manager.c + board_ssd1306_interface.c 1 - .\src\display_manager.c + .\src\board\board_ssd1306_interface.c - one_conduction_main.c + board_eeprom_driver.c 1 - .\src\one_conduction_main.c + .\src\board\board_eeprom_driver.c - sample_data_manager.c + board_power_mgr.c 1 - .\src\sample_data_manager.c + .\src\board\board_power_mgr.c - zeeprom_fs.c + device_state.c 1 - .\src\zeeprom_fs.c + .\src\basic_service\device_state.c device_version_info_mgr.c 1 - .\src\basic\device_version_info_mgr.c - - - main.c - 1 - .\src\main.c - - - board_beep_ctrl.c - 1 - .\src\board\board_beep_ctrl.c - - - board_adc_module_ctrl.c - 1 - .\src\board\board_adc_module_ctrl.c - - - board_battery_state.c - 1 - .\src\board\board_battery_state.c - - - board_ecg_sensor.c - 1 - .\src\board\board_ecg_sensor.c + .\src\basic_service\device_version_info_mgr.c - board_light_ctrl.c + driver_ssd1306.c 1 - .\src\board\board_light_ctrl.c + .\src\board\ssd1306\driver_ssd1306.c - FIR.c + driver_ssd1306_basic.c 1 - .\src\basic\FIR.c + .\src\board\ssd1306\driver_ssd1306_basic.c - HC_Chen_detect.c + fontlib.c 1 - .\src\basic\HC_Chen_detect.c + .\src\board\ssd1306\fontlib.c - So_Chen_detect.c + wave_drawer.c 1 - .\src\basic\So_Chen_detect.c + .\src\board\ssd1306\wave_drawer.c - adaptive_algorithm.c + ble_cmd_process_service.c 1 - .\src\basic\adaptive_algorithm.c + .\src\service\ble_cmd_processer\ble_cmd_process_service.c - Pan_Tompkins_detect.c + display_manager.c 1 - .\src\basic\Pan_Tompkins_detect.c + .\src\service\display_mgr\display_manager.c - qrs_time_domain_zh.c + heart_ware_sample_data_mgr.c 1 - .\src\basic\qrs_time_domain_zh.c + .\src\service\heart_wave_sample_service\heart_ware_sample_data_mgr.c - board_ssd1306_interface.c + heart_wave_sample_data_pre_process.c 1 - .\src\board\board_ssd1306_interface.c + .\src\service\heart_wave_sample_service\heart_wave_sample_data_pre_process.c - board_eeprom_driver.c + heart_wave_sample_service.c 1 - .\src\board\board_eeprom_driver.c + .\src\service\heart_wave_sample_service\heart_wave_sample_service.c - board_power_mgr.c + sample_data_manager.c 1 - .\src\board\board_power_mgr.c + .\src\service\storage\sample_data_manager.c - heart_ware_sample_data_mgr.c + zeeprom_fs.c 1 - .\src\heart_ware_sample_data_mgr.c + .\src\service\storage\zeeprom_fs.c - heart_wave_sample_data_pre_process.c + app_event_distribute.c 1 - .\src\heart_wave_sample_data_pre_process.c + .\src\basic_service\app_event_distribute.c diff --git a/app/config/sdk_config.h b/app/config/sdk_config.h index 25cdb27..2651555 100644 --- a/app/config/sdk_config.h +++ b/app/config/sdk_config.h @@ -7719,7 +7719,7 @@ #ifndef NRF_FPRINTF_DOUBLE_ENABLED -#define NRF_FPRINTF_DOUBLE_ENABLED 0 +#define NRF_FPRINTF_DOUBLE_ENABLED 1 #endif // diff --git a/app/src/app_event.h b/app/src/app_event.h deleted file mode 100644 index cc128f6..0000000 --- a/app/src/app_event.h +++ /dev/null @@ -1 +0,0 @@ -#include "device_state.h" \ No newline at end of file diff --git a/app/src/app_event_distribute.c b/app/src/app_event_distribute.c deleted file mode 100644 index 07a00a6..0000000 --- a/app/src/app_event_distribute.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "app_event_distribute.h" - -#include "app_event.h" -#include "app_scheduler.h" - -static AppEventListener m_listener[10]; -static int m_listener_num = 0; - -static void app_event_process_cb(void* p_event_data, uint16_t event_size) { - for (int i = 0; i < m_listener_num; i++) { - if (m_listener[i].cbfunc) { - m_listener[i].cbfunc(p_event_data, event_size); - } - } -} - -void AppEvent_regListener(app_event_listener_t listener) { // - m_listener[m_listener_num++].cbfunc = listener; -} - -void AppEvent_pushEvent(app_event_t* event) { // - app_sched_event_put(event, sizeof(app_event_t), app_event_process_cb); -} diff --git a/app/src/app_event_distribute.h b/app/src/app_event_distribute.h deleted file mode 100644 index 7f22132..0000000 --- a/app/src/app_event_distribute.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include -#include - -#include "app_event.h" - - -typedef void (*app_event_listener_t)(void* p_event_data, uint16_t event_size); - -typedef struct { - app_event_listener_t cbfunc; -} AppEventListener; - -void AppEvent_regListener(app_event_listener_t listener); -void AppEvent_pushEvent(app_event_t* event); diff --git a/app/src/aproject_config/config.h b/app/src/aproject_config/config.h new file mode 100644 index 0000000..9acfc73 --- /dev/null +++ b/app/src/aproject_config/config.h @@ -0,0 +1,65 @@ +#pragma once + +/*********************************************************************************************************************** + * É豸ÐÅÏ¢ÅäÖà * + ***********************************************************************************************************************/ + +#define CATEGORY "M1001" // µ¥µ¼Áª +#define MANUFACTURER_NAME "iflytop" + +#define FIRMWARE_VERSION (10) +#define BLESTACK_VERSION 1 +#define BOOTLOADER_VERSION 1 +#define HARDWARE_VERSION (1) + +#define APP_COMPANY_IDENTIFIER 0xFFFF + +/******************************************************************************* + * BEEP * + *******************************************************************************/ +#define BEEP_PIN 1 +#define BEEP_PWM_INSTANCE 0 + +/******************************************************************************* + * ADC * + *******************************************************************************/ + +#define ECG_NLOD_PIN 3 +#define ECG_PLOD_PIN 28 +#define ECG_ADC_PIN NRF_SAADC_INPUT_AIN0 +#define ECG_ADC_CHANNEL 0 // ²»Öظ´¼´¿É + +#define BATTERY_ADC_PIN NRF_SAADC_INPUT_AIN3 +#define BATTERY_ADC_CHANNEL 1 // ²»Öظ´¼´¿É +#define BATTERY_CHARGE_DETECT_PIN 6 + +/** + * @brief + */ + +#define MAX_STORAGE_TIMEOUT_S (60 * 10) // ×´æ´¢Ê±¼ä +#define MAX_STORAGE_SIZE (MAX_STORAGE_TIMEOUT_S * 400) // ´æ´¢×î´óÏÞÖÆÎª (256-8)kbyte +#define MAX_FILE_NUM 10 // ×î¶à´æ´¢ÌõÄ¿Êý +#define SAMPLE_RATE 500 // ²ÉÑùÂÊ +#define SAMPLE_PRECISION 12 // ²ÉÑù¾«¶È +#define AUTOMATIC_SLEEP_TIME 30000 // ¿ª»úºó×Ô¶¯ÐÝÃßʱ¼ä +#define SAMPLE_MIN_TIME_S (30.0) // ²ÉÑù×îСʱ¼ä +#define LITTLE_DATA_BLOCK_FRAME_NUM 5 // ÿ´Î¶àÉÙÖ¡Éϱ¨Ò»´Î + +#define KEEP_STILL_OVERTIME_MS_1P5 1500 // ±£³Ö¾²Ö¹³¬Ê±Ê±¼äµÄ1/6 + +#define LED_GREEN_PIN 9 +#define LED_BLUE_PIN 10 +#define LED_RED_PIN 39 + +#define HEART_WAVE_SAMPLE_TMR_INSTANCE 3 + +#define LIGHT_PWM_INSTANCE 1 + +// #define APP_BATTERY_PROTECT_LEVEL 2 // µÍÓڴ˵çÁ¿²»ÄÜ¿ª»ú£¬±£»¤µç³Ø +// #define APP_AUTO_STANDY_BATTERY_LEVEL 5 // µÍÓڴ˵çÁ¿×Ô¶¯´ý»ú,±£³ÖʱÖÓ +// #define APP_WORK_BATTERY_LEVEL 10 // Main³õʼ»¯Ê±ºòºÍ´ÓstandyÇл»µ½workµÄʱºò£¬¼ì²éÕâ¸öµçÁ¿ +#define APP_LOW_BATTERY_WARNING_LIMIT 20 // + +#define LOW_BATTERY_REMINDER_DELAY_MS 3000 +#define BLE_UNCONNECTED_OVERTIME_S 300 \ No newline at end of file diff --git a/app/src/basic/FIR.c b/app/src/basic/FIR.c deleted file mode 100644 index dfcad40..0000000 --- a/app/src/basic/FIR.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "FIR.h" -/*360hz 0.51Hz~8.9Hz 20190925*/ -#define taps 32 -static const float coefficients[taps] = {0.012177,0.01599,0.019905,0.02387,0.027827,0.031719,0.035487,0.039075,0.042426,0.045488,0.048212,0.050553,0.052475,0.053944,0.054937,0.055438,0.055438,0.054937,0.053944,0.052475,0.050553,0.048212,0.045488,0.042426,0.039075,0.035487,0.031719,0.027827,0.02387,0.019905,0.01599,0.012177}; - -static float buffer[taps]; -unsigned offset; - -float FIR_filter(float input) { - const float *coeff = coefficients; - const float *coeff_end = coefficients + taps; - - float *buf_val = buffer + offset; - - *buf_val = input; - float output_ = 0; - - while (buf_val >= buffer) { - output_ += *buf_val-- * *coeff++; - } - - buf_val = buffer + taps - 1; - - while (coeff < coeff_end) { - output_ += *buf_val-- * *coeff++; - } - - if (++offset >= taps) { - offset = 0; - } - - return output_; -} - -void FIR_reset_buffer() { - memset(buffer, 0, sizeof(float) * taps); - offset = 0; -} diff --git a/app/src/basic/FIR.h b/app/src/basic/FIR.h deleted file mode 100644 index f9545c5..0000000 --- a/app/src/basic/FIR.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __FIR_H__ -#define __FIR_H__ - -#include -#include -#include -#include -#include - - -extern float FIR_filter(float); -extern void FIR_reset_buffer(); - -#endif diff --git a/app/src/basic/HC_Chen_detect.c b/app/src/basic/HC_Chen_detect.c deleted file mode 100644 index 5bfcd67..0000000 --- a/app/src/basic/HC_Chen_detect.c +++ /dev/null @@ -1,128 +0,0 @@ -#include "HC_Chen_detect.h" - -bool HC_Chen_detect(float signal) -{ - ecg_buff[ecg_buff_WR_idx++] = signal; - sample = ecg_buff_WR_idx; - ecg_buff_WR_idx %= (M+1); - - /* High pass filtering */ - if(number_iter < M){ - // first fill buffer with enough points for HP filter - hp_sum += ecg_buff[ecg_buff_RD_idx]; - hp_buff[hp_buff_WR_idx] = 0; - } - else{ - hp_sum += ecg_buff[ecg_buff_RD_idx]; - - int tmp = ecg_buff_RD_idx - M; - if(tmp < 0){ - tmp += M + 1; - } - - hp_sum -= ecg_buff[tmp]; - - float y1 = 0; - float y2 = 0; - - tmp = (ecg_buff_RD_idx - ((M+1)/2)); - if(tmp < 0){ - tmp += M + 1; - } - - y2 = ecg_buff[tmp]; - - y1 = HP_CONSTANT * hp_sum; - - hp_buff[hp_buff_WR_idx] = y2 - y1; - - } - - // done reading ECG buffer, increment position - ecg_buff_RD_idx++; - ecg_buff_RD_idx %= (M+1); - - // done writing to HP buffer, increment position - hp_buff_WR_idx++; - hp_buff_WR_idx %= (N+1); - - /* Low pass filtering */ - - // shift in new sample from high pass filter - lp_sum += hp_buff[hp_buff_RD_idx] * hp_buff[hp_buff_RD_idx]; - - if(number_iter < N){ - // first fill buffer with enough points for LP filter - next_eval_pt = 0; - } - else{ - // shift out oldest data point - int tmp = hp_buff_RD_idx - N; - if(tmp < 0){ - tmp += N+1; - } - - lp_sum -= hp_buff[tmp] * hp_buff[tmp]; - - next_eval_pt = lp_sum; - } - - // done reading HP buffer, increment position - hp_buff_RD_idx++; - hp_buff_RD_idx %= (N+1); - - /* Adapative thresholding beat detection */ - // set initial threshold - if(number_iter < window_size) { - if(next_eval_pt > treshold) { - treshold = next_eval_pt; - } - ++number_iter; - } - - // check if detection hold off period has passed - if(triggered){ - trig_time++; - - if(trig_time >= DELAY_TIME){ - triggered = false; - trig_time = 0; - } - } - - // find if we have a new max - if(next_eval_pt > win_max) win_max = next_eval_pt; - - // find if we are above adaptive threshold - if(next_eval_pt > treshold && !triggered) { - //result.push_back(true); - - last_qrs_point = sample; - - triggered = true; - return true; - } - else { - //result.push_back(false); - } - - // adjust adaptive threshold using max of signal found - // in previous window - if(win_idx++ >= window_size){ - // weighting factor for determining the contribution of - // the current peak value to the threshold adjustment - float gamma = (0.2f+0.15f)/2.0f; // 0.15~0.2 - - // forgetting factor - - // rate at which we forget old observations - float alpha = 0.01f + ( ((float) rand() / (float) RAND_MAX) * ((0.1f - 0.01f))); // 0~1 - //float alpha = 1.0f*exp(-0.00005f*(sample - last_qrs_point)); - - treshold = alpha * gamma * win_max + (1.0f - alpha) * treshold; - - // reset current window ind - win_idx = 0; - win_max = -10000000; - } - return false; -} diff --git a/app/src/basic/HC_Chen_detect.h b/app/src/basic/HC_Chen_detect.h deleted file mode 100644 index cb9fa51..0000000 --- a/app/src/basic/HC_Chen_detect.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __HC_CHEN__ -#define __HC_CHEN__ - -#include -#include -#include -#include -#include - - -#include "QRS.h" - - -#define M 9 -#define N 54//SAMPLING_RATE * 0.15f -static const uint32_t window_size = SAMPLING_RATE; -static const float HP_CONSTANT = ((float) 1.0f / (float) M); -// circular buffer for input ecg signal -// we need to keep a history of M + 1 samples for HP filter -static float ecg_buff[M + 1] = {0}; -static int ecg_buff_WR_idx = 0; -static int ecg_buff_RD_idx = 0; - -// circular buffer for input ecg signal -// we need to keep a history of N+1 samples for LP filter -static float hp_buff[N + 1] = {0}; -static int hp_buff_WR_idx = 0; -static int hp_buff_RD_idx = 0; - -// LP filter outputs a single point for every input point -// This goes straight to adaptive filtering for eval -static float next_eval_pt = 0; - -// running sums for HP and LP filters, values shifted in FILO -static float hp_sum = 0; -static float lp_sum = 0; - -// parameters for adaptive thresholding -static float treshold = 0; -static bool triggered = false; -static int trig_time = 0; -static float win_max = 0; -static int win_idx = 0; -static int number_iter = 0; - -static int sample = 0; -static int last_qrs_point = 0; - -static const int DELAY_TIME = 180;//window_size * 0.5f; - -extern bool HC_Chen_detect(float); - -#endif diff --git a/app/src/basic/Pan_Tompkins_detect.c b/app/src/basic/Pan_Tompkins_detect.c deleted file mode 100644 index 6caea37..0000000 --- a/app/src/basic/Pan_Tompkins_detect.c +++ /dev/null @@ -1,373 +0,0 @@ -#include "Pan_Tompkins_detect.h" - -/* y(nT) = 1.875y(nT – T) – 0.9219y(nT – 2T) + x (nT) – x(nT – 2T) */ -int TwoPoleRecursive(int data) -{ - static int xnt, xm1, xm2, ynt, ym1, ym2 = 0; - - xnt = data; - ynt = (ym1 + (ym1 >> 1) + (ym1 >> 2) + (ym1 >> 3)) + // 1.875 = 1 + 1/2 + 1/4 + 1/8 - (((ym2 >> 1) + (ym2 >> 2) + (ym2 >> 3) + (ym2 >> 5) + (ym2 >> 6)) + xnt - xm2); // 0.916 = 1 + 1/2 + 1/4 + 1/8 + 1/32 + 1/64 - xm2 = xm1; - xm1 = xnt; - xm2 = ym1; - ym2 = ym1; - ym1 = ynt; - return ynt; -} - -/* y(nT) = 2y(nT – T) – y(nT – 2T) + x(nT) – 2x(nT – 6T) + x(nT – 12T) */ -int LowPassFilter(int data) -{ - static int y1 = 0, y2 = 0, x[26], n = 12; - int y0; - - x[n] = x[n + 13] = data; - y0 = (y1 << 1) - y2 + x[n] - (x[n + 6] << 1) + x[n + 12]; - y2 = y1; - y1 = y0; - y0 >>= 5; - if(--n < 0){ - n = 12; - } - return y0; -} - -/* p(nT) = x(nT – 16T) – 32 [y(nT – T) + x(nT) – x(nT – 32T)] */ -int HighPassFilter(int data) -{ - static int y1 = 0, x[66], n = 32; - int y0; - - x[n] = x[n + 33] = data; - y0 = y1 + x[n] - x[n + 32]; - y1 = y0; - if(--n < 0){ - n = 32; - } - return (x[n + 16] - (y0 >> 5)); -} - -/* y = 1/8 (2x( nT) + x( nT - T) - x( nT - 3T) - 2x( nT - 4T)) */ -int Derivative(int data) -{ - int y; - static int x_derv[4]; - - y = (data << 1) + x_derv[3] - x_derv[1] - ( x_derv[0] << 1); - y >>= 3; - for(int i = 0; i < 3; ++i){ - x_derv[i] = x_derv[i + 1]; - } - x_derv[3] = data; - return y; -} - -int Squar(int data) -{ - return (data * data); -} - -/* y(nT) = 1/N [x(nT – (N – 1)T) + x(nT – (N – 2)T) +...+ x(nT)] */ -int MovingWindowIntegral(int data) -{ - //static const int WINDOW_SIZE = SAMPLING_RATE * 0.2; - #define WINDOW_SIZE 72 - - static int x[WINDOW_SIZE], ptr = 0; - static long sum = 0; - long ly; - int y; - - if(++ptr == WINDOW_SIZE){ - ptr = 0; - } - sum -= x[ptr]; - sum += data; - x[ptr] = data; - ly = sum >> 5; - uint32_t MAX_INTEGRAL = 4096;//32400; - if(ly > MAX_INTEGRAL){ - y = MAX_INTEGRAL; - } - else{ - y = (int)ly; - } - return (y); -} - -SignalPoint ThresholdCalculate(int sample,float value,int bandpass,int square,int integral) -{ - //static const int QRS_TIME = SAMPLING_RATE * 0.1; - //static const int SEARCH_BACK_TIME = SAMPLING_RATE * 1.66f; - #define QRS_TIME 36 - #define SEARCH_BACK_TIME 598 - - static int bandpass_buffer[SEARCH_BACK_TIME],integral_buffer[SEARCH_BACK_TIME]; - static SignalPoint peak_buffer[SEARCH_BACK_TIME]; - static int square_buffer[QRS_TIME]; - static long unsigned last_qrs = 0, last_slope = 0, current_slope = 0; - static int peak_i = 0, peak_f = 0, threshold_i1 = 0, threshold_i2 = 0, threshold_f1 = 0, threshold_f2 = 0, spk_i = 0, spk_f = 0, npk_i = 0, npk_f = 0; - static bool qrs, regular = true, prev_regular; - static int rr1[8]={0}, rr2[8]={0}, rravg1, rravg2, rrlow = 0, rrhigh = 0, rrmiss = 0; - - SignalPoint result; - result.index = -1; - - peak_buffer[sample%SEARCH_BACK_TIME].index = sample; - peak_buffer[sample%SEARCH_BACK_TIME].value = value; - bandpass_buffer[sample%SEARCH_BACK_TIME] = bandpass; - integral_buffer[sample%SEARCH_BACK_TIME] = integral; - square_buffer[sample%QRS_TIME] = square; - - // If the current signal is above one of the thresholds (integral or filtered signal), it's a peak candidate. - if(integral >= threshold_i1 || bandpass >= threshold_f1){ - peak_i = integral; - peak_f = bandpass; - } - - // If both the integral and the signal are above their thresholds, they're probably signal peaks. - if((integral >= threshold_i1) && (bandpass >= threshold_f1)){ - // There's a 200ms latency. If the new peak respects this condition, we can keep testing. - if(sample > last_qrs + SAMPLING_RATE*0.2f){ - //if(sample > last_qrs + (SAMPLING_RATE*0.2f)){ - // If it respects the 200ms latency, but it doesn't respect the 360ms latency, we check the slope. - if(sample <= last_qrs + (long unsigned int)(0.36*SAMPLING_RATE)){ - // The squared slope is "M" shaped. So we have to check nearby samples to make sure we're really looking - // at its peak value, rather than a low one. - int current = sample; - current_slope = 0; - for(int j = current - QRS_TIME; j <= current; ++j){ - if(square_buffer[j%QRS_TIME] > current_slope){ - current_slope = square_buffer[j%QRS_TIME]; - } - } - //current_slope = square; - - if(current_slope <= (int)(last_slope/2)){ - qrs = false; - //return qrs; - } - - else{ - spk_i = 0.125*peak_i + 0.875*spk_i; - threshold_i1 = npk_i + 0.25*(spk_i - npk_i); - threshold_i2 = 0.5*threshold_i1; - - spk_f = 0.125*peak_f + 0.875*spk_f; - threshold_f1 = npk_f + 0.25*(spk_f - npk_f); - threshold_f2 = 0.5*threshold_f1; - - last_slope = current_slope; - qrs = true; - - result.value = value; - result.index = sample; - } - } - // If it was above both thresholds and respects both latency periods, it certainly is a R peak. - else{ - int current = sample; - current_slope = 0; - for(int j = current - QRS_TIME; j <= current; ++j){ - if(square_buffer[j%QRS_TIME] > current_slope){ - current_slope = square_buffer[j%QRS_TIME]; - } - } - //current_slope = square; - - spk_i = 0.125*peak_i + 0.875*spk_i; - threshold_i1 = npk_i + 0.25*(spk_i - npk_i); - threshold_i2 = 0.5*threshold_i1; - - spk_f = 0.125*peak_f + 0.875*spk_f; - threshold_f1 = npk_f + 0.25*(spk_f - npk_f); - threshold_f2 = 0.5*threshold_f1; - - last_slope = current_slope; - qrs = true; - - result.value = value; - result.index = sample; - } - } - // If the new peak doesn't respect the 200ms latency, it's noise. Update thresholds and move on to the next sample. - else{ - peak_i = integral; - npk_i = 0.125*peak_i + 0.875*npk_i; - threshold_i1 = npk_i + 0.25*(spk_i - npk_i); - threshold_i2 = 0.5*threshold_i1; - peak_f = bandpass; - npk_f = 0.125*peak_f + 0.875*npk_f; - threshold_f1 = npk_f + 0.25*(spk_f - npk_f); - threshold_f2 = 0.5*threshold_f1; - qrs = false; - /*outputSignal[current] = qrs; - if (sample > DELAY + BUFFSIZE) - output(outputSignal[0]); - continue;*/ - - //return qrs; - return result; - } - } - - // If a QRS complex was detected, the RR-averages must be updated. - if(qrs){ - // Add the newest RR-interval to the buffer and get the new average. - rravg1 = 0; - for (int i = 0; i < 7; ++i){ - rr1[i] = rr1[i+1]; - rravg1 += rr1[i]; - } - rr1[7] = sample - last_qrs; - last_qrs = sample; - rravg1 += rr1[7]; - rravg1 *= 0.125; - - // If the newly-discovered RR-average is normal, add it to the "normal" buffer and get the new "normal" average. - // Update the "normal" beat parameters. - if ( (rr1[7] >= rrlow) && (rr1[7] <= rrhigh) ){ - rravg2 = 0; - for (int i = 0; i < 7; ++i){ - rr2[i] = rr2[i+1]; - rravg2 += rr2[i]; - } - rr2[7] = rr1[7]; - rravg2 += rr2[7]; - rravg2 *= 0.125; - rrlow = 0.92*rravg2; - rrhigh = 1.16*rravg2; - rrmiss = 1.66*rravg2; - } - - prev_regular = regular; - if(rravg1 == rravg2){ - regular = true; - } - // If the beat had been normal but turned odd, change the thresholds. - else{ - regular = false; - if (prev_regular){ - threshold_i1 /= 2; - threshold_f1 /= 2; - } - } - } - // If no R-peak was detected, it's important to check how long it's been since the last detection. - else{ - int current = sample; - // If no R-peak was detected for too long, use the lighter thresholds and do a back search. - // However, the back search must respect the 200ms limit and the 360ms one (check the slope). - if((sample - last_qrs > (long unsigned int)rrmiss) && (sample > last_qrs + SAMPLING_RATE*0.2f)){ - //if((sample - last_qrs > (long unsigned int)rrmiss) && (sample > last_qrs + (SAMPLING_RATE*0.2f))){ - - // If over SEARCH_BACK_TIME of QRS complex - if((sample - last_qrs) > SEARCH_BACK_TIME){ - last_qrs = sample; - //return result; - } - - int qrs_last_index = 0; // Last point of QRS complex - - for(int i = current - (sample - last_qrs) + SAMPLING_RATE*0.2f; i < (long unsigned int)current; ++i){ - //for(int i = current - (sample - last_qrs) + (SAMPLING_RATE*0.2f); i < (long unsigned int)current; ++i){ - if((integral_buffer[i%SEARCH_BACK_TIME] > threshold_i2) && (bandpass_buffer[i%SEARCH_BACK_TIME] > threshold_f2)){ - current_slope = 0; - for(int j = current - QRS_TIME; j <= current; ++j){ - if(square_buffer[j%QRS_TIME] > current_slope){ - current_slope = square_buffer[j%QRS_TIME]; - } - } - //current_slope = square; - - if((current_slope < (int)(last_slope/2)) && (i + sample) < last_qrs + 0.36*last_qrs){ - qrs = false; - } - else if(i - last_qrs > 550){ - peak_i = integral_buffer[i%SEARCH_BACK_TIME]; - peak_f = bandpass_buffer[i%SEARCH_BACK_TIME]; - spk_i = 0.25*peak_i+ 0.75*spk_i; - spk_f = 0.25*peak_f + 0.75*spk_f; - threshold_i1 = npk_i + 0.25*(spk_i - npk_i); - threshold_i2 = 0.5*threshold_i1; - last_slope = current_slope; - threshold_f1 = npk_f + 0.25*(spk_f - npk_f); - threshold_f2 = 0.5*threshold_f1; - // If a signal peak was detected on the back search, the RR attributes must be updated. - // This is the same thing done when a peak is detected on the first try. - //RR Average 1 - rravg1 = 0; - for(int j = 0; j < 7; ++j){ - rr1[j] = rr1[j+1]; - rravg1 += rr1[j]; - } - rr1[7] = sample - (current - i) - last_qrs; - qrs = true; - qrs_last_index = i; - last_qrs = sample - (current - i); - rravg1 += rr1[7]; - rravg1 *= 0.125; - - //RR Average 2 - if((rr1[7] >= rrlow) && (rr1[7] <= rrhigh)){ - rravg2 = 0; - for (int i = 0; i < 7; ++i){ - rr2[i] = rr2[i+1]; - rravg2 += rr2[i]; - } - rr2[7] = rr1[7]; - rravg2 += rr2[7]; - rravg2 *= 0.125; - rrlow = 0.92*rravg2; - rrhigh = 1.16*rravg2; - rrmiss = 1.66*rravg2; - } - - prev_regular = regular; - if(rravg1 == rravg2){ - regular = true; - } - else{ - regular = false; - if(prev_regular){ - threshold_i1 /= 2; - threshold_f1 /= 2; - } - } - - break; - } - } - } - - if(qrs){ - //outputSignal[current] = false; - //outputSignal[i] = true; - //if (sample > DELAY + BUFFSIZE) - //output(outputSignal[0]); - //continue; - - //return qrs; - return peak_buffer[qrs_last_index%SEARCH_BACK_TIME]; - } - } - - // Definitely no signal peak was detected. - if(!qrs){ - // If some kind of peak had been detected, then it's certainly a noise peak. Thresholds must be updated accordinly. - if((integral >= threshold_i1) || (bandpass >= threshold_f1)){ - peak_i = integral; - npk_i = 0.125*peak_i + 0.875*npk_i; - threshold_i1 = npk_i + 0.25*(spk_i - npk_i); - threshold_i2 = 0.5*threshold_i1; - peak_f = bandpass; - npk_f = 0.125*peak_f + 0.875*npk_f; - threshold_f1 = npk_f + 0.25*(spk_f - npk_f); - threshold_f2 = 0.5*threshold_f1; - } - } - } - - return result; - } diff --git a/app/src/basic/Pan_Tompkins_detect.h b/app/src/basic/Pan_Tompkins_detect.h deleted file mode 100644 index cbd65d0..0000000 --- a/app/src/basic/Pan_Tompkins_detect.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __PAN_TOMPKINS__ -#define __PAN_TOMPKINS__ - -#include -#include -#include -#include -#include - -#include "QRS.h" -extern int TwoPoleRecursive(int); - -extern int LowPassFilter(int); -extern int HighPassFilter(int); - -extern int Derivative(int); -extern int Squar(int); -extern int MovingWindowIntegral(int); - -extern SignalPoint ThresholdCalculate(int,float,int,int,int); -#endif diff --git a/app/src/basic/QRS.h b/app/src/basic/QRS.h deleted file mode 100644 index 33aba1b..0000000 --- a/app/src/basic/QRS.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include -//const uint32_t SAMPLING_RATE = 1000; -#define SAMPLING_RATE 360 - -typedef struct -{ - float value; - int32_t index; -}SignalPoint; - -enum -{ - NOTQRS, /* not-QRS (not a getann/putann code) */ - NORMAL, /* normal beat */ - LBBB, /* left bundle branch block beat */ - RBBB, /* right bundle branch block beat */ - ABERR, /* aberrated atrial premature beat */ - PVC, /* premature ventricular contraction */ - FUSION, /* fusion of ventricular and normal beat */ - NPC, /* nodal (junctional) premature beat */ - APC, /* atrial premature contraction */ - SVPB, /* premature or ectopic supraventricular beat */ - VESC, /* ventricular escape beat */ - NESC, /* nodal (junctional) escape beat */ - PACE, /* paced beat */ - UNKNOWN, /* unclassifiable beat */ - NOISE, /* signal quality change */ - ARFCT /* isolated QRS-like artifact */ -}; diff --git a/app/src/basic/So_Chen_detect.c b/app/src/basic/So_Chen_detect.c deleted file mode 100644 index e329825..0000000 --- a/app/src/basic/So_Chen_detect.c +++ /dev/null @@ -1,93 +0,0 @@ -#include "So_Chen_detect.h" - -SignalPoint So_Chen_detect(SignalPoint signal,int initial_point,float threshold_parameter,float filter_parameter) -{ - /* init slop window pool, size = 5 */ - if(signal_window_count < signal_window_size){ - signal_window[signal_window_count%signal_window_size] = signal; - ++signal_window_count; - SignalPoint value; - value.index = -1; - return value; - } - else{ - signal_window[signal_window_count%signal_window_size] = signal; - ++signal_window_count; - SignalPoint value; - } - - /* calculate slop */ - uint32_t idx_for_slop = signal_window_count-2; - slop.value = ( (-2.0f * signal_window[(idx_for_slop-2)%signal_window_size].value) - signal_window[(idx_for_slop-1)%signal_window_size].value + signal_window[(idx_for_slop+1)%signal_window_size].value + (2.0f * signal_window[(idx_for_slop+2)%signal_window_size].value) ); - slop.index = signal_window[idx_for_slop%signal_window_size].index; - - /* init maxi */ - if(!so_chen_init_flag){ - if(!maxi_init){ - max.value = 0; - max.index = -1; - maxi = slop.value; - maxi_init = true; - } - ++init_count; - if(init_count > initial_point){ - so_chen_init_flag = true; - /* calculate slop threshold */ - slop_threshold = threshold_parameter / 16.0f * maxi; - } - if(slop.value > maxi){ - maxi = slop.value; - } - SignalPoint value; - value.index = -1; - return value; - } - - /* detect QRS complex on set */ - if(qrs_on_set_flag && (signal_window_count - last_point > enhanced_point)){ - if(!max_init){ - max = signal_window[(idx_for_slop)%signal_window_size]; - max_init = true; - } - if(signal_window[(idx_for_slop)%signal_window_size].value > max.value){ - max = signal_window[(idx_for_slop)%signal_window_size]; - max_slop = slop; - } - else if(signal_window[(idx_for_slop)%signal_window_size].value < max.value){ - last_point = signal_window_count; - qrs_on_set_flag = false; - max_init = false; - maxi = ((abs(max.value - qrs_onset_point.value) - maxi) / filter_parameter) + maxi; - slop_threshold = threshold_parameter / 16.0f * maxi; - last_maxi = maxi; - return max; - } - } - else{ - if(slop.value > slop_threshold){ - ++qrs_on_set_count; - } - else if(qrs_on_set_count){ - qrs_on_set_count = 0; - } - - if(qrs_on_set_count >= 2){ // is QRS complex on set - qrs_on_set_flag = true; - qrs_on_set_count = 0; - qrs_onset_idx = idx_for_slop; - qrs_onset_point = signal; - } - else if((signal_window_count - last_point > enhanced_point * 2) && (slop_threshold > 0)){ //decay threshold - - slop_threshold -= slop.value; - - if((signal_window_count - last_point > SAMPLING_RATE * 3)){ //threshold oscillating - slop_threshold -= ((signal_window_count - last_point) >> (int)threshold_parameter); - } - } - } - - SignalPoint value; - value.index = -1; - return value; -} diff --git a/app/src/basic/So_Chen_detect.h b/app/src/basic/So_Chen_detect.h deleted file mode 100644 index a505775..0000000 --- a/app/src/basic/So_Chen_detect.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __SO_AND_CHEN__ -#define __SO_AND_CHEN__ - -#include -#include -#include -#include -#include - -#include "QRS.h" -static const uint32_t enhanced_point = SAMPLING_RATE * 0.35f; - -#define signal_window_size 5 -static SignalPoint signal_window[signal_window_size]; -static uint32_t signal_window_count = 0; - -static SignalPoint slop; - -static bool so_chen_init_flag = false; -static uint32_t init_count = 0; - -static bool maxi_init = false; -static float maxi; - -static float slop_threshold = 0; - -static SignalPoint qrs_onset_point; - -static int qrs_on_set_count = 0; -static int qrs_onset_idx = 0; -static bool qrs_on_set_flag = false; - -static SignalPoint max; -static SignalPoint max_slop; -static bool max_init = false; - -static float last_maxi = 0; -static uint32_t last_point = 0; - -SignalPoint So_Chen_detect(SignalPoint,int,float,float); - -#endif diff --git a/app/src/basic/adaptive_algorithm.c b/app/src/basic/adaptive_algorithm.c deleted file mode 100644 index 11a4e60..0000000 --- a/app/src/basic/adaptive_algorithm.c +++ /dev/null @@ -1,100 +0,0 @@ -#include "adaptive_algorithm.h" - -float CalculateMean(float value) -{ - value /= 1000.0f; - if(mean_count < MEAN_SIZE){ - mean_sum += value; - ++mean_count; - } - else{ - mean = mean_sum/MEAN_SIZE; - mean_count = 0; - mean_sum = 0; - - } - return (mean * 1000.0f); -} - -float CalculateRootMeanSquare(float value) -{ - value /= 1000.0f; - if(rms_count < RMS_SIZE){ - rms_sum += value * value; - ++rms_count; - } - else{ - rms = sqrt(rms_sum/RMS_SIZE); - rms_count = 0; - rms_sum = 0; - - } - return (rms * 1000.0f); -} - -float CalculateCoefficientOfVariation(float value) -{ - value /= 1000.0f; - if(cv_count < CV_SIZE){ - sd += (value - mean) * (value - mean); - ++cv_count; - } - else{ - sd = sqrt(sd / (CV_SIZE-1)); - cv = (sd / mean) * 100; - cv_count = 0; - sd = 0; - - } - return cv; -} - -void InitPeakDetect(float value,bool emi_first) -{ - if(!init_flag){ - current_max = value; - current_min = value; - is_detecting_emi = emi_first; - init_flag = true; - } -} - -SignalPoint PeakDetect(float value,int index,float gradient,bool *is_peak) -{ - if(value > current_max){ - max_point = index; - current_max = value; - } - if(value < current_min){ - min_point = index; - current_min = value; - } - - if(is_detecting_emi && value < (current_max - gradient) ){ - - is_detecting_emi = false; - - current_min = current_max; - min_point = max_point; - *is_peak = true; - peak.value = current_max; - peak.index = max_point; - return peak; - } - else if((!is_detecting_emi) && value > (current_min + gradient)) - { - - is_detecting_emi = true; - - current_max = current_min; - max_point = min_point; - *is_peak = false; - peak.value = current_min; - peak.index = min_point; - return peak; - } - - peak.index = -1; - return peak; -} - diff --git a/app/src/basic/adaptive_algorithm.h b/app/src/basic/adaptive_algorithm.h deleted file mode 100644 index d1bbbc6..0000000 --- a/app/src/basic/adaptive_algorithm.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __ALGORITHM__ -#define __ALGORITHM__ - -#include -#include -#include -#include -#include -#include - -#include "QRS.h" -static const uint32_t MEAN_SIZE = SAMPLING_RATE; -static uint32_t mean_count; -static float mean_sum; -static float mean; - -static const uint32_t RMS_SIZE = SAMPLING_RATE; -static uint32_t rms_count; -static float rms_sum; -static float rms; - -static const uint32_t CV_SIZE = SAMPLING_RATE; -static uint32_t cv_count; -static float sd; -static float cv; - -static float current_max; -static float current_min; -static int max_point; -static int min_point; -static SignalPoint peak; -static bool is_detecting_emi; -static bool init_flag = false; - -extern float CalculateMean(float); -extern float CalculateRootMeanSquare(float); -extern float CalculateCoefficientOfVariation(float); -extern void InitPeakDetect(float,bool); -extern SignalPoint PeakDetect(float,int,float,bool*); - -#endif diff --git a/app/src/basic/device_version_info_mgr.c b/app/src/basic/device_version_info_mgr.c deleted file mode 100644 index ccf0cce..0000000 --- a/app/src/basic/device_version_info_mgr.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "device_version_info_mgr.h" - -#include "board/board.h" -#include "zble_module.h" -// -#include "version.h" -#include "znordic.h" -void device_info_read_sn(sn_t *sn) { - uint32_t lot = NRF_UICR->CUSTOMER[0]; - uint32_t id = NRF_UICR->CUSTOMER[1]; - static char sn_str[15]; - sprintf(sn_str, CATEGORY "%04d%05d", lot, id); - if (lot == 0 || id == 0 || lot == 0xffffffff || id == 0xffffffff) { - sprintf(sn_str, "iflytop_test"); - } - memcpy(sn->sn, sn_str, sizeof(sn->sn)); -} - -const char *device_info_read_sn_str() { - static char sn_str[15]; - device_info_read_sn((sn_t *)sn_str); - return sn_str; -} - -uint16_t device_info_read_blestack_version(void) { return BLESTACK_VERSION; } -uint16_t device_info_read_bootloader_version(void) { return BOOTLOADER_VERSION; } -uint16_t device_info_read_firmware_version(void) { return FIRMWARE_VERSION; } -uint16_t device_info_read_hardware_version(void) { return HARDWARE_VERSION; } \ No newline at end of file diff --git a/app/src/basic/device_version_info_mgr.h b/app/src/basic/device_version_info_mgr.h deleted file mode 100644 index f523659..0000000 --- a/app/src/basic/device_version_info_mgr.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "znordic.h" - -typedef struct { - uint8_t sn[14]; -} sn_t; - -void device_info_read_sn(sn_t *sn); -const char *device_info_read_sn_str(); - -uint16_t device_info_read_blestack_version(void); -uint16_t device_info_read_bootloader_version(void); -uint16_t device_info_read_firmware_version(void); -uint16_t device_info_read_hardware_version(void); \ No newline at end of file diff --git a/app/src/basic/m24m02/m24m02.c b/app/src/basic/m24m02/m24m02.c deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/basic/m24m02/m24m02.h b/app/src/basic/m24m02/m24m02.h deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/basic/qrs_time_domain_zh.c b/app/src/basic/qrs_time_domain_zh.c deleted file mode 100644 index b42291e..0000000 --- a/app/src/basic/qrs_time_domain_zh.c +++ /dev/null @@ -1,231 +0,0 @@ -#include "qrs_time_domain_zh.h" - -#include -#include -#include - -#define HEART_RATE_FILTER_SIZE 10 - -typedef struct { - uint16_t data[HEART_RATE_FILTER_SIZE]; - uint16_t data_process_buf[HEART_RATE_FILTER_SIZE]; - uint32_t cnt; - uint32_t index; -} HeartRateMedianFilter_t; // ÖÐÖµÂ˲¨Æ÷ - -typedef struct { - uint16_t data[HEART_RATE_FILTER_SIZE]; - uint32_t cnt; - uint32_t index; - uint32_t sum; -} HeartRateMeanFilter_t; // ¾ùÖµÂ˲¨Æ÷ - -HeartRateMedianFilter_t m_heart_rate_median_filter; -HeartRateMeanFilter_t m_heart_rate_mean_filter; - -static void HeartRateMedianFilter_reset() { - memset(m_heart_rate_median_filter.data, 0, sizeof(m_heart_rate_median_filter.data)); - m_heart_rate_median_filter.cnt = 0; - m_heart_rate_median_filter.index = 0; -} -static uint16_t HeartRateMedianFilter_process(uint16_t data) { - HeartRateMedianFilter_t* pfilter = &m_heart_rate_median_filter; - - pfilter->data[pfilter->index] = data; - pfilter->index++; - pfilter->cnt++; - if (pfilter->index >=HEART_RATE_FILTER_SIZE) { - pfilter->index = 0; - } - - if (pfilter->cnt data_process_buf, pfilter->data, HEART_RATE_FILTER_SIZE * sizeof(uint16_t)); - for (uint8_t i = 0; i < HEART_RATE_FILTER_SIZE; i++) { - for (uint8_t j = i + 1; j < HEART_RATE_FILTER_SIZE; j++) { - if (pfilter->data_process_buf[i] > pfilter->data_process_buf[j]) { - uint16_t temp = pfilter->data_process_buf[i]; - pfilter->data_process_buf[i] = pfilter->data_process_buf[j]; - pfilter->data_process_buf[j] = temp; - } - } - } - return pfilter->data_process_buf[2]; -} -static void HeartRateMeanFilter_reset() { - memset(m_heart_rate_mean_filter.data, 0, sizeof(m_heart_rate_mean_filter.data)); - m_heart_rate_mean_filter.cnt = 0; - m_heart_rate_mean_filter.index = 0; - m_heart_rate_mean_filter.sum = 0; -} -static uint16_t HeartRateMeanFilter_process(uint16_t data) { - HeartRateMeanFilter_t* pfilter = &m_heart_rate_mean_filter; - - pfilter->sum -= pfilter->data[pfilter->index]; - pfilter->data[pfilter->index] = data; - pfilter->sum += data; - - pfilter->index++; - pfilter->cnt++; - - if (pfilter->index >= HEART_RATE_FILTER_SIZE) { - pfilter->index = 0; - } - - if (pfilter->cnt < HEART_RATE_FILTER_SIZE) { - return data; - } - - return pfilter->sum / HEART_RATE_FILTER_SIZE; -} - -static uint16_t m_data[TABLE_SIZE]; -static uint32_t m_ndata = 0; -static uint32_t m_dataindex = 0; -static uint32_t m_data_cnt = 0; -static uint16_t m_heartrate = 0; - -static uint32_t m_datasum = 0; -static float m_avg = 0; -static uint32_t m_max_val_in_m_data; - -static bool m_findpeak = false; - -static uint16_t pQRS_median_filter_cache[HEART_RATE_FILTER_SIZE]; -static uint16_t pQRS_median_filter_cache_index = 0; -static uint16_t pQRS_median_filter_cache_cnt = 0; - -static uint32_t m_last_peak_pos = 0; -static uint32_t m_peakcnt = 0; - -static uint16_t pQRS_median_filter(uint16_t indata) { - // memcpy(pQRS_median_filter_cache + 1, pQRS_median_filter_cache, 4 * sizeof(uint16_t)); - pQRS_median_filter_cache[pQRS_median_filter_cache_index] = indata; - pQRS_median_filter_cache_index++; - pQRS_median_filter_cache_cnt++; - if (pQRS_median_filter_cache_index >= HEART_RATE_FILTER_SIZE) { - pQRS_median_filter_cache_index = 0; - } - - if (pQRS_median_filter_cache_cnt < HEART_RATE_FILTER_SIZE) { - return indata; - } - - static uint16_t process_cache[HEART_RATE_FILTER_SIZE]; - memcpy(process_cache, pQRS_median_filter_cache, HEART_RATE_FILTER_SIZE * sizeof(uint16_t)); - for (uint8_t i = 0; i < HEART_RATE_FILTER_SIZE; i++) { - for (uint8_t j = i + 1; j < HEART_RATE_FILTER_SIZE; j++) { - if (process_cache[i] > process_cache[j]) { - uint16_t temp = process_cache[i]; - process_cache[i] = process_cache[j]; - process_cache[j] = temp; - } - } - } - return process_cache[2]; -} - -static uint32_t pQRS_findMaxValue() { - uint32_t max_val = 0; - for (uint32_t i = 0; i < TABLE_SIZE; i++) { - if (m_data[i] > max_val) { - max_val = m_data[i]; - } - } - return max_val; -} - -void QRS_resetBuf() { // - m_ndata = 0; - m_dataindex = 0; - m_heartrate = 0; - m_data_cnt = 0; - memset(m_data, 0, sizeof(m_data)); - m_datasum = 0; - m_findpeak = false; - pQRS_median_filter_cache_index = 0; - pQRS_median_filter_cache_cnt = 0; - m_peakcnt = 0; - - HeartRateMedianFilter_reset(); - HeartRateMeanFilter_reset(); -} - -void QRS_processData(uint16_t _data) { - uint16_t data = pQRS_median_filter(_data); - /******************************************************************************* - * Ìî³äBUF * - *******************************************************************************/ - m_datasum -= m_data[m_dataindex]; - m_data[m_dataindex] = data; - m_datasum += data; - - m_data_cnt++; - - if (m_dataindex < TABLE_SIZE) { - m_dataindex++; - } else { - m_dataindex = 0; - } - - m_ndata++; - if (m_ndata > TABLE_SIZE) { - m_ndata = TABLE_SIZE; - } - - /******************************************************************************* - * ÇóBUFµÄƽ¾ùÖµºÍ×î´óÖµ * - *******************************************************************************/ - if (m_ndata == TABLE_SIZE) { - m_avg = (float)m_datasum / m_ndata; - m_max_val_in_m_data = pQRS_findMaxValue(); - } - - /******************************************************************************* - * ѰÕÒQRS²¨·åºÍ²¨¹È * - *******************************************************************************/ - - if (!m_findpeak) { - uint16_t thresholdValue = (m_max_val_in_m_data - m_avg) * 0.666 + m_avg; - if (data > thresholdValue) { - m_findpeak = true; - m_peakcnt++; - - if (m_last_peak_pos != 0) { - uint16_t diff_peak_pos = m_data_cnt - m_last_peak_pos; - if (diff_peak_pos > 0) { - // - // m_heartrate = 60 * 500 / diff_peak_pos; - - uint16_t diff_peak_ms = diff_peak_pos * 2; // 500Hz - uint16_t heart_rate = 60 * 1000 / diff_peak_ms; - - m_heartrate = HeartRateMeanFilter_process(HeartRateMedianFilter_process(heart_rate)); - } - } - - m_last_peak_pos = m_data_cnt; - } - } else { - if (data < m_avg) { - m_findpeak = false; - } - } -} -uint16_t QRS_getHeartRate() { - __disable_fiq(); - uint16_t heartrate = m_heartrate; - __enable_fiq(); - - if (heartrate > 200) return 0; - if (heartrate < 55) return 0; - return heartrate; -} - -uint16_t QRS_getMaxValueLastVal() { return m_max_val_in_m_data; } - -uint16_t QRS_getAvgValueVal() { // - return m_avg; -} diff --git a/app/src/basic/qrs_time_domain_zh.h b/app/src/basic/qrs_time_domain_zh.h deleted file mode 100644 index 56f1a65..0000000 --- a/app/src/basic/qrs_time_domain_zh.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @file qrs_time_domain_zh.h - * @author zhaohe (zhaohe@domain.com) - * @brief - * @version 0.1 - * @date 2024-02-10 - * - * @copyright Copyright (c) 2024 - * - */ -#pragma once -#include -#define TABLE_SIZE 1000 - -void QRS_resetBuf(); -void QRS_processData(uint16_t data); -uint16_t QRS_getHeartRate(); -uint16_t QRS_getMaxValueLastVal(); -uint16_t QRS_getAvgValueVal(); diff --git a/app/src/basic/ssd1306/driver_ssd1306.c b/app/src/basic/ssd1306/driver_ssd1306.c deleted file mode 100644 index ba880cb..0000000 --- a/app/src/basic/ssd1306/driver_ssd1306.c +++ /dev/null @@ -1,2353 +0,0 @@ -/** - * Copyright (c) 2015 - present LibDriver All rights reserved - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @file driver_ssd1306.c - * @brief driver ssd1306 source file - * @version 2.0.0 - * @author Shifeng Li - * @date 2021-03-30 - * - *

history

- * - *
Date Version Author Description - *
2021/03/30 2.0 Shifeng Li format the code - *
2020/12/10 1.0 Shifeng Li first upload - *
- */ - -#include "driver_ssd1306.h" -#include "driver_ssd1306_font.h" - -/** - * @brief chip information definition - */ -#define CHIP_NAME "Solomon Systech SSD1306" /**< chip name */ -#define MANUFACTURER_NAME "Solomon Systech" /**< manufacturer name */ -#define SUPPLY_VOLTAGE_MIN 1.65f /**< chip min supply voltage */ -#define SUPPLY_VOLTAGE_MAX 3.3f /**< chip max supply voltage */ -#define MAX_CURRENT 0.78f /**< chip max current */ -#define TEMPERATURE_MIN -40.0f /**< chip min operating temperature */ -#define TEMPERATURE_MAX 85.0f /**< chip max operating temperature */ -#define DRIVER_VERSION 2000 /**< driver version */ - -/** - * @brief chip command data definition - */ -#define SSD1306_CMD 0 /**< command */ -#define SSD1306_DATA 1 /**< data */ - -/** - * @brief chip command definition - */ -#define SSD1306_CMD_LOWER_COLUMN_START_ADDRESS 0x00 /**< command lower column start address */ -#define SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS 0x10 /**< command higher column start address */ -#define SSD1306_CMD_MEMORY_ADDRESSING_MODE 0x20 /**< command memory addressing mode */ -#define SSD1306_CMD_SET_COLUMN_ADDRESS 0x21 /**< command set column address */ -#define SSD1306_CMD_SET_PAGE_ADDRESS 0x22 /**< command set page address */ -#define SSD1306_CMD_SET_FADE_OUT_AND_BLINKING 0x23 /**< command set fade out and blinking */ -#define SSD1306_CMD_RIGHT_HORIZONTAL_SCROLL 0x26 /**< command right horizontal scroll */ -#define SSD1306_CMD_LEFT_HORIZONTAL_SCROLL 0x27 /**< command left horizontal scroll */ -#define SSD1306_CMD_VERTICAL_RIGHT_HORIZONTAL_SCROLL 0x29 /**< command vertical right horizontal scroll */ -#define SSD1306_CMD_VERTICAL_LEFT_HORIZONTAL_SCROLL 0x2A /**< command vertical left horizontal scroll */ -#define SSD1306_CMD_DEACTIVATE_SCROLL 0x2E /**< command deactivate scroll */ -#define SSD1306_CMD_ACTIVATE_SCROLL 0x2F /**< command activate scroll */ -#define SSD1306_CMD_DISPLAY_START_LINE 0x40 /**< command display start line */ -#define SSD1306_CMD_CONTRAST_CONTROL 0x81 /**< command contrast control */ -#define SSD1306_CMD_CHARGE_PUMP_SETTING 0x8D /**< command charge pump setting */ -#define SSD1306_CMD_COLUMN_0_MAPPED_TO_SEG0 0xA0 /**< command column 0 mapped to seg 0 */ -#define SSD1306_CMD_COLUMN_127_MAPPED_TO_SEG0 0xA1 /**< command column 127 mapped to seg 0 */ -#define SSD1306_CMD_VERTICAL_SCROLL_AREA 0xA3 /**< command vertical scroll area */ -#define SSD1306_CMD_ENTIRE_DISPLAY_OFF 0xA4 /**< command entire display off */ -#define SSD1306_CMD_ENTIRE_DISPLAY_ON 0xA5 /**< command entire display on */ -#define SSD1306_CMD_NORMAL_DISPLAY 0xA6 /**< command normal display */ -#define SSD1306_CMD_INVERSE_DISPLAY 0xA7 /**< command inverse display */ -#define SSD1306_CMD_MULTIPLEX_RATIO 0xA8 /**< command multiplex ratio */ -#define SSD1306_CMD_DISPLAY_OFF 0xAE /**< command display off */ -#define SSD1306_CMD_DISPLAY_ON 0xAF /**< command display on */ -#define SSD1306_CMD_PAGE_ADDR 0xB0 /**< command page address */ -#define SSD1306_CMD_SCAN_DIRECTION_COM0_START 0xC0 /**< command scan direction com 0 start */ -#define SSD1306_CMD_SCAN_DIRECTION_COMN_1_START 0xC8 /**< command scan direction com n-1 start */ -#define SSD1306_CMD_DISPLAY_OFFSET 0xD3 /**< command display offset */ -#define SSD1306_CMD_DISPLAY_CLOCK_DIVIDE 0xD5 /**< command display clock divide */ -#define SSD1306_CMD_SET_ZOOM_IN 0xD6 /**< command set zoom in */ -#define SSD1306_CMD_PRE_CHARGE_PERIOD 0xD9 /**< command pre charge period */ -#define SSD1306_CMD_COM_PINS_CONF 0xDA /**< command com pins conf */ -#define SSD1306_CMD_COMH_DESLECT_LEVEL 0xDB /**< command comh deslect level */ -#define SSD1306_CMD_NOP 0xE3 /**< command nop */ - -/** - * @brief write one byte - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] data is the write data - * @param[in] cmd is the command or data type - * @return status code - * - 0 success - * - 1 write failed - * @note none - */ -static uint8_t a_ssd1306_write_byte(ssd1306_handle_t *handle, uint8_t data, uint8_t cmd) -{ - uint8_t res; - - if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic */ - { - if (cmd != 0) /* if data */ - { - if (handle->iic_write(handle->iic_addr, 0x40, &data, 1) != 0) /* write data */ - { - return 1; /* return error */ - } - else - { - return 0; /* success return 0 */ - } - } - else - { - if (handle->iic_write(handle->iic_addr, 0x00, &data, 1) != 0) /* write command */ - { - return 1; /* return error */ - } - else - { - return 0; /* success return 0 */ - } - } - } - else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi */ - { - res = handle->spi_cmd_data_gpio_write(cmd); /* write data command */ - if (res != 0) /* check error */ - { - return 1; /* return error */ - } - - if (handle->spi_write_cmd(&data, 1) != 0) /* write command */ - { - return 1; /* return error */ - } - else - { - return 0; /* success return 0 */ - } - } - else - { - return 1; /* return error */ - } -} - -/** - * @brief write multiple bytes - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] *data points to a data buffer - * @param[in] len is the data length - * @param[in] cmd is the command or data type - * @return status code - * - 0 success - * - 1 write failed - * @note none - */ -static uint8_t a_ssd1306_multiple_write_byte(ssd1306_handle_t *handle, uint8_t *data, uint8_t len, uint8_t cmd) -{ - uint8_t res; - - if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic */ - { - if (cmd != 0) /* if data */ - { - if (handle->iic_write(handle->iic_addr, 0x40, data, len) != 0) /* write data */ - { - return 1; /* return error */ - } - else - { - return 0; /* success return 0 */ - } - } - else - { - if (handle->iic_write(handle->iic_addr, 0x00, data, len) != 0) /* write command */ - { - return 1; /* return error */ - } - else - { - return 0; /* success return 0 */ - } - } - } - else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi */ - { - res = handle->spi_cmd_data_gpio_write(cmd); /* write data command */ - if (res != 0) /* check error */ - { - return 1; /* return error */ - } - - if (handle->spi_write_cmd(data, len) != 0) /* write command */ - { - return 1; /* return error */ - } - else - { - return 0; /* success return 0 */ - } - } - else - { - return 1; /* return error */ - } -} - -/** - * @brief draw a point in gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] data is the write data - * @return status code - * - 0 success - * - 1 gram draw point failed - * @note none - */ -static uint8_t a_ssd1306_gram_draw_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data) -{ - uint8_t pos; - uint8_t bx; - uint8_t temp = 0; - - pos = y / 8; /* get y page */ - bx = y % 8; /* get y point */ - temp = 1 << bx; /* set data */ - if (data != 0) /* if 1 */ - { - handle->gram[x][pos] |= temp; /* set 1 */ - } - else - { - handle->gram[x][pos] &= ~temp; /* set 0 */ - } - - return 0; /* success return 0 */ -} - -/** - * @brief draw a char in gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] chr is the write char - * @param[in] size is the char size - * @param[in] mode is the display mode - * @return status code - * - 0 success - * - 1 gram show char failed - * @note none - */ -static uint8_t a_ssd1306_gram_show_char(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t chr, uint8_t size, uint8_t mode) -{ - uint8_t temp, t, t1; - uint8_t y0 = y; - uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); /* get size */ - - chr = chr - ' '; /* get index */ - for (t = 0; t < csize; t++) /* write size */ - { - if (size == 12) /* if size 12 */ - { - temp = gsc_ssd1306_ascii_1206[chr][t]; /* get ascii 1206 */ - } - else if (size == 16) /* if size 16 */ - { - temp = gsc_ssd1306_ascii_1608[chr][t]; /* get ascii 1608 */ - } - else if(size == 24) /* if size 24 */ - { - temp = gsc_ssd1306_ascii_2412[chr][t]; /* get ascii 2412 */ - } - else - { - return 1; /* return error */ - } - for (t1 = 0; t1 < 8; t1++) /* write one line */ - { - if ((temp & 0x80) != 0) /* if 1 */ - { - if (a_ssd1306_gram_draw_point(handle, x, y, mode) != 0) /* draw point */ - { - return 1; /* return error */ - } - } - else - { - if (a_ssd1306_gram_draw_point(handle, x, y, !mode) != 0) /* draw point */ - { - return 1; /* return error */ - } - } - temp <<= 1; /* left shift 1 */ - y++; - if ((y - y0) == size) /* reset size */ - { - y = y0; /* set y */ - x++; /* x++ */ - - break; /* break */ - } - } - } - - return 0; /* success return 0 */ -} - -/** - * @brief clear the screen - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 clear failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_clear(ssd1306_handle_t *handle) -{ - uint8_t i; - uint8_t n; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - for (i = 0; i < 8; i++) /* write 8 page */ - { - if (a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR+i, SSD1306_CMD) != 0) /* set page */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - if (a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set lower column 0 */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - if (a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set higher column 0 */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - for (n = 0; n < 128; n++) /* write 128 */ - { - handle->gram[n][i] = 0x00; /* set black */ - if (a_ssd1306_write_byte(handle, handle->gram[n][i], SSD1306_DATA) != 0) /* write data */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - } - } - - return 0; /* success return 0 */ -} - -/** - * @brief update the gram data - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 gram update failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_gram_update(ssd1306_handle_t *handle) -{ - uint8_t i; - uint8_t n; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - for (i = 0; i < 8; i++) /* write 8 page */ - { - if (a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR+i, SSD1306_CMD) != 0) /* set page */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - if (a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set lower column 0 */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - if (a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set higher column 0 */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - for (n = 0; n < 128; n++) /* write 128 */ - { - // handle->delay_ms(100); - if (a_ssd1306_write_byte(handle, handle->gram[n][i], SSD1306_DATA) != 0) /* write data */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - } - } - - return 0; /* success return 0 */ -} - -/** - * @brief write a point - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] data is the write data - * @return status code - * - 0 success - * - 1 write point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data) -{ - uint8_t pos; - uint8_t bx; - uint8_t temp = 0; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if ((x > 127) || (y > 63)) /* check x, y */ - { - - return 4; /* return error */ - } - - pos = y / 8; /* get y page */ - bx = y % 8; /* get y point */ - temp = 1 << bx; /* set data */ - if (data != 0) /* check the data */ - { - handle->gram[x][pos] |= temp; /* set 1 */ - } - else - { - handle->gram[x][pos] &= ~temp; /* set 0 */ - } - #if 1 - if (a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR + pos, SSD1306_CMD) != 0) /* write page addr */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - if (a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS|(x&0x0F), SSD1306_CMD) != 0) /* write lower column */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - if (a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS|((x>>4)&0x0F), SSD1306_CMD) != 0) /* write higher column */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - return 1; /* return error */ - } - if (a_ssd1306_write_byte(handle, handle->gram[x][pos], SSD1306_DATA) != 0) /* write data */ - { - handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ - - return 1; /* return error */ - } - else - { - return 0; /* success return 0 */ - } - #endif - return 0; -} - -/** - * @brief read a point - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[out] *data points to a data buffer - * @return status code - * - 0 success - * - 1 read point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data) -{ - uint8_t pos; - uint8_t bx; - uint8_t temp = 0; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if ((x > 127) || (y > 63)) /* check x, y */ - { - - return 4; /* return error */ - } - - pos = y / 8; /* get y page */ - bx = y % 8; /* get y point */ - temp = 1 << bx; /* set data */ - if ((handle->gram[x][pos] & temp) != 0) /* get data */ - { - *data = 1; /* set 1 */ - } - else - { - *data = 0; /* set 0 */ - } - - return 0; /* success return 0 */ -} - -/** - * @brief write a point in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] data is the write data - * @return status code - * - 0 success - * - 1 gram write point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_gram_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data) -{ - uint8_t pos; - uint8_t bx; - uint8_t temp = 0; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if ((x > 127) || (y > 63)) /* check x, y */ - { - return 4; /* return error */ - } - - pos = y / 8; /* get y page */ - bx = y % 8; /* get y point */ - temp = 1 << bx; /* set data */ - if (data != 0) /* if 1 */ - { - handle->gram[x][pos] |= temp; /* set 1 */ - } - else - { - handle->gram[x][pos] &= ~temp; /* set 0 */ - } - - return 0; /* success return 0 */ -} - -/** - * @brief read a point from the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[out] *data points to a data buffer - * @return status code - * - 0 success - * - 1 gram read point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_gram_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data) -{ - uint8_t pos; - uint8_t bx; - uint8_t temp = 0; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if ((x > 127) || (y > 63)) /* check x, y */ - { - - return 4; /* return error */ - } - - pos = y / 8; /* get y page */ - bx = y % 8; /* get y point */ - temp = 1 << bx; /* set data */ - if ((handle->gram[x][pos] & temp) != 0) /* get data */ - { - *data = 1; /* set 1 */ - } - else - { - *data = 0; /* set 0 */ - } - - return 0; /* success return 0 */ -} - -/** - * @brief draw a string in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] *str points to a write string address - * @param[in] len is the length of the string - * @param[in] color is the display color - * @param[in] font is the display font size - * @return status code - * - 0 success - * - 1 gram write string failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_gram_write_string(ssd1306_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if((x > 127) || (y > 63)) /* check x, y */ - { - - return 4; /* return error */ - } - - while ((len != 0) && (*str <= '~') && (*str >= ' ')) /* write all string */ - { - if (x > (127 - (font / 2))) /* check x point */ - { - x = 0; /* set x */ - y += (uint8_t)font; /* set next row */ - } - if (y > (63 - font)) /* check y pont */ - { - y = x = 0; /* reset to 0,0 */ - } - if (a_ssd1306_gram_show_char(handle, x, y, *str, font, color) != 0) /* show a char */ - { - return 1; /* return error */ - } - x += (uint8_t)(font / 2); /* x + font/2 */ - str++; /* str address++ */ - len--; /* str length-- */ - } - - return 0; /* success return 0 */ -} - -/** - * @brief fill a rectangle in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] color is the display color - * @return status code - * - 0 success - * - 1 gram fill rect failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 left or top is invalid - * - 5 right or bottom is invalid - * - 6 left > right or top > bottom - * @note none - */ -uint8_t ssd1306_gram_fill_rect(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color) -{ - uint8_t x, y; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if ((left > 127) || (top > 63)) /* check left top */ - { - handle->debug_print("ssd1306: left or top is invalid.\n"); /* left or top is invalid */ - - return 4; /* return error */ - } - if ((right > 127) || (bottom > 63)) /* check right bottom */ - { - handle->debug_print("ssd1306: right or bottom is invalid.\n"); /* right or bottom is invalid */ - - return 5; /* return error */ - } - if ((left > right) || (top > bottom)) /* check left right top bottom */ - { - handle->debug_print("ssd1306: left > right or top > bottom.\n"); /* left > right or top > bottom */ - - return 6; /* return error */ - } - - for (x = left; x <= right; x++) /* write x */ - { - for (y = top; y <= bottom; y++) /* write y */ - { - if (a_ssd1306_gram_draw_point(handle, x, y, color) != 0) /* draw point */ - { - return 1; /* return error */ - } - } - } - - return 0; /* return error */ -} - -/** - * @brief draw a picture in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] *img points to an image buffer - * @return status code - * - 0 success - * - 1 gram draw picture failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 left or top is invalid - * - 5 right or bottom is invalid - * - 6 left > right or top > bottom - * @note none - */ -uint8_t ssd1306_gram_draw_picture(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img) -{ - uint8_t x, y; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if ((left > 127) || (top > 63)) /* check left top */ - { - handle->debug_print("ssd1306: left or top is invalid.\n"); /* left or top is invalid */ - - return 4; /* return error */ - } - if ((right > 127) || (bottom > 63)) /* check right bottom */ - { - handle->debug_print("ssd1306: right or bottom is invalid.\n"); /* right or bottom is invalid */ - - return 5; /* return error */ - } - if ((left > right) || (top > bottom)) /* check left right top bottom */ - { - handle->debug_print("ssd1306: left > right or top > bottom.\n"); /* left > right or top > bottom */ - - return 6; /* return error */ - } - - for (x = left; x <= right; x++) /* write x */ - { - for (y = top; y <= bottom; y++) /* write y */ - { - if (a_ssd1306_gram_draw_point(handle, x, y, *img) != 0) /* draw point */ - { - return 1; /* return error */ - } - img++; /* img++ */ - } - } - - return 0; /* succeed return 0 */ -} - -/** - * @brief initialize the chip - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 iic or spi initialization failed - * - 2 handle is NULL - * - 3 linked functions is NULL - * - 4 reset failed - * - 5 command && data init failed - * - 6 interface param is invalid - * @note none - */ -uint8_t ssd1306_init(ssd1306_handle_t *handle) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->debug_print == NULL) /* check debug_print */ - { - return 3; /* return error */ - } - if (handle->iic_init == NULL) /* check iic_init */ - { - handle->debug_print("ssd1306: iic_init is null.\n"); /* iic_init is null */ - - return 3; /* return error */ - } - if (handle->iic_deinit == NULL) /* check iic_deinit */ - { - handle->debug_print("ssd1306: iic_deinit is null.\n"); /* iic_deinit is null */ - - return 3; /* return error */ - } - if (handle->iic_write == NULL) /* check iic_write */ - { - handle->debug_print("ssd1306: iic_write is null.\n"); /* iic_write is null */ - - return 3; /* return error */ - } - if (handle->spi_init == NULL) /* check spi_init */ - { - handle->debug_print("ssd1306: spi_init is null.\n"); /* spi_init is null */ - - return 3; /* return error */ - } - if (handle->spi_deinit == NULL) /* check spi_deinit */ - { - handle->debug_print("ssd1306: spi_deinit is null.\n"); /* spi_deinit is null */ - - return 3; /* return error */ - } - if (handle->spi_write_cmd == NULL) /* check spi_write_cmd */ - { - handle->debug_print("ssd1306: spi_write_cmd is null.\n"); /* spi_write_cmd is null */ - - return 3; /* return error */ - } - if (handle->delay_ms == NULL) /* check delay_ms */ - { - handle->debug_print("ssd1306: delay_ms is null.\n"); /* delay_ms is null */ - - return 3; /* return error */ - } - if (handle->spi_cmd_data_gpio_init == NULL) /* check spi_cmd_data_gpio_init */ - { - handle->debug_print("ssd1306: spi_cmd_data_gpio_init is null.\n"); /* spi_cmd_data_gpio_init is null */ - - return 3; /* return error */ - } - if (handle->spi_cmd_data_gpio_deinit == NULL) /* check spi_cmd_data_gpio_deinit */ - { - handle->debug_print("ssd1306: spi_cmd_data_gpio_deinit is null.\n"); /* spi_cmd_data_gpio_deinit is null */ - - return 3; /* return error */ - } - if (handle->spi_cmd_data_gpio_write == NULL) /* check spi_cmd_data_gpio_write */ - { - handle->debug_print("ssd1306: spi_cmd_data_gpio_write is null.\n"); /* spi_cmd_data_gpio_write is null */ - - return 3; /* return error */ - } - if (handle->reset_gpio_init == NULL) /* check reset_gpio_init */ - { - handle->debug_print("ssd1306: reset_gpio_init is null.\n"); /* reset_gpio_init is null */ - - return 3; /* return error */ - } - if (handle->reset_gpio_deinit == NULL) /* check reset_gpio_deinit */ - { - handle->debug_print("ssd1306: reset_gpio_deinit is null.\n"); /* reset_gpio_deinit is null */ - - return 3; /* return error */ - } - if(handle->reset_gpio_write == NULL) /* check reset_gpio_write */ - { - handle->debug_print("ssd1306: reset_gpio_write is null.\n"); /* reset_gpio_write is null */ - - return 3; /* return error */ - } - - if (handle->spi_cmd_data_gpio_init() != 0) /* check spi_cmd_data_gpio_init */ - { - handle->debug_print("ssd1306: spi cmd data gpio init failed.\n"); /* spi cmd data gpio init failed */ - - return 5; /* return error */ - } - if (handle->reset_gpio_init() != 0) /* reset gpio init */ - { - handle->debug_print("ssd1306: reset gpio init failed.\n"); /* reset gpio init failed */ - (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ - - return 4; /* return error */ - } - if (handle->reset_gpio_write(0) != 0) /* write 0 */ - { - handle->debug_print("ssd1306: reset gpio write failed.\n"); /* reset gpio write failed */ - (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ - (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ - - return 4; /* return error */ - } - handle->delay_ms(100); /* delay 100 ms */ - if (handle->reset_gpio_write(1) != 0) /* write 1 */ - { - handle->debug_print("ssd1306: reset gpio write failed.\n"); /* reset gpio write failed */ - (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ - (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ - - return 4; /* return error */ - } - if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic interface */ - { - if (handle->iic_init() != 0) /* iic init */ - { - handle->debug_print("ssd1306: iic init failed.\n"); /* iic init failed */ - (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ - (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ - - return 1; /* return error */ - } - } - else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi interface */ - { - if (handle->spi_init() != 0) /* spi init */ - { - handle->debug_print("ssd1306: spi init failed.\n"); /* spi init failed */ - (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ - (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ - - return 1; /* return error */ - } - } - else - { - handle->debug_print("ssd1306: interface is invalid.\n"); /* interface is invalid */ - (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ - (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ - - return 6; /* return error */ - } - handle->inited = 1; /* flag inited */ - - return 0; /* success return 0 */ -} - -/** - * @brief close the chip - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 iic or spi deinit failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 power down failed - * - 5 reset gpio deinit failed - * - 6 command && data deinit failed - * - 7 interface param is invalid - * @note none - */ -uint8_t ssd1306_deinit(ssd1306_handle_t *handle) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - buf[0] = SSD1306_CMD_CHARGE_PUMP_SETTING; /* charge pump off */ - buf[1] = 0x10 | (0 << 2); /* set charge pump */ - if (a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD) != 0) /* write command */ - { - handle->debug_print("ssd1306: write command failed.\n"); /* write command failed */ - - return 4; /* return error */ - } - if (a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_OFF, SSD1306_CMD) != 0) /* write display off */ - { - handle->debug_print("ssd1306: write command failed.\n"); /* write command failed */ - - return 4; /* return error */ - } - if (handle->reset_gpio_deinit() != 0) /* reset gpio deinit */ - { - handle->debug_print("ssd1306: reset gpio deinit failed.\n"); /* reset gpio deinit failed */ - - return 5; /* return error */ - } - if (handle->spi_cmd_data_gpio_deinit() != 0) /* spi cmd data gpio deinit */ - { - handle->debug_print("ssd1306: spi cmd data gpio deinit failed.\n"); /* spi cmd data gpio deinit failed */ - - return 6; /* return error */ - } - if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic interface */ - { - if (handle->iic_deinit() != 0) /* iic deinit */ - { - handle->debug_print("ssd1306: iic deinit failed.\n"); /* iic deinit failed */ - - return 1; /* return error */ - } - } - else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi interface */ - { - if (handle->spi_deinit() != 0) /* spi deinit */ - { - handle->debug_print("ssd1306: spi deinit failed.\n"); /* spi deinit failed */ - - return 1; /* return error */ - } - } - else - { - handle->debug_print("ssd1306: interface is invalid.\n"); /* interface is invalid */ - - return 7; /* return error */ - } - handle->inited = 0; /* flag close */ - - return 0; /* success return 0 */ -} - -/** - * @brief set the chip interface - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] interface is the chip interface - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_set_interface(ssd1306_handle_t *handle, ssd1306_interface_t ifhandler) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - - handle->iic_spi = (uint8_t)ifhandler; /* set interface */ - - return 0; /* success return 0 */ -} - -/** - * @brief get the chip interface - * @param[in] *handle points to an ssd1306 handle structure - * @param[out] *interface points to a chip interface buffer - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_get_interface(ssd1306_handle_t *handle, ssd1306_interface_t *ifhandler) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - - *ifhandler = (ssd1306_interface_t)(handle->iic_spi); /* get interface */ - - return 0; /* success return 0 */ -} - -/** - * @brief set the chip iic address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr_pin is the iic address - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_set_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t addr_pin) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - - handle->iic_addr = (uint8_t)addr_pin; /* set addr pin */ - - return 0; /* success return 0 */ -} - -/** - * @brief get the chip iic address - * @param[in] *handle points to an ssd1306 handle structure - * @param[out] *addr_pin points to an iic address buffer - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_get_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t *addr_pin) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - - *addr_pin = (ssd1306_address_t)(handle->iic_addr); /* set address */ - - return 0; /* success return 0 */ -} - -/** - * @brief set the low column start address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr is the low column start address - * @return status code - * - 0 success - * - 1 set low column start address failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 addr is invalid - * @note addr <= 0xF - */ -uint8_t ssd1306_set_low_column_start_address(ssd1306_handle_t *handle, uint8_t addr) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (addr > 0x0F) /* check addr */ - { - handle->debug_print("ssd1306: addr is invalid.\n"); /* addr is invalid */ - - return 4; /* return error */ - } - - return a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS|(addr&0x0F), SSD1306_CMD); /* write command */ -} - -/** - * @brief set the high column start address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr is the high column start address - * @return status code - * - 0 success - * - 1 set high column start address failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 addr is invalid - * @note addr <= 0xF - */ -uint8_t ssd1306_set_high_column_start_address(ssd1306_handle_t *handle, uint8_t addr) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (addr > 0x0F) /* check addr */ - { - handle->debug_print("ssd1306: addr is invalid.\n"); /* addr is invalid */ - - return 4; /* return error */ - } - - return a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS|(addr&0x0F), SSD1306_CMD); /* write command */ -} - -/** - * @brief set the memory addressing mode - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] mode is the memory addressing mode - * @return status code - * - 0 success - * - 1 set memory addressing mode failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_memory_addressing_mode(ssd1306_handle_t *handle, ssd1306_memory_addressing_mode_t mode) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - buf[0] = SSD1306_CMD_MEMORY_ADDRESSING_MODE; /* set command mode */ - buf[1] = mode; /* set mode */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the column address range - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_addr is the column start address - * @param[in] end_addr is the column end address - * @return status code - * - 0 success - * - 1 set column address range failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start addr is invalid - * - 5 end addr is invalid - * @note start addr and end addr can't be over 0x7F - */ -uint8_t ssd1306_set_column_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr) -{ - uint8_t buf[3]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (start_addr > 0x7F) /* check start addr */ - { - handle->debug_print("ssd1306: start addr is invalid.\n"); /* start addr is invalid */ - - return 4; /* return error */ - } - if (end_addr > 0x7F) /* check end addr */ - { - handle->debug_print("ssd1306: end addr is invalid.\n"); /* end addr is invalid */ - - return 5; /* return error */ - } - - buf[0] = SSD1306_CMD_SET_COLUMN_ADDRESS; /* set command */ - buf[1] = start_addr & 0x7F; /* set start address */ - buf[2] = end_addr & 0x7F; /* set end address */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 3, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the page address range - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_addr is the page start address - * @param[in] end_addr is the page end address - * @return status code - * - 0 success - * - 1 set page address range failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start addr is invalid - * - 5 end addr is invalid - * @note start addr and end addr can't be over 0x07 - */ -uint8_t ssd1306_set_page_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr) -{ - uint8_t buf[3]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (start_addr > 0x07) /* check start addr */ - { - handle->debug_print("ssd1306: start addr is invalid.\n"); /* start addr is invalid */ - - return 4; /* return error */ - } - if (end_addr > 0x07) /* check end addr */ - { - handle->debug_print("ssd1306: end addr is invalid.\n"); /* end_addr is invalid */ - - return 5; /* return error */ - } - - buf[0] = SSD1306_CMD_SET_PAGE_ADDRESS; /* set command */ - buf[1] = start_addr & 0x07; /* set start address */ - buf[2] = end_addr & 0x07; /* set end address */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 3, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the fade blinking mode - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] mode is the fade blinking mode - * @param[in] frames is the fade or blinking frames - * @return status code - * - 0 success - * - 1 set fade blinking mode failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 frames is invalid - * @note frames max is 0x0F and div is (frames + 1) * 8 - */ -uint8_t ssd1306_set_fade_blinking_mode(ssd1306_handle_t *handle, ssd1306_fade_blinking_mode_t mode, uint8_t frames) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (frames> 0x0F) /* check frames */ - { - handle->debug_print("ssd1306: frames is invalid.\n"); /* frames is invalid */ - - return 4; /* return error */ - } - - buf[0] = SSD1306_CMD_SET_FADE_OUT_AND_BLINKING; /* set command */ - buf[1] = (uint8_t)((mode << 4) | (frames & 0x0F)); /* set mode */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the right horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set right horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start page addr is invalid - * - 5 end page addr is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07 - */ -uint8_t ssd1306_set_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - ssd1306_scroll_frame_t frames) -{ - uint8_t buf[7]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (start_page_addr > 0x07) /* check start_page_addr */ - { - handle->debug_print("ssd1306: start page addr is invalid.\n"); /* start page addr is invalid */ - - return 4; /* return error */ - } - if (end_page_addr > 0x07) /* check end_page_addr */ - { - handle->debug_print("ssd1306: end page addr is invalid.\n"); /* end page addr is invalid */ - - return 5; /* return error */ - } - - buf[0] = SSD1306_CMD_RIGHT_HORIZONTAL_SCROLL; /* set command */ - buf[1] = 0x00; /* set null */ - buf[2] = start_page_addr & 0x07; /* set start page address */ - buf[3] = frames & 0x07; /* set frames */ - buf[4] = end_page_addr & 0x07; /* set end page address */ - buf[5] = 0x00; /* set null */ - buf[6] = 0xFF; /* set frame end */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 7, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the left horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set left horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_page_addr is invalid - * - 5 end_page_addr is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07 - */ -uint8_t ssd1306_set_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - ssd1306_scroll_frame_t frames) -{ - uint8_t buf[7]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (start_page_addr > 0x07) /* check start_page_addr */ - { - handle->debug_print("ssd1306: start_page_addr is invalid.\n"); /* start_page_addr is invalid */ - - return 4; /* return error */ - } - if (end_page_addr > 0x07) /* check end_page_addr */ - { - handle->debug_print("ssd1306: end_page_addr is invalid.\n"); /* end_page_addr is invalid */ - - return 5; /* return error */ - } - - buf[0] = SSD1306_CMD_LEFT_HORIZONTAL_SCROLL; /* set command */ - buf[1] = 0x00; /* set null */ - buf[2] = start_page_addr & 0x07; /* set end page addr */ - buf[3] = frames & 0x07; /* set frames */ - buf[4] = end_page_addr & 0x07; /* set end page addr */ - buf[5] = 0x00; /* set null */ - buf[6] = 0xFF; /* set frame end */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 7, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the vertical right horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] rows is the row address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set vertical right horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_page_addr is invalid - * - 5 end_page_addr is invalid - * - 6 rows is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F - */ -uint8_t ssd1306_set_vertical_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - uint8_t rows, ssd1306_scroll_frame_t frames) -{ - uint8_t buf[6]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (start_page_addr > 0x07) /* check start_page_addr */ - { - handle->debug_print("ssd1306: start_page_addr is invalid.\n"); /* start_page_addr is invalid */ - - return 4; /* return error */ - } - if (end_page_addr > 0x07) /* check end page addr */ - { - handle->debug_print("ssd1306: end_page_addr is invalid.\n"); /* end_page_addr is invalid */ - - return 5; /* return error */ - } - if (rows > 0x3F) /* check rows */ - { - handle->debug_print("ssd1306: rows is invalid.\n"); /* rows is invalid */ - - return 6; /* return error */ - } - - buf[0] = SSD1306_CMD_VERTICAL_RIGHT_HORIZONTAL_SCROLL; /* set command */ - buf[1] = 0x00; /* set null */ - buf[2] = start_page_addr & 0x07; /* set start page addr */ - buf[3] = frames & 0x07; /* set frames */ - buf[4] = end_page_addr & 0x07; /* set end page addr */ - buf[5] = rows & 0x3F; /* set rows */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 6, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the vertical left horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] rows is the row address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set vertical left horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_page_addr is invalid - * - 5 end_page_addr is invalid - * - 6 rows is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F - */ -uint8_t ssd1306_set_vertical_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - uint8_t rows, ssd1306_scroll_frame_t frames) -{ - uint8_t buf[6]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (start_page_addr > 0x07) /* check start_page_addr */ - { - handle->debug_print("ssd1306: start_page_addr is invalid.\n"); /* start_page_addr is invalid */ - - return 4; /* return error */ - } - if (end_page_addr > 0x07) /* check end_page_addr */ - { - handle->debug_print("ssd1306: end_page_addr is invalid.\n"); /* end_page_addr is invalid */ - - return 5; /* return error */ - } - if (rows > 0x3F) /* check rows */ - { - handle->debug_print("ssd1306: rows is invalid.\n"); /* rows is invalid */ - - return 6; /* return error */ - } - - buf[0] = SSD1306_CMD_VERTICAL_LEFT_HORIZONTAL_SCROLL; /* set command */ - buf[1] = 0x00; /* set null */ - buf[2] = start_page_addr & 0x07; /* set start page addr */ - buf[3] = frames & 0x07; /* set frames */ - buf[4] = end_page_addr & 0x07; /* set end page addr */ - buf[5] = rows & 0x3F; /* set rows */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 6, SSD1306_CMD); /* write command */ -} - -/** - * @brief deactivate the scroll - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 deactivate scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_deactivate_scroll(ssd1306_handle_t *handle) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - return a_ssd1306_write_byte(handle, SSD1306_CMD_DEACTIVATE_SCROLL, SSD1306_CMD); /* write command */ -} - -/** - * @brief activate the scroll - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 activate scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_activate_scroll(ssd1306_handle_t *handle) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - return a_ssd1306_write_byte(handle, SSD1306_CMD_ACTIVATE_SCROLL, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the display start line - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] l is the start line - * @return status code - * - 0 success - * - 1 set display start line failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 line is invalid - * @note line <= 0x3F - */ -uint8_t ssd1306_set_display_start_line(ssd1306_handle_t *handle, uint8_t l) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (l > 0x3F) /* check line */ - { - handle->debug_print("ssd1306: line is invalid.\n"); /* line is invalid */ - - return 4; /* return error */ - } - - return a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_START_LINE|(l&0x3F), SSD1306_CMD); /* write command */ -} - -/** - * @brief set the display contrast - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] contrast is the display contrast - * @return status code - * - 0 success - * - 1 set contrast failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_contrast(ssd1306_handle_t *handle, uint8_t contrast) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - buf[0] = SSD1306_CMD_CONTRAST_CONTROL; /* set command */ - buf[1] = contrast; /* set contrast */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief enable or disable the charge pump - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] enable is a bool value - * @return status code - * - 0 success - * - 1 set charge pump failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_charge_pump(ssd1306_handle_t *handle, ssd1306_charge_pump_t enable) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - buf[0] = SSD1306_CMD_CHARGE_PUMP_SETTING; /* set command */ - buf[1] = (uint8_t)(0x10 | (enable << 2)); /* set charge pump */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the segment remap - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] remap is the segment remap param - * @return status code - * - 0 success - * - 1 set segment remap failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_segment_remap(ssd1306_handle_t *handle, ssd1306_segment_column_remap_t remap) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - if (remap != 0) /* check remap */ - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_COLUMN_127_MAPPED_TO_SEG0, SSD1306_CMD); /* write remap */ - } - else - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_COLUMN_0_MAPPED_TO_SEG0, SSD1306_CMD); /* write remap */ - } -} - -/** - * @brief set the vertical scroll area - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_row is the start row - * @param[in] end_row is the end row - * @return status code - * - 0 success - * - 1 set vertical scroll area failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_row is invalid - * - 5 end_row is invalid - * - 6 end_row > start_row - * @note start_row <= 0x3F, end_row <= 0x7F, start_row >= end_row - */ -uint8_t ssd1306_set_vertical_scroll_area(ssd1306_handle_t *handle, uint8_t start_row, uint8_t end_row) -{ - uint8_t buf[3]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (start_row > 0x3F) /* check start row */ - { - handle->debug_print("ssd1306: start_row is invalid.\n"); /* start_row is invalid */ - - return 4; /* return error */ - } - if (end_row > 0x7F) /* check end_row */ - { - handle->debug_print("ssd1306: end_row is invalid.\n"); /* end_row is invalid */ - - return 5; /* return error */ - } - if (end_row > start_row) /* check start_row and end_row */ - { - handle->debug_print("ssd1306: end_row > start_row.\n"); /* end_row > start_row */ - - return 6; /* return error */ - } - - buf[0] = SSD1306_CMD_VERTICAL_SCROLL_AREA; /* set command */ - buf[1] = start_row; /* set start row */ - buf[2] = end_row; /* set end row */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 3, SSD1306_CMD); /* write command */ -} - -/** - * @brief enable or disable the entire display - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] enable is a bool value - * @return status code - * - 0 success - * - 1 set entire display failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_entire_display(ssd1306_handle_t *handle, ssd1306_entire_display_t enable) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - if (enable != 0) /* if enable */ - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_ENTIRE_DISPLAY_ON, SSD1306_CMD); /* write command */ - } - else - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_ENTIRE_DISPLAY_OFF, SSD1306_CMD); /* write command */ - } -} - -/** - * @brief set the display mode - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] mode is the display mode - * @return status code - * - 0 success - * - 1 set display mode failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_display_mode(ssd1306_handle_t *handle, ssd1306_display_mode_t mode) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - if (mode != 0) /* check mode */ - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_INVERSE_DISPLAY, SSD1306_CMD); /* write command */ - } - else - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_NORMAL_DISPLAY, SSD1306_CMD); /* write command */ - } -} - -/** - * @brief set the multiplex ratio - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] multiplex is the multiplex ratio - * @return status code - * - 0 success - * - 1 set multiplex ratio failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 multiplex is too small - * - 5 multiplex is too large - * @note multiplex must be over 0x0E and less than 0x40 - */ -uint8_t ssd1306_set_multiplex_ratio(ssd1306_handle_t *handle, uint8_t multiplex) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (multiplex < 0x0F) /* check multiplex */ - { - handle->debug_print("ssd1306: multiplex is too small.\n"); /* multiplex is too small */ - - return 4; /* return error */ - } - if (multiplex > 0x3F) /* check multiplex */ - { - handle->debug_print("ssd1306: multiplex is too large.\n"); /* multiplex is too large */ - - return 5; /* return error */ - } - - buf[0] = SSD1306_CMD_MULTIPLEX_RATIO ; /* set command */ - buf[1] = multiplex; /* set multiplex */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief enable or disable the display - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] on_off is a bool value - * @return status code - * - 0 success - * - 1 set display failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_display(ssd1306_handle_t *handle, ssd1306_display_t on_off) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - if (on_off != 0) /* check on off */ - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_ON, SSD1306_CMD); /* write command */ - } - else - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_OFF, SSD1306_CMD); /* write command */ - } -} - -/** - * @brief set the page address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr is the page address - * @return status code - * - 0 success - * - 1 set page address failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 addr is invalid - * @note addr <= 0x07 - */ -uint8_t ssd1306_set_page_address(ssd1306_handle_t *handle, uint8_t addr) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (addr > 0x07) /* check addr */ - { - handle->debug_print("ssd1306: addr is invalid.\n"); /* addr is invalid */ - - return 4; /* return error */ - } - - return a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR|(addr&0x07), SSD1306_CMD); /* write command */ -} - -/** - * @brief set the scan direction - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] dir is the scan direction - * @return status code - * - 0 success - * - 1 set scan direction failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_scan_direction(ssd1306_handle_t *handle, ssd1306_scan_direction_t dir) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - if (dir != 0) /* choose dir */ - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_SCAN_DIRECTION_COMN_1_START, SSD1306_CMD); /* write command */ - } - else - { - return a_ssd1306_write_byte(handle, SSD1306_CMD_SCAN_DIRECTION_COM0_START, SSD1306_CMD); /* write command */ - } -} - -/** - * @brief set the display offset - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] offset is the display offset - * @return status code - * - 0 success - * - 1 set display offset failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 offset is invalid - * @note offset <= 0x3F - */ -uint8_t ssd1306_set_display_offset(ssd1306_handle_t *handle, uint8_t offset) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (offset > 0x3F) /* check offset */ - { - handle->debug_print("ssd1306: offset is invalid.\n"); /* offset is invalid */ - - return 4; /* return error */ - } - - buf[0] = SSD1306_CMD_DISPLAY_OFFSET ; /* set command */ - buf[1] = offset; /* set offset */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the display clock - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] oscillator_frequency is the oscillator frequency - * @param[in] clock_divide is the clock divide - * @return status code - * - 0 success - * - 1 set display clock failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 oscillator frequency is invalid - * - 5 clock divide is invalid - * @note oscillator_frequency <= 0x0F, clock_divide <= 0x0F - */ -uint8_t ssd1306_set_display_clock(ssd1306_handle_t *handle, uint8_t oscillator_frequency, uint8_t clock_divide) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (oscillator_frequency> 0x0F) /* check oscillator_frequency */ - { - handle->debug_print("ssd1306: oscillator frequency is invalid.\n"); /* oscillator frequency is invalid */ - - return 4; /* return error */ - } - if (clock_divide> 0x0F) /* check clock_divide */ - { - handle->debug_print("ssd1306: clock divide is invalid.\n"); /* clock divide is invalid */ - - return 5; /* return error */ - } - - buf[0] = SSD1306_CMD_DISPLAY_CLOCK_DIVIDE ; /* set command */ - buf[1] = (oscillator_frequency<<4) | clock_divide; /* set oscillator frequency and clock divide */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the display zoom in - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] zoom is the display zoom in - * @return status code - * - 0 success - * - 1 set zoom in failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_zoom_in(ssd1306_handle_t *handle, ssd1306_zoom_in_t zoom) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - buf[0] = SSD1306_CMD_SET_ZOOM_IN ; /* set command */ - buf[1] = zoom; /* set zoom */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the pre charge period - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] phase1_period is the phase1 period - * @param[in] phase2_period is the phase2 period - * @return status code - * - 0 success - * - 1 set pre charge period failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 phase1 period is invalid - * - 5 phase2 period is invalid - * @note phase1_period <= 0x0F, phase2_period <= 0x0F - */ -uint8_t ssd1306_set_precharge_period(ssd1306_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - if (phase1_period> 0x0F) /* check phase1 period */ - { - handle->debug_print("ssd1306: phase1 period is invalid.\n"); /* phase1 period is invalid */ - - return 4; /* return error */ - } - if (phase2_period> 0x0F) /* check phase2 period */ - { - handle->debug_print("ssd1306: phase2 period is invalid.\n"); /* phase2 period is invalid */ - - return 5; /* return error */ - } - - buf[0] = SSD1306_CMD_PRE_CHARGE_PERIOD; /* set command */ - buf[1] = (phase2_period << 4) | phase1_period; /* set period */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the hardware com pins - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] conf is the pin conf - * @param[in] remap is the left right remap - * @return status code - * - 0 success - * - 1 set com pins hardware conf failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_com_pins_hardware_conf(ssd1306_handle_t *handle, ssd1306_pin_conf_t conf, ssd1306_left_right_remap_t remap) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - buf[0] = SSD1306_CMD_COM_PINS_CONF; /* set command */ - buf[1] = (uint8_t)((conf<<4) | (remap<<5) |0x02); /* set com pins */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief set the deselect level - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] level is the deselect level - * @return status code - * - 0 success - * - 1 set deselect level failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_deselect_level(ssd1306_handle_t *handle, ssd1306_deselect_level_t level) -{ - uint8_t buf[2]; - - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - buf[0] = SSD1306_CMD_COMH_DESLECT_LEVEL; /* set command */ - buf[1] = (uint8_t)(level << 4); /* set level */ - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ -} - -/** - * @brief write the register command - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] *buf points to a data buffer - * @param[in] len is the data length - * @return status code - * - 0 success - * - 1 write failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_write_cmd(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, len, SSD1306_CMD); /* write command */ -} - -/** - * @brief write the register data - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] *buf points to a data buffer - * @param[in] len is the data length - * @return status code - * - 0 success - * - 1 write failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_write_data(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len) -{ - if (handle == NULL) /* check handle */ - { - return 2; /* return error */ - } - if (handle->inited != 1) /* check handle initialization */ - { - return 3; /* return error */ - } - - return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, len, SSD1306_DATA); /* write data */ -} - -/** - * @brief get chip's information - * @param[out] *info points to an ssd1306 info structure - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_info(ssd1306_info_t *info) -{ - if (info == NULL) /* check handle */ - { - return 2; /* return error */ - } - - memset(info, 0, sizeof(ssd1306_info_t)); /* initialize ssd1306 info structure */ - strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */ - strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */ - strncpy(info->ifname, "IIC SPI", 8); /* copy interface name */ - info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */ - info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */ - info->max_current_ma = MAX_CURRENT; /* set maximum current */ - info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */ - info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */ - info->driver_version = DRIVER_VERSION; /* set driver version */ - - return 0; /* success return 0 */ -} diff --git a/app/src/basic/ssd1306/driver_ssd1306.h b/app/src/basic/ssd1306/driver_ssd1306.h deleted file mode 100644 index fa65147..0000000 --- a/app/src/basic/ssd1306/driver_ssd1306.h +++ /dev/null @@ -1,1105 +0,0 @@ -/** - * Copyright (c) 2015 - present LibDriver All rights reserved - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @file driver_ssd1306.h - * @brief driver ssd1306 header file - * @version 2.0.0 - * @author Shifeng Li - * @date 2021-03-30 - * - *

history

- * - *
Date Version Author Description - *
2021/03/30 2.0 Shifeng Li format the code - *
2020/12/10 1.0 Shifeng Li first upload - *
- */ - -#ifndef DRIVER_SSD1306_H -#define DRIVER_SSD1306_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C"{ -#endif - -/** - * @defgroup ssd1306_driver ssd1306 driver function - * @brief ssd1306 driver modules - * @{ - */ - -/** - * @addtogroup ssd1306_base_driver - * @{ - */ - -/** - * @brief ssd1306 interface enumeration definition - */ -typedef enum -{ - SSD1306_INTERFACE_IIC = 0x00, /**< interface iic */ - SSD1306_INTERFACE_SPI = 0x01, /**< interface spi */ -} ssd1306_interface_t; - -/** - * @brief ssd1306 address pin enumeration definition - */ -typedef enum -{ - SSD1306_ADDR_SA0_0 = 0x78, /**< address pin GND */ - SSD1306_ADDR_SA0_1 = 0x7A, /**< address pin VCC */ -} ssd1306_address_t; - -/** - * @brief ssd1306 memory addressing mode enumeration definition - */ -typedef enum -{ - SSD1306_MEMORY_ADDRESSING_MODE_HORIZONTAL = 0x00, /**< horizontal addressing mode */ - SSD1306_MEMORY_ADDRESSING_MODE_VERTICAL = 0x01, /**< vertical addressing mode */ - SSD1306_MEMORY_ADDRESSING_MODE_PAGE = 0x02, /**< page addressing mode */ -} ssd1306_memory_addressing_mode_t; - -/** - * @brief ssd1306 fade blinking mode enumeration definition - */ -typedef enum -{ - SSD1306_FADE_BLINKING_MODE_DISABLE = 0x00, /**< disable fade blinking mode */ - SSD1306_FADE_BLINKING_MODE_FADE_OUT = 0x02, /**< fade out fade blinking mode */ - SSD1306_FADE_BLINKING_MODE_BLINKING = 0x03, /**< blinking fade blinking mode */ -} ssd1306_fade_blinking_mode_t; - -/** - * @brief ssd1306 scroll frame enumeration definition - */ -typedef enum -{ - SSD1306_SCROLL_FRAME_2 = 0x07, /**< scroll frame 2 */ - SSD1306_SCROLL_FRAME_3 = 0x04, /**< scroll frame 3 */ - SSD1306_SCROLL_FRAME_4 = 0x05, /**< scroll frame 4 */ - SSD1306_SCROLL_FRAME_5 = 0x00, /**< scroll frame 5 */ - SSD1306_SCROLL_FRAME_25 = 0x06, /**< scroll frame 25 */ - SSD1306_SCROLL_FRAME_64 = 0x01, /**< scroll frame 64 */ - SSD1306_SCROLL_FRAME_128 = 0x02, /**< scroll frame 128 */ - SSD1306_SCROLL_FRAME_256 = 0x03, /**< scroll frame 256 */ -} ssd1306_scroll_frame_t; - -/** - * @brief ssd1306 charge pump enumeration definition - */ -typedef enum -{ - SSD1306_CHARGE_PUMP_DISABLE = 0x00, /**< charge pump disable */ - SSD1306_CHARGE_PUMP_ENABLE = 0x01, /**< charge pump enable */ -} ssd1306_charge_pump_t; - -/** - * @brief ssd1306 segment column remap enumeration definition - */ -typedef enum -{ - SSD1306_SEGMENT_COLUMN_ADDRESS_0 = 0x00, /**< segment column remap address 0 */ - SSD1306_SEGMENT_COLUMN_ADDRESS_127 = 0x01, /**< segment column remap address 127 */ -} ssd1306_segment_column_remap_t; - -/** - * @brief ssd1306 entire display enumeration definition - */ -typedef enum -{ - SSD1306_ENTIRE_DISPLAY_OFF = 0x00, /**< entire display off */ - SSD1306_ENTIRE_DISPLAY_ON = 0x01, /**< entire display on */ -} ssd1306_entire_display_t; - -/** - * @brief ssd1306 display mode enumeration definition - */ -typedef enum -{ - SSD1306_DISPLAY_MODE_NORMAL = 0x00, /**< display mode normal */ - SSD1306_DISPLAY_MODE_INVERSE = 0x01, /**< display mode inverse */ -} ssd1306_display_mode_t; - -/** - * @brief ssd1306 display enumeration definition - */ -typedef enum -{ - SSD1306_DISPLAY_OFF = 0x00, /**< close display */ - SSD1306_DISPLAY_ON = 0x01, /**< open display */ -} ssd1306_display_t; - -/** - * @brief ssd1306 scan direction enumeration definition - */ -typedef enum -{ - SSD1306_SCAN_DIRECTION_COM0_START = 0x00, /**< scan direction com 0 start */ - SSD1306_SCAN_DIRECTION_COMN_1_START = 0x01, /**< scan direction com N-1 start */ -} ssd1306_scan_direction_t; - -/** - * @brief ssd1306 zoom in enumeration definition - */ -typedef enum -{ - SSD1306_ZOOM_IN_DISABLE = 0x00, /**< disable zoom in */ - SSD1306_ZOOM_IN_ENABLE = 0x01, /**< enable zoom in */ -} ssd1306_zoom_in_t; - -/** - * @brief ssd1306 pin conf enumeration definition - */ -typedef enum -{ - SSD1306_PIN_CONF_SEQUENTIAL = 0x00, /**< pin conf sequential */ - SSD1306_PIN_CONF_ALTERNATIVE = 0x01, /**< pin conf alternative */ -} ssd1306_pin_conf_t; - -/** - * @brief ssd1306 left right remap enumeration definition - */ -typedef enum -{ - SSD1306_LEFT_RIGHT_REMAP_DISABLE = 0x00, /**< disable left right remap */ - SSD1306_LEFT_RIGHT_REMAP_ENABLE = 0x01, /**< enable left right remap */ -} ssd1306_left_right_remap_t; - -/** - * @brief ssd1306 deselect level enumeration definition - */ -typedef enum -{ - SSD1306_DESELECT_LEVEL_0P65 = 0x00, /**< deselect level 0.65 */ - SSD1306_DESELECT_LEVEL_0P77 = 0x02, /**< deselect level 0.77 */ - SSD1306_DESELECT_LEVEL_0P83 = 0x03, /**< deselect level 0.83 */ -} ssd1306_deselect_level_t; - -/** - * @brief ssd1306 font enumeration definition - */ -typedef enum -{ - SSD1306_FONT_12 = 0x0C, /**< font 12 */ - SSD1306_FONT_16 = 0x10, /**< font 16 */ - SSD1306_FONT_24 = 0x18, /**< font 24 */ -} ssd1306_font_t; - -/** - * @brief ssd1306 handle structure definition - */ -typedef struct ssd1306_handle_s -{ - uint8_t (*iic_init)(void); /**< point to an iic_init function address */ - uint8_t (*iic_deinit)(void); /**< point to an iic_deinit function address */ - uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len); /**< point to an iic_write function address */ - uint8_t (*spi_init)(void); /**< point to a spi_init function address */ - uint8_t (*spi_deinit)(void); /**< point to a spi_deinit function address */ - uint8_t (*spi_write_cmd)(uint8_t *buf, uint16_t len); /**< point to a spi_write_cmd function address */ - uint8_t (*spi_cmd_data_gpio_init)(void); /**< point to a spi_cmd_data_gpio_init function address */ - uint8_t (*spi_cmd_data_gpio_deinit)(void); /**< point to a spi_cmd_data_gpio_deinit function address */ - uint8_t (*spi_cmd_data_gpio_write)(uint8_t value); /**< point to a spi_cmd_data_gpio_write function address */ - uint8_t (*reset_gpio_init)(void); /**< point to a reset_gpio_init function address */ - uint8_t (*reset_gpio_deinit)(void); /**< point to a reset_gpio_deinit function address */ - uint8_t (*reset_gpio_write)(uint8_t value); /**< point to a reset_gpio_write function address */ - void (*debug_print)(const char *const fmt, ...); /**< point to a debug_print function address */ - void (*delay_ms)(uint32_t ms); /**< point to a delay_ms function address */ - uint8_t inited; /**< inited flag */ - uint8_t iic_addr; /**< iic address */ - uint8_t iic_spi; /**< iic spi type */ - uint8_t gram[128][8]; /**< gram buffer */ -} ssd1306_handle_t; - -/** - * @brief ssd1306 information structure definition - */ -typedef struct ssd1306_info_s -{ - char chip_name[32]; /**< chip name */ - char manufacturer_name[32]; /**< manufacturer name */ - char ifname[8]; /**< chip interface name */ - float supply_voltage_min_v; /**< chip min supply voltage */ - float supply_voltage_max_v; /**< chip max supply voltage */ - float max_current_ma; /**< chip max current */ - float temperature_min; /**< chip min operating temperature */ - float temperature_max; /**< chip max operating temperature */ - uint32_t driver_version; /**< driver version */ -} ssd1306_info_t; - -/** - * @} - */ - -/** - * @defgroup ssd1306_link_driver ssd1306 link driver function - * @brief ssd1306 link driver modules - * @ingroup ssd1306_driver - * @{ - */ - -/** - * @brief initialize ssd1306_handle_t structure - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] STRUCTURE is ssd1306_handle_t - * @note none - */ -#define DRIVER_SSD1306_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE)) - -/** - * @brief link iic_init function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to an iic_init function address - * @note none - */ -#define DRIVER_SSD1306_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC - -/** - * @brief link iic_deinit function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to an iic_deinit function address - * @note none - */ -#define DRIVER_SSD1306_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC - -/** - * @brief link iic_write function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to an iic_write function address - * @note none - */ -#define DRIVER_SSD1306_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC - -/** - * @brief link spi_init function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a spi_init function address - * @note none - */ -#define DRIVER_SSD1306_LINK_SPI_INIT(HANDLE, FUC) (HANDLE)->spi_init = FUC - -/** - * @brief link spi_deinit function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a spi_deinit function address - * @note none - */ -#define DRIVER_SSD1306_LINK_SPI_DEINIT(HANDLE, FUC) (HANDLE)->spi_deinit = FUC - -/** - * @brief link spi_write_cmd function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a spi_write_cmd function address - * @note none - */ -#define DRIVER_SSD1306_LINK_SPI_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->spi_write_cmd = FUC - -/** - * @brief link spi_cmd_data_gpio_init function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a spi_cmd_data_gpio_init function address - * @note none - */ -#define DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_INIT(HANDLE, FUC) (HANDLE)->spi_cmd_data_gpio_init = FUC - -/** - * @brief link spi_cmd_data_gpio_deinit function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a spi_cmd_data_gpio_deinit function address - * @note none - */ -#define DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_DEINIT(HANDLE, FUC) (HANDLE)->spi_cmd_data_gpio_deinit = FUC - -/** - * @brief link spi_cmd_data_gpio_write function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a spi_cmd_data_gpio_write function address - * @note none - */ -#define DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_WRITE(HANDLE, FUC) (HANDLE)->spi_cmd_data_gpio_write = FUC - -/** - * @brief link reset_gpio_init function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a reset_gpio_init function address - * @note none - */ -#define DRIVER_SSD1306_LINK_RESET_GPIO_INIT(HANDLE, FUC) (HANDLE)->reset_gpio_init = FUC - -/** - * @brief link reset_gpio_deinit function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a reset_gpio_deinit function address - * @note none - */ -#define DRIVER_SSD1306_LINK_RESET_GPIO_DEINIT(HANDLE, FUC) (HANDLE)->reset_gpio_deinit = FUC - -/** - * @brief link reset_gpio_write function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a reset_gpio_write function address - * @note none - */ -#define DRIVER_SSD1306_LINK_RESET_GPIO_WRITE(HANDLE, FUC) (HANDLE)->reset_gpio_write = FUC - -/** - * @brief link delay_ms function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a delay_ms function address - * @note none - */ -#define DRIVER_SSD1306_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC - -/** - * @brief link debug_print function - * @param[in] HANDLE points to an ssd1306 handle structure - * @param[in] FUC points to a debug_print function address - * @note none - */ -#define DRIVER_SSD1306_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC - -/** - * @} - */ - -/** - * @defgroup ssd1306_base_driver ssd1306 base driver function - * @brief ssd1306 base driver modules - * @ingroup ssd1306_driver - * @{ - */ - -/** - * @brief get chip's information - * @param[out] *info points to an ssd1306 info structure - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_info(ssd1306_info_t *info); - -/** - * @brief set the chip interface - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] interface is the chip interface - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_set_interface(ssd1306_handle_t *handle, ssd1306_interface_t ifhandler); - -/** - * @brief get the chip interface - * @param[in] *handle points to an ssd1306 handle structure - * @param[out] *interface points to a chip interface buffer - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_get_interface(ssd1306_handle_t *handle, ssd1306_interface_t *ifhandler); - -/** - * @brief set the chip iic address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr_pin is the iic address - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_set_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t addr_pin); - -/** - * @brief get the chip iic address - * @param[in] *handle points to an ssd1306 handle structure - * @param[out] *addr_pin points to an iic address buffer - * @return status code - * - 0 success - * - 2 handle is NULL - * @note none - */ -uint8_t ssd1306_get_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t *addr_pin); - -/** - * @brief initialize the chip - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 iic or spi initialization failed - * - 2 handle is NULL - * - 3 linked functions is NULL - * - 4 reset failed - * - 5 command && data init failed - * - 6 interface param is invalid - * @note none - */ -uint8_t ssd1306_init(ssd1306_handle_t *handle); - -/** - * @brief close the chip - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 iic or spi deinit failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 power down failed - * - 5 reset gpio deinit failed - * - 6 command && data deinit failed - * - 7 interface param is invalid - * @note none - */ -uint8_t ssd1306_deinit(ssd1306_handle_t *handle); - -/** - * @brief clear the screen - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 clear failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_clear(ssd1306_handle_t *handle); - -/** - * @brief update the gram data - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 gram update failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_gram_update(ssd1306_handle_t *handle); - -/** - * @brief write a point - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] data is the write data - * @return status code - * - 0 success - * - 1 write point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data); - -/** - * @brief read a point - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[out] *data points to a data buffer - * @return status code - * - 0 success - * - 1 read point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data); - -/** - * @brief write a point in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] data is the write data - * @return status code - * - 0 success - * - 1 gram write point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_gram_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data); - -/** - * @brief read a point from the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[out] *data points to a data buffer - * @return status code - * - 0 success - * - 1 gram read point failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_gram_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data); - -/** - * @brief draw a string in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] *str points to a write string address - * @param[in] len is the length of the string - * @param[in] color is the display color - * @param[in] font is the display font size - * @return status code - * - 0 success - * - 1 gram write string failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 x or y is invalid - * @note none - */ -uint8_t ssd1306_gram_write_string(ssd1306_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font); - -/** - * @brief fill a rectangle in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] color is the display color - * @return status code - * - 0 success - * - 1 gram fill rect failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 left or top is invalid - * - 5 right or bottom is invalid - * - 6 left > right or top > bottom - * @note none - */ -uint8_t ssd1306_gram_fill_rect(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color); - -/** - * @brief draw a picture in the gram - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] *img points to an image buffer - * @return status code - * - 0 success - * - 1 gram draw picture failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 left or top is invalid - * - 5 right or bottom is invalid - * - 6 left > right or top > bottom - * @note none - */ -uint8_t ssd1306_gram_draw_picture(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img); - -/** - * @brief set the low column start address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr is the low column start address - * @return status code - * - 0 success - * - 1 set low column start address failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 addr is invalid - * @note addr <= 0xF - */ -uint8_t ssd1306_set_low_column_start_address(ssd1306_handle_t *handle, uint8_t addr); - -/** - * @brief set the high column start address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr is the high column start address - * @return status code - * - 0 success - * - 1 set high column start address failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 addr is invalid - * @note addr <= 0xF - */ -uint8_t ssd1306_set_high_column_start_address(ssd1306_handle_t *handle, uint8_t addr); - -/** - * @brief set the memory addressing mode - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] mode is the memory addressing mode - * @return status code - * - 0 success - * - 1 set memory addressing mode failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_memory_addressing_mode(ssd1306_handle_t *handle, ssd1306_memory_addressing_mode_t mode); - -/** - * @brief set the column address range - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_addr is the column start address - * @param[in] end_addr is the column end address - * @return status code - * - 0 success - * - 1 set column address range failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start addr is invalid - * - 5 end addr is invalid - * @note start addr and end addr can't be over 0x7F - */ -uint8_t ssd1306_set_column_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr); - -/** - * @brief set the page address range - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_addr is the page start address - * @param[in] end_addr is the page end address - * @return status code - * - 0 success - * - 1 set page address range failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start addr is invalid - * - 5 end addr is invalid - * @note start addr and end addr can't be over 0x07 - */ -uint8_t ssd1306_set_page_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr); - -/** - * @brief set the fade blinking mode - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] mode is the fade blinking mode - * @param[in] frames is the fade or blinking frames - * @return status code - * - 0 success - * - 1 set fade blinking mode failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 frames is invalid - * @note frames max is 0x0F and div is (frames + 1) * 8 - */ -uint8_t ssd1306_set_fade_blinking_mode(ssd1306_handle_t *handle, ssd1306_fade_blinking_mode_t mode, uint8_t frames); - -/** - * @brief set the right horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set right horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start page addr is invalid - * - 5 end page addr is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07 - */ -uint8_t ssd1306_set_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - ssd1306_scroll_frame_t frames); - -/** - * @brief set the left horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set left horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_page_addr is invalid - * - 5 end_page_addr is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07 - */ -uint8_t ssd1306_set_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - ssd1306_scroll_frame_t frames); - -/** - * @brief set the vertical right horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] rows is the row address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set vertical right horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_page_addr is invalid - * - 5 end_page_addr is invalid - * - 6 rows is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F - */ -uint8_t ssd1306_set_vertical_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - uint8_t rows, ssd1306_scroll_frame_t frames); - -/** - * @brief set the vertical left horizontal scroll - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_page_addr is the start page address - * @param[in] end_page_addr is the end page address - * @param[in] rows is the row address - * @param[in] frames is the scroll frames - * @return status code - * - 0 success - * - 1 set vertical left horizontal scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_page_addr is invalid - * - 5 end_page_addr is invalid - * - 6 rows is invalid - * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F - */ -uint8_t ssd1306_set_vertical_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, - uint8_t rows, ssd1306_scroll_frame_t frames); - -/** - * @brief deactivate the scroll - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 deactivate scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_deactivate_scroll(ssd1306_handle_t *handle); - -/** - * @brief activate the scroll - * @param[in] *handle points to an ssd1306 handle structure - * @return status code - * - 0 success - * - 1 activate scroll failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_activate_scroll(ssd1306_handle_t *handle); - -/** - * @brief set the display start line - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] l is the start line - * @return status code - * - 0 success - * - 1 set display start line failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 line is invalid - * @note line <= 0x3F - */ -uint8_t ssd1306_set_display_start_line(ssd1306_handle_t *handle, uint8_t l); - -/** - * @brief set the display contrast - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] contrast is the display contrast - * @return status code - * - 0 success - * - 1 set contrast failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_contrast(ssd1306_handle_t *handle, uint8_t contrast); - -/** - * @brief enable or disable the charge pump - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] enable is a bool value - * @return status code - * - 0 success - * - 1 set charge pump failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_charge_pump(ssd1306_handle_t *handle, ssd1306_charge_pump_t enable); - -/** - * @brief set the segment remap - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] remap is the segment remap param - * @return status code - * - 0 success - * - 1 set segment remap failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_segment_remap(ssd1306_handle_t *handle, ssd1306_segment_column_remap_t remap); - -/** - * @brief set the vertical scroll area - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] start_row is the start row - * @param[in] end_row is the end row - * @return status code - * - 0 success - * - 1 set vertical scroll area failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 start_row is invalid - * - 5 end_row is invalid - * - 6 end_row > start_row - * @note start_row <= 0x3F, end_row <= 0x7F, start_row >= end_row - */ -uint8_t ssd1306_set_vertical_scroll_area(ssd1306_handle_t *handle, uint8_t start_row, uint8_t end_row); - -/** - * @brief enable or disable the entire display - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] enable is a bool value - * @return status code - * - 0 success - * - 1 set entire display failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_entire_display(ssd1306_handle_t *handle, ssd1306_entire_display_t enable); - -/** - * @brief set the display mode - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] mode is the display mode - * @return status code - * - 0 success - * - 1 set display mode failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_display_mode(ssd1306_handle_t *handle, ssd1306_display_mode_t mode); - -/** - * @brief set the multiplex ratio - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] multiplex is the multiplex ratio - * @return status code - * - 0 success - * - 1 set multiplex ratio failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 multiplex is too small - * - 5 multiplex is too large - * @note multiplex must be over 0x0E and less than 0x40 - */ -uint8_t ssd1306_set_multiplex_ratio(ssd1306_handle_t *handle, uint8_t multiplex); - -/** - * @brief enable or disable the display - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] on_off is a bool value - * @return status code - * - 0 success - * - 1 set display failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_display(ssd1306_handle_t *handle, ssd1306_display_t on_off); - -/** - * @brief set the page address - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] addr is the page address - * @return status code - * - 0 success - * - 1 set page address failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 addr is invalid - * @note addr <= 0x07 - */ -uint8_t ssd1306_set_page_address(ssd1306_handle_t *handle, uint8_t addr); - -/** - * @brief set the scan direction - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] dir is the scan direction - * @return status code - * - 0 success - * - 1 set scan direction failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_scan_direction(ssd1306_handle_t *handle, ssd1306_scan_direction_t dir); - -/** - * @brief set the display offset - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] offset is the display offset - * @return status code - * - 0 success - * - 1 set display offset failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 offset is invalid - * @note offset <= 0x3F - */ -uint8_t ssd1306_set_display_offset(ssd1306_handle_t *handle, uint8_t offset); - -/** - * @brief set the display clock - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] oscillator_frequency is the oscillator frequency - * @param[in] clock_divide is the clock divide - * @return status code - * - 0 success - * - 1 set display clock failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 oscillator frequency is invalid - * - 5 clock divide is invalid - * @note oscillator_frequency <= 0x0F, clock_divide <= 0x0F - */ -uint8_t ssd1306_set_display_clock(ssd1306_handle_t *handle, uint8_t oscillator_frequency, uint8_t clock_divide); - -/** - * @brief set the display zoom in - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] zoom is the display zoom in - * @return status code - * - 0 success - * - 1 set zoom in failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_zoom_in(ssd1306_handle_t *handle, ssd1306_zoom_in_t zoom); - -/** - * @brief set the pre charge period - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] phase1_period is the phase1 period - * @param[in] phase2_period is the phase2 period - * @return status code - * - 0 success - * - 1 set pre charge period failed - * - 2 handle is NULL - * - 3 handle is not initialized - * - 4 phase1 period is invalid - * - 5 phase2 period is invalid - * @note phase1_period <= 0x0F, phase2_period <= 0x0F - */ -uint8_t ssd1306_set_precharge_period(ssd1306_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period); - -/** - * @brief set the hardware com pins - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] conf is the pin conf - * @param[in] remap is the left right remap - * @return status code - * - 0 success - * - 1 set com pins hardware conf failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_com_pins_hardware_conf(ssd1306_handle_t *handle, ssd1306_pin_conf_t conf, ssd1306_left_right_remap_t remap); - -/** - * @brief set the deselect level - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] level is the deselect level - * @return status code - * - 0 success - * - 1 set deselect level failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_set_deselect_level(ssd1306_handle_t *handle, ssd1306_deselect_level_t level); - -/** - * @} - */ - -/** - * @defgroup ssd1306_extend_driver ssd1306 extend driver function - * @brief ssd1306 extend driver modules - * @ingroup ssd1306_driver - * @{ - */ - -/** - * @brief write the register command - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] *buf points to a data buffer - * @param[in] len is the data length - * @return status code - * - 0 success - * - 1 write failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_write_cmd(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len); - -/** - * @brief write the register data - * @param[in] *handle points to an ssd1306 handle structure - * @param[in] *buf points to a data buffer - * @param[in] len is the data length - * @return status code - * - 0 success - * - 1 write failed - * - 2 handle is NULL - * - 3 handle is not initialized - * @note none - */ -uint8_t ssd1306_write_data(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len); - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/app/src/basic/ssd1306/driver_ssd1306_basic.c b/app/src/basic/ssd1306/driver_ssd1306_basic.c deleted file mode 100644 index ff1fd58..0000000 --- a/app/src/basic/ssd1306/driver_ssd1306_basic.c +++ /dev/null @@ -1,792 +0,0 @@ -/** - * Copyright (c) 2015 - present LibDriver All rights reserved - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @file driver_ssd1306_basic.c - * @brief driver ssd1306 basic source file - * @version 2.0.0 - * @author Shifeng Li - * @date 2021-03-30 - * - *

history

- * - *
Date Version Author Description - *
2021/03/30 2.0 Shifeng Li format the code - *
2020/12/10 1.0 Shifeng Li first upload - *
- */ - -#include "driver_ssd1306_basic.h" - -#include - -static ssd1306_handle_t gs_handle; /**< ssd1306 handle */ - -/** - * @brief basic example init - * @param[in] interface is the interface type - * @param[in] addr is the iic device address - * @return status code - * - 0 success - * - 1 init failed - * @note none - */ -uint8_t ssd1306_basic_init(ssd1306_interface_t ifhandler, ssd1306_address_t addr) { - uint8_t res; - - /* link functions */ - DRIVER_SSD1306_LINK_INIT(&gs_handle, ssd1306_handle_t); - DRIVER_SSD1306_LINK_IIC_INIT(&gs_handle, ssd1306_interface_iic_init); - DRIVER_SSD1306_LINK_IIC_DEINIT(&gs_handle, ssd1306_interface_iic_deinit); - DRIVER_SSD1306_LINK_IIC_WRITE(&gs_handle, ssd1306_interface_iic_write); - DRIVER_SSD1306_LINK_SPI_INIT(&gs_handle, ssd1306_interface_spi_init); - DRIVER_SSD1306_LINK_SPI_DEINIT(&gs_handle, ssd1306_interface_spi_deinit); - DRIVER_SSD1306_LINK_SPI_WRITE_COMMAND(&gs_handle, ssd1306_interface_spi_write_cmd); - DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_INIT(&gs_handle, ssd1306_interface_spi_cmd_data_gpio_init); - DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_DEINIT(&gs_handle, ssd1306_interface_spi_cmd_data_gpio_deinit); - DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_WRITE(&gs_handle, ssd1306_interface_spi_cmd_data_gpio_write); - DRIVER_SSD1306_LINK_RESET_GPIO_INIT(&gs_handle, ssd1306_interface_reset_gpio_init); - DRIVER_SSD1306_LINK_RESET_GPIO_DEINIT(&gs_handle, ssd1306_interface_reset_gpio_deinit); - DRIVER_SSD1306_LINK_RESET_GPIO_WRITE(&gs_handle, ssd1306_interface_reset_gpio_write); - DRIVER_SSD1306_LINK_DELAY_MS(&gs_handle, ssd1306_interface_delay_ms); - DRIVER_SSD1306_LINK_DEBUG_PRINT(&gs_handle, ssd1306_interface_debug_print); - - /* set interface */ - res = ssd1306_set_interface(&gs_handle, ifhandler); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set interface failed.\n"); - - return 1; - } - - /* set addr pin */ - res = ssd1306_set_addr_pin(&gs_handle, addr); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set addr failed.\n"); - - return 1; - } - - /* ssd1306 init */ - res = ssd1306_init(&gs_handle); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: init failed.\n"); - - return 1; - } - - /* close display */ - res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_OFF); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set display failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set column address range */ - res = ssd1306_set_column_address_range(&gs_handle, SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_START, SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_END); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set column address range failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set page address range */ - res = ssd1306_set_page_address_range(&gs_handle, SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_START, SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_END); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set page address range failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set low column start address */ - res = ssd1306_set_low_column_start_address(&gs_handle, SSD1306_BASIC_DEFAULT_LOW_COLUMN_START_ADDRESS); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set low column start address failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set high column start address */ - res = ssd1306_set_high_column_start_address(&gs_handle, SSD1306_BASIC_DEFAULT_HIGH_COLUMN_START_ADDRESS); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set high column start address failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set display start line */ - res = ssd1306_set_display_start_line(&gs_handle, SSD1306_BASIC_DEFAULT_DISPLAY_START_LINE); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set display start line failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set fade blinking mode */ - res = ssd1306_set_fade_blinking_mode(&gs_handle, SSD1306_BASIC_DEFAULT_FADE_BLINKING_MODE, SSD1306_BASIC_DEFAULT_FADE_FRAMES); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set fade blinking failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* deactivate scroll */ - res = ssd1306_deactivate_scroll(&gs_handle); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set deactivate scroll failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set zoom in */ - res = ssd1306_set_zoom_in(&gs_handle, SSD1306_BASIC_DEFAULT_ZOOM_IN); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set set zoom in failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set contrast */ - res = ssd1306_set_contrast(&gs_handle, SSD1306_BASIC_DEFAULT_CONTRAST); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set contrast failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set segment remap */ - res = ssd1306_set_segment_remap(&gs_handle, SSD1306_BASIC_DEFAULT_SEGMENT); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set segment remap failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set scan direction */ - res = ssd1306_set_scan_direction(&gs_handle, SSD1306_BASIC_DEFAULT_SCAN_DIRECTION); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set scan direction failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set display mode */ - res = ssd1306_set_display_mode(&gs_handle, SSD1306_BASIC_DEFAULT_DISPLAY_MODE); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set display mode failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set multiplex ratio */ - res = ssd1306_set_multiplex_ratio(&gs_handle, SSD1306_BASIC_DEFAULT_MULTIPLEX_RATIO); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set multiplex ratio failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set display offset */ - res = ssd1306_set_display_offset(&gs_handle, SSD1306_BASIC_DEFAULT_DISPLAY_OFFSET); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set display offset failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set display clock */ - res = ssd1306_set_display_clock(&gs_handle, SSD1306_BASIC_DEFAULT_OSCILLATOR_FREQUENCY, SSD1306_BASIC_DEFAULT_CLOCK_DIVIDE); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set display clock failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set pre charge period */ - res = ssd1306_set_precharge_period(&gs_handle, SSD1306_BASIC_DEFAULT_PHASE1_PERIOD, SSD1306_BASIC_DEFAULT_PHASE2_PERIOD); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set pre charge period failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set hardware pins conf */ - res = ssd1306_set_com_pins_hardware_conf(&gs_handle, SSD1306_BASIC_DEFAULT_PIN_CONF, SSD1306_BASIC_DEFAULT_LEFT_RIGHT_REMAP); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set com pins hardware conf failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set deselect level 0.77 */ - res = ssd1306_set_deselect_level(&gs_handle, SSD1306_BASIC_DEFAULT_DESELECT_LEVEL); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set deselect level failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* set page memory addressing mode */ - res = ssd1306_set_memory_addressing_mode(&gs_handle, SSD1306_MEMORY_ADDRESSING_MODE_PAGE); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set memory addressing level failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* enable charge pump */ - res = ssd1306_set_charge_pump(&gs_handle, SSD1306_CHARGE_PUMP_ENABLE); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set charge pump failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* entire display off */ - res = ssd1306_set_entire_display(&gs_handle, SSD1306_ENTIRE_DISPLAY_OFF); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set entire display failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* enable display */ - res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_ON); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: set display failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - /* clear screen */ - res = ssd1306_clear(&gs_handle); - if (res != 0) { - ssd1306_interface_debug_print("ssd1306: clear failed.\n"); - (void)ssd1306_deinit(&gs_handle); - - return 1; - } - - return 0; -} - -/** - * @brief basic example deinit - * @return status code - * - 0 success - * - 1 deinit failed - * @note none - */ -uint8_t ssd1306_basic_deinit(void) { - /* deinit ssd1306 */ - if (ssd1306_deinit(&gs_handle) != 0) { - return 1; - } else { - return 0; - } -} - -/** - * @brief basic example display on - * @return status code - * - 0 success - * - 1 display on failed - * @note none - */ -uint8_t ssd1306_basic_display_on(void) { - uint8_t res; - - /* display on */ - res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_ON); - if (res != 0) { - return 1; - } else { - return 0; - } -} - -/** - * @brief basic example display off - * @return status code - * - 0 success - * - 1 display off failed - * @note none - */ -uint8_t ssd1306_basic_display_off(void) { - uint8_t res; - - /* display off */ - res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_OFF); - if (res != 0) { - return 1; - } else { - return 0; - } -} - -/** - * @brief basic example clear - * @return status code - * - 0 success - * - 1 clear failed - * @note none - */ -uint8_t ssd1306_basic_clear(void) { - /* clear */ - if (ssd1306_clear(&gs_handle) != 0) { - return 1; - } else { - return 0; - } -} - -/** - * @brief basic example write a point - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] data is the written data - * @return status code - * - 0 success - * - 1 write point failed - * @note none - */ -uint8_t ssd1306_basic_write_point(uint8_t x, uint8_t y, uint8_t data) { - uint8_t res; - - /* write point */ - res = ssd1306_write_point(&gs_handle, x, y, data); - if (res != 0) { - return 1; - } - - return 0; -} -ssd1306_handle_t *ssd1306_handler() { return &gs_handle; } - -/** - * @brief basic example read a point - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[out] *data points to a data buffer - * @return status code - * - 0 success - * - 1 read point failed - * @note none - */ -uint8_t ssd1306_basic_read_point(uint8_t x, uint8_t y, uint8_t *data) { - uint8_t res; - - /* read point in gram */ - res = ssd1306_read_point(&gs_handle, x, y, data); - if (res != 0) { - return 1; - } - - return 0; -} - -/** - * @brief basic example draw a string - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] *str points to a written string address - * @param[in] len is the length of the string - * @param[in] color is the display color - * @param[in] font is the display font size - * @return status code - * - 0 success - * - 1 write string failed - * @note none - */ -uint8_t ssd1306_basic_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font) { - uint8_t res; - - /* write string in gram */ - res = ssd1306_gram_write_string(&gs_handle, x, y, str, len, color, font); - if (res != 0) { - return 1; - } - - /* update gram */ - if (ssd1306_gram_update(&gs_handle) != 0) { - return 1; - } else { - return 0; - } -} - -/** - * @brief basic example fill a rectangle - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] color is the display color - * @return status code - * - 0 success - * - 1 fill rect failed - * @note none - */ -uint8_t ssd1306_basic_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color) { - uint8_t res; - - /* fill rect in gram */ - res = ssd1306_gram_fill_rect(&gs_handle, left, top, right, bottom, color); - if (res != 0) { - return 1; - } - - /* update gram */ - if (ssd1306_gram_update(&gs_handle) != 0) { - return 1; - } else { - return 0; - } -} - -/** - * @brief basic example draw a picture - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] *img points to a image buffer - * @return status code - * - 0 success - * - 1 draw picture failed - * @note none - */ -uint8_t ssd1306_basic_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img) { - uint8_t res; - - /* draw picture in gram */ - res = ssd1306_gram_draw_picture(&gs_handle, left, top, right, bottom, img); - if (res != 0) { - return 1; - } - - /* update gram */ - if (ssd1306_gram_update(&gs_handle) != 0) { - return 1; - } else { - return 0; - } -} -uint8_t ssd1306_basic_draw_screen(const char *img) { - for (size_t i = 0; i < 1024; i++) { - gs_handle.gram[i % 128][i / 128] = img[i]; - } - return 0; -} -uint8_t ssd1306_basic_clear_gram(void) { - memset(gs_handle.gram, 0, sizeof(gs_handle.gram)); - return 0; -} - -uint8_t ssd1306_basic_gram_update() { return ssd1306_gram_update(&gs_handle); } -#include "znordic.h" -uint8_t ssd1306_basic_draw_one_chr(uint8_t xs, uint8_t ys, const char *str, FontLibrary_t *frontlib) { - const uint8_t *frontbuf = NULL; - FontLibrary_findchar(frontlib, str, &frontbuf); - if (!frontbuf) return 1; - - // ssd1306_gram_write_point - for (uint32_t xoff = 0; xoff < frontlib->widthPixel; xoff++) { - for (uint32_t yoff = 0; yoff < frontlib->heightPixel; yoff++) { - bool pixval = 0; - /** - * |||||| - * VVVVVV - * |||||| - * VVVVVV - * - * x = 3; y = 9; - * byteoff = x + y / frontWidthPixel * frontWidthPixel - * bitoff = y % 8 - */ - - uint8_t byteoff = xoff + yoff / 8 * frontlib->widthPixel; - uint8_t bitoff = yoff % 8; - pixval = (frontbuf[byteoff] >> bitoff) & 0x01; - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, pixval); - } - } - return 0; -} - -uint8_t ssd1306_basic_draw_str(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, const char *str, FontLibrary_t *frontlib) { - uint8_t x = xs; - uint8_t y = ys; - StrIterator_t iterator; - *xchange = 0; - *ychange = 0; - str_iterator_start(&iterator, frontlib->fontCode, str); - char *nowchr = NULL; - while (true) { - str_iterator_next(&iterator, &nowchr); - if (!nowchr) { - break; - } - ssd1306_basic_draw_one_chr(x, y, nowchr, frontlib); - x += (uint8_t)(frontlib->widthPixel); /* x + font/2 */ - *xchange = *xchange + frontlib->widthPixel; - } - - *ychange = frontlib->heightPixel; - - return 0; -} - -uint8_t ssd1306_basic_draw_battery_level(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, int level, int width, int high) { - /** - * @brief - * ***** - * ******** - * * * - * * **** * - * * **** * - * ******** - */ - - if (level >= 100) { - level = 100; - } - - uint8_t xoff = 0; - uint8_t yoff = 0; - - int batteryHeaderHigh = 2; - int batteryHeaderWidth = 7; - int batteryBodyHigh = 20; - int batteryBodyWidth = 12; - int border_width = 1; - int blank_width = 1; - - float width_mult = width * 1.0 / batteryBodyWidth; - float high_mult = high * 1.0 / (batteryBodyHigh + batteryHeaderHigh); - - batteryHeaderHigh = batteryHeaderHigh * high_mult; - batteryHeaderWidth = batteryHeaderWidth * width_mult; - batteryBodyHigh = batteryBodyHigh * high_mult; - batteryBodyWidth = batteryBodyWidth * width_mult; - border_width = 1; - blank_width = 1; - - int batteryInterBodyWidth = batteryBodyWidth - blank_width * 2 - border_width * 2; - int batteryInterBodyHigh = batteryBodyHigh - border_width * 2 - blank_width * 2; - /** - * @brief »­Í·?? - */ - for (int yoff = 0; yoff < batteryHeaderHigh; yoff++) { - for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { - uint16_t battery_start = (batteryBodyWidth - batteryHeaderWidth) / 2; - uint16_t battery_end = battery_start + batteryHeaderWidth; - if (xoff >= battery_start && xoff <= battery_end) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); - } - } - } - ys += batteryHeaderHigh; - - /** - * @brief »­ÉϱßÑØ - */ - for (int yoff = 0; yoff < border_width; yoff++) { - for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } - } - ys += border_width; - /** - * @brief »­ÉÏÁô°× - */ - for (int yoff = 0; yoff < blank_width; yoff++) { - for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { - // uint16_t start = blank_width; - if (xoff < border_width) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else if (xoff >= (batteryInterBodyWidth + border_width * 1 + blank_width * 2)) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); - } - } - } - ys += blank_width; - - /** - * @brief »­Éí?? - */ - for (int yoff = 0; yoff < batteryInterBodyHigh; yoff++) { - for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { - // uint16_t start = blank_width; - if (xoff < border_width) { - // right border - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else if (xoff >= border_width + blank_width && xoff < batteryInterBodyWidth + border_width + blank_width) { - // body - // ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - - uint16_t batterylevel = (100 - level) / 100.0 * batteryInterBodyHigh; - if (yoff >= batterylevel) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); - } - - } else if (xoff >= batteryInterBodyWidth + border_width * 1 + blank_width * 2) { - // left border - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); - } - } - } - ys += batteryInterBodyHigh; - - /** - * @brief »­ÉÏÁô°× - */ - for (int yoff = 0; yoff < blank_width; yoff++) { - for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { - // uint16_t start = blank_width; - if (xoff < border_width) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else if (xoff >= (batteryInterBodyWidth + border_width * 1 + blank_width * 2)) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } else { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); - } - } - } - ys += blank_width; - /** - * @brief »­ÉϱßÑØ - */ - for (int yoff = 0; yoff < border_width; yoff++) { - for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { - ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); - } - } - ys += border_width; - - *xchange = batteryBodyWidth; - *ychange = batteryBodyHigh + batteryHeaderHigh; -} - -uint8_t ssd1306_basic_draw_progress(uint8_t xs, uint8_t ys, uint16_t width, uint16_t high, uint16_t markpos, uint16_t progress) { - /** - * @brief - * - * [==================> ] - */ - - /** - * @brief - */ - for (uint16_t i = 0; i < width; i++) { - ssd1306_gram_write_point(&gs_handle, xs + i, ys, 1); - } - ys += 1; - - /** - * @brief - */ - uint16_t progress_width = width * progress / 100.0; - uint16_t markpos_off = width * markpos / 100.0; - for (uint16_t yoff = 0; yoff < high - 2; yoff++) { - for (uint16_t i = 0; i < width; i++) { - if (i == width - 1) { - ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 1); - } else if (i >= markpos_off && i < markpos_off + 1) { - ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 1); - } else { - if (i < progress_width || i == 0) { - ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 1); - } else { - ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 0); - } - } - } - } - - ys += high - 2; - /** - * @brief - */ - for (uint16_t i = 0; i < width; i++) { - ssd1306_gram_write_point(&gs_handle, xs + i, ys, 1); - } - return 0; -} - -uint8_t ssd1306_basic_draw_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) { - int dx = abs(x2 - x1); - int dy = abs(y2 - y1); - int sx = (x1 < x2) ? 1 : -1; - int sy = (y1 < y2) ? 1 : -1; - int err = dx - dy; - - while (1) { - ssd1306_gram_write_point(&gs_handle, x1, y1, 1); - if (x1 == x2 && y1 == y2) { - break; - } - - int e2 = 2 * err; - if (e2 > -dy) { - err -= dy; - x1 += sx; - } - - if (e2 < dx) { - err += dx; - y1 += sy; - } - } -} diff --git a/app/src/basic/ssd1306/driver_ssd1306_basic.h b/app/src/basic/ssd1306/driver_ssd1306_basic.h deleted file mode 100644 index 2e1d706..0000000 --- a/app/src/basic/ssd1306/driver_ssd1306_basic.h +++ /dev/null @@ -1,226 +0,0 @@ -/** - * Copyright (c) 2015 - present LibDriver All rights reserved - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @file driver_ssd1306_basic.h - * @brief driver ssd1306 basic header file - * @version 2.0.0 - * @author Shifeng Li - * @date 2021-03-30 - * - *

history

- * - *
Date Version Author Description - *
2021/03/30 2.0 Shifeng Li format the code - *
2020/12/10 1.0 Shifeng Li first upload - *
- */ - -#ifndef DRIVER_SSD1306_BASIC_H -#define DRIVER_SSD1306_BASIC_H - -#include "driver_ssd1306_interface.h" -#include "fontlib.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup ssd1306_example_driver ssd1306 example driver function - * @brief ssd1306 example driver modules - * @ingroup ssd1306_driver - * @{ - */ - -/** - * @brief ssd1306 basic example default definition - */ -#define SSD1306_BASIC_DEFAULT_DESELECT_LEVEL SSD1306_DESELECT_LEVEL_0P77 /**< set deselect level 0.77 */ -#define SSD1306_BASIC_DEFAULT_LEFT_RIGHT_REMAP SSD1306_LEFT_RIGHT_REMAP_DISABLE /**< disable remap */ -#define SSD1306_BASIC_DEFAULT_PIN_CONF SSD1306_PIN_CONF_ALTERNATIVE /**< set alternative */ -#define SSD1306_BASIC_DEFAULT_PHASE1_PERIOD 0x01 /**< set phase 1 */ -#define SSD1306_BASIC_DEFAULT_PHASE2_PERIOD 0x0F /**< set phase F */ -#define SSD1306_BASIC_DEFAULT_OSCILLATOR_FREQUENCY 0x08 /**< set 8 */ -#define SSD1306_BASIC_DEFAULT_CLOCK_DIVIDE 0x00 /**< set clock div 0 */ -#define SSD1306_BASIC_DEFAULT_DISPLAY_OFFSET 0x00 /**< set display offset */ -#define SSD1306_BASIC_DEFAULT_MULTIPLEX_RATIO 0x3F /**< set ratio */ -#define SSD1306_BASIC_DEFAULT_DISPLAY_MODE SSD1306_DISPLAY_MODE_NORMAL /**< set normal mode */ -#define SSD1306_BASIC_DEFAULT_SCAN_DIRECTION SSD1306_SCAN_DIRECTION_COM0_START /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ -// #define SSD1306_BASIC_DEFAULT_SCAN_DIRECTION SSD1306_SCAN_DIRECTION_COM0_START /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ -#define SSD1306_BASIC_DEFAULT_SEGMENT SSD1306_SEGMENT_COLUMN_ADDRESS_127 /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ -// #define SSD1306_BASIC_DEFAULT_SEGMENT SSD1306_SEGMENT_COLUMN_ADDRESS_127 /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ -// #define SSD1306_BASIC_DEFAULT_CONTRAST 0xCF /**< set contrast CF */ -#define SSD1306_BASIC_DEFAULT_CONTRAST 0x05 /**< set contrast CF */ -#define SSD1306_BASIC_DEFAULT_ZOOM_IN SSD1306_ZOOM_IN_DISABLE /**< disable zoom in */ -#define SSD1306_BASIC_DEFAULT_FADE_BLINKING_MODE SSD1306_FADE_BLINKING_MODE_DISABLE /**< disable fade */ -#define SSD1306_BASIC_DEFAULT_FADE_FRAMES 0x00 /**< set frame 0 */ -#define SSD1306_BASIC_DEFAULT_DISPLAY_START_LINE 0x00 /**< set start line 0 */ -#define SSD1306_BASIC_DEFAULT_HIGH_COLUMN_START_ADDRESS 0x00 /**< set high start 0 */ -#define SSD1306_BASIC_DEFAULT_LOW_COLUMN_START_ADDRESS 0x00 /**< set low start 0 */ -#define SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_START 0x00 /**< set page range start */ -#define SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_END 0x07 /**< set page range end */ -#define SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_START 0x00 /**< set range start */ -#define SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_END 0x7F /**< set range end */ - -/** - * @brief basic example init - * @param[in] interface is the interface type - * @param[in] addr is the iic device address - * @return status code - * - 0 success - * - 1 init failed - * @note none - */ -uint8_t ssd1306_basic_init(ssd1306_interface_t ifhandler, ssd1306_address_t addr); - -/** - * @brief basic example deinit - * @return status code - * - 0 success - * - 1 deinit failed - * @note none - */ -uint8_t ssd1306_basic_deinit(void); - -/** - * @brief basic example display on - * @return status code - * - 0 success - * - 1 display on failed - * @note none - */ -uint8_t ssd1306_basic_display_on(void); - -/** - * @brief basic example display off - * @return status code - * - 0 success - * - 1 display off failed - * @note none - */ -uint8_t ssd1306_basic_display_off(void); - -/** - * @brief basic example clear - * @return status code - * - 0 success - * - 1 clear failed - * @note none - */ -uint8_t ssd1306_basic_clear(void); - -/** - * @brief basic example write a point - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] data is the written data - * @return status code - * - 0 success - * - 1 write point failed - * @note none - */ -uint8_t ssd1306_basic_write_point(uint8_t x, uint8_t y, uint8_t data); - -/** - * @brief basic example read a point - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[out] *data points to a data buffer - * @return status code - * - 0 success - * - 1 read point failed - * @note none - */ -uint8_t ssd1306_basic_read_point(uint8_t x, uint8_t y, uint8_t *data); - -/** - * @brief basic example draw a string - * @param[in] x is the coordinate x - * @param[in] y is the coordinate y - * @param[in] *str points to a written string address - * @param[in] len is the length of the string - * @param[in] color is the display color - * @param[in] font is the display font size - * @return status code - * - 0 success - * - 1 write string failed - * @note none - */ -uint8_t ssd1306_basic_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font); -/** - * @brief basic example fill a rectangle - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] color is the display color - * @return status code - * - 0 success - * - 1 fill rect failed - * @note none - */ -uint8_t ssd1306_basic_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color); - -/** - * @brief basic example draw a picture - * @param[in] left is the left coordinate x - * @param[in] top is the top coordinate y - * @param[in] right is the right coordinate x - * @param[in] bottom is the bottom coordinate y - * @param[in] *img points to a image buffer - * @return status code - * - 0 success - * - 1 draw picture failed - * @note none - */ -uint8_t ssd1306_basic_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img); - -/******************************************************************************* - * ADD_BY_ZHAOHE * - *******************************************************************************/ - -uint8_t ssd1306_basic_draw_screen(const char *img); -uint8_t ssd1306_basic_gram_update(); -ssd1306_handle_t *ssd1306_handler(); -uint8_t ssd1306_basic_line(uint8_t x, uint8_t y, uint8_t data); - -uint8_t ssd1306_basic_draw_str(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, const char *str, FontLibrary_t *frontlib); - -uint8_t ssd1306_basic_draw_battery_level(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, int level, int width, int high); - -uint8_t ssd1306_basic_draw_progress(uint8_t xs, uint8_t ys, uint16_t width, uint16_t high, uint16_t markpos, uint16_t progress); - -uint8_t ssd1306_basic_draw_line(uint8_t x1, uint8_t y1,uint8_t x2, uint8_t y2); - -uint8_t ssd1306_basic_clear_gram(void); - - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/app/src/basic/ssd1306/driver_ssd1306_font.h b/app/src/basic/ssd1306/driver_ssd1306_font.h deleted file mode 100644 index 1734127..0000000 --- a/app/src/basic/ssd1306/driver_ssd1306_font.h +++ /dev/null @@ -1,350 +0,0 @@ -/** - * Copyright (c) 2015 - present LibDriver All rights reserved - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @file driver_ssd1306_font.h - * @brief driver ssd1306 font header file - * @version 2.0.0 - * @author Shifeng Li - * @date 2021-03-30 - * - *

history

- * - *
Date Version Author Description - *
2021/03/30 2.0 Shifeng Li format the code - *
2020/12/10 1.0 Shifeng Li first upload - *
- */ - -#ifndef DRIVER_SSD1306_FONT_H -#define DRIVER_SSD1306_FONT_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C"{ -#endif - -static const uint8_t gsc_ssd1306_ascii_1206[95][12] = -{ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*" ", 0*/ - {0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"!", 1*/ - {0x00, 0x00, 0x30, 0x00, 0x40, 0x00, 0x30, 0x00, 0x40, 0x00, 0x00, 0x00}, /*""", 2*/ - {0x09, 0x00, 0x0B, 0xC0, 0x3D, 0x00, 0x0B, 0xC0, 0x3D, 0x00, 0x09, 0x00}, /*"#", 3*/ - {0x18, 0xC0, 0x24, 0x40, 0x7F, 0xE0, 0x22, 0x40, 0x31, 0x80, 0x00, 0x00}, /*"$", 4*/ - {0x18, 0x00, 0x24, 0xC0, 0x1B, 0x00, 0x0D, 0x80, 0x32, 0x40, 0x01, 0x80}, /*"%", 5*/ - {0x03, 0x80, 0x1C, 0x40, 0x27, 0x40, 0x1C, 0x80, 0x07, 0x40, 0x00, 0x40}, /*"&", 6*/ - {0x10, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"'", 7*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x80, 0x20, 0x40, 0x40, 0x20}, /*"(", 8*/ - {0x00, 0x00, 0x40, 0x20, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00}, /*")", 9*/ - {0x09, 0x00, 0x06, 0x00, 0x1F, 0x80, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00}, /*"*", 10*/ - {0x04, 0x00, 0x04, 0x00, 0x3F, 0x80, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00}, /*"+", 11*/ - {0x00, 0x10, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*", ", 12*/ - {0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00}, /*"-", 13*/ - {0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*".", 14*/ - {0x00, 0x20, 0x01, 0xC0, 0x06, 0x00, 0x38, 0x00, 0x40, 0x00, 0x00, 0x00}, /*"/", 15*/ - {0x1F, 0x80, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"0", 16*/ - {0x00, 0x00, 0x10, 0x40, 0x3F, 0xC0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}, /*"1", 17*/ - {0x18, 0xC0, 0x21, 0x40, 0x22, 0x40, 0x24, 0x40, 0x18, 0x40, 0x00, 0x00}, /*"2", 18*/ - {0x10, 0x80, 0x20, 0x40, 0x24, 0x40, 0x24, 0x40, 0x1B, 0x80, 0x00, 0x00}, /*"3", 19*/ - {0x02, 0x00, 0x0D, 0x00, 0x11, 0x00, 0x3F, 0xC0, 0x01, 0x40, 0x00, 0x00}, /*"4", 20*/ - {0x3C, 0x80, 0x24, 0x40, 0x24, 0x40, 0x24, 0x40, 0x23, 0x80, 0x00, 0x00}, /*"5", 21*/ - {0x1F, 0x80, 0x24, 0x40, 0x24, 0x40, 0x34, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"6", 22*/ - {0x30, 0x00, 0x20, 0x00, 0x27, 0xC0, 0x38, 0x00, 0x20, 0x00, 0x00, 0x00}, /*"7", 23*/ - {0x1B, 0x80, 0x24, 0x40, 0x24, 0x40, 0x24, 0x40, 0x1B, 0x80, 0x00, 0x00}, /*"8", 24*/ - {0x1C, 0x00, 0x22, 0xC0, 0x22, 0x40, 0x22, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"9", 25*/ - {0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*":", 26*/ - {0x00, 0x00, 0x00, 0x00, 0x04, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*";", 27*/ - {0x00, 0x00, 0x04, 0x00, 0x0A, 0x00, 0x11, 0x00, 0x20, 0x80, 0x40, 0x40}, /*"<", 28*/ - {0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x00, 0x00}, /*"=", 29*/ - {0x00, 0x00, 0x40, 0x40, 0x20, 0x80, 0x11, 0x00, 0x0A, 0x00, 0x04, 0x00}, /*">", 30*/ - {0x18, 0x00, 0x20, 0x00, 0x23, 0x40, 0x24, 0x00, 0x18, 0x00, 0x00, 0x00}, /*"?", 31*/ - {0x1F, 0x80, 0x20, 0x40, 0x27, 0x40, 0x29, 0x40, 0x1F, 0x40, 0x00, 0x00}, /*"@", 32*/ - {0x00, 0x40, 0x07, 0xC0, 0x39, 0x00, 0x0F, 0x00, 0x01, 0xC0, 0x00, 0x40}, /*"A", 33*/ - {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x24, 0x40, 0x1B, 0x80, 0x00, 0x00}, /*"B", 34*/ - {0x1F, 0x80, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x30, 0x80, 0x00, 0x00}, /*"C", 35*/ - {0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"D", 36*/ - {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x2E, 0x40, 0x30, 0xC0, 0x00, 0x00}, /*"E", 37*/ - {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x2E, 0x00, 0x30, 0x00, 0x00, 0x00}, /*"F", 38*/ - {0x0F, 0x00, 0x10, 0x80, 0x20, 0x40, 0x22, 0x40, 0x33, 0x80, 0x02, 0x00}, /*"G", 39*/ - {0x20, 0x40, 0x3F, 0xC0, 0x04, 0x00, 0x04, 0x00, 0x3F, 0xC0, 0x20, 0x40}, /*"H", 40*/ - {0x20, 0x40, 0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x20, 0x40, 0x00, 0x00}, /*"I", 41*/ - {0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x3F, 0xC0, 0x20, 0x00, 0x20, 0x00}, /*"J", 42*/ - {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x0B, 0x00, 0x30, 0xC0, 0x20, 0x40}, /*"K", 43*/ - {0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0xC0}, /*"L", 44*/ - {0x3F, 0xC0, 0x3C, 0x00, 0x03, 0xC0, 0x3C, 0x00, 0x3F, 0xC0, 0x00, 0x00}, /*"M", 45*/ - {0x20, 0x40, 0x3F, 0xC0, 0x0C, 0x40, 0x23, 0x00, 0x3F, 0xC0, 0x20, 0x00}, /*"N", 46*/ - {0x1F, 0x80, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"O", 47*/ - {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x24, 0x00, 0x18, 0x00, 0x00, 0x00}, /*"P", 48*/ - {0x1F, 0x80, 0x21, 0x40, 0x21, 0x40, 0x20, 0xE0, 0x1F, 0xA0, 0x00, 0x00}, /*"Q", 49*/ - {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x26, 0x00, 0x19, 0xC0, 0x00, 0x40}, /*"R", 50*/ - {0x18, 0xC0, 0x24, 0x40, 0x24, 0x40, 0x22, 0x40, 0x31, 0x80, 0x00, 0x00}, /*"S", 51*/ - {0x30, 0x00, 0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x30, 0x00, 0x00, 0x00}, /*"T", 52*/ - {0x20, 0x00, 0x3F, 0x80, 0x00, 0x40, 0x00, 0x40, 0x3F, 0x80, 0x20, 0x00}, /*"U", 53*/ - {0x20, 0x00, 0x3E, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x38, 0x00, 0x20, 0x00}, /*"V", 54*/ - {0x38, 0x00, 0x07, 0xC0, 0x3C, 0x00, 0x07, 0xC0, 0x38, 0x00, 0x00, 0x00}, /*"W", 55*/ - {0x20, 0x40, 0x39, 0xC0, 0x06, 0x00, 0x39, 0xC0, 0x20, 0x40, 0x00, 0x00}, /*"X", 56*/ - {0x20, 0x00, 0x38, 0x40, 0x07, 0xC0, 0x38, 0x40, 0x20, 0x00, 0x00, 0x00}, /*"Y", 57*/ - {0x30, 0x40, 0x21, 0xC0, 0x26, 0x40, 0x38, 0x40, 0x20, 0xC0, 0x00, 0x00}, /*"Z", 58*/ - {0x00, 0x00, 0x00, 0x00, 0x7F, 0xE0, 0x40, 0x20, 0x40, 0x20, 0x00, 0x00}, /*"[", 59*/ - {0x00, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x03, 0x80, 0x00, 0x40, 0x00, 0x00}, /*"\", 60*/ - {0x00, 0x00, 0x40, 0x20, 0x40, 0x20, 0x7F, 0xE0, 0x00, 0x00, 0x00, 0x00}, /*"]", 61*/ - {0x00, 0x00, 0x20, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"^", 62*/ - {0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10}, /*"_", 63*/ - {0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"`", 64*/ - {0x00, 0x00, 0x02, 0x80, 0x05, 0x40, 0x05, 0x40, 0x03, 0xC0, 0x00, 0x40}, /*"a", 65*/ - {0x20, 0x00, 0x3F, 0xC0, 0x04, 0x40, 0x04, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"b", 66*/ - {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x04, 0x40, 0x06, 0x40, 0x00, 0x00}, /*"c", 67*/ - {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x24, 0x40, 0x3F, 0xC0, 0x00, 0x40}, /*"d", 68*/ - {0x00, 0x00, 0x03, 0x80, 0x05, 0x40, 0x05, 0x40, 0x03, 0x40, 0x00, 0x00}, /*"e", 69*/ - {0x00, 0x00, 0x04, 0x40, 0x1F, 0xC0, 0x24, 0x40, 0x24, 0x40, 0x20, 0x00}, /*"f", 70*/ - {0x00, 0x00, 0x02, 0xE0, 0x05, 0x50, 0x05, 0x50, 0x06, 0x50, 0x04, 0x20}, /*"g", 71*/ - {0x20, 0x40, 0x3F, 0xC0, 0x04, 0x40, 0x04, 0x00, 0x03, 0xC0, 0x00, 0x40}, /*"h", 72*/ - {0x00, 0x00, 0x04, 0x40, 0x27, 0xC0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}, /*"i", 73*/ - {0x00, 0x10, 0x00, 0x10, 0x04, 0x10, 0x27, 0xE0, 0x00, 0x00, 0x00, 0x00}, /*"j", 74*/ - {0x20, 0x40, 0x3F, 0xC0, 0x01, 0x40, 0x07, 0x00, 0x04, 0xC0, 0x04, 0x40}, /*"k", 75*/ - {0x20, 0x40, 0x20, 0x40, 0x3F, 0xC0, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00}, /*"l", 76*/ - {0x07, 0xC0, 0x04, 0x00, 0x07, 0xC0, 0x04, 0x00, 0x03, 0xC0, 0x00, 0x00}, /*"m", 77*/ - {0x04, 0x40, 0x07, 0xC0, 0x04, 0x40, 0x04, 0x00, 0x03, 0xC0, 0x00, 0x40}, /*"n", 78*/ - {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x04, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"o", 79*/ - {0x04, 0x10, 0x07, 0xF0, 0x04, 0x50, 0x04, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"p", 80*/ - {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x04, 0x50, 0x07, 0xF0, 0x00, 0x10}, /*"q", 81*/ - {0x04, 0x40, 0x07, 0xC0, 0x02, 0x40, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00}, /*"r", 82*/ - {0x00, 0x00, 0x06, 0x40, 0x05, 0x40, 0x05, 0x40, 0x04, 0xC0, 0x00, 0x00}, /*"s", 83*/ - {0x00, 0x00, 0x04, 0x00, 0x1F, 0x80, 0x04, 0x40, 0x00, 0x40, 0x00, 0x00}, /*"t", 84*/ - {0x04, 0x00, 0x07, 0x80, 0x00, 0x40, 0x04, 0x40, 0x07, 0xC0, 0x00, 0x40}, /*"u", 85*/ - {0x04, 0x00, 0x07, 0x00, 0x04, 0xC0, 0x01, 0x80, 0x06, 0x00, 0x04, 0x00}, /*"v", 86*/ - {0x06, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x01, 0xC0, 0x06, 0x00, 0x00, 0x00}, /*"w", 87*/ - {0x04, 0x40, 0x06, 0xC0, 0x01, 0x00, 0x06, 0xC0, 0x04, 0x40, 0x00, 0x00}, /*"x", 88*/ - {0x04, 0x10, 0x07, 0x10, 0x04, 0xE0, 0x01, 0x80, 0x06, 0x00, 0x04, 0x00}, /*"y", 89*/ - {0x00, 0x00, 0x04, 0x40, 0x05, 0xC0, 0x06, 0x40, 0x04, 0x40, 0x00, 0x00}, /*"z", 90*/ - {0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x7B, 0xE0, 0x40, 0x20, 0x00, 0x00}, /*"{", 91*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00}, /*"|", 92*/ - {0x00, 0x00, 0x40, 0x20, 0x7B, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"}", 93*/ - {0x40, 0x00, 0x80, 0x00, 0x40, 0x00, 0x20, 0x00, 0x20, 0x00, 0x40, 0x00}, /*"~", 94*/ -}; - -static const uint8_t gsc_ssd1306_ascii_1608[95][16] = -{ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*" ", 0*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xCC, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"!", 1*/ - {0x00, 0x00, 0x08, 0x00, 0x30, 0x00, 0x60, 0x00, 0x08, 0x00, 0x30, 0x00, 0x60, 0x00, 0x00, 0x00}, /*""", 2*/ - {0x02, 0x20, 0x03, 0xFC, 0x1E, 0x20, 0x02, 0x20, 0x03, 0xFC, 0x1E, 0x20, 0x02, 0x20, 0x00, 0x00}, /*"#", 3*/ - {0x00, 0x00, 0x0E, 0x18, 0x11, 0x04, 0x3F, 0xFF, 0x10, 0x84, 0x0C, 0x78, 0x00, 0x00, 0x00, 0x00}, /*"$", 4*/ - {0x0F, 0x00, 0x10, 0x84, 0x0F, 0x38, 0x00, 0xC0, 0x07, 0x78, 0x18, 0x84, 0x00, 0x78, 0x00, 0x00}, /*"%", 5*/ - {0x00, 0x78, 0x0F, 0x84, 0x10, 0xC4, 0x11, 0x24, 0x0E, 0x98, 0x00, 0xE4, 0x00, 0x84, 0x00, 0x08}, /*"&", 6*/ - {0x08, 0x00, 0x68, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"'", 7*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x18, 0x18, 0x20, 0x04, 0x40, 0x02, 0x00, 0x00}, /*"(", 8*/ - {0x00, 0x00, 0x40, 0x02, 0x20, 0x04, 0x18, 0x18, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*")", 9*/ - {0x02, 0x40, 0x02, 0x40, 0x01, 0x80, 0x0F, 0xF0, 0x01, 0x80, 0x02, 0x40, 0x02, 0x40, 0x00, 0x00}, /*"*", 10*/ - {0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x0F, 0xF8, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00}, /*"+", 11*/ - {0x00, 0x01, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*", ", 12*/ - {0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80}, /*"-", 13*/ - {0x00, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*".", 14*/ - {0x00, 0x00, 0x00, 0x06, 0x00, 0x18, 0x00, 0x60, 0x01, 0x80, 0x06, 0x00, 0x18, 0x00, 0x20, 0x00}, /*"/", 15*/ - {0x00, 0x00, 0x07, 0xF0, 0x08, 0x08, 0x10, 0x04, 0x10, 0x04, 0x08, 0x08, 0x07, 0xF0, 0x00, 0x00}, /*"0", 16*/ - {0x00, 0x00, 0x08, 0x04, 0x08, 0x04, 0x1F, 0xFC, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"1", 17*/ - {0x00, 0x00, 0x0E, 0x0C, 0x10, 0x14, 0x10, 0x24, 0x10, 0x44, 0x11, 0x84, 0x0E, 0x0C, 0x00, 0x00}, /*"2", 18*/ - {0x00, 0x00, 0x0C, 0x18, 0x10, 0x04, 0x11, 0x04, 0x11, 0x04, 0x12, 0x88, 0x0C, 0x70, 0x00, 0x00}, /*"3", 19*/ - {0x00, 0x00, 0x00, 0xE0, 0x03, 0x20, 0x04, 0x24, 0x08, 0x24, 0x1F, 0xFC, 0x00, 0x24, 0x00, 0x00}, /*"4", 20*/ - {0x00, 0x00, 0x1F, 0x98, 0x10, 0x84, 0x11, 0x04, 0x11, 0x04, 0x10, 0x88, 0x10, 0x70, 0x00, 0x00}, /*"5", 21*/ - {0x00, 0x00, 0x07, 0xF0, 0x08, 0x88, 0x11, 0x04, 0x11, 0x04, 0x18, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"6", 22*/ - {0x00, 0x00, 0x1C, 0x00, 0x10, 0x00, 0x10, 0xFC, 0x13, 0x00, 0x1C, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"7", 23*/ - {0x00, 0x00, 0x0E, 0x38, 0x11, 0x44, 0x10, 0x84, 0x10, 0x84, 0x11, 0x44, 0x0E, 0x38, 0x00, 0x00}, /*"8", 24*/ - {0x00, 0x00, 0x07, 0x00, 0x08, 0x8C, 0x10, 0x44, 0x10, 0x44, 0x08, 0x88, 0x07, 0xF0, 0x00, 0x00}, /*"9", 25*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*":", 26*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*";", 27*/ - {0x00, 0x00, 0x00, 0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x00, 0x00}, /*"<", 28*/ - {0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x00, 0x00}, /*"=", 29*/ - {0x00, 0x00, 0x10, 0x04, 0x08, 0x08, 0x04, 0x10, 0x02, 0x20, 0x01, 0x40, 0x00, 0x80, 0x00, 0x00}, /*">", 30*/ - {0x00, 0x00, 0x0E, 0x00, 0x12, 0x00, 0x10, 0x0C, 0x10, 0x6C, 0x10, 0x80, 0x0F, 0x00, 0x00, 0x00}, /*"?", 31*/ - {0x03, 0xE0, 0x0C, 0x18, 0x13, 0xE4, 0x14, 0x24, 0x17, 0xC4, 0x08, 0x28, 0x07, 0xD0, 0x00, 0x00}, /*"@", 32*/ - {0x00, 0x04, 0x00, 0x3C, 0x03, 0xC4, 0x1C, 0x40, 0x07, 0x40, 0x00, 0xE4, 0x00, 0x1C, 0x00, 0x04}, /*"A", 33*/ - {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x04, 0x11, 0x04, 0x0E, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"B", 34*/ - {0x03, 0xE0, 0x0C, 0x18, 0x10, 0x04, 0x10, 0x04, 0x10, 0x04, 0x10, 0x08, 0x1C, 0x10, 0x00, 0x00}, /*"C", 35*/ - {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x10, 0x04, 0x10, 0x04, 0x08, 0x08, 0x07, 0xF0, 0x00, 0x00}, /*"D", 36*/ - {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x04, 0x17, 0xC4, 0x10, 0x04, 0x08, 0x18, 0x00, 0x00}, /*"E", 37*/ - {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x00, 0x17, 0xC0, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"F", 38*/ - {0x03, 0xE0, 0x0C, 0x18, 0x10, 0x04, 0x10, 0x04, 0x10, 0x44, 0x1C, 0x78, 0x00, 0x40, 0x00, 0x00}, /*"G", 39*/ - {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x84, 0x00, 0x80, 0x00, 0x80, 0x10, 0x84, 0x1F, 0xFC, 0x10, 0x04}, /*"H", 40*/ - {0x00, 0x00, 0x10, 0x04, 0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x10, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"I", 41*/ - {0x00, 0x03, 0x00, 0x01, 0x10, 0x01, 0x10, 0x01, 0x1F, 0xFE, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"J", 42*/ - {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x03, 0x80, 0x14, 0x64, 0x18, 0x1C, 0x10, 0x04, 0x00, 0x00}, /*"K", 43*/ - {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x0C, 0x00, 0x00}, /*"L", 44*/ - {0x10, 0x04, 0x1F, 0xFC, 0x1F, 0x00, 0x00, 0xFC, 0x1F, 0x00, 0x1F, 0xFC, 0x10, 0x04, 0x00, 0x00}, /*"M", 45*/ - {0x10, 0x04, 0x1F, 0xFC, 0x0C, 0x04, 0x03, 0x00, 0x00, 0xE0, 0x10, 0x18, 0x1F, 0xFC, 0x10, 0x00}, /*"N", 46*/ - {0x07, 0xF0, 0x08, 0x08, 0x10, 0x04, 0x10, 0x04, 0x10, 0x04, 0x08, 0x08, 0x07, 0xF0, 0x00, 0x00}, /*"O", 47*/ - {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x84, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x0F, 0x00, 0x00, 0x00}, /*"P", 48*/ - {0x07, 0xF0, 0x08, 0x18, 0x10, 0x24, 0x10, 0x24, 0x10, 0x1C, 0x08, 0x0A, 0x07, 0xF2, 0x00, 0x00}, /*"Q", 49*/ - {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x00, 0x11, 0xC0, 0x11, 0x30, 0x0E, 0x0C, 0x00, 0x04}, /*"R", 50*/ - {0x00, 0x00, 0x0E, 0x1C, 0x11, 0x04, 0x10, 0x84, 0x10, 0x84, 0x10, 0x44, 0x1C, 0x38, 0x00, 0x00}, /*"S", 51*/ - {0x18, 0x00, 0x10, 0x00, 0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x10, 0x00, 0x18, 0x00, 0x00, 0x00}, /*"T", 52*/ - {0x10, 0x00, 0x1F, 0xF8, 0x10, 0x04, 0x00, 0x04, 0x00, 0x04, 0x10, 0x04, 0x1F, 0xF8, 0x10, 0x00}, /*"U", 53*/ - {0x10, 0x00, 0x1E, 0x00, 0x11, 0xE0, 0x00, 0x1C, 0x00, 0x70, 0x13, 0x80, 0x1C, 0x00, 0x10, 0x00}, /*"V", 54*/ - {0x1F, 0xC0, 0x10, 0x3C, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0xE0, 0x10, 0x3C, 0x1F, 0xC0, 0x00, 0x00}, /*"W", 55*/ - {0x10, 0x04, 0x18, 0x0C, 0x16, 0x34, 0x01, 0xC0, 0x01, 0xC0, 0x16, 0x34, 0x18, 0x0C, 0x10, 0x04}, /*"X", 56*/ - {0x10, 0x00, 0x1C, 0x00, 0x13, 0x04, 0x00, 0xFC, 0x13, 0x04, 0x1C, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"Y", 57*/ - {0x08, 0x04, 0x10, 0x1C, 0x10, 0x64, 0x10, 0x84, 0x13, 0x04, 0x1C, 0x04, 0x10, 0x18, 0x00, 0x00}, /*"Z", 58*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFE, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x00, 0x00}, /*"[", 59*/ - {0x00, 0x00, 0x30, 0x00, 0x0C, 0x00, 0x03, 0x80, 0x00, 0x60, 0x00, 0x1C, 0x00, 0x03, 0x00, 0x00}, /*"\", 60*/ - {0x00, 0x00, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x7F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"]", 61*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00}, /*"^", 62*/ - {0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01}, /*"_", 63*/ - {0x00, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"`", 64*/ - {0x00, 0x00, 0x00, 0x98, 0x01, 0x24, 0x01, 0x44, 0x01, 0x44, 0x01, 0x44, 0x00, 0xFC, 0x00, 0x04}, /*"a", 65*/ - {0x10, 0x00, 0x1F, 0xFC, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x00, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"b", 66*/ - {0x00, 0x00, 0x00, 0x70, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x00, 0x88, 0x00, 0x00}, /*"c", 67*/ - {0x00, 0x00, 0x00, 0x70, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x11, 0x08, 0x1F, 0xFC, 0x00, 0x04}, /*"d", 68*/ - {0x00, 0x00, 0x00, 0xF8, 0x01, 0x44, 0x01, 0x44, 0x01, 0x44, 0x01, 0x44, 0x00, 0xC8, 0x00, 0x00}, /*"e", 69*/ - {0x00, 0x00, 0x01, 0x04, 0x01, 0x04, 0x0F, 0xFC, 0x11, 0x04, 0x11, 0x04, 0x11, 0x00, 0x18, 0x00}, /*"f", 70*/ - {0x00, 0x00, 0x00, 0xD6, 0x01, 0x29, 0x01, 0x29, 0x01, 0x29, 0x01, 0xC9, 0x01, 0x06, 0x00, 0x00}, /*"g", 71*/ - {0x10, 0x04, 0x1F, 0xFC, 0x00, 0x84, 0x01, 0x00, 0x01, 0x00, 0x01, 0x04, 0x00, 0xFC, 0x00, 0x04}, /*"h", 72*/ - {0x00, 0x00, 0x01, 0x04, 0x19, 0x04, 0x19, 0xFC, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"i", 73*/ - {0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01, 0x01, 0x19, 0x01, 0x19, 0xFE, 0x00, 0x00, 0x00, 0x00}, /*"j", 74*/ - {0x10, 0x04, 0x1F, 0xFC, 0x00, 0x24, 0x00, 0x40, 0x01, 0xB4, 0x01, 0x0C, 0x01, 0x04, 0x00, 0x00}, /*"k", 75*/ - {0x00, 0x00, 0x10, 0x04, 0x10, 0x04, 0x1F, 0xFC, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"l", 76*/ - {0x01, 0x04, 0x01, 0xFC, 0x01, 0x04, 0x01, 0x00, 0x01, 0xFC, 0x01, 0x04, 0x01, 0x00, 0x00, 0xFC}, /*"m", 77*/ - {0x01, 0x04, 0x01, 0xFC, 0x00, 0x84, 0x01, 0x00, 0x01, 0x00, 0x01, 0x04, 0x00, 0xFC, 0x00, 0x04}, /*"n", 78*/ - {0x00, 0x00, 0x00, 0xF8, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x00, 0xF8, 0x00, 0x00}, /*"o", 79*/ - {0x01, 0x01, 0x01, 0xFF, 0x00, 0x85, 0x01, 0x04, 0x01, 0x04, 0x00, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"p", 80*/ - {0x00, 0x00, 0x00, 0x70, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x01, 0x05, 0x01, 0xFF, 0x00, 0x01}, /*"q", 81*/ - {0x01, 0x04, 0x01, 0x04, 0x01, 0xFC, 0x00, 0x84, 0x01, 0x04, 0x01, 0x00, 0x01, 0x80, 0x00, 0x00}, /*"r", 82*/ - {0x00, 0x00, 0x00, 0xCC, 0x01, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0x98, 0x00, 0x00}, /*"s", 83*/ - {0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x07, 0xF8, 0x01, 0x04, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"t", 84*/ - {0x01, 0x00, 0x01, 0xF8, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x01, 0x08, 0x01, 0xFC, 0x00, 0x04}, /*"u", 85*/ - {0x01, 0x00, 0x01, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x10, 0x01, 0x60, 0x01, 0x80, 0x01, 0x00}, /*"v", 86*/ - {0x01, 0xF0, 0x01, 0x0C, 0x00, 0x30, 0x01, 0xC0, 0x00, 0x30, 0x01, 0x0C, 0x01, 0xF0, 0x01, 0x00}, /*"w", 87*/ - {0x00, 0x00, 0x01, 0x04, 0x01, 0x8C, 0x00, 0x74, 0x01, 0x70, 0x01, 0x8C, 0x01, 0x04, 0x00, 0x00}, /*"x", 88*/ - {0x01, 0x01, 0x01, 0x81, 0x01, 0x71, 0x00, 0x0E, 0x00, 0x18, 0x01, 0x60, 0x01, 0x80, 0x01, 0x00}, /*"y", 89*/ - {0x00, 0x00, 0x01, 0x84, 0x01, 0x0C, 0x01, 0x34, 0x01, 0x44, 0x01, 0x84, 0x01, 0x0C, 0x00, 0x00}, /*"z", 90*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3E, 0xFC, 0x40, 0x02, 0x40, 0x02}, /*"{", 91*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"|", 92*/ - {0x00, 0x00, 0x40, 0x02, 0x40, 0x02, 0x3E, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"}", 93*/ - {0x00, 0x00, 0x60, 0x00, 0x80, 0x00, 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x00, 0x20, 0x00}, /*"~", 94*/ -}; - -static const uint8_t gsc_ssd1306_ascii_2412[95][36] = -{ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*" ", 0*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x38, 0x0F, 0xFE, 0x38, 0x0F, 0x80, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"!", 1*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x38, 0x00, 0x00, 0x31, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x38, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00}, /*""", 2*/ - {0x00, 0x00, 0x00, 0x00, 0x61, 0x80, 0x00, 0x67, 0xF8, 0x07, 0xF9, 0x80, 0x00, 0x61, 0x80, 0x00, 0x61, 0x80, 0x00, 0x61, 0x80, 0x00, 0x61, 0x80, 0x00, 0x67, 0xF8, 0x07, 0xF9, 0x80, 0x00, 0x61, 0x80, 0x00, 0x00, 0x00}, /*"#", 3*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0xE0, 0x03, 0xE0, 0xF0, 0x06, 0x30, 0x08, 0x04, 0x18, 0x08, 0x1F, 0xFF, 0xFE, 0x04, 0x0E, 0x08, 0x07, 0x87, 0xF0, 0x03, 0x81, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"$", 4*/ - {0x01, 0xF0, 0x00, 0x06, 0x0C, 0x00, 0x04, 0x04, 0x08, 0x06, 0x0C, 0x70, 0x01, 0xF9, 0xC0, 0x00, 0x0E, 0x00, 0x00, 0x3B, 0xE0, 0x00, 0xEC, 0x18, 0x07, 0x08, 0x08, 0x04, 0x0C, 0x18, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00}, /*"%", 5*/ - {0x00, 0x01, 0xE0, 0x00, 0x07, 0xF0, 0x03, 0xF8, 0x18, 0x04, 0x1C, 0x08, 0x04, 0x17, 0x08, 0x07, 0xE1, 0xD0, 0x03, 0xC0, 0xE0, 0x00, 0x23, 0xB0, 0x00, 0x3C, 0x08, 0x00, 0x20, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"&", 6*/ - {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x31, 0x00, 0x00, 0x32, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"'", 7*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x01, 0xFF, 0xC0, 0x07, 0x80, 0xF0, 0x0C, 0x00, 0x18, 0x10, 0x00, 0x04, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00}, /*"(", 8*/ - {0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x10, 0x00, 0x04, 0x0C, 0x00, 0x18, 0x07, 0x80, 0xF0, 0x01, 0xFF, 0xC0, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*")", 9*/ - {0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x66, 0x00, 0x00, 0x66, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x18, 0x00, 0x03, 0xFF, 0xC0, 0x00, 0x18, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x66, 0x00, 0x00, 0x66, 0x00, 0x00, 0x42, 0x00}, /*"*", 10*/ - {0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x01, 0xFF, 0xC0, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00}, /*"+", 11*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x31, 0x00, 0x00, 0x32, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*", ", 12*/ - {0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}, /*"-", 13*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x38, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*".", 14*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x70, 0x00, 0x01, 0x80, 0x00, 0x0E, 0x00, 0x00, 0x38, 0x00, 0x00, 0xC0, 0x00, 0x07, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"/", 15*/ - {0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x03, 0x80, 0x70, 0x01, 0xFF, 0xE0, 0x00, 0x7F, 0x80, 0x00, 0x00, 0x00}, /*"0", 16*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x01, 0x00, 0x08, 0x01, 0x00, 0x08, 0x03, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"1", 17*/ - {0x00, 0x00, 0x00, 0x01, 0xC0, 0x38, 0x02, 0xC0, 0x58, 0x04, 0x00, 0x98, 0x04, 0x01, 0x18, 0x04, 0x02, 0x18, 0x04, 0x04, 0x18, 0x06, 0x1C, 0x18, 0x03, 0xF8, 0x18, 0x01, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"2", 18*/ - {0x00, 0x00, 0x00, 0x01, 0xC0, 0xE0, 0x03, 0xC0, 0xF0, 0x04, 0x00, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x06, 0x18, 0x08, 0x03, 0xF4, 0x18, 0x01, 0xE7, 0xF0, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"3", 19*/ - {0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x11, 0x00, 0x00, 0x61, 0x00, 0x00, 0x81, 0x08, 0x03, 0x01, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00}, /*"4", 20*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0xFC, 0xD0, 0x06, 0x08, 0x08, 0x06, 0x10, 0x08, 0x06, 0x10, 0x08, 0x06, 0x10, 0x08, 0x06, 0x18, 0x38, 0x06, 0x0F, 0xF0, 0x06, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"5", 21*/ - {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x84, 0x30, 0x02, 0x08, 0x18, 0x04, 0x10, 0x08, 0x04, 0x10, 0x08, 0x04, 0x10, 0x08, 0x07, 0x18, 0x10, 0x03, 0x0F, 0xF0, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x00}, /*"6", 22*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 0xF8, 0x06, 0x07, 0xF8, 0x06, 0x18, 0x00, 0x06, 0xE0, 0x00, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"7", 23*/ - {0x00, 0x00, 0x00, 0x01, 0xE1, 0xE0, 0x03, 0xF7, 0xF0, 0x06, 0x34, 0x10, 0x04, 0x18, 0x08, 0x04, 0x18, 0x08, 0x04, 0x0C, 0x08, 0x04, 0x0C, 0x08, 0x06, 0x16, 0x18, 0x03, 0xF3, 0xF0, 0x01, 0xC1, 0xE0, 0x00, 0x00, 0x00}, /*"8", 24*/ - {0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x03, 0xFC, 0x30, 0x03, 0x06, 0x38, 0x04, 0x02, 0x08, 0x04, 0x02, 0x08, 0x04, 0x02, 0x08, 0x04, 0x04, 0x10, 0x03, 0x08, 0xF0, 0x01, 0xFF, 0xC0, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00}, /*"9", 25*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x38, 0x00, 0x70, 0x38, 0x00, 0x70, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*":", 26*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x1A, 0x00, 0x30, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*";", 27*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x14, 0x00, 0x00, 0x22, 0x00, 0x00, 0x41, 0x00, 0x00, 0x80, 0x80, 0x01, 0x00, 0x40, 0x02, 0x00, 0x20, 0x04, 0x00, 0x10, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"<", 28*/ - {0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00}, /*"=", 29*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x04, 0x00, 0x10, 0x02, 0x00, 0x20, 0x01, 0x00, 0x40, 0x00, 0x80, 0x80, 0x00, 0x41, 0x00, 0x00, 0x22, 0x00, 0x00, 0x14, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}, /*">", 30*/ - {0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x04, 0xC0, 0x00, 0x04, 0x00, 0x00, 0x08, 0x00, 0x38, 0x08, 0x0F, 0x38, 0x08, 0x08, 0x38, 0x08, 0x10, 0x00, 0x0C, 0x30, 0x00, 0x07, 0xE0, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00}, /*"?", 31*/ - {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x02, 0x0F, 0x10, 0x06, 0x70, 0x88, 0x04, 0xC0, 0x88, 0x04, 0x83, 0x08, 0x04, 0x7F, 0x88, 0x02, 0xC0, 0x90, 0x03, 0x01, 0x20, 0x00, 0xFE, 0x40}, /*"@", 32*/ - {0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x01, 0xF8, 0x00, 0x3E, 0x08, 0x01, 0xC2, 0x00, 0x07, 0x02, 0x00, 0x07, 0xE2, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x1F, 0xC8, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x38, 0x00, 0x00, 0x08}, /*"A", 33*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x06, 0x18, 0x08, 0x03, 0xF4, 0x18, 0x01, 0xE7, 0xF0, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00}, /*"B", 34*/ - {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x02, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x10, 0x06, 0x00, 0x20, 0x07, 0x80, 0xC0, 0x00, 0x00, 0x00}, /*"C", 35*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x18, 0x02, 0x00, 0x10, 0x03, 0x80, 0x70, 0x01, 0xFF, 0xE0, 0x00, 0x7F, 0x80, 0x00, 0x00, 0x00}, /*"D", 36*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x3E, 0x08, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x01, 0x00, 0x60, 0x00, 0x00, 0x00}, /*"E", 37*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x00, 0x04, 0x08, 0x00, 0x04, 0x08, 0x00, 0x04, 0x3E, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00}, /*"F", 38*/ - {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x02, 0x08, 0x04, 0x02, 0x08, 0x02, 0x03, 0xF0, 0x07, 0x83, 0xF0, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00}, /*"G", 39*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x04, 0x08, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08}, /*"H", 40*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"I", 41*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x04, 0x00, 0x01, 0x04, 0x00, 0x01, 0x04, 0x00, 0x03, 0x07, 0xFF, 0xFE, 0x07, 0xFF, 0xFC, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"J", 42*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x0C, 0x08, 0x00, 0x18, 0x00, 0x00, 0x3E, 0x00, 0x04, 0xC7, 0x80, 0x05, 0x03, 0xC8, 0x06, 0x00, 0xF8, 0x04, 0x00, 0x38, 0x04, 0x00, 0x18, 0x00, 0x00, 0x08}, /*"K", 43*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00}, /*"L", 44*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0x80, 0x08, 0x07, 0xFC, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x03, 0xF8, 0x00, 0x07, 0xC0, 0x00, 0x78, 0x00, 0x07, 0x80, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08}, /*"M", 45*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0x00, 0x08, 0x03, 0xC0, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x38, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0xC0, 0x04, 0x00, 0xF0, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x00}, /*"N", 46*/ - {0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x03, 0x00, 0x30, 0x01, 0xFF, 0xE0, 0x00, 0x7F, 0x80, 0x00, 0x00, 0x00}, /*"O", 47*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x04, 0x08, 0x04, 0x04, 0x00, 0x04, 0x04, 0x00, 0x04, 0x04, 0x00, 0x04, 0x04, 0x00, 0x06, 0x0C, 0x00, 0x03, 0xF8, 0x00, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00}, /*"P", 48*/ - {0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x88, 0x04, 0x00, 0x88, 0x04, 0x00, 0xC8, 0x06, 0x00, 0x3C, 0x03, 0x00, 0x3E, 0x01, 0xFF, 0xE6, 0x00, 0x7F, 0x84, 0x00, 0x00, 0x00}, /*"Q", 49*/ - {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x00, 0x04, 0x0C, 0x00, 0x04, 0x0F, 0x00, 0x04, 0x0B, 0xC0, 0x06, 0x10, 0xF0, 0x03, 0xF0, 0x38, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x08}, /*"R", 50*/ - {0x00, 0x00, 0x00, 0x01, 0xE0, 0xF8, 0x03, 0xF0, 0x30, 0x06, 0x30, 0x10, 0x04, 0x18, 0x08, 0x04, 0x18, 0x08, 0x04, 0x0C, 0x08, 0x04, 0x0C, 0x08, 0x02, 0x06, 0x18, 0x02, 0x07, 0xF0, 0x07, 0x81, 0xE0, 0x00, 0x00, 0x00}, /*"S", 51*/ - {0x01, 0x80, 0x00, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x80, 0x00}, /*"T", 52*/ - {0x04, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x07, 0xFF, 0xF0, 0x04, 0x00, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x04, 0x00, 0x10, 0x07, 0xFF, 0xE0, 0x04, 0x00, 0x00}, /*"U", 53*/ - {0x04, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x07, 0xFE, 0x00, 0x04, 0x1F, 0xE0, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x38, 0x00, 0x01, 0xE0, 0x04, 0x3E, 0x00, 0x07, 0xC0, 0x00, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"V", 54*/ - {0x04, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x07, 0xFF, 0xC0, 0x04, 0x1F, 0xF8, 0x00, 0x07, 0xC0, 0x07, 0xF8, 0x00, 0x07, 0xFF, 0x80, 0x04, 0x3F, 0xF8, 0x00, 0x07, 0xC0, 0x04, 0xF8, 0x00, 0x07, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"W", 55*/ - {0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x07, 0xC0, 0x78, 0x05, 0xF1, 0xC8, 0x00, 0x3E, 0x00, 0x00, 0x1F, 0x80, 0x04, 0x63, 0xE8, 0x07, 0x80, 0xF8, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"X", 56*/ - {0x04, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0x80, 0x00, 0x07, 0xE0, 0x08, 0x04, 0x7C, 0x08, 0x00, 0x1F, 0xF8, 0x00, 0x07, 0xF8, 0x00, 0x18, 0x08, 0x04, 0xE0, 0x08, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"Y", 57*/ - {0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x06, 0x00, 0x38, 0x04, 0x00, 0xF8, 0x04, 0x03, 0xE8, 0x04, 0x0F, 0x08, 0x04, 0x7C, 0x08, 0x05, 0xF0, 0x08, 0x07, 0xC0, 0x08, 0x07, 0x00, 0x18, 0x04, 0x00, 0x60, 0x00, 0x00, 0x00}, /*"Z", 58*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFE, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00}, /*"[", 59*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x38, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x30, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}, /*"\", 60*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x3F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"]", 61*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00, 0x30, 0x00, 0x00, 0x10, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"^", 62*/ - {0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01}, /*"_", 63*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"`", 64*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x19, 0xF8, 0x00, 0x1B, 0x18, 0x00, 0x22, 0x08, 0x00, 0x26, 0x08, 0x00, 0x24, 0x08, 0x00, 0x24, 0x10, 0x00, 0x3F, 0xF8, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18}, /*"a", 65*/ - {0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF0, 0x00, 0x18, 0x18, 0x00, 0x10, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x30, 0x18, 0x00, 0x1F, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00}, /*"b", 66*/ - {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x18, 0x30, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x3C, 0x08, 0x00, 0x1C, 0x10, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"c", 67*/ - {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x38, 0x18, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x04, 0x10, 0x10, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"d", 68*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x12, 0x30, 0x00, 0x22, 0x18, 0x00, 0x22, 0x08, 0x00, 0x22, 0x08, 0x00, 0x32, 0x08, 0x00, 0x1E, 0x10, 0x00, 0x0E, 0x20, 0x00, 0x00, 0x00}, /*"e", 69*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x01, 0xFF, 0xF8, 0x03, 0xFF, 0xF8, 0x06, 0x20, 0x08, 0x04, 0x20, 0x08, 0x04, 0x20, 0x08, 0x07, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"f", 70*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x6E, 0x00, 0x1F, 0xF3, 0x00, 0x31, 0xB1, 0x00, 0x20, 0xB1, 0x00, 0x20, 0xB1, 0x00, 0x31, 0x91, 0x00, 0x1F, 0x13, 0x00, 0x2E, 0x1E, 0x00, 0x20, 0x0E, 0x00, 0x30, 0x00}, /*"g", 71*/ - {0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"h", 72*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x06, 0x3F, 0xF8, 0x06, 0x3F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"i", 73*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x20, 0x01, 0x00, 0x20, 0x01, 0x00, 0x20, 0x03, 0x06, 0x3F, 0xFE, 0x06, 0x3F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"j", 74*/ - {0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x01, 0x88, 0x00, 0x03, 0x00, 0x00, 0x2F, 0xC0, 0x00, 0x38, 0xF8, 0x00, 0x20, 0x38, 0x00, 0x20, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"k", 75*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"l", 76*/ - {0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x20, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x20, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x00, 0x08}, /*"m", 77*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"n", 78*/ - {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x0F, 0xF0, 0x00, 0x18, 0x30, 0x00, 0x30, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x30, 0x08, 0x00, 0x18, 0x30, 0x00, 0x0F, 0xF0, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x00}, /*"o", 79*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x3F, 0xFF, 0x00, 0x3F, 0xFF, 0x00, 0x10, 0x11, 0x00, 0x20, 0x09, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x30, 0x38, 0x00, 0x1F, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00}, /*"p", 80*/ - {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x38, 0x18, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x09, 0x00, 0x10, 0x11, 0x00, 0x1F, 0xFF, 0x00, 0x3F, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}, /*"q", 81*/ - {0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x08, 0x08, 0x00, 0x10, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x00, 0x00, 0x30, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00}, /*"r", 82*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x78, 0x00, 0x1E, 0x18, 0x00, 0x33, 0x08, 0x00, 0x23, 0x08, 0x00, 0x21, 0x08, 0x00, 0x21, 0x88, 0x00, 0x21, 0x98, 0x00, 0x30, 0xF0, 0x00, 0x38, 0x60, 0x00, 0x00, 0x00}, /*"s", 83*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0xFF, 0xF0, 0x03, 0xFF, 0xF8, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"t", 84*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x7F, 0xF8, 0x00, 0x00, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x20, 0x10, 0x00, 0x3F, 0xF8, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"u", 85*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x30, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x23, 0xF0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x70, 0x00, 0x23, 0x80, 0x00, 0x3C, 0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00}, /*"v", 86*/ - {0x00, 0x20, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x23, 0xF8, 0x00, 0x00, 0xE0, 0x00, 0x27, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x21, 0xF8, 0x00, 0x01, 0xE0, 0x00, 0x3E, 0x00, 0x00, 0x20, 0x00}, /*"w", 87*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x38, 0x38, 0x00, 0x3E, 0x68, 0x00, 0x27, 0x80, 0x00, 0x03, 0xC8, 0x00, 0x2C, 0xF8, 0x00, 0x38, 0x38, 0x00, 0x20, 0x18, 0x00, 0x20, 0x08, 0x00, 0x00, 0x00}, /*"x", 88*/ - {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x30, 0x03, 0x00, 0x3C, 0x01, 0x00, 0x3F, 0x83, 0x00, 0x23, 0xEC, 0x00, 0x00, 0x70, 0x00, 0x23, 0x80, 0x00, 0x3C, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00}, /*"y", 89*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x08, 0x00, 0x20, 0x38, 0x00, 0x20, 0xF8, 0x00, 0x23, 0xE8, 0x00, 0x2F, 0x88, 0x00, 0x3E, 0x08, 0x00, 0x38, 0x08, 0x00, 0x20, 0x18, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00}, /*"z", 90*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x14, 0x00, 0x1F, 0xF7, 0xFC, 0x30, 0x00, 0x06, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"{", 91*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"|", 92*/ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x30, 0x00, 0x06, 0x1F, 0xF7, 0xFC, 0x00, 0x14, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"}", 93*/ - {0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00, 0x00}, /*"~", 94*/ -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/app/src/basic/ssd1306/driver_ssd1306_interface.h b/app/src/basic/ssd1306/driver_ssd1306_interface.h deleted file mode 100644 index 093ed1d..0000000 --- a/app/src/basic/ssd1306/driver_ssd1306_interface.h +++ /dev/null @@ -1,192 +0,0 @@ -/** - * Copyright (c) 2015 - present LibDriver All rights reserved - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @file driver_ssd1306_interface.h - * @brief driver ssd1306 interface header file - * @version 2.0.0 - * @author Shifeng Li - * @date 2021-03-30 - * - *

history

- * - *
Date Version Author Description - *
2021/03/30 2.0 Shifeng Li format the code - *
2020/12/10 1.0 Shifeng Li first upload - *
- */ - -#ifndef DRIVER_SSD1306_INTERFACE_H -#define DRIVER_SSD1306_INTERFACE_H - -#include "driver_ssd1306.h" - -#ifdef __cplusplus -extern "C"{ -#endif - -/** - * @defgroup ssd1306_interface_driver ssd1306 interface driver function - * @brief ssd1306 interface driver modules - * @ingroup ssd1306_driver - * @{ - */ - -/** - * @brief interface iic bus init - * @return status code - * - 0 success - * - 1 iic init failed - * @note none - */ -uint8_t ssd1306_interface_iic_init(void); - -/** - * @brief interface iic bus deinit - * @return status code - * - 0 success - * - 1 iic deinit failed - * @note none - */ -uint8_t ssd1306_interface_iic_deinit(void); - -/** - * @brief interface iic bus write - * @param[in] addr is the iic device write address - * @param[in] reg is the iic register address - * @param[in] *buf points to a data buffer - * @param[in] len is the length of the data buffer - * @return status code - * - 0 success - * - 1 write failed - * @note none - */ -uint8_t ssd1306_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len); - -/** - * @brief interface spi bus init - * @return status code - * - 0 success - * - 1 spi init failed - * @note none - */ -uint8_t ssd1306_interface_spi_init(void); - -/** - * @brief interface spi bus deinit - * @return status code - * - 0 success - * - 1 spi deinit failed - * @note none - */ -uint8_t ssd1306_interface_spi_deinit(void); - -/** - * @brief interface spi bus write - * @param[in] *buf points to a data buffer - * @param[in] len is the length of data buffer - * @return status code - * - 0 success - * - 1 write failed - * @note none - */ -uint8_t ssd1306_interface_spi_write_cmd(uint8_t *buf, uint16_t len); - -/** - * @brief interface delay ms - * @param[in] ms - * @note none - */ -void ssd1306_interface_delay_ms(uint32_t ms); - -/** - * @brief interface print format data - * @param[in] fmt is the format data - * @note none - */ -void ssd1306_interface_debug_print(const char *const fmt, ...); - -/** - * @brief interface command && data gpio init - * @return status code - * - 0 success - * - 1 gpio init failed - * @note none - */ -uint8_t ssd1306_interface_spi_cmd_data_gpio_init(void); - -/** - * @brief interface command && data gpio deinit - * @return status code - * - 0 success - * - 1 gpio deinit failed - * @note none - */ -uint8_t ssd1306_interface_spi_cmd_data_gpio_deinit(void); - -/** - * @brief interface command && data gpio write - * @param[in] value is the written value - * @return status code - * - 0 success - * - 1 gpio write failed - * @note none - */ -uint8_t ssd1306_interface_spi_cmd_data_gpio_write(uint8_t value); - -/** - * @brief interface reset gpio init - * @return status code - * - 0 success - * - 1 gpio init failed - * @note none - */ -uint8_t ssd1306_interface_reset_gpio_init(void); - -/** - * @brief interface reset gpio deinit - * @return status code - * - 0 success - * - 1 gpio deinit failed - * @note none - */ -uint8_t ssd1306_interface_reset_gpio_deinit(void); - -/** - * @brief interface reset gpio write - * @param[in] value is the written value - * @return status code - * - 0 success - * - 1 gpio write failed - * @note none - */ -uint8_t ssd1306_interface_reset_gpio_write(uint8_t value); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/app/src/basic/ssd1306/fontlib.c b/app/src/basic/ssd1306/fontlib.c deleted file mode 100644 index b2e6090..0000000 --- a/app/src/basic/ssd1306/fontlib.c +++ /dev/null @@ -1,83 +0,0 @@ -#include "fontlib.h" - -static FontLibrary_t s_fontlibrary[10]; -static uint8_t s_fontlibrarylen = 0; - -uint8_t str_iterator_start(StrIterator_t *iterator, FontCode_t code, const char *chr) { - iterator->str = chr; - iterator->nowoff = 0; - iterator->code = code; - return 0; -} -uint8_t str_iterator_isend(StrIterator_t *iterator) { return iterator->str[iterator->nowoff] == '\0'; } -void str_iterator_next(StrIterator_t *iterator, const char **nowchr) { - *nowchr = iterator->str + iterator->nowoff; - if (*nowchr[0] == '\0') { - *nowchr = NULL; - return; - } - while (iterator->str[iterator->nowoff] != '\0') { - if ((iterator->str[iterator->nowoff] < 0x80)) { - iterator->nowoff++; - break; - } else { - if (iterator->code == kgbk) { - iterator->nowoff += 2; - } else if (iterator->code == kutf8) { - iterator->nowoff += 3; - } - break; - } - } -} - -void FontLibrary_regsiter(FontLibrary_t *lib) { s_fontlibrary[s_fontlibrarylen++] = *lib; } - -FontLibrary_t *FontLibrary_findlib(FontCode_t fontcode, uint8_t widthPixel, uint8_t heightPixel, bool isAscii) { - for (size_t i = 0; i < s_fontlibrarylen; i++) { - if (s_fontlibrary[i].fontCode == fontcode && // - s_fontlibrary[i].isAscii == isAscii && // - s_fontlibrary[i].widthPixel == widthPixel && // - s_fontlibrary[i].heightPixel == heightPixel) { - return &s_fontlibrary[i]; - } - } - return NULL; -} - -void FontLibrary_findchar(FontLibrary_t *lib, const char *chr, const uint8_t **font) { - *font = NULL; - - uint8_t eachIndexWidth = 1; - if (lib->isAscii) { - eachIndexWidth = 1; - } else { - if (lib->fontCode == kutf8) { - eachIndexWidth = 3; - } else if (lib->fontCode == kgbk) { - eachIndexWidth = 2; - } - } - - if (eachIndexWidth == 1) { - for (int i = 0; i < lib->fontIndexLen; i += 1) { - if (lib->fontIndex[i] == chr[0]) { - *font = &lib->font[i * lib->widthPixel * lib->heightPixel / 8]; - } - } - } else if (eachIndexWidth == 2) { - for (int i = 0; i < lib->fontIndexLen; i += 2) { - if (lib->fontIndex[i] == chr[0] && lib->fontIndex[i + 1] == chr[1]) { - *font = &lib->font[i / 2 * lib->widthPixel * lib->heightPixel / 8]; - } - } - } else if (eachIndexWidth == 3) { - for (int i = 0; i < lib->fontIndexLen; i += 3) { - if (lib->fontIndex[i] == chr[0] && lib->fontIndex[i + 1] == chr[1] && lib->fontIndex[i + 2] == chr[2]) { - *font = &lib->font[i / 3 * lib->widthPixel * lib->heightPixel / 8]; - } - } - } -} - -bool str_is_ascii(const char *chr) { return chr[0] < 0x80; } diff --git a/app/src/basic/ssd1306/fontlib.h b/app/src/basic/ssd1306/fontlib.h deleted file mode 100644 index 14113c6..0000000 --- a/app/src/basic/ssd1306/fontlib.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once -#include -#include -#include -typedef enum { - kutf8, - kgbk, -} FontCode_t; - -typedef enum { - kFontSize08x16, - kFontSize16x16, -} FontSize_t; - -typedef struct { - const uint8_t *font; - - const char *fontIndex; - int fontIndexLen; - - FontCode_t fontCode; - bool isAscii; - - uint8_t widthPixel; - uint8_t heightPixel; -} FontLibrary_t; - -typedef struct { - const char *str; - int nowoff; - FontCode_t code; -} StrIterator_t; - -uint8_t str_iterator_start(StrIterator_t *iterator, FontCode_t code, const char *chr); -uint8_t str_iterator_isend(StrIterator_t *iterator); -void str_iterator_next(StrIterator_t *iterator, const char **nowchr); -bool str_is_ascii(const char *chr); - -void FontLibrary_regsiter(FontLibrary_t *lib); -FontLibrary_t *FontLibrary_findlib(FontCode_t fontcode, uint8_t widthPixel, uint8_t heightPixel, bool isAscii); -void FontLibrary_findchar(FontLibrary_t *lib, const char *chr, const uint8_t **font); diff --git a/app/src/basic/ssd1306/wave_drawer.c b/app/src/basic/ssd1306/wave_drawer.c deleted file mode 100644 index a98fe9f..0000000 --- a/app/src/basic/ssd1306/wave_drawer.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "wave_drawer.h" - -#include "znordic.h" - -static bool m_draw_scan_line = false; - -void wave_drawer_init(wave_drawer_t *dw, uint8_t xs, uint8_t ys, uint16_t width, uint16_t high) { - dw->xs = xs; - dw->ys = ys; - dw->width = width; - dw->high = high; - dw->pointoffset = 0; - - dw->xright_border = xs + width; - dw->xleft_border = xs; - dw->ytop_border = ys; - dw->ybottom_border = ys + high; - - dw->ytop = ys + 1; - dw->ybottom = ys + high - 2; - dw->xleft = xs + 1; - dw->xright = xs + width - 1; - - dw->high = high - 2; - dw->width = width - 1; - dw->is_first_point = true; -} - -void wave_drawer_draw_border(wave_drawer_t *dw) { - for (uint16_t x = dw->xleft_border; x <= dw->xright_border; x++) { - for (uint16_t y = dw->ytop_border; y <= dw->ybottom_border; y++) { - if (x == dw->xleft_border || x == dw->xright_border || y == dw->ytop_border || y == dw->ybottom_border) { - ssd1306_gram_write_point(ssd1306_handler(), x, y, 1); - } else { - ssd1306_gram_write_point(ssd1306_handler(), x, y, 0); - } - } - } -} - -void wave_drawer_draw_next_point(wave_drawer_t *dw, uint8_t y) { - /** - * @brief - * - * ---------------- - * | - * | . ..| .... - * |.. . | - * | - * |--------------- - */ - - uint16_t yreal = y / 100.0 * (dw->high - 4); - uint16_t ypos = dw->ybottom - yreal; - uint16_t xpos = dw->xleft + dw->pointoffset; - - // Çå³ýÉÏÒ»´ÎµÄµã - for (size_t yoff = 0; yoff < dw->high; yoff++) { - ssd1306_gram_write_point(ssd1306_handler(), xpos + 0, dw->ybottom - yoff, 0); - } - - ssd1306_gram_write_point(ssd1306_handler(), xpos, ypos, 1); - if (xpos > dw->last_xs && !dw->is_first_point) { - // »­µ±Ç°µãºÍÉÏÒ»´ÎµãµÄÁ¬Ïß - ssd1306_basic_draw_line(xpos - 1, dw->last_ys, xpos, ypos); - } - /** - * @brief »­µ±Ç°Î»ÖñêÖ¾ - */ - for (size_t yoff = 0; yoff < dw->high; yoff++) { - if (xpos + 1 <= dw->xright) { - if (m_draw_scan_line) { - ssd1306_gram_write_point(ssd1306_handler(), xpos + 1, dw->ybottom - yoff, 1); - } else { - ssd1306_gram_write_point(ssd1306_handler(), xpos + 1, dw->ybottom - yoff, 0); - } - } - for (uint8_t i = 2; i < 2 + 5; i++) { - if (xpos + i <= dw->xright) { - ssd1306_gram_write_point(ssd1306_handler(), xpos + i, dw->ybottom - yoff, 0); - } - } - } - dw->last_xs = xpos; - dw->last_ys = ypos; - - dw->pointoffset++; - if (dw->pointoffset >= dw->width) { - dw->pointoffset = 0; - } - dw->is_first_point = false; -} \ No newline at end of file diff --git a/app/src/basic/ssd1306/wave_drawer.h b/app/src/basic/ssd1306/wave_drawer.h deleted file mode 100644 index e42d3fb..0000000 --- a/app/src/basic/ssd1306/wave_drawer.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "driver_ssd1306.h" -#include "driver_ssd1306_basic.h" - -typedef struct { - uint8_t xs; - uint8_t ys; - - uint8_t last_xs; - uint8_t last_ys; - - uint8_t xright_border; - uint8_t xleft_border; - - uint8_t ytop_border; - uint8_t ybottom_border; - - uint8_t ytop; - uint8_t ybottom; - - uint16_t xleft; - uint16_t xright; - - uint16_t width; - uint16_t high; - - uint16_t pointoffset; - bool is_first_point; -} wave_drawer_t; - -void wave_drawer_init(wave_drawer_t *drawer, uint8_t xs, uint8_t ys, uint16_t width, uint16_t high); -void wave_drawer_draw_border(wave_drawer_t *drawer); -void wave_drawer_draw_next_point(wave_drawer_t *drawer, uint8_t y); diff --git a/app/src/basic/version.h b/app/src/basic/version.h deleted file mode 100644 index e911879..0000000 --- a/app/src/basic/version.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#define CATEGORY "M1001" // µ¥µ¼Áª -#define MANUFACTURER_NAME "iflytop" - -#define FIRMWARE_VERSION (10) -#define BLESTACK_VERSION 1 -#define BOOTLOADER_VERSION 1 -#define HARDWARE_VERSION (1) - -// https://www.bluetooth.com/specifications/assigned-numbers/ -// #define APP_COMPANY_IDENTIFIER 0x0059 /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */ -#define APP_COMPANY_IDENTIFIER 0xFFFF /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */ diff --git a/app/src/basic_service/app_event.h b/app/src/basic_service/app_event.h new file mode 100644 index 0000000..0c4d493 --- /dev/null +++ b/app/src/basic_service/app_event.h @@ -0,0 +1,76 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" +typedef enum { + kplod_connected_event = 0, // µ¼ÁªÁ¬½Óʼþ + kplod_disconnected_event, // µ¼Áª¶Ï¿ªÊ¼þ + kplod_connecting_event, // µ¼ÁªÁ¬½ÓÖÐʼþ + + kbattery_start_charge_event, // ³äµçʼþ + kbattery_end_charge_event, // ³äµç½áÊøÊ¼þ + + kevent_tmr_scheduler_event, // ¶¨Ê±Æ÷µ÷¶Èʼþ + + kevent_capture_256data_event, // ²ÉÑùÊý¾Ý»Øµ÷ + kevent_capture_little_data_block_event, // µ¥´Î²ÉÑùÊý¾Ý»Øµ÷ +} app_event_type_t; + +typedef uint16_t one_frame_t; + +typedef struct { + app_event_type_t eventType; + union { + uint32_t plod_connected_accumulation_time; // µ¼ÁªÁ¬½ÓÀÛ¼ÆÊ±¼ä + uint8_t* capture_data_cache; // ʵʱ²ÉÑùÊý¾Ý£¬Êý¾Ý³¤¶ÈΪ256×Ö½Ú + struct { + uint32_t frameIndex; + one_frame_t data[LITTLE_DATA_BLOCK_FRAME_NUM]; + } little_data_block; + } val; +} app_event_t; + +typedef enum { + // ´ý»ú + kdevice_state_standby = 0, + // ³äµçÖÐ + kdevice_state_charging, + // ¿ª»ú + kdevice_state_poweron, + // Ê×Ò³ + kdevice_state_home, + // ÌáʾÓû§±£³Ö¾²Ö¹ + kdevice_state_keep_still, + // ²É¼¯ÖÐ + kdevice_state_sampling, + // ²É¼¯Íê³É + kdevice_state_sampling_complete, + // ²É¼¯Òì³£ + kdevice_state_sampling_error, + +} device_state_t; + +static const char* device_state_to_str(device_state_t ds) { + switch (ds) { + case kdevice_state_standby: + return "standby"; + case kdevice_state_poweron: + return "poweron"; + case kdevice_state_home: + return "home"; + case kdevice_state_keep_still: + return "keep_still"; + case kdevice_state_sampling: + return "sampling"; + case kdevice_state_sampling_complete: + return "sampling_complete"; + case kdevice_state_sampling_error: + return "sampling_error"; + case kdevice_state_charging: + return "charging"; + default: + return "unknow"; + } +} + diff --git a/app/src/basic_service/app_event_distribute.c b/app/src/basic_service/app_event_distribute.c new file mode 100644 index 0000000..a30938e --- /dev/null +++ b/app/src/basic_service/app_event_distribute.c @@ -0,0 +1,23 @@ +#include "basic_service/app_event_distribute.h" + +#include "basic_service/app_event.h" +#include "app_scheduler.h" + +static AppEventListener m_listener[10]; +static int m_listener_num = 0; + +static void app_event_process_cb(void* p_event_data, uint16_t event_size) { + for (int i = 0; i < m_listener_num; i++) { + if (m_listener[i].cbfunc) { + m_listener[i].cbfunc(p_event_data, event_size); + } + } +} + +void AppEvent_regListener(app_event_listener_t listener) { // + m_listener[m_listener_num++].cbfunc = listener; +} + +void AppEvent_pushEvent(app_event_t* event) { // + app_sched_event_put(event, sizeof(app_event_t), app_event_process_cb); +} diff --git a/app/src/basic_service/app_event_distribute.h b/app/src/basic_service/app_event_distribute.h new file mode 100644 index 0000000..2a004ae --- /dev/null +++ b/app/src/basic_service/app_event_distribute.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include + +#include "basic_service/app_event.h" + + +typedef void (*app_event_listener_t)(void* p_event_data, uint16_t event_size); + +typedef struct { + app_event_listener_t cbfunc; +} AppEventListener; + +void AppEvent_regListener(app_event_listener_t listener); +void AppEvent_pushEvent(app_event_t* event); diff --git a/app/src/basic_service/device_state.c b/app/src/basic_service/device_state.c new file mode 100644 index 0000000..243c1b5 --- /dev/null +++ b/app/src/basic_service/device_state.c @@ -0,0 +1,27 @@ + +#include "device_state.h" + +#include "znordic.h" +static device_state_t m_device_state = kdevice_state_standby; // É豸״̬ +static uint32_t m_change_to_cur_state_tp = 0; // Çл»µ½µ±Ç°×´Ì¬µÄʱ¼ä´Á + +void ds_change_to_state(device_state_t state) { + ZLOGI("change state from %s to %s", device_state_to_str(m_device_state), device_state_to_str(state)); + m_device_state = state; + m_change_to_cur_state_tp = znordic_getpower_on_ms(); +} + +uint32_t ds_cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); } +device_state_t ds_now_state() { return m_device_state; } + +static sample_capture_state_t m_sample_capture_state; + +sample_capture_state_t* sample_capture_state_get() { // + return &m_sample_capture_state; +} +void sample_capture_state_reset() { // + m_sample_capture_state.is_over30s = false; +}; +void sample_capture_state_set_is_over30s(bool over30s) { // + m_sample_capture_state.is_over30s = over30s; +} diff --git a/app/src/basic_service/device_state.h b/app/src/basic_service/device_state.h new file mode 100644 index 0000000..6c6d7c9 --- /dev/null +++ b/app/src/basic_service/device_state.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" +#include "basic_service/app_event.h" +void ds_change_to_state(device_state_t state); +uint32_t ds_cur_state_haspassed_ms(); +device_state_t ds_now_state(); + +typedef struct { + bool is_over30s; +} sample_capture_state_t; + +sample_capture_state_t* sample_capture_state_get(); + +void sample_capture_state_reset(); +void sample_capture_state_set_is_over30s(bool over30s); diff --git a/app/src/basic_service/device_version_info_mgr.c b/app/src/basic_service/device_version_info_mgr.c new file mode 100644 index 0000000..dc31614 --- /dev/null +++ b/app/src/basic_service/device_version_info_mgr.c @@ -0,0 +1,27 @@ +#include "device_version_info_mgr.h" + +#include "aproject_config/config.h" +#include "zble_module.h" +// +#include "znordic.h" +void device_info_read_sn(sn_t *sn) { + uint32_t lot = NRF_UICR->CUSTOMER[0]; + uint32_t id = NRF_UICR->CUSTOMER[1]; + static char sn_str[15]; + sprintf(sn_str, CATEGORY "%04d%05d", lot, id); + if (lot == 0 || id == 0 || lot == 0xffffffff || id == 0xffffffff) { + sprintf(sn_str, "iflytop_test"); + } + memcpy(sn->sn, sn_str, sizeof(sn->sn)); +} + +const char *device_info_read_sn_str() { + static char sn_str[15]; + device_info_read_sn((sn_t *)sn_str); + return sn_str; +} + +uint16_t device_info_read_blestack_version(void) { return BLESTACK_VERSION; } +uint16_t device_info_read_bootloader_version(void) { return BOOTLOADER_VERSION; } +uint16_t device_info_read_firmware_version(void) { return FIRMWARE_VERSION; } +uint16_t device_info_read_hardware_version(void) { return HARDWARE_VERSION; } \ No newline at end of file diff --git a/app/src/basic_service/device_version_info_mgr.h b/app/src/basic_service/device_version_info_mgr.h new file mode 100644 index 0000000..00f9abb --- /dev/null +++ b/app/src/basic_service/device_version_info_mgr.h @@ -0,0 +1,16 @@ +#pragma once +#include "znordic.h" + + + +typedef struct { + uint8_t sn[14]; +} sn_t; + +void device_info_read_sn(sn_t *sn); +const char *device_info_read_sn_str(); + +uint16_t device_info_read_blestack_version(void); +uint16_t device_info_read_bootloader_version(void); +uint16_t device_info_read_firmware_version(void); +uint16_t device_info_read_hardware_version(void); \ No newline at end of file diff --git a/app/src/ble_cmd_process_service.c b/app/src/ble_cmd_process_service.c deleted file mode 100644 index 23b039f..0000000 --- a/app/src/ble_cmd_process_service.c +++ /dev/null @@ -1,482 +0,0 @@ -#include "ble_cmd_process_service.h" - -#include "../../ify_hrs_protocol/heart_rate_sensor_protocol.h" -#include "basic/device_version_info_mgr.h" -#include "board/board.h" -#include "board/board_battery_state.h" -#include "board/board_ecg_sensor.h" -#include "config.h" - -#include "sample_data_manager.h" -#include "zble_module.h" -#include "zdatachannel_service.h" - -APP_TIMER_DEF(m_record_upload_tmr); // Êý¾ÝÉϱ¨¶¨Ê±Æ÷ -APP_TIMER_DEF(m_record_upload_finish_packet_report_tmr); // Êý¾ÝÉϱ¨Íê³ÉÉϱ¨¶¨Ê±Æ÷ -static uint8_t txbuf[128]; -static uint8_t reportbuf[128]; -static bool m_realtime_report_state = false; -static int m_upload_record_state = 0; -static uint32_t m_upload_data_state_enter_tp = 0; - -static bool m_ble_cmder_is_inited = false; -static uint32_t m_report_data_sumcheckcode = 0; - -static void record_upload_tmr_cb(void* p_context); -static void record_upload_finish_packet_report_tmr_cb(void* p_context); -int ble_stop_upload_record(); -/******************************************************************************* - * ¹ã²¥¿ØÖÆ * - *******************************************************************************/ -void ble_cmder_start_adv() { - m_realtime_report_state = false; - zble_module_start_adv(); -} -void ble_cmder_stop_adv() { - zble_module_stop_adv(); - m_realtime_report_state = false; -} - -/******************************************************************************* - * Ä£¿é³õʼ»¯ * - *******************************************************************************/ -void ble_cmder_init() { - if (!m_ble_cmder_is_inited) { - ZERROR_CHECK(app_timer_create(&m_record_upload_tmr, APP_TIMER_MODE_REPEATED, record_upload_tmr_cb)); - ZERROR_CHECK(app_timer_create(&m_record_upload_finish_packet_report_tmr, APP_TIMER_MODE_SINGLE_SHOT, record_upload_finish_packet_report_tmr_cb)); - } - m_ble_cmder_is_inited = true; -} -void ble_cmder_uninit() {} - -/******************************************************************************* - * ʵʱÉϱ¨¿ØÖÆ * - *******************************************************************************/ -int ble_start_realtime_report() { - m_realtime_report_state = true; - return 0; -} -int ble_stop_realtime_report() { - m_realtime_report_state = false; - return 0; -} -void ble_cmder_try_report_one_sample_data(uint32_t frameIndex, uint16_t data0, uint16_t data1, uint16_t data2, uint16_t data3, uint16_t data4) { - if (!m_realtime_report_state) { - return; - } - - heartrate_report_packet_t* reportpacket = (heartrate_report_packet_t*)reportbuf; - reportpacket->cmd = ify_hrs_report_heartrate_data; - reportpacket->frame_index = 0; - reportpacket->frame_type = kifyhrs_pt_report; - reportpacket->sample_data_index = frameIndex; - - reportpacket->data[0] = (data0 >> 0) & 0xFF; // µÚÒ»Ö¡Êý¾Ý - reportpacket->data[1] = (data0 >> 8) & 0xFF; // µÚÒ»Ö¡Êý¾Ý - reportpacket->data[2] = (data1 >> 0) & 0xFF; // µÚ¶þÖ¡Êý¾Ý - reportpacket->data[3] = (data1 >> 8) & 0xFF; // µÚ¶þÖ¡Êý¾Ý - reportpacket->data[4] = (data2 >> 0) & 0xFF; // µÚÈýÖ¡Êý¾Ý - reportpacket->data[5] = (data2 >> 8) & 0xFF; // µÚÈýÖ¡Êý¾Ý - reportpacket->data[6] = (data3 >> 0) & 0xFF; // µÚËÄÖ¡Êý¾Ý - reportpacket->data[7] = (data3 >> 8) & 0xFF; // µÚËÄÖ¡Êý¾Ý - reportpacket->data[8] = (data4 >> 0) & 0xFF; // µÚÎåÖ¡Êý¾Ý - reportpacket->data[9] = (data4 >> 8) & 0xFF; // µÚÎåÖ¡Êý¾Ý - - uint16_t sendlen = sizeof(heartrate_report_packet_t) + 10; - zdatachannel_data_send2(reportbuf, sendlen); - return; -} - -void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1) { - sensor_drop_event_report_packet_t* reportpacket = (sensor_drop_event_report_packet_t*)reportbuf; - reportpacket->cmd = ify_hrs_report_sensor_drop_detect; - reportpacket->frame_index = 0; - reportpacket->frame_type = kifyhrs_pt_report; - reportpacket->drop_state0 = dropstate0; - reportpacket->drop_state1 = dropstate1; - - uint16_t sendlen = sizeof(sensor_drop_event_report_packet_t); - zdatachannel_data_send2(reportbuf, sendlen); - return; -} -void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + 4; - - txheader->cmd = ify_hrs_report_record_upload_end; // 6A - txheader->frame_index = 0; - txheader->frame_type = kifyhrs_pt_report; - - // txheader->data[0] = errorcode; - *(uint32_t*)txheader->data = sumcheckcode; - - zdatachannel_data_send2(txbuf, sendlen); - return; -} - -void ble_cmder_report_sample_finish_event() { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t); - - txheader->cmd = ify_hrs_report_sample_finish_end; - txheader->frame_index = 0; - txheader->frame_type = kifyhrs_pt_report; - - zdatachannel_data_send2(txbuf, sendlen); - return; -} - -/******************************************************************************* - * ÉÏ´«Êý¾Ý¿ØÖÆ * - *******************************************************************************/ -static int m_upload_fd; -static uint8_t datacache[256]; -static int m_remaindatalen = 0; -/** - * @brief Êý¾ÝÉϱ¨¶¨Ê±Æ÷»Øµ÷ - * - * @param p_context - */ -static void record_upload_finish_packet_report_tmr_cb(void* p_context) { // - ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); -} - -static void record_upload_tmr_cb(void* p_context) { // - - if (m_upload_record_state == 0) return; - - if (m_upload_record_state == 1) { - if (m_remaindatalen == 0) { - memset(datacache, 0, sizeof(datacache)); - int32_t rdsize = sample_data_mgr_read(m_upload_fd, datacache, sizeof(datacache)); - if (rdsize <= 0) { - ZLOGI("read file end,stop upload"); - m_upload_record_state = 2; - m_upload_data_state_enter_tp = znordic_getpower_on_ms(); - return; - } - m_remaindatalen = rdsize; - } - if (m_remaindatalen == 0) { - return; - } - - int32_t mtusize = zble_module_get_mtu_size(); - mtusize = mtusize < 128 ? mtusize : 128; - - uint8_t* data = datacache + (sizeof(datacache) - m_remaindatalen); - int len = m_remaindatalen > mtusize ? mtusize : m_remaindatalen; - - ZLOGI("upload %d %d %d", len, m_remaindatalen, mtusize); - if (!zdatachannel_is_connected()) { - ZLOGI("ble is disconnected,stop upload"); - ble_stop_upload_record(); - return; - } - - uint32_t suc = zdatachannel_block_data_send2(data, len); - if (suc != NRF_SUCCESS) { - if (suc == NRF_ERROR_INVALID_STATE) { - // δʹÄÜnotify - ZLOGI("ble unenable notify,stop upload"); - ble_stop_upload_record(); - return; - } else if (suc == NRF_ERROR_BUSY || suc == NRF_ERROR_RESOURCES) { - // µÈ´ýÏ´η¢ËÍ - return; - } else { - ZLOGI("ble send error,stop upload %x", suc); - ble_stop_upload_record(); - return; - } - } - for (uint32_t i = 0; i < len; i++) { - m_report_data_sumcheckcode += data[i]; - } - m_remaindatalen -= len; - } else { - if (znordic_haspassed_ms(m_upload_data_state_enter_tp) > 30) { - ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); - ble_stop_upload_record(); - return; - } - } -} - -int ble_start_upload_record(sample_data_filename_t* recordid) { - // - // Æô¶¯ - // - if (ds_now_state() != kdevice_state_home && ds_now_state() != kdevice_state_charging) { - return kifyhrs_ecode_device_busy; - } - - m_upload_fd = sample_data_mgr_open(recordid, kwrflag_read_only); - if (m_upload_fd <= 0) { - return kifyhrs_ecode_no_record_find; - } - - ZERROR_CHECK(app_timer_start(m_record_upload_tmr, APP_TIMER_TICKS(15), NULL)); - m_upload_record_state = 1; - m_remaindatalen = 0; - m_report_data_sumcheckcode = 0; - return 0; -} -int ble_stop_upload_record() { - m_upload_record_state = 0; - app_timer_stop(m_record_upload_tmr); - if (m_upload_fd > 0) { - sample_data_mgr_close(m_upload_fd); - m_upload_fd = 0; - } - return 0; -} -bool ble_is_upload_record() { return m_upload_record_state != 0; } - -/******************************************************************************* - * UTILS * - *******************************************************************************/ -static void send_error_receipt(ify_hrs_packet_t* rxpacket, int32_t errorcode) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - error_receipt_t* receipt = (error_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(error_receipt_t); - - txheader->cmd = rxpacket->cmd; - txheader->frame_index = rxpacket->frame_index; - txheader->frame_type = kifyhrs_pt_error_receipt; - receipt->errorcode = errorcode; - zdatachannel_data_send2(txbuf, sendlen); -} - -static void send_success_receipt(ify_hrs_packet_t* rxpacket, int32_t emptydatasize) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + emptydatasize; - - txheader->cmd = rxpacket->cmd; - txheader->frame_index = rxpacket->frame_index; - txheader->frame_type = kifyhrs_pt_cmd_receipt; - - zdatachannel_data_send2(txbuf, sendlen); -} - -/******************************************************************************* - * Ï·¢ÏûÏ¢´¦Àí * - *******************************************************************************/ -void ble_cmder_process_rx(uint8_t* rx, int len) { - if (len < sizeof(ify_hrs_packet_t)) { - ZLOGI("rx len error:%d", len); - return; - } - - ify_hrs_packet_t* rxheader = (ify_hrs_packet_t*)rx; - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - ify_hrs_cmd_t cmd = (ify_hrs_cmd_t)rxheader->cmd; - memset(txbuf, 0, sizeof(txbuf)); - - txheader->cmd = rxheader->cmd; - txheader->frame_index = rxheader->frame_index; - txheader->frame_type = kifyhrs_pt_cmd_receipt; - - ZLOGI("rx cmd:%d index:%d datalen:%d", cmd, rxheader->frame_index, len - sizeof(ify_hrs_packet_t)); - NRF_LOG_HEXDUMP_INFO(rx, len); - - if (cmd == ify_hrs_cmd_read_device_version) { - device_version_info_receipt_t* receipt = (device_version_info_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_version_info_receipt_t); - - receipt->blestack_version = device_info_read_blestack_version(); - receipt->bootloader_version = device_info_read_bootloader_version(); - receipt->firmware_version = device_info_read_firmware_version(); - receipt->hardware_version = device_info_read_hardware_version(); - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_read_sensor_info) { - sensor_info_receipt_t* receipt = (sensor_info_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(sensor_info_receipt_t); - - receipt->sensor_num = 1; - receipt->sensor_precision = SAMPLE_PRECISION; - receipt->sensor_sample_rate = SAMPLE_RATE / 10; - receipt->sensor0_pos = kifyhrs_sensor_pos_none; - receipt->sensor1_pos = kifyhrs_sensor_pos_none; - receipt->sensor2_pos = kifyhrs_sensor_pos_none; - - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_read_device_state) { - device_state_receipt_t* receipt = (device_state_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_state_receipt_t); - - receipt->drop_state0 = (!BoardEcgSensor_plod_get_connected_state()); - receipt->drop_state1 = 0x00; - receipt->device_state0.sampling_state = (ds_now_state() == kdevice_state_sampling); - receipt->device_state0.report_state = m_realtime_report_state; - receipt->device_state0.low_battery = (BoardBattery_get_battery_level() < APP_LOW_BATTERY_WARNING_LIMIT); - receipt->device_state0.full_storge = (sample_data_mgr_storage_is_full()); - - receipt->device_state1 = 0; - receipt->powerlevel = BoardBattery_get_battery_level(); - receipt->storage_item_num = sample_data_mgr_get_file_num(); - - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_read_time) { - read_time_receipt_t* receipt = (read_time_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_time_receipt_t); - static ztm_t ztm; - znordic_rtc_gettime(&ztm); - - receipt->year = (ztm.tm_year + 1900 - 2000); - receipt->month = ztm.tm_mon + 1; - receipt->day = ztm.tm_mday; - receipt->hour = ztm.tm_hour; - receipt->minute = ztm.tm_min; - receipt->second = ztm.tm_sec; - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_sync_time) { - sync_time_cmd_t* cmd = (sync_time_cmd_t*)rxheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t); - - znordic_rtc_settime(cmd->year + 2000, cmd->month, cmd->day, cmd->hour, cmd->minute, cmd->second); - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_start_upload_record) { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } - - else if (cmd == ify_hrs_cmd_stop_upload_record) { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } - - else if (cmd == ify_hrs_cmd_start_realtime_preview) { - // unsupport cmd - int ecode = ble_start_realtime_report(); - if (ecode == 0) { - send_success_receipt(rxheader, 8); // ´Õ8¸ö×Ö½Ú£¬Ê¹Õâ¸ö»ØÖ´µÄ×Ö½Ú³¤¶ÈͬÉϱ¨°ü³¤¶ÈÒ»Ö£¬·½±ãµ÷ÊÔ - } else { - send_error_receipt(rxheader, ecode); - } - } - - else if (cmd == ify_hrs_cmd_stop_realtime_preview) { - int ecode = ble_stop_realtime_report(); - if (ecode == 0) { - send_success_receipt(rxheader, 0); - } else { - send_error_receipt(rxheader, ecode); - } - } - - else if (cmd == ify_hrs_cmd_read_records_info) { - // Ö¸Áî 10-¶ÁÈ¡²ÉÑù¼Ç¼ͷ²¿ÐÅÏ¢ - read_record_info_cmd_t* cmd = (read_record_info_cmd_t*)rxheader->data; - read_record_info_receipt_t* receipt = (read_record_info_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_record_info_receipt_t); - - uint8_t recordoff = cmd->record_index; - - // ²ÉÑùʱ²»Ö§³Ö - if (ds_now_state() != kdevice_state_home) { - send_error_receipt(rxheader, kifyhrs_ecode_device_busy); - return; - } - - sample_data_fileinfo_list_t* recordlist = sample_data_mgr_get_fileinfo_list(); - if (recordoff >= recordlist->count) { - send_error_receipt(rxheader, kifyhrs_ecode_no_record_find); - return; - } - - sample_data_fileinfo_t* fileinfo = recordlist->fileinfo[recordoff]; - memcpy(receipt->record_id, fileinfo->filename, 6); - receipt->frameNum = fileinfo->size / 2; // 2byte per frame - receipt->dataSize = fileinfo->size; - receipt->sensorNum = 1; - receipt->captureRate = SAMPLE_RATE / 10; - receipt->capturePrecision = SAMPLE_PRECISION; - receipt->compressAlgorithm = 0; - receipt->checksum = fileinfo->checksum; - zdatachannel_data_send2(txbuf, sendlen); - - } - - else if (cmd == ify_hrs_cmd_del_record) { - // Ö¸Áî 11-ɾ³ý²ÉÑù¼Ç¼ - del_record_cmd_t* cmd = (del_record_cmd_t*)rxheader->data; - - static sample_data_filename_t filename; - memset(&filename, 0, sizeof(filename)); - memcpy(&filename, cmd->record_id, sizeof(cmd->record_id)); - - // ²ÉÑùʱ²»Ö§³Ö - if (ds_now_state() != kdevice_state_home) { - send_error_receipt(rxheader, kifyhrs_ecode_device_busy); - return; - } - - int ecode = sample_data_mgr_delete_file(&filename); - if (ecode == 0) { - send_success_receipt(rxheader, 0); - } else { - send_error_receipt(rxheader, kifyhrs_ecode_unkown_error); - } - } - - else if (cmd == ify_hrs_cmd_start_upload_record) { // 12 0x0C - // Ö¸Áî 12-ÉÏ´«²É¼¯¼Ç¼ - start_upload_record_cmd_t* cmd = (start_upload_record_cmd_t*)rxheader->data; - - static sample_data_filename_t filename; - memset(&filename, 0, sizeof(filename)); - memcpy(&filename, cmd->record_id, sizeof(cmd->record_id)); - - // ²ÉÑùʱ²»Ö§³Ö - if (ds_now_state() != kdevice_state_home) { - send_error_receipt(rxheader, kifyhrs_ecode_device_busy); - return; - } - - int ecode = ble_start_upload_record(&filename); - if (ecode == 0) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + 1; // ´ÕÆë4BYTE£¬·½±ãµ÷ÊÔ - txheader->cmd = rxheader->cmd; - txheader->frame_index = rxheader->frame_index; - txheader->frame_type = kifyhrs_pt_cmd_receipt; - - zdatachannel_data_send2(txbuf, sendlen); - } else { - send_error_receipt(rxheader, ecode); - } - } - - else if (cmd == ify_hrs_cmd_stop_upload_record) { - ble_stop_upload_record(); - send_success_receipt(rxheader, 0); - } - - else if (cmd == ify_hrs_cmd_enter_ota) { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } - - else if (cmd == ify_hrs_cmd_read_sn) { - read_sn_receipt_t* receipt = (read_sn_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_sn_receipt_t); - device_info_read_sn((sn_t*)&receipt->sn); - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_reset) { - NVIC_SystemReset(); - } - // - else { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } -} diff --git a/app/src/ble_cmd_process_service.h b/app/src/ble_cmd_process_service.h deleted file mode 100644 index 889044d..0000000 --- a/app/src/ble_cmd_process_service.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "device_state.h" - -void ble_cmder_init(); -void ble_cmder_uninit(); - -void ble_cmder_process_rx(uint8_t* rx, int len); -void ble_cmder_start_adv(); -void ble_cmder_stop_adv(); - -void ble_cmder_try_report_one_sample_data(uint32_t frameIndex, uint16_t data0, uint16_t data1, uint16_t data2, uint16_t data3, uint16_t data4); -void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1); -void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode); -void ble_cmder_report_sample_finish_event(); -bool ble_is_upload_record(); -int ble_stop_upload_record(); diff --git a/app/src/board/ads1291/ads1291.c b/app/src/board/ads1291/ads1291.c new file mode 100644 index 0000000..556b9fa --- /dev/null +++ b/app/src/board/ads1291/ads1291.c @@ -0,0 +1,133 @@ +#include "ads1291.h" + +#include "ads1291_type.h" + +/** @addtogroup ADS1292R + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +typedef struct { + uint8_t id; /* id£¬ads1292r¹Ì¶¨Îª0x73 ads1291 0x52 */ + uint8_t cfg1; /* ÉèÖüĴæÆ÷ */ + uint8_t cfg2; /* ÉèÖüĴæÆ÷ */ + uint8_t loff; /* µ¼Áª */ + uint8_t ch1set; /* ͨµÀÒ»ÉèÖà */ + uint8_t ch2set; /* ͨµÀ¶þÉèÖà */ + uint8_t rld_sens; /* ÓÒÍÈÇý¶¯ */ + uint8_t loff_sens; /* µ¼Áª */ + uint8_t loff_stat; /* µ¼Áª */ + uint8_t resp1; /* ºôÎü */ + uint8_t resp2; /* ºôÎü */ + uint8_t gpio; /* gpio1£¬2µÄ¿ØÖÆ */ +} ads1292r_regs_s; + +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ +/* ¾Ö²¿È«¾Ö±äÁ¿£¬°üº¬ads1292¼Ä´æÆ÷ĬÈÏÖµ */ +static ads1292r_regs_s ads1292r_reg = { + /* ĬÈϲÎÊý */ + 0x73, /* ĬÈϵØÖ·0x73 */ + 0x02, /* Á¬Ðø×ª»»£¬500sps²ÉÑùÂÊ */ + 0x80, /* µ¼ÁªÍÑÂä±È½ÏÆ÷¹Ø£¬ÄÚ²¿²Î¿¼µçѹ¹Ø£¬2.42v²Î¿¼µçѹ£¬¾§ÕñÊä³ö¹Ø£¬²âÊÔÐźŹأ¬²âÊÔÐÅºÅÆµÂÊΪ0HZ */ + 0x10, /* ÍÑÂä±È½ÏÆ÷Õý¶ËãÐֵΪ95%£¬¸º¶ËΪ5%£¬Òý³öģʽµçÁ÷´óС6na£¬ÆµÂÊΪ0HZ */ + 0x00, /* ͨµÀÒ»¹Ø±Õ£¬6±¶ÔöÒæ£¬Õý³£µç¼«ÊäÈë */ + 0x00, /* ͨµÀ¶þ¹Ø±Õ£¬6±¶ÔöÒæ£¬Õý³£µç¼«ÊäÈë */ + 0x00, /* δÆôÓà */ + 0x00, /* δÆôÓà */ + 0x00, /* fmodΪclkËÄ·ÖÆµ£¬ÆäËûδÓà */ + 0x02, /* ºôÎüÏà¹ØÅäÖà */ + 0x03, /* ºôÎüÏà¹ØÅäÖà */ + 0x0c /* gpio1¡¢2½ÔΪÊäÈëģʽ */ +}; +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + +/* Exported functions --------------------------------------------------------*/ +/* ²»±ØÒª£¬¾¡Á¿²»Òª¶ÔÍ⿪·ÅÒÔϺ¯Êý£¬×îºÃÉèÖóÉstaticÀàÐÍ */ + +/* ads1292r·¢ËÍÖ¸Áî */ +uint8_t ads1292r_send_cmd(uint8_t cmd) { + uint8_t rx = 0; + + ADS1292_CS_RESET(); /* Ñ¡ÖÐÉ豸 */ + port_delay_us(100); + + rx = port_spi_transmit_receive(cmd); + + port_delay_us(100); + ADS1292_CS_SET(); /* ÊÍ·ÅÉ豸 */ + + return rx; +} + +/* ads1292r¶Áд¼Ä´æÆ÷£¬×Ô¶¯¸ù¾ÝÖ¸ÁîÀàÐÍÇø·Ö¶ÁºÍд²Ù×÷ */ +uint8_t ads1292r_rw_reg(uint8_t cmd, uint8_t data) { + uint8_t rx = 0; + + ADS1292_CS_RESET(); /* Ñ¡ÖÐÉ豸 */ + port_delay_us(1); + + port_spi_transmit_receive(cmd); /* ·¢ËͶÁдָÁî */ + port_spi_transmit_receive(0X00); /* ֻдһ¸öÊý¾Ý */ + + if ((cmd & ADS1292R_COMMAND_RREG) == ADS1292R_COMMAND_RREG) /* ÅжÏÖ¸ÁîÀàÐÍ */ + rx = port_spi_transmit_receive(0X00); /* ·µ»Ø¼Ä´æÆ÷Öµ */ + else + rx = port_spi_transmit_receive(data); /* дÈëÊýÖµ */ + + port_delay_us(1); + ADS1292_CS_SET(); /* ÊÍ·ÅÉ豸 */ + + return rx; +} + +/* ´ÓÖ¸¶¨¼Ä´æÆ÷¿ªÊ¼¶Áдһ¶¨ÊýÁ¿µÄ¼Ä´æÆ÷ */ +void ads1292r_write_multiregs(uint8_t reg, uint8_t *ch, uint8_t size) { + uint8_t i; + + ADS1292_CS_RESET(); /* Ñ¡ÖÐÉ豸 */ + port_delay_us(100); + + port_spi_transmit_receive(ADS1292R_COMMAND_WREG | reg); + port_delay_us(100); + port_spi_transmit_receive(size - 1); + + for (i = 0; i < size; i++) { + port_delay_us(100); + port_spi_transmit_receive(*ch); + ch++; + } + + port_delay_us(100); + ADS1292_CS_SET(); +} + +/* ´ÓÖ¸¶¨¼Ä´æÆ÷¿ªÊ¼¶Áдһ¶¨ÊýÁ¿µÄ¼Ä´æÆ÷ */ +void ads1292r_read_multiregs(uint8_t reg, uint8_t *ch, uint8_t size) { + uint8_t i; + + ADS1292_CS_RESET(); /* Ñ¡ÖÐÉ豸 */ + port_delay_us(100); + + port_spi_transmit_receive(ADS1292R_COMMAND_RREG | reg); + port_delay_us(100); + port_spi_transmit_receive(size - 1); + + for (i = 0; i < size; i++) { + port_delay_us(100); + *ch = port_spi_transmit_receive(0); + ch++; + } + + port_delay_us(100); + ADS1292_CS_SET(); +} + +uint8_t ads1292r_init(uint8_t timeout); +void ads1292r_normal_adc_start(void); +void ads1292r_test_adc_start(void); +void ads1292r_get_value(uint8_t *ad_buf); diff --git a/app/src/board/ads1291/ads1291.h b/app/src/board/ads1291/ads1291.h new file mode 100644 index 0000000..daac12f --- /dev/null +++ b/app/src/board/ads1291/ads1291.h @@ -0,0 +1,28 @@ +#ifndef __ADS1292R_H +#define __ADS1292R_H + +#ifdef __cplusplus +extern "C" { +#endif +#include +uint8_t ads1292r_init(uint8_t timeout); + +/** @brief ¿ªÆô˫ͨµÀÕý³£Ä£Ê½²ÉÑù£¬ÓÃÓÚÐĵç²É¼¯ + * @details 500sps£¬6±¶ÔöÒæ£¬µ÷Óøú¯ÊýºóÐèµ÷ÓöÁº¯Êý£¬¶ÁÈ¡adÊý¾Ý + * @retval NONE + */ +void ads1292r_normal_adc_start(void); + +/** @brief ¿ªÆôË«²âÊÔÐźÅadcת»»¡£ + * @details 500sps£¬6±¶ÔöÒæ£¬1HZ·½²¨£¬µ÷Óøú¯ÊýºóÐèµ÷ÓöÁº¯Êý£¬¶ÁÈ¡adÊý¾Ý + * @retval NONE + */ +void ads1292r_test_adc_start(void); + +void ads1292r_get_value(uint8_t *ad_buf); + +#ifdef __cplusplus +} +#endif + +#endif /* __ADS1292R_H */ diff --git a/app/src/board/ads1291/ads1291_type.h b/app/src/board/ads1291/ads1291_type.h new file mode 100644 index 0000000..3b7089f --- /dev/null +++ b/app/src/board/ads1291/ads1291_type.h @@ -0,0 +1,330 @@ +/** + ****************************************************************************** + * @file : ads1291_typ.h + * @brief : ads1291Ïà¹ØÊý¾ÝÀàÐͶ¨Òå + * @details : ¼Ä´æÆ÷±ê¡¢ÃüÁî±í¡¢ + * @author : + * @date : 2020/9/2 + * @version : V0.1 + * @copyright : Copyright (C) + ****************************************************************************** + * @attention + * NONE + ****************************************************************************** + * @verbatim + * ÐÞ¸ÄÀúÊ·: + * 1. ÈÕÆÚ£º2020/9/2 + * ×÷ÕߣºCharmander + * Ð޸ģº + * @endverbatim + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __ADS1292_TYP_H +#define __ADS1292_TYP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** @defgroup ADS1291_TYP ADS1291 TYP + * @{ + */ +/* Exported types ------------------------------------------------------------*/ +/** @addtogroup ADS1291_TYP_Exported_types ADS1291 TYP Exported types + * @{ + */ + +/** @brief ¼Ä´æÆ÷µØÖ·Ã¶¾Ù + * @details 11¸ö¼Ä´æÆ÷ + */ +typedef enum { + ADS1291_REG_ID = 0x00, + ADS1291_REG_CONFIG1 = 0x01, + ADS1291_REG_CONFIG2 = 0x02, + ADS1291_REG_LOFF = 0x03, + ADS1291_REG_CH1SET = 0x04, + ADS1291_REG_CH2SET = 0x05, + ADS1291_REG_RLDSENS = 0x06, + ADS1291_REG_LOFFSENS = 0x07, + ADS1291_REG_LOFFSTAT = 0x08, + ADS1291_REG_RESP1 = 0x09, + ADS1291_REG_RESP2 = 0x0A, + ADS1291_REG_GPIO = 0x0B +} ADS1291_REG_E; + +/** + * @} + */ + +/** @addtogroup ADS1291_TYP_Exported_constants ADS1291 TYP Exported constants + * @brief Ò»ÏÂÄÚÈÝÒ²¿ÉÒÔÈ«²¿ÓÉλÓò+ö¾ÙʵÏÖ£¬¿¼Âǵ½²»ÊÇËùÓбàÒëÆ÷¶¼Ö§³Ö£¬ + * ²ÉÓúê+ÑÚÂ뷽ʽʵÏÖ¡£ + * @{ + */ + +/* Exported constants --------------------------------------------------------*/ +#define ADS1291_REG_SIZE_MAX 12 /* ADS1291¼Ä´æÆ÷ÊýÁ¿ */ + +/** @addtogroup ADS1291_TYP_REG_CONTENT ADS1291 TYP Exported content + * @brief ¸÷¼Ä´æÆ÷ÄÚÈÝ + * @{ + */ +/* оƬID */ +#define ADS1291_ID 0x73 + +/* ÊôÓÚADS1291_REG_CONFIG1µÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_SINGLE_SHOT_OFF 0 /* Á¬Ðø×ª»»Ä£Ê½,ĬÈÏ */ +#define ADS1291_SINGLE_SHOT_ON 1 /* µ¥´Îת»»Ä£Ê½ */ +/* ²ÉÑùÂÊ£¬¸ÃÄ£¿é²ÉÓÃfclkΪ512k£¬0·ÖƵģʽ£¬ÆäËûÅäÖÃϲÉÑùÂÊ»á¸Ä±ä */ +#define ADS1291_OVERSAMPLING_125SPS 0 +#define ADS1291_OVERSAMPLING_250SPS 1 +#define ADS1291_OVERSAMPLING_500SPS 2 /* ĬÈÏ */ +#define ADS1291_OVERSAMPLING_1000SPS 3 +#define ADS1291_OVERSAMPLING_2000SPS 4 +#define ADS1291_OVERSAMPLING_4000SPS 5 +#define ADS1291_OVERSAMPLING_8000SPS 6 +#define ADS1291_OVERSAMPLING_NONESPS 7 + +/* ÊôÓÚADS1291_REG_CONFIG2µÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_PDB_LOFF_COMP_OFF 0 /* µ¼ÁªÍÑÂä±È½ÏÆ÷¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_PDB_LOFF_COMP_ON 1 /* µ¼ÁªÍÑÂä±È½ÏÆ÷¿ª */ +#define ADS1291_PDB_REFBUF_OFF 0 /* ÄÚ²¿²Î¿¼µçѹ¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_PDB_REFBUF_ON 1 /* ÄÚ²¿²Î¿¼µçѹ¿ª */ +#define ADS1291_VREF_2420MV 0 /* Ñ¡Ôñ²Î¿¼µçѹΪ2.42v£¬Ä¬ÈÏ */ +#define ADS1291_VREF_4033MV 1 /* Ñ¡Ôñ²Î¿¼µçѹΪ4.033v */ +#define ADS1291_CLK_OUTPUT_OFF 0 /* ʱÖÓÊä³ö¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_CLK_OUTPUT_ON 1 /* ʱÖÓÊä³ö¿ª */ +#define ADS1291_INT_TEST_OFF 0 /* ÄÚ²¿²âÊÔµçѹ¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_INT_TEST_ON 1 /* ÄÚ²¿²âÊÔµçѹ¿ª */ +#define ADS1291_INT_FREQ_DC 0 /* Ö±Á÷£¬Ä¬ÈÏ */ +#define ADS1291_INT_FREQ_AC 1 /* 1HZ·½²¨ */ + +/* ÊôÓÚADS1291_REG_LOFFµÄ¼Ä´æÆ÷ÉèÖà */ + +/* ÊôÓÚADS1291_REG_CH1SET£¬ÓëADS1291_REG_CH2SETµÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_CHx_OFF 1 /* ½ûֹʹÓÃͨµÀÒ» */ +#define ADS1291_CHx_ON 0 /* ʹÓÃͨµÀÒ»£¬Ä¬ÈÏ */ + +#define ADS1291_GAIN_6 0 /* ʹÓÃͨµÀÒ»6±¶ÔöÒæ£¬Ä¬ÈÏ */ +#define ADS1291_GAIN_1 1 /* ʹÓÃͨµÀÒ»1±¶ÔöÒæ */ +#define ADS1291_GAIN_2 2 /* ʹÓÃͨµÀÒ»2±¶ÔöÒæ */ +#define ADS1291_GAIN_3 3 /* ʹÓÃͨµÀÒ»3±¶ÔöÒæ */ +#define ADS1291_GAIN_4 4 /* ʹÓÃͨµÀÒ»4±¶ÔöÒæ */ +#define ADS1291_GAIN_8 5 /* ʹÓÃͨµÀÒ»8±¶ÔöÒæ */ +#define ADS1291_GAIN_12 6 /* ʹÓÃͨµÀÒ»12±¶ÔöÒæ */ +/* Ñ¡ÔñͨµÀÒ»µÄÊäÈë */ +#define ADS1291_CHx_INPUT_NORMAL 0 /* Õý³£µç¼«ÊäÈ룬ĬÈÏ */ +#define ADS1291_CHx_INPUT_SHORTED 1 /* ¶Ì·£¬²âƫִÓà */ +#define ADS1291_CHx_INPUT_RLD 2 /* ÓÒÍÈÇý¶¯ */ +/* For channel 1, (MVDDP ¨C MVDDN) is [0.5(AVDD + AVSS)]; for channel 2, (MVDDP ¨C MVDDN) is DVDD / 4. */ +/* For channel 2,VDD / 2 for supply measurement */ +#define ADS1291_CHx_INPUT_MVDD 3 +#define ADS1291_CHx_INPUT_TEMP 4 /* °åÔØÎÂ¶È */ +#define ADS1291_CHx_INPUT_TEST 5 /* ÄÚ²¿²âÊÔÐźŠ*/ +#define ADS1291_CHx_INPUT_RLDDRP 6 +#define ADS1291_CHx_INPUT_RLDDRM 7 +#define ADS1291_CHx_INPUT_RLDDRPM 8 +#define ADS1291_CHx_INPUT_ROUTE 9 /* Á¬½Óµ½Í¨µÀÈý */ +#define ADS1291_CHx_INPUT_RESERVED 10 /* Ô¤Áô */ + +/* ÊôÓÚADS1291_REG_RLDSENSµÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_CHOP_FREQ_DIV4 3 /* PGAÕ¶²¨ÆµÂÊδfMOD/4 */ +#define ADS1291_PDB_RLD_OFF 0 /* ÓÒÍÈÇý¶¯µçÔ´¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_PDB_RLD_ON 1 /* ÓÒÍÈÇý¶¯µçÔ´¿ª */ +#define ADS1291_PDB_RLD_SENSE_OFF 0 /* ÓÒÍÈÇý¶¯µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_PDB_RLD_SENSE_ON 1 /* ÓÒÍÈÇý¶¯µ¼ÁªÍÑÂä¼ì²â¿ª */ +#define ADS1291_RLD2N_OFF 0 /* ͨµÀ¶þ¸º¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_RLD2N_ON 1 /* ͨµÀ¶þ¸º¼«ÎªÓÒÍÈÊäÈ뿪 */ +#define ADS1291_RLD2P_OFF 0 /* ͨµÀ¶þÕý¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_RLD2P_ON 1 /* ͨµÀ¶þÕý¼«ÎªÓÒÍÈÊäÈ뿪 */ +#define ADS1291_RLD1N_OFF 0 /* ͨµÀÒ»¸º¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_RLD1N_ON 1 /* ͨµÀÒ»¸º¼«ÎªÓÒÍÈÊäÈ뿪 */ +#define ADS1291_RLD1P_OFF 0 /* ͨµÀÒ»Õý¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_RLD1P_ON 1 /* ͨµÀÒ»Õý¼«ÎªÓÒÍÈÊäÈ뿪 */ + +/* ÊôÓÚADS1291_REG_LOFFSENSµÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_FLIP2_OFF 0 /* µ¼ÁªÍÑÂä¼ì²âͨµÀ¶þµçÁ÷·½Ïò¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_FLIP2_ON 1 /* µ¼ÁªÍÑÂä¼ì²âͨµÀ¶þµçÁ÷·½Ïò¿ª */ +#define ADS1291_FLIP1_OFF 0 /* µ¼ÁªÍÑÂä¼ì²âͨµÀÒ»µçÁ÷·½Ïò¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_FLIP1_ON 1 /* µ¼ÁªÍÑÂä¼ì²âͨµÀÒ»µçÁ÷·½Ïò¿ª */ +#define ADS1291_LOFF2N_OFF 0 /* ͨµÀ¶þ¸º¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_LOFF2N_ON 1 /* ͨµÀ¶þ¸º¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ +#define ADS1291_LOFF2P_OFF 0 /* ͨµÀ¶þÕý¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_LOFF2P_ON 1 /* ͨµÀ¶þÕý¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ +#define ADS1291_LOFF1N_OFF 0 /* ͨµÀÒ»¸º¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_LOFF1N_ON 1 /* ͨµÀÒ»¸º¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ +#define ADS1291_LOFF1P_OFF 0 /* ͨµÀÒ»Õý¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_LOFF1P_ON 1 /* ͨµÀÒ»Õý¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ + +/* ÊôÓÚADS1291_REG_LOFFSTATµÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_CLK_DIV4 0 /* 0 = fMOD = fCLK / 4 (default, use when fCLK = 512 kHz) */ +#define ADS1291_CLK_DIV16 1 /* 1 = fMOD = fCLK / 16 (use when fCLK = 2.048 MHz) */ + +/* ÊôÓÚADS1291_REG_RESP1µÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_DEMOD_EN1_OFF 0 /* ͨµÀÒ»ÉϵĺôÎü½âµ÷µç·¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_DEMOD_EN1_ON 1 /* ͨµÀÒ»ÉϵĺôÎü½âµ÷µç·¿ª */ +#define ADS1291_DEMOD_EN_OFF 0 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_DEMOD_EN_ON 1 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¿ª */ +#define ADS1291_RESPPH_0 0 /* ½âµ÷ÐźÅÏàÎ»Æ«ÒÆ0£¬Ä¬ÈÏ */ +#define ADS1291_RESPPH_135 0x0c /* ½âµ÷ÐźÅÏàÎ»Æ«ÒÆ135¶È */ +#define ADS1291_RESP_CTRL_INT 0 /* ÄÚ²¿ºôÎüÄÚ²¿Ê±ÖÓ£¬Ä¬ÈÏ */ +#define ADS1291_RESP_CTRL_EXT 1 /* ÄÚ²¿ºôÎüÍⲿʱÖÓ */ + +/* ÊôÓÚADS1291_REG_RESP2µÄ¼Ä´æÆ÷ÉèÖà */ +#define ADS1291_CALIB_ON_OFF 0 /* У׼¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_CALIB_ON_ON 1 /* У׼¿ª */ +#define ADS1291_RESP_FREQ_36 0 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¹Ø£¬Ä¬ÈÏ */ +#define ADS1291_RESP_FREQ_64 1 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¿ª */ +#define ADS1291_RLDREF_EXT 0 /* ÓÒÍÈÇý¶¯²Î¿¼µçѹѡÔñÍⲿ·´À¡£¬Ä¬ÈÏ */ +#define ADS1291_RLDREF_INT 1 /* ÓÒÍÈÇý¶¯²Î¿¼µçѹѡÔñÄÚ²¿ÐźŠ*/ + +/* ÊôÓÚADS1291_REG_GPIOµÄ¼Ä´æÆ÷ÉèÖà */ +/** + * @} + */ + +/** @addtogroup ADS1291_TYP_REG_MASK ADS1291 TYP Reg Mask + * @brief ¸÷¼Ä´æÆ÷ÖµÓëλÖÃÑÚÂ룬±»ADS1291_GET_BITSÓëADS1291_SET_BITSº¯Êýµ÷Óà + * @{ + */ +#define ADS1291_ID_POS 0 +#define ADS1291_ID_MASK 0xFF + +#define ADS1291_SINGLE_SHOT_POS 7 +#define ADS1291_SINGLE_SHOT_MASK 0x80 +#define ADS1291_DR_POS 0 +#define ADS1291_DR_MASK 0x07 + +#define ADS1291_PDB_LOFF_COMP_POS 6 +#define ADS1291_PDB_LOFF_COMP_MASK 0x40 +#define ADS1291_PDB_REFBUF_POS 5 +#define ADS1291_PDB_REFBUF_MASK 0x20 +#define ADS1291_VREF_4V_POS 4 +#define ADS1291_VREF_4V_MASK 0x10 +#define ADS1291_CLK_EN_POS 3 +#define ADS1291_CLK_EN_MASK 0x80 +#define ADS1291_INT_TEST_POS 1 +#define ADS1291_INT_TEST_MASK 0x02 +#define ADS1291_INT_FREQ_POS 0 +#define ADS1291_INT_FREQ_MASK 0x01 + +#define ADS1291_PDx_POS 7 +#define ADS1291_PDx_MASK 0x80 +#define ADS1291_GAINx_POS 4 +#define ADS1291_GAINx_MASK 0x70 +#define ADS1291_MUXx_POS 0 +#define ADS1291_MUXx_MASK 0x0F + +#define ADS1291_CHOP_POS 6 +#define ADS1291_CHOP_MASK 0xC0 +#define ADS1291_PDB_RLD_POS 5 +#define ADS1291_PDB_RLD_MASK 0x20 +#define ADS1291_RLD_LOFF_SENSE_POS 4 +#define ADS1291_RLD_LOFF_SENSE_MASK 0x10 +#define ADS1291_RLD2N_POS 3 +#define ADS1291_RLD2N_MASK 0x08 +#define ADS1291_RLD2P_POS 2 +#define ADS1291_RLD2P_MASK 0x04 +#define ADS1291_RLD1N_POS 1 +#define ADS1291_RLD1N_MASK 0x02 +#define ADS1291_RLD1P_POS 0 +#define ADS1291_RLD1P_MASK 0x01 + +#define ADS1291_FLIP2_POS 5 +#define ADS1291_FLIP2_MASK 0x20 +#define ADS1291_FLIP1_POS 4 +#define ADS1291_FLIP1_MASK 0x10 +#define ADS1291_LOFF2N_POS 3 +#define ADS1291_LOFF2N_MASK 0x08 +#define ADS1291_LOFF2P_POS 2 +#define ADS1291_LOFF2P_MASK 0x04 +#define ADS1291_LOFFN_POS 1 +#define ADS1291_LOFF1N_MASK 0x02 +#define ADS1291_LOFF1P_POS 0 +#define ADS1291_LOFF1P_MASK 0x01 + +#define ADS1291_CLK_DIV_POS 6 +#define ADS1291_CLK_DIV_MASK 0x40 + +#define ADS1291_RESP_DEMOD_EN1_POS 7 +#define ADS1291_RESP_DEMOD_EN1_MASK 0x80 +#define ADS1291_RESP_MOD_EN_POS 6 +#define ADS1291_RESP_MOD_EN_MASK 0x40 +#define ADS1291_RESP_PH_POS 2 +#define ADS1291_RESP_PH_MASK 0x3c +#define ADS1291_RESP_CTRL_POS 0 +#define ADS1291_RESP_CTRL_MASK 0x01 + +#define ADS1291_CALIB_ON_POS 7 +#define ADS1291_CALIB_ON_MASK 0x80 +#define ADS1291_RESP_FREQ_POS 2 +#define ADS1291_RESP_FREQ_MASK 0x04 +#define ADS1291_RLDREF_INT_POS 1 +#define ADS1291_RLDREF_INT_MASK 0x02 + +/** + * @} + */ + +/** @addtogroup ADS1291_TYP_COMMAND ADS1291 TYP COMMAND + * @brief ÃüÁî + * @{ + */ +/* System Commands */ +#define ADS1291_COMMAND_WAKEUP 0x02 +#define ADS1291_COMMAND_STANDBY 0x04 +#define ADS1291_COMMAND_RESET 0x06 +#define ADS1291_COMMAND_START 0x08 +#define ADS1291_COMMAND_STOP 0x0A +#define ADS1291_COMMAND_OFFSETCAL 0x1A + +/* Data Read Commands */ +#define ADS1291_COMMAND_RDATAC 0x10 +#define ADS1291_COMMAND_SDATAC 0x11 +#define ADS1291_COMMAND_RDATA 0x12 + +/* Register Read Commands£¬×îºó5λΪ¶ÁдµÄµØÖ· */ +#define ADS1291_COMMAND_RREG 0x20 +#define ADS1291_COMMAND_WREG 0x40 +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/* Exported macro ------------------------------------------------------------*/ +/** @brief ¶ÁÈ¡ADS1291µÄÖ¸¶¨¼Ä´æÆ÷µÄÖ¸¶¨Î» + * @details + * @param[in] bitname λÃû×Ö + * @param[in] reg ¼Ä´æÆ÷Ãû×Ö + * @retval ¸ÃλµÄÖµ + */ +#define ADS1291_GET_BITS(bitname, reg) ((reg & bitname##_MASK) >> bitname##_POS) + +/** @brief ÉèÖÃADS1291µÄÖ¸¶¨¼Ä´æÆ÷µÄÖ¸¶¨Î» + * @details + * @param[in] reg ¼Ä´æÆ÷Ãû×Ö + * @param[in] bitname λÃû×Ö + * @param[in] val ÒªÉèÖõÄÖµ + * @retval NONE + */ +#define ADS1291_SET_BITS(reg, bitname, val) ((reg & ~bitname##_MASK) | ((val << bitname##_POS) & bitname##_MASK)) +/* Exported functions --------------------------------------------------------*/ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __ADS1292_TYP_H */ diff --git a/app/src/board/ads1291/ads1292r_typ.h b/app/src/board/ads1291/ads1292r_typ.h deleted file mode 100644 index 8c3d47d..0000000 --- a/app/src/board/ads1291/ads1292r_typ.h +++ /dev/null @@ -1,337 +0,0 @@ -/** - ****************************************************************************** - * @file : ads1292r_typ.h - * @brief : ads1292rÏà¹ØÊý¾ÝÀàÐͶ¨Òå - * @details : ¼Ä´æÆ÷±ê¡¢ÃüÁî±í¡¢ - * @author : - * @date : 2020/9/2 - * @version : V0.1 - * @copyright : Copyright (C) - ****************************************************************************** - * @attention - * NONE - ****************************************************************************** - * @verbatim - * ÐÞ¸ÄÀúÊ·: - * 1. ÈÕÆÚ£º2020/9/2 - * ×÷ÕߣºCharmander - * Ð޸ģº - * @endverbatim - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __ADS1292_TYP_H -#define __ADS1292_TYP_H - -#ifdef __cplusplus -extern "C" { -#endif - - - -/** @defgroup ADS1292R_TYP ADS1292R TYP - * @{ - */ -/* Exported types ------------------------------------------------------------*/ -/** @addtogroup ADS1292R_TYP_Exported_types ADS1292R TYP Exported types - * @{ - */ - -/** @brief ¼Ä´æÆ÷µØÖ·Ã¶¾Ù - * @details 11¸ö¼Ä´æÆ÷ - */ -typedef enum -{ - ADS1292R_REG_ID = 0x00 , - ADS1292R_REG_CONFIG1 = 0x01 , - ADS1292R_REG_CONFIG2 = 0x02 , - ADS1292R_REG_LOFF = 0x03 , - ADS1292R_REG_CH1SET = 0x04 , - ADS1292R_REG_CH2SET = 0x05 , - ADS1292R_REG_RLDSENS = 0x06 , - ADS1292R_REG_LOFFSENS = 0x07 , - ADS1292R_REG_LOFFSTAT = 0x08 , - ADS1292R_REG_RESP1 = 0x09 , - ADS1292R_REG_RESP2 = 0x0A , - ADS1292R_REG_GPIO = 0x0B -}ADS1292R_REG_E ; - -/** - * @} - */ - -/** @addtogroup ADS1292R_TYP_Exported_constants ADS1292R TYP Exported constants - * @brief Ò»ÏÂÄÚÈÝÒ²¿ÉÒÔÈ«²¿ÓÉλÓò+ö¾ÙʵÏÖ£¬¿¼Âǵ½²»ÊÇËùÓбàÒëÆ÷¶¼Ö§³Ö£¬ - * ²ÉÓúê+ÑÚÂ뷽ʽʵÏÖ¡£ - * @{ - */ - -/* Exported constants --------------------------------------------------------*/ -#define ADS1292R_REG_SIZE_MAX 12 /* ADS1292R¼Ä´æÆ÷ÊýÁ¿ */ - -/** @addtogroup ADS1292R_TYP_REG_CONTENT ADS1292R TYP Exported content - * @brief ¸÷¼Ä´æÆ÷ÄÚÈÝ - * @{ - */ -/* оƬID */ -#define ADS1292R_ID 0x73 - -/* ÊôÓÚADS1292R_REG_CONFIG1µÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_SINGLE_SHOT_OFF 0 /* Á¬Ðø×ª»»Ä£Ê½,ĬÈÏ */ -#define ADS1292R_SINGLE_SHOT_ON 1 /* µ¥´Îת»»Ä£Ê½ */ -/* ²ÉÑùÂÊ£¬¸ÃÄ£¿é²ÉÓÃfclkΪ512k£¬0·ÖƵģʽ£¬ÆäËûÅäÖÃϲÉÑùÂÊ»á¸Ä±ä */ -#define ADS1292R_OVERSAMPLING_125SPS 0 -#define ADS1292R_OVERSAMPLING_250SPS 1 -#define ADS1292R_OVERSAMPLING_500SPS 2 /* ĬÈÏ */ -#define ADS1292R_OVERSAMPLING_1000SPS 3 -#define ADS1292R_OVERSAMPLING_2000SPS 4 -#define ADS1292R_OVERSAMPLING_4000SPS 5 -#define ADS1292R_OVERSAMPLING_8000SPS 6 -#define ADS1292R_OVERSAMPLING_NONESPS 7 - -/* ÊôÓÚADS1292R_REG_CONFIG2µÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_PDB_LOFF_COMP_OFF 0 /* µ¼ÁªÍÑÂä±È½ÏÆ÷¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_PDB_LOFF_COMP_ON 1 /* µ¼ÁªÍÑÂä±È½ÏÆ÷¿ª */ -#define ADS1292R_PDB_REFBUF_OFF 0 /* ÄÚ²¿²Î¿¼µçѹ¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_PDB_REFBUF_ON 1 /* ÄÚ²¿²Î¿¼µçѹ¿ª */ -#define ADS1292R_VREF_2420MV 0 /* Ñ¡Ôñ²Î¿¼µçѹΪ2.42v£¬Ä¬ÈÏ */ -#define ADS1292R_VREF_4033MV 1 /* Ñ¡Ôñ²Î¿¼µçѹΪ4.033v */ -#define ADS1292R_CLK_OUTPUT_OFF 0 /* ʱÖÓÊä³ö¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_CLK_OUTPUT_ON 1 /* ʱÖÓÊä³ö¿ª */ -#define ADS1292R_INT_TEST_OFF 0 /* ÄÚ²¿²âÊÔµçѹ¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_INT_TEST_ON 1 /* ÄÚ²¿²âÊÔµçѹ¿ª */ -#define ADS1292R_INT_FREQ_DC 0 /* Ö±Á÷£¬Ä¬ÈÏ */ -#define ADS1292R_INT_FREQ_AC 1 /* 1HZ·½²¨ */ - -/* ÊôÓÚADS1292R_REG_LOFFµÄ¼Ä´æÆ÷ÉèÖà */ - -/* ÊôÓÚADS1292R_REG_CH1SET£¬ÓëADS1292R_REG_CH2SETµÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_CHx_OFF 1 /* ½ûֹʹÓÃͨµÀÒ» */ -#define ADS1292R_CHx_ON 0 /* ʹÓÃͨµÀÒ»£¬Ä¬ÈÏ */ - -#define ADS1292R_GAIN_6 0 /* ʹÓÃͨµÀÒ»6±¶ÔöÒæ£¬Ä¬ÈÏ */ -#define ADS1292R_GAIN_1 1 /* ʹÓÃͨµÀÒ»1±¶ÔöÒæ */ -#define ADS1292R_GAIN_2 2 /* ʹÓÃͨµÀÒ»2±¶ÔöÒæ */ -#define ADS1292R_GAIN_3 3 /* ʹÓÃͨµÀÒ»3±¶ÔöÒæ */ -#define ADS1292R_GAIN_4 4 /* ʹÓÃͨµÀÒ»4±¶ÔöÒæ */ -#define ADS1292R_GAIN_8 5 /* ʹÓÃͨµÀÒ»8±¶ÔöÒæ */ -#define ADS1292R_GAIN_12 6 /* ʹÓÃͨµÀÒ»12±¶ÔöÒæ */ -/* Ñ¡ÔñͨµÀÒ»µÄÊäÈë */ -#define ADS1292R_CHx_INPUT_NORMAL 0 /* Õý³£µç¼«ÊäÈ룬ĬÈÏ */ -#define ADS1292R_CHx_INPUT_SHORTED 1 /* ¶Ì·£¬²âƫִÓà */ -#define ADS1292R_CHx_INPUT_RLD 2 /* ÓÒÍÈÇý¶¯ */ -/* For channel 1, (MVDDP ¨C MVDDN) is [0.5(AVDD + AVSS)]; for channel 2, (MVDDP ¨C MVDDN) is DVDD / 4. */ -/* For channel 2,VDD / 2 for supply measurement */ -#define ADS1292R_CHx_INPUT_MVDD 3 -#define ADS1292R_CHx_INPUT_TEMP 4 /* °åÔØÎÂ¶È */ -#define ADS1292R_CHx_INPUT_TEST 5 /* ÄÚ²¿²âÊÔÐźŠ*/ -#define ADS1292R_CHx_INPUT_RLDDRP 6 -#define ADS1292R_CHx_INPUT_RLDDRM 7 -#define ADS1292R_CHx_INPUT_RLDDRPM 8 -#define ADS1292R_CHx_INPUT_ROUTE 9 /* Á¬½Óµ½Í¨µÀÈý */ -#define ADS1292R_CHx_INPUT_RESERVED 10 /* Ô¤Áô */ - -/* ÊôÓÚADS1292R_REG_RLDSENSµÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_CHOP_FREQ_DIV4 3 /* PGAÕ¶²¨ÆµÂÊδfMOD/4 */ -#define ADS1292R_PDB_RLD_OFF 0 /* ÓÒÍÈÇý¶¯µçÔ´¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_PDB_RLD_ON 1 /* ÓÒÍÈÇý¶¯µçÔ´¿ª */ -#define ADS1292R_PDB_RLD_SENSE_OFF 0 /* ÓÒÍÈÇý¶¯µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_PDB_RLD_SENSE_ON 1 /* ÓÒÍÈÇý¶¯µ¼ÁªÍÑÂä¼ì²â¿ª */ -#define ADS1292R_RLD2N_OFF 0 /* ͨµÀ¶þ¸º¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_RLD2N_ON 1 /* ͨµÀ¶þ¸º¼«ÎªÓÒÍÈÊäÈ뿪 */ -#define ADS1292R_RLD2P_OFF 0 /* ͨµÀ¶þÕý¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_RLD2P_ON 1 /* ͨµÀ¶þÕý¼«ÎªÓÒÍÈÊäÈ뿪 */ -#define ADS1292R_RLD1N_OFF 0 /* ͨµÀÒ»¸º¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_RLD1N_ON 1 /* ͨµÀÒ»¸º¼«ÎªÓÒÍÈÊäÈ뿪 */ -#define ADS1292R_RLD1P_OFF 0 /* ͨµÀÒ»Õý¼«ÎªÓÒÍÈÊäÈë¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_RLD1P_ON 1 /* ͨµÀÒ»Õý¼«ÎªÓÒÍÈÊäÈ뿪 */ - -/* ÊôÓÚADS1292R_REG_LOFFSENSµÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_FLIP2_OFF 0 /* µ¼ÁªÍÑÂä¼ì²âͨµÀ¶þµçÁ÷·½Ïò¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_FLIP2_ON 1 /* µ¼ÁªÍÑÂä¼ì²âͨµÀ¶þµçÁ÷·½Ïò¿ª */ -#define ADS1292R_FLIP1_OFF 0 /* µ¼ÁªÍÑÂä¼ì²âͨµÀÒ»µçÁ÷·½Ïò¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_FLIP1_ON 1 /* µ¼ÁªÍÑÂä¼ì²âͨµÀÒ»µçÁ÷·½Ïò¿ª */ -#define ADS1292R_LOFF2N_OFF 0 /* ͨµÀ¶þ¸º¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_LOFF2N_ON 1 /* ͨµÀ¶þ¸º¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ -#define ADS1292R_LOFF2P_OFF 0 /* ͨµÀ¶þÕý¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_LOFF2P_ON 1 /* ͨµÀ¶þÕý¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ -#define ADS1292R_LOFF1N_OFF 0 /* ͨµÀÒ»¸º¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_LOFF1N_ON 1 /* ͨµÀÒ»¸º¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ -#define ADS1292R_LOFF1P_OFF 0 /* ͨµÀÒ»Õý¼«µ¼ÁªÍÑÂä¼ì²â¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_LOFF1P_ON 1 /* ͨµÀÒ»Õý¼«µ¼ÁªÍÑÂä¼ì²â¿ª */ - -/* ÊôÓÚADS1292R_REG_LOFFSTATµÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_CLK_DIV4 0 /* 0 = fMOD = fCLK / 4 (default, use when fCLK = 512 kHz) */ -#define ADS1292R_CLK_DIV16 1 /* 1 = fMOD = fCLK / 16 (use when fCLK = 2.048 MHz) */ - -/* ÊôÓÚADS1292R_REG_RESP1µÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_DEMOD_EN1_OFF 0 /* ͨµÀÒ»ÉϵĺôÎü½âµ÷µç·¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_DEMOD_EN1_ON 1 /* ͨµÀÒ»ÉϵĺôÎü½âµ÷µç·¿ª */ -#define ADS1292R_DEMOD_EN_OFF 0 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_DEMOD_EN_ON 1 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¿ª */ -#define ADS1292R_RESPPH_0 0 /* ½âµ÷ÐźÅÏàÎ»Æ«ÒÆ0£¬Ä¬ÈÏ */ -#define ADS1292R_RESPPH_135 0x0c /* ½âµ÷ÐźÅÏàÎ»Æ«ÒÆ135¶È */ -#define ADS1292R_RESP_CTRL_INT 0 /* ÄÚ²¿ºôÎüÄÚ²¿Ê±ÖÓ£¬Ä¬ÈÏ */ -#define ADS1292R_RESP_CTRL_EXT 1 /* ÄÚ²¿ºôÎüÍⲿʱÖÓ */ - -/* ÊôÓÚADS1292R_REG_RESP2µÄ¼Ä´æÆ÷ÉèÖà */ -#define ADS1292R_CALIB_ON_OFF 0 /* У׼¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_CALIB_ON_ON 1 /* У׼¿ª */ -#define ADS1292R_RESP_FREQ_36 0 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¹Ø£¬Ä¬ÈÏ */ -#define ADS1292R_RESP_FREQ_64 1 /* ͨµÀÒ»ÉϵĺôÎüµ÷ÖÆµç·¿ª */ -#define ADS1292R_RLDREF_EXT 0 /* ÓÒÍÈÇý¶¯²Î¿¼µçѹѡÔñÍⲿ·´À¡£¬Ä¬ÈÏ */ -#define ADS1292R_RLDREF_INT 1 /* ÓÒÍÈÇý¶¯²Î¿¼µçѹѡÔñÄÚ²¿ÐźŠ*/ - -/* ÊôÓÚADS1292R_REG_GPIOµÄ¼Ä´æÆ÷ÉèÖà */ -/** - * @} - */ - -/** @addtogroup ADS1292R_TYP_REG_MASK ADS1292R TYP Reg Mask - * @brief ¸÷¼Ä´æÆ÷ÖµÓëλÖÃÑÚÂ룬±»ADS1292R_GET_BITSÓëADS1292R_SET_BITSº¯Êýµ÷Óà - * @{ - */ -#define ADS1292R_ID_POS 0 -#define ADS1292R_ID_MASK 0xFF - -#define ADS1292R_SINGLE_SHOT_POS 7 -#define ADS1292R_SINGLE_SHOT_MASK 0x80 -#define ADS1292R_DR_POS 0 -#define ADS1292R_DR_MASK 0x07 - -#define ADS1292R_PDB_LOFF_COMP_POS 6 -#define ADS1292R_PDB_LOFF_COMP_MASK 0x40 -#define ADS1292R_PDB_REFBUF_POS 5 -#define ADS1292R_PDB_REFBUF_MASK 0x20 -#define ADS1292R_VREF_4V_POS 4 -#define ADS1292R_VREF_4V_MASK 0x10 -#define ADS1292R_CLK_EN_POS 3 -#define ADS1292R_CLK_EN_MASK 0x80 -#define ADS1292R_INT_TEST_POS 1 -#define ADS1292R_INT_TEST_MASK 0x02 -#define ADS1292R_INT_FREQ_POS 0 -#define ADS1292R_INT_FREQ_MASK 0x01 - -#define ADS1292R_PDx_POS 7 -#define ADS1292R_PDx_MASK 0x80 -#define ADS1292R_GAINx_POS 4 -#define ADS1292R_GAINx_MASK 0x70 -#define ADS1292R_MUXx_POS 0 -#define ADS1292R_MUXx_MASK 0x0F - -#define ADS1292R_CHOP_POS 6 -#define ADS1292R_CHOP_MASK 0xC0 -#define ADS1292R_PDB_RLD_POS 5 -#define ADS1292R_PDB_RLD_MASK 0x20 -#define ADS1292R_RLD_LOFF_SENSE_POS 4 -#define ADS1292R_RLD_LOFF_SENSE_MASK 0x10 -#define ADS1292R_RLD2N_POS 3 -#define ADS1292R_RLD2N_MASK 0x08 -#define ADS1292R_RLD2P_POS 2 -#define ADS1292R_RLD2P_MASK 0x04 -#define ADS1292R_RLD1N_POS 1 -#define ADS1292R_RLD1N_MASK 0x02 -#define ADS1292R_RLD1P_POS 0 -#define ADS1292R_RLD1P_MASK 0x01 - -#define ADS1292R_FLIP2_POS 5 -#define ADS1292R_FLIP2_MASK 0x20 -#define ADS1292R_FLIP1_POS 4 -#define ADS1292R_FLIP1_MASK 0x10 -#define ADS1292R_LOFF2N_POS 3 -#define ADS1292R_LOFF2N_MASK 0x08 -#define ADS1292R_LOFF2P_POS 2 -#define ADS1292R_LOFF2P_MASK 0x04 -#define ADS1292R_LOFFN_POS 1 -#define ADS1292R_LOFF1N_MASK 0x02 -#define ADS1292R_LOFF1P_POS 0 -#define ADS1292R_LOFF1P_MASK 0x01 - -#define ADS1292R_CLK_DIV_POS 6 -#define ADS1292R_CLK_DIV_MASK 0x40 - -#define ADS1292R_RESP_DEMOD_EN1_POS 7 -#define ADS1292R_RESP_DEMOD_EN1_MASK 0x80 -#define ADS1292R_RESP_MOD_EN_POS 6 -#define ADS1292R_RESP_MOD_EN_MASK 0x40 -#define ADS1292R_RESP_PH_POS 2 -#define ADS1292R_RESP_PH_MASK 0x3c -#define ADS1292R_RESP_CTRL_POS 0 -#define ADS1292R_RESP_CTRL_MASK 0x01 - -#define ADS1292R_CALIB_ON_POS 7 -#define ADS1292R_CALIB_ON_MASK 0x80 -#define ADS1292R_RESP_FREQ_POS 2 -#define ADS1292R_RESP_FREQ_MASK 0x04 -#define ADS1292R_RLDREF_INT_POS 1 -#define ADS1292R_RLDREF_INT_MASK 0x02 - -/** - * @} - */ - -/** @addtogroup ADS1292R_TYP_COMMAND ADS1292R TYP COMMAND - * @brief ÃüÁî - * @{ - */ -/* System Commands */ -#define ADS1292R_COMMAND_WAKEUP 0x02 -#define ADS1292R_COMMAND_STANDBY 0x04 -#define ADS1292R_COMMAND_RESET 0x06 -#define ADS1292R_COMMAND_START 0x08 -#define ADS1292R_COMMAND_STOP 0x0A -#define ADS1292R_COMMAND_OFFSETCAL 0x1A - -/* Data Read Commands */ -#define ADS1292R_COMMAND_RDATAC 0x10 -#define ADS1292R_COMMAND_SDATAC 0x11 -#define ADS1292R_COMMAND_RDATA 0x12 - -/* Register Read Commands£¬×îºó5λΪ¶ÁдµÄµØÖ· */ -#define ADS1292R_COMMAND_RREG 0x20 -#define ADS1292R_COMMAND_WREG 0x40 -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/* Exported macro ------------------------------------------------------------*/ -/** @brief ¶ÁÈ¡ADS1292RµÄÖ¸¶¨¼Ä´æÆ÷µÄÖ¸¶¨Î» - * @details - * @param[in] bitname λÃû×Ö - * @param[in] reg ¼Ä´æÆ÷Ãû×Ö - * @retval ¸ÃλµÄÖµ - */ -#define ADS1292R_GET_BITS(bitname, reg) ((reg & bitname##_MASK) >> bitname##_POS) - -/** @brief ÉèÖÃADS1292RµÄÖ¸¶¨¼Ä´æÆ÷µÄÖ¸¶¨Î» - * @details - * @param[in] reg ¼Ä´æÆ÷Ãû×Ö - * @param[in] bitname λÃû×Ö - * @param[in] val ÒªÉèÖõÄÖµ - * @retval NONE - */ -#define ADS1292R_SET_BITS(reg, bitname, val) ((reg & ~bitname##_MASK) \ - | ((val << bitname##_POS) & bitname##_MASK)) -/* Exported functions --------------------------------------------------------*/ - - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADS1292_TYP_H */ - - diff --git a/app/src/board/board.h b/app/src/board/board.h deleted file mode 100644 index 937cc3a..0000000 --- a/app/src/board/board.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -/******************************************************************************* - * BEEP * - *******************************************************************************/ -#define BEEP_PIN 1 -#define BEEP_PWM_INSTANCE 0 - -/******************************************************************************* - * ADC * - *******************************************************************************/ - -#define ECG_NLOD_PIN 3 -#define ECG_PLOD_PIN 28 -#define ECG_ADC_PIN NRF_SAADC_INPUT_AIN0 -#define ECG_ADC_CHANNEL 0 // ²»Öظ´¼´¿É - -#define BATTERY_ADC_PIN NRF_SAADC_INPUT_AIN3 -#define BATTERY_ADC_CHANNEL 1 // ²»Öظ´¼´¿É -#define BATTERY_CHARGE_DETECT_PIN 6 - -/** - * @brief - */ - -#define MAX_STORAGE_TIMEOUT_S (60 * 10) // ×´æ´¢Ê±¼ä -#define MAX_STORAGE_SIZE (MAX_STORAGE_TIMEOUT_S * 400) // ´æ´¢×î´óÏÞÖÆÎª (256-8)kbyte -#define MAX_FILE_NUM 10 // ×î¶à´æ´¢ÌõÄ¿Êý -#define SAMPLE_RATE 500 // ²ÉÑùÂÊ -#define SAMPLE_PRECISION 12 // ²ÉÑù¾«¶È -#define AUTOMATIC_SLEEP_TIME 30000 // ¿ª»úºó×Ô¶¯ÐÝÃßʱ¼ä -#define SAMPLE_MIN_TIME_S (30.0) // ²ÉÑù×îСʱ¼ä -#define LITTLE_DATA_BLOCK_FRAME_NUM 5 // ÿ´Î¶àÉÙÖ¡Éϱ¨Ò»´Î - -#define KEEP_STILL_OVERTIME_MS_1P5 1500 // ±£³Ö¾²Ö¹³¬Ê±Ê±¼äµÄ1/6 - -#define LED_GREEN_PIN 9 -#define LED_BLUE_PIN 10 -#define LED_RED_PIN 39 - -#define HEART_WAVE_SAMPLE_TMR_INSTANCE 3 - -#define LIGHT_PWM_INSTANCE 1 - -// #define APP_BATTERY_PROTECT_LEVEL 2 // µÍÓڴ˵çÁ¿²»ÄÜ¿ª»ú£¬±£»¤µç³Ø -// #define APP_AUTO_STANDY_BATTERY_LEVEL 5 // µÍÓڴ˵çÁ¿×Ô¶¯´ý»ú,±£³ÖʱÖÓ -// #define APP_WORK_BATTERY_LEVEL 10 // Main³õʼ»¯Ê±ºòºÍ´ÓstandyÇл»µ½workµÄʱºò£¬¼ì²éÕâ¸öµçÁ¿ -#define APP_LOW_BATTERY_WARNING_LIMIT 20 // - -#define LOW_BATTERY_REMINDER_DELAY_MS 3000 -#define BLE_UNCONNECTED_OVERTIME_S 300 \ No newline at end of file diff --git a/app/src/board/board_adc_module_ctrl.h b/app/src/board/board_adc_module_ctrl.h index 28b27a1..49d2dc3 100644 --- a/app/src/board/board_adc_module_ctrl.h +++ b/app/src/board/board_adc_module_ctrl.h @@ -3,7 +3,7 @@ #include #include -#include "board/board.h" +#include "aproject_config/config.h" #include "znordic.h" void BoardAdc_init(); diff --git a/app/src/board/board_battery_state.c b/app/src/board/board_battery_state.c index c4ac135..55e8ae9 100644 --- a/app/src/board/board_battery_state.c +++ b/app/src/board/board_battery_state.c @@ -1,7 +1,7 @@ #include "board_battery_state.h" -#include "app_event.h" +#include "basic_service/app_event.h" #include "board_adc_module_ctrl.h" /******************************************************************************* * Battery * diff --git a/app/src/board/board_battery_state.h b/app/src/board/board_battery_state.h index df44b76..54825c6 100644 --- a/app/src/board/board_battery_state.h +++ b/app/src/board/board_battery_state.h @@ -3,7 +3,7 @@ #include #include -#include "board/board.h" +#include "aproject_config/config.h" #include "znordic.h" void BoardBattery_init(); diff --git a/app/src/board/board_beep_ctrl.h b/app/src/board/board_beep_ctrl.h index 6aef541..70cc354 100644 --- a/app/src/board/board_beep_ctrl.h +++ b/app/src/board/board_beep_ctrl.h @@ -3,7 +3,7 @@ #include #include -#include "board/board.h" +#include "aproject_config/config.h" #include "znordic.h" typedef enum { diff --git a/app/src/board/board_ecg_sensor.c b/app/src/board/board_ecg_sensor.c index 0406900..48d19c0 100644 --- a/app/src/board/board_ecg_sensor.c +++ b/app/src/board/board_ecg_sensor.c @@ -1,7 +1,6 @@ #include "board_ecg_sensor.h" -#include "ads1291/ads1292r_typ.h" -#include "app_event_distribute.h" +#include "basic_service/app_event_distribute.h" #include "board_adc_module_ctrl.h" #if 0 @@ -64,7 +63,7 @@ int16_t BoardEcgSensor_set_sence_state() { } #endif - +#if 0 void BoardEcgSensor_load() {} void BoardEcgSensor_unload() {} @@ -167,12 +166,12 @@ uint8_t ads1292r_rw_reg(uint8_t cmd, uint8_t data) { return rx; } -#define port_delay_ms nrf_delay_ms -#define port_delay_us nrf_delay_us +#define port_delay_ms nrf_delay_ms +#define port_delay_us nrf_delay_us #define ADS1292_START_RESET() nrf_gpio_pin_clear(ADS1291_START_PIN) -#define ADS1292_START_SET() nrf_gpio_pin_set(ADS1291_START_PIN) -#define ADS1292_REST_RESET() nrf_gpio_pin_clear(ADS1291_PWDN_PIN) -#define ADS1292_REST_SET() nrf_gpio_pin_set(ADS1291_PWDN_PIN) +#define ADS1292_START_SET() nrf_gpio_pin_set(ADS1291_START_PIN) +#define ADS1292_REST_RESET() nrf_gpio_pin_clear(ADS1291_PWDN_PIN) +#define ADS1292_REST_SET() nrf_gpio_pin_set(ADS1291_PWDN_PIN) uint8_t ads1292r_send_cmd(uint8_t cmd) { uint8_t rx = 0; @@ -187,6 +186,7 @@ uint8_t ads1292r_send_cmd(uint8_t cmd) { return rx; } +void znrf_serial_tx(char const * p_buffer, size_t len); void BoardEcgSensor_init() { /** @@ -195,8 +195,6 @@ void BoardEcgSensor_init() { ads1291_init(); - - ADS1292_CS_SET(); ADS1292_REST_RESET(); @@ -214,11 +212,26 @@ void BoardEcgSensor_init() { nrf_gpio_pin_set(ADS1291_PWDN_PIN); nrf_delay_ms(2000); - + char txdata[]= {1,2,3,4}; while (true) /* ʶ±ðоƬÐͺţ¬1291:0x52 */ { uint8_t id = ads1292r_rw_reg(ADS1292R_COMMAND_RREG | ADS1292R_REG_ID, 0); - ZLOGI("ads1292r id:%x", id); + znrf_serial_tx(txdata,4); + znordic_force_flush_log(); nrf_delay_ms(1000); } } + +#endif + +void BoardEcgSensor_init() {} +void BoardEcgSensor_load() {} +void BoardEcgSensor_unload() {} + +int16_t BoardEcgSensor_nlod_get_connected_state() { return 0; } +int16_t BoardEcgSensor_plod_get_connected_state() { return 0; } +int16_t BoardEcgSensor_plod_get_connected_state_after_filter() { return 0; } +int16_t BoardEcgSensor_plod_state_has_disconnected_ms() { return 0; } + +int16_t BoardEcgSensor_plod_get_ecg_val() { return 0; } +int16_t BoardEcgSensor_set_sence_state() { return 0; } diff --git a/app/src/board/board_ecg_sensor.h b/app/src/board/board_ecg_sensor.h index 9fbc59b..74ab33c 100644 --- a/app/src/board/board_ecg_sensor.h +++ b/app/src/board/board_ecg_sensor.h @@ -3,7 +3,7 @@ #include #include -#include "board/board.h" +#include "aproject_config/config.h" #include "znordic.h" void BoardEcgSensor_init(); diff --git a/app/src/board/board_eeprom_driver.c b/app/src/board/board_eeprom_driver.c index 30ce9da..e1948a5 100644 --- a/app/src/board/board_eeprom_driver.c +++ b/app/src/board/board_eeprom_driver.c @@ -14,8 +14,6 @@ #include "nrf_drv_wdt.h" #include "nrf_gpio.h" // -#include "basic/ssd1306/driver_ssd1306.h" -#include "basic/ssd1306/driver_ssd1306_basic.h" #define EEPROM_I2C_SCL_M 15 // I2C SCLÒý½Å #define EEPROM_I2C_SDA_M 17 // I2C SDAÒý½Å diff --git a/app/src/board/board_light_ctrl.c b/app/src/board/board_light_ctrl.c index 06c6a50..0bc64ea 100644 --- a/app/src/board/board_light_ctrl.c +++ b/app/src/board/board_light_ctrl.c @@ -1,6 +1,5 @@ #include "board_light_ctrl.h" - -#include "board.h" +#include "aproject_config/config.h" #include "znordic.h" #include "nrf_gpio.h" diff --git a/app/src/board/board_light_ctrl.h b/app/src/board/board_light_ctrl.h index f307f28..31ed0a4 100644 --- a/app/src/board/board_light_ctrl.h +++ b/app/src/board/board_light_ctrl.h @@ -3,7 +3,7 @@ #include #include -#include "board/board.h" +#include "aproject_config/config.h" typedef enum { kLightEffect_unset, diff --git a/app/src/board/board_ssd1306_interface.c b/app/src/board/board_ssd1306_interface.c index 8349517..f914fb6 100644 --- a/app/src/board/board_ssd1306_interface.c +++ b/app/src/board/board_ssd1306_interface.c @@ -2,7 +2,6 @@ #include -#include "basic/ssd1306/driver_ssd1306_interface.h" #include "znordic.h" // #include "app_timer.h" @@ -11,8 +10,9 @@ #include "nrf_delay.h" #include "nrf_gpio.h" // -#include "basic/ssd1306/driver_ssd1306.h" -#include "basic/ssd1306/driver_ssd1306_basic.h" +#include "ssd1306/driver_ssd1306.h" +#include "ssd1306/driver_ssd1306_basic.h" +#include "ssd1306/driver_ssd1306_interface.h" #define SCREEN_SPI_INSTANCE 0 #define SCREEN_RESET_PIN 20 diff --git a/app/src/board/board_ssd1306_interface.h b/app/src/board/board_ssd1306_interface.h index bb746db..bbb2c9b 100644 --- a/app/src/board/board_ssd1306_interface.h +++ b/app/src/board/board_ssd1306_interface.h @@ -6,6 +6,10 @@ #include #include "znordic.h" +#include "board/ssd1306/driver_ssd1306.h" +#include "board/ssd1306/driver_ssd1306_basic.h" +#include "board/ssd1306/wave_drawer.h" + void board_screen_init(); void board_screen_deinit(); diff --git a/app/src/board/ssd1306/driver_ssd1306.c b/app/src/board/ssd1306/driver_ssd1306.c new file mode 100644 index 0000000..ba880cb --- /dev/null +++ b/app/src/board/ssd1306/driver_ssd1306.c @@ -0,0 +1,2353 @@ +/** + * Copyright (c) 2015 - present LibDriver All rights reserved + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file driver_ssd1306.c + * @brief driver ssd1306 source file + * @version 2.0.0 + * @author Shifeng Li + * @date 2021-03-30 + * + *

history

+ * + *
Date Version Author Description + *
2021/03/30 2.0 Shifeng Li format the code + *
2020/12/10 1.0 Shifeng Li first upload + *
+ */ + +#include "driver_ssd1306.h" +#include "driver_ssd1306_font.h" + +/** + * @brief chip information definition + */ +#define CHIP_NAME "Solomon Systech SSD1306" /**< chip name */ +#define MANUFACTURER_NAME "Solomon Systech" /**< manufacturer name */ +#define SUPPLY_VOLTAGE_MIN 1.65f /**< chip min supply voltage */ +#define SUPPLY_VOLTAGE_MAX 3.3f /**< chip max supply voltage */ +#define MAX_CURRENT 0.78f /**< chip max current */ +#define TEMPERATURE_MIN -40.0f /**< chip min operating temperature */ +#define TEMPERATURE_MAX 85.0f /**< chip max operating temperature */ +#define DRIVER_VERSION 2000 /**< driver version */ + +/** + * @brief chip command data definition + */ +#define SSD1306_CMD 0 /**< command */ +#define SSD1306_DATA 1 /**< data */ + +/** + * @brief chip command definition + */ +#define SSD1306_CMD_LOWER_COLUMN_START_ADDRESS 0x00 /**< command lower column start address */ +#define SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS 0x10 /**< command higher column start address */ +#define SSD1306_CMD_MEMORY_ADDRESSING_MODE 0x20 /**< command memory addressing mode */ +#define SSD1306_CMD_SET_COLUMN_ADDRESS 0x21 /**< command set column address */ +#define SSD1306_CMD_SET_PAGE_ADDRESS 0x22 /**< command set page address */ +#define SSD1306_CMD_SET_FADE_OUT_AND_BLINKING 0x23 /**< command set fade out and blinking */ +#define SSD1306_CMD_RIGHT_HORIZONTAL_SCROLL 0x26 /**< command right horizontal scroll */ +#define SSD1306_CMD_LEFT_HORIZONTAL_SCROLL 0x27 /**< command left horizontal scroll */ +#define SSD1306_CMD_VERTICAL_RIGHT_HORIZONTAL_SCROLL 0x29 /**< command vertical right horizontal scroll */ +#define SSD1306_CMD_VERTICAL_LEFT_HORIZONTAL_SCROLL 0x2A /**< command vertical left horizontal scroll */ +#define SSD1306_CMD_DEACTIVATE_SCROLL 0x2E /**< command deactivate scroll */ +#define SSD1306_CMD_ACTIVATE_SCROLL 0x2F /**< command activate scroll */ +#define SSD1306_CMD_DISPLAY_START_LINE 0x40 /**< command display start line */ +#define SSD1306_CMD_CONTRAST_CONTROL 0x81 /**< command contrast control */ +#define SSD1306_CMD_CHARGE_PUMP_SETTING 0x8D /**< command charge pump setting */ +#define SSD1306_CMD_COLUMN_0_MAPPED_TO_SEG0 0xA0 /**< command column 0 mapped to seg 0 */ +#define SSD1306_CMD_COLUMN_127_MAPPED_TO_SEG0 0xA1 /**< command column 127 mapped to seg 0 */ +#define SSD1306_CMD_VERTICAL_SCROLL_AREA 0xA3 /**< command vertical scroll area */ +#define SSD1306_CMD_ENTIRE_DISPLAY_OFF 0xA4 /**< command entire display off */ +#define SSD1306_CMD_ENTIRE_DISPLAY_ON 0xA5 /**< command entire display on */ +#define SSD1306_CMD_NORMAL_DISPLAY 0xA6 /**< command normal display */ +#define SSD1306_CMD_INVERSE_DISPLAY 0xA7 /**< command inverse display */ +#define SSD1306_CMD_MULTIPLEX_RATIO 0xA8 /**< command multiplex ratio */ +#define SSD1306_CMD_DISPLAY_OFF 0xAE /**< command display off */ +#define SSD1306_CMD_DISPLAY_ON 0xAF /**< command display on */ +#define SSD1306_CMD_PAGE_ADDR 0xB0 /**< command page address */ +#define SSD1306_CMD_SCAN_DIRECTION_COM0_START 0xC0 /**< command scan direction com 0 start */ +#define SSD1306_CMD_SCAN_DIRECTION_COMN_1_START 0xC8 /**< command scan direction com n-1 start */ +#define SSD1306_CMD_DISPLAY_OFFSET 0xD3 /**< command display offset */ +#define SSD1306_CMD_DISPLAY_CLOCK_DIVIDE 0xD5 /**< command display clock divide */ +#define SSD1306_CMD_SET_ZOOM_IN 0xD6 /**< command set zoom in */ +#define SSD1306_CMD_PRE_CHARGE_PERIOD 0xD9 /**< command pre charge period */ +#define SSD1306_CMD_COM_PINS_CONF 0xDA /**< command com pins conf */ +#define SSD1306_CMD_COMH_DESLECT_LEVEL 0xDB /**< command comh deslect level */ +#define SSD1306_CMD_NOP 0xE3 /**< command nop */ + +/** + * @brief write one byte + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] data is the write data + * @param[in] cmd is the command or data type + * @return status code + * - 0 success + * - 1 write failed + * @note none + */ +static uint8_t a_ssd1306_write_byte(ssd1306_handle_t *handle, uint8_t data, uint8_t cmd) +{ + uint8_t res; + + if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic */ + { + if (cmd != 0) /* if data */ + { + if (handle->iic_write(handle->iic_addr, 0x40, &data, 1) != 0) /* write data */ + { + return 1; /* return error */ + } + else + { + return 0; /* success return 0 */ + } + } + else + { + if (handle->iic_write(handle->iic_addr, 0x00, &data, 1) != 0) /* write command */ + { + return 1; /* return error */ + } + else + { + return 0; /* success return 0 */ + } + } + } + else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi */ + { + res = handle->spi_cmd_data_gpio_write(cmd); /* write data command */ + if (res != 0) /* check error */ + { + return 1; /* return error */ + } + + if (handle->spi_write_cmd(&data, 1) != 0) /* write command */ + { + return 1; /* return error */ + } + else + { + return 0; /* success return 0 */ + } + } + else + { + return 1; /* return error */ + } +} + +/** + * @brief write multiple bytes + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] *data points to a data buffer + * @param[in] len is the data length + * @param[in] cmd is the command or data type + * @return status code + * - 0 success + * - 1 write failed + * @note none + */ +static uint8_t a_ssd1306_multiple_write_byte(ssd1306_handle_t *handle, uint8_t *data, uint8_t len, uint8_t cmd) +{ + uint8_t res; + + if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic */ + { + if (cmd != 0) /* if data */ + { + if (handle->iic_write(handle->iic_addr, 0x40, data, len) != 0) /* write data */ + { + return 1; /* return error */ + } + else + { + return 0; /* success return 0 */ + } + } + else + { + if (handle->iic_write(handle->iic_addr, 0x00, data, len) != 0) /* write command */ + { + return 1; /* return error */ + } + else + { + return 0; /* success return 0 */ + } + } + } + else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi */ + { + res = handle->spi_cmd_data_gpio_write(cmd); /* write data command */ + if (res != 0) /* check error */ + { + return 1; /* return error */ + } + + if (handle->spi_write_cmd(data, len) != 0) /* write command */ + { + return 1; /* return error */ + } + else + { + return 0; /* success return 0 */ + } + } + else + { + return 1; /* return error */ + } +} + +/** + * @brief draw a point in gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] data is the write data + * @return status code + * - 0 success + * - 1 gram draw point failed + * @note none + */ +static uint8_t a_ssd1306_gram_draw_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data) +{ + uint8_t pos; + uint8_t bx; + uint8_t temp = 0; + + pos = y / 8; /* get y page */ + bx = y % 8; /* get y point */ + temp = 1 << bx; /* set data */ + if (data != 0) /* if 1 */ + { + handle->gram[x][pos] |= temp; /* set 1 */ + } + else + { + handle->gram[x][pos] &= ~temp; /* set 0 */ + } + + return 0; /* success return 0 */ +} + +/** + * @brief draw a char in gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] chr is the write char + * @param[in] size is the char size + * @param[in] mode is the display mode + * @return status code + * - 0 success + * - 1 gram show char failed + * @note none + */ +static uint8_t a_ssd1306_gram_show_char(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t chr, uint8_t size, uint8_t mode) +{ + uint8_t temp, t, t1; + uint8_t y0 = y; + uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); /* get size */ + + chr = chr - ' '; /* get index */ + for (t = 0; t < csize; t++) /* write size */ + { + if (size == 12) /* if size 12 */ + { + temp = gsc_ssd1306_ascii_1206[chr][t]; /* get ascii 1206 */ + } + else if (size == 16) /* if size 16 */ + { + temp = gsc_ssd1306_ascii_1608[chr][t]; /* get ascii 1608 */ + } + else if(size == 24) /* if size 24 */ + { + temp = gsc_ssd1306_ascii_2412[chr][t]; /* get ascii 2412 */ + } + else + { + return 1; /* return error */ + } + for (t1 = 0; t1 < 8; t1++) /* write one line */ + { + if ((temp & 0x80) != 0) /* if 1 */ + { + if (a_ssd1306_gram_draw_point(handle, x, y, mode) != 0) /* draw point */ + { + return 1; /* return error */ + } + } + else + { + if (a_ssd1306_gram_draw_point(handle, x, y, !mode) != 0) /* draw point */ + { + return 1; /* return error */ + } + } + temp <<= 1; /* left shift 1 */ + y++; + if ((y - y0) == size) /* reset size */ + { + y = y0; /* set y */ + x++; /* x++ */ + + break; /* break */ + } + } + } + + return 0; /* success return 0 */ +} + +/** + * @brief clear the screen + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 clear failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_clear(ssd1306_handle_t *handle) +{ + uint8_t i; + uint8_t n; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + for (i = 0; i < 8; i++) /* write 8 page */ + { + if (a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR+i, SSD1306_CMD) != 0) /* set page */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + if (a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set lower column 0 */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + if (a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set higher column 0 */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + for (n = 0; n < 128; n++) /* write 128 */ + { + handle->gram[n][i] = 0x00; /* set black */ + if (a_ssd1306_write_byte(handle, handle->gram[n][i], SSD1306_DATA) != 0) /* write data */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + } + } + + return 0; /* success return 0 */ +} + +/** + * @brief update the gram data + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 gram update failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_gram_update(ssd1306_handle_t *handle) +{ + uint8_t i; + uint8_t n; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + for (i = 0; i < 8; i++) /* write 8 page */ + { + if (a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR+i, SSD1306_CMD) != 0) /* set page */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + if (a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set lower column 0 */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + if (a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS, SSD1306_CMD) != 0) /* set higher column 0 */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + for (n = 0; n < 128; n++) /* write 128 */ + { + // handle->delay_ms(100); + if (a_ssd1306_write_byte(handle, handle->gram[n][i], SSD1306_DATA) != 0) /* write data */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + } + } + + return 0; /* success return 0 */ +} + +/** + * @brief write a point + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] data is the write data + * @return status code + * - 0 success + * - 1 write point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data) +{ + uint8_t pos; + uint8_t bx; + uint8_t temp = 0; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if ((x > 127) || (y > 63)) /* check x, y */ + { + + return 4; /* return error */ + } + + pos = y / 8; /* get y page */ + bx = y % 8; /* get y point */ + temp = 1 << bx; /* set data */ + if (data != 0) /* check the data */ + { + handle->gram[x][pos] |= temp; /* set 1 */ + } + else + { + handle->gram[x][pos] &= ~temp; /* set 0 */ + } + #if 1 + if (a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR + pos, SSD1306_CMD) != 0) /* write page addr */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + if (a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS|(x&0x0F), SSD1306_CMD) != 0) /* write lower column */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + if (a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS|((x>>4)&0x0F), SSD1306_CMD) != 0) /* write higher column */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + return 1; /* return error */ + } + if (a_ssd1306_write_byte(handle, handle->gram[x][pos], SSD1306_DATA) != 0) /* write data */ + { + handle->debug_print("ssd1306: write byte failed.\n"); /* write byte failed */ + + return 1; /* return error */ + } + else + { + return 0; /* success return 0 */ + } + #endif + return 0; +} + +/** + * @brief read a point + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[out] *data points to a data buffer + * @return status code + * - 0 success + * - 1 read point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data) +{ + uint8_t pos; + uint8_t bx; + uint8_t temp = 0; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if ((x > 127) || (y > 63)) /* check x, y */ + { + + return 4; /* return error */ + } + + pos = y / 8; /* get y page */ + bx = y % 8; /* get y point */ + temp = 1 << bx; /* set data */ + if ((handle->gram[x][pos] & temp) != 0) /* get data */ + { + *data = 1; /* set 1 */ + } + else + { + *data = 0; /* set 0 */ + } + + return 0; /* success return 0 */ +} + +/** + * @brief write a point in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] data is the write data + * @return status code + * - 0 success + * - 1 gram write point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_gram_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data) +{ + uint8_t pos; + uint8_t bx; + uint8_t temp = 0; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if ((x > 127) || (y > 63)) /* check x, y */ + { + return 4; /* return error */ + } + + pos = y / 8; /* get y page */ + bx = y % 8; /* get y point */ + temp = 1 << bx; /* set data */ + if (data != 0) /* if 1 */ + { + handle->gram[x][pos] |= temp; /* set 1 */ + } + else + { + handle->gram[x][pos] &= ~temp; /* set 0 */ + } + + return 0; /* success return 0 */ +} + +/** + * @brief read a point from the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[out] *data points to a data buffer + * @return status code + * - 0 success + * - 1 gram read point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_gram_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data) +{ + uint8_t pos; + uint8_t bx; + uint8_t temp = 0; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if ((x > 127) || (y > 63)) /* check x, y */ + { + + return 4; /* return error */ + } + + pos = y / 8; /* get y page */ + bx = y % 8; /* get y point */ + temp = 1 << bx; /* set data */ + if ((handle->gram[x][pos] & temp) != 0) /* get data */ + { + *data = 1; /* set 1 */ + } + else + { + *data = 0; /* set 0 */ + } + + return 0; /* success return 0 */ +} + +/** + * @brief draw a string in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] *str points to a write string address + * @param[in] len is the length of the string + * @param[in] color is the display color + * @param[in] font is the display font size + * @return status code + * - 0 success + * - 1 gram write string failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_gram_write_string(ssd1306_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if((x > 127) || (y > 63)) /* check x, y */ + { + + return 4; /* return error */ + } + + while ((len != 0) && (*str <= '~') && (*str >= ' ')) /* write all string */ + { + if (x > (127 - (font / 2))) /* check x point */ + { + x = 0; /* set x */ + y += (uint8_t)font; /* set next row */ + } + if (y > (63 - font)) /* check y pont */ + { + y = x = 0; /* reset to 0,0 */ + } + if (a_ssd1306_gram_show_char(handle, x, y, *str, font, color) != 0) /* show a char */ + { + return 1; /* return error */ + } + x += (uint8_t)(font / 2); /* x + font/2 */ + str++; /* str address++ */ + len--; /* str length-- */ + } + + return 0; /* success return 0 */ +} + +/** + * @brief fill a rectangle in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] color is the display color + * @return status code + * - 0 success + * - 1 gram fill rect failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 left or top is invalid + * - 5 right or bottom is invalid + * - 6 left > right or top > bottom + * @note none + */ +uint8_t ssd1306_gram_fill_rect(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color) +{ + uint8_t x, y; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if ((left > 127) || (top > 63)) /* check left top */ + { + handle->debug_print("ssd1306: left or top is invalid.\n"); /* left or top is invalid */ + + return 4; /* return error */ + } + if ((right > 127) || (bottom > 63)) /* check right bottom */ + { + handle->debug_print("ssd1306: right or bottom is invalid.\n"); /* right or bottom is invalid */ + + return 5; /* return error */ + } + if ((left > right) || (top > bottom)) /* check left right top bottom */ + { + handle->debug_print("ssd1306: left > right or top > bottom.\n"); /* left > right or top > bottom */ + + return 6; /* return error */ + } + + for (x = left; x <= right; x++) /* write x */ + { + for (y = top; y <= bottom; y++) /* write y */ + { + if (a_ssd1306_gram_draw_point(handle, x, y, color) != 0) /* draw point */ + { + return 1; /* return error */ + } + } + } + + return 0; /* return error */ +} + +/** + * @brief draw a picture in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] *img points to an image buffer + * @return status code + * - 0 success + * - 1 gram draw picture failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 left or top is invalid + * - 5 right or bottom is invalid + * - 6 left > right or top > bottom + * @note none + */ +uint8_t ssd1306_gram_draw_picture(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img) +{ + uint8_t x, y; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if ((left > 127) || (top > 63)) /* check left top */ + { + handle->debug_print("ssd1306: left or top is invalid.\n"); /* left or top is invalid */ + + return 4; /* return error */ + } + if ((right > 127) || (bottom > 63)) /* check right bottom */ + { + handle->debug_print("ssd1306: right or bottom is invalid.\n"); /* right or bottom is invalid */ + + return 5; /* return error */ + } + if ((left > right) || (top > bottom)) /* check left right top bottom */ + { + handle->debug_print("ssd1306: left > right or top > bottom.\n"); /* left > right or top > bottom */ + + return 6; /* return error */ + } + + for (x = left; x <= right; x++) /* write x */ + { + for (y = top; y <= bottom; y++) /* write y */ + { + if (a_ssd1306_gram_draw_point(handle, x, y, *img) != 0) /* draw point */ + { + return 1; /* return error */ + } + img++; /* img++ */ + } + } + + return 0; /* succeed return 0 */ +} + +/** + * @brief initialize the chip + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 iic or spi initialization failed + * - 2 handle is NULL + * - 3 linked functions is NULL + * - 4 reset failed + * - 5 command && data init failed + * - 6 interface param is invalid + * @note none + */ +uint8_t ssd1306_init(ssd1306_handle_t *handle) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->debug_print == NULL) /* check debug_print */ + { + return 3; /* return error */ + } + if (handle->iic_init == NULL) /* check iic_init */ + { + handle->debug_print("ssd1306: iic_init is null.\n"); /* iic_init is null */ + + return 3; /* return error */ + } + if (handle->iic_deinit == NULL) /* check iic_deinit */ + { + handle->debug_print("ssd1306: iic_deinit is null.\n"); /* iic_deinit is null */ + + return 3; /* return error */ + } + if (handle->iic_write == NULL) /* check iic_write */ + { + handle->debug_print("ssd1306: iic_write is null.\n"); /* iic_write is null */ + + return 3; /* return error */ + } + if (handle->spi_init == NULL) /* check spi_init */ + { + handle->debug_print("ssd1306: spi_init is null.\n"); /* spi_init is null */ + + return 3; /* return error */ + } + if (handle->spi_deinit == NULL) /* check spi_deinit */ + { + handle->debug_print("ssd1306: spi_deinit is null.\n"); /* spi_deinit is null */ + + return 3; /* return error */ + } + if (handle->spi_write_cmd == NULL) /* check spi_write_cmd */ + { + handle->debug_print("ssd1306: spi_write_cmd is null.\n"); /* spi_write_cmd is null */ + + return 3; /* return error */ + } + if (handle->delay_ms == NULL) /* check delay_ms */ + { + handle->debug_print("ssd1306: delay_ms is null.\n"); /* delay_ms is null */ + + return 3; /* return error */ + } + if (handle->spi_cmd_data_gpio_init == NULL) /* check spi_cmd_data_gpio_init */ + { + handle->debug_print("ssd1306: spi_cmd_data_gpio_init is null.\n"); /* spi_cmd_data_gpio_init is null */ + + return 3; /* return error */ + } + if (handle->spi_cmd_data_gpio_deinit == NULL) /* check spi_cmd_data_gpio_deinit */ + { + handle->debug_print("ssd1306: spi_cmd_data_gpio_deinit is null.\n"); /* spi_cmd_data_gpio_deinit is null */ + + return 3; /* return error */ + } + if (handle->spi_cmd_data_gpio_write == NULL) /* check spi_cmd_data_gpio_write */ + { + handle->debug_print("ssd1306: spi_cmd_data_gpio_write is null.\n"); /* spi_cmd_data_gpio_write is null */ + + return 3; /* return error */ + } + if (handle->reset_gpio_init == NULL) /* check reset_gpio_init */ + { + handle->debug_print("ssd1306: reset_gpio_init is null.\n"); /* reset_gpio_init is null */ + + return 3; /* return error */ + } + if (handle->reset_gpio_deinit == NULL) /* check reset_gpio_deinit */ + { + handle->debug_print("ssd1306: reset_gpio_deinit is null.\n"); /* reset_gpio_deinit is null */ + + return 3; /* return error */ + } + if(handle->reset_gpio_write == NULL) /* check reset_gpio_write */ + { + handle->debug_print("ssd1306: reset_gpio_write is null.\n"); /* reset_gpio_write is null */ + + return 3; /* return error */ + } + + if (handle->spi_cmd_data_gpio_init() != 0) /* check spi_cmd_data_gpio_init */ + { + handle->debug_print("ssd1306: spi cmd data gpio init failed.\n"); /* spi cmd data gpio init failed */ + + return 5; /* return error */ + } + if (handle->reset_gpio_init() != 0) /* reset gpio init */ + { + handle->debug_print("ssd1306: reset gpio init failed.\n"); /* reset gpio init failed */ + (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ + + return 4; /* return error */ + } + if (handle->reset_gpio_write(0) != 0) /* write 0 */ + { + handle->debug_print("ssd1306: reset gpio write failed.\n"); /* reset gpio write failed */ + (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ + (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ + + return 4; /* return error */ + } + handle->delay_ms(100); /* delay 100 ms */ + if (handle->reset_gpio_write(1) != 0) /* write 1 */ + { + handle->debug_print("ssd1306: reset gpio write failed.\n"); /* reset gpio write failed */ + (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ + (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ + + return 4; /* return error */ + } + if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic interface */ + { + if (handle->iic_init() != 0) /* iic init */ + { + handle->debug_print("ssd1306: iic init failed.\n"); /* iic init failed */ + (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ + (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ + + return 1; /* return error */ + } + } + else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi interface */ + { + if (handle->spi_init() != 0) /* spi init */ + { + handle->debug_print("ssd1306: spi init failed.\n"); /* spi init failed */ + (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ + (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ + + return 1; /* return error */ + } + } + else + { + handle->debug_print("ssd1306: interface is invalid.\n"); /* interface is invalid */ + (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */ + (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */ + + return 6; /* return error */ + } + handle->inited = 1; /* flag inited */ + + return 0; /* success return 0 */ +} + +/** + * @brief close the chip + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 iic or spi deinit failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 power down failed + * - 5 reset gpio deinit failed + * - 6 command && data deinit failed + * - 7 interface param is invalid + * @note none + */ +uint8_t ssd1306_deinit(ssd1306_handle_t *handle) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + buf[0] = SSD1306_CMD_CHARGE_PUMP_SETTING; /* charge pump off */ + buf[1] = 0x10 | (0 << 2); /* set charge pump */ + if (a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD) != 0) /* write command */ + { + handle->debug_print("ssd1306: write command failed.\n"); /* write command failed */ + + return 4; /* return error */ + } + if (a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_OFF, SSD1306_CMD) != 0) /* write display off */ + { + handle->debug_print("ssd1306: write command failed.\n"); /* write command failed */ + + return 4; /* return error */ + } + if (handle->reset_gpio_deinit() != 0) /* reset gpio deinit */ + { + handle->debug_print("ssd1306: reset gpio deinit failed.\n"); /* reset gpio deinit failed */ + + return 5; /* return error */ + } + if (handle->spi_cmd_data_gpio_deinit() != 0) /* spi cmd data gpio deinit */ + { + handle->debug_print("ssd1306: spi cmd data gpio deinit failed.\n"); /* spi cmd data gpio deinit failed */ + + return 6; /* return error */ + } + if (handle->iic_spi == SSD1306_INTERFACE_IIC) /* if iic interface */ + { + if (handle->iic_deinit() != 0) /* iic deinit */ + { + handle->debug_print("ssd1306: iic deinit failed.\n"); /* iic deinit failed */ + + return 1; /* return error */ + } + } + else if (handle->iic_spi == SSD1306_INTERFACE_SPI) /* if spi interface */ + { + if (handle->spi_deinit() != 0) /* spi deinit */ + { + handle->debug_print("ssd1306: spi deinit failed.\n"); /* spi deinit failed */ + + return 1; /* return error */ + } + } + else + { + handle->debug_print("ssd1306: interface is invalid.\n"); /* interface is invalid */ + + return 7; /* return error */ + } + handle->inited = 0; /* flag close */ + + return 0; /* success return 0 */ +} + +/** + * @brief set the chip interface + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] interface is the chip interface + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_set_interface(ssd1306_handle_t *handle, ssd1306_interface_t ifhandler) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + + handle->iic_spi = (uint8_t)ifhandler; /* set interface */ + + return 0; /* success return 0 */ +} + +/** + * @brief get the chip interface + * @param[in] *handle points to an ssd1306 handle structure + * @param[out] *interface points to a chip interface buffer + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_get_interface(ssd1306_handle_t *handle, ssd1306_interface_t *ifhandler) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + + *ifhandler = (ssd1306_interface_t)(handle->iic_spi); /* get interface */ + + return 0; /* success return 0 */ +} + +/** + * @brief set the chip iic address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr_pin is the iic address + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_set_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t addr_pin) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + + handle->iic_addr = (uint8_t)addr_pin; /* set addr pin */ + + return 0; /* success return 0 */ +} + +/** + * @brief get the chip iic address + * @param[in] *handle points to an ssd1306 handle structure + * @param[out] *addr_pin points to an iic address buffer + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_get_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t *addr_pin) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + + *addr_pin = (ssd1306_address_t)(handle->iic_addr); /* set address */ + + return 0; /* success return 0 */ +} + +/** + * @brief set the low column start address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr is the low column start address + * @return status code + * - 0 success + * - 1 set low column start address failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 addr is invalid + * @note addr <= 0xF + */ +uint8_t ssd1306_set_low_column_start_address(ssd1306_handle_t *handle, uint8_t addr) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (addr > 0x0F) /* check addr */ + { + handle->debug_print("ssd1306: addr is invalid.\n"); /* addr is invalid */ + + return 4; /* return error */ + } + + return a_ssd1306_write_byte(handle, SSD1306_CMD_LOWER_COLUMN_START_ADDRESS|(addr&0x0F), SSD1306_CMD); /* write command */ +} + +/** + * @brief set the high column start address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr is the high column start address + * @return status code + * - 0 success + * - 1 set high column start address failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 addr is invalid + * @note addr <= 0xF + */ +uint8_t ssd1306_set_high_column_start_address(ssd1306_handle_t *handle, uint8_t addr) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (addr > 0x0F) /* check addr */ + { + handle->debug_print("ssd1306: addr is invalid.\n"); /* addr is invalid */ + + return 4; /* return error */ + } + + return a_ssd1306_write_byte(handle, SSD1306_CMD_HIGHER_COLUMN_START_ADDRESS|(addr&0x0F), SSD1306_CMD); /* write command */ +} + +/** + * @brief set the memory addressing mode + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] mode is the memory addressing mode + * @return status code + * - 0 success + * - 1 set memory addressing mode failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_memory_addressing_mode(ssd1306_handle_t *handle, ssd1306_memory_addressing_mode_t mode) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + buf[0] = SSD1306_CMD_MEMORY_ADDRESSING_MODE; /* set command mode */ + buf[1] = mode; /* set mode */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the column address range + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_addr is the column start address + * @param[in] end_addr is the column end address + * @return status code + * - 0 success + * - 1 set column address range failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start addr is invalid + * - 5 end addr is invalid + * @note start addr and end addr can't be over 0x7F + */ +uint8_t ssd1306_set_column_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr) +{ + uint8_t buf[3]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (start_addr > 0x7F) /* check start addr */ + { + handle->debug_print("ssd1306: start addr is invalid.\n"); /* start addr is invalid */ + + return 4; /* return error */ + } + if (end_addr > 0x7F) /* check end addr */ + { + handle->debug_print("ssd1306: end addr is invalid.\n"); /* end addr is invalid */ + + return 5; /* return error */ + } + + buf[0] = SSD1306_CMD_SET_COLUMN_ADDRESS; /* set command */ + buf[1] = start_addr & 0x7F; /* set start address */ + buf[2] = end_addr & 0x7F; /* set end address */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 3, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the page address range + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_addr is the page start address + * @param[in] end_addr is the page end address + * @return status code + * - 0 success + * - 1 set page address range failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start addr is invalid + * - 5 end addr is invalid + * @note start addr and end addr can't be over 0x07 + */ +uint8_t ssd1306_set_page_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr) +{ + uint8_t buf[3]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (start_addr > 0x07) /* check start addr */ + { + handle->debug_print("ssd1306: start addr is invalid.\n"); /* start addr is invalid */ + + return 4; /* return error */ + } + if (end_addr > 0x07) /* check end addr */ + { + handle->debug_print("ssd1306: end addr is invalid.\n"); /* end_addr is invalid */ + + return 5; /* return error */ + } + + buf[0] = SSD1306_CMD_SET_PAGE_ADDRESS; /* set command */ + buf[1] = start_addr & 0x07; /* set start address */ + buf[2] = end_addr & 0x07; /* set end address */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 3, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the fade blinking mode + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] mode is the fade blinking mode + * @param[in] frames is the fade or blinking frames + * @return status code + * - 0 success + * - 1 set fade blinking mode failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 frames is invalid + * @note frames max is 0x0F and div is (frames + 1) * 8 + */ +uint8_t ssd1306_set_fade_blinking_mode(ssd1306_handle_t *handle, ssd1306_fade_blinking_mode_t mode, uint8_t frames) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (frames> 0x0F) /* check frames */ + { + handle->debug_print("ssd1306: frames is invalid.\n"); /* frames is invalid */ + + return 4; /* return error */ + } + + buf[0] = SSD1306_CMD_SET_FADE_OUT_AND_BLINKING; /* set command */ + buf[1] = (uint8_t)((mode << 4) | (frames & 0x0F)); /* set mode */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the right horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set right horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start page addr is invalid + * - 5 end page addr is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07 + */ +uint8_t ssd1306_set_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + ssd1306_scroll_frame_t frames) +{ + uint8_t buf[7]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (start_page_addr > 0x07) /* check start_page_addr */ + { + handle->debug_print("ssd1306: start page addr is invalid.\n"); /* start page addr is invalid */ + + return 4; /* return error */ + } + if (end_page_addr > 0x07) /* check end_page_addr */ + { + handle->debug_print("ssd1306: end page addr is invalid.\n"); /* end page addr is invalid */ + + return 5; /* return error */ + } + + buf[0] = SSD1306_CMD_RIGHT_HORIZONTAL_SCROLL; /* set command */ + buf[1] = 0x00; /* set null */ + buf[2] = start_page_addr & 0x07; /* set start page address */ + buf[3] = frames & 0x07; /* set frames */ + buf[4] = end_page_addr & 0x07; /* set end page address */ + buf[5] = 0x00; /* set null */ + buf[6] = 0xFF; /* set frame end */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 7, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the left horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set left horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_page_addr is invalid + * - 5 end_page_addr is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07 + */ +uint8_t ssd1306_set_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + ssd1306_scroll_frame_t frames) +{ + uint8_t buf[7]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (start_page_addr > 0x07) /* check start_page_addr */ + { + handle->debug_print("ssd1306: start_page_addr is invalid.\n"); /* start_page_addr is invalid */ + + return 4; /* return error */ + } + if (end_page_addr > 0x07) /* check end_page_addr */ + { + handle->debug_print("ssd1306: end_page_addr is invalid.\n"); /* end_page_addr is invalid */ + + return 5; /* return error */ + } + + buf[0] = SSD1306_CMD_LEFT_HORIZONTAL_SCROLL; /* set command */ + buf[1] = 0x00; /* set null */ + buf[2] = start_page_addr & 0x07; /* set end page addr */ + buf[3] = frames & 0x07; /* set frames */ + buf[4] = end_page_addr & 0x07; /* set end page addr */ + buf[5] = 0x00; /* set null */ + buf[6] = 0xFF; /* set frame end */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 7, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the vertical right horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] rows is the row address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set vertical right horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_page_addr is invalid + * - 5 end_page_addr is invalid + * - 6 rows is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F + */ +uint8_t ssd1306_set_vertical_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + uint8_t rows, ssd1306_scroll_frame_t frames) +{ + uint8_t buf[6]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (start_page_addr > 0x07) /* check start_page_addr */ + { + handle->debug_print("ssd1306: start_page_addr is invalid.\n"); /* start_page_addr is invalid */ + + return 4; /* return error */ + } + if (end_page_addr > 0x07) /* check end page addr */ + { + handle->debug_print("ssd1306: end_page_addr is invalid.\n"); /* end_page_addr is invalid */ + + return 5; /* return error */ + } + if (rows > 0x3F) /* check rows */ + { + handle->debug_print("ssd1306: rows is invalid.\n"); /* rows is invalid */ + + return 6; /* return error */ + } + + buf[0] = SSD1306_CMD_VERTICAL_RIGHT_HORIZONTAL_SCROLL; /* set command */ + buf[1] = 0x00; /* set null */ + buf[2] = start_page_addr & 0x07; /* set start page addr */ + buf[3] = frames & 0x07; /* set frames */ + buf[4] = end_page_addr & 0x07; /* set end page addr */ + buf[5] = rows & 0x3F; /* set rows */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 6, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the vertical left horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] rows is the row address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set vertical left horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_page_addr is invalid + * - 5 end_page_addr is invalid + * - 6 rows is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F + */ +uint8_t ssd1306_set_vertical_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + uint8_t rows, ssd1306_scroll_frame_t frames) +{ + uint8_t buf[6]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (start_page_addr > 0x07) /* check start_page_addr */ + { + handle->debug_print("ssd1306: start_page_addr is invalid.\n"); /* start_page_addr is invalid */ + + return 4; /* return error */ + } + if (end_page_addr > 0x07) /* check end_page_addr */ + { + handle->debug_print("ssd1306: end_page_addr is invalid.\n"); /* end_page_addr is invalid */ + + return 5; /* return error */ + } + if (rows > 0x3F) /* check rows */ + { + handle->debug_print("ssd1306: rows is invalid.\n"); /* rows is invalid */ + + return 6; /* return error */ + } + + buf[0] = SSD1306_CMD_VERTICAL_LEFT_HORIZONTAL_SCROLL; /* set command */ + buf[1] = 0x00; /* set null */ + buf[2] = start_page_addr & 0x07; /* set start page addr */ + buf[3] = frames & 0x07; /* set frames */ + buf[4] = end_page_addr & 0x07; /* set end page addr */ + buf[5] = rows & 0x3F; /* set rows */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 6, SSD1306_CMD); /* write command */ +} + +/** + * @brief deactivate the scroll + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 deactivate scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_deactivate_scroll(ssd1306_handle_t *handle) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + return a_ssd1306_write_byte(handle, SSD1306_CMD_DEACTIVATE_SCROLL, SSD1306_CMD); /* write command */ +} + +/** + * @brief activate the scroll + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 activate scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_activate_scroll(ssd1306_handle_t *handle) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + return a_ssd1306_write_byte(handle, SSD1306_CMD_ACTIVATE_SCROLL, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the display start line + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] l is the start line + * @return status code + * - 0 success + * - 1 set display start line failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 line is invalid + * @note line <= 0x3F + */ +uint8_t ssd1306_set_display_start_line(ssd1306_handle_t *handle, uint8_t l) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (l > 0x3F) /* check line */ + { + handle->debug_print("ssd1306: line is invalid.\n"); /* line is invalid */ + + return 4; /* return error */ + } + + return a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_START_LINE|(l&0x3F), SSD1306_CMD); /* write command */ +} + +/** + * @brief set the display contrast + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] contrast is the display contrast + * @return status code + * - 0 success + * - 1 set contrast failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_contrast(ssd1306_handle_t *handle, uint8_t contrast) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + buf[0] = SSD1306_CMD_CONTRAST_CONTROL; /* set command */ + buf[1] = contrast; /* set contrast */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief enable or disable the charge pump + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] enable is a bool value + * @return status code + * - 0 success + * - 1 set charge pump failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_charge_pump(ssd1306_handle_t *handle, ssd1306_charge_pump_t enable) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + buf[0] = SSD1306_CMD_CHARGE_PUMP_SETTING; /* set command */ + buf[1] = (uint8_t)(0x10 | (enable << 2)); /* set charge pump */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the segment remap + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] remap is the segment remap param + * @return status code + * - 0 success + * - 1 set segment remap failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_segment_remap(ssd1306_handle_t *handle, ssd1306_segment_column_remap_t remap) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + if (remap != 0) /* check remap */ + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_COLUMN_127_MAPPED_TO_SEG0, SSD1306_CMD); /* write remap */ + } + else + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_COLUMN_0_MAPPED_TO_SEG0, SSD1306_CMD); /* write remap */ + } +} + +/** + * @brief set the vertical scroll area + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_row is the start row + * @param[in] end_row is the end row + * @return status code + * - 0 success + * - 1 set vertical scroll area failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_row is invalid + * - 5 end_row is invalid + * - 6 end_row > start_row + * @note start_row <= 0x3F, end_row <= 0x7F, start_row >= end_row + */ +uint8_t ssd1306_set_vertical_scroll_area(ssd1306_handle_t *handle, uint8_t start_row, uint8_t end_row) +{ + uint8_t buf[3]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (start_row > 0x3F) /* check start row */ + { + handle->debug_print("ssd1306: start_row is invalid.\n"); /* start_row is invalid */ + + return 4; /* return error */ + } + if (end_row > 0x7F) /* check end_row */ + { + handle->debug_print("ssd1306: end_row is invalid.\n"); /* end_row is invalid */ + + return 5; /* return error */ + } + if (end_row > start_row) /* check start_row and end_row */ + { + handle->debug_print("ssd1306: end_row > start_row.\n"); /* end_row > start_row */ + + return 6; /* return error */ + } + + buf[0] = SSD1306_CMD_VERTICAL_SCROLL_AREA; /* set command */ + buf[1] = start_row; /* set start row */ + buf[2] = end_row; /* set end row */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 3, SSD1306_CMD); /* write command */ +} + +/** + * @brief enable or disable the entire display + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] enable is a bool value + * @return status code + * - 0 success + * - 1 set entire display failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_entire_display(ssd1306_handle_t *handle, ssd1306_entire_display_t enable) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + if (enable != 0) /* if enable */ + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_ENTIRE_DISPLAY_ON, SSD1306_CMD); /* write command */ + } + else + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_ENTIRE_DISPLAY_OFF, SSD1306_CMD); /* write command */ + } +} + +/** + * @brief set the display mode + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] mode is the display mode + * @return status code + * - 0 success + * - 1 set display mode failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_display_mode(ssd1306_handle_t *handle, ssd1306_display_mode_t mode) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + if (mode != 0) /* check mode */ + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_INVERSE_DISPLAY, SSD1306_CMD); /* write command */ + } + else + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_NORMAL_DISPLAY, SSD1306_CMD); /* write command */ + } +} + +/** + * @brief set the multiplex ratio + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] multiplex is the multiplex ratio + * @return status code + * - 0 success + * - 1 set multiplex ratio failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 multiplex is too small + * - 5 multiplex is too large + * @note multiplex must be over 0x0E and less than 0x40 + */ +uint8_t ssd1306_set_multiplex_ratio(ssd1306_handle_t *handle, uint8_t multiplex) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (multiplex < 0x0F) /* check multiplex */ + { + handle->debug_print("ssd1306: multiplex is too small.\n"); /* multiplex is too small */ + + return 4; /* return error */ + } + if (multiplex > 0x3F) /* check multiplex */ + { + handle->debug_print("ssd1306: multiplex is too large.\n"); /* multiplex is too large */ + + return 5; /* return error */ + } + + buf[0] = SSD1306_CMD_MULTIPLEX_RATIO ; /* set command */ + buf[1] = multiplex; /* set multiplex */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief enable or disable the display + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] on_off is a bool value + * @return status code + * - 0 success + * - 1 set display failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_display(ssd1306_handle_t *handle, ssd1306_display_t on_off) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + if (on_off != 0) /* check on off */ + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_ON, SSD1306_CMD); /* write command */ + } + else + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_DISPLAY_OFF, SSD1306_CMD); /* write command */ + } +} + +/** + * @brief set the page address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr is the page address + * @return status code + * - 0 success + * - 1 set page address failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 addr is invalid + * @note addr <= 0x07 + */ +uint8_t ssd1306_set_page_address(ssd1306_handle_t *handle, uint8_t addr) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (addr > 0x07) /* check addr */ + { + handle->debug_print("ssd1306: addr is invalid.\n"); /* addr is invalid */ + + return 4; /* return error */ + } + + return a_ssd1306_write_byte(handle, SSD1306_CMD_PAGE_ADDR|(addr&0x07), SSD1306_CMD); /* write command */ +} + +/** + * @brief set the scan direction + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] dir is the scan direction + * @return status code + * - 0 success + * - 1 set scan direction failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_scan_direction(ssd1306_handle_t *handle, ssd1306_scan_direction_t dir) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + if (dir != 0) /* choose dir */ + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_SCAN_DIRECTION_COMN_1_START, SSD1306_CMD); /* write command */ + } + else + { + return a_ssd1306_write_byte(handle, SSD1306_CMD_SCAN_DIRECTION_COM0_START, SSD1306_CMD); /* write command */ + } +} + +/** + * @brief set the display offset + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] offset is the display offset + * @return status code + * - 0 success + * - 1 set display offset failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 offset is invalid + * @note offset <= 0x3F + */ +uint8_t ssd1306_set_display_offset(ssd1306_handle_t *handle, uint8_t offset) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (offset > 0x3F) /* check offset */ + { + handle->debug_print("ssd1306: offset is invalid.\n"); /* offset is invalid */ + + return 4; /* return error */ + } + + buf[0] = SSD1306_CMD_DISPLAY_OFFSET ; /* set command */ + buf[1] = offset; /* set offset */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the display clock + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] oscillator_frequency is the oscillator frequency + * @param[in] clock_divide is the clock divide + * @return status code + * - 0 success + * - 1 set display clock failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 oscillator frequency is invalid + * - 5 clock divide is invalid + * @note oscillator_frequency <= 0x0F, clock_divide <= 0x0F + */ +uint8_t ssd1306_set_display_clock(ssd1306_handle_t *handle, uint8_t oscillator_frequency, uint8_t clock_divide) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (oscillator_frequency> 0x0F) /* check oscillator_frequency */ + { + handle->debug_print("ssd1306: oscillator frequency is invalid.\n"); /* oscillator frequency is invalid */ + + return 4; /* return error */ + } + if (clock_divide> 0x0F) /* check clock_divide */ + { + handle->debug_print("ssd1306: clock divide is invalid.\n"); /* clock divide is invalid */ + + return 5; /* return error */ + } + + buf[0] = SSD1306_CMD_DISPLAY_CLOCK_DIVIDE ; /* set command */ + buf[1] = (oscillator_frequency<<4) | clock_divide; /* set oscillator frequency and clock divide */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the display zoom in + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] zoom is the display zoom in + * @return status code + * - 0 success + * - 1 set zoom in failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_zoom_in(ssd1306_handle_t *handle, ssd1306_zoom_in_t zoom) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + buf[0] = SSD1306_CMD_SET_ZOOM_IN ; /* set command */ + buf[1] = zoom; /* set zoom */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the pre charge period + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] phase1_period is the phase1 period + * @param[in] phase2_period is the phase2 period + * @return status code + * - 0 success + * - 1 set pre charge period failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 phase1 period is invalid + * - 5 phase2 period is invalid + * @note phase1_period <= 0x0F, phase2_period <= 0x0F + */ +uint8_t ssd1306_set_precharge_period(ssd1306_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + if (phase1_period> 0x0F) /* check phase1 period */ + { + handle->debug_print("ssd1306: phase1 period is invalid.\n"); /* phase1 period is invalid */ + + return 4; /* return error */ + } + if (phase2_period> 0x0F) /* check phase2 period */ + { + handle->debug_print("ssd1306: phase2 period is invalid.\n"); /* phase2 period is invalid */ + + return 5; /* return error */ + } + + buf[0] = SSD1306_CMD_PRE_CHARGE_PERIOD; /* set command */ + buf[1] = (phase2_period << 4) | phase1_period; /* set period */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the hardware com pins + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] conf is the pin conf + * @param[in] remap is the left right remap + * @return status code + * - 0 success + * - 1 set com pins hardware conf failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_com_pins_hardware_conf(ssd1306_handle_t *handle, ssd1306_pin_conf_t conf, ssd1306_left_right_remap_t remap) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + buf[0] = SSD1306_CMD_COM_PINS_CONF; /* set command */ + buf[1] = (uint8_t)((conf<<4) | (remap<<5) |0x02); /* set com pins */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief set the deselect level + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] level is the deselect level + * @return status code + * - 0 success + * - 1 set deselect level failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_deselect_level(ssd1306_handle_t *handle, ssd1306_deselect_level_t level) +{ + uint8_t buf[2]; + + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + buf[0] = SSD1306_CMD_COMH_DESLECT_LEVEL; /* set command */ + buf[1] = (uint8_t)(level << 4); /* set level */ + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, 2, SSD1306_CMD); /* write command */ +} + +/** + * @brief write the register command + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] *buf points to a data buffer + * @param[in] len is the data length + * @return status code + * - 0 success + * - 1 write failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_write_cmd(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, len, SSD1306_CMD); /* write command */ +} + +/** + * @brief write the register data + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] *buf points to a data buffer + * @param[in] len is the data length + * @return status code + * - 0 success + * - 1 write failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_write_data(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len) +{ + if (handle == NULL) /* check handle */ + { + return 2; /* return error */ + } + if (handle->inited != 1) /* check handle initialization */ + { + return 3; /* return error */ + } + + return a_ssd1306_multiple_write_byte(handle, (uint8_t *)buf, len, SSD1306_DATA); /* write data */ +} + +/** + * @brief get chip's information + * @param[out] *info points to an ssd1306 info structure + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_info(ssd1306_info_t *info) +{ + if (info == NULL) /* check handle */ + { + return 2; /* return error */ + } + + memset(info, 0, sizeof(ssd1306_info_t)); /* initialize ssd1306 info structure */ + strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */ + strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */ + strncpy(info->ifname, "IIC SPI", 8); /* copy interface name */ + info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */ + info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */ + info->max_current_ma = MAX_CURRENT; /* set maximum current */ + info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */ + info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */ + info->driver_version = DRIVER_VERSION; /* set driver version */ + + return 0; /* success return 0 */ +} diff --git a/app/src/board/ssd1306/driver_ssd1306.h b/app/src/board/ssd1306/driver_ssd1306.h new file mode 100644 index 0000000..fa65147 --- /dev/null +++ b/app/src/board/ssd1306/driver_ssd1306.h @@ -0,0 +1,1105 @@ +/** + * Copyright (c) 2015 - present LibDriver All rights reserved + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file driver_ssd1306.h + * @brief driver ssd1306 header file + * @version 2.0.0 + * @author Shifeng Li + * @date 2021-03-30 + * + *

history

+ * + *
Date Version Author Description + *
2021/03/30 2.0 Shifeng Li format the code + *
2020/12/10 1.0 Shifeng Li first upload + *
+ */ + +#ifndef DRIVER_SSD1306_H +#define DRIVER_SSD1306_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C"{ +#endif + +/** + * @defgroup ssd1306_driver ssd1306 driver function + * @brief ssd1306 driver modules + * @{ + */ + +/** + * @addtogroup ssd1306_base_driver + * @{ + */ + +/** + * @brief ssd1306 interface enumeration definition + */ +typedef enum +{ + SSD1306_INTERFACE_IIC = 0x00, /**< interface iic */ + SSD1306_INTERFACE_SPI = 0x01, /**< interface spi */ +} ssd1306_interface_t; + +/** + * @brief ssd1306 address pin enumeration definition + */ +typedef enum +{ + SSD1306_ADDR_SA0_0 = 0x78, /**< address pin GND */ + SSD1306_ADDR_SA0_1 = 0x7A, /**< address pin VCC */ +} ssd1306_address_t; + +/** + * @brief ssd1306 memory addressing mode enumeration definition + */ +typedef enum +{ + SSD1306_MEMORY_ADDRESSING_MODE_HORIZONTAL = 0x00, /**< horizontal addressing mode */ + SSD1306_MEMORY_ADDRESSING_MODE_VERTICAL = 0x01, /**< vertical addressing mode */ + SSD1306_MEMORY_ADDRESSING_MODE_PAGE = 0x02, /**< page addressing mode */ +} ssd1306_memory_addressing_mode_t; + +/** + * @brief ssd1306 fade blinking mode enumeration definition + */ +typedef enum +{ + SSD1306_FADE_BLINKING_MODE_DISABLE = 0x00, /**< disable fade blinking mode */ + SSD1306_FADE_BLINKING_MODE_FADE_OUT = 0x02, /**< fade out fade blinking mode */ + SSD1306_FADE_BLINKING_MODE_BLINKING = 0x03, /**< blinking fade blinking mode */ +} ssd1306_fade_blinking_mode_t; + +/** + * @brief ssd1306 scroll frame enumeration definition + */ +typedef enum +{ + SSD1306_SCROLL_FRAME_2 = 0x07, /**< scroll frame 2 */ + SSD1306_SCROLL_FRAME_3 = 0x04, /**< scroll frame 3 */ + SSD1306_SCROLL_FRAME_4 = 0x05, /**< scroll frame 4 */ + SSD1306_SCROLL_FRAME_5 = 0x00, /**< scroll frame 5 */ + SSD1306_SCROLL_FRAME_25 = 0x06, /**< scroll frame 25 */ + SSD1306_SCROLL_FRAME_64 = 0x01, /**< scroll frame 64 */ + SSD1306_SCROLL_FRAME_128 = 0x02, /**< scroll frame 128 */ + SSD1306_SCROLL_FRAME_256 = 0x03, /**< scroll frame 256 */ +} ssd1306_scroll_frame_t; + +/** + * @brief ssd1306 charge pump enumeration definition + */ +typedef enum +{ + SSD1306_CHARGE_PUMP_DISABLE = 0x00, /**< charge pump disable */ + SSD1306_CHARGE_PUMP_ENABLE = 0x01, /**< charge pump enable */ +} ssd1306_charge_pump_t; + +/** + * @brief ssd1306 segment column remap enumeration definition + */ +typedef enum +{ + SSD1306_SEGMENT_COLUMN_ADDRESS_0 = 0x00, /**< segment column remap address 0 */ + SSD1306_SEGMENT_COLUMN_ADDRESS_127 = 0x01, /**< segment column remap address 127 */ +} ssd1306_segment_column_remap_t; + +/** + * @brief ssd1306 entire display enumeration definition + */ +typedef enum +{ + SSD1306_ENTIRE_DISPLAY_OFF = 0x00, /**< entire display off */ + SSD1306_ENTIRE_DISPLAY_ON = 0x01, /**< entire display on */ +} ssd1306_entire_display_t; + +/** + * @brief ssd1306 display mode enumeration definition + */ +typedef enum +{ + SSD1306_DISPLAY_MODE_NORMAL = 0x00, /**< display mode normal */ + SSD1306_DISPLAY_MODE_INVERSE = 0x01, /**< display mode inverse */ +} ssd1306_display_mode_t; + +/** + * @brief ssd1306 display enumeration definition + */ +typedef enum +{ + SSD1306_DISPLAY_OFF = 0x00, /**< close display */ + SSD1306_DISPLAY_ON = 0x01, /**< open display */ +} ssd1306_display_t; + +/** + * @brief ssd1306 scan direction enumeration definition + */ +typedef enum +{ + SSD1306_SCAN_DIRECTION_COM0_START = 0x00, /**< scan direction com 0 start */ + SSD1306_SCAN_DIRECTION_COMN_1_START = 0x01, /**< scan direction com N-1 start */ +} ssd1306_scan_direction_t; + +/** + * @brief ssd1306 zoom in enumeration definition + */ +typedef enum +{ + SSD1306_ZOOM_IN_DISABLE = 0x00, /**< disable zoom in */ + SSD1306_ZOOM_IN_ENABLE = 0x01, /**< enable zoom in */ +} ssd1306_zoom_in_t; + +/** + * @brief ssd1306 pin conf enumeration definition + */ +typedef enum +{ + SSD1306_PIN_CONF_SEQUENTIAL = 0x00, /**< pin conf sequential */ + SSD1306_PIN_CONF_ALTERNATIVE = 0x01, /**< pin conf alternative */ +} ssd1306_pin_conf_t; + +/** + * @brief ssd1306 left right remap enumeration definition + */ +typedef enum +{ + SSD1306_LEFT_RIGHT_REMAP_DISABLE = 0x00, /**< disable left right remap */ + SSD1306_LEFT_RIGHT_REMAP_ENABLE = 0x01, /**< enable left right remap */ +} ssd1306_left_right_remap_t; + +/** + * @brief ssd1306 deselect level enumeration definition + */ +typedef enum +{ + SSD1306_DESELECT_LEVEL_0P65 = 0x00, /**< deselect level 0.65 */ + SSD1306_DESELECT_LEVEL_0P77 = 0x02, /**< deselect level 0.77 */ + SSD1306_DESELECT_LEVEL_0P83 = 0x03, /**< deselect level 0.83 */ +} ssd1306_deselect_level_t; + +/** + * @brief ssd1306 font enumeration definition + */ +typedef enum +{ + SSD1306_FONT_12 = 0x0C, /**< font 12 */ + SSD1306_FONT_16 = 0x10, /**< font 16 */ + SSD1306_FONT_24 = 0x18, /**< font 24 */ +} ssd1306_font_t; + +/** + * @brief ssd1306 handle structure definition + */ +typedef struct ssd1306_handle_s +{ + uint8_t (*iic_init)(void); /**< point to an iic_init function address */ + uint8_t (*iic_deinit)(void); /**< point to an iic_deinit function address */ + uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len); /**< point to an iic_write function address */ + uint8_t (*spi_init)(void); /**< point to a spi_init function address */ + uint8_t (*spi_deinit)(void); /**< point to a spi_deinit function address */ + uint8_t (*spi_write_cmd)(uint8_t *buf, uint16_t len); /**< point to a spi_write_cmd function address */ + uint8_t (*spi_cmd_data_gpio_init)(void); /**< point to a spi_cmd_data_gpio_init function address */ + uint8_t (*spi_cmd_data_gpio_deinit)(void); /**< point to a spi_cmd_data_gpio_deinit function address */ + uint8_t (*spi_cmd_data_gpio_write)(uint8_t value); /**< point to a spi_cmd_data_gpio_write function address */ + uint8_t (*reset_gpio_init)(void); /**< point to a reset_gpio_init function address */ + uint8_t (*reset_gpio_deinit)(void); /**< point to a reset_gpio_deinit function address */ + uint8_t (*reset_gpio_write)(uint8_t value); /**< point to a reset_gpio_write function address */ + void (*debug_print)(const char *const fmt, ...); /**< point to a debug_print function address */ + void (*delay_ms)(uint32_t ms); /**< point to a delay_ms function address */ + uint8_t inited; /**< inited flag */ + uint8_t iic_addr; /**< iic address */ + uint8_t iic_spi; /**< iic spi type */ + uint8_t gram[128][8]; /**< gram buffer */ +} ssd1306_handle_t; + +/** + * @brief ssd1306 information structure definition + */ +typedef struct ssd1306_info_s +{ + char chip_name[32]; /**< chip name */ + char manufacturer_name[32]; /**< manufacturer name */ + char ifname[8]; /**< chip interface name */ + float supply_voltage_min_v; /**< chip min supply voltage */ + float supply_voltage_max_v; /**< chip max supply voltage */ + float max_current_ma; /**< chip max current */ + float temperature_min; /**< chip min operating temperature */ + float temperature_max; /**< chip max operating temperature */ + uint32_t driver_version; /**< driver version */ +} ssd1306_info_t; + +/** + * @} + */ + +/** + * @defgroup ssd1306_link_driver ssd1306 link driver function + * @brief ssd1306 link driver modules + * @ingroup ssd1306_driver + * @{ + */ + +/** + * @brief initialize ssd1306_handle_t structure + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] STRUCTURE is ssd1306_handle_t + * @note none + */ +#define DRIVER_SSD1306_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE)) + +/** + * @brief link iic_init function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to an iic_init function address + * @note none + */ +#define DRIVER_SSD1306_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC + +/** + * @brief link iic_deinit function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to an iic_deinit function address + * @note none + */ +#define DRIVER_SSD1306_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC + +/** + * @brief link iic_write function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to an iic_write function address + * @note none + */ +#define DRIVER_SSD1306_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC + +/** + * @brief link spi_init function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a spi_init function address + * @note none + */ +#define DRIVER_SSD1306_LINK_SPI_INIT(HANDLE, FUC) (HANDLE)->spi_init = FUC + +/** + * @brief link spi_deinit function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a spi_deinit function address + * @note none + */ +#define DRIVER_SSD1306_LINK_SPI_DEINIT(HANDLE, FUC) (HANDLE)->spi_deinit = FUC + +/** + * @brief link spi_write_cmd function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a spi_write_cmd function address + * @note none + */ +#define DRIVER_SSD1306_LINK_SPI_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->spi_write_cmd = FUC + +/** + * @brief link spi_cmd_data_gpio_init function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a spi_cmd_data_gpio_init function address + * @note none + */ +#define DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_INIT(HANDLE, FUC) (HANDLE)->spi_cmd_data_gpio_init = FUC + +/** + * @brief link spi_cmd_data_gpio_deinit function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a spi_cmd_data_gpio_deinit function address + * @note none + */ +#define DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_DEINIT(HANDLE, FUC) (HANDLE)->spi_cmd_data_gpio_deinit = FUC + +/** + * @brief link spi_cmd_data_gpio_write function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a spi_cmd_data_gpio_write function address + * @note none + */ +#define DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_WRITE(HANDLE, FUC) (HANDLE)->spi_cmd_data_gpio_write = FUC + +/** + * @brief link reset_gpio_init function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a reset_gpio_init function address + * @note none + */ +#define DRIVER_SSD1306_LINK_RESET_GPIO_INIT(HANDLE, FUC) (HANDLE)->reset_gpio_init = FUC + +/** + * @brief link reset_gpio_deinit function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a reset_gpio_deinit function address + * @note none + */ +#define DRIVER_SSD1306_LINK_RESET_GPIO_DEINIT(HANDLE, FUC) (HANDLE)->reset_gpio_deinit = FUC + +/** + * @brief link reset_gpio_write function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a reset_gpio_write function address + * @note none + */ +#define DRIVER_SSD1306_LINK_RESET_GPIO_WRITE(HANDLE, FUC) (HANDLE)->reset_gpio_write = FUC + +/** + * @brief link delay_ms function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a delay_ms function address + * @note none + */ +#define DRIVER_SSD1306_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC + +/** + * @brief link debug_print function + * @param[in] HANDLE points to an ssd1306 handle structure + * @param[in] FUC points to a debug_print function address + * @note none + */ +#define DRIVER_SSD1306_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC + +/** + * @} + */ + +/** + * @defgroup ssd1306_base_driver ssd1306 base driver function + * @brief ssd1306 base driver modules + * @ingroup ssd1306_driver + * @{ + */ + +/** + * @brief get chip's information + * @param[out] *info points to an ssd1306 info structure + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_info(ssd1306_info_t *info); + +/** + * @brief set the chip interface + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] interface is the chip interface + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_set_interface(ssd1306_handle_t *handle, ssd1306_interface_t ifhandler); + +/** + * @brief get the chip interface + * @param[in] *handle points to an ssd1306 handle structure + * @param[out] *interface points to a chip interface buffer + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_get_interface(ssd1306_handle_t *handle, ssd1306_interface_t *ifhandler); + +/** + * @brief set the chip iic address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr_pin is the iic address + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_set_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t addr_pin); + +/** + * @brief get the chip iic address + * @param[in] *handle points to an ssd1306 handle structure + * @param[out] *addr_pin points to an iic address buffer + * @return status code + * - 0 success + * - 2 handle is NULL + * @note none + */ +uint8_t ssd1306_get_addr_pin(ssd1306_handle_t *handle, ssd1306_address_t *addr_pin); + +/** + * @brief initialize the chip + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 iic or spi initialization failed + * - 2 handle is NULL + * - 3 linked functions is NULL + * - 4 reset failed + * - 5 command && data init failed + * - 6 interface param is invalid + * @note none + */ +uint8_t ssd1306_init(ssd1306_handle_t *handle); + +/** + * @brief close the chip + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 iic or spi deinit failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 power down failed + * - 5 reset gpio deinit failed + * - 6 command && data deinit failed + * - 7 interface param is invalid + * @note none + */ +uint8_t ssd1306_deinit(ssd1306_handle_t *handle); + +/** + * @brief clear the screen + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 clear failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_clear(ssd1306_handle_t *handle); + +/** + * @brief update the gram data + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 gram update failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_gram_update(ssd1306_handle_t *handle); + +/** + * @brief write a point + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] data is the write data + * @return status code + * - 0 success + * - 1 write point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data); + +/** + * @brief read a point + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[out] *data points to a data buffer + * @return status code + * - 0 success + * - 1 read point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data); + +/** + * @brief write a point in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] data is the write data + * @return status code + * - 0 success + * - 1 gram write point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_gram_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t data); + +/** + * @brief read a point from the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[out] *data points to a data buffer + * @return status code + * - 0 success + * - 1 gram read point failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_gram_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data); + +/** + * @brief draw a string in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] *str points to a write string address + * @param[in] len is the length of the string + * @param[in] color is the display color + * @param[in] font is the display font size + * @return status code + * - 0 success + * - 1 gram write string failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 x or y is invalid + * @note none + */ +uint8_t ssd1306_gram_write_string(ssd1306_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font); + +/** + * @brief fill a rectangle in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] color is the display color + * @return status code + * - 0 success + * - 1 gram fill rect failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 left or top is invalid + * - 5 right or bottom is invalid + * - 6 left > right or top > bottom + * @note none + */ +uint8_t ssd1306_gram_fill_rect(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color); + +/** + * @brief draw a picture in the gram + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] *img points to an image buffer + * @return status code + * - 0 success + * - 1 gram draw picture failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 left or top is invalid + * - 5 right or bottom is invalid + * - 6 left > right or top > bottom + * @note none + */ +uint8_t ssd1306_gram_draw_picture(ssd1306_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img); + +/** + * @brief set the low column start address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr is the low column start address + * @return status code + * - 0 success + * - 1 set low column start address failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 addr is invalid + * @note addr <= 0xF + */ +uint8_t ssd1306_set_low_column_start_address(ssd1306_handle_t *handle, uint8_t addr); + +/** + * @brief set the high column start address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr is the high column start address + * @return status code + * - 0 success + * - 1 set high column start address failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 addr is invalid + * @note addr <= 0xF + */ +uint8_t ssd1306_set_high_column_start_address(ssd1306_handle_t *handle, uint8_t addr); + +/** + * @brief set the memory addressing mode + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] mode is the memory addressing mode + * @return status code + * - 0 success + * - 1 set memory addressing mode failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_memory_addressing_mode(ssd1306_handle_t *handle, ssd1306_memory_addressing_mode_t mode); + +/** + * @brief set the column address range + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_addr is the column start address + * @param[in] end_addr is the column end address + * @return status code + * - 0 success + * - 1 set column address range failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start addr is invalid + * - 5 end addr is invalid + * @note start addr and end addr can't be over 0x7F + */ +uint8_t ssd1306_set_column_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr); + +/** + * @brief set the page address range + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_addr is the page start address + * @param[in] end_addr is the page end address + * @return status code + * - 0 success + * - 1 set page address range failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start addr is invalid + * - 5 end addr is invalid + * @note start addr and end addr can't be over 0x07 + */ +uint8_t ssd1306_set_page_address_range(ssd1306_handle_t *handle, uint8_t start_addr, uint8_t end_addr); + +/** + * @brief set the fade blinking mode + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] mode is the fade blinking mode + * @param[in] frames is the fade or blinking frames + * @return status code + * - 0 success + * - 1 set fade blinking mode failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 frames is invalid + * @note frames max is 0x0F and div is (frames + 1) * 8 + */ +uint8_t ssd1306_set_fade_blinking_mode(ssd1306_handle_t *handle, ssd1306_fade_blinking_mode_t mode, uint8_t frames); + +/** + * @brief set the right horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set right horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start page addr is invalid + * - 5 end page addr is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07 + */ +uint8_t ssd1306_set_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + ssd1306_scroll_frame_t frames); + +/** + * @brief set the left horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set left horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_page_addr is invalid + * - 5 end_page_addr is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07 + */ +uint8_t ssd1306_set_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + ssd1306_scroll_frame_t frames); + +/** + * @brief set the vertical right horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] rows is the row address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set vertical right horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_page_addr is invalid + * - 5 end_page_addr is invalid + * - 6 rows is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F + */ +uint8_t ssd1306_set_vertical_right_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + uint8_t rows, ssd1306_scroll_frame_t frames); + +/** + * @brief set the vertical left horizontal scroll + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_page_addr is the start page address + * @param[in] end_page_addr is the end page address + * @param[in] rows is the row address + * @param[in] frames is the scroll frames + * @return status code + * - 0 success + * - 1 set vertical left horizontal scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_page_addr is invalid + * - 5 end_page_addr is invalid + * - 6 rows is invalid + * @note start_page_addr <= 0x07, end_page_addr <= 0x07, rows <= 0x3F + */ +uint8_t ssd1306_set_vertical_left_horizontal_scroll(ssd1306_handle_t *handle, uint8_t start_page_addr, uint8_t end_page_addr, + uint8_t rows, ssd1306_scroll_frame_t frames); + +/** + * @brief deactivate the scroll + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 deactivate scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_deactivate_scroll(ssd1306_handle_t *handle); + +/** + * @brief activate the scroll + * @param[in] *handle points to an ssd1306 handle structure + * @return status code + * - 0 success + * - 1 activate scroll failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_activate_scroll(ssd1306_handle_t *handle); + +/** + * @brief set the display start line + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] l is the start line + * @return status code + * - 0 success + * - 1 set display start line failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 line is invalid + * @note line <= 0x3F + */ +uint8_t ssd1306_set_display_start_line(ssd1306_handle_t *handle, uint8_t l); + +/** + * @brief set the display contrast + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] contrast is the display contrast + * @return status code + * - 0 success + * - 1 set contrast failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_contrast(ssd1306_handle_t *handle, uint8_t contrast); + +/** + * @brief enable or disable the charge pump + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] enable is a bool value + * @return status code + * - 0 success + * - 1 set charge pump failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_charge_pump(ssd1306_handle_t *handle, ssd1306_charge_pump_t enable); + +/** + * @brief set the segment remap + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] remap is the segment remap param + * @return status code + * - 0 success + * - 1 set segment remap failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_segment_remap(ssd1306_handle_t *handle, ssd1306_segment_column_remap_t remap); + +/** + * @brief set the vertical scroll area + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] start_row is the start row + * @param[in] end_row is the end row + * @return status code + * - 0 success + * - 1 set vertical scroll area failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 start_row is invalid + * - 5 end_row is invalid + * - 6 end_row > start_row + * @note start_row <= 0x3F, end_row <= 0x7F, start_row >= end_row + */ +uint8_t ssd1306_set_vertical_scroll_area(ssd1306_handle_t *handle, uint8_t start_row, uint8_t end_row); + +/** + * @brief enable or disable the entire display + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] enable is a bool value + * @return status code + * - 0 success + * - 1 set entire display failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_entire_display(ssd1306_handle_t *handle, ssd1306_entire_display_t enable); + +/** + * @brief set the display mode + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] mode is the display mode + * @return status code + * - 0 success + * - 1 set display mode failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_display_mode(ssd1306_handle_t *handle, ssd1306_display_mode_t mode); + +/** + * @brief set the multiplex ratio + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] multiplex is the multiplex ratio + * @return status code + * - 0 success + * - 1 set multiplex ratio failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 multiplex is too small + * - 5 multiplex is too large + * @note multiplex must be over 0x0E and less than 0x40 + */ +uint8_t ssd1306_set_multiplex_ratio(ssd1306_handle_t *handle, uint8_t multiplex); + +/** + * @brief enable or disable the display + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] on_off is a bool value + * @return status code + * - 0 success + * - 1 set display failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_display(ssd1306_handle_t *handle, ssd1306_display_t on_off); + +/** + * @brief set the page address + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] addr is the page address + * @return status code + * - 0 success + * - 1 set page address failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 addr is invalid + * @note addr <= 0x07 + */ +uint8_t ssd1306_set_page_address(ssd1306_handle_t *handle, uint8_t addr); + +/** + * @brief set the scan direction + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] dir is the scan direction + * @return status code + * - 0 success + * - 1 set scan direction failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_scan_direction(ssd1306_handle_t *handle, ssd1306_scan_direction_t dir); + +/** + * @brief set the display offset + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] offset is the display offset + * @return status code + * - 0 success + * - 1 set display offset failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 offset is invalid + * @note offset <= 0x3F + */ +uint8_t ssd1306_set_display_offset(ssd1306_handle_t *handle, uint8_t offset); + +/** + * @brief set the display clock + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] oscillator_frequency is the oscillator frequency + * @param[in] clock_divide is the clock divide + * @return status code + * - 0 success + * - 1 set display clock failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 oscillator frequency is invalid + * - 5 clock divide is invalid + * @note oscillator_frequency <= 0x0F, clock_divide <= 0x0F + */ +uint8_t ssd1306_set_display_clock(ssd1306_handle_t *handle, uint8_t oscillator_frequency, uint8_t clock_divide); + +/** + * @brief set the display zoom in + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] zoom is the display zoom in + * @return status code + * - 0 success + * - 1 set zoom in failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_zoom_in(ssd1306_handle_t *handle, ssd1306_zoom_in_t zoom); + +/** + * @brief set the pre charge period + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] phase1_period is the phase1 period + * @param[in] phase2_period is the phase2 period + * @return status code + * - 0 success + * - 1 set pre charge period failed + * - 2 handle is NULL + * - 3 handle is not initialized + * - 4 phase1 period is invalid + * - 5 phase2 period is invalid + * @note phase1_period <= 0x0F, phase2_period <= 0x0F + */ +uint8_t ssd1306_set_precharge_period(ssd1306_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period); + +/** + * @brief set the hardware com pins + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] conf is the pin conf + * @param[in] remap is the left right remap + * @return status code + * - 0 success + * - 1 set com pins hardware conf failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_com_pins_hardware_conf(ssd1306_handle_t *handle, ssd1306_pin_conf_t conf, ssd1306_left_right_remap_t remap); + +/** + * @brief set the deselect level + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] level is the deselect level + * @return status code + * - 0 success + * - 1 set deselect level failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_set_deselect_level(ssd1306_handle_t *handle, ssd1306_deselect_level_t level); + +/** + * @} + */ + +/** + * @defgroup ssd1306_extend_driver ssd1306 extend driver function + * @brief ssd1306 extend driver modules + * @ingroup ssd1306_driver + * @{ + */ + +/** + * @brief write the register command + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] *buf points to a data buffer + * @param[in] len is the data length + * @return status code + * - 0 success + * - 1 write failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_write_cmd(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len); + +/** + * @brief write the register data + * @param[in] *handle points to an ssd1306 handle structure + * @param[in] *buf points to a data buffer + * @param[in] len is the data length + * @return status code + * - 0 success + * - 1 write failed + * - 2 handle is NULL + * - 3 handle is not initialized + * @note none + */ +uint8_t ssd1306_write_data(ssd1306_handle_t *handle, uint8_t *buf, uint8_t len); + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/board/ssd1306/driver_ssd1306_basic.c b/app/src/board/ssd1306/driver_ssd1306_basic.c new file mode 100644 index 0000000..ff1fd58 --- /dev/null +++ b/app/src/board/ssd1306/driver_ssd1306_basic.c @@ -0,0 +1,792 @@ +/** + * Copyright (c) 2015 - present LibDriver All rights reserved + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file driver_ssd1306_basic.c + * @brief driver ssd1306 basic source file + * @version 2.0.0 + * @author Shifeng Li + * @date 2021-03-30 + * + *

history

+ * + *
Date Version Author Description + *
2021/03/30 2.0 Shifeng Li format the code + *
2020/12/10 1.0 Shifeng Li first upload + *
+ */ + +#include "driver_ssd1306_basic.h" + +#include + +static ssd1306_handle_t gs_handle; /**< ssd1306 handle */ + +/** + * @brief basic example init + * @param[in] interface is the interface type + * @param[in] addr is the iic device address + * @return status code + * - 0 success + * - 1 init failed + * @note none + */ +uint8_t ssd1306_basic_init(ssd1306_interface_t ifhandler, ssd1306_address_t addr) { + uint8_t res; + + /* link functions */ + DRIVER_SSD1306_LINK_INIT(&gs_handle, ssd1306_handle_t); + DRIVER_SSD1306_LINK_IIC_INIT(&gs_handle, ssd1306_interface_iic_init); + DRIVER_SSD1306_LINK_IIC_DEINIT(&gs_handle, ssd1306_interface_iic_deinit); + DRIVER_SSD1306_LINK_IIC_WRITE(&gs_handle, ssd1306_interface_iic_write); + DRIVER_SSD1306_LINK_SPI_INIT(&gs_handle, ssd1306_interface_spi_init); + DRIVER_SSD1306_LINK_SPI_DEINIT(&gs_handle, ssd1306_interface_spi_deinit); + DRIVER_SSD1306_LINK_SPI_WRITE_COMMAND(&gs_handle, ssd1306_interface_spi_write_cmd); + DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_INIT(&gs_handle, ssd1306_interface_spi_cmd_data_gpio_init); + DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_DEINIT(&gs_handle, ssd1306_interface_spi_cmd_data_gpio_deinit); + DRIVER_SSD1306_LINK_SPI_COMMAND_DATA_GPIO_WRITE(&gs_handle, ssd1306_interface_spi_cmd_data_gpio_write); + DRIVER_SSD1306_LINK_RESET_GPIO_INIT(&gs_handle, ssd1306_interface_reset_gpio_init); + DRIVER_SSD1306_LINK_RESET_GPIO_DEINIT(&gs_handle, ssd1306_interface_reset_gpio_deinit); + DRIVER_SSD1306_LINK_RESET_GPIO_WRITE(&gs_handle, ssd1306_interface_reset_gpio_write); + DRIVER_SSD1306_LINK_DELAY_MS(&gs_handle, ssd1306_interface_delay_ms); + DRIVER_SSD1306_LINK_DEBUG_PRINT(&gs_handle, ssd1306_interface_debug_print); + + /* set interface */ + res = ssd1306_set_interface(&gs_handle, ifhandler); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set interface failed.\n"); + + return 1; + } + + /* set addr pin */ + res = ssd1306_set_addr_pin(&gs_handle, addr); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set addr failed.\n"); + + return 1; + } + + /* ssd1306 init */ + res = ssd1306_init(&gs_handle); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: init failed.\n"); + + return 1; + } + + /* close display */ + res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_OFF); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set display failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set column address range */ + res = ssd1306_set_column_address_range(&gs_handle, SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_START, SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_END); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set column address range failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set page address range */ + res = ssd1306_set_page_address_range(&gs_handle, SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_START, SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_END); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set page address range failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set low column start address */ + res = ssd1306_set_low_column_start_address(&gs_handle, SSD1306_BASIC_DEFAULT_LOW_COLUMN_START_ADDRESS); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set low column start address failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set high column start address */ + res = ssd1306_set_high_column_start_address(&gs_handle, SSD1306_BASIC_DEFAULT_HIGH_COLUMN_START_ADDRESS); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set high column start address failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set display start line */ + res = ssd1306_set_display_start_line(&gs_handle, SSD1306_BASIC_DEFAULT_DISPLAY_START_LINE); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set display start line failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set fade blinking mode */ + res = ssd1306_set_fade_blinking_mode(&gs_handle, SSD1306_BASIC_DEFAULT_FADE_BLINKING_MODE, SSD1306_BASIC_DEFAULT_FADE_FRAMES); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set fade blinking failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* deactivate scroll */ + res = ssd1306_deactivate_scroll(&gs_handle); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set deactivate scroll failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set zoom in */ + res = ssd1306_set_zoom_in(&gs_handle, SSD1306_BASIC_DEFAULT_ZOOM_IN); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set set zoom in failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set contrast */ + res = ssd1306_set_contrast(&gs_handle, SSD1306_BASIC_DEFAULT_CONTRAST); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set contrast failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set segment remap */ + res = ssd1306_set_segment_remap(&gs_handle, SSD1306_BASIC_DEFAULT_SEGMENT); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set segment remap failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set scan direction */ + res = ssd1306_set_scan_direction(&gs_handle, SSD1306_BASIC_DEFAULT_SCAN_DIRECTION); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set scan direction failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set display mode */ + res = ssd1306_set_display_mode(&gs_handle, SSD1306_BASIC_DEFAULT_DISPLAY_MODE); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set display mode failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set multiplex ratio */ + res = ssd1306_set_multiplex_ratio(&gs_handle, SSD1306_BASIC_DEFAULT_MULTIPLEX_RATIO); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set multiplex ratio failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set display offset */ + res = ssd1306_set_display_offset(&gs_handle, SSD1306_BASIC_DEFAULT_DISPLAY_OFFSET); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set display offset failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set display clock */ + res = ssd1306_set_display_clock(&gs_handle, SSD1306_BASIC_DEFAULT_OSCILLATOR_FREQUENCY, SSD1306_BASIC_DEFAULT_CLOCK_DIVIDE); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set display clock failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set pre charge period */ + res = ssd1306_set_precharge_period(&gs_handle, SSD1306_BASIC_DEFAULT_PHASE1_PERIOD, SSD1306_BASIC_DEFAULT_PHASE2_PERIOD); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set pre charge period failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set hardware pins conf */ + res = ssd1306_set_com_pins_hardware_conf(&gs_handle, SSD1306_BASIC_DEFAULT_PIN_CONF, SSD1306_BASIC_DEFAULT_LEFT_RIGHT_REMAP); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set com pins hardware conf failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set deselect level 0.77 */ + res = ssd1306_set_deselect_level(&gs_handle, SSD1306_BASIC_DEFAULT_DESELECT_LEVEL); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set deselect level failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* set page memory addressing mode */ + res = ssd1306_set_memory_addressing_mode(&gs_handle, SSD1306_MEMORY_ADDRESSING_MODE_PAGE); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set memory addressing level failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* enable charge pump */ + res = ssd1306_set_charge_pump(&gs_handle, SSD1306_CHARGE_PUMP_ENABLE); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set charge pump failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* entire display off */ + res = ssd1306_set_entire_display(&gs_handle, SSD1306_ENTIRE_DISPLAY_OFF); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set entire display failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* enable display */ + res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_ON); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: set display failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + /* clear screen */ + res = ssd1306_clear(&gs_handle); + if (res != 0) { + ssd1306_interface_debug_print("ssd1306: clear failed.\n"); + (void)ssd1306_deinit(&gs_handle); + + return 1; + } + + return 0; +} + +/** + * @brief basic example deinit + * @return status code + * - 0 success + * - 1 deinit failed + * @note none + */ +uint8_t ssd1306_basic_deinit(void) { + /* deinit ssd1306 */ + if (ssd1306_deinit(&gs_handle) != 0) { + return 1; + } else { + return 0; + } +} + +/** + * @brief basic example display on + * @return status code + * - 0 success + * - 1 display on failed + * @note none + */ +uint8_t ssd1306_basic_display_on(void) { + uint8_t res; + + /* display on */ + res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_ON); + if (res != 0) { + return 1; + } else { + return 0; + } +} + +/** + * @brief basic example display off + * @return status code + * - 0 success + * - 1 display off failed + * @note none + */ +uint8_t ssd1306_basic_display_off(void) { + uint8_t res; + + /* display off */ + res = ssd1306_set_display(&gs_handle, SSD1306_DISPLAY_OFF); + if (res != 0) { + return 1; + } else { + return 0; + } +} + +/** + * @brief basic example clear + * @return status code + * - 0 success + * - 1 clear failed + * @note none + */ +uint8_t ssd1306_basic_clear(void) { + /* clear */ + if (ssd1306_clear(&gs_handle) != 0) { + return 1; + } else { + return 0; + } +} + +/** + * @brief basic example write a point + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] data is the written data + * @return status code + * - 0 success + * - 1 write point failed + * @note none + */ +uint8_t ssd1306_basic_write_point(uint8_t x, uint8_t y, uint8_t data) { + uint8_t res; + + /* write point */ + res = ssd1306_write_point(&gs_handle, x, y, data); + if (res != 0) { + return 1; + } + + return 0; +} +ssd1306_handle_t *ssd1306_handler() { return &gs_handle; } + +/** + * @brief basic example read a point + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[out] *data points to a data buffer + * @return status code + * - 0 success + * - 1 read point failed + * @note none + */ +uint8_t ssd1306_basic_read_point(uint8_t x, uint8_t y, uint8_t *data) { + uint8_t res; + + /* read point in gram */ + res = ssd1306_read_point(&gs_handle, x, y, data); + if (res != 0) { + return 1; + } + + return 0; +} + +/** + * @brief basic example draw a string + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] *str points to a written string address + * @param[in] len is the length of the string + * @param[in] color is the display color + * @param[in] font is the display font size + * @return status code + * - 0 success + * - 1 write string failed + * @note none + */ +uint8_t ssd1306_basic_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font) { + uint8_t res; + + /* write string in gram */ + res = ssd1306_gram_write_string(&gs_handle, x, y, str, len, color, font); + if (res != 0) { + return 1; + } + + /* update gram */ + if (ssd1306_gram_update(&gs_handle) != 0) { + return 1; + } else { + return 0; + } +} + +/** + * @brief basic example fill a rectangle + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] color is the display color + * @return status code + * - 0 success + * - 1 fill rect failed + * @note none + */ +uint8_t ssd1306_basic_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color) { + uint8_t res; + + /* fill rect in gram */ + res = ssd1306_gram_fill_rect(&gs_handle, left, top, right, bottom, color); + if (res != 0) { + return 1; + } + + /* update gram */ + if (ssd1306_gram_update(&gs_handle) != 0) { + return 1; + } else { + return 0; + } +} + +/** + * @brief basic example draw a picture + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] *img points to a image buffer + * @return status code + * - 0 success + * - 1 draw picture failed + * @note none + */ +uint8_t ssd1306_basic_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img) { + uint8_t res; + + /* draw picture in gram */ + res = ssd1306_gram_draw_picture(&gs_handle, left, top, right, bottom, img); + if (res != 0) { + return 1; + } + + /* update gram */ + if (ssd1306_gram_update(&gs_handle) != 0) { + return 1; + } else { + return 0; + } +} +uint8_t ssd1306_basic_draw_screen(const char *img) { + for (size_t i = 0; i < 1024; i++) { + gs_handle.gram[i % 128][i / 128] = img[i]; + } + return 0; +} +uint8_t ssd1306_basic_clear_gram(void) { + memset(gs_handle.gram, 0, sizeof(gs_handle.gram)); + return 0; +} + +uint8_t ssd1306_basic_gram_update() { return ssd1306_gram_update(&gs_handle); } +#include "znordic.h" +uint8_t ssd1306_basic_draw_one_chr(uint8_t xs, uint8_t ys, const char *str, FontLibrary_t *frontlib) { + const uint8_t *frontbuf = NULL; + FontLibrary_findchar(frontlib, str, &frontbuf); + if (!frontbuf) return 1; + + // ssd1306_gram_write_point + for (uint32_t xoff = 0; xoff < frontlib->widthPixel; xoff++) { + for (uint32_t yoff = 0; yoff < frontlib->heightPixel; yoff++) { + bool pixval = 0; + /** + * |||||| + * VVVVVV + * |||||| + * VVVVVV + * + * x = 3; y = 9; + * byteoff = x + y / frontWidthPixel * frontWidthPixel + * bitoff = y % 8 + */ + + uint8_t byteoff = xoff + yoff / 8 * frontlib->widthPixel; + uint8_t bitoff = yoff % 8; + pixval = (frontbuf[byteoff] >> bitoff) & 0x01; + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, pixval); + } + } + return 0; +} + +uint8_t ssd1306_basic_draw_str(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, const char *str, FontLibrary_t *frontlib) { + uint8_t x = xs; + uint8_t y = ys; + StrIterator_t iterator; + *xchange = 0; + *ychange = 0; + str_iterator_start(&iterator, frontlib->fontCode, str); + char *nowchr = NULL; + while (true) { + str_iterator_next(&iterator, &nowchr); + if (!nowchr) { + break; + } + ssd1306_basic_draw_one_chr(x, y, nowchr, frontlib); + x += (uint8_t)(frontlib->widthPixel); /* x + font/2 */ + *xchange = *xchange + frontlib->widthPixel; + } + + *ychange = frontlib->heightPixel; + + return 0; +} + +uint8_t ssd1306_basic_draw_battery_level(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, int level, int width, int high) { + /** + * @brief + * ***** + * ******** + * * * + * * **** * + * * **** * + * ******** + */ + + if (level >= 100) { + level = 100; + } + + uint8_t xoff = 0; + uint8_t yoff = 0; + + int batteryHeaderHigh = 2; + int batteryHeaderWidth = 7; + int batteryBodyHigh = 20; + int batteryBodyWidth = 12; + int border_width = 1; + int blank_width = 1; + + float width_mult = width * 1.0 / batteryBodyWidth; + float high_mult = high * 1.0 / (batteryBodyHigh + batteryHeaderHigh); + + batteryHeaderHigh = batteryHeaderHigh * high_mult; + batteryHeaderWidth = batteryHeaderWidth * width_mult; + batteryBodyHigh = batteryBodyHigh * high_mult; + batteryBodyWidth = batteryBodyWidth * width_mult; + border_width = 1; + blank_width = 1; + + int batteryInterBodyWidth = batteryBodyWidth - blank_width * 2 - border_width * 2; + int batteryInterBodyHigh = batteryBodyHigh - border_width * 2 - blank_width * 2; + /** + * @brief »­Í·?? + */ + for (int yoff = 0; yoff < batteryHeaderHigh; yoff++) { + for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { + uint16_t battery_start = (batteryBodyWidth - batteryHeaderWidth) / 2; + uint16_t battery_end = battery_start + batteryHeaderWidth; + if (xoff >= battery_start && xoff <= battery_end) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); + } + } + } + ys += batteryHeaderHigh; + + /** + * @brief »­ÉϱßÑØ + */ + for (int yoff = 0; yoff < border_width; yoff++) { + for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } + } + ys += border_width; + /** + * @brief »­ÉÏÁô°× + */ + for (int yoff = 0; yoff < blank_width; yoff++) { + for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { + // uint16_t start = blank_width; + if (xoff < border_width) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else if (xoff >= (batteryInterBodyWidth + border_width * 1 + blank_width * 2)) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); + } + } + } + ys += blank_width; + + /** + * @brief »­Éí?? + */ + for (int yoff = 0; yoff < batteryInterBodyHigh; yoff++) { + for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { + // uint16_t start = blank_width; + if (xoff < border_width) { + // right border + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else if (xoff >= border_width + blank_width && xoff < batteryInterBodyWidth + border_width + blank_width) { + // body + // ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + + uint16_t batterylevel = (100 - level) / 100.0 * batteryInterBodyHigh; + if (yoff >= batterylevel) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); + } + + } else if (xoff >= batteryInterBodyWidth + border_width * 1 + blank_width * 2) { + // left border + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); + } + } + } + ys += batteryInterBodyHigh; + + /** + * @brief »­ÉÏÁô°× + */ + for (int yoff = 0; yoff < blank_width; yoff++) { + for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { + // uint16_t start = blank_width; + if (xoff < border_width) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else if (xoff >= (batteryInterBodyWidth + border_width * 1 + blank_width * 2)) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } else { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 0); + } + } + } + ys += blank_width; + /** + * @brief »­ÉϱßÑØ + */ + for (int yoff = 0; yoff < border_width; yoff++) { + for (int xoff = 0; xoff < batteryBodyWidth; xoff++) { + ssd1306_gram_write_point(&gs_handle, xs + xoff, ys + yoff, 1); + } + } + ys += border_width; + + *xchange = batteryBodyWidth; + *ychange = batteryBodyHigh + batteryHeaderHigh; +} + +uint8_t ssd1306_basic_draw_progress(uint8_t xs, uint8_t ys, uint16_t width, uint16_t high, uint16_t markpos, uint16_t progress) { + /** + * @brief + * + * [==================> ] + */ + + /** + * @brief + */ + for (uint16_t i = 0; i < width; i++) { + ssd1306_gram_write_point(&gs_handle, xs + i, ys, 1); + } + ys += 1; + + /** + * @brief + */ + uint16_t progress_width = width * progress / 100.0; + uint16_t markpos_off = width * markpos / 100.0; + for (uint16_t yoff = 0; yoff < high - 2; yoff++) { + for (uint16_t i = 0; i < width; i++) { + if (i == width - 1) { + ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 1); + } else if (i >= markpos_off && i < markpos_off + 1) { + ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 1); + } else { + if (i < progress_width || i == 0) { + ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 1); + } else { + ssd1306_gram_write_point(&gs_handle, xs + i, ys + yoff, 0); + } + } + } + } + + ys += high - 2; + /** + * @brief + */ + for (uint16_t i = 0; i < width; i++) { + ssd1306_gram_write_point(&gs_handle, xs + i, ys, 1); + } + return 0; +} + +uint8_t ssd1306_basic_draw_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) { + int dx = abs(x2 - x1); + int dy = abs(y2 - y1); + int sx = (x1 < x2) ? 1 : -1; + int sy = (y1 < y2) ? 1 : -1; + int err = dx - dy; + + while (1) { + ssd1306_gram_write_point(&gs_handle, x1, y1, 1); + if (x1 == x2 && y1 == y2) { + break; + } + + int e2 = 2 * err; + if (e2 > -dy) { + err -= dy; + x1 += sx; + } + + if (e2 < dx) { + err += dx; + y1 += sy; + } + } +} diff --git a/app/src/board/ssd1306/driver_ssd1306_basic.h b/app/src/board/ssd1306/driver_ssd1306_basic.h new file mode 100644 index 0000000..2e1d706 --- /dev/null +++ b/app/src/board/ssd1306/driver_ssd1306_basic.h @@ -0,0 +1,226 @@ +/** + * Copyright (c) 2015 - present LibDriver All rights reserved + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file driver_ssd1306_basic.h + * @brief driver ssd1306 basic header file + * @version 2.0.0 + * @author Shifeng Li + * @date 2021-03-30 + * + *

history

+ * + *
Date Version Author Description + *
2021/03/30 2.0 Shifeng Li format the code + *
2020/12/10 1.0 Shifeng Li first upload + *
+ */ + +#ifndef DRIVER_SSD1306_BASIC_H +#define DRIVER_SSD1306_BASIC_H + +#include "driver_ssd1306_interface.h" +#include "fontlib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup ssd1306_example_driver ssd1306 example driver function + * @brief ssd1306 example driver modules + * @ingroup ssd1306_driver + * @{ + */ + +/** + * @brief ssd1306 basic example default definition + */ +#define SSD1306_BASIC_DEFAULT_DESELECT_LEVEL SSD1306_DESELECT_LEVEL_0P77 /**< set deselect level 0.77 */ +#define SSD1306_BASIC_DEFAULT_LEFT_RIGHT_REMAP SSD1306_LEFT_RIGHT_REMAP_DISABLE /**< disable remap */ +#define SSD1306_BASIC_DEFAULT_PIN_CONF SSD1306_PIN_CONF_ALTERNATIVE /**< set alternative */ +#define SSD1306_BASIC_DEFAULT_PHASE1_PERIOD 0x01 /**< set phase 1 */ +#define SSD1306_BASIC_DEFAULT_PHASE2_PERIOD 0x0F /**< set phase F */ +#define SSD1306_BASIC_DEFAULT_OSCILLATOR_FREQUENCY 0x08 /**< set 8 */ +#define SSD1306_BASIC_DEFAULT_CLOCK_DIVIDE 0x00 /**< set clock div 0 */ +#define SSD1306_BASIC_DEFAULT_DISPLAY_OFFSET 0x00 /**< set display offset */ +#define SSD1306_BASIC_DEFAULT_MULTIPLEX_RATIO 0x3F /**< set ratio */ +#define SSD1306_BASIC_DEFAULT_DISPLAY_MODE SSD1306_DISPLAY_MODE_NORMAL /**< set normal mode */ +#define SSD1306_BASIC_DEFAULT_SCAN_DIRECTION SSD1306_SCAN_DIRECTION_COM0_START /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ +// #define SSD1306_BASIC_DEFAULT_SCAN_DIRECTION SSD1306_SCAN_DIRECTION_COM0_START /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ +#define SSD1306_BASIC_DEFAULT_SEGMENT SSD1306_SEGMENT_COLUMN_ADDRESS_127 /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ +// #define SSD1306_BASIC_DEFAULT_SEGMENT SSD1306_SEGMENT_COLUMN_ADDRESS_127 /**< ×ֵķ½Ïò²»¶ÔÐÞ¸ÄÕâÀï */ +// #define SSD1306_BASIC_DEFAULT_CONTRAST 0xCF /**< set contrast CF */ +#define SSD1306_BASIC_DEFAULT_CONTRAST 0x05 /**< set contrast CF */ +#define SSD1306_BASIC_DEFAULT_ZOOM_IN SSD1306_ZOOM_IN_DISABLE /**< disable zoom in */ +#define SSD1306_BASIC_DEFAULT_FADE_BLINKING_MODE SSD1306_FADE_BLINKING_MODE_DISABLE /**< disable fade */ +#define SSD1306_BASIC_DEFAULT_FADE_FRAMES 0x00 /**< set frame 0 */ +#define SSD1306_BASIC_DEFAULT_DISPLAY_START_LINE 0x00 /**< set start line 0 */ +#define SSD1306_BASIC_DEFAULT_HIGH_COLUMN_START_ADDRESS 0x00 /**< set high start 0 */ +#define SSD1306_BASIC_DEFAULT_LOW_COLUMN_START_ADDRESS 0x00 /**< set low start 0 */ +#define SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_START 0x00 /**< set page range start */ +#define SSD1306_BASIC_DEFAULT_PAGE_ADDRESS_RANGE_END 0x07 /**< set page range end */ +#define SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_START 0x00 /**< set range start */ +#define SSD1306_BASIC_DEFAULT_COLUMN_ADDRESS_RANGE_END 0x7F /**< set range end */ + +/** + * @brief basic example init + * @param[in] interface is the interface type + * @param[in] addr is the iic device address + * @return status code + * - 0 success + * - 1 init failed + * @note none + */ +uint8_t ssd1306_basic_init(ssd1306_interface_t ifhandler, ssd1306_address_t addr); + +/** + * @brief basic example deinit + * @return status code + * - 0 success + * - 1 deinit failed + * @note none + */ +uint8_t ssd1306_basic_deinit(void); + +/** + * @brief basic example display on + * @return status code + * - 0 success + * - 1 display on failed + * @note none + */ +uint8_t ssd1306_basic_display_on(void); + +/** + * @brief basic example display off + * @return status code + * - 0 success + * - 1 display off failed + * @note none + */ +uint8_t ssd1306_basic_display_off(void); + +/** + * @brief basic example clear + * @return status code + * - 0 success + * - 1 clear failed + * @note none + */ +uint8_t ssd1306_basic_clear(void); + +/** + * @brief basic example write a point + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] data is the written data + * @return status code + * - 0 success + * - 1 write point failed + * @note none + */ +uint8_t ssd1306_basic_write_point(uint8_t x, uint8_t y, uint8_t data); + +/** + * @brief basic example read a point + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[out] *data points to a data buffer + * @return status code + * - 0 success + * - 1 read point failed + * @note none + */ +uint8_t ssd1306_basic_read_point(uint8_t x, uint8_t y, uint8_t *data); + +/** + * @brief basic example draw a string + * @param[in] x is the coordinate x + * @param[in] y is the coordinate y + * @param[in] *str points to a written string address + * @param[in] len is the length of the string + * @param[in] color is the display color + * @param[in] font is the display font size + * @return status code + * - 0 success + * - 1 write string failed + * @note none + */ +uint8_t ssd1306_basic_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1306_font_t font); +/** + * @brief basic example fill a rectangle + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] color is the display color + * @return status code + * - 0 success + * - 1 fill rect failed + * @note none + */ +uint8_t ssd1306_basic_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color); + +/** + * @brief basic example draw a picture + * @param[in] left is the left coordinate x + * @param[in] top is the top coordinate y + * @param[in] right is the right coordinate x + * @param[in] bottom is the bottom coordinate y + * @param[in] *img points to a image buffer + * @return status code + * - 0 success + * - 1 draw picture failed + * @note none + */ +uint8_t ssd1306_basic_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img); + +/******************************************************************************* + * ADD_BY_ZHAOHE * + *******************************************************************************/ + +uint8_t ssd1306_basic_draw_screen(const char *img); +uint8_t ssd1306_basic_gram_update(); +ssd1306_handle_t *ssd1306_handler(); +uint8_t ssd1306_basic_line(uint8_t x, uint8_t y, uint8_t data); + +uint8_t ssd1306_basic_draw_str(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, const char *str, FontLibrary_t *frontlib); + +uint8_t ssd1306_basic_draw_battery_level(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t *ychange, int level, int width, int high); + +uint8_t ssd1306_basic_draw_progress(uint8_t xs, uint8_t ys, uint16_t width, uint16_t high, uint16_t markpos, uint16_t progress); + +uint8_t ssd1306_basic_draw_line(uint8_t x1, uint8_t y1,uint8_t x2, uint8_t y2); + +uint8_t ssd1306_basic_clear_gram(void); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/board/ssd1306/driver_ssd1306_font.h b/app/src/board/ssd1306/driver_ssd1306_font.h new file mode 100644 index 0000000..1734127 --- /dev/null +++ b/app/src/board/ssd1306/driver_ssd1306_font.h @@ -0,0 +1,350 @@ +/** + * Copyright (c) 2015 - present LibDriver All rights reserved + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file driver_ssd1306_font.h + * @brief driver ssd1306 font header file + * @version 2.0.0 + * @author Shifeng Li + * @date 2021-03-30 + * + *

history

+ * + *
Date Version Author Description + *
2021/03/30 2.0 Shifeng Li format the code + *
2020/12/10 1.0 Shifeng Li first upload + *
+ */ + +#ifndef DRIVER_SSD1306_FONT_H +#define DRIVER_SSD1306_FONT_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C"{ +#endif + +static const uint8_t gsc_ssd1306_ascii_1206[95][12] = +{ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*" ", 0*/ + {0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"!", 1*/ + {0x00, 0x00, 0x30, 0x00, 0x40, 0x00, 0x30, 0x00, 0x40, 0x00, 0x00, 0x00}, /*""", 2*/ + {0x09, 0x00, 0x0B, 0xC0, 0x3D, 0x00, 0x0B, 0xC0, 0x3D, 0x00, 0x09, 0x00}, /*"#", 3*/ + {0x18, 0xC0, 0x24, 0x40, 0x7F, 0xE0, 0x22, 0x40, 0x31, 0x80, 0x00, 0x00}, /*"$", 4*/ + {0x18, 0x00, 0x24, 0xC0, 0x1B, 0x00, 0x0D, 0x80, 0x32, 0x40, 0x01, 0x80}, /*"%", 5*/ + {0x03, 0x80, 0x1C, 0x40, 0x27, 0x40, 0x1C, 0x80, 0x07, 0x40, 0x00, 0x40}, /*"&", 6*/ + {0x10, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"'", 7*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x80, 0x20, 0x40, 0x40, 0x20}, /*"(", 8*/ + {0x00, 0x00, 0x40, 0x20, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00}, /*")", 9*/ + {0x09, 0x00, 0x06, 0x00, 0x1F, 0x80, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00}, /*"*", 10*/ + {0x04, 0x00, 0x04, 0x00, 0x3F, 0x80, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00}, /*"+", 11*/ + {0x00, 0x10, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*", ", 12*/ + {0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00}, /*"-", 13*/ + {0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*".", 14*/ + {0x00, 0x20, 0x01, 0xC0, 0x06, 0x00, 0x38, 0x00, 0x40, 0x00, 0x00, 0x00}, /*"/", 15*/ + {0x1F, 0x80, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"0", 16*/ + {0x00, 0x00, 0x10, 0x40, 0x3F, 0xC0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}, /*"1", 17*/ + {0x18, 0xC0, 0x21, 0x40, 0x22, 0x40, 0x24, 0x40, 0x18, 0x40, 0x00, 0x00}, /*"2", 18*/ + {0x10, 0x80, 0x20, 0x40, 0x24, 0x40, 0x24, 0x40, 0x1B, 0x80, 0x00, 0x00}, /*"3", 19*/ + {0x02, 0x00, 0x0D, 0x00, 0x11, 0x00, 0x3F, 0xC0, 0x01, 0x40, 0x00, 0x00}, /*"4", 20*/ + {0x3C, 0x80, 0x24, 0x40, 0x24, 0x40, 0x24, 0x40, 0x23, 0x80, 0x00, 0x00}, /*"5", 21*/ + {0x1F, 0x80, 0x24, 0x40, 0x24, 0x40, 0x34, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"6", 22*/ + {0x30, 0x00, 0x20, 0x00, 0x27, 0xC0, 0x38, 0x00, 0x20, 0x00, 0x00, 0x00}, /*"7", 23*/ + {0x1B, 0x80, 0x24, 0x40, 0x24, 0x40, 0x24, 0x40, 0x1B, 0x80, 0x00, 0x00}, /*"8", 24*/ + {0x1C, 0x00, 0x22, 0xC0, 0x22, 0x40, 0x22, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"9", 25*/ + {0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*":", 26*/ + {0x00, 0x00, 0x00, 0x00, 0x04, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*";", 27*/ + {0x00, 0x00, 0x04, 0x00, 0x0A, 0x00, 0x11, 0x00, 0x20, 0x80, 0x40, 0x40}, /*"<", 28*/ + {0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x00, 0x00}, /*"=", 29*/ + {0x00, 0x00, 0x40, 0x40, 0x20, 0x80, 0x11, 0x00, 0x0A, 0x00, 0x04, 0x00}, /*">", 30*/ + {0x18, 0x00, 0x20, 0x00, 0x23, 0x40, 0x24, 0x00, 0x18, 0x00, 0x00, 0x00}, /*"?", 31*/ + {0x1F, 0x80, 0x20, 0x40, 0x27, 0x40, 0x29, 0x40, 0x1F, 0x40, 0x00, 0x00}, /*"@", 32*/ + {0x00, 0x40, 0x07, 0xC0, 0x39, 0x00, 0x0F, 0x00, 0x01, 0xC0, 0x00, 0x40}, /*"A", 33*/ + {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x24, 0x40, 0x1B, 0x80, 0x00, 0x00}, /*"B", 34*/ + {0x1F, 0x80, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x30, 0x80, 0x00, 0x00}, /*"C", 35*/ + {0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"D", 36*/ + {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x2E, 0x40, 0x30, 0xC0, 0x00, 0x00}, /*"E", 37*/ + {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x2E, 0x00, 0x30, 0x00, 0x00, 0x00}, /*"F", 38*/ + {0x0F, 0x00, 0x10, 0x80, 0x20, 0x40, 0x22, 0x40, 0x33, 0x80, 0x02, 0x00}, /*"G", 39*/ + {0x20, 0x40, 0x3F, 0xC0, 0x04, 0x00, 0x04, 0x00, 0x3F, 0xC0, 0x20, 0x40}, /*"H", 40*/ + {0x20, 0x40, 0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x20, 0x40, 0x00, 0x00}, /*"I", 41*/ + {0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x3F, 0xC0, 0x20, 0x00, 0x20, 0x00}, /*"J", 42*/ + {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x0B, 0x00, 0x30, 0xC0, 0x20, 0x40}, /*"K", 43*/ + {0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0xC0}, /*"L", 44*/ + {0x3F, 0xC0, 0x3C, 0x00, 0x03, 0xC0, 0x3C, 0x00, 0x3F, 0xC0, 0x00, 0x00}, /*"M", 45*/ + {0x20, 0x40, 0x3F, 0xC0, 0x0C, 0x40, 0x23, 0x00, 0x3F, 0xC0, 0x20, 0x00}, /*"N", 46*/ + {0x1F, 0x80, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x1F, 0x80, 0x00, 0x00}, /*"O", 47*/ + {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x24, 0x00, 0x18, 0x00, 0x00, 0x00}, /*"P", 48*/ + {0x1F, 0x80, 0x21, 0x40, 0x21, 0x40, 0x20, 0xE0, 0x1F, 0xA0, 0x00, 0x00}, /*"Q", 49*/ + {0x20, 0x40, 0x3F, 0xC0, 0x24, 0x40, 0x26, 0x00, 0x19, 0xC0, 0x00, 0x40}, /*"R", 50*/ + {0x18, 0xC0, 0x24, 0x40, 0x24, 0x40, 0x22, 0x40, 0x31, 0x80, 0x00, 0x00}, /*"S", 51*/ + {0x30, 0x00, 0x20, 0x40, 0x3F, 0xC0, 0x20, 0x40, 0x30, 0x00, 0x00, 0x00}, /*"T", 52*/ + {0x20, 0x00, 0x3F, 0x80, 0x00, 0x40, 0x00, 0x40, 0x3F, 0x80, 0x20, 0x00}, /*"U", 53*/ + {0x20, 0x00, 0x3E, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x38, 0x00, 0x20, 0x00}, /*"V", 54*/ + {0x38, 0x00, 0x07, 0xC0, 0x3C, 0x00, 0x07, 0xC0, 0x38, 0x00, 0x00, 0x00}, /*"W", 55*/ + {0x20, 0x40, 0x39, 0xC0, 0x06, 0x00, 0x39, 0xC0, 0x20, 0x40, 0x00, 0x00}, /*"X", 56*/ + {0x20, 0x00, 0x38, 0x40, 0x07, 0xC0, 0x38, 0x40, 0x20, 0x00, 0x00, 0x00}, /*"Y", 57*/ + {0x30, 0x40, 0x21, 0xC0, 0x26, 0x40, 0x38, 0x40, 0x20, 0xC0, 0x00, 0x00}, /*"Z", 58*/ + {0x00, 0x00, 0x00, 0x00, 0x7F, 0xE0, 0x40, 0x20, 0x40, 0x20, 0x00, 0x00}, /*"[", 59*/ + {0x00, 0x00, 0x70, 0x00, 0x0C, 0x00, 0x03, 0x80, 0x00, 0x40, 0x00, 0x00}, /*"\", 60*/ + {0x00, 0x00, 0x40, 0x20, 0x40, 0x20, 0x7F, 0xE0, 0x00, 0x00, 0x00, 0x00}, /*"]", 61*/ + {0x00, 0x00, 0x20, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"^", 62*/ + {0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10}, /*"_", 63*/ + {0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"`", 64*/ + {0x00, 0x00, 0x02, 0x80, 0x05, 0x40, 0x05, 0x40, 0x03, 0xC0, 0x00, 0x40}, /*"a", 65*/ + {0x20, 0x00, 0x3F, 0xC0, 0x04, 0x40, 0x04, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"b", 66*/ + {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x04, 0x40, 0x06, 0x40, 0x00, 0x00}, /*"c", 67*/ + {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x24, 0x40, 0x3F, 0xC0, 0x00, 0x40}, /*"d", 68*/ + {0x00, 0x00, 0x03, 0x80, 0x05, 0x40, 0x05, 0x40, 0x03, 0x40, 0x00, 0x00}, /*"e", 69*/ + {0x00, 0x00, 0x04, 0x40, 0x1F, 0xC0, 0x24, 0x40, 0x24, 0x40, 0x20, 0x00}, /*"f", 70*/ + {0x00, 0x00, 0x02, 0xE0, 0x05, 0x50, 0x05, 0x50, 0x06, 0x50, 0x04, 0x20}, /*"g", 71*/ + {0x20, 0x40, 0x3F, 0xC0, 0x04, 0x40, 0x04, 0x00, 0x03, 0xC0, 0x00, 0x40}, /*"h", 72*/ + {0x00, 0x00, 0x04, 0x40, 0x27, 0xC0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}, /*"i", 73*/ + {0x00, 0x10, 0x00, 0x10, 0x04, 0x10, 0x27, 0xE0, 0x00, 0x00, 0x00, 0x00}, /*"j", 74*/ + {0x20, 0x40, 0x3F, 0xC0, 0x01, 0x40, 0x07, 0x00, 0x04, 0xC0, 0x04, 0x40}, /*"k", 75*/ + {0x20, 0x40, 0x20, 0x40, 0x3F, 0xC0, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00}, /*"l", 76*/ + {0x07, 0xC0, 0x04, 0x00, 0x07, 0xC0, 0x04, 0x00, 0x03, 0xC0, 0x00, 0x00}, /*"m", 77*/ + {0x04, 0x40, 0x07, 0xC0, 0x04, 0x40, 0x04, 0x00, 0x03, 0xC0, 0x00, 0x40}, /*"n", 78*/ + {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x04, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"o", 79*/ + {0x04, 0x10, 0x07, 0xF0, 0x04, 0x50, 0x04, 0x40, 0x03, 0x80, 0x00, 0x00}, /*"p", 80*/ + {0x00, 0x00, 0x03, 0x80, 0x04, 0x40, 0x04, 0x50, 0x07, 0xF0, 0x00, 0x10}, /*"q", 81*/ + {0x04, 0x40, 0x07, 0xC0, 0x02, 0x40, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00}, /*"r", 82*/ + {0x00, 0x00, 0x06, 0x40, 0x05, 0x40, 0x05, 0x40, 0x04, 0xC0, 0x00, 0x00}, /*"s", 83*/ + {0x00, 0x00, 0x04, 0x00, 0x1F, 0x80, 0x04, 0x40, 0x00, 0x40, 0x00, 0x00}, /*"t", 84*/ + {0x04, 0x00, 0x07, 0x80, 0x00, 0x40, 0x04, 0x40, 0x07, 0xC0, 0x00, 0x40}, /*"u", 85*/ + {0x04, 0x00, 0x07, 0x00, 0x04, 0xC0, 0x01, 0x80, 0x06, 0x00, 0x04, 0x00}, /*"v", 86*/ + {0x06, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x01, 0xC0, 0x06, 0x00, 0x00, 0x00}, /*"w", 87*/ + {0x04, 0x40, 0x06, 0xC0, 0x01, 0x00, 0x06, 0xC0, 0x04, 0x40, 0x00, 0x00}, /*"x", 88*/ + {0x04, 0x10, 0x07, 0x10, 0x04, 0xE0, 0x01, 0x80, 0x06, 0x00, 0x04, 0x00}, /*"y", 89*/ + {0x00, 0x00, 0x04, 0x40, 0x05, 0xC0, 0x06, 0x40, 0x04, 0x40, 0x00, 0x00}, /*"z", 90*/ + {0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x7B, 0xE0, 0x40, 0x20, 0x00, 0x00}, /*"{", 91*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00}, /*"|", 92*/ + {0x00, 0x00, 0x40, 0x20, 0x7B, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"}", 93*/ + {0x40, 0x00, 0x80, 0x00, 0x40, 0x00, 0x20, 0x00, 0x20, 0x00, 0x40, 0x00}, /*"~", 94*/ +}; + +static const uint8_t gsc_ssd1306_ascii_1608[95][16] = +{ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*" ", 0*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xCC, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"!", 1*/ + {0x00, 0x00, 0x08, 0x00, 0x30, 0x00, 0x60, 0x00, 0x08, 0x00, 0x30, 0x00, 0x60, 0x00, 0x00, 0x00}, /*""", 2*/ + {0x02, 0x20, 0x03, 0xFC, 0x1E, 0x20, 0x02, 0x20, 0x03, 0xFC, 0x1E, 0x20, 0x02, 0x20, 0x00, 0x00}, /*"#", 3*/ + {0x00, 0x00, 0x0E, 0x18, 0x11, 0x04, 0x3F, 0xFF, 0x10, 0x84, 0x0C, 0x78, 0x00, 0x00, 0x00, 0x00}, /*"$", 4*/ + {0x0F, 0x00, 0x10, 0x84, 0x0F, 0x38, 0x00, 0xC0, 0x07, 0x78, 0x18, 0x84, 0x00, 0x78, 0x00, 0x00}, /*"%", 5*/ + {0x00, 0x78, 0x0F, 0x84, 0x10, 0xC4, 0x11, 0x24, 0x0E, 0x98, 0x00, 0xE4, 0x00, 0x84, 0x00, 0x08}, /*"&", 6*/ + {0x08, 0x00, 0x68, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"'", 7*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x18, 0x18, 0x20, 0x04, 0x40, 0x02, 0x00, 0x00}, /*"(", 8*/ + {0x00, 0x00, 0x40, 0x02, 0x20, 0x04, 0x18, 0x18, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*")", 9*/ + {0x02, 0x40, 0x02, 0x40, 0x01, 0x80, 0x0F, 0xF0, 0x01, 0x80, 0x02, 0x40, 0x02, 0x40, 0x00, 0x00}, /*"*", 10*/ + {0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x0F, 0xF8, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00}, /*"+", 11*/ + {0x00, 0x01, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*", ", 12*/ + {0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80}, /*"-", 13*/ + {0x00, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*".", 14*/ + {0x00, 0x00, 0x00, 0x06, 0x00, 0x18, 0x00, 0x60, 0x01, 0x80, 0x06, 0x00, 0x18, 0x00, 0x20, 0x00}, /*"/", 15*/ + {0x00, 0x00, 0x07, 0xF0, 0x08, 0x08, 0x10, 0x04, 0x10, 0x04, 0x08, 0x08, 0x07, 0xF0, 0x00, 0x00}, /*"0", 16*/ + {0x00, 0x00, 0x08, 0x04, 0x08, 0x04, 0x1F, 0xFC, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"1", 17*/ + {0x00, 0x00, 0x0E, 0x0C, 0x10, 0x14, 0x10, 0x24, 0x10, 0x44, 0x11, 0x84, 0x0E, 0x0C, 0x00, 0x00}, /*"2", 18*/ + {0x00, 0x00, 0x0C, 0x18, 0x10, 0x04, 0x11, 0x04, 0x11, 0x04, 0x12, 0x88, 0x0C, 0x70, 0x00, 0x00}, /*"3", 19*/ + {0x00, 0x00, 0x00, 0xE0, 0x03, 0x20, 0x04, 0x24, 0x08, 0x24, 0x1F, 0xFC, 0x00, 0x24, 0x00, 0x00}, /*"4", 20*/ + {0x00, 0x00, 0x1F, 0x98, 0x10, 0x84, 0x11, 0x04, 0x11, 0x04, 0x10, 0x88, 0x10, 0x70, 0x00, 0x00}, /*"5", 21*/ + {0x00, 0x00, 0x07, 0xF0, 0x08, 0x88, 0x11, 0x04, 0x11, 0x04, 0x18, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"6", 22*/ + {0x00, 0x00, 0x1C, 0x00, 0x10, 0x00, 0x10, 0xFC, 0x13, 0x00, 0x1C, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"7", 23*/ + {0x00, 0x00, 0x0E, 0x38, 0x11, 0x44, 0x10, 0x84, 0x10, 0x84, 0x11, 0x44, 0x0E, 0x38, 0x00, 0x00}, /*"8", 24*/ + {0x00, 0x00, 0x07, 0x00, 0x08, 0x8C, 0x10, 0x44, 0x10, 0x44, 0x08, 0x88, 0x07, 0xF0, 0x00, 0x00}, /*"9", 25*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*":", 26*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*";", 27*/ + {0x00, 0x00, 0x00, 0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x00, 0x00}, /*"<", 28*/ + {0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x00, 0x00}, /*"=", 29*/ + {0x00, 0x00, 0x10, 0x04, 0x08, 0x08, 0x04, 0x10, 0x02, 0x20, 0x01, 0x40, 0x00, 0x80, 0x00, 0x00}, /*">", 30*/ + {0x00, 0x00, 0x0E, 0x00, 0x12, 0x00, 0x10, 0x0C, 0x10, 0x6C, 0x10, 0x80, 0x0F, 0x00, 0x00, 0x00}, /*"?", 31*/ + {0x03, 0xE0, 0x0C, 0x18, 0x13, 0xE4, 0x14, 0x24, 0x17, 0xC4, 0x08, 0x28, 0x07, 0xD0, 0x00, 0x00}, /*"@", 32*/ + {0x00, 0x04, 0x00, 0x3C, 0x03, 0xC4, 0x1C, 0x40, 0x07, 0x40, 0x00, 0xE4, 0x00, 0x1C, 0x00, 0x04}, /*"A", 33*/ + {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x04, 0x11, 0x04, 0x0E, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"B", 34*/ + {0x03, 0xE0, 0x0C, 0x18, 0x10, 0x04, 0x10, 0x04, 0x10, 0x04, 0x10, 0x08, 0x1C, 0x10, 0x00, 0x00}, /*"C", 35*/ + {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x10, 0x04, 0x10, 0x04, 0x08, 0x08, 0x07, 0xF0, 0x00, 0x00}, /*"D", 36*/ + {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x04, 0x17, 0xC4, 0x10, 0x04, 0x08, 0x18, 0x00, 0x00}, /*"E", 37*/ + {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x00, 0x17, 0xC0, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"F", 38*/ + {0x03, 0xE0, 0x0C, 0x18, 0x10, 0x04, 0x10, 0x04, 0x10, 0x44, 0x1C, 0x78, 0x00, 0x40, 0x00, 0x00}, /*"G", 39*/ + {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x84, 0x00, 0x80, 0x00, 0x80, 0x10, 0x84, 0x1F, 0xFC, 0x10, 0x04}, /*"H", 40*/ + {0x00, 0x00, 0x10, 0x04, 0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x10, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"I", 41*/ + {0x00, 0x03, 0x00, 0x01, 0x10, 0x01, 0x10, 0x01, 0x1F, 0xFE, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"J", 42*/ + {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x03, 0x80, 0x14, 0x64, 0x18, 0x1C, 0x10, 0x04, 0x00, 0x00}, /*"K", 43*/ + {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x0C, 0x00, 0x00}, /*"L", 44*/ + {0x10, 0x04, 0x1F, 0xFC, 0x1F, 0x00, 0x00, 0xFC, 0x1F, 0x00, 0x1F, 0xFC, 0x10, 0x04, 0x00, 0x00}, /*"M", 45*/ + {0x10, 0x04, 0x1F, 0xFC, 0x0C, 0x04, 0x03, 0x00, 0x00, 0xE0, 0x10, 0x18, 0x1F, 0xFC, 0x10, 0x00}, /*"N", 46*/ + {0x07, 0xF0, 0x08, 0x08, 0x10, 0x04, 0x10, 0x04, 0x10, 0x04, 0x08, 0x08, 0x07, 0xF0, 0x00, 0x00}, /*"O", 47*/ + {0x10, 0x04, 0x1F, 0xFC, 0x10, 0x84, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x0F, 0x00, 0x00, 0x00}, /*"P", 48*/ + {0x07, 0xF0, 0x08, 0x18, 0x10, 0x24, 0x10, 0x24, 0x10, 0x1C, 0x08, 0x0A, 0x07, 0xF2, 0x00, 0x00}, /*"Q", 49*/ + {0x10, 0x04, 0x1F, 0xFC, 0x11, 0x04, 0x11, 0x00, 0x11, 0xC0, 0x11, 0x30, 0x0E, 0x0C, 0x00, 0x04}, /*"R", 50*/ + {0x00, 0x00, 0x0E, 0x1C, 0x11, 0x04, 0x10, 0x84, 0x10, 0x84, 0x10, 0x44, 0x1C, 0x38, 0x00, 0x00}, /*"S", 51*/ + {0x18, 0x00, 0x10, 0x00, 0x10, 0x04, 0x1F, 0xFC, 0x10, 0x04, 0x10, 0x00, 0x18, 0x00, 0x00, 0x00}, /*"T", 52*/ + {0x10, 0x00, 0x1F, 0xF8, 0x10, 0x04, 0x00, 0x04, 0x00, 0x04, 0x10, 0x04, 0x1F, 0xF8, 0x10, 0x00}, /*"U", 53*/ + {0x10, 0x00, 0x1E, 0x00, 0x11, 0xE0, 0x00, 0x1C, 0x00, 0x70, 0x13, 0x80, 0x1C, 0x00, 0x10, 0x00}, /*"V", 54*/ + {0x1F, 0xC0, 0x10, 0x3C, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0xE0, 0x10, 0x3C, 0x1F, 0xC0, 0x00, 0x00}, /*"W", 55*/ + {0x10, 0x04, 0x18, 0x0C, 0x16, 0x34, 0x01, 0xC0, 0x01, 0xC0, 0x16, 0x34, 0x18, 0x0C, 0x10, 0x04}, /*"X", 56*/ + {0x10, 0x00, 0x1C, 0x00, 0x13, 0x04, 0x00, 0xFC, 0x13, 0x04, 0x1C, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"Y", 57*/ + {0x08, 0x04, 0x10, 0x1C, 0x10, 0x64, 0x10, 0x84, 0x13, 0x04, 0x1C, 0x04, 0x10, 0x18, 0x00, 0x00}, /*"Z", 58*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFE, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x00, 0x00}, /*"[", 59*/ + {0x00, 0x00, 0x30, 0x00, 0x0C, 0x00, 0x03, 0x80, 0x00, 0x60, 0x00, 0x1C, 0x00, 0x03, 0x00, 0x00}, /*"\", 60*/ + {0x00, 0x00, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x7F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"]", 61*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00}, /*"^", 62*/ + {0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01}, /*"_", 63*/ + {0x00, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"`", 64*/ + {0x00, 0x00, 0x00, 0x98, 0x01, 0x24, 0x01, 0x44, 0x01, 0x44, 0x01, 0x44, 0x00, 0xFC, 0x00, 0x04}, /*"a", 65*/ + {0x10, 0x00, 0x1F, 0xFC, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x00, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"b", 66*/ + {0x00, 0x00, 0x00, 0x70, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x00, 0x88, 0x00, 0x00}, /*"c", 67*/ + {0x00, 0x00, 0x00, 0x70, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x11, 0x08, 0x1F, 0xFC, 0x00, 0x04}, /*"d", 68*/ + {0x00, 0x00, 0x00, 0xF8, 0x01, 0x44, 0x01, 0x44, 0x01, 0x44, 0x01, 0x44, 0x00, 0xC8, 0x00, 0x00}, /*"e", 69*/ + {0x00, 0x00, 0x01, 0x04, 0x01, 0x04, 0x0F, 0xFC, 0x11, 0x04, 0x11, 0x04, 0x11, 0x00, 0x18, 0x00}, /*"f", 70*/ + {0x00, 0x00, 0x00, 0xD6, 0x01, 0x29, 0x01, 0x29, 0x01, 0x29, 0x01, 0xC9, 0x01, 0x06, 0x00, 0x00}, /*"g", 71*/ + {0x10, 0x04, 0x1F, 0xFC, 0x00, 0x84, 0x01, 0x00, 0x01, 0x00, 0x01, 0x04, 0x00, 0xFC, 0x00, 0x04}, /*"h", 72*/ + {0x00, 0x00, 0x01, 0x04, 0x19, 0x04, 0x19, 0xFC, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"i", 73*/ + {0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01, 0x01, 0x19, 0x01, 0x19, 0xFE, 0x00, 0x00, 0x00, 0x00}, /*"j", 74*/ + {0x10, 0x04, 0x1F, 0xFC, 0x00, 0x24, 0x00, 0x40, 0x01, 0xB4, 0x01, 0x0C, 0x01, 0x04, 0x00, 0x00}, /*"k", 75*/ + {0x00, 0x00, 0x10, 0x04, 0x10, 0x04, 0x1F, 0xFC, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"l", 76*/ + {0x01, 0x04, 0x01, 0xFC, 0x01, 0x04, 0x01, 0x00, 0x01, 0xFC, 0x01, 0x04, 0x01, 0x00, 0x00, 0xFC}, /*"m", 77*/ + {0x01, 0x04, 0x01, 0xFC, 0x00, 0x84, 0x01, 0x00, 0x01, 0x00, 0x01, 0x04, 0x00, 0xFC, 0x00, 0x04}, /*"n", 78*/ + {0x00, 0x00, 0x00, 0xF8, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x00, 0xF8, 0x00, 0x00}, /*"o", 79*/ + {0x01, 0x01, 0x01, 0xFF, 0x00, 0x85, 0x01, 0x04, 0x01, 0x04, 0x00, 0x88, 0x00, 0x70, 0x00, 0x00}, /*"p", 80*/ + {0x00, 0x00, 0x00, 0x70, 0x00, 0x88, 0x01, 0x04, 0x01, 0x04, 0x01, 0x05, 0x01, 0xFF, 0x00, 0x01}, /*"q", 81*/ + {0x01, 0x04, 0x01, 0x04, 0x01, 0xFC, 0x00, 0x84, 0x01, 0x04, 0x01, 0x00, 0x01, 0x80, 0x00, 0x00}, /*"r", 82*/ + {0x00, 0x00, 0x00, 0xCC, 0x01, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0x98, 0x00, 0x00}, /*"s", 83*/ + {0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x07, 0xF8, 0x01, 0x04, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00}, /*"t", 84*/ + {0x01, 0x00, 0x01, 0xF8, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x01, 0x08, 0x01, 0xFC, 0x00, 0x04}, /*"u", 85*/ + {0x01, 0x00, 0x01, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x10, 0x01, 0x60, 0x01, 0x80, 0x01, 0x00}, /*"v", 86*/ + {0x01, 0xF0, 0x01, 0x0C, 0x00, 0x30, 0x01, 0xC0, 0x00, 0x30, 0x01, 0x0C, 0x01, 0xF0, 0x01, 0x00}, /*"w", 87*/ + {0x00, 0x00, 0x01, 0x04, 0x01, 0x8C, 0x00, 0x74, 0x01, 0x70, 0x01, 0x8C, 0x01, 0x04, 0x00, 0x00}, /*"x", 88*/ + {0x01, 0x01, 0x01, 0x81, 0x01, 0x71, 0x00, 0x0E, 0x00, 0x18, 0x01, 0x60, 0x01, 0x80, 0x01, 0x00}, /*"y", 89*/ + {0x00, 0x00, 0x01, 0x84, 0x01, 0x0C, 0x01, 0x34, 0x01, 0x44, 0x01, 0x84, 0x01, 0x0C, 0x00, 0x00}, /*"z", 90*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3E, 0xFC, 0x40, 0x02, 0x40, 0x02}, /*"{", 91*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"|", 92*/ + {0x00, 0x00, 0x40, 0x02, 0x40, 0x02, 0x3E, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"}", 93*/ + {0x00, 0x00, 0x60, 0x00, 0x80, 0x00, 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x00, 0x20, 0x00}, /*"~", 94*/ +}; + +static const uint8_t gsc_ssd1306_ascii_2412[95][36] = +{ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*" ", 0*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x38, 0x0F, 0xFE, 0x38, 0x0F, 0x80, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"!", 1*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x38, 0x00, 0x00, 0x31, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x38, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00}, /*""", 2*/ + {0x00, 0x00, 0x00, 0x00, 0x61, 0x80, 0x00, 0x67, 0xF8, 0x07, 0xF9, 0x80, 0x00, 0x61, 0x80, 0x00, 0x61, 0x80, 0x00, 0x61, 0x80, 0x00, 0x61, 0x80, 0x00, 0x67, 0xF8, 0x07, 0xF9, 0x80, 0x00, 0x61, 0x80, 0x00, 0x00, 0x00}, /*"#", 3*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0xE0, 0x03, 0xE0, 0xF0, 0x06, 0x30, 0x08, 0x04, 0x18, 0x08, 0x1F, 0xFF, 0xFE, 0x04, 0x0E, 0x08, 0x07, 0x87, 0xF0, 0x03, 0x81, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"$", 4*/ + {0x01, 0xF0, 0x00, 0x06, 0x0C, 0x00, 0x04, 0x04, 0x08, 0x06, 0x0C, 0x70, 0x01, 0xF9, 0xC0, 0x00, 0x0E, 0x00, 0x00, 0x3B, 0xE0, 0x00, 0xEC, 0x18, 0x07, 0x08, 0x08, 0x04, 0x0C, 0x18, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00}, /*"%", 5*/ + {0x00, 0x01, 0xE0, 0x00, 0x07, 0xF0, 0x03, 0xF8, 0x18, 0x04, 0x1C, 0x08, 0x04, 0x17, 0x08, 0x07, 0xE1, 0xD0, 0x03, 0xC0, 0xE0, 0x00, 0x23, 0xB0, 0x00, 0x3C, 0x08, 0x00, 0x20, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"&", 6*/ + {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x31, 0x00, 0x00, 0x32, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"'", 7*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x01, 0xFF, 0xC0, 0x07, 0x80, 0xF0, 0x0C, 0x00, 0x18, 0x10, 0x00, 0x04, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00}, /*"(", 8*/ + {0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x10, 0x00, 0x04, 0x0C, 0x00, 0x18, 0x07, 0x80, 0xF0, 0x01, 0xFF, 0xC0, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*")", 9*/ + {0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x66, 0x00, 0x00, 0x66, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x18, 0x00, 0x03, 0xFF, 0xC0, 0x00, 0x18, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x66, 0x00, 0x00, 0x66, 0x00, 0x00, 0x42, 0x00}, /*"*", 10*/ + {0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x01, 0xFF, 0xC0, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00}, /*"+", 11*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x31, 0x00, 0x00, 0x32, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*", ", 12*/ + {0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}, /*"-", 13*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x38, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*".", 14*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x70, 0x00, 0x01, 0x80, 0x00, 0x0E, 0x00, 0x00, 0x38, 0x00, 0x00, 0xC0, 0x00, 0x07, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"/", 15*/ + {0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x03, 0x80, 0x70, 0x01, 0xFF, 0xE0, 0x00, 0x7F, 0x80, 0x00, 0x00, 0x00}, /*"0", 16*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x01, 0x00, 0x08, 0x01, 0x00, 0x08, 0x03, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"1", 17*/ + {0x00, 0x00, 0x00, 0x01, 0xC0, 0x38, 0x02, 0xC0, 0x58, 0x04, 0x00, 0x98, 0x04, 0x01, 0x18, 0x04, 0x02, 0x18, 0x04, 0x04, 0x18, 0x06, 0x1C, 0x18, 0x03, 0xF8, 0x18, 0x01, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"2", 18*/ + {0x00, 0x00, 0x00, 0x01, 0xC0, 0xE0, 0x03, 0xC0, 0xF0, 0x04, 0x00, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x06, 0x18, 0x08, 0x03, 0xF4, 0x18, 0x01, 0xE7, 0xF0, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"3", 19*/ + {0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x11, 0x00, 0x00, 0x61, 0x00, 0x00, 0x81, 0x08, 0x03, 0x01, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00}, /*"4", 20*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0xFC, 0xD0, 0x06, 0x08, 0x08, 0x06, 0x10, 0x08, 0x06, 0x10, 0x08, 0x06, 0x10, 0x08, 0x06, 0x18, 0x38, 0x06, 0x0F, 0xF0, 0x06, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"5", 21*/ + {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x84, 0x30, 0x02, 0x08, 0x18, 0x04, 0x10, 0x08, 0x04, 0x10, 0x08, 0x04, 0x10, 0x08, 0x07, 0x18, 0x10, 0x03, 0x0F, 0xF0, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x00}, /*"6", 22*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 0xF8, 0x06, 0x07, 0xF8, 0x06, 0x18, 0x00, 0x06, 0xE0, 0x00, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"7", 23*/ + {0x00, 0x00, 0x00, 0x01, 0xE1, 0xE0, 0x03, 0xF7, 0xF0, 0x06, 0x34, 0x10, 0x04, 0x18, 0x08, 0x04, 0x18, 0x08, 0x04, 0x0C, 0x08, 0x04, 0x0C, 0x08, 0x06, 0x16, 0x18, 0x03, 0xF3, 0xF0, 0x01, 0xC1, 0xE0, 0x00, 0x00, 0x00}, /*"8", 24*/ + {0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x03, 0xFC, 0x30, 0x03, 0x06, 0x38, 0x04, 0x02, 0x08, 0x04, 0x02, 0x08, 0x04, 0x02, 0x08, 0x04, 0x04, 0x10, 0x03, 0x08, 0xF0, 0x01, 0xFF, 0xC0, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00}, /*"9", 25*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x38, 0x00, 0x70, 0x38, 0x00, 0x70, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*":", 26*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x1A, 0x00, 0x30, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*";", 27*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x14, 0x00, 0x00, 0x22, 0x00, 0x00, 0x41, 0x00, 0x00, 0x80, 0x80, 0x01, 0x00, 0x40, 0x02, 0x00, 0x20, 0x04, 0x00, 0x10, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"<", 28*/ + {0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00}, /*"=", 29*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x04, 0x00, 0x10, 0x02, 0x00, 0x20, 0x01, 0x00, 0x40, 0x00, 0x80, 0x80, 0x00, 0x41, 0x00, 0x00, 0x22, 0x00, 0x00, 0x14, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}, /*">", 30*/ + {0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x04, 0xC0, 0x00, 0x04, 0x00, 0x00, 0x08, 0x00, 0x38, 0x08, 0x0F, 0x38, 0x08, 0x08, 0x38, 0x08, 0x10, 0x00, 0x0C, 0x30, 0x00, 0x07, 0xE0, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00}, /*"?", 31*/ + {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x02, 0x0F, 0x10, 0x06, 0x70, 0x88, 0x04, 0xC0, 0x88, 0x04, 0x83, 0x08, 0x04, 0x7F, 0x88, 0x02, 0xC0, 0x90, 0x03, 0x01, 0x20, 0x00, 0xFE, 0x40}, /*"@", 32*/ + {0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x01, 0xF8, 0x00, 0x3E, 0x08, 0x01, 0xC2, 0x00, 0x07, 0x02, 0x00, 0x07, 0xE2, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x1F, 0xC8, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x38, 0x00, 0x00, 0x08}, /*"A", 33*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x06, 0x18, 0x08, 0x03, 0xF4, 0x18, 0x01, 0xE7, 0xF0, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00}, /*"B", 34*/ + {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x02, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x10, 0x06, 0x00, 0x20, 0x07, 0x80, 0xC0, 0x00, 0x00, 0x00}, /*"C", 35*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x18, 0x02, 0x00, 0x10, 0x03, 0x80, 0x70, 0x01, 0xFF, 0xE0, 0x00, 0x7F, 0x80, 0x00, 0x00, 0x00}, /*"D", 36*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x08, 0x08, 0x04, 0x3E, 0x08, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x01, 0x00, 0x60, 0x00, 0x00, 0x00}, /*"E", 37*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x00, 0x04, 0x08, 0x00, 0x04, 0x08, 0x00, 0x04, 0x3E, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00}, /*"F", 38*/ + {0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x02, 0x08, 0x04, 0x02, 0x08, 0x02, 0x03, 0xF0, 0x07, 0x83, 0xF0, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00}, /*"G", 39*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x04, 0x08, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08}, /*"H", 40*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"I", 41*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x04, 0x00, 0x01, 0x04, 0x00, 0x01, 0x04, 0x00, 0x03, 0x07, 0xFF, 0xFE, 0x07, 0xFF, 0xFC, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"J", 42*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x0C, 0x08, 0x00, 0x18, 0x00, 0x00, 0x3E, 0x00, 0x04, 0xC7, 0x80, 0x05, 0x03, 0xC8, 0x06, 0x00, 0xF8, 0x04, 0x00, 0x38, 0x04, 0x00, 0x18, 0x00, 0x00, 0x08}, /*"K", 43*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00}, /*"L", 44*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0x80, 0x08, 0x07, 0xFC, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x03, 0xF8, 0x00, 0x07, 0xC0, 0x00, 0x78, 0x00, 0x07, 0x80, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08}, /*"M", 45*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0x00, 0x08, 0x03, 0xC0, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x38, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0xC0, 0x04, 0x00, 0xF0, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x00}, /*"N", 46*/ + {0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x03, 0x00, 0x30, 0x01, 0xFF, 0xE0, 0x00, 0x7F, 0x80, 0x00, 0x00, 0x00}, /*"O", 47*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x04, 0x08, 0x04, 0x04, 0x00, 0x04, 0x04, 0x00, 0x04, 0x04, 0x00, 0x04, 0x04, 0x00, 0x06, 0x0C, 0x00, 0x03, 0xF8, 0x00, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00}, /*"P", 48*/ + {0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0x80, 0x70, 0x06, 0x00, 0x88, 0x04, 0x00, 0x88, 0x04, 0x00, 0xC8, 0x06, 0x00, 0x3C, 0x03, 0x00, 0x3E, 0x01, 0xFF, 0xE6, 0x00, 0x7F, 0x84, 0x00, 0x00, 0x00}, /*"Q", 49*/ + {0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x08, 0x08, 0x04, 0x08, 0x00, 0x04, 0x0C, 0x00, 0x04, 0x0F, 0x00, 0x04, 0x0B, 0xC0, 0x06, 0x10, 0xF0, 0x03, 0xF0, 0x38, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x08}, /*"R", 50*/ + {0x00, 0x00, 0x00, 0x01, 0xE0, 0xF8, 0x03, 0xF0, 0x30, 0x06, 0x30, 0x10, 0x04, 0x18, 0x08, 0x04, 0x18, 0x08, 0x04, 0x0C, 0x08, 0x04, 0x0C, 0x08, 0x02, 0x06, 0x18, 0x02, 0x07, 0xF0, 0x07, 0x81, 0xE0, 0x00, 0x00, 0x00}, /*"S", 51*/ + {0x01, 0x80, 0x00, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x07, 0xFF, 0xF8, 0x04, 0x00, 0x08, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x80, 0x00}, /*"T", 52*/ + {0x04, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x07, 0xFF, 0xF0, 0x04, 0x00, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x04, 0x00, 0x10, 0x07, 0xFF, 0xE0, 0x04, 0x00, 0x00}, /*"U", 53*/ + {0x04, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x07, 0xFE, 0x00, 0x04, 0x1F, 0xE0, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x38, 0x00, 0x01, 0xE0, 0x04, 0x3E, 0x00, 0x07, 0xC0, 0x00, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"V", 54*/ + {0x04, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x07, 0xFF, 0xC0, 0x04, 0x1F, 0xF8, 0x00, 0x07, 0xC0, 0x07, 0xF8, 0x00, 0x07, 0xFF, 0x80, 0x04, 0x3F, 0xF8, 0x00, 0x07, 0xC0, 0x04, 0xF8, 0x00, 0x07, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"W", 55*/ + {0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x07, 0xC0, 0x78, 0x05, 0xF1, 0xC8, 0x00, 0x3E, 0x00, 0x00, 0x1F, 0x80, 0x04, 0x63, 0xE8, 0x07, 0x80, 0xF8, 0x06, 0x00, 0x18, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"X", 56*/ + {0x04, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0x80, 0x00, 0x07, 0xE0, 0x08, 0x04, 0x7C, 0x08, 0x00, 0x1F, 0xF8, 0x00, 0x07, 0xF8, 0x00, 0x18, 0x08, 0x04, 0xE0, 0x08, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00}, /*"Y", 57*/ + {0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x06, 0x00, 0x38, 0x04, 0x00, 0xF8, 0x04, 0x03, 0xE8, 0x04, 0x0F, 0x08, 0x04, 0x7C, 0x08, 0x05, 0xF0, 0x08, 0x07, 0xC0, 0x08, 0x07, 0x00, 0x18, 0x04, 0x00, 0x60, 0x00, 0x00, 0x00}, /*"Z", 58*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFE, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00}, /*"[", 59*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x38, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x30, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}, /*"\", 60*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x20, 0x00, 0x02, 0x3F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"]", 61*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00, 0x30, 0x00, 0x00, 0x10, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"^", 62*/ + {0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01}, /*"_", 63*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"`", 64*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x19, 0xF8, 0x00, 0x1B, 0x18, 0x00, 0x22, 0x08, 0x00, 0x26, 0x08, 0x00, 0x24, 0x08, 0x00, 0x24, 0x10, 0x00, 0x3F, 0xF8, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18}, /*"a", 65*/ + {0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF0, 0x00, 0x18, 0x18, 0x00, 0x10, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x30, 0x18, 0x00, 0x1F, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00}, /*"b", 66*/ + {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x18, 0x30, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x3C, 0x08, 0x00, 0x1C, 0x10, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"c", 67*/ + {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x38, 0x18, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x04, 0x10, 0x10, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"d", 68*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x12, 0x30, 0x00, 0x22, 0x18, 0x00, 0x22, 0x08, 0x00, 0x22, 0x08, 0x00, 0x32, 0x08, 0x00, 0x1E, 0x10, 0x00, 0x0E, 0x20, 0x00, 0x00, 0x00}, /*"e", 69*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x01, 0xFF, 0xF8, 0x03, 0xFF, 0xF8, 0x06, 0x20, 0x08, 0x04, 0x20, 0x08, 0x04, 0x20, 0x08, 0x07, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"f", 70*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x6E, 0x00, 0x1F, 0xF3, 0x00, 0x31, 0xB1, 0x00, 0x20, 0xB1, 0x00, 0x20, 0xB1, 0x00, 0x31, 0x91, 0x00, 0x1F, 0x13, 0x00, 0x2E, 0x1E, 0x00, 0x20, 0x0E, 0x00, 0x30, 0x00}, /*"g", 71*/ + {0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"h", 72*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x06, 0x3F, 0xF8, 0x06, 0x3F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"i", 73*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x20, 0x01, 0x00, 0x20, 0x01, 0x00, 0x20, 0x03, 0x06, 0x3F, 0xFE, 0x06, 0x3F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"j", 74*/ + {0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x01, 0x88, 0x00, 0x03, 0x00, 0x00, 0x2F, 0xC0, 0x00, 0x38, 0xF8, 0x00, 0x20, 0x38, 0x00, 0x20, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"k", 75*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 0x07, 0xFF, 0xF8, 0x0F, 0xFF, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"l", 76*/ + {0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x20, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x20, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x00, 0x08}, /*"m", 77*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x10, 0x08, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00}, /*"n", 78*/ + {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x0F, 0xF0, 0x00, 0x18, 0x30, 0x00, 0x30, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x30, 0x08, 0x00, 0x18, 0x30, 0x00, 0x0F, 0xF0, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x00}, /*"o", 79*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x3F, 0xFF, 0x00, 0x3F, 0xFF, 0x00, 0x10, 0x11, 0x00, 0x20, 0x09, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x30, 0x38, 0x00, 0x1F, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00}, /*"p", 80*/ + {0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x1F, 0xF0, 0x00, 0x38, 0x18, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x09, 0x00, 0x10, 0x11, 0x00, 0x1F, 0xFF, 0x00, 0x3F, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}, /*"q", 81*/ + {0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x3F, 0xF8, 0x00, 0x3F, 0xF8, 0x00, 0x08, 0x08, 0x00, 0x10, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x00, 0x00, 0x30, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00}, /*"r", 82*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x78, 0x00, 0x1E, 0x18, 0x00, 0x33, 0x08, 0x00, 0x23, 0x08, 0x00, 0x21, 0x08, 0x00, 0x21, 0x88, 0x00, 0x21, 0x98, 0x00, 0x30, 0xF0, 0x00, 0x38, 0x60, 0x00, 0x00, 0x00}, /*"s", 83*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0xFF, 0xF0, 0x03, 0xFF, 0xF8, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"t", 84*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x7F, 0xF8, 0x00, 0x00, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x20, 0x10, 0x00, 0x3F, 0xF8, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, /*"u", 85*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x30, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x23, 0xF0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x70, 0x00, 0x23, 0x80, 0x00, 0x3C, 0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00}, /*"v", 86*/ + {0x00, 0x20, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x23, 0xF8, 0x00, 0x00, 0xE0, 0x00, 0x27, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x21, 0xF8, 0x00, 0x01, 0xE0, 0x00, 0x3E, 0x00, 0x00, 0x20, 0x00}, /*"w", 87*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x20, 0x08, 0x00, 0x38, 0x38, 0x00, 0x3E, 0x68, 0x00, 0x27, 0x80, 0x00, 0x03, 0xC8, 0x00, 0x2C, 0xF8, 0x00, 0x38, 0x38, 0x00, 0x20, 0x18, 0x00, 0x20, 0x08, 0x00, 0x00, 0x00}, /*"x", 88*/ + {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x30, 0x03, 0x00, 0x3C, 0x01, 0x00, 0x3F, 0x83, 0x00, 0x23, 0xEC, 0x00, 0x00, 0x70, 0x00, 0x23, 0x80, 0x00, 0x3C, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00}, /*"y", 89*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x08, 0x00, 0x20, 0x38, 0x00, 0x20, 0xF8, 0x00, 0x23, 0xE8, 0x00, 0x2F, 0x88, 0x00, 0x3E, 0x08, 0x00, 0x38, 0x08, 0x00, 0x20, 0x18, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00}, /*"z", 90*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x14, 0x00, 0x1F, 0xF7, 0xFC, 0x30, 0x00, 0x06, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"{", 91*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"|", 92*/ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x30, 0x00, 0x06, 0x1F, 0xF7, 0xFC, 0x00, 0x14, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*"}", 93*/ + {0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00, 0x00}, /*"~", 94*/ +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/board/ssd1306/driver_ssd1306_interface.h b/app/src/board/ssd1306/driver_ssd1306_interface.h new file mode 100644 index 0000000..093ed1d --- /dev/null +++ b/app/src/board/ssd1306/driver_ssd1306_interface.h @@ -0,0 +1,192 @@ +/** + * Copyright (c) 2015 - present LibDriver All rights reserved + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file driver_ssd1306_interface.h + * @brief driver ssd1306 interface header file + * @version 2.0.0 + * @author Shifeng Li + * @date 2021-03-30 + * + *

history

+ * + *
Date Version Author Description + *
2021/03/30 2.0 Shifeng Li format the code + *
2020/12/10 1.0 Shifeng Li first upload + *
+ */ + +#ifndef DRIVER_SSD1306_INTERFACE_H +#define DRIVER_SSD1306_INTERFACE_H + +#include "driver_ssd1306.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +/** + * @defgroup ssd1306_interface_driver ssd1306 interface driver function + * @brief ssd1306 interface driver modules + * @ingroup ssd1306_driver + * @{ + */ + +/** + * @brief interface iic bus init + * @return status code + * - 0 success + * - 1 iic init failed + * @note none + */ +uint8_t ssd1306_interface_iic_init(void); + +/** + * @brief interface iic bus deinit + * @return status code + * - 0 success + * - 1 iic deinit failed + * @note none + */ +uint8_t ssd1306_interface_iic_deinit(void); + +/** + * @brief interface iic bus write + * @param[in] addr is the iic device write address + * @param[in] reg is the iic register address + * @param[in] *buf points to a data buffer + * @param[in] len is the length of the data buffer + * @return status code + * - 0 success + * - 1 write failed + * @note none + */ +uint8_t ssd1306_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len); + +/** + * @brief interface spi bus init + * @return status code + * - 0 success + * - 1 spi init failed + * @note none + */ +uint8_t ssd1306_interface_spi_init(void); + +/** + * @brief interface spi bus deinit + * @return status code + * - 0 success + * - 1 spi deinit failed + * @note none + */ +uint8_t ssd1306_interface_spi_deinit(void); + +/** + * @brief interface spi bus write + * @param[in] *buf points to a data buffer + * @param[in] len is the length of data buffer + * @return status code + * - 0 success + * - 1 write failed + * @note none + */ +uint8_t ssd1306_interface_spi_write_cmd(uint8_t *buf, uint16_t len); + +/** + * @brief interface delay ms + * @param[in] ms + * @note none + */ +void ssd1306_interface_delay_ms(uint32_t ms); + +/** + * @brief interface print format data + * @param[in] fmt is the format data + * @note none + */ +void ssd1306_interface_debug_print(const char *const fmt, ...); + +/** + * @brief interface command && data gpio init + * @return status code + * - 0 success + * - 1 gpio init failed + * @note none + */ +uint8_t ssd1306_interface_spi_cmd_data_gpio_init(void); + +/** + * @brief interface command && data gpio deinit + * @return status code + * - 0 success + * - 1 gpio deinit failed + * @note none + */ +uint8_t ssd1306_interface_spi_cmd_data_gpio_deinit(void); + +/** + * @brief interface command && data gpio write + * @param[in] value is the written value + * @return status code + * - 0 success + * - 1 gpio write failed + * @note none + */ +uint8_t ssd1306_interface_spi_cmd_data_gpio_write(uint8_t value); + +/** + * @brief interface reset gpio init + * @return status code + * - 0 success + * - 1 gpio init failed + * @note none + */ +uint8_t ssd1306_interface_reset_gpio_init(void); + +/** + * @brief interface reset gpio deinit + * @return status code + * - 0 success + * - 1 gpio deinit failed + * @note none + */ +uint8_t ssd1306_interface_reset_gpio_deinit(void); + +/** + * @brief interface reset gpio write + * @param[in] value is the written value + * @return status code + * - 0 success + * - 1 gpio write failed + * @note none + */ +uint8_t ssd1306_interface_reset_gpio_write(uint8_t value); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/board/ssd1306/fontlib.c b/app/src/board/ssd1306/fontlib.c new file mode 100644 index 0000000..b2e6090 --- /dev/null +++ b/app/src/board/ssd1306/fontlib.c @@ -0,0 +1,83 @@ +#include "fontlib.h" + +static FontLibrary_t s_fontlibrary[10]; +static uint8_t s_fontlibrarylen = 0; + +uint8_t str_iterator_start(StrIterator_t *iterator, FontCode_t code, const char *chr) { + iterator->str = chr; + iterator->nowoff = 0; + iterator->code = code; + return 0; +} +uint8_t str_iterator_isend(StrIterator_t *iterator) { return iterator->str[iterator->nowoff] == '\0'; } +void str_iterator_next(StrIterator_t *iterator, const char **nowchr) { + *nowchr = iterator->str + iterator->nowoff; + if (*nowchr[0] == '\0') { + *nowchr = NULL; + return; + } + while (iterator->str[iterator->nowoff] != '\0') { + if ((iterator->str[iterator->nowoff] < 0x80)) { + iterator->nowoff++; + break; + } else { + if (iterator->code == kgbk) { + iterator->nowoff += 2; + } else if (iterator->code == kutf8) { + iterator->nowoff += 3; + } + break; + } + } +} + +void FontLibrary_regsiter(FontLibrary_t *lib) { s_fontlibrary[s_fontlibrarylen++] = *lib; } + +FontLibrary_t *FontLibrary_findlib(FontCode_t fontcode, uint8_t widthPixel, uint8_t heightPixel, bool isAscii) { + for (size_t i = 0; i < s_fontlibrarylen; i++) { + if (s_fontlibrary[i].fontCode == fontcode && // + s_fontlibrary[i].isAscii == isAscii && // + s_fontlibrary[i].widthPixel == widthPixel && // + s_fontlibrary[i].heightPixel == heightPixel) { + return &s_fontlibrary[i]; + } + } + return NULL; +} + +void FontLibrary_findchar(FontLibrary_t *lib, const char *chr, const uint8_t **font) { + *font = NULL; + + uint8_t eachIndexWidth = 1; + if (lib->isAscii) { + eachIndexWidth = 1; + } else { + if (lib->fontCode == kutf8) { + eachIndexWidth = 3; + } else if (lib->fontCode == kgbk) { + eachIndexWidth = 2; + } + } + + if (eachIndexWidth == 1) { + for (int i = 0; i < lib->fontIndexLen; i += 1) { + if (lib->fontIndex[i] == chr[0]) { + *font = &lib->font[i * lib->widthPixel * lib->heightPixel / 8]; + } + } + } else if (eachIndexWidth == 2) { + for (int i = 0; i < lib->fontIndexLen; i += 2) { + if (lib->fontIndex[i] == chr[0] && lib->fontIndex[i + 1] == chr[1]) { + *font = &lib->font[i / 2 * lib->widthPixel * lib->heightPixel / 8]; + } + } + } else if (eachIndexWidth == 3) { + for (int i = 0; i < lib->fontIndexLen; i += 3) { + if (lib->fontIndex[i] == chr[0] && lib->fontIndex[i + 1] == chr[1] && lib->fontIndex[i + 2] == chr[2]) { + *font = &lib->font[i / 3 * lib->widthPixel * lib->heightPixel / 8]; + } + } + } +} + +bool str_is_ascii(const char *chr) { return chr[0] < 0x80; } diff --git a/app/src/board/ssd1306/fontlib.h b/app/src/board/ssd1306/fontlib.h new file mode 100644 index 0000000..14113c6 --- /dev/null +++ b/app/src/board/ssd1306/fontlib.h @@ -0,0 +1,41 @@ +#pragma once +#include +#include +#include +typedef enum { + kutf8, + kgbk, +} FontCode_t; + +typedef enum { + kFontSize08x16, + kFontSize16x16, +} FontSize_t; + +typedef struct { + const uint8_t *font; + + const char *fontIndex; + int fontIndexLen; + + FontCode_t fontCode; + bool isAscii; + + uint8_t widthPixel; + uint8_t heightPixel; +} FontLibrary_t; + +typedef struct { + const char *str; + int nowoff; + FontCode_t code; +} StrIterator_t; + +uint8_t str_iterator_start(StrIterator_t *iterator, FontCode_t code, const char *chr); +uint8_t str_iterator_isend(StrIterator_t *iterator); +void str_iterator_next(StrIterator_t *iterator, const char **nowchr); +bool str_is_ascii(const char *chr); + +void FontLibrary_regsiter(FontLibrary_t *lib); +FontLibrary_t *FontLibrary_findlib(FontCode_t fontcode, uint8_t widthPixel, uint8_t heightPixel, bool isAscii); +void FontLibrary_findchar(FontLibrary_t *lib, const char *chr, const uint8_t **font); diff --git a/app/src/board/ssd1306/wave_drawer.c b/app/src/board/ssd1306/wave_drawer.c new file mode 100644 index 0000000..a98fe9f --- /dev/null +++ b/app/src/board/ssd1306/wave_drawer.c @@ -0,0 +1,92 @@ +#include "wave_drawer.h" + +#include "znordic.h" + +static bool m_draw_scan_line = false; + +void wave_drawer_init(wave_drawer_t *dw, uint8_t xs, uint8_t ys, uint16_t width, uint16_t high) { + dw->xs = xs; + dw->ys = ys; + dw->width = width; + dw->high = high; + dw->pointoffset = 0; + + dw->xright_border = xs + width; + dw->xleft_border = xs; + dw->ytop_border = ys; + dw->ybottom_border = ys + high; + + dw->ytop = ys + 1; + dw->ybottom = ys + high - 2; + dw->xleft = xs + 1; + dw->xright = xs + width - 1; + + dw->high = high - 2; + dw->width = width - 1; + dw->is_first_point = true; +} + +void wave_drawer_draw_border(wave_drawer_t *dw) { + for (uint16_t x = dw->xleft_border; x <= dw->xright_border; x++) { + for (uint16_t y = dw->ytop_border; y <= dw->ybottom_border; y++) { + if (x == dw->xleft_border || x == dw->xright_border || y == dw->ytop_border || y == dw->ybottom_border) { + ssd1306_gram_write_point(ssd1306_handler(), x, y, 1); + } else { + ssd1306_gram_write_point(ssd1306_handler(), x, y, 0); + } + } + } +} + +void wave_drawer_draw_next_point(wave_drawer_t *dw, uint8_t y) { + /** + * @brief + * + * ---------------- + * | + * | . ..| .... + * |.. . | + * | + * |--------------- + */ + + uint16_t yreal = y / 100.0 * (dw->high - 4); + uint16_t ypos = dw->ybottom - yreal; + uint16_t xpos = dw->xleft + dw->pointoffset; + + // Çå³ýÉÏÒ»´ÎµÄµã + for (size_t yoff = 0; yoff < dw->high; yoff++) { + ssd1306_gram_write_point(ssd1306_handler(), xpos + 0, dw->ybottom - yoff, 0); + } + + ssd1306_gram_write_point(ssd1306_handler(), xpos, ypos, 1); + if (xpos > dw->last_xs && !dw->is_first_point) { + // »­µ±Ç°µãºÍÉÏÒ»´ÎµãµÄÁ¬Ïß + ssd1306_basic_draw_line(xpos - 1, dw->last_ys, xpos, ypos); + } + /** + * @brief »­µ±Ç°Î»ÖñêÖ¾ + */ + for (size_t yoff = 0; yoff < dw->high; yoff++) { + if (xpos + 1 <= dw->xright) { + if (m_draw_scan_line) { + ssd1306_gram_write_point(ssd1306_handler(), xpos + 1, dw->ybottom - yoff, 1); + } else { + ssd1306_gram_write_point(ssd1306_handler(), xpos + 1, dw->ybottom - yoff, 0); + } + } + for (uint8_t i = 2; i < 2 + 5; i++) { + if (xpos + i <= dw->xright) { + ssd1306_gram_write_point(ssd1306_handler(), xpos + i, dw->ybottom - yoff, 0); + } + } + } + dw->last_xs = xpos; + dw->last_ys = ypos; + + dw->pointoffset++; + if (dw->pointoffset >= dw->width) { + dw->pointoffset = 0; + } + dw->is_first_point = false; +} \ No newline at end of file diff --git a/app/src/board/ssd1306/wave_drawer.h b/app/src/board/ssd1306/wave_drawer.h new file mode 100644 index 0000000..e42d3fb --- /dev/null +++ b/app/src/board/ssd1306/wave_drawer.h @@ -0,0 +1,33 @@ +#pragma once +#include "driver_ssd1306.h" +#include "driver_ssd1306_basic.h" + +typedef struct { + uint8_t xs; + uint8_t ys; + + uint8_t last_xs; + uint8_t last_ys; + + uint8_t xright_border; + uint8_t xleft_border; + + uint8_t ytop_border; + uint8_t ybottom_border; + + uint8_t ytop; + uint8_t ybottom; + + uint16_t xleft; + uint16_t xright; + + uint16_t width; + uint16_t high; + + uint16_t pointoffset; + bool is_first_point; +} wave_drawer_t; + +void wave_drawer_init(wave_drawer_t *drawer, uint8_t xs, uint8_t ys, uint16_t width, uint16_t high); +void wave_drawer_draw_border(wave_drawer_t *drawer); +void wave_drawer_draw_next_point(wave_drawer_t *drawer, uint8_t y); diff --git a/app/src/config.h b/app/src/config.h deleted file mode 100644 index 3977535..0000000 --- a/app/src/config.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "board/board.h" \ No newline at end of file diff --git a/app/src/device_controler.c b/app/src/device_controler.c deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/device_controler.h b/app/src/device_controler.h deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/device_state.c b/app/src/device_state.c deleted file mode 100644 index 243c1b5..0000000 --- a/app/src/device_state.c +++ /dev/null @@ -1,27 +0,0 @@ - -#include "device_state.h" - -#include "znordic.h" -static device_state_t m_device_state = kdevice_state_standby; // É豸״̬ -static uint32_t m_change_to_cur_state_tp = 0; // Çл»µ½µ±Ç°×´Ì¬µÄʱ¼ä´Á - -void ds_change_to_state(device_state_t state) { - ZLOGI("change state from %s to %s", device_state_to_str(m_device_state), device_state_to_str(state)); - m_device_state = state; - m_change_to_cur_state_tp = znordic_getpower_on_ms(); -} - -uint32_t ds_cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); } -device_state_t ds_now_state() { return m_device_state; } - -static sample_capture_state_t m_sample_capture_state; - -sample_capture_state_t* sample_capture_state_get() { // - return &m_sample_capture_state; -} -void sample_capture_state_reset() { // - m_sample_capture_state.is_over30s = false; -}; -void sample_capture_state_set_is_over30s(bool over30s) { // - m_sample_capture_state.is_over30s = over30s; -} diff --git a/app/src/device_state.h b/app/src/device_state.h deleted file mode 100644 index 5d1e3c6..0000000 --- a/app/src/device_state.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once -#include -#include - -#include "board/board.h" -typedef enum { - kplod_connected_event = 0, // µ¼ÁªÁ¬½Óʼþ - kplod_disconnected_event, // µ¼Áª¶Ï¿ªÊ¼þ - kplod_connecting_event, // µ¼ÁªÁ¬½ÓÖÐʼþ - - kbattery_start_charge_event, // ³äµçʼþ - kbattery_end_charge_event, // ³äµç½áÊøÊ¼þ - - kevent_tmr_scheduler_event, // ¶¨Ê±Æ÷µ÷¶Èʼþ - - kevent_capture_256data_event, // ²ÉÑùÊý¾Ý»Øµ÷ - kevent_capture_little_data_block_event, // µ¥´Î²ÉÑùÊý¾Ý»Øµ÷ -} app_event_type_t; - -typedef uint16_t one_frame_t; - -typedef struct { - app_event_type_t eventType; - union { - uint32_t plod_connected_accumulation_time; // µ¼ÁªÁ¬½ÓÀÛ¼ÆÊ±¼ä - uint8_t* capture_data_cache; // ʵʱ²ÉÑùÊý¾Ý£¬Êý¾Ý³¤¶ÈΪ256×Ö½Ú - struct { - uint32_t frameIndex; - one_frame_t data[LITTLE_DATA_BLOCK_FRAME_NUM]; - } little_data_block; - } val; -} app_event_t; - -typedef enum { - // ´ý»ú - kdevice_state_standby = 0, - // ³äµçÖÐ - kdevice_state_charging, - // ¿ª»ú - kdevice_state_poweron, - // Ê×Ò³ - kdevice_state_home, - // ÌáʾÓû§±£³Ö¾²Ö¹ - kdevice_state_keep_still, - // ²É¼¯ÖÐ - kdevice_state_sampling, - // ²É¼¯Íê³É - kdevice_state_sampling_complete, - // ²É¼¯Òì³£ - kdevice_state_sampling_error, - -} device_state_t; - -static const char* device_state_to_str(device_state_t ds) { - switch (ds) { - case kdevice_state_standby: - return "standby"; - case kdevice_state_poweron: - return "poweron"; - case kdevice_state_home: - return "home"; - case kdevice_state_keep_still: - return "keep_still"; - case kdevice_state_sampling: - return "sampling"; - case kdevice_state_sampling_complete: - return "sampling_complete"; - case kdevice_state_sampling_error: - return "sampling_error"; - case kdevice_state_charging: - return "charging"; - default: - return "unknow"; - } -} - -void app_event_process_cb(void* p_event_data, uint16_t event_size); - -void ds_change_to_state(device_state_t state); -uint32_t ds_cur_state_haspassed_ms(); -device_state_t ds_now_state(); - -typedef struct { - bool is_over30s; -} sample_capture_state_t; - -sample_capture_state_t* sample_capture_state_get(); - -void sample_capture_state_reset(); -void sample_capture_state_set_is_over30s(bool over30s); diff --git a/app/src/display_manager.c b/app/src/display_manager.c deleted file mode 100644 index 34cd303..0000000 --- a/app/src/display_manager.c +++ /dev/null @@ -1,446 +0,0 @@ -#include "display_manager.h" - -#include "../../../screen_res/logo_mono.c" -// -#include - -#include "basic/ssd1306/driver_ssd1306.h" -#include "basic/ssd1306/driver_ssd1306_basic.h" -#include "basic/ssd1306/wave_drawer.h" -#include "board/board_battery_state.h" -#include "board/board_ssd1306_interface.h" -#include "config.h" -#include "font.h" -PageState_t g_pageState; - -void dsp_mgr_change_to_page(page_t page) { // - g_pageState.page = page; - g_pageState.last_page = page; - g_pageState.page_change_to_page_time = znordic_getpower_on_s(); - - g_pageState.in_prompt = false; - memset(g_pageState.prompt, 0, sizeof(g_pageState.prompt)); -} - -uint32_t dsp_mgr_get_page_elapsed_time_s(void) { // - return znordic_getpower_on_s() - g_pageState.page_change_to_page_time; -} - -void dsp_mgr_schedule(void) {} - -PageState_t* dsp_mgr_get_state(void) { return NULL; } - -int compute_x_pos_by_center(int16_t x, int16_t width) { return x - width / 2; } -int compute_y_pos_by_center(int16_t y, int16_t height) { return y - height / 2; } - -#define SCREEN_CENTER_X 64 -#define SCREEN_CENTER_Y 32 - -#define CHARGE_BATTERY_WIDTH (12 * 1.2) -#define CHARGE_BATTERY_HEIGHT (22 * 1.2) - -#define MAIN_PAGE_BATTERY_WIDTH (12) // Ê×Ò³µç³Ø¿í¶È -#define MAIN_PAGE_BATTERY_HEIGHT (22) // Ê×Ò³µç³Ø¸ß¶È - -/******************************************************************************* - * ³äµçÒ³Ãæ * - *******************************************************************************/ -/** - * ÏÔÊ¾ÔªËØ: - * 1.µç³ØµçÁ¿ - * --------------- - * | _ | - * | | | | - * | | - * --------------- - * - * ¶¯»­Ð§¹û: - * 1. µç³ØµçÁ¿±ä»¯ - * - */ - -static uint32_t m_nowshowbatterylevel; // µ±Ç°ÏÔʾµÄµç³ØµçÁ¿ - -void dsp_mgr_change_to_chargingPage() { - ssd1306_basic_clear(); - uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); - uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); - uint8_t xchange, ychange; - ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, BoardBattery_get_battery_level(), CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); - m_nowshowbatterylevel = BoardBattery_get_battery_level(); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_chargingPage); -} - -void chargingPage_set_batteryLevel(int batteryLevel) { - uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); - uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); - uint8_t xchange, ychange; - ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batteryLevel, CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); - ssd1306_basic_gram_update(); -} - -void chargingPage_schedule() { // - static uint32_t last_update_time = 0; - if (znordic_haspassed_ms(last_update_time) < 300) { - return; - } - - last_update_time = znordic_getpower_on_ms(); - m_nowshowbatterylevel += 5; - if (m_nowshowbatterylevel > 100) { - m_nowshowbatterylevel = BoardBattery_get_battery_level(); - } - chargingPage_set_batteryLevel(m_nowshowbatterylevel); -} - -/******************************************************************************* - * »¶Ó­Ò³Ãæ * - *******************************************************************************/ -void dsp_mgr_change_to_welcome() { - /** - * @brief Çл»µ½»¶Ó­½çÃæ - * 1. ¼ÓÔØÆÁÄ»ÍâÉè - * 2. ´ò¿ªÆÁÄ»µçÔ´ - * 3. ³õʼ»¯¿ª»úÒ³Ãæ - */ - - // ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12); - ssd1306_basic_draw_screen((const char*)gImage_logo_mono); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_welcome); -} - -void welcomePage_schedule() {} - -/******************************************************************************* - * Ê×Ò³ * - *******************************************************************************/ -static bool m_main_page_colon_state = false; - -void mainPage_show(bool colon_state) { - static ztm_t now; - int16_t batterylevel; - uint8_t xchange, ychange; - uint8_t x, y; - x = compute_x_pos_by_center(SCREEN_CENTER_X, fontclocklib.widthPixel * 5 + MAIN_PAGE_BATTERY_WIDTH); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, fontclocklib.heightPixel + 1); - znordic_rtc_gettime(&now); - batterylevel = BoardBattery_get_battery_level(); - - ssd1306_basic_clear_gram(); - - // ZLOGI("mainPage_show %d %d", colon_state, x, y); - - ssd1306_basic_draw_str(x, y, &xchange, &ychange, fmt("%02d:%02d", now.tm_hour, now.tm_min), &fontclocklib); - x = x + 6 + xchange; - ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batterylevel, MAIN_PAGE_BATTERY_WIDTH, MAIN_PAGE_BATTERY_HEIGHT); - ssd1306_basic_gram_update(); - m_main_page_colon_state = colon_state; - dsp_mgr_change_to_page(kPage_main); -} - -void dsp_mgr_change_to_main() { mainPage_show(true); } -void mainPage_updateState() { mainPage_show(!m_main_page_colon_state); } -void mainPage_schedule() { - static uint32_t last_update_time = 0; - if (znordic_haspassed_ms(last_update_time) < 300) { - return; - } - last_update_time = znordic_getpower_on_ms(); - mainPage_updateState(); -} - -/******************************************************************************* - * ±£³Ö¾²Ö¹Ò³Ãæ * - *******************************************************************************/ -static int m_prepare_page_progress = 0; -void PreparePage_show(int progress) { - m_prepare_page_progress = progress; - ssd1306_basic_clear_gram(); - uint8_t x = 0; - uint8_t y = 0; - uint8_t xchange, ychange; - - x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); - - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "±£³Ö¾²Ö¹", &font24x24_zh_lib); - - if (progress == 0) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "xxxx", &font8x8_xo_lib); - } else if (progress == 1) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oxxx", &font8x8_xo_lib); - } else if (progress == 2) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooxx", &font8x8_xo_lib); - } else if (progress == 3) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooox", &font8x8_xo_lib); - } else if (progress == 4) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oooo", &font8x8_xo_lib); - } - - ssd1306_basic_gram_update(); -} - -void dsp_mgr_change_to_preparePage() { - PreparePage_show(0); - dsp_mgr_change_to_page(kPage_preparePage); -} -void dsp_mgr_preparePage_set_progress(int progress) { PreparePage_show(progress); } -int dsp_mgr_preparePage_get_progress() { return m_prepare_page_progress; } - -void PreparePage_schedule() {} - -/******************************************************************************* - * ²ÉÑùÒ³Ãæ * - *******************************************************************************/ - -#define SMAPLE_PAGE_START_X 1 -#define SMAPLE_PAGE_START_Y 1 - -typedef struct { - wave_drawer_t wave_drawer; - - int wave_drawser_x; - int wave_drawser_y; - int wave_drawser_hight; - int wave_drawser_width; - - int progress_x; - int progress_y; - - int progress_width; - int progress_hight; - - int heartrate_x; - int heartrate_y; -} sample_page_state_t; -sample_page_state_t m_sample_page_state; -#if 0 -void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // - sample_page_state_t* sps = &m_sample_page_state; - - sps->wave_drawser_x = SMAPLE_PAGE_START_X; - sps->wave_drawser_y = SMAPLE_PAGE_START_Y; - sps->wave_drawser_hight = 40; - sps->wave_drawser_width = 120; - - sps->progress_x = SMAPLE_PAGE_START_X + 1; - sps->progress_y = SMAPLE_PAGE_START_Y + sps->wave_drawser_hight + 3 + 4; - sps->progress_width = 80; - sps->progress_hight = 8; - - sps->heartrate_x = sps->progress_x + sps->progress_width + 2; - sps->heartrate_y = sps->progress_y - 4; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - - ssd1306_basic_clear_gram(); - - wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); - wave_drawer_draw_border(&sps->wave_drawer); - uint8_t xchange, ychange; - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - if (heartrate <= 0) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); - } - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_sampling); -} - -void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool update_screen) { // - - sample_page_state_t* sps = &m_sample_page_state; - uint8_t xchange, ychange; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - - if (progress_s / 10 == 0) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "xxx", &font8x8_xo_lib); - } else if (progress_s / 10 == 1) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oxx", &font8x8_xo_lib); - } else if (progress_s / 10 == 2) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oox", &font8x8_xo_lib); - } else if (progress_s / 10 == 3) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "ooo", &font8x8_xo_lib); - } - - wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - if (heartrate <= 0) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); - } - if (update_screen) ssd1306_basic_gram_update(); -} -#endif -void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // - sample_page_state_t* sps = &m_sample_page_state; - - sps->progress_x = SMAPLE_PAGE_START_X + 10; - sps->progress_y = SMAPLE_PAGE_START_Y + 3; - sps->progress_width = 100; - sps->progress_hight = 8; - - sps->wave_drawser_x = SMAPLE_PAGE_START_X + 5; - sps->wave_drawser_y = SMAPLE_PAGE_START_Y + sps->progress_hight + 5; - sps->wave_drawser_hight = 45; - sps->wave_drawser_width = 85; - - sps->heartrate_x = sps->wave_drawser_x + sps->wave_drawser_width + 1; - sps->heartrate_y = sps->wave_drawser_y + 5; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - uint8_t xchange, ychange; - - ssd1306_basic_clear_gram(); - /** - * @brief - * ================= - * | | ÐÄ - * | wave | - * | | ÐÄÂÊ - */ - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); - - wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); - // wave_drawer_draw_border(&sps->wave_drawer); - - ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_sampling); -} - -void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool updateHeart, bool update_screen) { // - - sample_page_state_t* sps = &m_sample_page_state; - uint8_t xchange, ychange; - static bool heart_logo_state = false; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - // if (progress_s / 10 >= 3) { - // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "o", &font8x8_xo_lib); - // } else { - // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); - // } - if (update_screen && updateHeart) { - if (heart_logo_state) { - ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, " ", &font_asicc16x8_lib); - } - heart_logo_state = !heart_logo_state; - } - - if (heartrate <= 0) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); - } else { - if (heartrate >= 100) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); - } - } - wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); - if (update_screen) ssd1306_basic_gram_update(); -} - -void samplePage_schedule() { - static int count = 0; - count++; - int capturetime = hwss_has_captured_time_ms(); - int wave_y = (int)hwss_read_val(); - int heartrate = (int)hwss_read_heart_rate(); - // ZLOGI("samplePage_schedule %d %d %d", capturetime, wave_y, heartrate); - samplePage_update_state(capturetime / 1000, wave_y, hwss_read_heart_rate(), count % 30 == 0, count % 10 == 0); -} - -/******************************************************************************* - * samplingError * - *******************************************************************************/ -void dsp_mgr_change_to_samplingError() { - /** - * @brief - * ²»×ã30Ãë[X] - */ - ssd1306_basic_clear_gram(); - - uint8_t x; - uint8_t y; - - x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 3 + font12x24_asiic_lib.widthPixel * 2); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); - - uint8_t xchange, ychange; - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "²»×ã", &font24x24_zh_lib); - x = x + xchange; - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "30", &font12x24_asiic_lib); - x = x + xchange; - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "Ãë", &font24x24_zh_lib); - x = x + xchange; - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_samplingError); -} - -void dsp_mgr_change_to_sampleSuc() { - /** - * @brief - * 1.½ø¶ÈÌõ - * 2.ÌáʾÐÅÏ¢ - */ - ssd1306_basic_clear(); - uint8_t x = 0; - uint8_t y = 0; - - uint8_t xchange, ychange; - x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); - - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "²É¼¯Íê³É", &font24x24_zh_lib); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_storagingSuc); -} - -/******************************************************************************* - * SCHEDULE * - *******************************************************************************/ - -APP_TIMER_DEF(m_dsp_mgr_schedule_tmr); -static void dsp_mgr_schedule_tmr_cb(void* p_context) { // - if (g_pageState.page == kPage_chargingPage) { - chargingPage_schedule(); - } else if (g_pageState.page == kPage_welcome) { - welcomePage_schedule(); - } else if (g_pageState.page == kPage_main) { - mainPage_schedule(); - } else if (g_pageState.page == kPage_preparePage) { - PreparePage_schedule(); - } else if (g_pageState.page == kPage_sampling) { - samplePage_schedule(); - } -} - -void dsp_mgr_init(void) { - static bool timer_inited = false; - board_screen_init(); - if (!timer_inited) { - ZERROR_CHECK(app_timer_create(&m_dsp_mgr_schedule_tmr, APP_TIMER_MODE_REPEATED, dsp_mgr_schedule_tmr_cb)); - } - // ´Ë´¦ÖÜÆÚ¾ö¶¨²ÉÑùÒ»¸öÒ³ÃæÏÔʾµÄ¿í¶È - ZERROR_CHECK(app_timer_start(m_dsp_mgr_schedule_tmr, APP_TIMER_TICKS(12), NULL)); - timer_inited = true; -} -void dsp_mgr_uninit(void) { - app_timer_stop(m_dsp_mgr_schedule_tmr); - board_screen_deinit(); -} diff --git a/app/src/display_manager.h b/app/src/display_manager.h deleted file mode 100644 index 0553b77..0000000 --- a/app/src/display_manager.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include "znordic.h" -// -#include "app_timer.h" -#include "diskio_blkdev.h" -#include "ff.h" -#include "nrf_block_dev_sdc.h" -#include "nrf_delay.h" -#include "nrf_drv_pwm.h" -#include "nrf_drv_saadc.h" -#include "nrf_drv_twi.h" -#include "nrf_drv_wdt.h" -#include "nrf_gpio.h" - -/** - * @brief - * Ò³ÃæÁ÷ת - * - * close <--------------------- - * | - * button ---> welcome ---> main ---> preparePage ---> sampling ---> storaging ---> storagingSuc - * ^ ---> samplingError | - * |-------------------------------------------| | - * |-----------------------------------------------------------| - * - */ - -typedef enum { - kPage_poweroff, - kPage_welcome, - kPage_main, - kPage_preparePage, - kPage_sampling, - kPage_samplingError, - kPage_storaging, - kPage_storagingSuc, - kPage_chargingPage, -} page_t; - -typedef struct { - /** - * @brief Ò³Ãæ×´Ì¬ - */ - page_t page; // µ±Ç°Ò³Ãæ - page_t last_page; // ÉÏÒ»¸öÒ³Ãæ - uint32_t page_change_to_page_time; // µ±Ç°Ò³Ãæ³ÖÐøµÄʱ¼ä - - bool in_prompt; // ÊÇ·ñÔÚÌáʾ״̬ - char prompt[32]; // ÌáʾÄÚÈÝ - - /** - * @brief - */ - -} PageState_t; - -void dsp_mgr_init(void); -void dsp_mgr_uninit(void); -void dsp_mgr_schedule(void); - -PageState_t* dsp_mgr_get_state(void); -uint32_t dsp_mgr_get_page_elapsed_time_s(void); - -void dsp_mgr_change_to_poweroff(); -void dsp_mgr_change_to_welcome(); -void dsp_mgr_change_to_main(); -void dsp_mgr_change_to_chargingPage(); - -// ±£³Ö¾²Ö¹Ò³Ãæ -void dsp_mgr_change_to_preparePage(); -void dsp_mgr_preparePage_set_progress(int progress); -int dsp_mgr_preparePage_get_progress(); - -// ²ÉÑùÖÐÒ³Ãæ -void dsp_mgr_change_to_sampling(int progress_s, int heartrate); - -// ²ÉÑù³ö´íÒ³Ãæ -void dsp_mgr_change_to_samplingError(); -// ²ÉÑù³É¹¦Ò³Ãæ -void dsp_mgr_change_to_sampleSuc(); \ No newline at end of file diff --git a/app/src/display_manager_res.h b/app/src/display_manager_res.h deleted file mode 100644 index 15109eb..0000000 --- a/app/src/display_manager_res.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - - diff --git a/app/src/font.h b/app/src/font.h deleted file mode 100644 index 179ea34..0000000 --- a/app/src/font.h +++ /dev/null @@ -1,275 +0,0 @@ -// https://www.23bei.com/tool-965.html - -#include -#if 0 -const uint8_t fontclocklib_code[] = { - 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0xFF, 0xF0, 0x07, 0x80, 0x78, 0x06, // - 0x00, 0x18, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x07, 0x80, 0x78, 0x03, 0xFF, 0xF0, 0x01, 0xFF, // - 0xE0, 0x00, 0x7F, 0x80, // - 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x07, 0xFF, 0xF0, 0x0F, // - 0xFF, 0xF0, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x03, 0x80, 0x70, 0x07, 0x80, 0xF0, 0x0D, 0x81, 0xB0, 0x08, 0x03, 0x30, 0x08, 0x06, 0x30, 0x08, // - 0x0C, 0x30, 0x0C, 0x38, 0x30, 0x0F, 0xF8, 0x30, 0x07, 0xF1, 0xF0, 0x03, 0xC1, 0xF0, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x03, 0x81, 0xC0, 0x07, 0x81, 0xE0, 0x0F, 0x81, 0xF0, 0x08, 0x10, 0x10, 0x08, 0x10, 0x10, 0x0C, // - 0x30, 0x10, 0x0F, 0xF8, 0x30, 0x07, 0xEF, 0xF0, 0x03, 0xCF, 0xE0, 0x00, 0x03, 0xC0, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x06, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x3A, 0x00, 0x00, 0xE2, 0x00, 0x01, 0xC2, 0x10, 0x07, // - 0x02, 0x10, 0x0F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x00, 0x02, 0x10, 0x00, 0x02, // - 0x10, 0x00, 0x00, 0x00, // - 0x00, 0x01, 0xC0, 0x0F, 0xF9, 0xE0, 0x0F, 0xF9, 0xB0, 0x0C, 0x30, 0x10, 0x0C, 0x20, 0x10, 0x0C, // - 0x20, 0x10, 0x0C, 0x30, 0x70, 0x0C, 0x3F, 0xF0, 0x0C, 0x1F, 0xE0, 0x0C, 0x0F, 0x80, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x7F, 0x00, 0x03, 0xFF, 0xC0, 0x07, 0xFF, 0xE0, 0x07, 0x18, 0x70, 0x0C, 0x30, 0x30, 0x08, // - 0x20, 0x10, 0x08, 0x20, 0x10, 0x0E, 0x30, 0x30, 0x0E, 0x3F, 0xE0, 0x06, 0x1F, 0xE0, 0x00, 0x0F, // - 0x80, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0F, 0x80, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x01, 0xF0, 0x0C, // - 0x0F, 0xF0, 0x0C, 0x3F, 0xF0, 0x0D, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x03, 0xC3, 0xC0, 0x07, 0xEF, 0xE0, 0x0F, 0xEF, 0xE0, 0x0C, 0x78, 0x30, 0x08, 0x30, 0x10, 0x08, // - 0x38, 0x10, 0x08, 0x18, 0x10, 0x0C, 0x3C, 0x30, 0x0F, 0xEF, 0xF0, 0x07, 0xE7, 0xE0, 0x03, 0x83, // - 0xC0, 0x00, 0x00, 0x00, // - 0x01, 0xF0, 0x00, 0x07, 0xF8, 0x60, 0x07, 0xFC, 0x70, 0x0E, 0x0C, 0x70, 0x08, 0x04, 0x10, 0x08, // - 0x04, 0x10, 0x08, 0x0C, 0x30, 0x0E, 0x19, 0xE0, 0x07, 0xFF, 0xE0, 0x03, 0xFF, 0x80, 0x00, 0xFE, // - 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x70, 0x00, // - 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // -}; - -static FontLibrary_t fontclocklib = { - .font = fontclocklib_code, - .fontIndex = "0123456789:", - .fontIndexLen = 12, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 24, - .heightPixel = 24, -}; -#endif - -// DB 00H 00H 07H F0H 0FH F8H 18H 0CH 10H 04H 18H 0CH 0FH F8H 07H F0H;"0",0 -// DB 10H 08H 10H 08H 3FH F8H 3FH F8H 00H 08H 00H 08H 00H 00H 00H 00H;"1",1 -// DB 1CH 18H 3CH 38H 20H 68H 20H C8H 23H 88H 3FH 18H 1CH 18H 00H 00H;"2",2 -// DB 18H 30H 38H 38H 22H 08H 22H 08H 27H 18H 3DH F0H 18H E0H 00H 00H;"3",3 -// DB 01H C0H 07H C0H 0EH 48H 18H 48H 3FH F8H 3FH F8H 00H 48H 00H 00H;"4",4 -// DB 3FH 30H 3FH 38H 23H 08H 22H 08H 23H 18H 21H F0H 20H E0H 00H 00H;"5",5 -// DB 0FH E0H 1FH F0H 33H 18H 22H 08H 33H 18H 31H F0H 00H E0H 00H 00H;"6",6 -// DB 38H 00H 38H 00H 21H F8H 27H F8H 3EH 00H 38H 00H 20H 00H 00H 00H;"7",7 -// DB 1CH 70H 3EH F8H 23H 88H 21H 08H 23H 88H 3EH F8H 1CH 70H 00H 00H;"8",8 -// DB 0EH 00H 1FH 18H 31H 98H 20H 88H 31H 98H 1FH F0H 0FH E0H 00H 00H;"9",9 -// DB 00H 00H 00H 00H 06H 18H 06H 18H 06H 18H 00H 00H 00H 00H 00H 00H;":",10 - -#if 0 -//32*32 -const uint8_t fontclocklib_code[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xFF, 0xFE, 0xF0, - 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, /*"0",0*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x07, 0x07, 0x07, 0x06, 0x04, 0x04, 0x04, 0x00, 0x00, /*"1",1*/ - 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xFF, 0x7F, 0x3E, 0x00, - 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x01, 0x00, /*"2",2*/ - 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0xFF, 0xFE, 0x78, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"3",3*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x3C, 0x0E, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, - 0x00, 0x10, 0x1C, 0x1E, 0x13, 0x11, 0x10, 0x10, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x0F, 0x0F, 0x0F, 0x0F, 0x08, 0x08, 0x08, /*"4",4*/ - 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0xC7, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xE1, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"5",5*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFE, 0x8F, 0x81, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC3, 0x83, 0x03, 0x00, - 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xC3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, /*"6",6*/ - 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x80, 0xE0, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x3F, 0x7F, 0xF1, 0xE0, 0xC0, 0x80, 0x80, 0x80, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, - 0x00, 0xF8, 0xFC, 0xFE, 0x07, 0x03, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0F, 0xFE, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"8",8*/ - 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xFF, 0xFE, 0xF8, 0x00, - 0x00, 0x00, 0x81, 0x83, 0x87, 0x06, 0x04, 0x04, 0x04, 0x06, 0x83, 0xF3, 0xFF, 0x7F, 0x0F, 0x00, 0x00, 0x00, 0x03, 0x03, 0x07, 0x04, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /*":",10*/ -}; -static FontLibrary_t fontclocklib = { - .font = fontclocklib_code, - .fontIndex = "0123456789:", - .fontIndexLen = 12, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 16, - .heightPixel = 32, -}; -#endif - -// 24*24 -const uint8_t fontclocklib_code[] = { - - 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFE, 0x00, 0x01, 0x07, 0x0F, 0x1E, 0x18, 0x10, 0x18, 0x1E, 0x0F, 0x07, 0x01, /*"0",0*/ - 0x00, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, 0x10, 0x00, /*"1",1*/ - 0x00, 0x80, 0xC0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x03, 0x03, 0x03, 0x80, 0xC0, 0x60, 0x38, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x1C, 0x1E, 0x1B, 0x19, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x1F, 0x00, /*"2",2*/ - 0x00, 0x80, 0xC0, 0xE0, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x10, 0x10, 0x18, 0x3F, 0xEF, 0xE7, 0x80, 0x00, 0x00, 0x07, 0x0F, 0x1F, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, 0x00, /*"3",3*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, /*"4",4*/ - 0x00, 0x00, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x07, 0x0F, 0x1B, 0x10, 0x10, 0x10, 0x1C, 0x1F, 0x0F, 0x03, 0x00, /*"5",5*/ - 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x60, 0x20, 0x20, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x31, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x01, 0x07, 0x0F, 0x1C, 0x18, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, /*"6",6*/ - 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0x60, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0xE0, 0xF8, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x87, 0xEF, 0xEF, 0x3C, 0x18, 0x38, 0x30, 0x78, 0xEF, 0xCF, 0x83, 0x00, 0x07, 0x0F, 0x0F, 0x18, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, /*"8",8*/ - 0x00, 0x00, 0xC0, 0xC0, 0xE0, 0x20, 0x20, 0x20, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x60, 0x40, 0x40, 0x60, 0x30, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x0C, 0x1C, 0x1C, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, /*":",10*/ - -}; -static FontLibrary_t fontclocklib = { - .font = fontclocklib_code, - .fontIndex = "0123456789:", - .fontIndexLen = 12, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 12, - .heightPixel = 24, -}; - -const uint8_t font8x8_xo_code[] = { - 0x00, 0x3C, 0x7E, 0x7E, 0x7E, 0x7E, 0x3C, 0x00, /*ʵÐÄÔ²,´ú±íÍê³É*/ - 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, /*¿ÕÐÄÔ²,´ú±íδÍê³É*/ - -}; - -static FontLibrary_t font8x8_xo_lib = { - .font = font8x8_xo_code, - .fontIndex = "ox", - .fontIndexLen = 2, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 8, - .heightPixel = 8, -}; - -const uint8_t font12x24_asiic_code[] = { - - 0x00, 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x01, 0x07, 0x0E, 0x0C, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"0",0*/ - 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, /*"1",1*/ - 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x80, 0xC0, 0xE0, 0x38, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x0F, 0x0B, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /*"2",2*/ - 0x00, 0x80, 0xC0, 0x60, 0x30, 0x30, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x18, 0x38, 0x7F, 0xE7, 0x80, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x0E, 0x07, 0x01, 0x00, /*"3",3*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x01, /*"4",4*/ - 0x00, 0x00, 0xE0, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x0D, 0x04, 0x04, 0x0C, 0x0C, 0x3C, 0xF8, 0xC0, 0x00, 0x01, 0x07, 0x0E, 0x08, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"5",5*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x0F, 0x0D, 0x0C, 0x0C, 0x18, 0xF8, 0xF0, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x03, 0x00, /*"6",6*/ - 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x20, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xE3, 0xFF, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x3F, 0xE7, 0xC0, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x07, 0x03, 0x00, /*"8",8*/ - 0x00, 0xC0, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x02, 0x1F, 0x3D, 0x30, 0x60, 0x60, 0xE0, 0xF0, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x1C, 0xF0, 0xE0, 0xE0, 0x38, 0x1C, 0x04, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0E, 0x03, 0x01, 0x03, 0x07, 0x0E, 0x18, 0x10, 0x00, /*"x",10*/ - 0x00, 0x30, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x83, 0xEF, 0x7C, 0x7E, 0xE7, 0x81, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x01, 0x0F, 0x1E, 0x18, 0x00, /*"X",11*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, /*"[",12*/ - 0x00, 0x0C, 0x0C, 0x0C, 0x0C, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, - /*"]",13*/}; - -static FontLibrary_t font12x24_asiic_lib = { - .font = font12x24_asiic_code, - .fontIndex = "0123456789xX[]", - .fontIndexLen = 15, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 12, - .heightPixel = 24, -}; - -const uint8_t font24x24_zh_code[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF8, 0x38, 0x10, 0x10, 0xF0, 0x90, 0x10, 0x10, 0x10, 0x88, 0xF8, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x0C, 0x06, 0xE7, 0x1C, 0x10, 0x10, 0x10, 0x10, 0x93, - 0x71, 0xFF, 0x39, 0x49, 0x89, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x03, 0x07, 0x06, 0x06, 0x04, 0x04, 0x00, /*"±£",0*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFC, 0xFC, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC2, 0x63, 0x33, 0xFF, 0x0D, 0x09, 0x08, 0x48, - 0x48, 0x49, 0x48, 0x47, 0x4F, 0xFC, 0x24, 0x24, 0x26, 0x06, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x08, 0x38, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x20, 0x60, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"³Ö",1*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xFC, 0x20, 0xA0, 0x20, 0x00, 0x80, 0x60, 0x3C, 0x2C, 0xA0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0C, 0x94, 0x75, 0x55, 0x57, 0x15, 0xF4, 0x02, 0x90, - 0x92, 0x92, 0x92, 0xFF, 0x92, 0x8A, 0x49, 0x3F, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0F, 0x02, 0x01, 0x09, 0x18, 0x0F, 0x00, 0x00, 0x00, 0x20, 0x60, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¾²",2*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0x00, 0x00, 0x00, - 0xFF, 0x0F, 0x08, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x0C, 0x0F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, /*"Ö¹",3*/ - 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x60, 0x60, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x0D, 0xFF, - 0x03, 0x00, 0x00, 0x10, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, /*"²»",4*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xE0, 0x20, 0x20, 0x10, 0x10, 0x10, 0xF8, 0xF8, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x61, 0x87, 0x82, 0x06, 0xFE, - 0x12, 0x11, 0x11, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x02, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"×ã",5*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0xC4, 0x64, 0x1A, 0xFF, 0x12, 0x32, 0x00, 0x18, - 0x0F, 0x00, 0x00, 0x1F, 0x80, 0xE0, 0x3C, 0x08, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x40, 0x20, 0x30, 0x18, 0x0C, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"Ãë",6*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x20, 0x20, 0x38, 0xF8, 0x20, 0x20, 0x20, 0x60, 0x9C, 0x24, 0x10, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x67, 0x7E, 0x00, - 0x10, 0x8C, 0x9B, 0xB9, 0xE4, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x23, 0x3F, 0x11, 0x13, 0x1D, 0x11, 0x1D, 0x17, 0x10, 0x18, 0x1F, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, /*"À¶",7*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x10, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x18, 0x18, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x04, 0x84, 0x64, 0x34, 0x1E, - 0x06, 0xFF, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x10, 0x20, 0x70, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"ÑÀ",8*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x0E, 0x08, 0x08, 0x08, 0x04, 0x04, 0x07, - 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x08, 0x08, 0x18, 0x18, 0x18, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x0C, 0x0E, 0x07, 0x00, 0x00, 0x00, /*"ÒÑ",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x10, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0x20, 0x20, 0xA0, 0xF0, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x67, 0x74, 0x2C, 0x26, 0x01, 0x00, 0x10, 0x50, - 0x48, 0x44, 0xC3, 0xC3, 0x62, 0x24, 0x2C, 0x0C, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x02, 0x02, 0x01, 0x10, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x0B, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x08, 0x00, 0x00, /*"¾­",10*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x40, 0x40, 0xC0, 0xE0, 0x5C, 0x2C, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0xF8, 0x08, 0x00, 0x40, 0x48, 0x4E, 0x4B, - 0x44, 0x45, 0xFF, 0x24, 0x24, 0x24, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x04, 0x07, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x17, 0x30, 0x30, 0x30, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, /*"Á¬",11*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0x98, 0xD0, 0xC0, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x82, 0xC2, 0x62, 0xFF, 0x11, 0x91, 0x80, 0x80, 0x90, - 0x92, 0xF4, 0xB0, 0x98, 0x97, 0x89, 0x48, 0x48, 0x48, 0x40, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x3F, 0x0F, 0x00, 0x00, 0x20, 0x20, 0x13, 0x12, 0x0C, 0x06, 0x0F, 0x08, 0x18, 0x30, 0x20, 0x00, 0x00, 0x00, /*"½Ó",12*/ - 0x00, 0x00, 0x00, 0xE0, 0x40, 0x40, 0x80, 0x00, 0xF8, 0x88, 0x40, 0x20, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x40, 0x25, 0x1A, 0xFF, 0x12, 0x12, 0x12, - 0x00, 0xE0, 0x3F, 0x08, 0x04, 0xFC, 0xFC, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x12, 0x08, 0x06, 0x01, 0x00, 0x00, 0x00, 0x7F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¶Ï",13*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x60, 0xE0, 0x20, 0x20, 0x20, 0x20, 0xF0, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xE8, 0x3F, 0x08, 0x08, - 0x04, 0x04, 0xFF, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¿ª",14*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xF8, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x7F, 0x81, 0x89, 0x49, 0xC8, 0xFF, 0x4C, - 0x44, 0x44, 0x40, 0x3C, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x18, 0x10, 0x10, 0x30, 0x30, 0x30, 0x10, 0x10, 0x1A, 0x1C, 0x00, 0x00, 0x00, /*"µç",15*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x78, 0xA8, 0xA8, 0xA8, 0xA8, 0x88, 0xE4, 0x7C, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x14, 0xF4, 0x94, 0x14, 0x52, 0xF2, - 0xAA, 0xAA, 0x8A, 0xFA, 0x3A, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x24, 0x25, 0x25, 0x25, 0x3F, 0x24, 0x24, 0x27, 0x30, 0x30, 0x30, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, /*"Á¿",16*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC6, 0xFC, 0xA0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x24, 0xE6, 0xA3, 0xA1, 0x94, 0xAF, - 0x10, 0x11, 0xF3, 0xF6, 0x2C, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x21, 0x27, 0x24, 0x24, 0x34, 0x12, 0x16, 0x13, 0x10, 0x10, 0x10, 0x10, 0x30, 0x00, 0x00, 0x00, 0x00, /*"²é",17*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x90, 0x90, 0xF0, 0xB8, 0x88, 0x8C, 0xCC, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0xC8, 0x78, 0xFC, 0xA7, 0xA4, - 0xA4, 0xA4, 0x14, 0x14, 0xF2, 0x22, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x14, 0x14, 0x14, 0x12, 0x10, 0x30, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¿´",18*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x38, 0x10, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xC6, 0x65, 0x3C, 0x2C, 0x23, 0x01, 0x80, 0x02, - 0x22, 0x22, 0x22, 0x22, 0x3F, 0x91, 0x91, 0x91, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x04, 0x06, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x03, 0x1F, 0x09, 0x09, 0x09, 0x08, 0x08, 0x0F, 0x01, 0x00, 0x00, 0x00, /*"½á",19*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0xF0, 0x10, 0x90, 0x90, 0xF0, 0xF0, 0xD0, 0x10, 0x88, 0xF8, 0x78, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x21, 0x27, 0xA4, 0x64, 0xFF, - 0x52, 0x92, 0x12, 0x13, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x00, 0x7F, 0x00, 0x00, 0x01, 0x02, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"¹û",20*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0xD0, 0x90, 0x18, 0x0C, 0x88, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x60, 0x20, 0x20, 0x20, 0x22, 0x22, 0x33, 0x11, - 0xFF, 0x11, 0x11, 0x11, 0x11, 0x10, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x60, 0x78, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"ÊÖ",21*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x86, 0xC2, 0x32, 0x0F, 0xFF, 0x21, 0x61, 0x01, 0x01, - 0xFF, 0x01, 0x01, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x0F, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x0C, 0x0C, 0x0C, 0x0F, 0x06, 0x00, /*"»ú",22*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x20, 0x20, 0x50, 0xD0, 0x88, 0x0C, 0x8C, 0x40, 0x70, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x11, 0xD0, 0x70, 0x32, 0xFC, 0x30, - 0x48, 0x88, 0x88, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x30, 0x7F, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x06, 0x0C, 0x0C, 0x04, 0x08, 0x00, 0x00, /*"²É",23*/ - 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0xF0, 0x0C, 0x24, 0xA0, 0xA4, 0xEC, 0xE8, 0x90, 0x50, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xBF, 0x90, 0x90, 0xD2, 0xF2, - 0xCF, 0x4B, 0x4A, 0x49, 0x48, 0x48, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x7F, 0x00, 0x01, 0x02, 0x04, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x10, 0x00, 0x00, /*"¼¯",24*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x7C, 0xC0, 0x80, 0x80, 0x88, 0x98, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFE, 0x42, 0x42, 0x22, 0x22, 0xE1, 0x21, - 0x03, 0x1F, 0x70, 0x80, 0xE0, 0x3C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x03, 0x00, 0x04, 0x08, 0x1C, 0x07, 0x00, 0x08, 0x04, 0x02, 0x01, 0x07, 0x0C, 0x18, 0x30, 0x70, 0x78, 0x00, 0x00, /*"³É",25*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x81, 0x81, 0xC1, 0x7F, 0x20, 0x20, 0x20, 0x12, - 0x82, 0xE2, 0x3E, 0x07, 0x02, 0x01, 0x01, 0xFF, 0x0F, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x04, 0x08, 0x38, 0x1C, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, /*"¹¦",26*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x40, 0x48, 0x58, 0x50, 0x40, 0x20, 0x20, 0xA0, 0xE0, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x40, 0x60, 0x24, 0xE4, 0x26, 0x22, - 0xF2, 0x12, 0x10, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x00, 0x00, 0x00, 0x1F, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x3E, 0x10, 0x00, 0x00, /*"Íê",27*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x78, 0x10, 0x00, 0x80, 0x80, 0x40, 0x40, 0xA0, 0x38, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0x0C, 0x03, 0xFD, 0x00, 0x00, 0x00, 0xE1, 0xFF, - 0x10, 0x88, 0x0F, 0x3C, 0xE4, 0x84, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x00, 0x00, 0x04, 0x0F, 0x03, 0x01, 0x00, 0x04, 0x0C, 0x00, 0x01, 0x06, 0x0C, 0x18, 0x3E, 0x30, 0x00, /*"µÍ",28*/ -}; -static FontLibrary_t font24x24_zh_lib = { - .font = font24x24_zh_code, - .fontIndex = "±£³Ö¾²Ö¹²»×ãÃëÀ¶ÑÀÒѾ­Á¬½Ó¶Ï¿ªµçÁ¿²é¿´½á¹ûÊÖ»ú²É¼¯³É¹¦ÍêµÍ", - .fontIndexLen = 88, - .fontCode = kgbk, - .isAscii = false, - .widthPixel = 24, - .heightPixel = 24, -}; - -#if 0 -// const unsigned char gImage_heart_16x16[] = { -// /* 0X22,0X01,0X10,0X00,0X10,0X00, */ -// 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XF8, 0X00, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, 0X7F, 0X3F, 0X1F, 0X0F, 0X07, 0X03, 0X00, 0X00, -// }; -#endif - -const unsigned char font_asicc_code_16x8[] = { - 0x00, 0xF0, 0x18, 0x08, 0x08, 0x18, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x30, 0x18, 0x0F, 0x00, /*"0",0*/ - 0x00, 0x60, 0x20, 0xF0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x00, /*"1",1*/ - 0x00, 0x30, 0x18, 0x08, 0x08, 0xD8, 0x70, 0x00, 0x00, 0x30, 0x38, 0x34, 0x33, 0x31, 0x30, 0x00, /*"2",2*/ - 0x00, 0x30, 0x18, 0x08, 0x88, 0xD8, 0x70, 0x00, 0x00, 0x18, 0x10, 0x20, 0x21, 0x13, 0x0E, 0x00, /*"3",3*/ - 0x00, 0x00, 0x80, 0x60, 0x30, 0xF8, 0x00, 0x00, 0x04, 0x07, 0x05, 0x04, 0x04, 0x3F, 0x04, 0x04, /*"4",4*/ - 0x00, 0xF0, 0x98, 0xC8, 0x88, 0x88, 0x08, 0x00, 0x08, 0x19, 0x30, 0x20, 0x30, 0x19, 0x0F, 0x00, /*"5",5*/ - 0x00, 0x80, 0xC0, 0xF0, 0x98, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x31, 0x20, 0x20, 0x30, 0x1F, 0x06, /*"6",6*/ - 0x00, 0x08, 0x08, 0x08, 0x88, 0xE8, 0x38, 0x00, 0x00, 0x00, 0x30, 0x3E, 0x03, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0xF0, 0x88, 0x88, 0x88, 0xD8, 0x70, 0x00, 0x04, 0x1F, 0x31, 0x21, 0x21, 0x31, 0x1E, 0x00, /*"8",8*/ - 0xE0, 0xF0, 0x08, 0x08, 0x08, 0x98, 0xF0, 0x00, 0x00, 0x01, 0x23, 0x3A, 0x0F, 0x03, 0x00, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, /*"-",10*/ - 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x11, 0x00, 0x00, 0x00, /*":",10*/ - - 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, /*?ÓÒ°ë*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" "*/ -}; - -static FontLibrary_t font_asicc16x8_lib = { - .font = font_asicc_code_16x8, - .fontIndex = "0123456789-:<> ", // <> ÕâÁ½¸ö·ûºÅÊÇÐÄÐεÄ×óÓÒ°ë±ß - .fontIndexLen = 16, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 8, - .heightPixel = 16, -}; diff --git a/app/src/heart_ware_sample_data_mgr.c b/app/src/heart_ware_sample_data_mgr.c deleted file mode 100644 index f28c7a0..0000000 --- a/app/src/heart_ware_sample_data_mgr.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "app_event.h" -#include "app_event_distribute.h" -#include "basic/qrs_time_domain_zh.h" -#include "board/board_ecg_sensor.h" -#include "heart_wave_sample_service.h" -#include "nrfx_timer.h" - -static uint32_t m_frame_index = 0; // Ö¡¾ø¶ÔÐòºÅ -/*********************************************************************************************************************** - * ab buffer * - ***********************************************************************************************************************/ -#define FRAME_BUFFER_SIZE (256 / sizeof(one_frame_t)) - -static one_frame_t m_capture_buffer_a[FRAME_BUFFER_SIZE]; -static one_frame_t m_capture_buffer_b[FRAME_BUFFER_SIZE]; -static one_frame_t* m_capture_buffer; -static one_frame_t m_capture_buffer_index = 0; - -static void eeprom_cache_buffer_swap() { - if (m_capture_buffer == NULL) { - m_capture_buffer = m_capture_buffer_a; - m_capture_buffer_index = 0; - return; - } - - if (m_capture_buffer == m_capture_buffer_a) { - m_capture_buffer = m_capture_buffer_b; - } else { - m_capture_buffer = m_capture_buffer_a; - } - m_capture_buffer_index = 0; - return; -} - -/*********************************************************************************************************************** - * littlebuffer * - ***********************************************************************************************************************/ -static one_frame_t m_prepare_data_cache[LITTLE_DATA_BLOCK_FRAME_NUM]; -static uint32_t m_prepare_data_cache_index; - -static inline void preview_data_cache_push_data(one_frame_t data) { - if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { - return; - } - m_prepare_data_cache[m_prepare_data_cache_index] = data; - m_prepare_data_cache_index++; -} - -static inline bool preview_data_cache_is_full(void) { - if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { - return true; - } - return false; -} -static inline void preview_data_cache_clear(void) { m_prepare_data_cache_index = 0; } -static inline void preview_data_trigger_event() { - static app_event_t event; - event.eventType = kevent_capture_little_data_block_event; - for (uint32_t i = 0; i < LITTLE_DATA_BLOCK_FRAME_NUM; i++) { - event.val.little_data_block.data[i] = m_prepare_data_cache[i]; - } - event.val.little_data_block.frameIndex = m_frame_index - LITTLE_DATA_BLOCK_FRAME_NUM; - AppEvent_pushEvent(&event); -} - -/*********************************************************************************************************************** - * EXT * - ***********************************************************************************************************************/ - -void hwsd_mgr_push_one_frame(one_frame_t data) { - m_frame_index++; - - /*********************************************************************************************************************** - * EEPROMÊý¾Ý²ÉÑù´æ´¢ * - ***********************************************************************************************************************/ - if (m_capture_buffer == NULL) eeprom_cache_buffer_swap(); - - if (m_capture_buffer_index < FRAME_BUFFER_SIZE) { - m_capture_buffer[m_capture_buffer_index++] = data; - } - - if (m_capture_buffer_index == FRAME_BUFFER_SIZE) { - app_event_t evt; - evt.eventType = kevent_capture_256data_event; - evt.val.capture_data_cache = (uint8_t*)m_capture_buffer; - eeprom_cache_buffer_swap(); - AppEvent_pushEvent(&evt); - } - - /******************************************************************************* - * ʵʱ²ÉÑùÊý¾ÝʼþÉϱ¨ * - *******************************************************************************/ - /** - * @brief »º´æÊý¾Ý£¬²¢´¥·¢Ð¡Êý¾Ý¿éʼþ - */ - preview_data_cache_push_data(data); - if (preview_data_cache_is_full()) { - preview_data_trigger_event(); - preview_data_cache_clear(); - } -} - -void hwsd_mgr_reset_buffer(){ - m_frame_index = 0; - m_capture_buffer = NULL; - m_capture_buffer_index = 0; - preview_data_cache_clear(); -} diff --git a/app/src/heart_ware_sample_data_mgr.h b/app/src/heart_ware_sample_data_mgr.h deleted file mode 100644 index 24a7e9b..0000000 --- a/app/src/heart_ware_sample_data_mgr.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -#include "app_event.h" -#include "app_event_distribute.h" -#include "nrfx_timer.h" - -void hwsd_mgr_push_one_frame(one_frame_t data); -void hwsd_mgr_reset_buffer(); \ No newline at end of file diff --git a/app/src/heart_wave_sample_data_pre_process.c b/app/src/heart_wave_sample_data_pre_process.c deleted file mode 100644 index 984b197..0000000 --- a/app/src/heart_wave_sample_data_pre_process.c +++ /dev/null @@ -1,107 +0,0 @@ -#include "heart_wave_sample_data_pre_process.h" - -/*********************************************************************************************************************** - * ALGO * - ***********************************************************************************************************************/ - -typedef struct { - float value; - float efectiveFactor; -} filter_t; - -typedef struct { - float coef[2]; - float v_out[2]; -} LPFilter; -#define PI 3.14159265358979323846f - -static float Filter(filter_t* filter, float newInput) { - float newv = ((float)filter->value * (1.0f - filter->efectiveFactor)) + ((float)newInput * filter->efectiveFactor); - filter->value = newv; - return newv; -} - -void LPFilter_Init(LPFilter* filter, float cutoffFreqHz, float sampleTimeS) { - float RC = 0.0; - RC = 1.0 / (2 * PI * cutoffFreqHz); - filter->coef[0] = sampleTimeS / (sampleTimeS + RC); - filter->coef[1] = RC / (sampleTimeS + RC); - - filter->v_out[0] = 0.0; - filter->v_out[1] = 0.0; -} - -float LPFilter_Update(LPFilter* filter, float v_in) { - filter->v_out[1] = filter->v_out[0]; - filter->v_out[0] = (filter->coef[0] * v_in) + (filter->coef[1] * filter->v_out[1]); - - return (filter->v_out[0]); -} - -/** - * @brief ·Å´óÏÔʾÊý¾Ý - * - * @param val - * @param valcener - * @param amp - * @return float - */ -static float amp_display_val(uint16_t val, uint16_t valcener, float amp) { - float valf = (float)val - valcener; - valf = valf * amp; - valf += valcener; - - if (valf >= 100) { - valf = 100; - } - - if (valf <= 0) { - valf = 0; - } - return valf; -} - -uint16_t getRecommendedMagnification() { - // return 0; - uint16_t max = QRS_getMaxValueLastVal(); - if (max == 0) { - return 15; - } - // 3750.0f - if (max <= (3750 / 2)) { - return 15; - } - float af = (3750 / 2) / (max - 3750 / 2); - if (af > 15) { - return 15; - } - return af; -} - -/*********************************************************************************************************************** - * VAR * - ***********************************************************************************************************************/ -static one_frame_t m_datacache; -static one_frame_t m_displaydata; -filter_t m_filter = {0, 0.8}; -LPFilter m_lpfilter_01; -LPFilter m_lpfilter_02; - -void hwsd_pre_processer_init() { QRS_resetBuf(); } -void hwsd_pre_processer_process(one_frame_t framdata) { // - m_datacache = framdata; - m_displaydata = framdata; - /******************************************************************************* - * ÏÔʾÊý¾Ý¼ÆËã²¢¸³Öµ * - *******************************************************************************/ - // QRS_getMaxValueLastVal(); - // float lowpassf_val = LPFilter_Update(&m_lpfilter_01, framdata); - // QRS_processData(lowpassf_val); - // float val_af100 = (float)lowpassf_val / 3750.0f * 100; // ²Î¿¼µçѹΪ3.6v,µ«Ðźŷ¶Î§Îª3.3v - // val_af100 = amp_val(val_af100, 50, getRecommendedMagnification()); - // val_af100 = LPFilter_Update(&m_lpfilter_02, val_af100); - // m_displaydata = m_datacache; -} - -uint16_t hwsd_pre_processer_get_display_data() { return m_displaydata; } -one_frame_t hwsd_pre_processer_get_storage_data() { return m_datacache; } diff --git a/app/src/heart_wave_sample_data_pre_process.h b/app/src/heart_wave_sample_data_pre_process.h deleted file mode 100644 index bb594e4..0000000 --- a/app/src/heart_wave_sample_data_pre_process.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -#include "app_event.h" - -void hwsd_pre_processer_init(); -void hwsd_pre_processer_process(one_frame_t framdata); -one_frame_t hwsd_pre_processer_get_display_data(); -one_frame_t hwsd_pre_processer_get_storage_data(); diff --git a/app/src/heart_wave_sample_service.c b/app/src/heart_wave_sample_service.c deleted file mode 100644 index bb65c00..0000000 --- a/app/src/heart_wave_sample_service.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "heart_wave_sample_service.h" - -#include "app_event.h" -#include "app_event_distribute.h" -#include "basic/qrs_time_domain_zh.h" -#include "board/board_ecg_sensor.h" -#include "heart_ware_sample_data_mgr.h" -#include "heart_wave_sample_data_pre_process.h" -#include "nrfx_timer.h" - -typedef enum { - kidle, - kprepare, - kcapture, -} capture_state_t; - -static capture_state_t m_prepare_capture_state = kidle; -static uint32_t m_start_capture_tp; - -static nrfx_timer_t m_timer = NRFX_TIMER_INSTANCE(HEART_WAVE_SAMPLE_TMR_INSTANCE); - -void nrfx_timer_event_handler(nrf_timer_event_t event_type, void* p_context) { // - static uint16_t val = 25; - val++; - if (val > 75) val = 25; - - if (m_prepare_capture_state == kprepare) { - hwsd_pre_processer_process(val); - } else if (m_prepare_capture_state == kcapture) { - hwsd_pre_processer_process(val); - hwsd_mgr_push_one_frame(hwsd_pre_processer_get_storage_data()); - } -} - -void hwss_init(void) { - static bool m_timer_inited = false; - if (!m_timer_inited) { - /** - * @brief ³õʼ»¯¶¨Ê±Æ÷ - */ - static nrfx_timer_config_t timer_cfg = { - .frequency = NRF_TIMER_FREQ_500kHz, - .mode = NRF_TIMER_MODE_TIMER, - .bit_width = NRF_TIMER_BIT_WIDTH_24, - .p_context = NULL, - .interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, - }; - - // nrfx_timer_init(&m_timer, &timer_cfg, nrfx_timer_event_handler); - ZERROR_CHECK(nrfx_timer_init(&m_timer, &timer_cfg, nrfx_timer_event_handler)); - uint32_t timer_ticks = nrfx_timer_ms_to_ticks(&m_timer, 2); // - ZASSERT(SAMPLE_RATE == 500); - nrfx_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, timer_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); - m_timer_inited = true; - } -} -void hwss_uninit(void) { nrfx_timer_disable(&m_timer); } -void hwss_start_prepare_capture(void) { - m_start_capture_tp = znordic_getpower_on_s(); - m_prepare_capture_state = kprepare; - hwsd_pre_processer_init(); - hwsd_mgr_reset_buffer(); - nrfx_timer_enable(&m_timer); -} -void hwss_start_capture(void) { - m_start_capture_tp = znordic_getpower_on_s(); - m_prepare_capture_state = kcapture; -} -void hwss_stop_capture(void) { - m_prepare_capture_state = kidle; - nrfx_timer_disable(&m_timer); - hwsd_mgr_reset_buffer(); -} - -float hwss_read_val(void) { - __disable_irq(); - float val = hwsd_pre_processer_get_display_data(); - __enable_irq(); - return val; -} -float hwss_read_heart_rate(void) { // - return QRS_getHeartRate(); -} -int hwss_has_captured_time_ms() { return (znordic_getpower_on_s() - m_start_capture_tp) * 1000; } diff --git a/app/src/heart_wave_sample_service.h b/app/src/heart_wave_sample_service.h deleted file mode 100644 index d1df979..0000000 --- a/app/src/heart_wave_sample_service.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include - - -// ÿ256¸ö×Ö½Ú´¥·¢Ò»´Î»Øµ÷ -typedef void (*heart_wave_sample_service_callback_t)(uint16_t *p_data, uint16_t length); - -void hwss_init(void); -void hwss_uninit(void); - -void hwss_start_capture(void); -void hwss_stop_capture(void); - -float hwss_read_val(void); -float hwss_read_heart_rate(void); -int hwss_has_captured_time_ms(); -void hwss_start_prepare_capture(void); \ No newline at end of file diff --git a/app/src/main.c b/app/src/main.c index a949336..d1e9149 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -6,10 +6,10 @@ #include #include // -#include "app_event.h" -#include "app_event_distribute.h" -#include "basic/device_version_info_mgr.h" -#include "board/board.h" +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "basic_service/device_version_info_mgr.h" +#include "aproject_config/config.h" #include "zble_module.h" #include "zdatachannel_service.h" // diff --git a/app/src/one_conduction_main.c b/app/src/one_conduction_main.c index 26145f7..3352b45 100644 --- a/app/src/one_conduction_main.c +++ b/app/src/one_conduction_main.c @@ -1,19 +1,21 @@ #include -#include "app_event.h" -#include "app_event_distribute.h" -#include "basic/device_version_info_mgr.h" -#include "ble_cmd_process_service.h" +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "basic_service/device_version_info_mgr.h" +// #include "board/board_adc_module_ctrl.h" #include "board/board_battery_state.h" #include "board/board_beep_ctrl.h" #include "board/board_ecg_sensor.h" #include "board/board_light_ctrl.h" #include "board/board_power_mgr.h" -#include "config.h" -#include "display_manager.h" -#include "heart_wave_sample_service.h" -#include "sample_data_manager.h" +// +#include "service/ble_cmd_processer/ble_cmd_process_service.h" +#include "service/display_mgr/display_manager.h" +#include "service/heart_wave_sample_service/heart_wave_sample_service.h" +#include "service/storage/storage_service.h" + #include "zble_module.h" #include "zdatachannel_service.h" #include "znordic.h" diff --git a/app/src/sample_data_manager.c b/app/src/sample_data_manager.c deleted file mode 100644 index 04c5204..0000000 --- a/app/src/sample_data_manager.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "sample_data_manager.h" - -#include - -#include "zeeprom_fs.h" -#include "znordic.h" - -static sample_data_fileinfo_t fileinfocache[MAX_FILE_NUM * 2]; -static uint8_t fileinfocache_count = 0; - -void sample_data_mgr_init() { zeeprom_fs_init(); } -void sample_data_mgr_uninit() { zeeprom_fs_uinit(); } - -sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list() { // - static sample_data_fileinfo_list_t fileinfo_list; - memset(&fileinfo_list, 0, sizeof(fileinfo_list)); - fileinfocache_count = 0; - - // ¶ÁÈ¡ËùÓмǼÐÅÏ¢ - zeeprom_header_t* header = zeeprom_fs_get_header(); - - for (uint16_t i = 0; i < ZARRAY_SIZE(header->sectorinfos); i++) { - zeeprom_sector_info_t* sectorinfo = &header->sectorinfos[i]; - if (sectorinfo->usage == 1 && sectorinfo->sector_index_in_file == 0) { - // ¶ÁÈ¡ÎļþÐÅÏ¢ - if (fileinfocache_count >= ZARRAY_SIZE(fileinfocache)) { - ZLOGE("fileinfocache_count >= MAX_FILE_NUM"); - break; - } - - sample_data_fileinfo_t* fileinfo = &fileinfocache[fileinfocache_count]; - fileinfo->fileuuid = sectorinfo->fileuuid; - memcpy(fileinfo->filename, sectorinfo->filename, sizeof(fileinfo->filename)); - fileinfo->size = zeeprom_fs_get_filesize_by_fileuuid(fileinfo->fileuuid); - fileinfo->checksum = zeeprom_fs_get_checksum_by_fileuuid(fileinfo->fileuuid); - - fileinfo_list.fileinfo[fileinfo_list.count] = fileinfo; - fileinfo_list.count++; - fileinfocache_count++; - } - } - // ¸ù¾ÝÎļþuuidÅÅÐò£¬uuid×î´óµÄÅÅÔÚ×îÇ°Ãæ - for (uint16_t i = 0; i < fileinfo_list.count; i++) { - for (uint16_t j = i + 1; j < fileinfo_list.count; j++) { - if (fileinfo_list.fileinfo[i]->fileuuid < fileinfo_list.fileinfo[j]->fileuuid) { - sample_data_fileinfo_t* tmp = fileinfo_list.fileinfo[i]; - fileinfo_list.fileinfo[i] = fileinfo_list.fileinfo[j]; - fileinfo_list.fileinfo[j] = tmp; - } - } - } - return &fileinfo_list; -} - -bool sample_data_mgr_storage_is_full() { return zeeprom_fs_get_file_num() >= MAX_FILE_NUM; } -int32_t sample_data_mgr_get_file_num() { return zeeprom_fs_get_file_num(); } - -#if 1 -static const char* filename2str(uint8_t* filename) { - static char filename_str[32]; - sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); - return filename_str; -} -#endif - -void sample_data_mgr_dump_fileinfo_list() { - zeeprom_fs_dump_sector_state(); - sample_data_fileinfo_list_t* fileinfo_list = sample_data_mgr_get_fileinfo_list(); - ZLOGI_BLOCK("fileinfo_list->count=%d\n", fileinfo_list->count); - for (uint16_t i = 0; i < fileinfo_list->count; i++) { - sample_data_fileinfo_t* fileinfo = fileinfo_list->fileinfo[i]; - ZLOGI_BLOCK("[%d]: filename=%s, fileuuid=%d, size=%d", i, filename2str(fileinfo->filename), fileinfo->fileuuid, fileinfo->size); - } -} - -int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag) { - /** - * @brief ²é¿´ÎļþÊýÁ¿ - */ - if (flag == kwrflag_write_only) { - if (zeeprom_fs_get_file_num() >= MAX_FILE_NUM) { - zeeprom_fs_delete_the_oldest_file(); - } - } - return zeeprom_fs_open((uint8_t*)filename, flag); -} -int32_t sample_data_mgr_close(int32_t fd) { return zeeprom_fs_close(fd); } -int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size) { return zeeprom_fs_write(fd, data, size); } -int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size) { return zeeprom_fs_read(fd, data, size); } -int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd) { return zeeprom_fs_get_filesize_by_fd(fd); } -int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename) { return zeeprom_fs_delete_by_name((uint8_t*)filename); } diff --git a/app/src/sample_data_manager.h b/app/src/sample_data_manager.h deleted file mode 100644 index 5c34fd1..0000000 --- a/app/src/sample_data_manager.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once -#include -#include - -#include "config.h" -#include "zeeprom_fs.h" - -void sample_data_mgr_init(); - -typedef struct { - uint8_t year; - uint8_t month; - uint8_t day; - uint8_t hour; - uint8_t min; - uint8_t sec; - uint8_t placeholder[2]; -} sample_data_filename_t; - -typedef struct { - uint8_t filename[8]; - int32_t fileuuid; - int32_t size; - uint32_t checksum; -} sample_data_fileinfo_t; - -typedef struct { - sample_data_fileinfo_t* fileinfo[MAX_FILE_NUM]; - int count; -} sample_data_fileinfo_list_t; - -void sample_data_mgr_init(); -void sample_data_mgr_uninit(); - -sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list(); -bool sample_data_mgr_storage_is_full(); -int32_t sample_data_mgr_get_file_num(); - -int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag); -int32_t sample_data_mgr_close(int32_t fd); - -int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size); -int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size); -int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd); - -int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename); diff --git a/app/src/service/ble_cmd_processer/ble_cmd_process_service.c b/app/src/service/ble_cmd_processer/ble_cmd_process_service.c new file mode 100644 index 0000000..f6a97ff --- /dev/null +++ b/app/src/service/ble_cmd_processer/ble_cmd_process_service.c @@ -0,0 +1,483 @@ +#include "ble_cmd_process_service.h" + +#include "aproject_config/config.h" +// +#include "ify_hrs_protocol/heart_rate_sensor_protocol.h" +// +#include "basic_service/device_version_info_mgr.h" +#include "board/board_battery_state.h" +#include "board/board_ecg_sensor.h" +#include "service/storage/storage_service.h" +// +#include "zble_module.h" +#include "zdatachannel_service.h" + +APP_TIMER_DEF(m_record_upload_tmr); // Êý¾ÝÉϱ¨¶¨Ê±Æ÷ +APP_TIMER_DEF(m_record_upload_finish_packet_report_tmr); // Êý¾ÝÉϱ¨Íê³ÉÉϱ¨¶¨Ê±Æ÷ +static uint8_t txbuf[128]; +static uint8_t reportbuf[128]; +static bool m_realtime_report_state = false; +static int m_upload_record_state = 0; +static uint32_t m_upload_data_state_enter_tp = 0; + +static bool m_ble_cmder_is_inited = false; +static uint32_t m_report_data_sumcheckcode = 0; + +static void record_upload_tmr_cb(void* p_context); +static void record_upload_finish_packet_report_tmr_cb(void* p_context); +int ble_stop_upload_record(); +/******************************************************************************* + * ¹ã²¥¿ØÖÆ * + *******************************************************************************/ +void ble_cmder_start_adv() { + m_realtime_report_state = false; + zble_module_start_adv(); +} +void ble_cmder_stop_adv() { + zble_module_stop_adv(); + m_realtime_report_state = false; +} + +/******************************************************************************* + * Ä£¿é³õʼ»¯ * + *******************************************************************************/ +void ble_cmder_init() { + if (!m_ble_cmder_is_inited) { + ZERROR_CHECK(app_timer_create(&m_record_upload_tmr, APP_TIMER_MODE_REPEATED, record_upload_tmr_cb)); + ZERROR_CHECK(app_timer_create(&m_record_upload_finish_packet_report_tmr, APP_TIMER_MODE_SINGLE_SHOT, record_upload_finish_packet_report_tmr_cb)); + } + m_ble_cmder_is_inited = true; +} +void ble_cmder_uninit() {} + +/******************************************************************************* + * ʵʱÉϱ¨¿ØÖÆ * + *******************************************************************************/ +int ble_start_realtime_report() { + m_realtime_report_state = true; + return 0; +} +int ble_stop_realtime_report() { + m_realtime_report_state = false; + return 0; +} +void ble_cmder_try_report_one_sample_data(uint32_t frameIndex, uint16_t data0, uint16_t data1, uint16_t data2, uint16_t data3, uint16_t data4) { + if (!m_realtime_report_state) { + return; + } + + heartrate_report_packet_t* reportpacket = (heartrate_report_packet_t*)reportbuf; + reportpacket->cmd = ify_hrs_report_heartrate_data; + reportpacket->frame_index = 0; + reportpacket->frame_type = kifyhrs_pt_report; + reportpacket->sample_data_index = frameIndex; + + reportpacket->data[0] = (data0 >> 0) & 0xFF; // µÚÒ»Ö¡Êý¾Ý + reportpacket->data[1] = (data0 >> 8) & 0xFF; // µÚÒ»Ö¡Êý¾Ý + reportpacket->data[2] = (data1 >> 0) & 0xFF; // µÚ¶þÖ¡Êý¾Ý + reportpacket->data[3] = (data1 >> 8) & 0xFF; // µÚ¶þÖ¡Êý¾Ý + reportpacket->data[4] = (data2 >> 0) & 0xFF; // µÚÈýÖ¡Êý¾Ý + reportpacket->data[5] = (data2 >> 8) & 0xFF; // µÚÈýÖ¡Êý¾Ý + reportpacket->data[6] = (data3 >> 0) & 0xFF; // µÚËÄÖ¡Êý¾Ý + reportpacket->data[7] = (data3 >> 8) & 0xFF; // µÚËÄÖ¡Êý¾Ý + reportpacket->data[8] = (data4 >> 0) & 0xFF; // µÚÎåÖ¡Êý¾Ý + reportpacket->data[9] = (data4 >> 8) & 0xFF; // µÚÎåÖ¡Êý¾Ý + + uint16_t sendlen = sizeof(heartrate_report_packet_t) + 10; + zdatachannel_data_send2(reportbuf, sendlen); + return; +} + +void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1) { + sensor_drop_event_report_packet_t* reportpacket = (sensor_drop_event_report_packet_t*)reportbuf; + reportpacket->cmd = ify_hrs_report_sensor_drop_detect; + reportpacket->frame_index = 0; + reportpacket->frame_type = kifyhrs_pt_report; + reportpacket->drop_state0 = dropstate0; + reportpacket->drop_state1 = dropstate1; + + uint16_t sendlen = sizeof(sensor_drop_event_report_packet_t); + zdatachannel_data_send2(reportbuf, sendlen); + return; +} +void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + 4; + + txheader->cmd = ify_hrs_report_record_upload_end; // 6A + txheader->frame_index = 0; + txheader->frame_type = kifyhrs_pt_report; + + // txheader->data[0] = errorcode; + *(uint32_t*)txheader->data = sumcheckcode; + + zdatachannel_data_send2(txbuf, sendlen); + return; +} + +void ble_cmder_report_sample_finish_event() { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t); + + txheader->cmd = ify_hrs_report_sample_finish_end; + txheader->frame_index = 0; + txheader->frame_type = kifyhrs_pt_report; + + zdatachannel_data_send2(txbuf, sendlen); + return; +} + +/******************************************************************************* + * ÉÏ´«Êý¾Ý¿ØÖÆ * + *******************************************************************************/ +static int m_upload_fd; +static uint8_t datacache[256]; +static int m_remaindatalen = 0; +/** + * @brief Êý¾ÝÉϱ¨¶¨Ê±Æ÷»Øµ÷ + * + * @param p_context + */ +static void record_upload_finish_packet_report_tmr_cb(void* p_context) { // + ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); +} + +static void record_upload_tmr_cb(void* p_context) { // + + if (m_upload_record_state == 0) return; + + if (m_upload_record_state == 1) { + if (m_remaindatalen == 0) { + memset(datacache, 0, sizeof(datacache)); + int32_t rdsize = sample_data_mgr_read(m_upload_fd, datacache, sizeof(datacache)); + if (rdsize <= 0) { + ZLOGI("read file end,stop upload"); + m_upload_record_state = 2; + m_upload_data_state_enter_tp = znordic_getpower_on_ms(); + return; + } + m_remaindatalen = rdsize; + } + if (m_remaindatalen == 0) { + return; + } + + int32_t mtusize = zble_module_get_mtu_size(); + mtusize = mtusize < 128 ? mtusize : 128; + + uint8_t* data = datacache + (sizeof(datacache) - m_remaindatalen); + int len = m_remaindatalen > mtusize ? mtusize : m_remaindatalen; + + ZLOGI("upload %d %d %d", len, m_remaindatalen, mtusize); + if (!zdatachannel_is_connected()) { + ZLOGI("ble is disconnected,stop upload"); + ble_stop_upload_record(); + return; + } + + uint32_t suc = zdatachannel_block_data_send2(data, len); + if (suc != NRF_SUCCESS) { + if (suc == NRF_ERROR_INVALID_STATE) { + // δʹÄÜnotify + ZLOGI("ble unenable notify,stop upload"); + ble_stop_upload_record(); + return; + } else if (suc == NRF_ERROR_BUSY || suc == NRF_ERROR_RESOURCES) { + // µÈ´ýÏ´η¢ËÍ + return; + } else { + ZLOGI("ble send error,stop upload %x", suc); + ble_stop_upload_record(); + return; + } + } + for (uint32_t i = 0; i < len; i++) { + m_report_data_sumcheckcode += data[i]; + } + m_remaindatalen -= len; + } else { + if (znordic_haspassed_ms(m_upload_data_state_enter_tp) > 30) { + ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); + ble_stop_upload_record(); + return; + } + } +} + +int ble_start_upload_record(sample_data_filename_t* recordid) { + // + // Æô¶¯ + // + if (ds_now_state() != kdevice_state_home && ds_now_state() != kdevice_state_charging) { + return kifyhrs_ecode_device_busy; + } + + m_upload_fd = sample_data_mgr_open(recordid, kwrflag_read_only); + if (m_upload_fd <= 0) { + return kifyhrs_ecode_no_record_find; + } + + ZERROR_CHECK(app_timer_start(m_record_upload_tmr, APP_TIMER_TICKS(15), NULL)); + m_upload_record_state = 1; + m_remaindatalen = 0; + m_report_data_sumcheckcode = 0; + return 0; +} +int ble_stop_upload_record() { + m_upload_record_state = 0; + app_timer_stop(m_record_upload_tmr); + if (m_upload_fd > 0) { + sample_data_mgr_close(m_upload_fd); + m_upload_fd = 0; + } + return 0; +} +bool ble_is_upload_record() { return m_upload_record_state != 0; } + +/******************************************************************************* + * UTILS * + *******************************************************************************/ +static void send_error_receipt(ify_hrs_packet_t* rxpacket, int32_t errorcode) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + error_receipt_t* receipt = (error_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(error_receipt_t); + + txheader->cmd = rxpacket->cmd; + txheader->frame_index = rxpacket->frame_index; + txheader->frame_type = kifyhrs_pt_error_receipt; + receipt->errorcode = errorcode; + zdatachannel_data_send2(txbuf, sendlen); +} + +static void send_success_receipt(ify_hrs_packet_t* rxpacket, int32_t emptydatasize) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + emptydatasize; + + txheader->cmd = rxpacket->cmd; + txheader->frame_index = rxpacket->frame_index; + txheader->frame_type = kifyhrs_pt_cmd_receipt; + + zdatachannel_data_send2(txbuf, sendlen); +} + +/******************************************************************************* + * Ï·¢ÏûÏ¢´¦Àí * + *******************************************************************************/ +void ble_cmder_process_rx(uint8_t* rx, int len) { + if (len < sizeof(ify_hrs_packet_t)) { + ZLOGI("rx len error:%d", len); + return; + } + + ify_hrs_packet_t* rxheader = (ify_hrs_packet_t*)rx; + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + ify_hrs_cmd_t cmd = (ify_hrs_cmd_t)rxheader->cmd; + memset(txbuf, 0, sizeof(txbuf)); + + txheader->cmd = rxheader->cmd; + txheader->frame_index = rxheader->frame_index; + txheader->frame_type = kifyhrs_pt_cmd_receipt; + + ZLOGI("rx cmd:%d index:%d datalen:%d", cmd, rxheader->frame_index, len - sizeof(ify_hrs_packet_t)); + NRF_LOG_HEXDUMP_INFO(rx, len); + + if (cmd == ify_hrs_cmd_read_device_version) { + device_version_info_receipt_t* receipt = (device_version_info_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_version_info_receipt_t); + + receipt->blestack_version = device_info_read_blestack_version(); + receipt->bootloader_version = device_info_read_bootloader_version(); + receipt->firmware_version = device_info_read_firmware_version(); + receipt->hardware_version = device_info_read_hardware_version(); + zdatachannel_data_send2(txbuf, sendlen); + } + + else if (cmd == ify_hrs_cmd_read_sensor_info) { + sensor_info_receipt_t* receipt = (sensor_info_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(sensor_info_receipt_t); + + receipt->sensor_num = 1; + receipt->sensor_precision = SAMPLE_PRECISION; + receipt->sensor_sample_rate = SAMPLE_RATE / 10; + receipt->sensor0_pos = kifyhrs_sensor_pos_none; + receipt->sensor1_pos = kifyhrs_sensor_pos_none; + receipt->sensor2_pos = kifyhrs_sensor_pos_none; + + zdatachannel_data_send2(txbuf, sendlen); + } + + else if (cmd == ify_hrs_cmd_read_device_state) { + device_state_receipt_t* receipt = (device_state_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_state_receipt_t); + + receipt->drop_state0 = (!BoardEcgSensor_plod_get_connected_state()); + receipt->drop_state1 = 0x00; + receipt->device_state0.sampling_state = (ds_now_state() == kdevice_state_sampling); + receipt->device_state0.report_state = m_realtime_report_state; + receipt->device_state0.low_battery = (BoardBattery_get_battery_level() < APP_LOW_BATTERY_WARNING_LIMIT); + receipt->device_state0.full_storge = (sample_data_mgr_storage_is_full()); + + receipt->device_state1 = 0; + receipt->powerlevel = BoardBattery_get_battery_level(); + receipt->storage_item_num = sample_data_mgr_get_file_num(); + + zdatachannel_data_send2(txbuf, sendlen); + } + + else if (cmd == ify_hrs_cmd_read_time) { + read_time_receipt_t* receipt = (read_time_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_time_receipt_t); + static ztm_t ztm; + znordic_rtc_gettime(&ztm); + + receipt->year = (ztm.tm_year + 1900 - 2000); + receipt->month = ztm.tm_mon + 1; + receipt->day = ztm.tm_mday; + receipt->hour = ztm.tm_hour; + receipt->minute = ztm.tm_min; + receipt->second = ztm.tm_sec; + zdatachannel_data_send2(txbuf, sendlen); + } + + else if (cmd == ify_hrs_cmd_sync_time) { + sync_time_cmd_t* cmd = (sync_time_cmd_t*)rxheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t); + + znordic_rtc_settime(cmd->year + 2000, cmd->month, cmd->day, cmd->hour, cmd->minute, cmd->second); + zdatachannel_data_send2(txbuf, sendlen); + } + + else if (cmd == ify_hrs_cmd_start_upload_record) { + send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); + } + + else if (cmd == ify_hrs_cmd_stop_upload_record) { + send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); + } + + else if (cmd == ify_hrs_cmd_start_realtime_preview) { + // unsupport cmd + int ecode = ble_start_realtime_report(); + if (ecode == 0) { + send_success_receipt(rxheader, 8); // ´Õ8¸ö×Ö½Ú£¬Ê¹Õâ¸ö»ØÖ´µÄ×Ö½Ú³¤¶ÈͬÉϱ¨°ü³¤¶ÈÒ»Ö£¬·½±ãµ÷ÊÔ + } else { + send_error_receipt(rxheader, ecode); + } + } + + else if (cmd == ify_hrs_cmd_stop_realtime_preview) { + int ecode = ble_stop_realtime_report(); + if (ecode == 0) { + send_success_receipt(rxheader, 0); + } else { + send_error_receipt(rxheader, ecode); + } + } + + else if (cmd == ify_hrs_cmd_read_records_info) { + // Ö¸Áî 10-¶ÁÈ¡²ÉÑù¼Ç¼ͷ²¿ÐÅÏ¢ + read_record_info_cmd_t* cmd = (read_record_info_cmd_t*)rxheader->data; + read_record_info_receipt_t* receipt = (read_record_info_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_record_info_receipt_t); + + uint8_t recordoff = cmd->record_index; + + // ²ÉÑùʱ²»Ö§³Ö + if (ds_now_state() != kdevice_state_home) { + send_error_receipt(rxheader, kifyhrs_ecode_device_busy); + return; + } + + sample_data_fileinfo_list_t* recordlist = sample_data_mgr_get_fileinfo_list(); + if (recordoff >= recordlist->count) { + send_error_receipt(rxheader, kifyhrs_ecode_no_record_find); + return; + } + + sample_data_fileinfo_t* fileinfo = recordlist->fileinfo[recordoff]; + memcpy(receipt->record_id, fileinfo->filename, 6); + receipt->frameNum = fileinfo->size / 2; // 2byte per frame + receipt->dataSize = fileinfo->size; + receipt->sensorNum = 1; + receipt->captureRate = SAMPLE_RATE / 10; + receipt->capturePrecision = SAMPLE_PRECISION; + receipt->compressAlgorithm = 0; + receipt->checksum = fileinfo->checksum; + zdatachannel_data_send2(txbuf, sendlen); + + } + + else if (cmd == ify_hrs_cmd_del_record) { + // Ö¸Áî 11-ɾ³ý²ÉÑù¼Ç¼ + del_record_cmd_t* cmd = (del_record_cmd_t*)rxheader->data; + + static sample_data_filename_t filename; + memset(&filename, 0, sizeof(filename)); + memcpy(&filename, cmd->record_id, sizeof(cmd->record_id)); + + // ²ÉÑùʱ²»Ö§³Ö + if (ds_now_state() != kdevice_state_home) { + send_error_receipt(rxheader, kifyhrs_ecode_device_busy); + return; + } + + int ecode = sample_data_mgr_delete_file(&filename); + if (ecode == 0) { + send_success_receipt(rxheader, 0); + } else { + send_error_receipt(rxheader, kifyhrs_ecode_unkown_error); + } + } + + else if (cmd == ify_hrs_cmd_start_upload_record) { // 12 0x0C + // Ö¸Áî 12-ÉÏ´«²É¼¯¼Ç¼ + start_upload_record_cmd_t* cmd = (start_upload_record_cmd_t*)rxheader->data; + + static sample_data_filename_t filename; + memset(&filename, 0, sizeof(filename)); + memcpy(&filename, cmd->record_id, sizeof(cmd->record_id)); + + // ²ÉÑùʱ²»Ö§³Ö + if (ds_now_state() != kdevice_state_home) { + send_error_receipt(rxheader, kifyhrs_ecode_device_busy); + return; + } + + int ecode = ble_start_upload_record(&filename); + if (ecode == 0) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + 1; // ´ÕÆë4BYTE£¬·½±ãµ÷ÊÔ + txheader->cmd = rxheader->cmd; + txheader->frame_index = rxheader->frame_index; + txheader->frame_type = kifyhrs_pt_cmd_receipt; + + zdatachannel_data_send2(txbuf, sendlen); + } else { + send_error_receipt(rxheader, ecode); + } + } + + else if (cmd == ify_hrs_cmd_stop_upload_record) { + ble_stop_upload_record(); + send_success_receipt(rxheader, 0); + } + + else if (cmd == ify_hrs_cmd_enter_ota) { + send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); + } + + else if (cmd == ify_hrs_cmd_read_sn) { + read_sn_receipt_t* receipt = (read_sn_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_sn_receipt_t); + device_info_read_sn((sn_t*)&receipt->sn); + zdatachannel_data_send2(txbuf, sendlen); + } + + else if (cmd == ify_hrs_cmd_reset) { + NVIC_SystemReset(); + } + // + else { + send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); + } +} diff --git a/app/src/service/ble_cmd_processer/ble_cmd_process_service.h b/app/src/service/ble_cmd_processer/ble_cmd_process_service.h new file mode 100644 index 0000000..1b9658c --- /dev/null +++ b/app/src/service/ble_cmd_processer/ble_cmd_process_service.h @@ -0,0 +1,17 @@ +#pragma once + +#include "basic_service/device_state.h" + +void ble_cmder_init(); +void ble_cmder_uninit(); + +void ble_cmder_process_rx(uint8_t* rx, int len); +void ble_cmder_start_adv(); +void ble_cmder_stop_adv(); + +void ble_cmder_try_report_one_sample_data(uint32_t frameIndex, uint16_t data0, uint16_t data1, uint16_t data2, uint16_t data3, uint16_t data4); +void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1); +void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode); +void ble_cmder_report_sample_finish_event(); +bool ble_is_upload_record(); +int ble_stop_upload_record(); diff --git a/app/src/service/display_mgr/display_manager.c b/app/src/service/display_mgr/display_manager.c new file mode 100644 index 0000000..a886363 --- /dev/null +++ b/app/src/service/display_mgr/display_manager.c @@ -0,0 +1,443 @@ +#include "display_manager.h" + +#include "../../../screen_res/logo_mono.c" +// +#include + +#include "board/board_battery_state.h" +#include "board/board_ssd1306_interface.h" +#include "aproject_config/config.h" +#include "font.h" +PageState_t g_pageState; + +void dsp_mgr_change_to_page(page_t page) { // + g_pageState.page = page; + g_pageState.last_page = page; + g_pageState.page_change_to_page_time = znordic_getpower_on_s(); + + g_pageState.in_prompt = false; + memset(g_pageState.prompt, 0, sizeof(g_pageState.prompt)); +} + +uint32_t dsp_mgr_get_page_elapsed_time_s(void) { // + return znordic_getpower_on_s() - g_pageState.page_change_to_page_time; +} + +void dsp_mgr_schedule(void) {} + +PageState_t* dsp_mgr_get_state(void) { return NULL; } + +int compute_x_pos_by_center(int16_t x, int16_t width) { return x - width / 2; } +int compute_y_pos_by_center(int16_t y, int16_t height) { return y - height / 2; } + +#define SCREEN_CENTER_X 64 +#define SCREEN_CENTER_Y 32 + +#define CHARGE_BATTERY_WIDTH (12 * 1.2) +#define CHARGE_BATTERY_HEIGHT (22 * 1.2) + +#define MAIN_PAGE_BATTERY_WIDTH (12) // Ê×Ò³µç³Ø¿í¶È +#define MAIN_PAGE_BATTERY_HEIGHT (22) // Ê×Ò³µç³Ø¸ß¶È + +/******************************************************************************* + * ³äµçÒ³Ãæ * + *******************************************************************************/ +/** + * ÏÔÊ¾ÔªËØ: + * 1.µç³ØµçÁ¿ + * --------------- + * | _ | + * | | | | + * | | + * --------------- + * + * ¶¯»­Ð§¹û: + * 1. µç³ØµçÁ¿±ä»¯ + * + */ + +static uint32_t m_nowshowbatterylevel; // µ±Ç°ÏÔʾµÄµç³ØµçÁ¿ + +void dsp_mgr_change_to_chargingPage() { + ssd1306_basic_clear(); + uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); + uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); + uint8_t xchange, ychange; + ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, BoardBattery_get_battery_level(), CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); + m_nowshowbatterylevel = BoardBattery_get_battery_level(); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_chargingPage); +} + +void chargingPage_set_batteryLevel(int batteryLevel) { + uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); + uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); + uint8_t xchange, ychange; + ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batteryLevel, CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); + ssd1306_basic_gram_update(); +} + +void chargingPage_schedule() { // + static uint32_t last_update_time = 0; + if (znordic_haspassed_ms(last_update_time) < 300) { + return; + } + + last_update_time = znordic_getpower_on_ms(); + m_nowshowbatterylevel += 5; + if (m_nowshowbatterylevel > 100) { + m_nowshowbatterylevel = BoardBattery_get_battery_level(); + } + chargingPage_set_batteryLevel(m_nowshowbatterylevel); +} + +/******************************************************************************* + * »¶Ó­Ò³Ãæ * + *******************************************************************************/ +void dsp_mgr_change_to_welcome() { + /** + * @brief Çл»µ½»¶Ó­½çÃæ + * 1. ¼ÓÔØÆÁÄ»ÍâÉè + * 2. ´ò¿ªÆÁÄ»µçÔ´ + * 3. ³õʼ»¯¿ª»úÒ³Ãæ + */ + + // ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12); + ssd1306_basic_draw_screen((const char*)gImage_logo_mono); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_welcome); +} + +void welcomePage_schedule() {} + +/******************************************************************************* + * Ê×Ò³ * + *******************************************************************************/ +static bool m_main_page_colon_state = false; + +void mainPage_show(bool colon_state) { + static ztm_t now; + int16_t batterylevel; + uint8_t xchange, ychange; + uint8_t x, y; + x = compute_x_pos_by_center(SCREEN_CENTER_X, fontclocklib.widthPixel * 5 + MAIN_PAGE_BATTERY_WIDTH); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, fontclocklib.heightPixel + 1); + znordic_rtc_gettime(&now); + batterylevel = BoardBattery_get_battery_level(); + + ssd1306_basic_clear_gram(); + + // ZLOGI("mainPage_show %d %d", colon_state, x, y); + + ssd1306_basic_draw_str(x, y, &xchange, &ychange, fmt("%02d:%02d", now.tm_hour, now.tm_min), &fontclocklib); + x = x + 6 + xchange; + ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batterylevel, MAIN_PAGE_BATTERY_WIDTH, MAIN_PAGE_BATTERY_HEIGHT); + ssd1306_basic_gram_update(); + m_main_page_colon_state = colon_state; + dsp_mgr_change_to_page(kPage_main); +} + +void dsp_mgr_change_to_main() { mainPage_show(true); } +void mainPage_updateState() { mainPage_show(!m_main_page_colon_state); } +void mainPage_schedule() { + static uint32_t last_update_time = 0; + if (znordic_haspassed_ms(last_update_time) < 300) { + return; + } + last_update_time = znordic_getpower_on_ms(); + mainPage_updateState(); +} + +/******************************************************************************* + * ±£³Ö¾²Ö¹Ò³Ãæ * + *******************************************************************************/ +static int m_prepare_page_progress = 0; +void PreparePage_show(int progress) { + m_prepare_page_progress = progress; + ssd1306_basic_clear_gram(); + uint8_t x = 0; + uint8_t y = 0; + uint8_t xchange, ychange; + + x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); + + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "±£³Ö¾²Ö¹", &font24x24_zh_lib); + + if (progress == 0) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "xxxx", &font8x8_xo_lib); + } else if (progress == 1) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oxxx", &font8x8_xo_lib); + } else if (progress == 2) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooxx", &font8x8_xo_lib); + } else if (progress == 3) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooox", &font8x8_xo_lib); + } else if (progress == 4) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oooo", &font8x8_xo_lib); + } + + ssd1306_basic_gram_update(); +} + +void dsp_mgr_change_to_preparePage() { + PreparePage_show(0); + dsp_mgr_change_to_page(kPage_preparePage); +} +void dsp_mgr_preparePage_set_progress(int progress) { PreparePage_show(progress); } +int dsp_mgr_preparePage_get_progress() { return m_prepare_page_progress; } + +void PreparePage_schedule() {} + +/******************************************************************************* + * ²ÉÑùÒ³Ãæ * + *******************************************************************************/ + +#define SMAPLE_PAGE_START_X 1 +#define SMAPLE_PAGE_START_Y 1 + +typedef struct { + wave_drawer_t wave_drawer; + + int wave_drawser_x; + int wave_drawser_y; + int wave_drawser_hight; + int wave_drawser_width; + + int progress_x; + int progress_y; + + int progress_width; + int progress_hight; + + int heartrate_x; + int heartrate_y; +} sample_page_state_t; +sample_page_state_t m_sample_page_state; +#if 0 +void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // + sample_page_state_t* sps = &m_sample_page_state; + + sps->wave_drawser_x = SMAPLE_PAGE_START_X; + sps->wave_drawser_y = SMAPLE_PAGE_START_Y; + sps->wave_drawser_hight = 40; + sps->wave_drawser_width = 120; + + sps->progress_x = SMAPLE_PAGE_START_X + 1; + sps->progress_y = SMAPLE_PAGE_START_Y + sps->wave_drawser_hight + 3 + 4; + sps->progress_width = 80; + sps->progress_hight = 8; + + sps->heartrate_x = sps->progress_x + sps->progress_width + 2; + sps->heartrate_y = sps->progress_y - 4; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + + ssd1306_basic_clear_gram(); + + wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); + wave_drawer_draw_border(&sps->wave_drawer); + uint8_t xchange, ychange; + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + if (heartrate <= 0) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); + } + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_sampling); +} + +void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool update_screen) { // + + sample_page_state_t* sps = &m_sample_page_state; + uint8_t xchange, ychange; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + + if (progress_s / 10 == 0) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "xxx", &font8x8_xo_lib); + } else if (progress_s / 10 == 1) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oxx", &font8x8_xo_lib); + } else if (progress_s / 10 == 2) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oox", &font8x8_xo_lib); + } else if (progress_s / 10 == 3) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "ooo", &font8x8_xo_lib); + } + + wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + if (heartrate <= 0) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); + } + if (update_screen) ssd1306_basic_gram_update(); +} +#endif +void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // + sample_page_state_t* sps = &m_sample_page_state; + + sps->progress_x = SMAPLE_PAGE_START_X + 10; + sps->progress_y = SMAPLE_PAGE_START_Y + 3; + sps->progress_width = 100; + sps->progress_hight = 8; + + sps->wave_drawser_x = SMAPLE_PAGE_START_X + 5; + sps->wave_drawser_y = SMAPLE_PAGE_START_Y + sps->progress_hight + 5; + sps->wave_drawser_hight = 45; + sps->wave_drawser_width = 85; + + sps->heartrate_x = sps->wave_drawser_x + sps->wave_drawser_width + 1; + sps->heartrate_y = sps->wave_drawser_y + 5; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + uint8_t xchange, ychange; + + ssd1306_basic_clear_gram(); + /** + * @brief + * ================= + * | | ÐÄ + * | wave | + * | | ÐÄÂÊ + */ + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); + + wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); + // wave_drawer_draw_border(&sps->wave_drawer); + + ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_sampling); +} + +void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool updateHeart, bool update_screen) { // + + sample_page_state_t* sps = &m_sample_page_state; + uint8_t xchange, ychange; + static bool heart_logo_state = false; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + // if (progress_s / 10 >= 3) { + // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "o", &font8x8_xo_lib); + // } else { + // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); + // } + if (update_screen && updateHeart) { + if (heart_logo_state) { + ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, " ", &font_asicc16x8_lib); + } + heart_logo_state = !heart_logo_state; + } + + if (heartrate <= 0) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); + } else { + if (heartrate >= 100) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); + } + } + wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); + if (update_screen) ssd1306_basic_gram_update(); +} + +void samplePage_schedule() { + static int count = 0; + count++; + int capturetime = hwss_has_captured_time_ms(); + int wave_y = (int)hwss_read_val(); + int heartrate = (int)hwss_read_heart_rate(); + // ZLOGI("samplePage_schedule %d %d %d", capturetime, wave_y, heartrate); + samplePage_update_state(capturetime / 1000, wave_y, hwss_read_heart_rate(), count % 30 == 0, count % 10 == 0); +} + +/******************************************************************************* + * samplingError * + *******************************************************************************/ +void dsp_mgr_change_to_samplingError() { + /** + * @brief + * ²»×ã30Ãë[X] + */ + ssd1306_basic_clear_gram(); + + uint8_t x; + uint8_t y; + + x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 3 + font12x24_asiic_lib.widthPixel * 2); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); + + uint8_t xchange, ychange; + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "²»×ã", &font24x24_zh_lib); + x = x + xchange; + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "30", &font12x24_asiic_lib); + x = x + xchange; + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "Ãë", &font24x24_zh_lib); + x = x + xchange; + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_samplingError); +} + +void dsp_mgr_change_to_sampleSuc() { + /** + * @brief + * 1.½ø¶ÈÌõ + * 2.ÌáʾÐÅÏ¢ + */ + ssd1306_basic_clear(); + uint8_t x = 0; + uint8_t y = 0; + + uint8_t xchange, ychange; + x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); + + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "²É¼¯Íê³É", &font24x24_zh_lib); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_storagingSuc); +} + +/******************************************************************************* + * SCHEDULE * + *******************************************************************************/ + +APP_TIMER_DEF(m_dsp_mgr_schedule_tmr); +static void dsp_mgr_schedule_tmr_cb(void* p_context) { // + if (g_pageState.page == kPage_chargingPage) { + chargingPage_schedule(); + } else if (g_pageState.page == kPage_welcome) { + welcomePage_schedule(); + } else if (g_pageState.page == kPage_main) { + mainPage_schedule(); + } else if (g_pageState.page == kPage_preparePage) { + PreparePage_schedule(); + } else if (g_pageState.page == kPage_sampling) { + samplePage_schedule(); + } +} + +void dsp_mgr_init(void) { + static bool timer_inited = false; + board_screen_init(); + if (!timer_inited) { + ZERROR_CHECK(app_timer_create(&m_dsp_mgr_schedule_tmr, APP_TIMER_MODE_REPEATED, dsp_mgr_schedule_tmr_cb)); + } + // ´Ë´¦ÖÜÆÚ¾ö¶¨²ÉÑùÒ»¸öÒ³ÃæÏÔʾµÄ¿í¶È + ZERROR_CHECK(app_timer_start(m_dsp_mgr_schedule_tmr, APP_TIMER_TICKS(12), NULL)); + timer_inited = true; +} +void dsp_mgr_uninit(void) { + app_timer_stop(m_dsp_mgr_schedule_tmr); + board_screen_deinit(); +} diff --git a/app/src/service/display_mgr/display_manager.h b/app/src/service/display_mgr/display_manager.h new file mode 100644 index 0000000..0553b77 --- /dev/null +++ b/app/src/service/display_mgr/display_manager.h @@ -0,0 +1,81 @@ +#pragma once + +#include "znordic.h" +// +#include "app_timer.h" +#include "diskio_blkdev.h" +#include "ff.h" +#include "nrf_block_dev_sdc.h" +#include "nrf_delay.h" +#include "nrf_drv_pwm.h" +#include "nrf_drv_saadc.h" +#include "nrf_drv_twi.h" +#include "nrf_drv_wdt.h" +#include "nrf_gpio.h" + +/** + * @brief + * Ò³ÃæÁ÷ת + * + * close <--------------------- + * | + * button ---> welcome ---> main ---> preparePage ---> sampling ---> storaging ---> storagingSuc + * ^ ---> samplingError | + * |-------------------------------------------| | + * |-----------------------------------------------------------| + * + */ + +typedef enum { + kPage_poweroff, + kPage_welcome, + kPage_main, + kPage_preparePage, + kPage_sampling, + kPage_samplingError, + kPage_storaging, + kPage_storagingSuc, + kPage_chargingPage, +} page_t; + +typedef struct { + /** + * @brief Ò³Ãæ×´Ì¬ + */ + page_t page; // µ±Ç°Ò³Ãæ + page_t last_page; // ÉÏÒ»¸öÒ³Ãæ + uint32_t page_change_to_page_time; // µ±Ç°Ò³Ãæ³ÖÐøµÄʱ¼ä + + bool in_prompt; // ÊÇ·ñÔÚÌáʾ״̬ + char prompt[32]; // ÌáʾÄÚÈÝ + + /** + * @brief + */ + +} PageState_t; + +void dsp_mgr_init(void); +void dsp_mgr_uninit(void); +void dsp_mgr_schedule(void); + +PageState_t* dsp_mgr_get_state(void); +uint32_t dsp_mgr_get_page_elapsed_time_s(void); + +void dsp_mgr_change_to_poweroff(); +void dsp_mgr_change_to_welcome(); +void dsp_mgr_change_to_main(); +void dsp_mgr_change_to_chargingPage(); + +// ±£³Ö¾²Ö¹Ò³Ãæ +void dsp_mgr_change_to_preparePage(); +void dsp_mgr_preparePage_set_progress(int progress); +int dsp_mgr_preparePage_get_progress(); + +// ²ÉÑùÖÐÒ³Ãæ +void dsp_mgr_change_to_sampling(int progress_s, int heartrate); + +// ²ÉÑù³ö´íÒ³Ãæ +void dsp_mgr_change_to_samplingError(); +// ²ÉÑù³É¹¦Ò³Ãæ +void dsp_mgr_change_to_sampleSuc(); \ No newline at end of file diff --git a/app/src/service/display_mgr/font.h b/app/src/service/display_mgr/font.h new file mode 100644 index 0000000..179ea34 --- /dev/null +++ b/app/src/service/display_mgr/font.h @@ -0,0 +1,275 @@ +// https://www.23bei.com/tool-965.html + +#include +#if 0 +const uint8_t fontclocklib_code[] = { + 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0xFF, 0xF0, 0x07, 0x80, 0x78, 0x06, // + 0x00, 0x18, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x07, 0x80, 0x78, 0x03, 0xFF, 0xF0, 0x01, 0xFF, // + 0xE0, 0x00, 0x7F, 0x80, // + 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x07, 0xFF, 0xF0, 0x0F, // + 0xFF, 0xF0, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x03, 0x80, 0x70, 0x07, 0x80, 0xF0, 0x0D, 0x81, 0xB0, 0x08, 0x03, 0x30, 0x08, 0x06, 0x30, 0x08, // + 0x0C, 0x30, 0x0C, 0x38, 0x30, 0x0F, 0xF8, 0x30, 0x07, 0xF1, 0xF0, 0x03, 0xC1, 0xF0, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x03, 0x81, 0xC0, 0x07, 0x81, 0xE0, 0x0F, 0x81, 0xF0, 0x08, 0x10, 0x10, 0x08, 0x10, 0x10, 0x0C, // + 0x30, 0x10, 0x0F, 0xF8, 0x30, 0x07, 0xEF, 0xF0, 0x03, 0xCF, 0xE0, 0x00, 0x03, 0xC0, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x06, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x3A, 0x00, 0x00, 0xE2, 0x00, 0x01, 0xC2, 0x10, 0x07, // + 0x02, 0x10, 0x0F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x00, 0x02, 0x10, 0x00, 0x02, // + 0x10, 0x00, 0x00, 0x00, // + 0x00, 0x01, 0xC0, 0x0F, 0xF9, 0xE0, 0x0F, 0xF9, 0xB0, 0x0C, 0x30, 0x10, 0x0C, 0x20, 0x10, 0x0C, // + 0x20, 0x10, 0x0C, 0x30, 0x70, 0x0C, 0x3F, 0xF0, 0x0C, 0x1F, 0xE0, 0x0C, 0x0F, 0x80, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x7F, 0x00, 0x03, 0xFF, 0xC0, 0x07, 0xFF, 0xE0, 0x07, 0x18, 0x70, 0x0C, 0x30, 0x30, 0x08, // + 0x20, 0x10, 0x08, 0x20, 0x10, 0x0E, 0x30, 0x30, 0x0E, 0x3F, 0xE0, 0x06, 0x1F, 0xE0, 0x00, 0x0F, // + 0x80, 0x00, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0F, 0x80, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x01, 0xF0, 0x0C, // + 0x0F, 0xF0, 0x0C, 0x3F, 0xF0, 0x0D, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x03, 0xC3, 0xC0, 0x07, 0xEF, 0xE0, 0x0F, 0xEF, 0xE0, 0x0C, 0x78, 0x30, 0x08, 0x30, 0x10, 0x08, // + 0x38, 0x10, 0x08, 0x18, 0x10, 0x0C, 0x3C, 0x30, 0x0F, 0xEF, 0xF0, 0x07, 0xE7, 0xE0, 0x03, 0x83, // + 0xC0, 0x00, 0x00, 0x00, // + 0x01, 0xF0, 0x00, 0x07, 0xF8, 0x60, 0x07, 0xFC, 0x70, 0x0E, 0x0C, 0x70, 0x08, 0x04, 0x10, 0x08, // + 0x04, 0x10, 0x08, 0x0C, 0x30, 0x0E, 0x19, 0xE0, 0x07, 0xFF, 0xE0, 0x03, 0xFF, 0x80, 0x00, 0xFE, // + 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x70, 0x00, // + 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // +}; + +static FontLibrary_t fontclocklib = { + .font = fontclocklib_code, + .fontIndex = "0123456789:", + .fontIndexLen = 12, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 24, + .heightPixel = 24, +}; +#endif + +// DB 00H 00H 07H F0H 0FH F8H 18H 0CH 10H 04H 18H 0CH 0FH F8H 07H F0H;"0",0 +// DB 10H 08H 10H 08H 3FH F8H 3FH F8H 00H 08H 00H 08H 00H 00H 00H 00H;"1",1 +// DB 1CH 18H 3CH 38H 20H 68H 20H C8H 23H 88H 3FH 18H 1CH 18H 00H 00H;"2",2 +// DB 18H 30H 38H 38H 22H 08H 22H 08H 27H 18H 3DH F0H 18H E0H 00H 00H;"3",3 +// DB 01H C0H 07H C0H 0EH 48H 18H 48H 3FH F8H 3FH F8H 00H 48H 00H 00H;"4",4 +// DB 3FH 30H 3FH 38H 23H 08H 22H 08H 23H 18H 21H F0H 20H E0H 00H 00H;"5",5 +// DB 0FH E0H 1FH F0H 33H 18H 22H 08H 33H 18H 31H F0H 00H E0H 00H 00H;"6",6 +// DB 38H 00H 38H 00H 21H F8H 27H F8H 3EH 00H 38H 00H 20H 00H 00H 00H;"7",7 +// DB 1CH 70H 3EH F8H 23H 88H 21H 08H 23H 88H 3EH F8H 1CH 70H 00H 00H;"8",8 +// DB 0EH 00H 1FH 18H 31H 98H 20H 88H 31H 98H 1FH F0H 0FH E0H 00H 00H;"9",9 +// DB 00H 00H 00H 00H 06H 18H 06H 18H 06H 18H 00H 00H 00H 00H 00H 00H;":",10 + +#if 0 +//32*32 +const uint8_t fontclocklib_code[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xFF, 0xFE, 0xF0, + 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, /*"0",0*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x07, 0x07, 0x07, 0x06, 0x04, 0x04, 0x04, 0x00, 0x00, /*"1",1*/ + 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xFF, 0x7F, 0x3E, 0x00, + 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x01, 0x00, /*"2",2*/ + 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0xFF, 0xFE, 0x78, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"3",3*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x3C, 0x0E, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x1C, 0x1E, 0x13, 0x11, 0x10, 0x10, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x0F, 0x0F, 0x0F, 0x0F, 0x08, 0x08, 0x08, /*"4",4*/ + 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0xC7, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xE1, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"5",5*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFE, 0x8F, 0x81, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC3, 0x83, 0x03, 0x00, + 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xC3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, /*"6",6*/ + 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x80, 0xE0, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x3F, 0x7F, 0xF1, 0xE0, 0xC0, 0x80, 0x80, 0x80, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, + 0x00, 0xF8, 0xFC, 0xFE, 0x07, 0x03, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0F, 0xFE, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"8",8*/ + 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xFF, 0xFE, 0xF8, 0x00, + 0x00, 0x00, 0x81, 0x83, 0x87, 0x06, 0x04, 0x04, 0x04, 0x06, 0x83, 0xF3, 0xFF, 0x7F, 0x0F, 0x00, 0x00, 0x00, 0x03, 0x03, 0x07, 0x04, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /*":",10*/ +}; +static FontLibrary_t fontclocklib = { + .font = fontclocklib_code, + .fontIndex = "0123456789:", + .fontIndexLen = 12, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 16, + .heightPixel = 32, +}; +#endif + +// 24*24 +const uint8_t fontclocklib_code[] = { + + 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFE, 0x00, 0x01, 0x07, 0x0F, 0x1E, 0x18, 0x10, 0x18, 0x1E, 0x0F, 0x07, 0x01, /*"0",0*/ + 0x00, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, 0x10, 0x00, /*"1",1*/ + 0x00, 0x80, 0xC0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x03, 0x03, 0x03, 0x80, 0xC0, 0x60, 0x38, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x1C, 0x1E, 0x1B, 0x19, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x1F, 0x00, /*"2",2*/ + 0x00, 0x80, 0xC0, 0xE0, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x10, 0x10, 0x18, 0x3F, 0xEF, 0xE7, 0x80, 0x00, 0x00, 0x07, 0x0F, 0x1F, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, 0x00, /*"3",3*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, /*"4",4*/ + 0x00, 0x00, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x07, 0x0F, 0x1B, 0x10, 0x10, 0x10, 0x1C, 0x1F, 0x0F, 0x03, 0x00, /*"5",5*/ + 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x60, 0x20, 0x20, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x31, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x01, 0x07, 0x0F, 0x1C, 0x18, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, /*"6",6*/ + 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0x60, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0xE0, 0xF8, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x87, 0xEF, 0xEF, 0x3C, 0x18, 0x38, 0x30, 0x78, 0xEF, 0xCF, 0x83, 0x00, 0x07, 0x0F, 0x0F, 0x18, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, /*"8",8*/ + 0x00, 0x00, 0xC0, 0xC0, 0xE0, 0x20, 0x20, 0x20, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x60, 0x40, 0x40, 0x60, 0x30, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x0C, 0x1C, 0x1C, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, /*":",10*/ + +}; +static FontLibrary_t fontclocklib = { + .font = fontclocklib_code, + .fontIndex = "0123456789:", + .fontIndexLen = 12, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 12, + .heightPixel = 24, +}; + +const uint8_t font8x8_xo_code[] = { + 0x00, 0x3C, 0x7E, 0x7E, 0x7E, 0x7E, 0x3C, 0x00, /*ʵÐÄÔ²,´ú±íÍê³É*/ + 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, /*¿ÕÐÄÔ²,´ú±íδÍê³É*/ + +}; + +static FontLibrary_t font8x8_xo_lib = { + .font = font8x8_xo_code, + .fontIndex = "ox", + .fontIndexLen = 2, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 8, + .heightPixel = 8, +}; + +const uint8_t font12x24_asiic_code[] = { + + 0x00, 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x01, 0x07, 0x0E, 0x0C, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"0",0*/ + 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, /*"1",1*/ + 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x80, 0xC0, 0xE0, 0x38, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x0F, 0x0B, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /*"2",2*/ + 0x00, 0x80, 0xC0, 0x60, 0x30, 0x30, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x18, 0x38, 0x7F, 0xE7, 0x80, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x0E, 0x07, 0x01, 0x00, /*"3",3*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x01, /*"4",4*/ + 0x00, 0x00, 0xE0, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x0D, 0x04, 0x04, 0x0C, 0x0C, 0x3C, 0xF8, 0xC0, 0x00, 0x01, 0x07, 0x0E, 0x08, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"5",5*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x0F, 0x0D, 0x0C, 0x0C, 0x18, 0xF8, 0xF0, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x03, 0x00, /*"6",6*/ + 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x20, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xE3, 0xFF, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x3F, 0xE7, 0xC0, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x07, 0x03, 0x00, /*"8",8*/ + 0x00, 0xC0, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x02, 0x1F, 0x3D, 0x30, 0x60, 0x60, 0xE0, 0xF0, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x1C, 0xF0, 0xE0, 0xE0, 0x38, 0x1C, 0x04, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0E, 0x03, 0x01, 0x03, 0x07, 0x0E, 0x18, 0x10, 0x00, /*"x",10*/ + 0x00, 0x30, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x83, 0xEF, 0x7C, 0x7E, 0xE7, 0x81, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x01, 0x0F, 0x1E, 0x18, 0x00, /*"X",11*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, /*"[",12*/ + 0x00, 0x0C, 0x0C, 0x0C, 0x0C, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, + /*"]",13*/}; + +static FontLibrary_t font12x24_asiic_lib = { + .font = font12x24_asiic_code, + .fontIndex = "0123456789xX[]", + .fontIndexLen = 15, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 12, + .heightPixel = 24, +}; + +const uint8_t font24x24_zh_code[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF8, 0x38, 0x10, 0x10, 0xF0, 0x90, 0x10, 0x10, 0x10, 0x88, 0xF8, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x0C, 0x06, 0xE7, 0x1C, 0x10, 0x10, 0x10, 0x10, 0x93, + 0x71, 0xFF, 0x39, 0x49, 0x89, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x03, 0x07, 0x06, 0x06, 0x04, 0x04, 0x00, /*"±£",0*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFC, 0xFC, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC2, 0x63, 0x33, 0xFF, 0x0D, 0x09, 0x08, 0x48, + 0x48, 0x49, 0x48, 0x47, 0x4F, 0xFC, 0x24, 0x24, 0x26, 0x06, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x08, 0x38, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x20, 0x60, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"³Ö",1*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xFC, 0x20, 0xA0, 0x20, 0x00, 0x80, 0x60, 0x3C, 0x2C, 0xA0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0C, 0x94, 0x75, 0x55, 0x57, 0x15, 0xF4, 0x02, 0x90, + 0x92, 0x92, 0x92, 0xFF, 0x92, 0x8A, 0x49, 0x3F, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0F, 0x02, 0x01, 0x09, 0x18, 0x0F, 0x00, 0x00, 0x00, 0x20, 0x60, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¾²",2*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0x00, 0x00, 0x00, + 0xFF, 0x0F, 0x08, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x0C, 0x0F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, /*"Ö¹",3*/ + 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x60, 0x60, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x0D, 0xFF, + 0x03, 0x00, 0x00, 0x10, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, /*"²»",4*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xE0, 0x20, 0x20, 0x10, 0x10, 0x10, 0xF8, 0xF8, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x61, 0x87, 0x82, 0x06, 0xFE, + 0x12, 0x11, 0x11, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x02, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"×ã",5*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0xC4, 0x64, 0x1A, 0xFF, 0x12, 0x32, 0x00, 0x18, + 0x0F, 0x00, 0x00, 0x1F, 0x80, 0xE0, 0x3C, 0x08, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x40, 0x20, 0x30, 0x18, 0x0C, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"Ãë",6*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x20, 0x20, 0x38, 0xF8, 0x20, 0x20, 0x20, 0x60, 0x9C, 0x24, 0x10, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x67, 0x7E, 0x00, + 0x10, 0x8C, 0x9B, 0xB9, 0xE4, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x23, 0x3F, 0x11, 0x13, 0x1D, 0x11, 0x1D, 0x17, 0x10, 0x18, 0x1F, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, /*"À¶",7*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x10, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x18, 0x18, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x04, 0x84, 0x64, 0x34, 0x1E, + 0x06, 0xFF, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x10, 0x20, 0x70, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"ÑÀ",8*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x0E, 0x08, 0x08, 0x08, 0x04, 0x04, 0x07, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x08, 0x08, 0x18, 0x18, 0x18, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x0C, 0x0E, 0x07, 0x00, 0x00, 0x00, /*"ÒÑ",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x10, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0x20, 0x20, 0xA0, 0xF0, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x67, 0x74, 0x2C, 0x26, 0x01, 0x00, 0x10, 0x50, + 0x48, 0x44, 0xC3, 0xC3, 0x62, 0x24, 0x2C, 0x0C, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x02, 0x02, 0x01, 0x10, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x0B, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x08, 0x00, 0x00, /*"¾­",10*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x40, 0x40, 0xC0, 0xE0, 0x5C, 0x2C, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0xF8, 0x08, 0x00, 0x40, 0x48, 0x4E, 0x4B, + 0x44, 0x45, 0xFF, 0x24, 0x24, 0x24, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x04, 0x07, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x17, 0x30, 0x30, 0x30, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, /*"Á¬",11*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0x98, 0xD0, 0xC0, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x82, 0xC2, 0x62, 0xFF, 0x11, 0x91, 0x80, 0x80, 0x90, + 0x92, 0xF4, 0xB0, 0x98, 0x97, 0x89, 0x48, 0x48, 0x48, 0x40, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x3F, 0x0F, 0x00, 0x00, 0x20, 0x20, 0x13, 0x12, 0x0C, 0x06, 0x0F, 0x08, 0x18, 0x30, 0x20, 0x00, 0x00, 0x00, /*"½Ó",12*/ + 0x00, 0x00, 0x00, 0xE0, 0x40, 0x40, 0x80, 0x00, 0xF8, 0x88, 0x40, 0x20, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x40, 0x25, 0x1A, 0xFF, 0x12, 0x12, 0x12, + 0x00, 0xE0, 0x3F, 0x08, 0x04, 0xFC, 0xFC, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x12, 0x08, 0x06, 0x01, 0x00, 0x00, 0x00, 0x7F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¶Ï",13*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x60, 0xE0, 0x20, 0x20, 0x20, 0x20, 0xF0, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xE8, 0x3F, 0x08, 0x08, + 0x04, 0x04, 0xFF, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¿ª",14*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xF8, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x7F, 0x81, 0x89, 0x49, 0xC8, 0xFF, 0x4C, + 0x44, 0x44, 0x40, 0x3C, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x18, 0x10, 0x10, 0x30, 0x30, 0x30, 0x10, 0x10, 0x1A, 0x1C, 0x00, 0x00, 0x00, /*"µç",15*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x78, 0xA8, 0xA8, 0xA8, 0xA8, 0x88, 0xE4, 0x7C, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x14, 0xF4, 0x94, 0x14, 0x52, 0xF2, + 0xAA, 0xAA, 0x8A, 0xFA, 0x3A, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x24, 0x25, 0x25, 0x25, 0x3F, 0x24, 0x24, 0x27, 0x30, 0x30, 0x30, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, /*"Á¿",16*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC6, 0xFC, 0xA0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x24, 0xE6, 0xA3, 0xA1, 0x94, 0xAF, + 0x10, 0x11, 0xF3, 0xF6, 0x2C, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x21, 0x27, 0x24, 0x24, 0x34, 0x12, 0x16, 0x13, 0x10, 0x10, 0x10, 0x10, 0x30, 0x00, 0x00, 0x00, 0x00, /*"²é",17*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x90, 0x90, 0xF0, 0xB8, 0x88, 0x8C, 0xCC, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0xC8, 0x78, 0xFC, 0xA7, 0xA4, + 0xA4, 0xA4, 0x14, 0x14, 0xF2, 0x22, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x14, 0x14, 0x14, 0x12, 0x10, 0x30, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"¿´",18*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x38, 0x10, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xC6, 0x65, 0x3C, 0x2C, 0x23, 0x01, 0x80, 0x02, + 0x22, 0x22, 0x22, 0x22, 0x3F, 0x91, 0x91, 0x91, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x04, 0x06, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x03, 0x1F, 0x09, 0x09, 0x09, 0x08, 0x08, 0x0F, 0x01, 0x00, 0x00, 0x00, /*"½á",19*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0xF0, 0x10, 0x90, 0x90, 0xF0, 0xF0, 0xD0, 0x10, 0x88, 0xF8, 0x78, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x21, 0x27, 0xA4, 0x64, 0xFF, + 0x52, 0x92, 0x12, 0x13, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x00, 0x7F, 0x00, 0x00, 0x01, 0x02, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"¹û",20*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0xD0, 0x90, 0x18, 0x0C, 0x88, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x60, 0x20, 0x20, 0x20, 0x22, 0x22, 0x33, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x10, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x60, 0x78, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"ÊÖ",21*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x86, 0xC2, 0x32, 0x0F, 0xFF, 0x21, 0x61, 0x01, 0x01, + 0xFF, 0x01, 0x01, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x0F, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x0C, 0x0C, 0x0C, 0x0F, 0x06, 0x00, /*"»ú",22*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x20, 0x20, 0x50, 0xD0, 0x88, 0x0C, 0x8C, 0x40, 0x70, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x11, 0xD0, 0x70, 0x32, 0xFC, 0x30, + 0x48, 0x88, 0x88, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x30, 0x7F, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x06, 0x0C, 0x0C, 0x04, 0x08, 0x00, 0x00, /*"²É",23*/ + 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0xF0, 0x0C, 0x24, 0xA0, 0xA4, 0xEC, 0xE8, 0x90, 0x50, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xBF, 0x90, 0x90, 0xD2, 0xF2, + 0xCF, 0x4B, 0x4A, 0x49, 0x48, 0x48, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x7F, 0x00, 0x01, 0x02, 0x04, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x10, 0x00, 0x00, /*"¼¯",24*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x7C, 0xC0, 0x80, 0x80, 0x88, 0x98, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFE, 0x42, 0x42, 0x22, 0x22, 0xE1, 0x21, + 0x03, 0x1F, 0x70, 0x80, 0xE0, 0x3C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x03, 0x00, 0x04, 0x08, 0x1C, 0x07, 0x00, 0x08, 0x04, 0x02, 0x01, 0x07, 0x0C, 0x18, 0x30, 0x70, 0x78, 0x00, 0x00, /*"³É",25*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x81, 0x81, 0xC1, 0x7F, 0x20, 0x20, 0x20, 0x12, + 0x82, 0xE2, 0x3E, 0x07, 0x02, 0x01, 0x01, 0xFF, 0x0F, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x04, 0x08, 0x38, 0x1C, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, /*"¹¦",26*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x40, 0x48, 0x58, 0x50, 0x40, 0x20, 0x20, 0xA0, 0xE0, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x40, 0x60, 0x24, 0xE4, 0x26, 0x22, + 0xF2, 0x12, 0x10, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x00, 0x00, 0x00, 0x1F, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x3E, 0x10, 0x00, 0x00, /*"Íê",27*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x78, 0x10, 0x00, 0x80, 0x80, 0x40, 0x40, 0xA0, 0x38, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0x0C, 0x03, 0xFD, 0x00, 0x00, 0x00, 0xE1, 0xFF, + 0x10, 0x88, 0x0F, 0x3C, 0xE4, 0x84, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x00, 0x00, 0x04, 0x0F, 0x03, 0x01, 0x00, 0x04, 0x0C, 0x00, 0x01, 0x06, 0x0C, 0x18, 0x3E, 0x30, 0x00, /*"µÍ",28*/ +}; +static FontLibrary_t font24x24_zh_lib = { + .font = font24x24_zh_code, + .fontIndex = "±£³Ö¾²Ö¹²»×ãÃëÀ¶ÑÀÒѾ­Á¬½Ó¶Ï¿ªµçÁ¿²é¿´½á¹ûÊÖ»ú²É¼¯³É¹¦ÍêµÍ", + .fontIndexLen = 88, + .fontCode = kgbk, + .isAscii = false, + .widthPixel = 24, + .heightPixel = 24, +}; + +#if 0 +// const unsigned char gImage_heart_16x16[] = { +// /* 0X22,0X01,0X10,0X00,0X10,0X00, */ +// 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XF8, 0X00, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, 0X7F, 0X3F, 0X1F, 0X0F, 0X07, 0X03, 0X00, 0X00, +// }; +#endif + +const unsigned char font_asicc_code_16x8[] = { + 0x00, 0xF0, 0x18, 0x08, 0x08, 0x18, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x30, 0x18, 0x0F, 0x00, /*"0",0*/ + 0x00, 0x60, 0x20, 0xF0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x00, /*"1",1*/ + 0x00, 0x30, 0x18, 0x08, 0x08, 0xD8, 0x70, 0x00, 0x00, 0x30, 0x38, 0x34, 0x33, 0x31, 0x30, 0x00, /*"2",2*/ + 0x00, 0x30, 0x18, 0x08, 0x88, 0xD8, 0x70, 0x00, 0x00, 0x18, 0x10, 0x20, 0x21, 0x13, 0x0E, 0x00, /*"3",3*/ + 0x00, 0x00, 0x80, 0x60, 0x30, 0xF8, 0x00, 0x00, 0x04, 0x07, 0x05, 0x04, 0x04, 0x3F, 0x04, 0x04, /*"4",4*/ + 0x00, 0xF0, 0x98, 0xC8, 0x88, 0x88, 0x08, 0x00, 0x08, 0x19, 0x30, 0x20, 0x30, 0x19, 0x0F, 0x00, /*"5",5*/ + 0x00, 0x80, 0xC0, 0xF0, 0x98, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x31, 0x20, 0x20, 0x30, 0x1F, 0x06, /*"6",6*/ + 0x00, 0x08, 0x08, 0x08, 0x88, 0xE8, 0x38, 0x00, 0x00, 0x00, 0x30, 0x3E, 0x03, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0xF0, 0x88, 0x88, 0x88, 0xD8, 0x70, 0x00, 0x04, 0x1F, 0x31, 0x21, 0x21, 0x31, 0x1E, 0x00, /*"8",8*/ + 0xE0, 0xF0, 0x08, 0x08, 0x08, 0x98, 0xF0, 0x00, 0x00, 0x01, 0x23, 0x3A, 0x0F, 0x03, 0x00, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, /*"-",10*/ + 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x11, 0x00, 0x00, 0x00, /*":",10*/ + + 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, /*?ÓÒ°ë*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" "*/ +}; + +static FontLibrary_t font_asicc16x8_lib = { + .font = font_asicc_code_16x8, + .fontIndex = "0123456789-:<> ", // <> ÕâÁ½¸ö·ûºÅÊÇÐÄÐεÄ×óÓÒ°ë±ß + .fontIndexLen = 16, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 8, + .heightPixel = 16, +}; diff --git a/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c b/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c new file mode 100644 index 0000000..0f6334c --- /dev/null +++ b/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c @@ -0,0 +1,106 @@ +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "board/board_ecg_sensor.h" +#include "nrfx_timer.h" + +static uint32_t m_frame_index = 0; // Ö¡¾ø¶ÔÐòºÅ +/*********************************************************************************************************************** + * ab buffer * + ***********************************************************************************************************************/ +#define FRAME_BUFFER_SIZE (256 / sizeof(one_frame_t)) + +static one_frame_t m_capture_buffer_a[FRAME_BUFFER_SIZE]; +static one_frame_t m_capture_buffer_b[FRAME_BUFFER_SIZE]; +static one_frame_t* m_capture_buffer; +static one_frame_t m_capture_buffer_index = 0; + +static void eeprom_cache_buffer_swap() { + if (m_capture_buffer == NULL) { + m_capture_buffer = m_capture_buffer_a; + m_capture_buffer_index = 0; + return; + } + + if (m_capture_buffer == m_capture_buffer_a) { + m_capture_buffer = m_capture_buffer_b; + } else { + m_capture_buffer = m_capture_buffer_a; + } + m_capture_buffer_index = 0; + return; +} + +/*********************************************************************************************************************** + * littlebuffer * + ***********************************************************************************************************************/ +static one_frame_t m_prepare_data_cache[LITTLE_DATA_BLOCK_FRAME_NUM]; +static uint32_t m_prepare_data_cache_index; + +static inline void preview_data_cache_push_data(one_frame_t data) { + if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { + return; + } + m_prepare_data_cache[m_prepare_data_cache_index] = data; + m_prepare_data_cache_index++; +} + +static inline bool preview_data_cache_is_full(void) { + if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { + return true; + } + return false; +} +static inline void preview_data_cache_clear(void) { m_prepare_data_cache_index = 0; } +static inline void preview_data_trigger_event() { + static app_event_t event; + event.eventType = kevent_capture_little_data_block_event; + for (uint32_t i = 0; i < LITTLE_DATA_BLOCK_FRAME_NUM; i++) { + event.val.little_data_block.data[i] = m_prepare_data_cache[i]; + } + event.val.little_data_block.frameIndex = m_frame_index - LITTLE_DATA_BLOCK_FRAME_NUM; + AppEvent_pushEvent(&event); +} + +/*********************************************************************************************************************** + * EXT * + ***********************************************************************************************************************/ + +void hwsd_mgr_push_one_frame(one_frame_t data) { + m_frame_index++; + + /*********************************************************************************************************************** + * EEPROMÊý¾Ý²ÉÑù´æ´¢ * + ***********************************************************************************************************************/ + if (m_capture_buffer == NULL) eeprom_cache_buffer_swap(); + + if (m_capture_buffer_index < FRAME_BUFFER_SIZE) { + m_capture_buffer[m_capture_buffer_index++] = data; + } + + if (m_capture_buffer_index == FRAME_BUFFER_SIZE) { + app_event_t evt; + evt.eventType = kevent_capture_256data_event; + evt.val.capture_data_cache = (uint8_t*)m_capture_buffer; + eeprom_cache_buffer_swap(); + AppEvent_pushEvent(&evt); + } + + /******************************************************************************* + * ʵʱ²ÉÑùÊý¾ÝʼþÉϱ¨ * + *******************************************************************************/ + /** + * @brief »º´æÊý¾Ý£¬²¢´¥·¢Ð¡Êý¾Ý¿éʼþ + */ + preview_data_cache_push_data(data); + if (preview_data_cache_is_full()) { + preview_data_trigger_event(); + preview_data_cache_clear(); + } +} + +void hwsd_mgr_reset_buffer(){ + m_frame_index = 0; + m_capture_buffer = NULL; + m_capture_buffer_index = 0; + preview_data_cache_clear(); +} diff --git a/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h b/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h new file mode 100644 index 0000000..71c04f3 --- /dev/null +++ b/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h @@ -0,0 +1,9 @@ +#pragma once +#include + +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "nrfx_timer.h" + +void hwsd_mgr_push_one_frame(one_frame_t data); +void hwsd_mgr_reset_buffer(); \ No newline at end of file diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c b/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c new file mode 100644 index 0000000..53b0497 --- /dev/null +++ b/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c @@ -0,0 +1,12 @@ +#include "heart_wave_sample_data_pre_process.h" +static one_frame_t m_datacache; +static one_frame_t m_displaydata; + +void hwsd_pre_processer_init() {} +void hwsd_pre_processer_process(one_frame_t framdata) { // + m_datacache = framdata; + m_displaydata = framdata; +} + +uint16_t hwsd_pre_processer_get_display_data() { return m_displaydata; } +one_frame_t hwsd_pre_processer_get_storage_data() { return m_datacache; } diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h b/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h new file mode 100644 index 0000000..a188a77 --- /dev/null +++ b/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h @@ -0,0 +1,9 @@ +#pragma once +#include + +#include "basic_service/app_event.h" + +void hwsd_pre_processer_init(); +void hwsd_pre_processer_process(one_frame_t framdata); +one_frame_t hwsd_pre_processer_get_display_data(); +one_frame_t hwsd_pre_processer_get_storage_data(); diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c new file mode 100644 index 0000000..e2e9dc3 --- /dev/null +++ b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c @@ -0,0 +1,83 @@ +#include "heart_wave_sample_service.h" + +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "board/board_ecg_sensor.h" +#include "heart_ware_sample_data_mgr.h" +#include "heart_wave_sample_data_pre_process.h" +#include "nrfx_timer.h" + +typedef enum { + kidle, + kprepare, + kcapture, +} capture_state_t; + +static capture_state_t m_prepare_capture_state = kidle; +static uint32_t m_start_capture_tp; + +static nrfx_timer_t m_timer = NRFX_TIMER_INSTANCE(HEART_WAVE_SAMPLE_TMR_INSTANCE); + +void nrfx_timer_event_handler(nrf_timer_event_t event_type, void* p_context) { // + static uint16_t val = 25; + val++; + if (val > 75) val = 25; + + if (m_prepare_capture_state == kprepare) { + hwsd_pre_processer_process(val); + } else if (m_prepare_capture_state == kcapture) { + hwsd_pre_processer_process(val); + hwsd_mgr_push_one_frame(hwsd_pre_processer_get_storage_data()); + } +} + +void hwss_init(void) { + static bool m_timer_inited = false; + if (!m_timer_inited) { + /** + * @brief ³õʼ»¯¶¨Ê±Æ÷ + */ + static nrfx_timer_config_t timer_cfg = { + .frequency = NRF_TIMER_FREQ_500kHz, + .mode = NRF_TIMER_MODE_TIMER, + .bit_width = NRF_TIMER_BIT_WIDTH_24, + .p_context = NULL, + .interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, + }; + + // nrfx_timer_init(&m_timer, &timer_cfg, nrfx_timer_event_handler); + ZERROR_CHECK(nrfx_timer_init(&m_timer, &timer_cfg, nrfx_timer_event_handler)); + uint32_t timer_ticks = nrfx_timer_ms_to_ticks(&m_timer, 2); // + ZASSERT(SAMPLE_RATE == 500); + nrfx_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, timer_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); + m_timer_inited = true; + } +} +void hwss_uninit(void) { nrfx_timer_disable(&m_timer); } +void hwss_start_prepare_capture(void) { + m_start_capture_tp = znordic_getpower_on_s(); + m_prepare_capture_state = kprepare; + hwsd_pre_processer_init(); + hwsd_mgr_reset_buffer(); + nrfx_timer_enable(&m_timer); +} +void hwss_start_capture(void) { + m_start_capture_tp = znordic_getpower_on_s(); + m_prepare_capture_state = kcapture; +} +void hwss_stop_capture(void) { + m_prepare_capture_state = kidle; + nrfx_timer_disable(&m_timer); + hwsd_mgr_reset_buffer(); +} + +float hwss_read_val(void) { + __disable_irq(); + float val = hwsd_pre_processer_get_display_data(); + __enable_irq(); + return val; +} +float hwss_read_heart_rate(void) { // + return 0; +} +int hwss_has_captured_time_ms() { return (znordic_getpower_on_s() - m_start_capture_tp) * 1000; } diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.h b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.h new file mode 100644 index 0000000..d1df979 --- /dev/null +++ b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.h @@ -0,0 +1,17 @@ +#pragma once +#include + + +// ÿ256¸ö×Ö½Ú´¥·¢Ò»´Î»Øµ÷ +typedef void (*heart_wave_sample_service_callback_t)(uint16_t *p_data, uint16_t length); + +void hwss_init(void); +void hwss_uninit(void); + +void hwss_start_capture(void); +void hwss_stop_capture(void); + +float hwss_read_val(void); +float hwss_read_heart_rate(void); +int hwss_has_captured_time_ms(); +void hwss_start_prepare_capture(void); \ No newline at end of file diff --git a/app/src/service/storage/sample_data_manager.c b/app/src/service/storage/sample_data_manager.c new file mode 100644 index 0000000..6e90080 --- /dev/null +++ b/app/src/service/storage/sample_data_manager.c @@ -0,0 +1,92 @@ +#include "sample_data_manager.h" + +#include + +#include "zeeprom_fs.h" +#include "znordic.h" +#include "aproject_config/config.h" + +static sample_data_fileinfo_t fileinfocache[MAX_FILE_NUM * 2]; +static uint8_t fileinfocache_count = 0; + +void sample_data_mgr_init() { zeeprom_fs_init(); } +void sample_data_mgr_uninit() { zeeprom_fs_uinit(); } + +sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list() { // + static sample_data_fileinfo_list_t fileinfo_list; + memset(&fileinfo_list, 0, sizeof(fileinfo_list)); + fileinfocache_count = 0; + + // ¶ÁÈ¡ËùÓмǼÐÅÏ¢ + zeeprom_header_t* header = zeeprom_fs_get_header(); + + for (uint16_t i = 0; i < ZARRAY_SIZE(header->sectorinfos); i++) { + zeeprom_sector_info_t* sectorinfo = &header->sectorinfos[i]; + if (sectorinfo->usage == 1 && sectorinfo->sector_index_in_file == 0) { + // ¶ÁÈ¡ÎļþÐÅÏ¢ + if (fileinfocache_count >= ZARRAY_SIZE(fileinfocache)) { + ZLOGE("fileinfocache_count >= MAX_FILE_NUM"); + break; + } + + sample_data_fileinfo_t* fileinfo = &fileinfocache[fileinfocache_count]; + fileinfo->fileuuid = sectorinfo->fileuuid; + memcpy(fileinfo->filename, sectorinfo->filename, sizeof(fileinfo->filename)); + fileinfo->size = zeeprom_fs_get_filesize_by_fileuuid(fileinfo->fileuuid); + fileinfo->checksum = zeeprom_fs_get_checksum_by_fileuuid(fileinfo->fileuuid); + + fileinfo_list.fileinfo[fileinfo_list.count] = fileinfo; + fileinfo_list.count++; + fileinfocache_count++; + } + } + // ¸ù¾ÝÎļþuuidÅÅÐò£¬uuid×î´óµÄÅÅÔÚ×îÇ°Ãæ + for (uint16_t i = 0; i < fileinfo_list.count; i++) { + for (uint16_t j = i + 1; j < fileinfo_list.count; j++) { + if (fileinfo_list.fileinfo[i]->fileuuid < fileinfo_list.fileinfo[j]->fileuuid) { + sample_data_fileinfo_t* tmp = fileinfo_list.fileinfo[i]; + fileinfo_list.fileinfo[i] = fileinfo_list.fileinfo[j]; + fileinfo_list.fileinfo[j] = tmp; + } + } + } + return &fileinfo_list; +} + +bool sample_data_mgr_storage_is_full() { return zeeprom_fs_get_file_num() >= MAX_FILE_NUM; } +int32_t sample_data_mgr_get_file_num() { return zeeprom_fs_get_file_num(); } + +#if 1 +static const char* filename2str(uint8_t* filename) { + static char filename_str[32]; + sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); + return filename_str; +} +#endif + +void sample_data_mgr_dump_fileinfo_list() { + zeeprom_fs_dump_sector_state(); + sample_data_fileinfo_list_t* fileinfo_list = sample_data_mgr_get_fileinfo_list(); + ZLOGI_BLOCK("fileinfo_list->count=%d\n", fileinfo_list->count); + for (uint16_t i = 0; i < fileinfo_list->count; i++) { + sample_data_fileinfo_t* fileinfo = fileinfo_list->fileinfo[i]; + ZLOGI_BLOCK("[%d]: filename=%s, fileuuid=%d, size=%d", i, filename2str(fileinfo->filename), fileinfo->fileuuid, fileinfo->size); + } +} + +int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag) { + /** + * @brief ²é¿´ÎļþÊýÁ¿ + */ + if (flag == kwrflag_write_only) { + if (zeeprom_fs_get_file_num() >= MAX_FILE_NUM) { + zeeprom_fs_delete_the_oldest_file(); + } + } + return zeeprom_fs_open((uint8_t*)filename, flag); +} +int32_t sample_data_mgr_close(int32_t fd) { return zeeprom_fs_close(fd); } +int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size) { return zeeprom_fs_write(fd, data, size); } +int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size) { return zeeprom_fs_read(fd, data, size); } +int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd) { return zeeprom_fs_get_filesize_by_fd(fd); } +int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename) { return zeeprom_fs_delete_by_name((uint8_t*)filename); } diff --git a/app/src/service/storage/sample_data_manager.h b/app/src/service/storage/sample_data_manager.h new file mode 100644 index 0000000..3a70e22 --- /dev/null +++ b/app/src/service/storage/sample_data_manager.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" +#include "zeeprom_fs.h" + +void sample_data_mgr_init(); + +typedef struct { + uint8_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t min; + uint8_t sec; + uint8_t placeholder[2]; +} sample_data_filename_t; + +typedef struct { + uint8_t filename[8]; + int32_t fileuuid; + int32_t size; + uint32_t checksum; +} sample_data_fileinfo_t; + +typedef struct { + sample_data_fileinfo_t* fileinfo[MAX_FILE_NUM]; + int count; +} sample_data_fileinfo_list_t; + +void sample_data_mgr_init(); +void sample_data_mgr_uninit(); + +sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list(); +bool sample_data_mgr_storage_is_full(); +int32_t sample_data_mgr_get_file_num(); + +int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag); +int32_t sample_data_mgr_close(int32_t fd); + +int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size); +int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size); +int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd); + +int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename); diff --git a/app/src/service/storage/storage_service.h b/app/src/service/storage/storage_service.h new file mode 100644 index 0000000..895d343 --- /dev/null +++ b/app/src/service/storage/storage_service.h @@ -0,0 +1,3 @@ +#pragma once +#include "sample_data_manager.h" +#include "zeeprom_fs.h" diff --git a/app/src/service/storage/zeeprom_fs.c b/app/src/service/storage/zeeprom_fs.c new file mode 100644 index 0000000..1c6594a --- /dev/null +++ b/app/src/service/storage/zeeprom_fs.c @@ -0,0 +1,572 @@ +#include "zeeprom_fs.h" + +#include "board/board_eeprom_driver.h" + +static zeeprom_header_t m_eeprom_header; +static bool m_is_init = false; + +static filehandler_t m_filehandler[2]; +static int m_fd_off; + +/******************************************************************************* + * º¯ÊýÉùÃ÷ * + *******************************************************************************/ + +static filehandler_t* filehandler_find(int fd); +static filehandler_t* filehandler_alloc(); +static void filehandler_rlease(int fd); + +static int32_t sector_mgr_find_earliest_file_created_index(); +static int32_t sector_mgr_free_sector(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_find_idle_sector(); +static bool sector_mgr_sector_is_open(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector(); +static void sector_mgr_open_sector(int32_t fileuuid); +static void sector_mgr_close_sector(int32_t fileuuid); +// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file); +static int32_t sector_mgr_file_get_size(int32_t fileuuid); + +static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid); +static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector); +static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector); +static int32_t sector_mgr_file_get_checksum(int32_t fileuuid); + +static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len); +static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len); +static uint32_t compute_checksum(const uint8_t* data, uint16_t len); + +/******************************************************************************* + * CODE * + *******************************************************************************/ + +static bool m_eeprom_header_inited = false; +int zeeprom_fs_init() { // + board_eeprom_init(); + if (!m_eeprom_header_inited) { + zeeprom_read(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); + uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); + if (checksum_val != m_eeprom_header.sector_info_headers_checksum) { + memset(&m_eeprom_header, 0, sizeof(m_eeprom_header)); + } + } + m_is_init = true; + m_eeprom_header_inited = true; + return 0; +} +int zeeprom_fs_uinit() { // + // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); + board_eeprom_uninit(); + m_is_init = false; + return 0; +} + +zeeprom_header_t* zeeprom_fs_get_header() { return &m_eeprom_header; } + +int zeeprom_fs_open(uint8_t* filename, wrflag_t wrflag) { + ZASSERT(m_is_init); + /** + * @brief + * 1. Èç¹ûÎļþÒѾ­´æÔÚ£¬Ôò´ò¿ªÎļþ + * 2. Èç¹ûÎļþ²»´æÔÚ£¬ Ôò´´½¨Îļþ + * + * ´´½¨Îļþ: + * 1. ÕÒµ½Ò»¸ö¿ÕÏÐÉÈÇø + * 2. ³õʼ»¯ÎļþÍ· + */ + + filehandler_t* fileHander = filehandler_alloc(); + if (!fileHander) { + ZLOGI("fileHander_alloc fail"); + return -1; + } + + if (wrflag == kwrflag_write_only) { + /******************************************************************************* + * дÎļþ * + *******************************************************************************/ + zeeprom_sector_info_t* sectorHeaderInfo = NULL; + zeeprom_fs_delete_by_name(filename); + + sectorHeaderInfo = sector_mgr_force_find_idle_sector(); + if (!sectorHeaderInfo) { + ZLOGE("sector_mgr_force_find_idle_sector fail"); + filehandler_rlease(fileHander->fd); + return -1; + } + + memset(sectorHeaderInfo, 0, sizeof(zeeprom_sector_info_t)); + sectorHeaderInfo->usage = 1; + sectorHeaderInfo->opened = 1; + memcpy(sectorHeaderInfo->filename, filename, 8); + sectorHeaderInfo->sector_index_in_file = 0; + sectorHeaderInfo->datalen = 0; + sectorHeaderInfo->sector_data_checksum = 0; + sectorHeaderInfo->fileuuid = m_eeprom_header.fileuuid_cnt++; + fileHander->fileuuid = sectorHeaderInfo->fileuuid; + fileHander->sector_header = sectorHeaderInfo; + fileHander->file_offset = 0; + fileHander->file_size = 0; + fileHander->checksum = 0; + return fileHander->fd; + + } else { + /******************************************************************************* + * ¶ÁÎļþ * + *******************************************************************************/ + zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); + if (sectorHeaderInfo) { + fileHander->fileuuid = sectorHeaderInfo->fileuuid; + fileHander->file_offset = 0; + fileHander->fd = fileHander->fd; + fileHander->sector_header = sectorHeaderInfo; + fileHander->file_size = sector_mgr_file_get_size(fileHander->fileuuid); + fileHander->checksum = sector_mgr_file_get_checksum(fileHander->fileuuid); + ZLOGI("filesize:%d", fileHander->file_size); + memcpy(fileHander->filename, filename, 8); + memcpy(fileHander->usrdata, sectorHeaderInfo->usrdata, sizeof(sectorHeaderInfo->usrdata)); + sector_mgr_open_sector(fileHander->fileuuid); + return fileHander->fd; + } else { + filehandler_rlease(fileHander->fd); + return -1; + } + } +} + +int zeeprom_fs_write(int fileid, const uint8_t* data, int32_t size) { + ZASSERT(m_is_init); + + filehandler_t* fileHander = NULL; + zeeprom_sector_info_t* header_sinfo = NULL; + zeeprom_sector_info_t* endsector = NULL; + int32_t wadd = 0; + + ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); + + fileHander = filehandler_find(fileid); + if (!fileHander) { + ZLOGE("fileHander_find fail"); + return -1; + } + + header_sinfo = fileHander->sector_header; + if (!header_sinfo) { + ZLOGE("header_sinfo fail"); + return -1; + } + + endsector = sector_mgr_find_end_sector(fileHander->fileuuid); + if (!endsector) { + ZLOGE("sector_mgr_find_end_sector fail"); + return -1; + } + + if (endsector->datalen + size > EEPROM_SECTOR_SIZE) { + ZLOGE("endsector->datalen + size > EEPROM_SECTOR_SIZE"); + return -1; + } + + wadd = sector_mgr_get_sector_rom_add(endsector); + if (wadd < 0) { + ZLOGE("sector_mgr_get_sector_rom_add fail"); + return -1; + } + ZASSERT(wadd % EEPROM_SECTOR_MIN_WR_SIZE == 0); + ZASSERT(wadd >= EEPROM_SECTOR_SIZE); + zeeprom_write(wadd + endsector->datalen, data, size); + + endsector->datalen = endsector->datalen + size; + endsector->sector_data_checksum += compute_checksum(data, size); + fileHander->file_offset += size; + fileHander->file_size += size; + fileHander->checksum += compute_checksum(data, size); + + if (endsector->datalen == EEPROM_SECTOR_SIZE) { + zeeprom_sector_info_t* newsector = sector_mgr_force_find_idle_sector(); + if (!newsector) { + ZLOGE("sector_mgr_force_find_idle_sector fail"); + return -1; + } + + memset(newsector, 0, sizeof(zeeprom_sector_info_t)); + newsector->usage = 1; + newsector->opened = 1; + newsector->sector_data_checksum = 0; + memcpy(newsector->filename, header_sinfo->filename, 8); + newsector->sector_index_in_file = endsector->sector_index_in_file + 1; + newsector->datalen = 0; + newsector->fileuuid = header_sinfo->fileuuid; + } + return size; +} + +int zeeprom_fs_close(int fileid) { + ZASSERT(m_is_init); + + filehandler_t* fileHander = filehandler_find(fileid); + if (!fileHander) { + ZLOGE("zeeprom_fs_close fileHander_find fail"); + return -1; + } + + sector_mgr_close_sector(fileHander->fileuuid); + uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); + m_eeprom_header.sector_info_headers_checksum = checksum_val; + // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); + + filehandler_rlease(fileid); + return 0; +} + +int zeeprom_fs_get_filesize_by_fd(int fd) { + ZASSERT(m_is_init); + filehandler_t* fileHander = filehandler_find(fd); + if (!fileHander) return 0; + return fileHander->file_size; +} + +int zeeprom_fs_read(int fileid, uint8_t* data, int32_t size) { + ZASSERT(m_is_init); + + /** + * @brief + * ÕÒµ½µ±Ç°ÉÈÇø + */ + ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); + filehandler_t* fileHander = filehandler_find(fileid); + if (!fileHander) return -1; + + if (fileHander->file_offset + size > fileHander->file_size) { + return -1; + } + + zeeprom_sector_info_t* header_sinfo = fileHander->sector_header; + if (!header_sinfo) { + return -1; + } + + int32_t sector_idx = fileHander->file_offset / EEPROM_SECTOR_SIZE; + int32_t sector_off = fileHander->file_offset % EEPROM_SECTOR_SIZE; + + zeeprom_sector_info_t* sector = sector_mgr_find_sector(fileHander->fileuuid, sector_idx); + if (!sector) { + return -1; + } + + int32_t radd = sector_mgr_get_sector_rom_add(sector); + ZASSERT(radd % EEPROM_SECTOR_MIN_WR_SIZE == 0); + radd += sector_off; + + zeeprom_read(radd, data, size); + fileHander->file_offset += size; + return size; +} + +int zeeprom_fs_delete(int32_t fileuuid) { + ZASSERT(m_is_init); + + sector_mgr_free_sector(fileuuid); + return 0; +} +int zeeprom_fs_delete_by_name(uint8_t* filename) { + ZASSERT(m_is_init); + + zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); + if (sectorHeaderInfo) { + sector_mgr_free_sector(sectorHeaderInfo->fileuuid); + } + return 0; +} + +int zeeprom_fs_get_file_num() { + ZASSERT(m_is_init); + + int count = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0) { + count++; + } + } + return count; +} +int zeeprom_fs_delete_the_oldest_file() { + ZASSERT(m_is_init); + + int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); + sector_mgr_free_sector(earliest_file_created_index); + return 0; +} + +int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid) { + ZASSERT(m_is_init); + return sector_mgr_file_get_size(fileuuid); +} + +int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid) { + ZASSERT(m_is_init); + return sector_mgr_file_get_checksum(fileuuid); +} + +static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len) { // + int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; + + int readTimes = len / wrsize; + int readRemain = len % wrsize; + + for (int i = 0; i < readTimes; i++) { + board_eeprom_read(add + i * wrsize, data + i * wrsize, wrsize); + } + if (readRemain > 0) { + board_eeprom_read(add + readTimes * wrsize, data + readTimes * wrsize, readRemain); + } +} +static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len) { + int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; + + int writeTimes = len / wrsize; + int writeRemain = len % wrsize; + + for (int i = 0; i < writeTimes; i++) { + // int pageoff = add / wrsize + i; + int32_t writeadd = add + i * wrsize; + board_eeprom_write(writeadd, data + i * wrsize, wrsize); + } + if (writeRemain > 0) { + int32_t writeadd = add + writeTimes * wrsize; + board_eeprom_write(writeadd, data + writeTimes * wrsize, writeRemain); + } +} + +static uint32_t compute_checksum(const uint8_t* data, uint16_t len) { + uint32_t sum = 0; + for (int i = 0; i < len; i++) { + sum += data[i]; + } + return sum; +} +/******************************************************************************* + * filehandler * + *******************************************************************************/ +static filehandler_t* filehandler_find(int fd) { + for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { + if (m_filehandler[i].fd == fd) { + return &m_filehandler[i]; + } + } + return NULL; +} +static filehandler_t* filehandler_alloc() { + for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { + if (m_filehandler[i].fd == 0) { + m_filehandler[i].fd = ++m_fd_off; + return &m_filehandler[i]; + } + } + return NULL; +} +static void filehandler_rlease(int fd) { + for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { + if (m_filehandler[i].fd == fd) { + m_filehandler[i].fd = 0; + return; + } + } +} +/******************************************************************************* + * sector_mgr * + *******************************************************************************/ + +// ²éÕÒ×îÔç´´½¨µÄÎļþµÄfile_created_index +static int32_t sector_mgr_find_earliest_file_created_index() { + int32_t earliest_file_created_index = INT32_MAX; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1) { + if (sinfo->fileuuid < earliest_file_created_index) { + earliest_file_created_index = sinfo->fileuuid; + } + } + } + return earliest_file_created_index; +} +// ɾ³ýÎļþ +static int32_t sector_mgr_free_sector(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + sinfo->usage = 0; + } + } + return 0; +} +// +static zeeprom_sector_info_t* sector_mgr_find_idle_sector() { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 0) { + return sinfo; + } + } + return NULL; +} +static bool sector_mgr_sector_is_open(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + return sinfo->opened; + } + } + return false; +} + +static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector() { + /** + * @brief ²éÕÒ¿ÕÏÐÉÈÇø + */ + zeeprom_sector_info_t* ret_sinfo = sector_mgr_find_idle_sector(); + if (ret_sinfo) return ret_sinfo; + /** + * @brief ²éÕÒ×îÔç´´½¨µÄÎļþ + */ + int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); + if (sector_mgr_sector_is_open(earliest_file_created_index)) { + return NULL; + } + + /** + * @brief ɾ³ý×îÔç´´½¨µÄÎļþ + */ + sector_mgr_free_sector(earliest_file_created_index); + + /** + * @brief ÖØÐ²éÕÒ¿ÕÏÐÉÈÇø + */ + ret_sinfo = sector_mgr_find_idle_sector(); + if (ret_sinfo) return ret_sinfo; + + return NULL; +} + +static void sector_mgr_open_sector(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + sinfo->opened = true; + } + } +} + +static void sector_mgr_close_sector(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + sinfo->opened = false; + } + } +} + +// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid) { +// for (int i = 0; i < MAX_SECTOR_NUM; i++) { +// zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; +// if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && sinfo->fileuuid == fileuuid) { +// return sinfo; +// } +// } +// return NULL; +// } + +static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->sector_index_in_file == sector_index_in_file && sinfo->fileuuid == fileuuid) { + return sinfo; + } + } + return NULL; +} + +static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid) { + int32_t maxsectorindex = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + if (sinfo->sector_index_in_file >= maxsectorindex) { + maxsectorindex = sinfo->sector_index_in_file; + } + } + } + return sector_mgr_find_sector(fileuuid, maxsectorindex); +} + +static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && memcmp(sinfo->filename, fileid, 8) == 0) { + return sinfo; + } + } + return NULL; +} + +static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo == sector) { + return i; + } + } + return -1; +} + +static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector) { + int32_t offset = sector_mgr_get_sector_offset(sector); + if (offset < 0) return -1; + return (offset + 1) * EEPROM_SECTOR_SIZE; +} + +static int32_t sector_mgr_file_get_size(int32_t fileuuid) { + int32_t filesize = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + filesize += sinfo->datalen; + } + } + return filesize; +} + +static int32_t sector_mgr_file_get_checksum(int32_t fileuuid) { + int32_t checksum = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + checksum += sinfo->sector_data_checksum; + } + } + return checksum; +} + +static const char* filename2str(uint8_t* filename) { + static char filename_str[32]; + sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); + return filename_str; +} + +int zeeprom_fs_dump_sector_state() { + ZLOGI_BLOCK("zeeprom_fs_dump_sector_state\n"); + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1) { + ZLOGI_BLOCK("[%d]: usage=%d opened=%d", i, sinfo->usage, sinfo->opened); + ZLOGI_BLOCK(" fname=%s, index_in_file=%d, datalen=%d, fileuuid=%d", filename2str(sinfo->filename), sinfo->sector_index_in_file, sinfo->datalen, sinfo->fileuuid); + } else { + ZLOGI_BLOCK("[%d]: usage=%d", i, sinfo->usage); + } + } + return 0; +} diff --git a/app/src/service/storage/zeeprom_fs.h b/app/src/service/storage/zeeprom_fs.h new file mode 100644 index 0000000..642a53f --- /dev/null +++ b/app/src/service/storage/zeeprom_fs.h @@ -0,0 +1,108 @@ +#pragma once +#include +/** + * @brief EEPROM¼òÒ×Îļþϵͳ´úÂë¿ò¼Ü + * + * Õû¸ö´æ´¢ÇøÓò·ÖΪÁ½¸öÇø [ÉÈÇøÍ·][ÎļþÊý¾ÝÇø] + * + * ----------------- + * | | + * | ÉÈÇøÍ· | 8K * 1 + * | | + * ----------------- + * | | + * | N*Êý¾ÝÉÈÇø | 8K * 31 + * | | + * ----------------- + * + * ÉÈÇøÍ·´æ´¢ 31* zeeprom_sector_info_t¸ö½á¹¹Ìå + * ½á¹¹Ìå:zeeprom_sector_info_t * 31 + * uint8_t usage; // 0:¿ÕÏÐ 1:ÒÑʹÓà + * uint8_t opened; // 0:δ´ò¿ª 1:ÒÑ´ò¿ª + * uint8_t filename[8]; // ÎļþÃû + * int32_t sector_index_in_file; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄÆðʼµØÖ· + * int32_t datalen; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄ³¤¶È + * uint32_t checksum; // ÎļþÊý¾ÝµÄУÑéºÍ + * int32_t fileuuid; // µÝÔö£¬¸ù¾ÝÕâ¸öindexÅжÏÎļþ´´½¨µÄÏȺó˳Ðò£¬Í¬Ê±Ò²Ï൱ÓÚÎļþΨһ±êʶ + * uint8_t usrdata[20]; // Óû§Êý¾Ý + * + * + * ÎļþµÄ¸ÅÄî: + * 1.Ò»¸öÎļþÓÉÒ»¸ö»ò¶à¸öÉÈÇø×é³É£¬Ã¿¸öÉÈÇøµÄ´óСΪ8K, + * 2.ͬһ¸öÎļþÒÀ¿¿fileuuid½øÐÐÅж¨ + * 3.Èç¹ûÏëÒª¶ÁÈ¡Îļþ´óС£¬Ö»Ðè¼ÆËãÏàͬfileuuidµÄËùÓÐzeeprom_sector_info_t.datalenµÄºÍ¼´¿É¡£ + * 4.Îļþ˳ÐòÒÀ¿¿sector_index_in_file½øÐÐÅÐ¶Ï + * 5.ÎļþÃû±£´æÔÚsector_index_in_fileΪ0µÄzeeprom_sector_info_t½á¹¹ÌåÖÐ + * + * ÉÈÇøÍ·µÄÌØÊâÐÔ: + * 1. ÉÈÇøÍ·³£×¤ÄÚ´æÖÐ + * 2. Èç¹ûÆÚÍûµôµç¶ªÆúÊý¾Ý£¬ÉÈÇøÍ·²»±£´æµ¼flashÖм´¿É + * + */ + +#define EEPROM_SIZE (256 * 1024) +#define EEPROM_SECTOR_MIN_WR_SIZE (256) +#define EEPROM_SECTOR_SIZE (8 * 1024) +#define MAX_SECTOR_NUM (EEPROM_SIZE / EEPROM_SECTOR_SIZE - 1) +#define EEPROM_FILE_SIZE (EEPROM_SECTOR_SIZE * MAX_SECTOR_NUM) + +// +#pragma pack(1) +typedef struct { + uint8_t usage; + uint8_t opened; + uint8_t filename[8]; // ×¢ÒâÎļþÃûΪ¹Ì¶¨°Ë¸ö×ֽڵĶþ½øÖÆÊý¾Ý£¬²»ÊÇ×Ö·û´® + int32_t sector_index_in_file; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄÆðʼµØÖ· + int32_t datalen; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄ³¤¶È + uint32_t sector_data_checksum; // ÎļþÊý¾ÝµÄУÑéºÍ + int32_t fileuuid; // µÝÔö£¬¸ù¾ÝÕâ¸öindexÅжÏÎļþ´´½¨µÄÏȺó˳Ðò£¬Í¬Ê±Ò²Ï൱ÓÚÎļþΨһ±êʶ + uint8_t usrdata[20]; +} zeeprom_sector_info_t; + +typedef struct { + uint8_t filename[8]; + uint8_t usrdata[20]; + + zeeprom_sector_info_t* sector_header; + int32_t file_offset; + int32_t file_size; + uint32_t checksum; + + int fd; + int32_t fileuuid; +} filehandler_t; + +typedef struct { + zeeprom_sector_info_t sectorinfos[MAX_SECTOR_NUM]; + int32_t fileuuid_cnt; // µÝÔö£¬Ð´´½¨ÎļþʱʹÓà + uint32_t sector_info_headers_checksum; // ÉÈÇøÍ·µÄУÑéºÍ +} zeeprom_header_t; +#pragma pack() + +int zeeprom_fs_init(); +int zeeprom_fs_uinit(); + +typedef enum { + kwrflag_read_only, + kwrflag_write_only, +} wrflag_t; + +zeeprom_header_t* zeeprom_fs_get_header(); + +int zeeprom_fs_open(uint8_t* filename, wrflag_t flag); + +int zeeprom_fs_close(int fd); + +int zeeprom_fs_write(int fd, const uint8_t* data, int32_t size); +int zeeprom_fs_read(int fd, uint8_t* data, int32_t size); + +int zeeprom_fs_get_filesize_by_fd(int fd); + +int zeeprom_fs_get_file_num(); +int zeeprom_fs_delete_the_oldest_file(); +int zeeprom_fs_delete(int32_t fileuuid); +int zeeprom_fs_delete_by_name(uint8_t* filename); + +int zeeprom_fs_dump_sector_state(); +int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid); +int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid); diff --git a/app/src/zeeprom_fs.c b/app/src/zeeprom_fs.c deleted file mode 100644 index 1c6594a..0000000 --- a/app/src/zeeprom_fs.c +++ /dev/null @@ -1,572 +0,0 @@ -#include "zeeprom_fs.h" - -#include "board/board_eeprom_driver.h" - -static zeeprom_header_t m_eeprom_header; -static bool m_is_init = false; - -static filehandler_t m_filehandler[2]; -static int m_fd_off; - -/******************************************************************************* - * º¯ÊýÉùÃ÷ * - *******************************************************************************/ - -static filehandler_t* filehandler_find(int fd); -static filehandler_t* filehandler_alloc(); -static void filehandler_rlease(int fd); - -static int32_t sector_mgr_find_earliest_file_created_index(); -static int32_t sector_mgr_free_sector(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_find_idle_sector(); -static bool sector_mgr_sector_is_open(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector(); -static void sector_mgr_open_sector(int32_t fileuuid); -static void sector_mgr_close_sector(int32_t fileuuid); -// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file); -static int32_t sector_mgr_file_get_size(int32_t fileuuid); - -static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid); -static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector); -static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector); -static int32_t sector_mgr_file_get_checksum(int32_t fileuuid); - -static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len); -static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len); -static uint32_t compute_checksum(const uint8_t* data, uint16_t len); - -/******************************************************************************* - * CODE * - *******************************************************************************/ - -static bool m_eeprom_header_inited = false; -int zeeprom_fs_init() { // - board_eeprom_init(); - if (!m_eeprom_header_inited) { - zeeprom_read(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); - uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); - if (checksum_val != m_eeprom_header.sector_info_headers_checksum) { - memset(&m_eeprom_header, 0, sizeof(m_eeprom_header)); - } - } - m_is_init = true; - m_eeprom_header_inited = true; - return 0; -} -int zeeprom_fs_uinit() { // - // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); - board_eeprom_uninit(); - m_is_init = false; - return 0; -} - -zeeprom_header_t* zeeprom_fs_get_header() { return &m_eeprom_header; } - -int zeeprom_fs_open(uint8_t* filename, wrflag_t wrflag) { - ZASSERT(m_is_init); - /** - * @brief - * 1. Èç¹ûÎļþÒѾ­´æÔÚ£¬Ôò´ò¿ªÎļþ - * 2. Èç¹ûÎļþ²»´æÔÚ£¬ Ôò´´½¨Îļþ - * - * ´´½¨Îļþ: - * 1. ÕÒµ½Ò»¸ö¿ÕÏÐÉÈÇø - * 2. ³õʼ»¯ÎļþÍ· - */ - - filehandler_t* fileHander = filehandler_alloc(); - if (!fileHander) { - ZLOGI("fileHander_alloc fail"); - return -1; - } - - if (wrflag == kwrflag_write_only) { - /******************************************************************************* - * дÎļþ * - *******************************************************************************/ - zeeprom_sector_info_t* sectorHeaderInfo = NULL; - zeeprom_fs_delete_by_name(filename); - - sectorHeaderInfo = sector_mgr_force_find_idle_sector(); - if (!sectorHeaderInfo) { - ZLOGE("sector_mgr_force_find_idle_sector fail"); - filehandler_rlease(fileHander->fd); - return -1; - } - - memset(sectorHeaderInfo, 0, sizeof(zeeprom_sector_info_t)); - sectorHeaderInfo->usage = 1; - sectorHeaderInfo->opened = 1; - memcpy(sectorHeaderInfo->filename, filename, 8); - sectorHeaderInfo->sector_index_in_file = 0; - sectorHeaderInfo->datalen = 0; - sectorHeaderInfo->sector_data_checksum = 0; - sectorHeaderInfo->fileuuid = m_eeprom_header.fileuuid_cnt++; - fileHander->fileuuid = sectorHeaderInfo->fileuuid; - fileHander->sector_header = sectorHeaderInfo; - fileHander->file_offset = 0; - fileHander->file_size = 0; - fileHander->checksum = 0; - return fileHander->fd; - - } else { - /******************************************************************************* - * ¶ÁÎļþ * - *******************************************************************************/ - zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); - if (sectorHeaderInfo) { - fileHander->fileuuid = sectorHeaderInfo->fileuuid; - fileHander->file_offset = 0; - fileHander->fd = fileHander->fd; - fileHander->sector_header = sectorHeaderInfo; - fileHander->file_size = sector_mgr_file_get_size(fileHander->fileuuid); - fileHander->checksum = sector_mgr_file_get_checksum(fileHander->fileuuid); - ZLOGI("filesize:%d", fileHander->file_size); - memcpy(fileHander->filename, filename, 8); - memcpy(fileHander->usrdata, sectorHeaderInfo->usrdata, sizeof(sectorHeaderInfo->usrdata)); - sector_mgr_open_sector(fileHander->fileuuid); - return fileHander->fd; - } else { - filehandler_rlease(fileHander->fd); - return -1; - } - } -} - -int zeeprom_fs_write(int fileid, const uint8_t* data, int32_t size) { - ZASSERT(m_is_init); - - filehandler_t* fileHander = NULL; - zeeprom_sector_info_t* header_sinfo = NULL; - zeeprom_sector_info_t* endsector = NULL; - int32_t wadd = 0; - - ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); - - fileHander = filehandler_find(fileid); - if (!fileHander) { - ZLOGE("fileHander_find fail"); - return -1; - } - - header_sinfo = fileHander->sector_header; - if (!header_sinfo) { - ZLOGE("header_sinfo fail"); - return -1; - } - - endsector = sector_mgr_find_end_sector(fileHander->fileuuid); - if (!endsector) { - ZLOGE("sector_mgr_find_end_sector fail"); - return -1; - } - - if (endsector->datalen + size > EEPROM_SECTOR_SIZE) { - ZLOGE("endsector->datalen + size > EEPROM_SECTOR_SIZE"); - return -1; - } - - wadd = sector_mgr_get_sector_rom_add(endsector); - if (wadd < 0) { - ZLOGE("sector_mgr_get_sector_rom_add fail"); - return -1; - } - ZASSERT(wadd % EEPROM_SECTOR_MIN_WR_SIZE == 0); - ZASSERT(wadd >= EEPROM_SECTOR_SIZE); - zeeprom_write(wadd + endsector->datalen, data, size); - - endsector->datalen = endsector->datalen + size; - endsector->sector_data_checksum += compute_checksum(data, size); - fileHander->file_offset += size; - fileHander->file_size += size; - fileHander->checksum += compute_checksum(data, size); - - if (endsector->datalen == EEPROM_SECTOR_SIZE) { - zeeprom_sector_info_t* newsector = sector_mgr_force_find_idle_sector(); - if (!newsector) { - ZLOGE("sector_mgr_force_find_idle_sector fail"); - return -1; - } - - memset(newsector, 0, sizeof(zeeprom_sector_info_t)); - newsector->usage = 1; - newsector->opened = 1; - newsector->sector_data_checksum = 0; - memcpy(newsector->filename, header_sinfo->filename, 8); - newsector->sector_index_in_file = endsector->sector_index_in_file + 1; - newsector->datalen = 0; - newsector->fileuuid = header_sinfo->fileuuid; - } - return size; -} - -int zeeprom_fs_close(int fileid) { - ZASSERT(m_is_init); - - filehandler_t* fileHander = filehandler_find(fileid); - if (!fileHander) { - ZLOGE("zeeprom_fs_close fileHander_find fail"); - return -1; - } - - sector_mgr_close_sector(fileHander->fileuuid); - uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); - m_eeprom_header.sector_info_headers_checksum = checksum_val; - // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); - - filehandler_rlease(fileid); - return 0; -} - -int zeeprom_fs_get_filesize_by_fd(int fd) { - ZASSERT(m_is_init); - filehandler_t* fileHander = filehandler_find(fd); - if (!fileHander) return 0; - return fileHander->file_size; -} - -int zeeprom_fs_read(int fileid, uint8_t* data, int32_t size) { - ZASSERT(m_is_init); - - /** - * @brief - * ÕÒµ½µ±Ç°ÉÈÇø - */ - ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); - filehandler_t* fileHander = filehandler_find(fileid); - if (!fileHander) return -1; - - if (fileHander->file_offset + size > fileHander->file_size) { - return -1; - } - - zeeprom_sector_info_t* header_sinfo = fileHander->sector_header; - if (!header_sinfo) { - return -1; - } - - int32_t sector_idx = fileHander->file_offset / EEPROM_SECTOR_SIZE; - int32_t sector_off = fileHander->file_offset % EEPROM_SECTOR_SIZE; - - zeeprom_sector_info_t* sector = sector_mgr_find_sector(fileHander->fileuuid, sector_idx); - if (!sector) { - return -1; - } - - int32_t radd = sector_mgr_get_sector_rom_add(sector); - ZASSERT(radd % EEPROM_SECTOR_MIN_WR_SIZE == 0); - radd += sector_off; - - zeeprom_read(radd, data, size); - fileHander->file_offset += size; - return size; -} - -int zeeprom_fs_delete(int32_t fileuuid) { - ZASSERT(m_is_init); - - sector_mgr_free_sector(fileuuid); - return 0; -} -int zeeprom_fs_delete_by_name(uint8_t* filename) { - ZASSERT(m_is_init); - - zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); - if (sectorHeaderInfo) { - sector_mgr_free_sector(sectorHeaderInfo->fileuuid); - } - return 0; -} - -int zeeprom_fs_get_file_num() { - ZASSERT(m_is_init); - - int count = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0) { - count++; - } - } - return count; -} -int zeeprom_fs_delete_the_oldest_file() { - ZASSERT(m_is_init); - - int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); - sector_mgr_free_sector(earliest_file_created_index); - return 0; -} - -int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid) { - ZASSERT(m_is_init); - return sector_mgr_file_get_size(fileuuid); -} - -int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid) { - ZASSERT(m_is_init); - return sector_mgr_file_get_checksum(fileuuid); -} - -static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len) { // - int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; - - int readTimes = len / wrsize; - int readRemain = len % wrsize; - - for (int i = 0; i < readTimes; i++) { - board_eeprom_read(add + i * wrsize, data + i * wrsize, wrsize); - } - if (readRemain > 0) { - board_eeprom_read(add + readTimes * wrsize, data + readTimes * wrsize, readRemain); - } -} -static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len) { - int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; - - int writeTimes = len / wrsize; - int writeRemain = len % wrsize; - - for (int i = 0; i < writeTimes; i++) { - // int pageoff = add / wrsize + i; - int32_t writeadd = add + i * wrsize; - board_eeprom_write(writeadd, data + i * wrsize, wrsize); - } - if (writeRemain > 0) { - int32_t writeadd = add + writeTimes * wrsize; - board_eeprom_write(writeadd, data + writeTimes * wrsize, writeRemain); - } -} - -static uint32_t compute_checksum(const uint8_t* data, uint16_t len) { - uint32_t sum = 0; - for (int i = 0; i < len; i++) { - sum += data[i]; - } - return sum; -} -/******************************************************************************* - * filehandler * - *******************************************************************************/ -static filehandler_t* filehandler_find(int fd) { - for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { - if (m_filehandler[i].fd == fd) { - return &m_filehandler[i]; - } - } - return NULL; -} -static filehandler_t* filehandler_alloc() { - for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { - if (m_filehandler[i].fd == 0) { - m_filehandler[i].fd = ++m_fd_off; - return &m_filehandler[i]; - } - } - return NULL; -} -static void filehandler_rlease(int fd) { - for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { - if (m_filehandler[i].fd == fd) { - m_filehandler[i].fd = 0; - return; - } - } -} -/******************************************************************************* - * sector_mgr * - *******************************************************************************/ - -// ²éÕÒ×îÔç´´½¨µÄÎļþµÄfile_created_index -static int32_t sector_mgr_find_earliest_file_created_index() { - int32_t earliest_file_created_index = INT32_MAX; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1) { - if (sinfo->fileuuid < earliest_file_created_index) { - earliest_file_created_index = sinfo->fileuuid; - } - } - } - return earliest_file_created_index; -} -// ɾ³ýÎļþ -static int32_t sector_mgr_free_sector(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - sinfo->usage = 0; - } - } - return 0; -} -// -static zeeprom_sector_info_t* sector_mgr_find_idle_sector() { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 0) { - return sinfo; - } - } - return NULL; -} -static bool sector_mgr_sector_is_open(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - return sinfo->opened; - } - } - return false; -} - -static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector() { - /** - * @brief ²éÕÒ¿ÕÏÐÉÈÇø - */ - zeeprom_sector_info_t* ret_sinfo = sector_mgr_find_idle_sector(); - if (ret_sinfo) return ret_sinfo; - /** - * @brief ²éÕÒ×îÔç´´½¨µÄÎļþ - */ - int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); - if (sector_mgr_sector_is_open(earliest_file_created_index)) { - return NULL; - } - - /** - * @brief ɾ³ý×îÔç´´½¨µÄÎļþ - */ - sector_mgr_free_sector(earliest_file_created_index); - - /** - * @brief ÖØÐ²éÕÒ¿ÕÏÐÉÈÇø - */ - ret_sinfo = sector_mgr_find_idle_sector(); - if (ret_sinfo) return ret_sinfo; - - return NULL; -} - -static void sector_mgr_open_sector(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - sinfo->opened = true; - } - } -} - -static void sector_mgr_close_sector(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - sinfo->opened = false; - } - } -} - -// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid) { -// for (int i = 0; i < MAX_SECTOR_NUM; i++) { -// zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; -// if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && sinfo->fileuuid == fileuuid) { -// return sinfo; -// } -// } -// return NULL; -// } - -static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->sector_index_in_file == sector_index_in_file && sinfo->fileuuid == fileuuid) { - return sinfo; - } - } - return NULL; -} - -static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid) { - int32_t maxsectorindex = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - if (sinfo->sector_index_in_file >= maxsectorindex) { - maxsectorindex = sinfo->sector_index_in_file; - } - } - } - return sector_mgr_find_sector(fileuuid, maxsectorindex); -} - -static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && memcmp(sinfo->filename, fileid, 8) == 0) { - return sinfo; - } - } - return NULL; -} - -static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo == sector) { - return i; - } - } - return -1; -} - -static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector) { - int32_t offset = sector_mgr_get_sector_offset(sector); - if (offset < 0) return -1; - return (offset + 1) * EEPROM_SECTOR_SIZE; -} - -static int32_t sector_mgr_file_get_size(int32_t fileuuid) { - int32_t filesize = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - filesize += sinfo->datalen; - } - } - return filesize; -} - -static int32_t sector_mgr_file_get_checksum(int32_t fileuuid) { - int32_t checksum = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - checksum += sinfo->sector_data_checksum; - } - } - return checksum; -} - -static const char* filename2str(uint8_t* filename) { - static char filename_str[32]; - sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); - return filename_str; -} - -int zeeprom_fs_dump_sector_state() { - ZLOGI_BLOCK("zeeprom_fs_dump_sector_state\n"); - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1) { - ZLOGI_BLOCK("[%d]: usage=%d opened=%d", i, sinfo->usage, sinfo->opened); - ZLOGI_BLOCK(" fname=%s, index_in_file=%d, datalen=%d, fileuuid=%d", filename2str(sinfo->filename), sinfo->sector_index_in_file, sinfo->datalen, sinfo->fileuuid); - } else { - ZLOGI_BLOCK("[%d]: usage=%d", i, sinfo->usage); - } - } - return 0; -} diff --git a/app/src/zeeprom_fs.h b/app/src/zeeprom_fs.h deleted file mode 100644 index 642a53f..0000000 --- a/app/src/zeeprom_fs.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once -#include -/** - * @brief EEPROM¼òÒ×Îļþϵͳ´úÂë¿ò¼Ü - * - * Õû¸ö´æ´¢ÇøÓò·ÖΪÁ½¸öÇø [ÉÈÇøÍ·][ÎļþÊý¾ÝÇø] - * - * ----------------- - * | | - * | ÉÈÇøÍ· | 8K * 1 - * | | - * ----------------- - * | | - * | N*Êý¾ÝÉÈÇø | 8K * 31 - * | | - * ----------------- - * - * ÉÈÇøÍ·´æ´¢ 31* zeeprom_sector_info_t¸ö½á¹¹Ìå - * ½á¹¹Ìå:zeeprom_sector_info_t * 31 - * uint8_t usage; // 0:¿ÕÏÐ 1:ÒÑʹÓà - * uint8_t opened; // 0:δ´ò¿ª 1:ÒÑ´ò¿ª - * uint8_t filename[8]; // ÎļþÃû - * int32_t sector_index_in_file; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄÆðʼµØÖ· - * int32_t datalen; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄ³¤¶È - * uint32_t checksum; // ÎļþÊý¾ÝµÄУÑéºÍ - * int32_t fileuuid; // µÝÔö£¬¸ù¾ÝÕâ¸öindexÅжÏÎļþ´´½¨µÄÏȺó˳Ðò£¬Í¬Ê±Ò²Ï൱ÓÚÎļþΨһ±êʶ - * uint8_t usrdata[20]; // Óû§Êý¾Ý - * - * - * ÎļþµÄ¸ÅÄî: - * 1.Ò»¸öÎļþÓÉÒ»¸ö»ò¶à¸öÉÈÇø×é³É£¬Ã¿¸öÉÈÇøµÄ´óСΪ8K, - * 2.ͬһ¸öÎļþÒÀ¿¿fileuuid½øÐÐÅж¨ - * 3.Èç¹ûÏëÒª¶ÁÈ¡Îļþ´óС£¬Ö»Ðè¼ÆËãÏàͬfileuuidµÄËùÓÐzeeprom_sector_info_t.datalenµÄºÍ¼´¿É¡£ - * 4.Îļþ˳ÐòÒÀ¿¿sector_index_in_file½øÐÐÅÐ¶Ï - * 5.ÎļþÃû±£´æÔÚsector_index_in_fileΪ0µÄzeeprom_sector_info_t½á¹¹ÌåÖÐ - * - * ÉÈÇøÍ·µÄÌØÊâÐÔ: - * 1. ÉÈÇøÍ·³£×¤ÄÚ´æÖÐ - * 2. Èç¹ûÆÚÍûµôµç¶ªÆúÊý¾Ý£¬ÉÈÇøÍ·²»±£´æµ¼flashÖм´¿É - * - */ - -#define EEPROM_SIZE (256 * 1024) -#define EEPROM_SECTOR_MIN_WR_SIZE (256) -#define EEPROM_SECTOR_SIZE (8 * 1024) -#define MAX_SECTOR_NUM (EEPROM_SIZE / EEPROM_SECTOR_SIZE - 1) -#define EEPROM_FILE_SIZE (EEPROM_SECTOR_SIZE * MAX_SECTOR_NUM) - -// -#pragma pack(1) -typedef struct { - uint8_t usage; - uint8_t opened; - uint8_t filename[8]; // ×¢ÒâÎļþÃûΪ¹Ì¶¨°Ë¸ö×ֽڵĶþ½øÖÆÊý¾Ý£¬²»ÊÇ×Ö·û´® - int32_t sector_index_in_file; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄÆðʼµØÖ· - int32_t datalen; // µ±Ç°ÉÈÇøÖÐÎļþÊý¾ÝµÄ³¤¶È - uint32_t sector_data_checksum; // ÎļþÊý¾ÝµÄУÑéºÍ - int32_t fileuuid; // µÝÔö£¬¸ù¾ÝÕâ¸öindexÅжÏÎļþ´´½¨µÄÏȺó˳Ðò£¬Í¬Ê±Ò²Ï൱ÓÚÎļþΨһ±êʶ - uint8_t usrdata[20]; -} zeeprom_sector_info_t; - -typedef struct { - uint8_t filename[8]; - uint8_t usrdata[20]; - - zeeprom_sector_info_t* sector_header; - int32_t file_offset; - int32_t file_size; - uint32_t checksum; - - int fd; - int32_t fileuuid; -} filehandler_t; - -typedef struct { - zeeprom_sector_info_t sectorinfos[MAX_SECTOR_NUM]; - int32_t fileuuid_cnt; // µÝÔö£¬Ð´´½¨ÎļþʱʹÓà - uint32_t sector_info_headers_checksum; // ÉÈÇøÍ·µÄУÑéºÍ -} zeeprom_header_t; -#pragma pack() - -int zeeprom_fs_init(); -int zeeprom_fs_uinit(); - -typedef enum { - kwrflag_read_only, - kwrflag_write_only, -} wrflag_t; - -zeeprom_header_t* zeeprom_fs_get_header(); - -int zeeprom_fs_open(uint8_t* filename, wrflag_t flag); - -int zeeprom_fs_close(int fd); - -int zeeprom_fs_write(int fd, const uint8_t* data, int32_t size); -int zeeprom_fs_read(int fd, uint8_t* data, int32_t size); - -int zeeprom_fs_get_filesize_by_fd(int fd); - -int zeeprom_fs_get_file_num(); -int zeeprom_fs_delete_the_oldest_file(); -int zeeprom_fs_delete(int32_t fileuuid); -int zeeprom_fs_delete_by_name(uint8_t* filename); - -int zeeprom_fs_dump_sector_state(); -int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid); -int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid); diff --git a/bak/FIR.c b/bak/FIR.c new file mode 100644 index 0000000..dfcad40 --- /dev/null +++ b/bak/FIR.c @@ -0,0 +1,38 @@ +#include "FIR.h" +/*360hz 0.51Hz~8.9Hz 20190925*/ +#define taps 32 +static const float coefficients[taps] = {0.012177,0.01599,0.019905,0.02387,0.027827,0.031719,0.035487,0.039075,0.042426,0.045488,0.048212,0.050553,0.052475,0.053944,0.054937,0.055438,0.055438,0.054937,0.053944,0.052475,0.050553,0.048212,0.045488,0.042426,0.039075,0.035487,0.031719,0.027827,0.02387,0.019905,0.01599,0.012177}; + +static float buffer[taps]; +unsigned offset; + +float FIR_filter(float input) { + const float *coeff = coefficients; + const float *coeff_end = coefficients + taps; + + float *buf_val = buffer + offset; + + *buf_val = input; + float output_ = 0; + + while (buf_val >= buffer) { + output_ += *buf_val-- * *coeff++; + } + + buf_val = buffer + taps - 1; + + while (coeff < coeff_end) { + output_ += *buf_val-- * *coeff++; + } + + if (++offset >= taps) { + offset = 0; + } + + return output_; +} + +void FIR_reset_buffer() { + memset(buffer, 0, sizeof(float) * taps); + offset = 0; +} diff --git a/bak/FIR.h b/bak/FIR.h new file mode 100644 index 0000000..f9545c5 --- /dev/null +++ b/bak/FIR.h @@ -0,0 +1,14 @@ +#ifndef __FIR_H__ +#define __FIR_H__ + +#include +#include +#include +#include +#include + + +extern float FIR_filter(float); +extern void FIR_reset_buffer(); + +#endif diff --git a/bak/HC_Chen_detect.c b/bak/HC_Chen_detect.c new file mode 100644 index 0000000..5bfcd67 --- /dev/null +++ b/bak/HC_Chen_detect.c @@ -0,0 +1,128 @@ +#include "HC_Chen_detect.h" + +bool HC_Chen_detect(float signal) +{ + ecg_buff[ecg_buff_WR_idx++] = signal; + sample = ecg_buff_WR_idx; + ecg_buff_WR_idx %= (M+1); + + /* High pass filtering */ + if(number_iter < M){ + // first fill buffer with enough points for HP filter + hp_sum += ecg_buff[ecg_buff_RD_idx]; + hp_buff[hp_buff_WR_idx] = 0; + } + else{ + hp_sum += ecg_buff[ecg_buff_RD_idx]; + + int tmp = ecg_buff_RD_idx - M; + if(tmp < 0){ + tmp += M + 1; + } + + hp_sum -= ecg_buff[tmp]; + + float y1 = 0; + float y2 = 0; + + tmp = (ecg_buff_RD_idx - ((M+1)/2)); + if(tmp < 0){ + tmp += M + 1; + } + + y2 = ecg_buff[tmp]; + + y1 = HP_CONSTANT * hp_sum; + + hp_buff[hp_buff_WR_idx] = y2 - y1; + + } + + // done reading ECG buffer, increment position + ecg_buff_RD_idx++; + ecg_buff_RD_idx %= (M+1); + + // done writing to HP buffer, increment position + hp_buff_WR_idx++; + hp_buff_WR_idx %= (N+1); + + /* Low pass filtering */ + + // shift in new sample from high pass filter + lp_sum += hp_buff[hp_buff_RD_idx] * hp_buff[hp_buff_RD_idx]; + + if(number_iter < N){ + // first fill buffer with enough points for LP filter + next_eval_pt = 0; + } + else{ + // shift out oldest data point + int tmp = hp_buff_RD_idx - N; + if(tmp < 0){ + tmp += N+1; + } + + lp_sum -= hp_buff[tmp] * hp_buff[tmp]; + + next_eval_pt = lp_sum; + } + + // done reading HP buffer, increment position + hp_buff_RD_idx++; + hp_buff_RD_idx %= (N+1); + + /* Adapative thresholding beat detection */ + // set initial threshold + if(number_iter < window_size) { + if(next_eval_pt > treshold) { + treshold = next_eval_pt; + } + ++number_iter; + } + + // check if detection hold off period has passed + if(triggered){ + trig_time++; + + if(trig_time >= DELAY_TIME){ + triggered = false; + trig_time = 0; + } + } + + // find if we have a new max + if(next_eval_pt > win_max) win_max = next_eval_pt; + + // find if we are above adaptive threshold + if(next_eval_pt > treshold && !triggered) { + //result.push_back(true); + + last_qrs_point = sample; + + triggered = true; + return true; + } + else { + //result.push_back(false); + } + + // adjust adaptive threshold using max of signal found + // in previous window + if(win_idx++ >= window_size){ + // weighting factor for determining the contribution of + // the current peak value to the threshold adjustment + float gamma = (0.2f+0.15f)/2.0f; // 0.15~0.2 + + // forgetting factor - + // rate at which we forget old observations + float alpha = 0.01f + ( ((float) rand() / (float) RAND_MAX) * ((0.1f - 0.01f))); // 0~1 + //float alpha = 1.0f*exp(-0.00005f*(sample - last_qrs_point)); + + treshold = alpha * gamma * win_max + (1.0f - alpha) * treshold; + + // reset current window ind + win_idx = 0; + win_max = -10000000; + } + return false; +} diff --git a/bak/HC_Chen_detect.h b/bak/HC_Chen_detect.h new file mode 100644 index 0000000..cb9fa51 --- /dev/null +++ b/bak/HC_Chen_detect.h @@ -0,0 +1,53 @@ +#ifndef __HC_CHEN__ +#define __HC_CHEN__ + +#include +#include +#include +#include +#include + + +#include "QRS.h" + + +#define M 9 +#define N 54//SAMPLING_RATE * 0.15f +static const uint32_t window_size = SAMPLING_RATE; +static const float HP_CONSTANT = ((float) 1.0f / (float) M); +// circular buffer for input ecg signal +// we need to keep a history of M + 1 samples for HP filter +static float ecg_buff[M + 1] = {0}; +static int ecg_buff_WR_idx = 0; +static int ecg_buff_RD_idx = 0; + +// circular buffer for input ecg signal +// we need to keep a history of N+1 samples for LP filter +static float hp_buff[N + 1] = {0}; +static int hp_buff_WR_idx = 0; +static int hp_buff_RD_idx = 0; + +// LP filter outputs a single point for every input point +// This goes straight to adaptive filtering for eval +static float next_eval_pt = 0; + +// running sums for HP and LP filters, values shifted in FILO +static float hp_sum = 0; +static float lp_sum = 0; + +// parameters for adaptive thresholding +static float treshold = 0; +static bool triggered = false; +static int trig_time = 0; +static float win_max = 0; +static int win_idx = 0; +static int number_iter = 0; + +static int sample = 0; +static int last_qrs_point = 0; + +static const int DELAY_TIME = 180;//window_size * 0.5f; + +extern bool HC_Chen_detect(float); + +#endif diff --git a/bak/Pan_Tompkins_detect.c b/bak/Pan_Tompkins_detect.c new file mode 100644 index 0000000..6caea37 --- /dev/null +++ b/bak/Pan_Tompkins_detect.c @@ -0,0 +1,373 @@ +#include "Pan_Tompkins_detect.h" + +/* y(nT) = 1.875y(nT – T) – 0.9219y(nT – 2T) + x (nT) – x(nT – 2T) */ +int TwoPoleRecursive(int data) +{ + static int xnt, xm1, xm2, ynt, ym1, ym2 = 0; + + xnt = data; + ynt = (ym1 + (ym1 >> 1) + (ym1 >> 2) + (ym1 >> 3)) + // 1.875 = 1 + 1/2 + 1/4 + 1/8 + (((ym2 >> 1) + (ym2 >> 2) + (ym2 >> 3) + (ym2 >> 5) + (ym2 >> 6)) + xnt - xm2); // 0.916 = 1 + 1/2 + 1/4 + 1/8 + 1/32 + 1/64 + xm2 = xm1; + xm1 = xnt; + xm2 = ym1; + ym2 = ym1; + ym1 = ynt; + return ynt; +} + +/* y(nT) = 2y(nT – T) – y(nT – 2T) + x(nT) – 2x(nT – 6T) + x(nT – 12T) */ +int LowPassFilter(int data) +{ + static int y1 = 0, y2 = 0, x[26], n = 12; + int y0; + + x[n] = x[n + 13] = data; + y0 = (y1 << 1) - y2 + x[n] - (x[n + 6] << 1) + x[n + 12]; + y2 = y1; + y1 = y0; + y0 >>= 5; + if(--n < 0){ + n = 12; + } + return y0; +} + +/* p(nT) = x(nT – 16T) – 32 [y(nT – T) + x(nT) – x(nT – 32T)] */ +int HighPassFilter(int data) +{ + static int y1 = 0, x[66], n = 32; + int y0; + + x[n] = x[n + 33] = data; + y0 = y1 + x[n] - x[n + 32]; + y1 = y0; + if(--n < 0){ + n = 32; + } + return (x[n + 16] - (y0 >> 5)); +} + +/* y = 1/8 (2x( nT) + x( nT - T) - x( nT - 3T) - 2x( nT - 4T)) */ +int Derivative(int data) +{ + int y; + static int x_derv[4]; + + y = (data << 1) + x_derv[3] - x_derv[1] - ( x_derv[0] << 1); + y >>= 3; + for(int i = 0; i < 3; ++i){ + x_derv[i] = x_derv[i + 1]; + } + x_derv[3] = data; + return y; +} + +int Squar(int data) +{ + return (data * data); +} + +/* y(nT) = 1/N [x(nT – (N – 1)T) + x(nT – (N – 2)T) +...+ x(nT)] */ +int MovingWindowIntegral(int data) +{ + //static const int WINDOW_SIZE = SAMPLING_RATE * 0.2; + #define WINDOW_SIZE 72 + + static int x[WINDOW_SIZE], ptr = 0; + static long sum = 0; + long ly; + int y; + + if(++ptr == WINDOW_SIZE){ + ptr = 0; + } + sum -= x[ptr]; + sum += data; + x[ptr] = data; + ly = sum >> 5; + uint32_t MAX_INTEGRAL = 4096;//32400; + if(ly > MAX_INTEGRAL){ + y = MAX_INTEGRAL; + } + else{ + y = (int)ly; + } + return (y); +} + +SignalPoint ThresholdCalculate(int sample,float value,int bandpass,int square,int integral) +{ + //static const int QRS_TIME = SAMPLING_RATE * 0.1; + //static const int SEARCH_BACK_TIME = SAMPLING_RATE * 1.66f; + #define QRS_TIME 36 + #define SEARCH_BACK_TIME 598 + + static int bandpass_buffer[SEARCH_BACK_TIME],integral_buffer[SEARCH_BACK_TIME]; + static SignalPoint peak_buffer[SEARCH_BACK_TIME]; + static int square_buffer[QRS_TIME]; + static long unsigned last_qrs = 0, last_slope = 0, current_slope = 0; + static int peak_i = 0, peak_f = 0, threshold_i1 = 0, threshold_i2 = 0, threshold_f1 = 0, threshold_f2 = 0, spk_i = 0, spk_f = 0, npk_i = 0, npk_f = 0; + static bool qrs, regular = true, prev_regular; + static int rr1[8]={0}, rr2[8]={0}, rravg1, rravg2, rrlow = 0, rrhigh = 0, rrmiss = 0; + + SignalPoint result; + result.index = -1; + + peak_buffer[sample%SEARCH_BACK_TIME].index = sample; + peak_buffer[sample%SEARCH_BACK_TIME].value = value; + bandpass_buffer[sample%SEARCH_BACK_TIME] = bandpass; + integral_buffer[sample%SEARCH_BACK_TIME] = integral; + square_buffer[sample%QRS_TIME] = square; + + // If the current signal is above one of the thresholds (integral or filtered signal), it's a peak candidate. + if(integral >= threshold_i1 || bandpass >= threshold_f1){ + peak_i = integral; + peak_f = bandpass; + } + + // If both the integral and the signal are above their thresholds, they're probably signal peaks. + if((integral >= threshold_i1) && (bandpass >= threshold_f1)){ + // There's a 200ms latency. If the new peak respects this condition, we can keep testing. + if(sample > last_qrs + SAMPLING_RATE*0.2f){ + //if(sample > last_qrs + (SAMPLING_RATE*0.2f)){ + // If it respects the 200ms latency, but it doesn't respect the 360ms latency, we check the slope. + if(sample <= last_qrs + (long unsigned int)(0.36*SAMPLING_RATE)){ + // The squared slope is "M" shaped. So we have to check nearby samples to make sure we're really looking + // at its peak value, rather than a low one. + int current = sample; + current_slope = 0; + for(int j = current - QRS_TIME; j <= current; ++j){ + if(square_buffer[j%QRS_TIME] > current_slope){ + current_slope = square_buffer[j%QRS_TIME]; + } + } + //current_slope = square; + + if(current_slope <= (int)(last_slope/2)){ + qrs = false; + //return qrs; + } + + else{ + spk_i = 0.125*peak_i + 0.875*spk_i; + threshold_i1 = npk_i + 0.25*(spk_i - npk_i); + threshold_i2 = 0.5*threshold_i1; + + spk_f = 0.125*peak_f + 0.875*spk_f; + threshold_f1 = npk_f + 0.25*(spk_f - npk_f); + threshold_f2 = 0.5*threshold_f1; + + last_slope = current_slope; + qrs = true; + + result.value = value; + result.index = sample; + } + } + // If it was above both thresholds and respects both latency periods, it certainly is a R peak. + else{ + int current = sample; + current_slope = 0; + for(int j = current - QRS_TIME; j <= current; ++j){ + if(square_buffer[j%QRS_TIME] > current_slope){ + current_slope = square_buffer[j%QRS_TIME]; + } + } + //current_slope = square; + + spk_i = 0.125*peak_i + 0.875*spk_i; + threshold_i1 = npk_i + 0.25*(spk_i - npk_i); + threshold_i2 = 0.5*threshold_i1; + + spk_f = 0.125*peak_f + 0.875*spk_f; + threshold_f1 = npk_f + 0.25*(spk_f - npk_f); + threshold_f2 = 0.5*threshold_f1; + + last_slope = current_slope; + qrs = true; + + result.value = value; + result.index = sample; + } + } + // If the new peak doesn't respect the 200ms latency, it's noise. Update thresholds and move on to the next sample. + else{ + peak_i = integral; + npk_i = 0.125*peak_i + 0.875*npk_i; + threshold_i1 = npk_i + 0.25*(spk_i - npk_i); + threshold_i2 = 0.5*threshold_i1; + peak_f = bandpass; + npk_f = 0.125*peak_f + 0.875*npk_f; + threshold_f1 = npk_f + 0.25*(spk_f - npk_f); + threshold_f2 = 0.5*threshold_f1; + qrs = false; + /*outputSignal[current] = qrs; + if (sample > DELAY + BUFFSIZE) + output(outputSignal[0]); + continue;*/ + + //return qrs; + return result; + } + } + + // If a QRS complex was detected, the RR-averages must be updated. + if(qrs){ + // Add the newest RR-interval to the buffer and get the new average. + rravg1 = 0; + for (int i = 0; i < 7; ++i){ + rr1[i] = rr1[i+1]; + rravg1 += rr1[i]; + } + rr1[7] = sample - last_qrs; + last_qrs = sample; + rravg1 += rr1[7]; + rravg1 *= 0.125; + + // If the newly-discovered RR-average is normal, add it to the "normal" buffer and get the new "normal" average. + // Update the "normal" beat parameters. + if ( (rr1[7] >= rrlow) && (rr1[7] <= rrhigh) ){ + rravg2 = 0; + for (int i = 0; i < 7; ++i){ + rr2[i] = rr2[i+1]; + rravg2 += rr2[i]; + } + rr2[7] = rr1[7]; + rravg2 += rr2[7]; + rravg2 *= 0.125; + rrlow = 0.92*rravg2; + rrhigh = 1.16*rravg2; + rrmiss = 1.66*rravg2; + } + + prev_regular = regular; + if(rravg1 == rravg2){ + regular = true; + } + // If the beat had been normal but turned odd, change the thresholds. + else{ + regular = false; + if (prev_regular){ + threshold_i1 /= 2; + threshold_f1 /= 2; + } + } + } + // If no R-peak was detected, it's important to check how long it's been since the last detection. + else{ + int current = sample; + // If no R-peak was detected for too long, use the lighter thresholds and do a back search. + // However, the back search must respect the 200ms limit and the 360ms one (check the slope). + if((sample - last_qrs > (long unsigned int)rrmiss) && (sample > last_qrs + SAMPLING_RATE*0.2f)){ + //if((sample - last_qrs > (long unsigned int)rrmiss) && (sample > last_qrs + (SAMPLING_RATE*0.2f))){ + + // If over SEARCH_BACK_TIME of QRS complex + if((sample - last_qrs) > SEARCH_BACK_TIME){ + last_qrs = sample; + //return result; + } + + int qrs_last_index = 0; // Last point of QRS complex + + for(int i = current - (sample - last_qrs) + SAMPLING_RATE*0.2f; i < (long unsigned int)current; ++i){ + //for(int i = current - (sample - last_qrs) + (SAMPLING_RATE*0.2f); i < (long unsigned int)current; ++i){ + if((integral_buffer[i%SEARCH_BACK_TIME] > threshold_i2) && (bandpass_buffer[i%SEARCH_BACK_TIME] > threshold_f2)){ + current_slope = 0; + for(int j = current - QRS_TIME; j <= current; ++j){ + if(square_buffer[j%QRS_TIME] > current_slope){ + current_slope = square_buffer[j%QRS_TIME]; + } + } + //current_slope = square; + + if((current_slope < (int)(last_slope/2)) && (i + sample) < last_qrs + 0.36*last_qrs){ + qrs = false; + } + else if(i - last_qrs > 550){ + peak_i = integral_buffer[i%SEARCH_BACK_TIME]; + peak_f = bandpass_buffer[i%SEARCH_BACK_TIME]; + spk_i = 0.25*peak_i+ 0.75*spk_i; + spk_f = 0.25*peak_f + 0.75*spk_f; + threshold_i1 = npk_i + 0.25*(spk_i - npk_i); + threshold_i2 = 0.5*threshold_i1; + last_slope = current_slope; + threshold_f1 = npk_f + 0.25*(spk_f - npk_f); + threshold_f2 = 0.5*threshold_f1; + // If a signal peak was detected on the back search, the RR attributes must be updated. + // This is the same thing done when a peak is detected on the first try. + //RR Average 1 + rravg1 = 0; + for(int j = 0; j < 7; ++j){ + rr1[j] = rr1[j+1]; + rravg1 += rr1[j]; + } + rr1[7] = sample - (current - i) - last_qrs; + qrs = true; + qrs_last_index = i; + last_qrs = sample - (current - i); + rravg1 += rr1[7]; + rravg1 *= 0.125; + + //RR Average 2 + if((rr1[7] >= rrlow) && (rr1[7] <= rrhigh)){ + rravg2 = 0; + for (int i = 0; i < 7; ++i){ + rr2[i] = rr2[i+1]; + rravg2 += rr2[i]; + } + rr2[7] = rr1[7]; + rravg2 += rr2[7]; + rravg2 *= 0.125; + rrlow = 0.92*rravg2; + rrhigh = 1.16*rravg2; + rrmiss = 1.66*rravg2; + } + + prev_regular = regular; + if(rravg1 == rravg2){ + regular = true; + } + else{ + regular = false; + if(prev_regular){ + threshold_i1 /= 2; + threshold_f1 /= 2; + } + } + + break; + } + } + } + + if(qrs){ + //outputSignal[current] = false; + //outputSignal[i] = true; + //if (sample > DELAY + BUFFSIZE) + //output(outputSignal[0]); + //continue; + + //return qrs; + return peak_buffer[qrs_last_index%SEARCH_BACK_TIME]; + } + } + + // Definitely no signal peak was detected. + if(!qrs){ + // If some kind of peak had been detected, then it's certainly a noise peak. Thresholds must be updated accordinly. + if((integral >= threshold_i1) || (bandpass >= threshold_f1)){ + peak_i = integral; + npk_i = 0.125*peak_i + 0.875*npk_i; + threshold_i1 = npk_i + 0.25*(spk_i - npk_i); + threshold_i2 = 0.5*threshold_i1; + peak_f = bandpass; + npk_f = 0.125*peak_f + 0.875*npk_f; + threshold_f1 = npk_f + 0.25*(spk_f - npk_f); + threshold_f2 = 0.5*threshold_f1; + } + } + } + + return result; + } diff --git a/bak/Pan_Tompkins_detect.h b/bak/Pan_Tompkins_detect.h new file mode 100644 index 0000000..cbd65d0 --- /dev/null +++ b/bak/Pan_Tompkins_detect.h @@ -0,0 +1,21 @@ +#ifndef __PAN_TOMPKINS__ +#define __PAN_TOMPKINS__ + +#include +#include +#include +#include +#include + +#include "QRS.h" +extern int TwoPoleRecursive(int); + +extern int LowPassFilter(int); +extern int HighPassFilter(int); + +extern int Derivative(int); +extern int Squar(int); +extern int MovingWindowIntegral(int); + +extern SignalPoint ThresholdCalculate(int,float,int,int,int); +#endif diff --git a/bak/QRS.h b/bak/QRS.h new file mode 100644 index 0000000..33aba1b --- /dev/null +++ b/bak/QRS.h @@ -0,0 +1,30 @@ +#pragma once +#include +//const uint32_t SAMPLING_RATE = 1000; +#define SAMPLING_RATE 360 + +typedef struct +{ + float value; + int32_t index; +}SignalPoint; + +enum +{ + NOTQRS, /* not-QRS (not a getann/putann code) */ + NORMAL, /* normal beat */ + LBBB, /* left bundle branch block beat */ + RBBB, /* right bundle branch block beat */ + ABERR, /* aberrated atrial premature beat */ + PVC, /* premature ventricular contraction */ + FUSION, /* fusion of ventricular and normal beat */ + NPC, /* nodal (junctional) premature beat */ + APC, /* atrial premature contraction */ + SVPB, /* premature or ectopic supraventricular beat */ + VESC, /* ventricular escape beat */ + NESC, /* nodal (junctional) escape beat */ + PACE, /* paced beat */ + UNKNOWN, /* unclassifiable beat */ + NOISE, /* signal quality change */ + ARFCT /* isolated QRS-like artifact */ +}; diff --git a/bak/So_Chen_detect.c b/bak/So_Chen_detect.c new file mode 100644 index 0000000..e329825 --- /dev/null +++ b/bak/So_Chen_detect.c @@ -0,0 +1,93 @@ +#include "So_Chen_detect.h" + +SignalPoint So_Chen_detect(SignalPoint signal,int initial_point,float threshold_parameter,float filter_parameter) +{ + /* init slop window pool, size = 5 */ + if(signal_window_count < signal_window_size){ + signal_window[signal_window_count%signal_window_size] = signal; + ++signal_window_count; + SignalPoint value; + value.index = -1; + return value; + } + else{ + signal_window[signal_window_count%signal_window_size] = signal; + ++signal_window_count; + SignalPoint value; + } + + /* calculate slop */ + uint32_t idx_for_slop = signal_window_count-2; + slop.value = ( (-2.0f * signal_window[(idx_for_slop-2)%signal_window_size].value) - signal_window[(idx_for_slop-1)%signal_window_size].value + signal_window[(idx_for_slop+1)%signal_window_size].value + (2.0f * signal_window[(idx_for_slop+2)%signal_window_size].value) ); + slop.index = signal_window[idx_for_slop%signal_window_size].index; + + /* init maxi */ + if(!so_chen_init_flag){ + if(!maxi_init){ + max.value = 0; + max.index = -1; + maxi = slop.value; + maxi_init = true; + } + ++init_count; + if(init_count > initial_point){ + so_chen_init_flag = true; + /* calculate slop threshold */ + slop_threshold = threshold_parameter / 16.0f * maxi; + } + if(slop.value > maxi){ + maxi = slop.value; + } + SignalPoint value; + value.index = -1; + return value; + } + + /* detect QRS complex on set */ + if(qrs_on_set_flag && (signal_window_count - last_point > enhanced_point)){ + if(!max_init){ + max = signal_window[(idx_for_slop)%signal_window_size]; + max_init = true; + } + if(signal_window[(idx_for_slop)%signal_window_size].value > max.value){ + max = signal_window[(idx_for_slop)%signal_window_size]; + max_slop = slop; + } + else if(signal_window[(idx_for_slop)%signal_window_size].value < max.value){ + last_point = signal_window_count; + qrs_on_set_flag = false; + max_init = false; + maxi = ((abs(max.value - qrs_onset_point.value) - maxi) / filter_parameter) + maxi; + slop_threshold = threshold_parameter / 16.0f * maxi; + last_maxi = maxi; + return max; + } + } + else{ + if(slop.value > slop_threshold){ + ++qrs_on_set_count; + } + else if(qrs_on_set_count){ + qrs_on_set_count = 0; + } + + if(qrs_on_set_count >= 2){ // is QRS complex on set + qrs_on_set_flag = true; + qrs_on_set_count = 0; + qrs_onset_idx = idx_for_slop; + qrs_onset_point = signal; + } + else if((signal_window_count - last_point > enhanced_point * 2) && (slop_threshold > 0)){ //decay threshold + + slop_threshold -= slop.value; + + if((signal_window_count - last_point > SAMPLING_RATE * 3)){ //threshold oscillating + slop_threshold -= ((signal_window_count - last_point) >> (int)threshold_parameter); + } + } + } + + SignalPoint value; + value.index = -1; + return value; +} diff --git a/bak/So_Chen_detect.h b/bak/So_Chen_detect.h new file mode 100644 index 0000000..a505775 --- /dev/null +++ b/bak/So_Chen_detect.h @@ -0,0 +1,42 @@ +#ifndef __SO_AND_CHEN__ +#define __SO_AND_CHEN__ + +#include +#include +#include +#include +#include + +#include "QRS.h" +static const uint32_t enhanced_point = SAMPLING_RATE * 0.35f; + +#define signal_window_size 5 +static SignalPoint signal_window[signal_window_size]; +static uint32_t signal_window_count = 0; + +static SignalPoint slop; + +static bool so_chen_init_flag = false; +static uint32_t init_count = 0; + +static bool maxi_init = false; +static float maxi; + +static float slop_threshold = 0; + +static SignalPoint qrs_onset_point; + +static int qrs_on_set_count = 0; +static int qrs_onset_idx = 0; +static bool qrs_on_set_flag = false; + +static SignalPoint max; +static SignalPoint max_slop; +static bool max_init = false; + +static float last_maxi = 0; +static uint32_t last_point = 0; + +SignalPoint So_Chen_detect(SignalPoint,int,float,float); + +#endif diff --git a/bak/adaptive_algorithm.c b/bak/adaptive_algorithm.c new file mode 100644 index 0000000..11a4e60 --- /dev/null +++ b/bak/adaptive_algorithm.c @@ -0,0 +1,100 @@ +#include "adaptive_algorithm.h" + +float CalculateMean(float value) +{ + value /= 1000.0f; + if(mean_count < MEAN_SIZE){ + mean_sum += value; + ++mean_count; + } + else{ + mean = mean_sum/MEAN_SIZE; + mean_count = 0; + mean_sum = 0; + + } + return (mean * 1000.0f); +} + +float CalculateRootMeanSquare(float value) +{ + value /= 1000.0f; + if(rms_count < RMS_SIZE){ + rms_sum += value * value; + ++rms_count; + } + else{ + rms = sqrt(rms_sum/RMS_SIZE); + rms_count = 0; + rms_sum = 0; + + } + return (rms * 1000.0f); +} + +float CalculateCoefficientOfVariation(float value) +{ + value /= 1000.0f; + if(cv_count < CV_SIZE){ + sd += (value - mean) * (value - mean); + ++cv_count; + } + else{ + sd = sqrt(sd / (CV_SIZE-1)); + cv = (sd / mean) * 100; + cv_count = 0; + sd = 0; + + } + return cv; +} + +void InitPeakDetect(float value,bool emi_first) +{ + if(!init_flag){ + current_max = value; + current_min = value; + is_detecting_emi = emi_first; + init_flag = true; + } +} + +SignalPoint PeakDetect(float value,int index,float gradient,bool *is_peak) +{ + if(value > current_max){ + max_point = index; + current_max = value; + } + if(value < current_min){ + min_point = index; + current_min = value; + } + + if(is_detecting_emi && value < (current_max - gradient) ){ + + is_detecting_emi = false; + + current_min = current_max; + min_point = max_point; + *is_peak = true; + peak.value = current_max; + peak.index = max_point; + return peak; + } + else if((!is_detecting_emi) && value > (current_min + gradient)) + { + + is_detecting_emi = true; + + current_max = current_min; + max_point = min_point; + *is_peak = false; + peak.value = current_min; + peak.index = min_point; + return peak; + } + + peak.index = -1; + return peak; +} + diff --git a/bak/adaptive_algorithm.h b/bak/adaptive_algorithm.h new file mode 100644 index 0000000..d1bbbc6 --- /dev/null +++ b/bak/adaptive_algorithm.h @@ -0,0 +1,41 @@ +#ifndef __ALGORITHM__ +#define __ALGORITHM__ + +#include +#include +#include +#include +#include +#include + +#include "QRS.h" +static const uint32_t MEAN_SIZE = SAMPLING_RATE; +static uint32_t mean_count; +static float mean_sum; +static float mean; + +static const uint32_t RMS_SIZE = SAMPLING_RATE; +static uint32_t rms_count; +static float rms_sum; +static float rms; + +static const uint32_t CV_SIZE = SAMPLING_RATE; +static uint32_t cv_count; +static float sd; +static float cv; + +static float current_max; +static float current_min; +static int max_point; +static int min_point; +static SignalPoint peak; +static bool is_detecting_emi; +static bool init_flag = false; + +extern float CalculateMean(float); +extern float CalculateRootMeanSquare(float); +extern float CalculateCoefficientOfVariation(float); +extern void InitPeakDetect(float,bool); +extern SignalPoint PeakDetect(float,int,float,bool*); + +#endif diff --git a/bak/qrs_time_domain_zh.c b/bak/qrs_time_domain_zh.c new file mode 100644 index 0000000..b42291e --- /dev/null +++ b/bak/qrs_time_domain_zh.c @@ -0,0 +1,231 @@ +#include "qrs_time_domain_zh.h" + +#include +#include +#include + +#define HEART_RATE_FILTER_SIZE 10 + +typedef struct { + uint16_t data[HEART_RATE_FILTER_SIZE]; + uint16_t data_process_buf[HEART_RATE_FILTER_SIZE]; + uint32_t cnt; + uint32_t index; +} HeartRateMedianFilter_t; // ÖÐÖµÂ˲¨Æ÷ + +typedef struct { + uint16_t data[HEART_RATE_FILTER_SIZE]; + uint32_t cnt; + uint32_t index; + uint32_t sum; +} HeartRateMeanFilter_t; // ¾ùÖµÂ˲¨Æ÷ + +HeartRateMedianFilter_t m_heart_rate_median_filter; +HeartRateMeanFilter_t m_heart_rate_mean_filter; + +static void HeartRateMedianFilter_reset() { + memset(m_heart_rate_median_filter.data, 0, sizeof(m_heart_rate_median_filter.data)); + m_heart_rate_median_filter.cnt = 0; + m_heart_rate_median_filter.index = 0; +} +static uint16_t HeartRateMedianFilter_process(uint16_t data) { + HeartRateMedianFilter_t* pfilter = &m_heart_rate_median_filter; + + pfilter->data[pfilter->index] = data; + pfilter->index++; + pfilter->cnt++; + if (pfilter->index >=HEART_RATE_FILTER_SIZE) { + pfilter->index = 0; + } + + if (pfilter->cnt data_process_buf, pfilter->data, HEART_RATE_FILTER_SIZE * sizeof(uint16_t)); + for (uint8_t i = 0; i < HEART_RATE_FILTER_SIZE; i++) { + for (uint8_t j = i + 1; j < HEART_RATE_FILTER_SIZE; j++) { + if (pfilter->data_process_buf[i] > pfilter->data_process_buf[j]) { + uint16_t temp = pfilter->data_process_buf[i]; + pfilter->data_process_buf[i] = pfilter->data_process_buf[j]; + pfilter->data_process_buf[j] = temp; + } + } + } + return pfilter->data_process_buf[2]; +} +static void HeartRateMeanFilter_reset() { + memset(m_heart_rate_mean_filter.data, 0, sizeof(m_heart_rate_mean_filter.data)); + m_heart_rate_mean_filter.cnt = 0; + m_heart_rate_mean_filter.index = 0; + m_heart_rate_mean_filter.sum = 0; +} +static uint16_t HeartRateMeanFilter_process(uint16_t data) { + HeartRateMeanFilter_t* pfilter = &m_heart_rate_mean_filter; + + pfilter->sum -= pfilter->data[pfilter->index]; + pfilter->data[pfilter->index] = data; + pfilter->sum += data; + + pfilter->index++; + pfilter->cnt++; + + if (pfilter->index >= HEART_RATE_FILTER_SIZE) { + pfilter->index = 0; + } + + if (pfilter->cnt < HEART_RATE_FILTER_SIZE) { + return data; + } + + return pfilter->sum / HEART_RATE_FILTER_SIZE; +} + +static uint16_t m_data[TABLE_SIZE]; +static uint32_t m_ndata = 0; +static uint32_t m_dataindex = 0; +static uint32_t m_data_cnt = 0; +static uint16_t m_heartrate = 0; + +static uint32_t m_datasum = 0; +static float m_avg = 0; +static uint32_t m_max_val_in_m_data; + +static bool m_findpeak = false; + +static uint16_t pQRS_median_filter_cache[HEART_RATE_FILTER_SIZE]; +static uint16_t pQRS_median_filter_cache_index = 0; +static uint16_t pQRS_median_filter_cache_cnt = 0; + +static uint32_t m_last_peak_pos = 0; +static uint32_t m_peakcnt = 0; + +static uint16_t pQRS_median_filter(uint16_t indata) { + // memcpy(pQRS_median_filter_cache + 1, pQRS_median_filter_cache, 4 * sizeof(uint16_t)); + pQRS_median_filter_cache[pQRS_median_filter_cache_index] = indata; + pQRS_median_filter_cache_index++; + pQRS_median_filter_cache_cnt++; + if (pQRS_median_filter_cache_index >= HEART_RATE_FILTER_SIZE) { + pQRS_median_filter_cache_index = 0; + } + + if (pQRS_median_filter_cache_cnt < HEART_RATE_FILTER_SIZE) { + return indata; + } + + static uint16_t process_cache[HEART_RATE_FILTER_SIZE]; + memcpy(process_cache, pQRS_median_filter_cache, HEART_RATE_FILTER_SIZE * sizeof(uint16_t)); + for (uint8_t i = 0; i < HEART_RATE_FILTER_SIZE; i++) { + for (uint8_t j = i + 1; j < HEART_RATE_FILTER_SIZE; j++) { + if (process_cache[i] > process_cache[j]) { + uint16_t temp = process_cache[i]; + process_cache[i] = process_cache[j]; + process_cache[j] = temp; + } + } + } + return process_cache[2]; +} + +static uint32_t pQRS_findMaxValue() { + uint32_t max_val = 0; + for (uint32_t i = 0; i < TABLE_SIZE; i++) { + if (m_data[i] > max_val) { + max_val = m_data[i]; + } + } + return max_val; +} + +void QRS_resetBuf() { // + m_ndata = 0; + m_dataindex = 0; + m_heartrate = 0; + m_data_cnt = 0; + memset(m_data, 0, sizeof(m_data)); + m_datasum = 0; + m_findpeak = false; + pQRS_median_filter_cache_index = 0; + pQRS_median_filter_cache_cnt = 0; + m_peakcnt = 0; + + HeartRateMedianFilter_reset(); + HeartRateMeanFilter_reset(); +} + +void QRS_processData(uint16_t _data) { + uint16_t data = pQRS_median_filter(_data); + /******************************************************************************* + * Ìî³äBUF * + *******************************************************************************/ + m_datasum -= m_data[m_dataindex]; + m_data[m_dataindex] = data; + m_datasum += data; + + m_data_cnt++; + + if (m_dataindex < TABLE_SIZE) { + m_dataindex++; + } else { + m_dataindex = 0; + } + + m_ndata++; + if (m_ndata > TABLE_SIZE) { + m_ndata = TABLE_SIZE; + } + + /******************************************************************************* + * ÇóBUFµÄƽ¾ùÖµºÍ×î´óÖµ * + *******************************************************************************/ + if (m_ndata == TABLE_SIZE) { + m_avg = (float)m_datasum / m_ndata; + m_max_val_in_m_data = pQRS_findMaxValue(); + } + + /******************************************************************************* + * ѰÕÒQRS²¨·åºÍ²¨¹È * + *******************************************************************************/ + + if (!m_findpeak) { + uint16_t thresholdValue = (m_max_val_in_m_data - m_avg) * 0.666 + m_avg; + if (data > thresholdValue) { + m_findpeak = true; + m_peakcnt++; + + if (m_last_peak_pos != 0) { + uint16_t diff_peak_pos = m_data_cnt - m_last_peak_pos; + if (diff_peak_pos > 0) { + // + // m_heartrate = 60 * 500 / diff_peak_pos; + + uint16_t diff_peak_ms = diff_peak_pos * 2; // 500Hz + uint16_t heart_rate = 60 * 1000 / diff_peak_ms; + + m_heartrate = HeartRateMeanFilter_process(HeartRateMedianFilter_process(heart_rate)); + } + } + + m_last_peak_pos = m_data_cnt; + } + } else { + if (data < m_avg) { + m_findpeak = false; + } + } +} +uint16_t QRS_getHeartRate() { + __disable_fiq(); + uint16_t heartrate = m_heartrate; + __enable_fiq(); + + if (heartrate > 200) return 0; + if (heartrate < 55) return 0; + return heartrate; +} + +uint16_t QRS_getMaxValueLastVal() { return m_max_val_in_m_data; } + +uint16_t QRS_getAvgValueVal() { // + return m_avg; +} diff --git a/bak/qrs_time_domain_zh.h b/bak/qrs_time_domain_zh.h new file mode 100644 index 0000000..56f1a65 --- /dev/null +++ b/bak/qrs_time_domain_zh.h @@ -0,0 +1,19 @@ +/** + * @file qrs_time_domain_zh.h + * @author zhaohe (zhaohe@domain.com) + * @brief + * @version 0.1 + * @date 2024-02-10 + * + * @copyright Copyright (c) 2024 + * + */ +#pragma once +#include +#define TABLE_SIZE 1000 + +void QRS_resetBuf(); +void QRS_processData(uint16_t data); +uint16_t QRS_getHeartRate(); +uint16_t QRS_getMaxValueLastVal(); +uint16_t QRS_getAvgValueVal(); diff --git a/libznordic b/libznordic index c7adce2..6000f28 160000 --- a/libznordic +++ b/libznordic @@ -1 +1 @@ -Subproject commit c7adce2fba7f404c4076a440b520b733c70df89c +Subproject commit 6000f285863c7979f08800f2aa6de8db96c99df4 diff --git a/sdk b/sdk index 5d4b797..1d34e6a 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 5d4b7977455415a88f3a8bd62dc4213f1edc0b37 +Subproject commit 1d34e6ac316c27dc0e1149835d5f1ad53e074c88