From 0db5ed0103a629792b16349a6a7969aa80b2d643 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 6 May 2024 16:05:15 +0800 Subject: [PATCH] recode --- app/app.uvoptx | 210 +- app/app.uvprojx | 190 +- app/src/_board/ads129x/ads129x.c | 294 +++ app/src/_board/ads129x/ads129x.h | 54 + app/src/_board/ads129x/ads129x_type.h | 286 +++ app/src/_board/board_battery_state.c | 100 + app/src/_board/board_battery_state.h | 21 + app/src/_board/board_eeprom_driver.c | 133 ++ app/src/_board/board_eeprom_driver.h | 20 + app/src/_board/board_light_ctrl.c | 213 ++ app/src/_board/board_light_ctrl.h | 31 + app/src/_board/board_power_mgr.c | 18 + app/src/_board/board_power_mgr.h | 12 + app/src/_board/board_ssd1306_interface.c | 98 + app/src/_board/board_ssd1306_interface.h | 15 + app/src/_board/soc_public_res_mgr.c | 0 app/src/_board/soc_public_res_mgr.h | 1 + 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/app_basic_service/basic/event.h | 4 +- app/src/app_service/battery_mgr_service.c | 2 +- app/src/app_service/beep_ctrl.c | 24 +- .../display_ctrl_service/display_manager.bak.c | 443 ---- .../display_ctrl_service/display_manager.bak.h | 81 - .../app_service/display_ctrl_service/display_mgr.c | 26 +- app/src/app_service/display_ctrl_service/font.h | 1 + .../display_ctrl_service/ssd1306/driver_ssd1306.c | 2 +- .../ssd1306/driver_ssd1306_basic.c | 8 +- .../ecg_service/algo/ecg_data_analyszer.c | 4 +- .../ecg_service/algo/iflytop_simple_filter.c | 10 +- app/src/app_service/ecg_service/ecg_data_mgr.c | 1 + app/src/app_service/ecg_service/ecg_service.c | 51 +- app/src/app_service/ecg_service/ecg_service.h | 3 + app/src/app_service/light_ctrl.c | 2 +- app/src/board/ads129x/ads129x.c | 294 --- app/src/board/ads129x/ads129x.h | 54 - app/src/board/ads129x/ads129x_type.h | 286 --- app/src/board/board_battery_state.c | 100 - app/src/board/board_battery_state.h | 21 - app/src/board/board_eeprom_driver.c | 133 -- app/src/board/board_eeprom_driver.h | 20 - app/src/board/board_light_ctrl.c | 213 -- app/src/board/board_light_ctrl.h | 31 - app/src/board/board_power_mgr.c | 18 - app/src/board/board_power_mgr.h | 12 - app/src/board/board_ssd1306_interface.c | 98 - app/src/board/board_ssd1306_interface.h | 15 - app/src/board/soc_public_res_mgr.c | 0 app/src/board/soc_public_res_mgr.h | 1 - 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/one_conduction_main.c | 6 +- 68 files changed, 7012 insertions(+), 7182 deletions(-) create mode 100644 app/src/_board/ads129x/ads129x.c create mode 100644 app/src/_board/ads129x/ads129x.h create mode 100644 app/src/_board/ads129x/ads129x_type.h create mode 100644 app/src/_board/board_battery_state.c create mode 100644 app/src/_board/board_battery_state.h create mode 100644 app/src/_board/board_eeprom_driver.c create mode 100644 app/src/_board/board_eeprom_driver.h create mode 100644 app/src/_board/board_light_ctrl.c create mode 100644 app/src/_board/board_light_ctrl.h create mode 100644 app/src/_board/board_power_mgr.c create mode 100644 app/src/_board/board_power_mgr.h create mode 100644 app/src/_board/board_ssd1306_interface.c create mode 100644 app/src/_board/board_ssd1306_interface.h create mode 100644 app/src/_board/soc_public_res_mgr.c create mode 100644 app/src/_board/soc_public_res_mgr.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/app_service/display_ctrl_service/display_manager.bak.c delete mode 100644 app/src/app_service/display_ctrl_service/display_manager.bak.h delete mode 100644 app/src/board/ads129x/ads129x.c delete mode 100644 app/src/board/ads129x/ads129x.h delete mode 100644 app/src/board/ads129x/ads129x_type.h delete mode 100644 app/src/board/board_battery_state.c delete mode 100644 app/src/board/board_battery_state.h delete mode 100644 app/src/board/board_eeprom_driver.c delete mode 100644 app/src/board/board_eeprom_driver.h delete mode 100644 app/src/board/board_light_ctrl.c delete mode 100644 app/src/board/board_light_ctrl.h delete mode 100644 app/src/board/board_power_mgr.c delete mode 100644 app/src/board/board_power_mgr.h delete mode 100644 app/src/board/board_ssd1306_interface.c delete mode 100644 app/src/board/board_ssd1306_interface.h delete mode 100644 app/src/board/soc_public_res_mgr.c delete mode 100644 app/src/board/soc_public_res_mgr.h delete mode 100644 app/src/board/ssd1306/driver_ssd1306.c delete mode 100644 app/src/board/ssd1306/driver_ssd1306.h delete mode 100644 app/src/board/ssd1306/driver_ssd1306_basic.c delete mode 100644 app/src/board/ssd1306/driver_ssd1306_basic.h delete mode 100644 app/src/board/ssd1306/driver_ssd1306_font.h delete mode 100644 app/src/board/ssd1306/driver_ssd1306_interface.h delete mode 100644 app/src/board/ssd1306/fontlib.c delete mode 100644 app/src/board/ssd1306/fontlib.h delete mode 100644 app/src/board/ssd1306/wave_drawer.c delete mode 100644 app/src/board/ssd1306/wave_drawer.h diff --git a/app/app.uvoptx b/app/app.uvoptx index 24dc30d..8ef17b0 100644 --- a/app/app.uvoptx +++ b/app/app.uvoptx @@ -386,8 +386,8 @@ 0 0 0 - .\src\one_conduction_main.c - one_conduction_main.c + .\src\main.c + main.c 0 0 @@ -398,8 +398,8 @@ 0 0 0 - .\src\main.c - main.c + .\src\one_conduction_main.c + one_conduction_main.c 0 0 @@ -410,8 +410,8 @@ 0 0 0 - .\src\app_basic_service\device_version_info_mgr.c - device_version_info_mgr.c + .\src\app_basic_service\zapp.c + zapp.c 0 0 @@ -422,8 +422,8 @@ 0 0 0 - .\src\app_basic_service\zapp.c - zapp.c + .\src\app_basic_service\device_version_info_mgr.c + device_version_info_mgr.c 0 0 @@ -431,7 +431,7 @@ Board Definition - 0 + 1 0 0 0 @@ -627,7 +627,7 @@ nRF_Drivers - 0 + 1 0 0 0 @@ -875,7 +875,7 @@ nRF_Libraries - 0 + 1 0 0 0 @@ -1530,8 +1530,8 @@ 0 0 0 - .\src\app_service\adc_mgr.c - adc_mgr.c + .\src\app_service\ecg_service\ecg_service.c + ecg_service.c 0 0 @@ -1542,8 +1542,188 @@ 0 0 0 - .\src\app_service\ecg_service\ecg_service.c - ecg_service.c + .\src\app_service\base_hardware\adc_mgr.c + adc_mgr.c + 0 + 0 + + + 15 + 90 + 1 + 0 + 0 + 0 + .\src\app_service\base_hardware\hardware_power_mgr.c + hardware_power_mgr.c + 0 + 0 + + + 15 + 91 + 1 + 0 + 0 + 0 + .\src\app_service\beep_ctrl.c + beep_ctrl.c + 0 + 0 + + + 15 + 92 + 1 + 0 + 0 + 0 + .\src\app_service\light_ctrl.c + light_ctrl.c + 0 + 0 + + + 15 + 93 + 1 + 0 + 0 + 0 + .\src\app_service\display_ctrl_service\display_mgr.c + display_mgr.c + 0 + 0 + + + 15 + 94 + 1 + 0 + 0 + 0 + .\src\app_service\display_ctrl_service\ssd1306_if_impl.c + ssd1306_if_impl.c + 0 + 0 + + + 15 + 95 + 1 + 0 + 0 + 0 + .\src\app_service\display_ctrl_service\ssd1306\driver_ssd1306.c + driver_ssd1306.c + 0 + 0 + + + 15 + 96 + 1 + 0 + 0 + 0 + .\src\app_service\display_ctrl_service\ssd1306\driver_ssd1306_basic.c + driver_ssd1306_basic.c + 0 + 0 + + + 15 + 97 + 1 + 0 + 0 + 0 + .\src\app_service\display_ctrl_service\ssd1306\fontlib.c + fontlib.c + 0 + 0 + + + 15 + 98 + 1 + 0 + 0 + 0 + .\src\app_service\display_ctrl_service\ssd1306\wave_drawer.c + wave_drawer.c + 0 + 0 + + + 15 + 99 + 1 + 0 + 0 + 0 + .\src\app_service\ecg_service\ecg_algo.c + ecg_algo.c + 0 + 0 + + + 15 + 100 + 1 + 0 + 0 + 0 + .\src\app_service\ecg_service\ecg_data_mgr.c + ecg_data_mgr.c + 0 + 0 + + + 15 + 101 + 1 + 0 + 0 + 0 + .\src\app_service\ecg_service\algo\ecg_data_analyszer.c + ecg_data_analyszer.c + 0 + 0 + + + 15 + 102 + 1 + 0 + 0 + 0 + .\src\app_service\ecg_service\algo\iflytop_simple_filter.c + iflytop_simple_filter.c + 0 + 0 + + + 15 + 103 + 1 + 0 + 0 + 0 + .\src\app_service\ecg_service\algo\iflytop_simple_filter_ext.c + iflytop_simple_filter_ext.c + 0 + 0 + + + 15 + 104 + 1 + 0 + 0 + 0 + .\src\app_service\ecg_service\algo\iflytop_simple_qrs.c + iflytop_simple_qrs.c 0 0 diff --git a/app/app.uvprojx b/app/app.uvprojx index 0da6b8d..5d84d0e 100644 --- a/app/app.uvprojx +++ b/app/app.uvprojx @@ -389,25 +389,25 @@ .\config\sdk_config.h - one_conduction_main.c - 1 - .\src\one_conduction_main.c - - main.c 1 .\src\main.c - device_version_info_mgr.c + one_conduction_main.c 1 - .\src\app_basic_service\device_version_info_mgr.c + .\src\one_conduction_main.c zapp.c 1 .\src\app_basic_service\zapp.c + + device_version_info_mgr.c + 1 + .\src\app_basic_service\device_version_info_mgr.c + @@ -3796,14 +3796,89 @@ .\src\app_service\battery_mgr_service.c + ecg_service.c + 1 + .\src\app_service\ecg_service\ecg_service.c + + adc_mgr.c 1 - .\src\app_service\adc_mgr.c + .\src\app_service\base_hardware\adc_mgr.c - ecg_service.c + hardware_power_mgr.c 1 - .\src\app_service\ecg_service\ecg_service.c + .\src\app_service\base_hardware\hardware_power_mgr.c + + + beep_ctrl.c + 1 + .\src\app_service\beep_ctrl.c + + + light_ctrl.c + 1 + .\src\app_service\light_ctrl.c + + + display_mgr.c + 1 + .\src\app_service\display_ctrl_service\display_mgr.c + + + ssd1306_if_impl.c + 1 + .\src\app_service\display_ctrl_service\ssd1306_if_impl.c + + + driver_ssd1306.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\driver_ssd1306.c + + + driver_ssd1306_basic.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\driver_ssd1306_basic.c + + + fontlib.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\fontlib.c + + + wave_drawer.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\wave_drawer.c + + + ecg_algo.c + 1 + .\src\app_service\ecg_service\ecg_algo.c + + + ecg_data_mgr.c + 1 + .\src\app_service\ecg_service\ecg_data_mgr.c + + + ecg_data_analyszer.c + 1 + .\src\app_service\ecg_service\algo\ecg_data_analyszer.c + + + iflytop_simple_filter.c + 1 + .\src\app_service\ecg_service\algo\iflytop_simple_filter.c + + + iflytop_simple_filter_ext.c + 1 + .\src\app_service\ecg_service\algo\iflytop_simple_filter_ext.c + + + iflytop_simple_qrs.c + 1 + .\src\app_service\ecg_service\algo\iflytop_simple_qrs.c @@ -4198,25 +4273,25 @@ .\config\sdk_config.h - one_conduction_main.c - 1 - .\src\one_conduction_main.c - - main.c 1 .\src\main.c - device_version_info_mgr.c + one_conduction_main.c 1 - .\src\app_basic_service\device_version_info_mgr.c + .\src\one_conduction_main.c zapp.c 1 .\src\app_basic_service\zapp.c + + device_version_info_mgr.c + 1 + .\src\app_basic_service\device_version_info_mgr.c + @@ -7605,14 +7680,89 @@ .\src\app_service\battery_mgr_service.c + ecg_service.c + 1 + .\src\app_service\ecg_service\ecg_service.c + + adc_mgr.c 1 - .\src\app_service\adc_mgr.c + .\src\app_service\base_hardware\adc_mgr.c - ecg_service.c + hardware_power_mgr.c 1 - .\src\app_service\ecg_service\ecg_service.c + .\src\app_service\base_hardware\hardware_power_mgr.c + + + beep_ctrl.c + 1 + .\src\app_service\beep_ctrl.c + + + light_ctrl.c + 1 + .\src\app_service\light_ctrl.c + + + display_mgr.c + 1 + .\src\app_service\display_ctrl_service\display_mgr.c + + + ssd1306_if_impl.c + 1 + .\src\app_service\display_ctrl_service\ssd1306_if_impl.c + + + driver_ssd1306.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\driver_ssd1306.c + + + driver_ssd1306_basic.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\driver_ssd1306_basic.c + + + fontlib.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\fontlib.c + + + wave_drawer.c + 1 + .\src\app_service\display_ctrl_service\ssd1306\wave_drawer.c + + + ecg_algo.c + 1 + .\src\app_service\ecg_service\ecg_algo.c + + + ecg_data_mgr.c + 1 + .\src\app_service\ecg_service\ecg_data_mgr.c + + + ecg_data_analyszer.c + 1 + .\src\app_service\ecg_service\algo\ecg_data_analyszer.c + + + iflytop_simple_filter.c + 1 + .\src\app_service\ecg_service\algo\iflytop_simple_filter.c + + + iflytop_simple_filter_ext.c + 1 + .\src\app_service\ecg_service\algo\iflytop_simple_filter_ext.c + + + iflytop_simple_qrs.c + 1 + .\src\app_service\ecg_service\algo\iflytop_simple_qrs.c diff --git a/app/src/_board/ads129x/ads129x.c b/app/src/_board/ads129x/ads129x.c new file mode 100644 index 0000000..a0d613a --- /dev/null +++ b/app/src/_board/ads129x/ads129x.c @@ -0,0 +1,294 @@ +#include "ads129x.h" + +#include "ads129x_type.h" +#include "nrf_drv_gpiote.h" +#include "znordic.h" + +/** + * @brief ads129x 使用注意事项 + * + * ads129x SPI 通信格式 + * + * [cmd 8bit] [data nbit] + * + * + * ads129x 支持的指令如下 + * 唤醒 (0x02) + * 待机 (0x04) + * 复位 (0x06) + * 开始转换 (0x08) + * 停止 (0x0A) + * 通道偏移校准 (0x1A) + * 使能数据连续读模式 (0x10) + * 停止数据连续读模式 (0x11) + * 读数据 (0x12) + * 读寄存器 (0x2x) + * 写寄存器 (0x4x) + * + * + * 注意事项: + * 1. 当ads129x处于连续读模式下,寄存器读写指令失效 + * 2. 不进入连续模式下,可以通过[读数据]指令,读取数据,此时寄存器操作指令是有效的 + * + */ + +static ads129x_cfg_t* ads129x_cfg; + +#define ADS129X_CS_SET() nrf_gpio_pin_set(ads129x_cfg->cspin); +#define ADS129X_CS_RESET() nrf_gpio_pin_clear(ads129x_cfg->cspin); +#define ADS129X_START_SET() nrf_gpio_pin_set(ads129x_cfg->startpin); +#define ADS129X_START_RESET() nrf_gpio_pin_clear(ads129x_cfg->startpin); +#define ADS129X_REST_SET() nrf_gpio_pin_set(ads129x_cfg->pwdnpin); +#define ADS129X_REST_RESET() nrf_gpio_pin_clear(ads129x_cfg->pwdnpin); +#define ADS129X_DRDY_GET() nrf_gpio_pin_read(ads129x_cfg->drdypin) + +static void port_ads129x_delay_us(uint32_t us) { nrf_delay_us(us); } +static void port_ads129x_delay_ms(uint32_t ms) { nrf_delay_ms(ms); } + +#define port_delay_ms port_ads129x_delay_ms + +/*********************************************************************************************************************** + * BASE_FUNCTION_IMPL * + ***********************************************************************************************************************/ + +uint8_t port_spi_transmit_receive(uint8_t tx) { + uint8_t data; + nrf_drv_spi_transfer(ads129x_cfg->spi, &tx, 1, &data, 1); + return data; +} + +/* ads129X发送指令 */ +uint8_t ads129x_send_cmd(uint8_t cmd) { + uint8_t rx = 0; + + ADS129X_CS_RESET(); /* 选中设备 */ + port_ads129x_delay_us(100); + + rx = port_spi_transmit_receive(cmd); + + port_ads129x_delay_us(100); + ADS129X_CS_SET(); /* 释放设备 */ + + return rx; +} + +/* ads129X读写寄存器,自动根据指令类型区分读和写操作 */ +uint8_t ads129x_rw_reg(uint8_t cmd, uint8_t data) { + uint8_t rx = 0; + + ADS129X_CS_RESET(); /* 选中设备 */ + port_ads129x_delay_us(1); + + port_spi_transmit_receive(cmd); /* 发送读写指令 */ + port_spi_transmit_receive(0X00); /* 只写一个数据 */ + + if ((cmd & ADS129X_COMMAND_RREG) == ADS129X_COMMAND_RREG) /* 判断指令类型 */ + rx = port_spi_transmit_receive(0X00); /* 返回寄存器值 */ + else + rx = port_spi_transmit_receive(data); /* 写入数值 */ + + port_ads129x_delay_us(1); + ADS129X_CS_SET(); /* 释放设备 */ + + return rx; +} + +/* 从指定寄存器开始读写一定数量的寄存器 */ +void ads129X_write_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { + uint8_t i; + + ADS129X_CS_RESET(); /* 选中设备 */ + port_ads129x_delay_us(100); + + port_spi_transmit_receive(ADS129X_COMMAND_WREG | reg); + port_ads129x_delay_us(100); + port_spi_transmit_receive(size - 1); + + for (i = 0; i < size; i++) { + port_ads129x_delay_us(100); + port_spi_transmit_receive(*ch); + ch++; + } + + port_ads129x_delay_us(100); + ADS129X_CS_SET(); +} + +/* 从指定寄存器开始读写一定数量的寄存器 */ +void ads129X_read_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { + uint8_t i; + + ADS129X_CS_RESET(); /* 选中设备 */ + port_ads129x_delay_us(100); + + port_spi_transmit_receive(ADS129X_COMMAND_RREG | reg); + port_ads129x_delay_us(100); + port_spi_transmit_receive(size - 1); + + for (i = 0; i < size; i++) { + port_ads129x_delay_us(100); + *ch = port_spi_transmit_receive(0); + ch++; + } + + port_ads129x_delay_us(100); + ADS129X_CS_SET(); +} + +static void ads129x_readback_regs(ads129x_regs_t* regcache) { ads129X_read_multiregs(ADS129X_REG_ID, (uint8_t*)regcache, sizeof(ads129x_regs_t)); } +static void ads129x_dump_regs(ads129x_regs_t* regcache) { + ZLOGI("id : %x", regcache->id); + ZLOGI("cfg1 : %x", regcache->cfg1); + ZLOGI("cfg2 : %x", regcache->cfg2); + ZLOGI("loff : %x", regcache->loff); + ZLOGI("ch1set : %x", regcache->ch1set); + ZLOGI("ch2set : %x", regcache->ch2set); + ZLOGI("rld_sens : %x", regcache->rld_sens); + ZLOGI("loff_sens : %x", regcache->loff_sens); + ZLOGI("loff_stat : %x", regcache->loff_stat); + ZLOGI("resp1 : %x", regcache->resp1); + ZLOGI("resp2 : %x", regcache->resp2); + ZLOGI("gpio : %x", regcache->gpio); +} + +static bool ads129x_write_regs(ads129x_regs_t* writeval) { + static ads129x_regs_t rdbak; + ads129X_write_multiregs(ADS129X_REG_ID, (uint8_t*)writeval, sizeof(ads129x_regs_t)); + ads129X_read_multiregs(ADS129X_REG_ID, (uint8_t*)&rdbak, sizeof(ads129x_regs_t)); + + writeval->id = 0; + writeval->loff_stat = writeval->loff_stat & (0x01 << 6); + + rdbak.id = 0; + rdbak.loff_stat = rdbak.loff_stat & (0x01 << 6); + + if (memcmp(writeval, &rdbak, sizeof(ads129x_regs_t)) != 0) { + ZLOGE("ads129x_write_reg reg fail"); + return false; + } + ZLOGI("ads129x_write_reg reg success"); + return true; +} + +/*********************************************************************************************************************** + * EXTERN * + ***********************************************************************************************************************/ +void ads129x_read_data_loop() { + // app_timer_pause(); + + // ads129x_capture_data_t capture_data; + // while (true) { + // ads129x_read_data(&capture_data); + // ZLOGI("%d {%d} %x", ADS129X_DRDY_GET(), capture_data.ch1data, capture_data.loffstate); + // znordic_force_flush_log(); + // } +} + +uint8_t ads129x_init(ads129x_cfg_t* cfg) { + /** + * @brief + */ + ads129x_cfg = cfg; + ZASSERT(nrfx_gpiote_is_init()); + + ADS129X_CS_SET(); + + ADS129X_REST_RESET(); + ADS129X_START_RESET(); + port_ads129x_delay_ms(1000); + ADS129X_REST_SET(); + port_ads129x_delay_ms(100); /* 硬件复位 */ + + ads129x_send_cmd(ADS129X_COMMAND_SDATAC); /* 软件复位,并停止连续读状态 */ + port_ads129x_delay_ms(100); + ads129x_send_cmd(ADS129X_COMMAND_RESET); + port_ads129x_delay_ms(1000); + ads129x_send_cmd(ADS129X_COMMAND_SDATAC); + port_ads129x_delay_ms(100); + + static ads129x_regs_t regcache; + ads129x_readback_regs(®cache); + ads129x_dump_regs(®cache); + regcache.cfg1 = 0x02; + regcache.cfg2 = 0xE0; + regcache.loff = 0xF0; + regcache.ch1set = 0x00; + regcache.ch2set = 0x00; + regcache.rld_sens = 0x20; + regcache.loff_sens = 0x03; + ads129x_write_regs(®cache); + + nrf_gpio_pin_set(ads129x_cfg->pwdnpin); + return 0; +} + +uint8_t ads129x_read_reg(uint8_t add) { return ads129x_rw_reg(ADS129X_COMMAND_RREG | add, 0); } + +void ads129x_write_reg(uint8_t add, uint8_t data) { + ZLOGI("ads129x_write_reg %x %x", add, data); + static ads129x_regs_t regcache; + ads129x_readback_regs(®cache); + uint8_t* reg = (uint8_t*)®cache; + reg[add] = data; + ads129x_write_regs(®cache); +} + +uint8_t ads129x_start_capture() { + ads129x_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ + return 0; +} + +uint8_t ads129x_stop_capture() { + ads129x_send_cmd(ADS129X_COMMAND_STOP); /* 发送停止数据转换(等效于拉低START引脚) */ + return 0; +} + +static int32_t i24toi32(uint8_t* p_i32) { + int32_t rev = 0; + rev = (((int32_t)p_i32[0]) << 16) | (((int32_t)p_i32[1]) << 8) | ((int32_t)p_i32[2]); + if ((p_i32[0] & 0x80) == 0x80) { + rev |= 0xFF000000; + } + return rev; +} + +void ads129x_read_data(ads129x_capture_data_t* capture_data) { + uint8_t rddata[9]; + + ADS129X_CS_RESET(); /* 选中设备 */ + port_ads129x_delay_us(10); + + port_spi_transmit_receive(ADS129X_COMMAND_RDATA); + port_ads129x_delay_us(1); + for (int i = 0; i < 9; i++) { + rddata[i] = port_spi_transmit_receive(0); + } + ADS129X_CS_SET(); + + /** + * @brief + * + * 回读数据格式(datasheet page 42) + * 24bit status (1100 + LOFF_STAT[4:0] + GPIO[1:0] + 13`b0) + * 24bit ch0 MSB + * 24bit ch1 MSB + * + */ + uint32_t status = (((uint32_t)rddata[0]) << 16) | (((uint32_t)rddata[1]) << 8) | ((uint32_t)rddata[2]); + + capture_data->loffstate = (status >> (13 + 2)) & 0x1f; + capture_data->gpio0 = status >> (14); + capture_data->gpio1 = status >> (13); + + capture_data->ch1data = i24toi32(&rddata[3]); + capture_data->ch2data = i24toi32(&rddata[6]); +} + +uint8_t ads129x_get_lead_off_state() { + // FLIP2,FLIP1,LOFF2N,LOFF2P,LOFF1N,LOFF1P + uint8_t leadoffstate = ads129x_read_reg(ADS129X_REG_LOFFSTAT); + return leadoffstate; +} + +uint8_t ads129x_enter_low_power_mode() { return 0; } +uint8_t ads129x_enter_lead_off_detect_mode() { return 0; } diff --git a/app/src/_board/ads129x/ads129x.h b/app/src/_board/ads129x/ads129x.h new file mode 100644 index 0000000..202ac06 --- /dev/null +++ b/app/src/_board/ads129x/ads129x.h @@ -0,0 +1,54 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + +#include "znordic.h" +typedef struct { + /** + * @brief + * + * loffstate:[4:0] RLD_STAT IN2N_OFF IN2P_OFF IN1N_OFF IN1P_OFF + * ch1data: 有符号数据 + * ch2data: 有符号数据 + */ + + uint8_t loffstate; + + uint8_t gpio0; + uint8_t gpio1; + + uint32_t ch1data; + uint32_t ch2data; +} ads129x_capture_data_t; + +typedef struct { + nrf_drv_spi_t* spi; + uint32_t cspin; + uint32_t startpin; + uint32_t drdypin; + uint32_t pwdnpin; +} ads129x_cfg_t; + +/** + * @brief 初始化SPI + */ +uint8_t ads129x_init(ads129x_cfg_t* cfg); + +// uint8_t ads129x_start_capture(bool test); +uint8_t ads129x_stop_capture(); +uint8_t ads129x_start_capture(); + +void ads129x_write_reg(uint8_t addr, uint8_t val); +uint8_t ads129x_read_reg(uint8_t addr); + +void ads129x_read_data(ads129x_capture_data_t* rddata); + +uint8_t ads129x_get_lead_off_state(); + +#ifdef __cplusplus +} +#endif diff --git a/app/src/_board/ads129x/ads129x_type.h b/app/src/_board/ads129x/ads129x_type.h new file mode 100644 index 0000000..d3a5cf6 --- /dev/null +++ b/app/src/_board/ads129x/ads129x_type.h @@ -0,0 +1,286 @@ +#pragma once +#include +#ifdef __cplusplus +extern "C" { +#endif +typedef enum { + ADS129X_REG_ID = 0x00, + ADS129X_REG_CONFIG1 = 0x01, + ADS129X_REG_CONFIG2 = 0x02, + ADS129X_REG_LOFF = 0x03, + ADS129X_REG_CH1SET = 0x04, + ADS129X_REG_CH2SET = 0x05, + ADS129X_REG_RLDSENS = 0x06, + ADS129X_REG_LOFFSENS = 0x07, + ADS129X_REG_LOFFSTAT = 0x08, + ADS129X_REG_RESP1 = 0x09, + ADS129X_REG_RESP2 = 0x0A, + ADS129X_REG_GPIO = 0x0B +} ADS129X_REG_E; + +typedef struct { + uint8_t id; /* id,ads1292r固定为0x73 */ + 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的控制 */ +} ads129x_regs_t; + +#define ADS129X_REG_SIZE_MAX 12 /* ADS1291寄存器数量 */ +#define ADS129X_ID 0x52 + +/* 属于ADS129X_REG_CONFIG1的寄存器设置 */ +#define ADS129X_SINGLE_SHOT_OFF 0 /* 连续转换模式,默认 */ +#define ADS129X_SINGLE_SHOT_ON 1 /* 单次转换模式 */ +/* 采样率,该模块采用fclk为512k,0分频模式,其他配置下采样率会改变 */ +#define ADS129X_OVERSAMPLING_125SPS 0 +#define ADS129X_OVERSAMPLING_250SPS 1 +#define ADS129X_OVERSAMPLING_500SPS 2 /* 默认 */ +#define ADS129X_OVERSAMPLING_1000SPS 3 +#define ADS129X_OVERSAMPLING_2000SPS 4 +#define ADS129X_OVERSAMPLING_4000SPS 5 +#define ADS129X_OVERSAMPLING_8000SPS 6 +#define ADS129X_OVERSAMPLING_NONESPS 7 + +/* 属于ADS129X_REG_CONFIG2的寄存器设置 */ +#define ADS129X_PDB_LOFF_COMP_OFF 0 /* 导联脱落比较器关,默认 */ +#define ADS129X_PDB_LOFF_COMP_ON 1 /* 导联脱落比较器开 */ +#define ADS129X_PDB_REFBUF_OFF 0 /* 内部参考电压关,默认 */ +#define ADS129X_PDB_REFBUF_ON 1 /* 内部参考电压开 */ +#define ADS129X_VREF_2420MV 0 /* 选择参考电压为2.42v,默认 */ +#define ADS129X_VREF_4033MV 1 /* 选择参考电压为4.033v */ +#define ADS129X_CLK_OUTPUT_OFF 0 /* 时钟输出关,默认 */ +#define ADS129X_CLK_OUTPUT_ON 1 /* 时钟输出开 */ +#define ADS129X_INT_TEST_OFF 0 /* 内部测试电压关,默认 */ +#define ADS129X_INT_TEST_ON 1 /* 内部测试电压开 */ +#define ADS129X_INT_FREQ_DC 0 /* 直流,默认 */ +#define ADS129X_INT_FREQ_AC 1 /* 1HZ方波 */ + +/* 属于ADS129X_REG_LOFF的寄存器设置 */ + +/* 属于ADS129X_REG_CH1SET,与ADS129X_REG_CH2SET的寄存器设置 */ +#define ADS129X_CHx_OFF 1 /* 禁止使用通道一 */ +#define ADS129X_CHx_ON 0 /* 使用通道一,默认 */ + +#define ADS129X_GAIN_6 0 /* 使用通道一6倍增益,默认 */ +#define ADS129X_GAIN_1 1 /* 使用通道一1倍增益 */ +#define ADS129X_GAIN_2 2 /* 使用通道一2倍增益 */ +#define ADS129X_GAIN_3 3 /* 使用通道一3倍增益 */ +#define ADS129X_GAIN_4 4 /* 使用通道一4倍增益 */ +#define ADS129X_GAIN_8 5 /* 使用通道一8倍增益 */ +#define ADS129X_GAIN_12 6 /* 使用通道一12倍增益 */ +/* 选择通道一的输入 */ +#define ADS129X_CHx_INPUT_NORMAL 0 /* 正常电极输入,默认 */ +#define ADS129X_CHx_INPUT_SHORTED 1 /* 短路,测偏执用 */ +#define ADS129X_CHx_INPUT_RLD 2 /* 右腿驱动 */ +/* For channel 1, (MVDDP – MVDDN) is [0.5(AVDD + AVSS)]; for channel 2, (MVDDP – MVDDN) is DVDD / 4. */ +/* For channel 2,VDD / 2 for supply measurement */ +#define ADS129X_CHx_INPUT_MVDD 3 +#define ADS129X_CHx_INPUT_TEMP 4 /* 板载温度 */ +#define ADS129X_CHx_INPUT_TEST 5 /* 内部测试信号 */ +#define ADS129X_CHx_INPUT_RLDDRP 6 +#define ADS129X_CHx_INPUT_RLDDRM 7 +#define ADS129X_CHx_INPUT_RLDDRPM 8 +#define ADS129X_CHx_INPUT_ROUTE 9 /* 连接到通道三 */ +#define ADS129X_CHx_INPUT_RESERVED 10 /* 预留 */ + +/* 属于ADS129X_REG_RLDSENS的寄存器设置 */ +#define ADS129X_CHOP_FREQ_DIV4 3 /* PGA斩波频率未fMOD/4 */ +#define ADS129X_PDB_RLD_OFF 0 /* 右腿驱动电源关,默认 */ +#define ADS129X_PDB_RLD_ON 1 /* 右腿驱动电源开 */ +#define ADS129X_PDB_RLD_SENSE_OFF 0 /* 右腿驱动导联脱落检测关,默认 */ +#define ADS129X_PDB_RLD_SENSE_ON 1 /* 右腿驱动导联脱落检测开 */ +#define ADS129X_RLD2N_OFF 0 /* 通道二负极为右腿输入关,默认 */ +#define ADS129X_RLD2N_ON 1 /* 通道二负极为右腿输入开 */ +#define ADS129X_RLD2P_OFF 0 /* 通道二正极为右腿输入关,默认 */ +#define ADS129X_RLD2P_ON 1 /* 通道二正极为右腿输入开 */ +#define ADS129X_RLD1N_OFF 0 /* 通道一负极为右腿输入关,默认 */ +#define ADS129X_RLD1N_ON 1 /* 通道一负极为右腿输入开 */ +#define ADS129X_RLD1P_OFF 0 /* 通道一正极为右腿输入关,默认 */ +#define ADS129X_RLD1P_ON 1 /* 通道一正极为右腿输入开 */ + +/* 属于ADS129X_REG_LOFFSENS的寄存器设置 */ +#define ADS129X_FLIP2_OFF 0 /* 导联脱落检测通道二电流方向关,默认 */ +#define ADS129X_FLIP2_ON 1 /* 导联脱落检测通道二电流方向开 */ +#define ADS129X_FLIP1_OFF 0 /* 导联脱落检测通道一电流方向关,默认 */ +#define ADS129X_FLIP1_ON 1 /* 导联脱落检测通道一电流方向开 */ +#define ADS129X_LOFF2N_OFF 0 /* 通道二负极导联脱落检测关,默认 */ +#define ADS129X_LOFF2N_ON 1 /* 通道二负极导联脱落检测开 */ +#define ADS129X_LOFF2P_OFF 0 /* 通道二正极导联脱落检测关,默认 */ +#define ADS129X_LOFF2P_ON 1 /* 通道二正极导联脱落检测开 */ +#define ADS129X_LOFF1N_OFF 0 /* 通道一负极导联脱落检测关,默认 */ +#define ADS129X_LOFF1N_ON 1 /* 通道一负极导联脱落检测开 */ +#define ADS129X_LOFF1P_OFF 0 /* 通道一正极导联脱落检测关,默认 */ +#define ADS129X_LOFF1P_ON 1 /* 通道一正极导联脱落检测开 */ + +/* 属于ADS129X_REG_LOFFSTAT的寄存器设置 */ +#define ADS129X_CLK_DIV4 0 /* 0 = fMOD = fCLK / 4 (default, use when fCLK = 512 kHz) */ +#define ADS129X_CLK_DIV16 1 /* 1 = fMOD = fCLK / 16 (use when fCLK = 2.048 MHz) */ + +/* 属于ADS129X_REG_RESP1的寄存器设置 */ +#define ADS129X_DEMOD_EN1_OFF 0 /* 通道一上的呼吸解调电路关,默认 */ +#define ADS129X_DEMOD_EN1_ON 1 /* 通道一上的呼吸解调电路开 */ +#define ADS129X_DEMOD_EN_OFF 0 /* 通道一上的呼吸调制电路关,默认 */ +#define ADS129X_DEMOD_EN_ON 1 /* 通道一上的呼吸调制电路开 */ +#define ADS129X_RESPPH_0 0 /* 解调信号相位偏移0,默认 */ +#define ADS129X_RESPPH_135 0x0c /* 解调信号相位偏移135度 */ +#define ADS129X_RESP_CTRL_INT 0 /* 内部呼吸内部时钟,默认 */ +#define ADS129X_RESP_CTRL_EXT 1 /* 内部呼吸外部时钟 */ + +/* 属于ADS129X_REG_RESP2的寄存器设置 */ +#define ADS129X_CALIB_ON_OFF 0 /* 校准关,默认 */ +#define ADS129X_CALIB_ON_ON 1 /* 校准开 */ +#define ADS129X_RESP_FREQ_36 0 /* 通道一上的呼吸调制电路关,默认 */ +#define ADS129X_RESP_FREQ_64 1 /* 通道一上的呼吸调制电路开 */ +#define ADS129X_RLDREF_EXT 0 /* 右腿驱动参考电压选择外部反馈,默认 */ +#define ADS129X_RLDREF_INT 1 /* 右腿驱动参考电压选择内部信号 */ + +/* 属于ADS129X_REG_GPIO的寄存器设置 */ +/** + * @} + */ + +/** @addtogroup ADS129X_TYP_REG_MASK ADS1291 TYP Reg Mask + * @brief 各寄存器值与位置掩码,被ADS129X_GET_BITS与ADS129X_SET_BITS函数调用 + * @{ + */ +#define ADS129X_ID_POS 0 +#define ADS129X_ID_MASK 0xFF + +#define ADS129X_SINGLE_SHOT_POS 7 +#define ADS129X_SINGLE_SHOT_MASK 0x80 +#define ADS129X_DR_POS 0 +#define ADS129X_DR_MASK 0x07 + +#define ADS129X_PDB_LOFF_COMP_POS 6 +#define ADS129X_PDB_LOFF_COMP_MASK 0x40 +#define ADS129X_PDB_REFBUF_POS 5 +#define ADS129X_PDB_REFBUF_MASK 0x20 +#define ADS129X_VREF_4V_POS 4 +#define ADS129X_VREF_4V_MASK 0x10 +#define ADS129X_CLK_EN_POS 3 +#define ADS129X_CLK_EN_MASK 0x80 +#define ADS129X_INT_TEST_POS 1 +#define ADS129X_INT_TEST_MASK 0x02 +#define ADS129X_INT_FREQ_POS 0 +#define ADS129X_INT_FREQ_MASK 0x01 + +#define ADS129X_PDx_POS 7 +#define ADS129X_PDx_MASK 0x80 +#define ADS129X_GAINx_POS 4 +#define ADS129X_GAINx_MASK 0x70 +#define ADS129X_MUXx_POS 0 +#define ADS129X_MUXx_MASK 0x0F + +#define ADS129X_CHOP_POS 6 +#define ADS129X_CHOP_MASK 0xC0 +#define ADS129X_PDB_RLD_POS 5 +#define ADS129X_PDB_RLD_MASK 0x20 +#define ADS129X_RLD_LOFF_SENSE_POS 4 +#define ADS129X_RLD_LOFF_SENSE_MASK 0x10 +#define ADS129X_RLD2N_POS 3 +#define ADS129X_RLD2N_MASK 0x08 +#define ADS129X_RLD2P_POS 2 +#define ADS129X_RLD2P_MASK 0x04 +#define ADS129X_RLD1N_POS 1 +#define ADS129X_RLD1N_MASK 0x02 +#define ADS129X_RLD1P_POS 0 +#define ADS129X_RLD1P_MASK 0x01 + +#define ADS129X_FLIP2_POS 5 +#define ADS129X_FLIP2_MASK 0x20 +#define ADS129X_FLIP1_POS 4 +#define ADS129X_FLIP1_MASK 0x10 +#define ADS129X_LOFF2N_POS 3 +#define ADS129X_LOFF2N_MASK 0x08 +#define ADS129X_LOFF2P_POS 2 +#define ADS129X_LOFF2P_MASK 0x04 +#define ADS129X_LOFFN_POS 1 +#define ADS129X_LOFF1N_MASK 0x02 +#define ADS129X_LOFF1P_POS 0 +#define ADS129X_LOFF1P_MASK 0x01 + +#define ADS129X_CLK_DIV_POS 6 +#define ADS129X_CLK_DIV_MASK 0x40 + +#define ADS129X_RESP_DEMOD_EN1_POS 7 +#define ADS129X_RESP_DEMOD_EN1_MASK 0x80 +#define ADS129X_RESP_MOD_EN_POS 6 +#define ADS129X_RESP_MOD_EN_MASK 0x40 +#define ADS129X_RESP_PH_POS 2 +#define ADS129X_RESP_PH_MASK 0x3c +#define ADS129X_RESP_CTRL_POS 0 +#define ADS129X_RESP_CTRL_MASK 0x01 + +#define ADS129X_CALIB_ON_POS 7 +#define ADS129X_CALIB_ON_MASK 0x80 +#define ADS129X_RESP_FREQ_POS 2 +#define ADS129X_RESP_FREQ_MASK 0x04 +#define ADS129X_RLDREF_INT_POS 1 +#define ADS129X_RLDREF_INT_MASK 0x02 + +/** + * @} + */ + +/** @addtogroup ADS129X_TYP_COMMAND ADS1291 TYP COMMAND + * @brief 命令 + * @{ + */ +/* System Commands */ +#define ADS129X_COMMAND_WAKEUP 0x02 // Wake-up from standby mode +#define ADS129X_COMMAND_STANDBY 0x04 // Enter standby mode +#define ADS129X_COMMAND_RESET 0x06 // Reset the device +#define ADS129X_COMMAND_START 0x08 // Start or restart (synchronize) conversion +#define ADS129X_COMMAND_STOP 0x0A // Stop conversion +#define ADS129X_COMMAND_OFFSETCAL 0x1A // Channel offset calibration + +/* Data Read Commands */ +#define ADS129X_COMMAND_RDATAC 0x10 // Enable Read Data Continuous mode. This mode is the default mode at power-up.(1) +#define ADS129X_COMMAND_SDATAC 0x11 // Stop Read Data Continuously mode +#define ADS129X_COMMAND_RDATA 0x12 // Read data by command; supports multiple read back + +/* Register Read Commands,最后5位为读写的地址 */ +#define ADS129X_COMMAND_RREG 0x20 // Read n nnnn registers starting at address r rrrr +#define ADS129X_COMMAND_WREG 0x40 // Write n nnnn registers starting at address r rrrr +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/* Exported macro ------------------------------------------------------------*/ +/** @brief 读取ADS1291的指定寄存器的指定位 + * @details + * @param[in] bitname 位名字 + * @param[in] reg 寄存器名字 + * @retval 该位的值 + */ +#define ADS129X_GET_BITS(bitname, reg) ((reg & bitname##_MASK) >> bitname##_POS) + +/** @brief 设置ADS1291的指定寄存器的指定位 + * @details + * @param[in] reg 寄存器名字 + * @param[in] bitname 位名字 + * @param[in] val 要设置的值 + * @retval NONE + */ +#define ADS129X_SET_BITS(reg, bitname, val) ((reg & ~bitname##_MASK) | ((val << bitname##_POS) & bitname##_MASK)) +/* Exported functions --------------------------------------------------------*/ + +#ifdef __cplusplus +} +#endif diff --git a/app/src/_board/board_battery_state.c b/app/src/_board/board_battery_state.c new file mode 100644 index 0000000..44d1601 --- /dev/null +++ b/app/src/_board/board_battery_state.c @@ -0,0 +1,100 @@ + +#include "board_battery_state.h" + +#include "app_basic_service/app_event.h" +#include "board_adc_module_ctrl.h" +/******************************************************************************* + * Battery * + *******************************************************************************/ +APP_TIMER_DEF(battery_state_detect_tmr); // +static bool m_battery_is_chargeing = false; // + +static bool battery_get_chargeing_state() { return !nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN); } +static void module_tmr_cb(void *context) { // + bool chargeing_state = battery_get_chargeing_state(); + if (chargeing_state != m_battery_is_chargeing) { + app_event_t event; + memset(&event, 0, sizeof(event)); + if (chargeing_state) { + ZLOGI("battery is charging"); + event.eventType = kbattery_start_charge_event; + } else { + ZLOGI("battery end charging"); + event.eventType = kbattery_end_charge_event; + } + AppEvent_pushEvent(&event); + } + m_battery_is_chargeing = chargeing_state; +} + +void BoardBattery_init() { + /** + * @brief 500ms启动定时器500ms检查一次当前是否正在充电 + */ + nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE); + app_timer_create(&battery_state_detect_tmr, APP_TIMER_MODE_REPEATED, module_tmr_cb); + app_timer_start(battery_state_detect_tmr, APP_TIMER_TICKS(500), NULL); +} +void BoardBattery_load() { BoardAdc_load(); } +void BoardBattery_unload() { BoardAdc_unload(); } + +int16_t BoardBattery_sence_gpio_init_before_sleep() { nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); } + +int16_t BoardBattery_get_adc_val() { + int16_t val = BoardAdc_get_val(BATTERY_ADC_CHANNEL); + return val; +} +int16_t BoardBattery_get_charging_state() { // + return !nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN); +} + +static int16_t battery_level_filter(int16_t nowlevel) { + static int16_t lastlevel = 0; + if (abs(nowlevel - lastlevel) >= 5) { + lastlevel = nowlevel; + } else if (nowlevel >= 95) { + lastlevel = 100; + } else if (nowlevel <= 5) { + lastlevel = nowlevel; + } + + int16_t retlevel = lastlevel; + retlevel = retlevel / 5 * 5; + return retlevel; +} + +int16_t BoardBattery_get_battery_level() { + static const float maxv = 4.15; + static const float minv = 3.75; + + int16_t rawval = BoardBattery_get_adc_val(); + + float voltage = rawval / 4096.0 * 3.6 / 2.0 * 3; + // if (voltage > maxv) voltage = maxv; + // if (voltage < minv) voltage = minv; + + float percent = (voltage - minv) / (maxv - minv) * 100 + (float)0.1 /*加0.1是为了避免999.999时显示电量为90*/; + int16_t percent_int = (int16_t)percent; + + if (battery_get_chargeing_state()) { + percent_int = percent_int - 10; + } + + if (percent_int < 0) { + percent_int = 0; + } else if (percent_int > 100) { + percent_int = 100; + } + + return battery_level_filter(percent_int); + // return percent_int; +} + +int16_t BoardBattery_selfTest() { + nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); + BoardAdc_load(); + while (true) { + ZLOGI_BLOCK("adc raw:%d %d", BoardBattery_get_adc_val(), nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN)); + nrf_delay_ms(1000); + } +} diff --git a/app/src/_board/board_battery_state.h b/app/src/_board/board_battery_state.h new file mode 100644 index 0000000..54825c6 --- /dev/null +++ b/app/src/_board/board_battery_state.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +#include "aproject_config/config.h" +#include "znordic.h" + +void BoardBattery_init(); +void BoardBattery_load(); +void BoardBattery_unload(); + +int16_t BoardBattery_get_adc_val(); +int16_t BoardBattery_get_battery_level(); // 0->100 +int16_t BoardBattery_get_charging_state(); + +int16_t BoardBattery_sence_gpio_init_before_sleep(); + + +int16_t BoardBattery_selfTest(); + diff --git a/app/src/_board/board_eeprom_driver.c b/app/src/_board/board_eeprom_driver.c new file mode 100644 index 0000000..e1948a5 --- /dev/null +++ b/app/src/_board/board_eeprom_driver.c @@ -0,0 +1,133 @@ + +#include "board_eeprom_driver.h" + +#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" +// + +#define EEPROM_I2C_SCL_M 15 // I2C SCL引脚 +#define EEPROM_I2C_SDA_M 17 // I2C SDA引脚 +#define EEPROM_I2C_INSTANCE 1 // I2C使用的硬件控制器ID + +/******************************************************************************* + * eeprom * + *******************************************************************************/ +static const nrf_drv_twi_t m_eeprom_twi_master = NRF_DRV_TWI_INSTANCE(EEPROM_I2C_INSTANCE); + +void board_eeprom_init() { + nrf_drv_twi_config_t config = NRF_DRV_TWI_DEFAULT_CONFIG; + + config.scl = EEPROM_I2C_SCL_M; + config.sda = EEPROM_I2C_SDA_M; + config.frequency = NRF_DRV_TWI_FREQ_400K; + ZERROR_CHECK(nrf_drv_twi_init(&m_eeprom_twi_master, &config, NULL, NULL)); + nrf_drv_twi_enable(&m_eeprom_twi_master); +} + +void board_eeprom_uninit() { + nrf_drv_twi_disable(&m_eeprom_twi_master); + nrf_drv_twi_uninit(&m_eeprom_twi_master); +} + +static uint8_t eeprom_cache[EEPROM_PAGE + 2]; + +static void assign_i2c_add(uint32_t add, bool wr, uint8_t *i2cadd, uint8_t *memadd0, uint8_t *memadd1) { + // DEVICE SELECT + // bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 + // 1 0 1 0 E2 A17 A16 RW(W=0) + // + // PS: E2 参考原理图中的电平为0,所以bit3为0 + // + // MEM0 + // bit15 bit14 bit13 bit12 bit11 bit10 bit9 bit8 + // MEM1 + // bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 + // + + *i2cadd = 0xA0; + uint8_t a16a17 = (add >> 16) & 0x03; + *i2cadd |= a16a17 << 1; + *i2cadd = *i2cadd >> 1; + + *memadd0 = add >> 8; + *memadd1 = add & 0xFF; +} + +void board_eeprom_write(uint32_t addr, const uint8_t *data, uint16_t len) { // + // uint32_t addr = page * EEPROM_PAGE; + // len = len > EEPROM_PAGE ? EEPROM_PAGE : len; + + // ZASSERT(len == EEPROM_PAGE); + ZASSERT((addr % EEPROM_PAGE) == 0); + // ZLOGI_BLOCK("eeprom_write %d %d", addr, len); + uint8_t deviceSelect = 0; + + assign_i2c_add(addr, true, &deviceSelect, &eeprom_cache[0], &eeprom_cache[1]); + memcpy(&eeprom_cache[2], data, len); + + ret_code_t ecode = nrf_drv_twi_tx(&m_eeprom_twi_master, deviceSelect, eeprom_cache, len + 2, false); + if (ecode != NRF_SUCCESS) { + ZLOGE("nrf_drv_twi_tx error %x", ecode); + NRF_LOG_INTERNAL_FLUSH(); + } +} +/** + * @brief 用来检测读取整个eeprom是否正常 + */ +void board_eeprom_wr_check() { + /** + * @brief + * 256kbyte + * 写入数据,回读检查数据是否正确 + */ + + static uint8_t wdata_cache[256]; + static uint8_t rdata_cache[256]; +#define CHECKCODE (i % 21) + + for (uint32_t i = 0; i < 1024; i++) { + uint32_t addr = i * EEPROM_PAGE; + for (uint32_t j = 0; j < EEPROM_PAGE; j++) { + wdata_cache[j] = CHECKCODE; + } + ZLOGI_BLOCK("write %d", i); + board_eeprom_write(addr, wdata_cache, EEPROM_PAGE); + nrf_delay_ms(15); + } + + for (uint32_t i = 0; i < 1024; i++) { + uint32_t addr = i * EEPROM_PAGE; + ZLOGI_BLOCK("check %d", i); + board_eeprom_read(addr, rdata_cache, EEPROM_PAGE); + for (uint32_t j = 0; j < EEPROM_PAGE; j++) { + if (rdata_cache[j] != (CHECKCODE)) { + ZLOGE("eeprom_wr_check error %d %d %d", i, j, rdata_cache[j]); + } + } + } + ZLOGD_BLOCK("eeprom_wr_check ok,block here"); + while (true) { + nrf_delay_ms(10); + } +} + +void board_eeprom_read(uint32_t add, uint8_t *data, uint16_t len) { + uint8_t deviceSelect = 0; + uint8_t wadd[2] = {0}; + + assign_i2c_add(add, false, &deviceSelect, &wadd[0], &wadd[1]); + nrf_drv_twi_tx(&m_eeprom_twi_master, deviceSelect, wadd, 2, false); + + deviceSelect |= 0x01; // read + nrf_drv_twi_rx(&m_eeprom_twi_master, deviceSelect, data, len); +} diff --git a/app/src/_board/board_eeprom_driver.h b/app/src/_board/board_eeprom_driver.h new file mode 100644 index 0000000..27910bc --- /dev/null +++ b/app/src/_board/board_eeprom_driver.h @@ -0,0 +1,20 @@ +#pragma once + +/******************************************************************************* + * INCLUDE * + *******************************************************************************/ +#include +#include "znordic.h" + +/** + * + * PageSize 256byte + * + */ +#define EEPROM_PAGE 256 +void board_eeprom_init(); +void board_eeprom_uninit(); +void board_eeprom_write(uint32_t page, const uint8_t* data, uint16_t len); +void board_eeprom_read(uint32_t add, uint8_t* data, uint16_t len); + +void board_eeprom_wr_check(); \ No newline at end of file diff --git a/app/src/_board/board_light_ctrl.c b/app/src/_board/board_light_ctrl.c new file mode 100644 index 0000000..0bc64ea --- /dev/null +++ b/app/src/_board/board_light_ctrl.c @@ -0,0 +1,213 @@ +#include "board_light_ctrl.h" +#include "aproject_config/config.h" +#include "znordic.h" +#include "nrf_gpio.h" + +#define BLINK_CNT 1 +#define BLINK_PERIOD_MS (100) +#define QUICK_BLINK_PERIOD_MS (100) +#define SLOW_BLINK_PERIOD_MS (2000) +// LED_GREEN_PIN +#if 0 +typedef struct { + nrf_drv_pwm_t driver; + nrf_pwm_values_individual_t seq_values; + nrf_pwm_sequence_t seq; + nrf_drv_pwm_config_t config; +} pwm_light_ctrl_t; +static pwm_light_ctrl_t light_ctrl = { + .driver = NRF_DRV_PWM_INSTANCE(LIGHT_PWM_INSTANCE), + .seq_values = {0}, + .seq = + { + .values.p_individual = &light_ctrl.seq_values, + .length = NRF_PWM_VALUES_LENGTH(light_ctrl.seq_values), + .repeats = 0, + .end_delay = 0, + }, + .config = + { + + .output_pins = + { + LED_BLUE_PIN, // + NRF_DRV_PWM_PIN_NOT_USED, + NRF_DRV_PWM_PIN_NOT_USED, + NRF_DRV_PWM_PIN_NOT_USED, + }, + .irq_priority = APP_IRQ_PRIORITY_LOWEST, + .base_clock = NRF_PWM_CLK_250kHz, + .count_mode = NRF_PWM_MODE_UP, + .top_value = 100, // 125kHz / 46 = 2.717k + .load_mode = NRF_PWM_LOAD_INDIVIDUAL, + .step_mode = NRF_PWM_STEP_AUTO, + + }, +}; + +static LightEffect_t m_light_effect; +static bool m_led_green_light_state; +static int m_blink_cnt; +APP_TIMER_DEF(m_green_light_effect_tmr); + +static bool m_boardlight_greenlightstate = false; + +void BoardLight_toggleGreenLightState() { BoardLight_setGreenLightState(!m_boardlight_greenlightstate); } +void BoardLight_setGreenLightState(bool state) { + m_boardlight_greenlightstate = state; + if (state) { + light_ctrl.seq_values.channel_0 = 90; // 设置占空比,数值最大不超过 top_value + nrfx_pwm_simple_playback(&light_ctrl.driver, &light_ctrl.seq, 1, NRF_DRV_PWM_FLAG_LOOP); + } else { + nrfx_pwm_stop(&light_ctrl.driver, true); + } +} + +static void BoardLight_effect_tmr_handler(void* p_context) { // + if (m_light_effect == kLightEffect_close) { + if (m_led_green_light_state) { + BoardLight_setGreenLightState(false); + } + } else if (m_light_effect == kLightEffect_open) { + if (!m_led_green_light_state) { + BoardLight_setGreenLightState(true); + } + } else if (m_light_effect == kLightEffect_slowFlash) { + if (m_blink_cnt < 2) { + if (m_blink_cnt % 2 == 0) { + BoardLight_setGreenLightState(true); + } else if (m_blink_cnt % 2 == 1) { + BoardLight_setGreenLightState(false); + } + } else { + if (BLINK_PERIOD_MS * m_blink_cnt >= SLOW_BLINK_PERIOD_MS) { + m_blink_cnt = 0; + return; + } + } + } else if (m_light_effect == kLightEffect_quickFlash) { + if (BLINK_PERIOD_MS * m_blink_cnt >= QUICK_BLINK_PERIOD_MS) { + BoardLight_toggleGreenLightState(); + m_blink_cnt = 0; + return; + } + } + m_blink_cnt++; +} + +void BoardLight_Init() { + ZERROR_CHECK(app_timer_create(&m_green_light_effect_tmr, APP_TIMER_MODE_REPEATED, BoardLight_effect_tmr_handler)); +} +static bool m_boardlight_loaded = false; + +void BoardLight_load() { + // if (m_boardlight_loaded) { + // return; + // } + // m_boardlight_loaded = true; + nrfx_pwm_init(&light_ctrl.driver, &light_ctrl.config, NULL); + BoardLight_setGreenLightState(false); +} +void BoardLight_unload() { + // if (!m_boardlight_loaded) { + // return; + // } + m_boardlight_loaded = false; + BoardLight_setGreenLightEffect(kLightEffect_close); + nrfx_pwm_uninit(&light_ctrl.driver); +} + +void BoardLight_setGreenLightEffect(LightEffect_t effect) { + if (m_light_effect == effect) return; + m_light_effect = effect; + + switch (effect) { + case kLightEffect_close: + app_timer_stop(m_green_light_effect_tmr); + BoardLight_setGreenLightState(false); + break; + case kLightEffect_open: + app_timer_stop(m_green_light_effect_tmr); + BoardLight_setGreenLightState(true); + break; + case kLightEffect_slowFlash: + app_timer_start(m_green_light_effect_tmr, APP_TIMER_TICKS(BLINK_PERIOD_MS), NULL); + break; + case kLightEffect_quickFlash: + app_timer_start(m_green_light_effect_tmr, APP_TIMER_TICKS(BLINK_PERIOD_MS), NULL); + break; + default: + break; + } + return; +} + +void BoardLight_blockFlash(int times, int periodms) { + for (int i = 0; i < times; i++) { + BoardLight_setGreenLightState(true); + nrf_delay_ms(periodms); + BoardLight_setGreenLightState(false); + nrf_delay_ms(periodms); + } +} + +#endif + +void BoardLight_Init() { + // LED_GREEN_PIN + // LED_BLUE_PIN + // LED_RED_PIN + + znrf_gpio_cfg_output(LED_GREEN_PIN, NRF_GPIO_PIN_NOPULL); + znrf_gpio_cfg_output(LED_BLUE_PIN, NRF_GPIO_PIN_NOPULL); + znrf_gpio_cfg_output(LED_RED_PIN, NRF_GPIO_PIN_NOPULL); +} +void BoardLight_load() {} +void BoardLight_unload() {} + +void BoardLight_setGreenLightState(bool state) { + if (state) { + nrf_gpio_pin_set(LED_GREEN_PIN); + } else { + nrf_gpio_pin_clear(LED_GREEN_PIN); + } +} +void BoardLight_setRedLightState(bool state) { + if (state) { + nrf_gpio_pin_set(LED_RED_PIN); + } else { + nrf_gpio_pin_clear(LED_RED_PIN); + } +} +void BoardLight_setBlueLightState(bool state) { + if (state) { + nrf_gpio_pin_set(LED_BLUE_PIN); + } else { + nrf_gpio_pin_clear(LED_BLUE_PIN); + } +} + +void BoardLight_toggleGreenLightState() {} + +void BoardLight_setGreenLightEffect(LightEffect_t effect) {} +void BoardLight_blockFlash(int times, int periodms) {} + +void BoardLight_selftest() { + BoardLight_Init(); + while (true) { + BoardLight_setGreenLightState(true); + nrf_delay_ms(1000); + BoardLight_setGreenLightState(false); + nrf_delay_ms(1000); + + BoardLight_setRedLightState(true); + nrf_delay_ms(1000); + BoardLight_setRedLightState(false); + nrf_delay_ms(1000); + + BoardLight_setBlueLightState(true); + nrf_delay_ms(1000); + BoardLight_setBlueLightState(false); + nrf_delay_ms(1000); + } +} diff --git a/app/src/_board/board_light_ctrl.h b/app/src/_board/board_light_ctrl.h new file mode 100644 index 0000000..31ed0a4 --- /dev/null +++ b/app/src/_board/board_light_ctrl.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +#include "aproject_config/config.h" + +typedef enum { + kLightEffect_unset, + kLightEffect_close, + kLightEffect_open, + kLightEffect_slowFlash, + kLightEffect_quickFlash, +} LightEffect_t; + +void BoardLight_Init(); // main中初始化一遍 +void BoardLight_load(); +void BoardLight_unload(); + +void BoardLight_setGreenLightState(bool state); +void BoardLight_setRedLightState(bool state); +void BoardLight_setBlueLightState(bool state); + +void BoardLight_toggleGreenLightState(); + + +void BoardLight_setGreenLightEffect(LightEffect_t effect); +void BoardLight_blockFlash(int times, int periodms); + + +void BoardLight_selftest(); diff --git a/app/src/_board/board_power_mgr.c b/app/src/_board/board_power_mgr.c new file mode 100644 index 0000000..0d16e16 --- /dev/null +++ b/app/src/_board/board_power_mgr.c @@ -0,0 +1,18 @@ +#include "board_power_mgr.h" + +#define SCREEN_RESET_PIN 7 + +void board_power_mgr_init() { // + znrf_gpio_cfg_output(SCREEN_RESET_PIN, NRF_GPIO_PIN_NOPULL); +} + +void board_power_mgr_deinit() { // + nrf_gpio_cfg_default(SCREEN_RESET_PIN); +} +void board_power_mgr_main_power_supply_set(bool val) { + if (val) { + nrf_gpio_pin_set(SCREEN_RESET_PIN); + } else { + nrf_gpio_pin_clear(SCREEN_RESET_PIN); + } +} diff --git a/app/src/_board/board_power_mgr.h b/app/src/_board/board_power_mgr.h new file mode 100644 index 0000000..973879a --- /dev/null +++ b/app/src/_board/board_power_mgr.h @@ -0,0 +1,12 @@ +#pragma once + +/******************************************************************************* + * INCLUDE * + *******************************************************************************/ +#include + +#include "znordic.h" + +void board_power_mgr_init(); +void board_power_mgr_deinit(); +void board_power_mgr_main_power_supply_set(bool val); \ No newline at end of file diff --git a/app/src/_board/board_ssd1306_interface.c b/app/src/_board/board_ssd1306_interface.c new file mode 100644 index 0000000..f914fb6 --- /dev/null +++ b/app/src/_board/board_ssd1306_interface.c @@ -0,0 +1,98 @@ +#include "board_ssd1306_interface.h" + +#include + +#include "znordic.h" +// +#include "app_timer.h" +#include "ff.h" +#include "nrf_block_dev_sdc.h" +#include "nrf_delay.h" +#include "nrf_gpio.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 +#define SCREEN_POWER_PIN 30 +#define SCREEN_A0PIN 31 +#define SCREEN_CS_PIN 29 +#define SCREEN_CLK_PIN 4 +#define SCREEN_MOSI_PIN 11 + +/******************************************************************************* + * SCREEN * + *******************************************************************************/ + +static const nrf_drv_spi_t m_screen_spi = NRF_DRV_SPI_INSTANCE(SCREEN_SPI_INSTANCE); /**< SPI instance. */ + +void board_screen_init() { + znrf_gpio_cfg_output(SCREEN_RESET_PIN, NRF_GPIO_PIN_NOPULL); + znrf_gpio_cfg_output(SCREEN_POWER_PIN, NRF_GPIO_PIN_NOPULL); + znrf_gpio_cfg_output(SCREEN_A0PIN, NRF_GPIO_PIN_NOPULL); + + nrf_gpio_pin_set(SCREEN_POWER_PIN); + // 参考 + // OLED驱动程序 : https://iflytop1.feishu.cn/wiki/OQ4Iwv0DpiQDJvkjftjcQHJBnCg + // nRF5_SDK-使用手册: https://iflytop1.feishu.cn/wiki/ThaAwZEGVi2bspkfGU9cbl9Enqd + nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; + spi_config.ss_pin = SCREEN_CS_PIN; // NRF_DRV_SPI_PIN_NOT_USED + spi_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED; + spi_config.mosi_pin = SCREEN_MOSI_PIN; + spi_config.sck_pin = SCREEN_CLK_PIN; + spi_config.frequency = NRF_DRV_SPI_FREQ_8M; + spi_config.mode = NRF_DRV_SPI_MODE_3; + ZERROR_CHECK(nrf_drv_spi_init(&m_screen_spi, &spi_config, NULL, NULL)); + ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0); +} + +void board_screen_deinit() { + nrf_gpio_cfg_default(SCREEN_RESET_PIN); + nrf_gpio_cfg_default(SCREEN_POWER_PIN); + nrf_gpio_cfg_default(SCREEN_A0PIN); + + ssd1306_basic_deinit(); + nrf_drv_spi_uninit(&m_screen_spi); +} + +uint8_t board_screen_spi_write_cmd(uint8_t *buf, uint16_t len) { // + ZERROR_CHECK(nrf_drv_spi_transfer(&m_screen_spi, buf, len, NULL, 0)); + return 0; +} +void board_screen_delay_ms(uint32_t ms) { nrf_delay_ms(ms); } +uint8_t board_spi_cmd_data_gpio_write(uint8_t value) { + if (value) { + nrf_gpio_pin_set(SCREEN_A0PIN); + } else { + nrf_gpio_pin_clear(SCREEN_A0PIN); + } + return 0; +} +uint8_t board_reset_gpio_write(uint8_t value) { + if (value) { + nrf_gpio_pin_set(SCREEN_RESET_PIN); + } else { + nrf_gpio_pin_clear(SCREEN_RESET_PIN); + } + return 0; +} + +/*********************************************************************************************************************** + * 对接 * + ***********************************************************************************************************************/ +uint8_t ssd1306_interface_iic_init(void) { return 0; } +uint8_t ssd1306_interface_iic_deinit(void) { return 0; } +uint8_t ssd1306_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len) { return 0; } +uint8_t ssd1306_interface_spi_init(void) { return 0; } +uint8_t ssd1306_interface_spi_deinit(void) { return 0; } +uint8_t ssd1306_interface_spi_write_cmd(uint8_t *buf, uint16_t len) { return board_screen_spi_write_cmd(buf, len); } +void ssd1306_interface_delay_ms(uint32_t ms) { board_screen_delay_ms(ms); } +void ssd1306_interface_debug_print(const char *const fmt, ...) {} +uint8_t ssd1306_interface_spi_cmd_data_gpio_init(void) { return 0; } +uint8_t ssd1306_interface_spi_cmd_data_gpio_deinit(void) { return 0; } +uint8_t ssd1306_interface_spi_cmd_data_gpio_write(uint8_t value) { return board_spi_cmd_data_gpio_write(value); } +uint8_t ssd1306_interface_reset_gpio_init(void) { return 0; } +uint8_t ssd1306_interface_reset_gpio_deinit(void) { return 0; } +uint8_t ssd1306_interface_reset_gpio_write(uint8_t value) { return board_reset_gpio_write(value); } diff --git a/app/src/_board/board_ssd1306_interface.h b/app/src/_board/board_ssd1306_interface.h new file mode 100644 index 0000000..bbb2c9b --- /dev/null +++ b/app/src/_board/board_ssd1306_interface.h @@ -0,0 +1,15 @@ +#pragma once + +/******************************************************************************* + * INCLUDE * + *******************************************************************************/ +#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/soc_public_res_mgr.c b/app/src/_board/soc_public_res_mgr.c new file mode 100644 index 0000000..e69de29 diff --git a/app/src/_board/soc_public_res_mgr.h b/app/src/_board/soc_public_res_mgr.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/app/src/_board/soc_public_res_mgr.h @@ -0,0 +1 @@ +#pragma once 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/app_basic_service/basic/event.h b/app/src/app_basic_service/basic/event.h index ec93ff3..3ddbe0b 100644 --- a/app/src/app_basic_service/basic/event.h +++ b/app/src/app_basic_service/basic/event.h @@ -8,7 +8,9 @@ #define ECG_DATA_REPORT_FRAME_NUM 32 // ecg每次上报的帧数 typedef enum { - kecg_data_report_event, // ecg数据上报事件 + kevent_tmr_scheduler_event, + + kecg_data_report_event, // ecg数据上报事件 kappevent_battery_start_charge, // 开始充电事件 kappevent_battery_end_charge, // 停止充电事件 } app_event_type_t; diff --git a/app/src/app_service/battery_mgr_service.c b/app/src/app_service/battery_mgr_service.c index cd76810..f406e33 100644 --- a/app/src/app_service/battery_mgr_service.c +++ b/app/src/app_service/battery_mgr_service.c @@ -77,7 +77,7 @@ static int16_t _battery_mgr_service_get_battery_level() { // percent_int = 100; } - return battery_level_filter(percent_int); + return _battery_level_filter(percent_int); } /*********************************************************************************************************************** diff --git a/app/src/app_service/beep_ctrl.c b/app/src/app_service/beep_ctrl.c index 7384edd..f820872 100644 --- a/app/src/app_service/beep_ctrl.c +++ b/app/src/app_service/beep_ctrl.c @@ -30,12 +30,12 @@ static uint32_t m_beep_cnt = 0; static void beep_tmr_handler(void *context) { if (m_beep_effect == kBoardBeepEffect_none) { - board_beep_ctrl_set(false); + beep_set(false); } else if (m_beep_effect == kBoardBeepEffect_oneShortBeep) { if (m_beep_cnt == 0) { - board_beep_ctrl_set(true); + beep_set(true); } else if (m_beep_cnt >= 1) { - board_beep_ctrl_set(false); + beep_set(false); app_timer_stop(m_beep_tmr); m_beep_effect = kBoardBeepEffect_none; } @@ -43,9 +43,9 @@ static void beep_tmr_handler(void *context) { else if (m_beep_effect == kBoardBeepEffect_oneShortLongBeep) { if (m_beep_cnt == 0) { - board_beep_ctrl_set(true); + beep_set(true); } else if (m_beep_cnt >= 6) { - board_beep_ctrl_set(false); + beep_set(false); app_timer_stop(m_beep_tmr); m_beep_effect = kBoardBeepEffect_none; } @@ -54,12 +54,12 @@ static void beep_tmr_handler(void *context) { else if (m_beep_effect == kBoardBeepEffect_threeShortBeep) { if (m_beep_cnt < 6) { if (m_beep_cnt % 2 == 0) { - board_beep_ctrl_set(true); + beep_set(true); } else if (m_beep_cnt % 2 == 1) { - board_beep_ctrl_set(false); + beep_set(false); } } else { - board_beep_ctrl_set(false); + beep_set(false); app_timer_stop(m_beep_tmr); m_beep_effect = kBoardBeepEffect_none; } @@ -68,9 +68,9 @@ static void beep_tmr_handler(void *context) { // 每隔1秒响三声 if (m_beep_cnt < 6) { if (m_beep_cnt % 2 == 0) { - board_beep_ctrl_set(true); + beep_set(true); } else if (m_beep_cnt % 2 == 1) { - board_beep_ctrl_set(false); + beep_set(false); } } else { if (BEEP_TIMER_INTERVAL * m_beep_cnt >= 10000) { @@ -96,7 +96,7 @@ void beep_load() { // void beep_unload() { if (!m_beep_loaded) return; - board_beep_ctrl_set(0); + beep_set(0); nrfx_pwm_uninit(&m_beep_pwm0); m_beep_loaded = false; } @@ -118,7 +118,7 @@ void beep_set_effect(board_beep_effect_t effect) { app_timer_stop(m_beep_tmr); m_beep_cnt = 0; if (m_beep_effect == kBoardBeepEffect_none) { - board_beep_ctrl_set(false); + beep_set(false); } else { app_timer_start(m_beep_tmr, APP_TIMER_TICKS(BEEP_TIMER_INTERVAL), NULL); } diff --git a/app/src/app_service/display_ctrl_service/display_manager.bak.c b/app/src/app_service/display_ctrl_service/display_manager.bak.c deleted file mode 100644 index a886363..0000000 --- a/app/src/app_service/display_ctrl_service/display_manager.bak.c +++ /dev/null @@ -1,443 +0,0 @@ -#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/app_service/display_ctrl_service/display_manager.bak.h b/app/src/app_service/display_ctrl_service/display_manager.bak.h deleted file mode 100644 index 0553b77..0000000 --- a/app/src/app_service/display_ctrl_service/display_manager.bak.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/app_service/display_ctrl_service/display_mgr.c b/app/src/app_service/display_ctrl_service/display_mgr.c index e760123..1de411f 100644 --- a/app/src/app_service/display_ctrl_service/display_mgr.c +++ b/app/src/app_service/display_ctrl_service/display_mgr.c @@ -4,11 +4,14 @@ // #include +#include "app_service/battery_mgr_service.h" #include "aproject_config/config.h" -#include "board/board_battery_state.h" #include "font.h" #include "ssd1306/driver_ssd1306_basic.h" #include "ssd1306/wave_drawer.h" +// +#include "app_service/ecg_service/ecg_service.h" +#include "ssd1306_if_impl.h" /*********************************************************************************************************************** * MARCO * @@ -23,8 +26,7 @@ #define MAIN_PAGE_BATTERY_HEIGHT (22) // 首页电池高度 typedef struct { - page_t page; - uint32_t page_get_schedule_period; + page_t page; void (*on_page_load)(); void (*on_page_scheduler)(); @@ -89,6 +91,9 @@ static void _page_change(page_t page) { } } +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; } + /*********************************************************************************************************************** * PAGE_IMPL * ***********************************************************************************************************************/ @@ -125,7 +130,7 @@ static void page_main_load() { 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(); + batterylevel = battery_mgr_service_get_battery_level(); ssd1306_basic_clear_gram(); @@ -136,9 +141,7 @@ static void page_main_load() { } static void page_main_unload() {} static uint32_t page_main_get_scheduler_period() { return 300; } -static void page_main_tmr_cb() { - page_main_load(); -} +static void page_main_tmr_cb() { page_main_load(); } /*********************************************************************************************************************** * 采样页面 * ***********************************************************************************************************************/ @@ -240,11 +243,11 @@ static uint32_t page_sampling_get_scheduler_period() { return 10; } static void page_sampling_tmr_cb() { 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(); + int capturetime = ecg_service_has_captured_time(); + int wave_y = (int)ecg_service_get_display_val(); + int heartrate = (int)ecg_service_get_heart_rate(); - samplePage_update_state(capturetime / 1000, wave_y, hwss_read_heart_rate(), count % 30 == 0, count % 10 == 0); + samplePage_update_state(capturetime / 1000, wave_y, heartrate, count % 30 == 0, count % 10 == 0); } /*********************************************************************************************************************** @@ -294,7 +297,6 @@ static void page_charging_page_load() { static void page_charging_page_unload() {} static uint32_t page_charging_page_get_scheduler_period() { return 300; } static void page_charging_page_tmr_cb() { - charging_page__batterylevel += 5; if (charging_page__batterylevel > 100) { charging_page__batterylevel = battery_mgr_service_get_battery_level(); diff --git a/app/src/app_service/display_ctrl_service/font.h b/app/src/app_service/display_ctrl_service/font.h index 179ea34..91069b5 100644 --- a/app/src/app_service/display_ctrl_service/font.h +++ b/app/src/app_service/display_ctrl_service/font.h @@ -1,6 +1,7 @@ // https://www.23bei.com/tool-965.html #include +#include "ssd1306/fontlib.h" #if 0 const uint8_t fontclocklib_code[] = { 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0xFF, 0xF0, 0x07, 0x80, 0x78, 0x06, // diff --git a/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306.c b/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306.c index ba880cb..0704444 100644 --- a/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306.c +++ b/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306.c @@ -513,7 +513,7 @@ uint8_t ssd1306_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint return 0; /* success return 0 */ } #endif - return 0; + } /** diff --git a/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306_basic.c b/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306_basic.c index ff1fd58..3b12a67 100644 --- a/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306_basic.c +++ b/app/src/app_service/display_ctrl_service/ssd1306/driver_ssd1306_basic.c @@ -566,7 +566,7 @@ uint8_t ssd1306_basic_draw_str(uint8_t xs, uint8_t ys, uint8_t *xchange, uint8_t str_iterator_start(&iterator, frontlib->fontCode, str); char *nowchr = NULL; while (true) { - str_iterator_next(&iterator, &nowchr); + str_iterator_next(&iterator, (const char **)&nowchr); if (!nowchr) { break; } @@ -595,8 +595,8 @@ uint8_t ssd1306_basic_draw_battery_level(uint8_t xs, uint8_t ys, uint8_t *xchang level = 100; } - uint8_t xoff = 0; - uint8_t yoff = 0; + //uint8_t xoff = 0; + //uint8_t yoff = 0; int batteryHeaderHigh = 2; int batteryHeaderWidth = 7; @@ -717,6 +717,7 @@ uint8_t ssd1306_basic_draw_battery_level(uint8_t xs, uint8_t ys, uint8_t *xchang *xchange = batteryBodyWidth; *ychange = batteryBodyHigh + batteryHeaderHigh; + return 0; } uint8_t ssd1306_basic_draw_progress(uint8_t xs, uint8_t ys, uint16_t width, uint16_t high, uint16_t markpos, uint16_t progress) { @@ -789,4 +790,5 @@ uint8_t ssd1306_basic_draw_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) y1 += sy; } } + return 0; } diff --git a/app/src/app_service/ecg_service/algo/ecg_data_analyszer.c b/app/src/app_service/ecg_service/algo/ecg_data_analyszer.c index 52d507a..6138b2a 100644 --- a/app/src/app_service/ecg_service/algo/ecg_data_analyszer.c +++ b/app/src/app_service/ecg_service/algo/ecg_data_analyszer.c @@ -3,5 +3,5 @@ void ecg_data_analyszer_init() {} void ecg_data_analyszer_push_data(int32_t data) {} -float ecg_data_analyszer_get_display_data() {} -float ecg_data_analyszer_get_heart_rate() {} \ No newline at end of file +float ecg_data_analyszer_get_display_data() { return 50; } +float ecg_data_analyszer_get_heart_rate() { return 50; } \ No newline at end of file diff --git a/app/src/app_service/ecg_service/algo/iflytop_simple_filter.c b/app/src/app_service/ecg_service/algo/iflytop_simple_filter.c index a17498b..9a8d8f9 100644 --- a/app/src/app_service/ecg_service/algo/iflytop_simple_filter.c +++ b/app/src/app_service/ecg_service/algo/iflytop_simple_filter.c @@ -95,12 +95,12 @@ void NOTCHFilter_Init(NOTCHFilter_t *filter, float centerFreqHz, float notchWidt float ww_rps = 2.0 * PI * notchWidthHz; // pre warp center frequency - float w0_pw_rps = (2.0 / sampleTimeS) * tanf(0.5 * w0_rps * sampleTimeS); + float w0_pw_rps = (2.0f / sampleTimeS) * tanf(0.5f * w0_rps * sampleTimeS); // computing filter coefficients - filter->alpha = 4.0 + w0_rps * w0_pw_rps * sampleTimeS * sampleTimeS; - filter->beta = 2.0 * ww_rps * sampleTimeS; + filter->alpha = 4.0f + w0_rps * w0_pw_rps * sampleTimeS * sampleTimeS; + filter->beta = 2.0f * ww_rps * sampleTimeS; // clearing input and output buffers @@ -124,8 +124,8 @@ float NOTCHFilter_Update(NOTCHFilter_t *filter, float vin) { filter->vin[0] = vin; // compute new output - filter->vout[0] = (filter->alpha * filter->vin[0] + 2.0 * (filter->alpha - 8.0) * filter->vin[1] + filter->alpha * filter->vin[2] - - (2.0f * (filter->alpha - 8.0) * filter->vout[1] + (filter->alpha - filter->beta) * filter->vout[2])) / + filter->vout[0] = (filter->alpha * filter->vin[0] + 2.0f * (filter->alpha - 8.0f) * filter->vin[1] + filter->alpha * filter->vin[2] - + (2.0f * (filter->alpha - 8.0f) * filter->vout[1] + (filter->alpha - filter->beta) * filter->vout[2])) / (filter->alpha + filter->beta); return (filter->vout[0]); diff --git a/app/src/app_service/ecg_service/ecg_data_mgr.c b/app/src/app_service/ecg_service/ecg_data_mgr.c index e1fc03c..c96fe4f 100644 --- a/app/src/app_service/ecg_service/ecg_data_mgr.c +++ b/app/src/app_service/ecg_service/ecg_data_mgr.c @@ -1,4 +1,5 @@ #include "ecg_data_mgr.h" +#include static ecg_report_data_t m_report_data_cache; diff --git a/app/src/app_service/ecg_service/ecg_service.c b/app/src/app_service/ecg_service/ecg_service.c index 399226c..eefe3d6 100644 --- a/app/src/app_service/ecg_service/ecg_service.c +++ b/app/src/app_service/ecg_service/ecg_service.c @@ -55,11 +55,11 @@ uint8_t ads129x_send_cmd(uint8_t cmd) { uint8_t rx = 0; ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(100); + nrf_delay_us(100); rx = port_spi_transmit_receive(cmd); - port_ads129x_delay_us(100); + nrf_delay_us(100); ADS129X_CS_SET(); /* 释放设备 */ return rx; @@ -70,7 +70,7 @@ uint8_t ads129x_rw_reg(uint8_t cmd, uint8_t data) { uint8_t rx = 0; ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(1); + nrf_delay_us(1); port_spi_transmit_receive(cmd); /* 发送读写指令 */ port_spi_transmit_receive(0X00); /* 只写一个数据 */ @@ -80,7 +80,7 @@ uint8_t ads129x_rw_reg(uint8_t cmd, uint8_t data) { else rx = port_spi_transmit_receive(data); /* 写入数值 */ - port_ads129x_delay_us(1); + nrf_delay_us(1); ADS129X_CS_SET(); /* 释放设备 */ return rx; @@ -91,19 +91,19 @@ void ads129x_write_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { uint8_t i; ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(100); + nrf_delay_us(100); port_spi_transmit_receive(ADS129X_COMMAND_WREG | reg); - port_ads129x_delay_us(100); + nrf_delay_us(100); port_spi_transmit_receive(size - 1); for (i = 0; i < size; i++) { - port_ads129x_delay_us(100); + nrf_delay_us(100); port_spi_transmit_receive(*ch); ch++; } - port_ads129x_delay_us(100); + nrf_delay_us(100); ADS129X_CS_SET(); } @@ -112,19 +112,19 @@ void ads129x_read_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { uint8_t i; ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(100); + nrf_delay_us(100); port_spi_transmit_receive(ADS129X_COMMAND_RREG | reg); - port_ads129x_delay_us(100); + nrf_delay_us(100); port_spi_transmit_receive(size - 1); for (i = 0; i < size; i++) { - port_ads129x_delay_us(100); + nrf_delay_us(100); *ch = port_spi_transmit_receive(0); ch++; } - port_ads129x_delay_us(100); + nrf_delay_us(100); ADS129X_CS_SET(); } @@ -167,10 +167,10 @@ void ads129x_read_data(ads129x_capture_data_t* capture_data) { uint8_t rddata[9]; ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(10); + nrf_delay_us(10); port_spi_transmit_receive(ADS129X_COMMAND_RDATA); - port_ads129x_delay_us(1); + nrf_delay_us(1); for (int i = 0; i < 9; i++) { rddata[i] = port_spi_transmit_receive(0); } @@ -258,16 +258,16 @@ void ecg_service_load() { ADS129X_REST_RESET(); ADS129X_START_RESET(); - port_ads129x_delay_ms(1000); + nrf_delay_ms(1000); ADS129X_REST_SET(); - port_ads129x_delay_ms(100); /* 硬件复位 */ + nrf_delay_ms(100); /* 硬件复位 */ ads129x_send_cmd(ADS129X_COMMAND_SDATAC); /* 软件复位,并停止连续读状态 */ - port_ads129x_delay_ms(100); + nrf_delay_ms(100); ads129x_send_cmd(ADS129X_COMMAND_RESET); - port_ads129x_delay_ms(1000); + nrf_delay_ms(1000); ads129x_send_cmd(ADS129X_COMMAND_SDATAC); - port_ads129x_delay_ms(100); + nrf_delay_ms(100); static ads129x_regs_t regcache; ads129x_readback_regs(®cache); @@ -296,13 +296,26 @@ void ecg_service_unload() { nrf_gpio_cfg_default(ADS1291_READY_PIN); } +static uint32_t ecg_service_captured_time = 0; + void ecg_service_start_capture() { // ecg_data_mgr_clear_buffer(); ads129x_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ + ecg_service_captured_time = znordic_getpower_on_ms(); } void ecg_service_stop_capture() { // ads129x_send_cmd(ADS129X_COMMAND_STOP); /* 发送停止数据转换(等效于拉低START引脚) */ } +uint32_t ecg_service_has_captured_time() { return znordic_haspassed_ms(ecg_service_captured_time); } void ecg_service_subic_write_reg(uint8_t addr, uint8_t val) { ads129x_rw_reg(ADS129X_COMMAND_WREG | addr, val); } uint8_t ecg_service_subic_read_reg(uint8_t addr) { return ads129x_rw_reg(ADS129X_COMMAND_RREG | addr, 0); } + + +int32_t ecg_service_get_display_val(){ + return ecg_algo_get_display_data(); +} + +int32_t ecg_service_get_heart_rate(){ + return ecg_algo_get_heart_rate(); +} diff --git a/app/src/app_service/ecg_service/ecg_service.h b/app/src/app_service/ecg_service/ecg_service.h index f6459a9..d890698 100644 --- a/app/src/app_service/ecg_service/ecg_service.h +++ b/app/src/app_service/ecg_service/ecg_service.h @@ -28,6 +28,9 @@ void ecg_service_unload(); void ecg_service_start_capture(); void ecg_service_stop_capture(); +uint32_t ecg_service_has_captured_time(); +int32_t ecg_service_get_display_val(); +int32_t ecg_service_get_heart_rate(); void ecg_service_subic_write_reg(uint8_t addr, uint8_t val); uint8_t ecg_service_subic_read_reg(uint8_t addr); diff --git a/app/src/app_service/light_ctrl.c b/app/src/app_service/light_ctrl.c index 19b1065..d4e2f07 100644 --- a/app/src/app_service/light_ctrl.c +++ b/app/src/app_service/light_ctrl.c @@ -37,7 +37,7 @@ static void light_ctrl_effect_tmr_handler(void* p_context) { // } } else if (m_led_green_light_effect == kLightEffect_quickFlash) { if (BLINK_PERIOD_MS * m_blink_cnt >= QUICK_BLINK_PERIOD_MS) { - board_light_toggle_green_light_state(); + light_ctrl_toggle_green_light_state(); m_blink_cnt = 0; return; } diff --git a/app/src/board/ads129x/ads129x.c b/app/src/board/ads129x/ads129x.c deleted file mode 100644 index a0d613a..0000000 --- a/app/src/board/ads129x/ads129x.c +++ /dev/null @@ -1,294 +0,0 @@ -#include "ads129x.h" - -#include "ads129x_type.h" -#include "nrf_drv_gpiote.h" -#include "znordic.h" - -/** - * @brief ads129x 使用注意事项 - * - * ads129x SPI 通信格式 - * - * [cmd 8bit] [data nbit] - * - * - * ads129x 支持的指令如下 - * 唤醒 (0x02) - * 待机 (0x04) - * 复位 (0x06) - * 开始转换 (0x08) - * 停止 (0x0A) - * 通道偏移校准 (0x1A) - * 使能数据连续读模式 (0x10) - * 停止数据连续读模式 (0x11) - * 读数据 (0x12) - * 读寄存器 (0x2x) - * 写寄存器 (0x4x) - * - * - * 注意事项: - * 1. 当ads129x处于连续读模式下,寄存器读写指令失效 - * 2. 不进入连续模式下,可以通过[读数据]指令,读取数据,此时寄存器操作指令是有效的 - * - */ - -static ads129x_cfg_t* ads129x_cfg; - -#define ADS129X_CS_SET() nrf_gpio_pin_set(ads129x_cfg->cspin); -#define ADS129X_CS_RESET() nrf_gpio_pin_clear(ads129x_cfg->cspin); -#define ADS129X_START_SET() nrf_gpio_pin_set(ads129x_cfg->startpin); -#define ADS129X_START_RESET() nrf_gpio_pin_clear(ads129x_cfg->startpin); -#define ADS129X_REST_SET() nrf_gpio_pin_set(ads129x_cfg->pwdnpin); -#define ADS129X_REST_RESET() nrf_gpio_pin_clear(ads129x_cfg->pwdnpin); -#define ADS129X_DRDY_GET() nrf_gpio_pin_read(ads129x_cfg->drdypin) - -static void port_ads129x_delay_us(uint32_t us) { nrf_delay_us(us); } -static void port_ads129x_delay_ms(uint32_t ms) { nrf_delay_ms(ms); } - -#define port_delay_ms port_ads129x_delay_ms - -/*********************************************************************************************************************** - * BASE_FUNCTION_IMPL * - ***********************************************************************************************************************/ - -uint8_t port_spi_transmit_receive(uint8_t tx) { - uint8_t data; - nrf_drv_spi_transfer(ads129x_cfg->spi, &tx, 1, &data, 1); - return data; -} - -/* ads129X发送指令 */ -uint8_t ads129x_send_cmd(uint8_t cmd) { - uint8_t rx = 0; - - ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(100); - - rx = port_spi_transmit_receive(cmd); - - port_ads129x_delay_us(100); - ADS129X_CS_SET(); /* 释放设备 */ - - return rx; -} - -/* ads129X读写寄存器,自动根据指令类型区分读和写操作 */ -uint8_t ads129x_rw_reg(uint8_t cmd, uint8_t data) { - uint8_t rx = 0; - - ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(1); - - port_spi_transmit_receive(cmd); /* 发送读写指令 */ - port_spi_transmit_receive(0X00); /* 只写一个数据 */ - - if ((cmd & ADS129X_COMMAND_RREG) == ADS129X_COMMAND_RREG) /* 判断指令类型 */ - rx = port_spi_transmit_receive(0X00); /* 返回寄存器值 */ - else - rx = port_spi_transmit_receive(data); /* 写入数值 */ - - port_ads129x_delay_us(1); - ADS129X_CS_SET(); /* 释放设备 */ - - return rx; -} - -/* 从指定寄存器开始读写一定数量的寄存器 */ -void ads129X_write_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { - uint8_t i; - - ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(100); - - port_spi_transmit_receive(ADS129X_COMMAND_WREG | reg); - port_ads129x_delay_us(100); - port_spi_transmit_receive(size - 1); - - for (i = 0; i < size; i++) { - port_ads129x_delay_us(100); - port_spi_transmit_receive(*ch); - ch++; - } - - port_ads129x_delay_us(100); - ADS129X_CS_SET(); -} - -/* 从指定寄存器开始读写一定数量的寄存器 */ -void ads129X_read_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { - uint8_t i; - - ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(100); - - port_spi_transmit_receive(ADS129X_COMMAND_RREG | reg); - port_ads129x_delay_us(100); - port_spi_transmit_receive(size - 1); - - for (i = 0; i < size; i++) { - port_ads129x_delay_us(100); - *ch = port_spi_transmit_receive(0); - ch++; - } - - port_ads129x_delay_us(100); - ADS129X_CS_SET(); -} - -static void ads129x_readback_regs(ads129x_regs_t* regcache) { ads129X_read_multiregs(ADS129X_REG_ID, (uint8_t*)regcache, sizeof(ads129x_regs_t)); } -static void ads129x_dump_regs(ads129x_regs_t* regcache) { - ZLOGI("id : %x", regcache->id); - ZLOGI("cfg1 : %x", regcache->cfg1); - ZLOGI("cfg2 : %x", regcache->cfg2); - ZLOGI("loff : %x", regcache->loff); - ZLOGI("ch1set : %x", regcache->ch1set); - ZLOGI("ch2set : %x", regcache->ch2set); - ZLOGI("rld_sens : %x", regcache->rld_sens); - ZLOGI("loff_sens : %x", regcache->loff_sens); - ZLOGI("loff_stat : %x", regcache->loff_stat); - ZLOGI("resp1 : %x", regcache->resp1); - ZLOGI("resp2 : %x", regcache->resp2); - ZLOGI("gpio : %x", regcache->gpio); -} - -static bool ads129x_write_regs(ads129x_regs_t* writeval) { - static ads129x_regs_t rdbak; - ads129X_write_multiregs(ADS129X_REG_ID, (uint8_t*)writeval, sizeof(ads129x_regs_t)); - ads129X_read_multiregs(ADS129X_REG_ID, (uint8_t*)&rdbak, sizeof(ads129x_regs_t)); - - writeval->id = 0; - writeval->loff_stat = writeval->loff_stat & (0x01 << 6); - - rdbak.id = 0; - rdbak.loff_stat = rdbak.loff_stat & (0x01 << 6); - - if (memcmp(writeval, &rdbak, sizeof(ads129x_regs_t)) != 0) { - ZLOGE("ads129x_write_reg reg fail"); - return false; - } - ZLOGI("ads129x_write_reg reg success"); - return true; -} - -/*********************************************************************************************************************** - * EXTERN * - ***********************************************************************************************************************/ -void ads129x_read_data_loop() { - // app_timer_pause(); - - // ads129x_capture_data_t capture_data; - // while (true) { - // ads129x_read_data(&capture_data); - // ZLOGI("%d {%d} %x", ADS129X_DRDY_GET(), capture_data.ch1data, capture_data.loffstate); - // znordic_force_flush_log(); - // } -} - -uint8_t ads129x_init(ads129x_cfg_t* cfg) { - /** - * @brief - */ - ads129x_cfg = cfg; - ZASSERT(nrfx_gpiote_is_init()); - - ADS129X_CS_SET(); - - ADS129X_REST_RESET(); - ADS129X_START_RESET(); - port_ads129x_delay_ms(1000); - ADS129X_REST_SET(); - port_ads129x_delay_ms(100); /* 硬件复位 */ - - ads129x_send_cmd(ADS129X_COMMAND_SDATAC); /* 软件复位,并停止连续读状态 */ - port_ads129x_delay_ms(100); - ads129x_send_cmd(ADS129X_COMMAND_RESET); - port_ads129x_delay_ms(1000); - ads129x_send_cmd(ADS129X_COMMAND_SDATAC); - port_ads129x_delay_ms(100); - - static ads129x_regs_t regcache; - ads129x_readback_regs(®cache); - ads129x_dump_regs(®cache); - regcache.cfg1 = 0x02; - regcache.cfg2 = 0xE0; - regcache.loff = 0xF0; - regcache.ch1set = 0x00; - regcache.ch2set = 0x00; - regcache.rld_sens = 0x20; - regcache.loff_sens = 0x03; - ads129x_write_regs(®cache); - - nrf_gpio_pin_set(ads129x_cfg->pwdnpin); - return 0; -} - -uint8_t ads129x_read_reg(uint8_t add) { return ads129x_rw_reg(ADS129X_COMMAND_RREG | add, 0); } - -void ads129x_write_reg(uint8_t add, uint8_t data) { - ZLOGI("ads129x_write_reg %x %x", add, data); - static ads129x_regs_t regcache; - ads129x_readback_regs(®cache); - uint8_t* reg = (uint8_t*)®cache; - reg[add] = data; - ads129x_write_regs(®cache); -} - -uint8_t ads129x_start_capture() { - ads129x_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ - return 0; -} - -uint8_t ads129x_stop_capture() { - ads129x_send_cmd(ADS129X_COMMAND_STOP); /* 发送停止数据转换(等效于拉低START引脚) */ - return 0; -} - -static int32_t i24toi32(uint8_t* p_i32) { - int32_t rev = 0; - rev = (((int32_t)p_i32[0]) << 16) | (((int32_t)p_i32[1]) << 8) | ((int32_t)p_i32[2]); - if ((p_i32[0] & 0x80) == 0x80) { - rev |= 0xFF000000; - } - return rev; -} - -void ads129x_read_data(ads129x_capture_data_t* capture_data) { - uint8_t rddata[9]; - - ADS129X_CS_RESET(); /* 选中设备 */ - port_ads129x_delay_us(10); - - port_spi_transmit_receive(ADS129X_COMMAND_RDATA); - port_ads129x_delay_us(1); - for (int i = 0; i < 9; i++) { - rddata[i] = port_spi_transmit_receive(0); - } - ADS129X_CS_SET(); - - /** - * @brief - * - * 回读数据格式(datasheet page 42) - * 24bit status (1100 + LOFF_STAT[4:0] + GPIO[1:0] + 13`b0) - * 24bit ch0 MSB - * 24bit ch1 MSB - * - */ - uint32_t status = (((uint32_t)rddata[0]) << 16) | (((uint32_t)rddata[1]) << 8) | ((uint32_t)rddata[2]); - - capture_data->loffstate = (status >> (13 + 2)) & 0x1f; - capture_data->gpio0 = status >> (14); - capture_data->gpio1 = status >> (13); - - capture_data->ch1data = i24toi32(&rddata[3]); - capture_data->ch2data = i24toi32(&rddata[6]); -} - -uint8_t ads129x_get_lead_off_state() { - // FLIP2,FLIP1,LOFF2N,LOFF2P,LOFF1N,LOFF1P - uint8_t leadoffstate = ads129x_read_reg(ADS129X_REG_LOFFSTAT); - return leadoffstate; -} - -uint8_t ads129x_enter_low_power_mode() { return 0; } -uint8_t ads129x_enter_lead_off_detect_mode() { return 0; } diff --git a/app/src/board/ads129x/ads129x.h b/app/src/board/ads129x/ads129x.h deleted file mode 100644 index 202ac06..0000000 --- a/app/src/board/ads129x/ads129x.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif -#include -#include - -#include "znordic.h" -typedef struct { - /** - * @brief - * - * loffstate:[4:0] RLD_STAT IN2N_OFF IN2P_OFF IN1N_OFF IN1P_OFF - * ch1data: 有符号数据 - * ch2data: 有符号数据 - */ - - uint8_t loffstate; - - uint8_t gpio0; - uint8_t gpio1; - - uint32_t ch1data; - uint32_t ch2data; -} ads129x_capture_data_t; - -typedef struct { - nrf_drv_spi_t* spi; - uint32_t cspin; - uint32_t startpin; - uint32_t drdypin; - uint32_t pwdnpin; -} ads129x_cfg_t; - -/** - * @brief 初始化SPI - */ -uint8_t ads129x_init(ads129x_cfg_t* cfg); - -// uint8_t ads129x_start_capture(bool test); -uint8_t ads129x_stop_capture(); -uint8_t ads129x_start_capture(); - -void ads129x_write_reg(uint8_t addr, uint8_t val); -uint8_t ads129x_read_reg(uint8_t addr); - -void ads129x_read_data(ads129x_capture_data_t* rddata); - -uint8_t ads129x_get_lead_off_state(); - -#ifdef __cplusplus -} -#endif diff --git a/app/src/board/ads129x/ads129x_type.h b/app/src/board/ads129x/ads129x_type.h deleted file mode 100644 index d3a5cf6..0000000 --- a/app/src/board/ads129x/ads129x_type.h +++ /dev/null @@ -1,286 +0,0 @@ -#pragma once -#include -#ifdef __cplusplus -extern "C" { -#endif -typedef enum { - ADS129X_REG_ID = 0x00, - ADS129X_REG_CONFIG1 = 0x01, - ADS129X_REG_CONFIG2 = 0x02, - ADS129X_REG_LOFF = 0x03, - ADS129X_REG_CH1SET = 0x04, - ADS129X_REG_CH2SET = 0x05, - ADS129X_REG_RLDSENS = 0x06, - ADS129X_REG_LOFFSENS = 0x07, - ADS129X_REG_LOFFSTAT = 0x08, - ADS129X_REG_RESP1 = 0x09, - ADS129X_REG_RESP2 = 0x0A, - ADS129X_REG_GPIO = 0x0B -} ADS129X_REG_E; - -typedef struct { - uint8_t id; /* id,ads1292r固定为0x73 */ - 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的控制 */ -} ads129x_regs_t; - -#define ADS129X_REG_SIZE_MAX 12 /* ADS1291寄存器数量 */ -#define ADS129X_ID 0x52 - -/* 属于ADS129X_REG_CONFIG1的寄存器设置 */ -#define ADS129X_SINGLE_SHOT_OFF 0 /* 连续转换模式,默认 */ -#define ADS129X_SINGLE_SHOT_ON 1 /* 单次转换模式 */ -/* 采样率,该模块采用fclk为512k,0分频模式,其他配置下采样率会改变 */ -#define ADS129X_OVERSAMPLING_125SPS 0 -#define ADS129X_OVERSAMPLING_250SPS 1 -#define ADS129X_OVERSAMPLING_500SPS 2 /* 默认 */ -#define ADS129X_OVERSAMPLING_1000SPS 3 -#define ADS129X_OVERSAMPLING_2000SPS 4 -#define ADS129X_OVERSAMPLING_4000SPS 5 -#define ADS129X_OVERSAMPLING_8000SPS 6 -#define ADS129X_OVERSAMPLING_NONESPS 7 - -/* 属于ADS129X_REG_CONFIG2的寄存器设置 */ -#define ADS129X_PDB_LOFF_COMP_OFF 0 /* 导联脱落比较器关,默认 */ -#define ADS129X_PDB_LOFF_COMP_ON 1 /* 导联脱落比较器开 */ -#define ADS129X_PDB_REFBUF_OFF 0 /* 内部参考电压关,默认 */ -#define ADS129X_PDB_REFBUF_ON 1 /* 内部参考电压开 */ -#define ADS129X_VREF_2420MV 0 /* 选择参考电压为2.42v,默认 */ -#define ADS129X_VREF_4033MV 1 /* 选择参考电压为4.033v */ -#define ADS129X_CLK_OUTPUT_OFF 0 /* 时钟输出关,默认 */ -#define ADS129X_CLK_OUTPUT_ON 1 /* 时钟输出开 */ -#define ADS129X_INT_TEST_OFF 0 /* 内部测试电压关,默认 */ -#define ADS129X_INT_TEST_ON 1 /* 内部测试电压开 */ -#define ADS129X_INT_FREQ_DC 0 /* 直流,默认 */ -#define ADS129X_INT_FREQ_AC 1 /* 1HZ方波 */ - -/* 属于ADS129X_REG_LOFF的寄存器设置 */ - -/* 属于ADS129X_REG_CH1SET,与ADS129X_REG_CH2SET的寄存器设置 */ -#define ADS129X_CHx_OFF 1 /* 禁止使用通道一 */ -#define ADS129X_CHx_ON 0 /* 使用通道一,默认 */ - -#define ADS129X_GAIN_6 0 /* 使用通道一6倍增益,默认 */ -#define ADS129X_GAIN_1 1 /* 使用通道一1倍增益 */ -#define ADS129X_GAIN_2 2 /* 使用通道一2倍增益 */ -#define ADS129X_GAIN_3 3 /* 使用通道一3倍增益 */ -#define ADS129X_GAIN_4 4 /* 使用通道一4倍增益 */ -#define ADS129X_GAIN_8 5 /* 使用通道一8倍增益 */ -#define ADS129X_GAIN_12 6 /* 使用通道一12倍增益 */ -/* 选择通道一的输入 */ -#define ADS129X_CHx_INPUT_NORMAL 0 /* 正常电极输入,默认 */ -#define ADS129X_CHx_INPUT_SHORTED 1 /* 短路,测偏执用 */ -#define ADS129X_CHx_INPUT_RLD 2 /* 右腿驱动 */ -/* For channel 1, (MVDDP – MVDDN) is [0.5(AVDD + AVSS)]; for channel 2, (MVDDP – MVDDN) is DVDD / 4. */ -/* For channel 2,VDD / 2 for supply measurement */ -#define ADS129X_CHx_INPUT_MVDD 3 -#define ADS129X_CHx_INPUT_TEMP 4 /* 板载温度 */ -#define ADS129X_CHx_INPUT_TEST 5 /* 内部测试信号 */ -#define ADS129X_CHx_INPUT_RLDDRP 6 -#define ADS129X_CHx_INPUT_RLDDRM 7 -#define ADS129X_CHx_INPUT_RLDDRPM 8 -#define ADS129X_CHx_INPUT_ROUTE 9 /* 连接到通道三 */ -#define ADS129X_CHx_INPUT_RESERVED 10 /* 预留 */ - -/* 属于ADS129X_REG_RLDSENS的寄存器设置 */ -#define ADS129X_CHOP_FREQ_DIV4 3 /* PGA斩波频率未fMOD/4 */ -#define ADS129X_PDB_RLD_OFF 0 /* 右腿驱动电源关,默认 */ -#define ADS129X_PDB_RLD_ON 1 /* 右腿驱动电源开 */ -#define ADS129X_PDB_RLD_SENSE_OFF 0 /* 右腿驱动导联脱落检测关,默认 */ -#define ADS129X_PDB_RLD_SENSE_ON 1 /* 右腿驱动导联脱落检测开 */ -#define ADS129X_RLD2N_OFF 0 /* 通道二负极为右腿输入关,默认 */ -#define ADS129X_RLD2N_ON 1 /* 通道二负极为右腿输入开 */ -#define ADS129X_RLD2P_OFF 0 /* 通道二正极为右腿输入关,默认 */ -#define ADS129X_RLD2P_ON 1 /* 通道二正极为右腿输入开 */ -#define ADS129X_RLD1N_OFF 0 /* 通道一负极为右腿输入关,默认 */ -#define ADS129X_RLD1N_ON 1 /* 通道一负极为右腿输入开 */ -#define ADS129X_RLD1P_OFF 0 /* 通道一正极为右腿输入关,默认 */ -#define ADS129X_RLD1P_ON 1 /* 通道一正极为右腿输入开 */ - -/* 属于ADS129X_REG_LOFFSENS的寄存器设置 */ -#define ADS129X_FLIP2_OFF 0 /* 导联脱落检测通道二电流方向关,默认 */ -#define ADS129X_FLIP2_ON 1 /* 导联脱落检测通道二电流方向开 */ -#define ADS129X_FLIP1_OFF 0 /* 导联脱落检测通道一电流方向关,默认 */ -#define ADS129X_FLIP1_ON 1 /* 导联脱落检测通道一电流方向开 */ -#define ADS129X_LOFF2N_OFF 0 /* 通道二负极导联脱落检测关,默认 */ -#define ADS129X_LOFF2N_ON 1 /* 通道二负极导联脱落检测开 */ -#define ADS129X_LOFF2P_OFF 0 /* 通道二正极导联脱落检测关,默认 */ -#define ADS129X_LOFF2P_ON 1 /* 通道二正极导联脱落检测开 */ -#define ADS129X_LOFF1N_OFF 0 /* 通道一负极导联脱落检测关,默认 */ -#define ADS129X_LOFF1N_ON 1 /* 通道一负极导联脱落检测开 */ -#define ADS129X_LOFF1P_OFF 0 /* 通道一正极导联脱落检测关,默认 */ -#define ADS129X_LOFF1P_ON 1 /* 通道一正极导联脱落检测开 */ - -/* 属于ADS129X_REG_LOFFSTAT的寄存器设置 */ -#define ADS129X_CLK_DIV4 0 /* 0 = fMOD = fCLK / 4 (default, use when fCLK = 512 kHz) */ -#define ADS129X_CLK_DIV16 1 /* 1 = fMOD = fCLK / 16 (use when fCLK = 2.048 MHz) */ - -/* 属于ADS129X_REG_RESP1的寄存器设置 */ -#define ADS129X_DEMOD_EN1_OFF 0 /* 通道一上的呼吸解调电路关,默认 */ -#define ADS129X_DEMOD_EN1_ON 1 /* 通道一上的呼吸解调电路开 */ -#define ADS129X_DEMOD_EN_OFF 0 /* 通道一上的呼吸调制电路关,默认 */ -#define ADS129X_DEMOD_EN_ON 1 /* 通道一上的呼吸调制电路开 */ -#define ADS129X_RESPPH_0 0 /* 解调信号相位偏移0,默认 */ -#define ADS129X_RESPPH_135 0x0c /* 解调信号相位偏移135度 */ -#define ADS129X_RESP_CTRL_INT 0 /* 内部呼吸内部时钟,默认 */ -#define ADS129X_RESP_CTRL_EXT 1 /* 内部呼吸外部时钟 */ - -/* 属于ADS129X_REG_RESP2的寄存器设置 */ -#define ADS129X_CALIB_ON_OFF 0 /* 校准关,默认 */ -#define ADS129X_CALIB_ON_ON 1 /* 校准开 */ -#define ADS129X_RESP_FREQ_36 0 /* 通道一上的呼吸调制电路关,默认 */ -#define ADS129X_RESP_FREQ_64 1 /* 通道一上的呼吸调制电路开 */ -#define ADS129X_RLDREF_EXT 0 /* 右腿驱动参考电压选择外部反馈,默认 */ -#define ADS129X_RLDREF_INT 1 /* 右腿驱动参考电压选择内部信号 */ - -/* 属于ADS129X_REG_GPIO的寄存器设置 */ -/** - * @} - */ - -/** @addtogroup ADS129X_TYP_REG_MASK ADS1291 TYP Reg Mask - * @brief 各寄存器值与位置掩码,被ADS129X_GET_BITS与ADS129X_SET_BITS函数调用 - * @{ - */ -#define ADS129X_ID_POS 0 -#define ADS129X_ID_MASK 0xFF - -#define ADS129X_SINGLE_SHOT_POS 7 -#define ADS129X_SINGLE_SHOT_MASK 0x80 -#define ADS129X_DR_POS 0 -#define ADS129X_DR_MASK 0x07 - -#define ADS129X_PDB_LOFF_COMP_POS 6 -#define ADS129X_PDB_LOFF_COMP_MASK 0x40 -#define ADS129X_PDB_REFBUF_POS 5 -#define ADS129X_PDB_REFBUF_MASK 0x20 -#define ADS129X_VREF_4V_POS 4 -#define ADS129X_VREF_4V_MASK 0x10 -#define ADS129X_CLK_EN_POS 3 -#define ADS129X_CLK_EN_MASK 0x80 -#define ADS129X_INT_TEST_POS 1 -#define ADS129X_INT_TEST_MASK 0x02 -#define ADS129X_INT_FREQ_POS 0 -#define ADS129X_INT_FREQ_MASK 0x01 - -#define ADS129X_PDx_POS 7 -#define ADS129X_PDx_MASK 0x80 -#define ADS129X_GAINx_POS 4 -#define ADS129X_GAINx_MASK 0x70 -#define ADS129X_MUXx_POS 0 -#define ADS129X_MUXx_MASK 0x0F - -#define ADS129X_CHOP_POS 6 -#define ADS129X_CHOP_MASK 0xC0 -#define ADS129X_PDB_RLD_POS 5 -#define ADS129X_PDB_RLD_MASK 0x20 -#define ADS129X_RLD_LOFF_SENSE_POS 4 -#define ADS129X_RLD_LOFF_SENSE_MASK 0x10 -#define ADS129X_RLD2N_POS 3 -#define ADS129X_RLD2N_MASK 0x08 -#define ADS129X_RLD2P_POS 2 -#define ADS129X_RLD2P_MASK 0x04 -#define ADS129X_RLD1N_POS 1 -#define ADS129X_RLD1N_MASK 0x02 -#define ADS129X_RLD1P_POS 0 -#define ADS129X_RLD1P_MASK 0x01 - -#define ADS129X_FLIP2_POS 5 -#define ADS129X_FLIP2_MASK 0x20 -#define ADS129X_FLIP1_POS 4 -#define ADS129X_FLIP1_MASK 0x10 -#define ADS129X_LOFF2N_POS 3 -#define ADS129X_LOFF2N_MASK 0x08 -#define ADS129X_LOFF2P_POS 2 -#define ADS129X_LOFF2P_MASK 0x04 -#define ADS129X_LOFFN_POS 1 -#define ADS129X_LOFF1N_MASK 0x02 -#define ADS129X_LOFF1P_POS 0 -#define ADS129X_LOFF1P_MASK 0x01 - -#define ADS129X_CLK_DIV_POS 6 -#define ADS129X_CLK_DIV_MASK 0x40 - -#define ADS129X_RESP_DEMOD_EN1_POS 7 -#define ADS129X_RESP_DEMOD_EN1_MASK 0x80 -#define ADS129X_RESP_MOD_EN_POS 6 -#define ADS129X_RESP_MOD_EN_MASK 0x40 -#define ADS129X_RESP_PH_POS 2 -#define ADS129X_RESP_PH_MASK 0x3c -#define ADS129X_RESP_CTRL_POS 0 -#define ADS129X_RESP_CTRL_MASK 0x01 - -#define ADS129X_CALIB_ON_POS 7 -#define ADS129X_CALIB_ON_MASK 0x80 -#define ADS129X_RESP_FREQ_POS 2 -#define ADS129X_RESP_FREQ_MASK 0x04 -#define ADS129X_RLDREF_INT_POS 1 -#define ADS129X_RLDREF_INT_MASK 0x02 - -/** - * @} - */ - -/** @addtogroup ADS129X_TYP_COMMAND ADS1291 TYP COMMAND - * @brief 命令 - * @{ - */ -/* System Commands */ -#define ADS129X_COMMAND_WAKEUP 0x02 // Wake-up from standby mode -#define ADS129X_COMMAND_STANDBY 0x04 // Enter standby mode -#define ADS129X_COMMAND_RESET 0x06 // Reset the device -#define ADS129X_COMMAND_START 0x08 // Start or restart (synchronize) conversion -#define ADS129X_COMMAND_STOP 0x0A // Stop conversion -#define ADS129X_COMMAND_OFFSETCAL 0x1A // Channel offset calibration - -/* Data Read Commands */ -#define ADS129X_COMMAND_RDATAC 0x10 // Enable Read Data Continuous mode. This mode is the default mode at power-up.(1) -#define ADS129X_COMMAND_SDATAC 0x11 // Stop Read Data Continuously mode -#define ADS129X_COMMAND_RDATA 0x12 // Read data by command; supports multiple read back - -/* Register Read Commands,最后5位为读写的地址 */ -#define ADS129X_COMMAND_RREG 0x20 // Read n nnnn registers starting at address r rrrr -#define ADS129X_COMMAND_WREG 0x40 // Write n nnnn registers starting at address r rrrr -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/* Exported macro ------------------------------------------------------------*/ -/** @brief 读取ADS1291的指定寄存器的指定位 - * @details - * @param[in] bitname 位名字 - * @param[in] reg 寄存器名字 - * @retval 该位的值 - */ -#define ADS129X_GET_BITS(bitname, reg) ((reg & bitname##_MASK) >> bitname##_POS) - -/** @brief 设置ADS1291的指定寄存器的指定位 - * @details - * @param[in] reg 寄存器名字 - * @param[in] bitname 位名字 - * @param[in] val 要设置的值 - * @retval NONE - */ -#define ADS129X_SET_BITS(reg, bitname, val) ((reg & ~bitname##_MASK) | ((val << bitname##_POS) & bitname##_MASK)) -/* Exported functions --------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif diff --git a/app/src/board/board_battery_state.c b/app/src/board/board_battery_state.c deleted file mode 100644 index 44d1601..0000000 --- a/app/src/board/board_battery_state.c +++ /dev/null @@ -1,100 +0,0 @@ - -#include "board_battery_state.h" - -#include "app_basic_service/app_event.h" -#include "board_adc_module_ctrl.h" -/******************************************************************************* - * Battery * - *******************************************************************************/ -APP_TIMER_DEF(battery_state_detect_tmr); // -static bool m_battery_is_chargeing = false; // - -static bool battery_get_chargeing_state() { return !nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN); } -static void module_tmr_cb(void *context) { // - bool chargeing_state = battery_get_chargeing_state(); - if (chargeing_state != m_battery_is_chargeing) { - app_event_t event; - memset(&event, 0, sizeof(event)); - if (chargeing_state) { - ZLOGI("battery is charging"); - event.eventType = kbattery_start_charge_event; - } else { - ZLOGI("battery end charging"); - event.eventType = kbattery_end_charge_event; - } - AppEvent_pushEvent(&event); - } - m_battery_is_chargeing = chargeing_state; -} - -void BoardBattery_init() { - /** - * @brief 500ms启动定时器500ms检查一次当前是否正在充电 - */ - nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE); - app_timer_create(&battery_state_detect_tmr, APP_TIMER_MODE_REPEATED, module_tmr_cb); - app_timer_start(battery_state_detect_tmr, APP_TIMER_TICKS(500), NULL); -} -void BoardBattery_load() { BoardAdc_load(); } -void BoardBattery_unload() { BoardAdc_unload(); } - -int16_t BoardBattery_sence_gpio_init_before_sleep() { nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); } - -int16_t BoardBattery_get_adc_val() { - int16_t val = BoardAdc_get_val(BATTERY_ADC_CHANNEL); - return val; -} -int16_t BoardBattery_get_charging_state() { // - return !nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN); -} - -static int16_t battery_level_filter(int16_t nowlevel) { - static int16_t lastlevel = 0; - if (abs(nowlevel - lastlevel) >= 5) { - lastlevel = nowlevel; - } else if (nowlevel >= 95) { - lastlevel = 100; - } else if (nowlevel <= 5) { - lastlevel = nowlevel; - } - - int16_t retlevel = lastlevel; - retlevel = retlevel / 5 * 5; - return retlevel; -} - -int16_t BoardBattery_get_battery_level() { - static const float maxv = 4.15; - static const float minv = 3.75; - - int16_t rawval = BoardBattery_get_adc_val(); - - float voltage = rawval / 4096.0 * 3.6 / 2.0 * 3; - // if (voltage > maxv) voltage = maxv; - // if (voltage < minv) voltage = minv; - - float percent = (voltage - minv) / (maxv - minv) * 100 + (float)0.1 /*加0.1是为了避免999.999时显示电量为90*/; - int16_t percent_int = (int16_t)percent; - - if (battery_get_chargeing_state()) { - percent_int = percent_int - 10; - } - - if (percent_int < 0) { - percent_int = 0; - } else if (percent_int > 100) { - percent_int = 100; - } - - return battery_level_filter(percent_int); - // return percent_int; -} - -int16_t BoardBattery_selfTest() { - nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); - BoardAdc_load(); - while (true) { - ZLOGI_BLOCK("adc raw:%d %d", BoardBattery_get_adc_val(), nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN)); - nrf_delay_ms(1000); - } -} diff --git a/app/src/board/board_battery_state.h b/app/src/board/board_battery_state.h deleted file mode 100644 index 54825c6..0000000 --- a/app/src/board/board_battery_state.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include - -#include "aproject_config/config.h" -#include "znordic.h" - -void BoardBattery_init(); -void BoardBattery_load(); -void BoardBattery_unload(); - -int16_t BoardBattery_get_adc_val(); -int16_t BoardBattery_get_battery_level(); // 0->100 -int16_t BoardBattery_get_charging_state(); - -int16_t BoardBattery_sence_gpio_init_before_sleep(); - - -int16_t BoardBattery_selfTest(); - diff --git a/app/src/board/board_eeprom_driver.c b/app/src/board/board_eeprom_driver.c deleted file mode 100644 index e1948a5..0000000 --- a/app/src/board/board_eeprom_driver.c +++ /dev/null @@ -1,133 +0,0 @@ - -#include "board_eeprom_driver.h" - -#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" -// - -#define EEPROM_I2C_SCL_M 15 // I2C SCL引脚 -#define EEPROM_I2C_SDA_M 17 // I2C SDA引脚 -#define EEPROM_I2C_INSTANCE 1 // I2C使用的硬件控制器ID - -/******************************************************************************* - * eeprom * - *******************************************************************************/ -static const nrf_drv_twi_t m_eeprom_twi_master = NRF_DRV_TWI_INSTANCE(EEPROM_I2C_INSTANCE); - -void board_eeprom_init() { - nrf_drv_twi_config_t config = NRF_DRV_TWI_DEFAULT_CONFIG; - - config.scl = EEPROM_I2C_SCL_M; - config.sda = EEPROM_I2C_SDA_M; - config.frequency = NRF_DRV_TWI_FREQ_400K; - ZERROR_CHECK(nrf_drv_twi_init(&m_eeprom_twi_master, &config, NULL, NULL)); - nrf_drv_twi_enable(&m_eeprom_twi_master); -} - -void board_eeprom_uninit() { - nrf_drv_twi_disable(&m_eeprom_twi_master); - nrf_drv_twi_uninit(&m_eeprom_twi_master); -} - -static uint8_t eeprom_cache[EEPROM_PAGE + 2]; - -static void assign_i2c_add(uint32_t add, bool wr, uint8_t *i2cadd, uint8_t *memadd0, uint8_t *memadd1) { - // DEVICE SELECT - // bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 - // 1 0 1 0 E2 A17 A16 RW(W=0) - // - // PS: E2 参考原理图中的电平为0,所以bit3为0 - // - // MEM0 - // bit15 bit14 bit13 bit12 bit11 bit10 bit9 bit8 - // MEM1 - // bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 - // - - *i2cadd = 0xA0; - uint8_t a16a17 = (add >> 16) & 0x03; - *i2cadd |= a16a17 << 1; - *i2cadd = *i2cadd >> 1; - - *memadd0 = add >> 8; - *memadd1 = add & 0xFF; -} - -void board_eeprom_write(uint32_t addr, const uint8_t *data, uint16_t len) { // - // uint32_t addr = page * EEPROM_PAGE; - // len = len > EEPROM_PAGE ? EEPROM_PAGE : len; - - // ZASSERT(len == EEPROM_PAGE); - ZASSERT((addr % EEPROM_PAGE) == 0); - // ZLOGI_BLOCK("eeprom_write %d %d", addr, len); - uint8_t deviceSelect = 0; - - assign_i2c_add(addr, true, &deviceSelect, &eeprom_cache[0], &eeprom_cache[1]); - memcpy(&eeprom_cache[2], data, len); - - ret_code_t ecode = nrf_drv_twi_tx(&m_eeprom_twi_master, deviceSelect, eeprom_cache, len + 2, false); - if (ecode != NRF_SUCCESS) { - ZLOGE("nrf_drv_twi_tx error %x", ecode); - NRF_LOG_INTERNAL_FLUSH(); - } -} -/** - * @brief 用来检测读取整个eeprom是否正常 - */ -void board_eeprom_wr_check() { - /** - * @brief - * 256kbyte - * 写入数据,回读检查数据是否正确 - */ - - static uint8_t wdata_cache[256]; - static uint8_t rdata_cache[256]; -#define CHECKCODE (i % 21) - - for (uint32_t i = 0; i < 1024; i++) { - uint32_t addr = i * EEPROM_PAGE; - for (uint32_t j = 0; j < EEPROM_PAGE; j++) { - wdata_cache[j] = CHECKCODE; - } - ZLOGI_BLOCK("write %d", i); - board_eeprom_write(addr, wdata_cache, EEPROM_PAGE); - nrf_delay_ms(15); - } - - for (uint32_t i = 0; i < 1024; i++) { - uint32_t addr = i * EEPROM_PAGE; - ZLOGI_BLOCK("check %d", i); - board_eeprom_read(addr, rdata_cache, EEPROM_PAGE); - for (uint32_t j = 0; j < EEPROM_PAGE; j++) { - if (rdata_cache[j] != (CHECKCODE)) { - ZLOGE("eeprom_wr_check error %d %d %d", i, j, rdata_cache[j]); - } - } - } - ZLOGD_BLOCK("eeprom_wr_check ok,block here"); - while (true) { - nrf_delay_ms(10); - } -} - -void board_eeprom_read(uint32_t add, uint8_t *data, uint16_t len) { - uint8_t deviceSelect = 0; - uint8_t wadd[2] = {0}; - - assign_i2c_add(add, false, &deviceSelect, &wadd[0], &wadd[1]); - nrf_drv_twi_tx(&m_eeprom_twi_master, deviceSelect, wadd, 2, false); - - deviceSelect |= 0x01; // read - nrf_drv_twi_rx(&m_eeprom_twi_master, deviceSelect, data, len); -} diff --git a/app/src/board/board_eeprom_driver.h b/app/src/board/board_eeprom_driver.h deleted file mode 100644 index 27910bc..0000000 --- a/app/src/board/board_eeprom_driver.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -/******************************************************************************* - * INCLUDE * - *******************************************************************************/ -#include -#include "znordic.h" - -/** - * - * PageSize 256byte - * - */ -#define EEPROM_PAGE 256 -void board_eeprom_init(); -void board_eeprom_uninit(); -void board_eeprom_write(uint32_t page, const uint8_t* data, uint16_t len); -void board_eeprom_read(uint32_t add, uint8_t* data, uint16_t len); - -void board_eeprom_wr_check(); \ No newline at end of file diff --git a/app/src/board/board_light_ctrl.c b/app/src/board/board_light_ctrl.c deleted file mode 100644 index 0bc64ea..0000000 --- a/app/src/board/board_light_ctrl.c +++ /dev/null @@ -1,213 +0,0 @@ -#include "board_light_ctrl.h" -#include "aproject_config/config.h" -#include "znordic.h" -#include "nrf_gpio.h" - -#define BLINK_CNT 1 -#define BLINK_PERIOD_MS (100) -#define QUICK_BLINK_PERIOD_MS (100) -#define SLOW_BLINK_PERIOD_MS (2000) -// LED_GREEN_PIN -#if 0 -typedef struct { - nrf_drv_pwm_t driver; - nrf_pwm_values_individual_t seq_values; - nrf_pwm_sequence_t seq; - nrf_drv_pwm_config_t config; -} pwm_light_ctrl_t; -static pwm_light_ctrl_t light_ctrl = { - .driver = NRF_DRV_PWM_INSTANCE(LIGHT_PWM_INSTANCE), - .seq_values = {0}, - .seq = - { - .values.p_individual = &light_ctrl.seq_values, - .length = NRF_PWM_VALUES_LENGTH(light_ctrl.seq_values), - .repeats = 0, - .end_delay = 0, - }, - .config = - { - - .output_pins = - { - LED_BLUE_PIN, // - NRF_DRV_PWM_PIN_NOT_USED, - NRF_DRV_PWM_PIN_NOT_USED, - NRF_DRV_PWM_PIN_NOT_USED, - }, - .irq_priority = APP_IRQ_PRIORITY_LOWEST, - .base_clock = NRF_PWM_CLK_250kHz, - .count_mode = NRF_PWM_MODE_UP, - .top_value = 100, // 125kHz / 46 = 2.717k - .load_mode = NRF_PWM_LOAD_INDIVIDUAL, - .step_mode = NRF_PWM_STEP_AUTO, - - }, -}; - -static LightEffect_t m_light_effect; -static bool m_led_green_light_state; -static int m_blink_cnt; -APP_TIMER_DEF(m_green_light_effect_tmr); - -static bool m_boardlight_greenlightstate = false; - -void BoardLight_toggleGreenLightState() { BoardLight_setGreenLightState(!m_boardlight_greenlightstate); } -void BoardLight_setGreenLightState(bool state) { - m_boardlight_greenlightstate = state; - if (state) { - light_ctrl.seq_values.channel_0 = 90; // 设置占空比,数值最大不超过 top_value - nrfx_pwm_simple_playback(&light_ctrl.driver, &light_ctrl.seq, 1, NRF_DRV_PWM_FLAG_LOOP); - } else { - nrfx_pwm_stop(&light_ctrl.driver, true); - } -} - -static void BoardLight_effect_tmr_handler(void* p_context) { // - if (m_light_effect == kLightEffect_close) { - if (m_led_green_light_state) { - BoardLight_setGreenLightState(false); - } - } else if (m_light_effect == kLightEffect_open) { - if (!m_led_green_light_state) { - BoardLight_setGreenLightState(true); - } - } else if (m_light_effect == kLightEffect_slowFlash) { - if (m_blink_cnt < 2) { - if (m_blink_cnt % 2 == 0) { - BoardLight_setGreenLightState(true); - } else if (m_blink_cnt % 2 == 1) { - BoardLight_setGreenLightState(false); - } - } else { - if (BLINK_PERIOD_MS * m_blink_cnt >= SLOW_BLINK_PERIOD_MS) { - m_blink_cnt = 0; - return; - } - } - } else if (m_light_effect == kLightEffect_quickFlash) { - if (BLINK_PERIOD_MS * m_blink_cnt >= QUICK_BLINK_PERIOD_MS) { - BoardLight_toggleGreenLightState(); - m_blink_cnt = 0; - return; - } - } - m_blink_cnt++; -} - -void BoardLight_Init() { - ZERROR_CHECK(app_timer_create(&m_green_light_effect_tmr, APP_TIMER_MODE_REPEATED, BoardLight_effect_tmr_handler)); -} -static bool m_boardlight_loaded = false; - -void BoardLight_load() { - // if (m_boardlight_loaded) { - // return; - // } - // m_boardlight_loaded = true; - nrfx_pwm_init(&light_ctrl.driver, &light_ctrl.config, NULL); - BoardLight_setGreenLightState(false); -} -void BoardLight_unload() { - // if (!m_boardlight_loaded) { - // return; - // } - m_boardlight_loaded = false; - BoardLight_setGreenLightEffect(kLightEffect_close); - nrfx_pwm_uninit(&light_ctrl.driver); -} - -void BoardLight_setGreenLightEffect(LightEffect_t effect) { - if (m_light_effect == effect) return; - m_light_effect = effect; - - switch (effect) { - case kLightEffect_close: - app_timer_stop(m_green_light_effect_tmr); - BoardLight_setGreenLightState(false); - break; - case kLightEffect_open: - app_timer_stop(m_green_light_effect_tmr); - BoardLight_setGreenLightState(true); - break; - case kLightEffect_slowFlash: - app_timer_start(m_green_light_effect_tmr, APP_TIMER_TICKS(BLINK_PERIOD_MS), NULL); - break; - case kLightEffect_quickFlash: - app_timer_start(m_green_light_effect_tmr, APP_TIMER_TICKS(BLINK_PERIOD_MS), NULL); - break; - default: - break; - } - return; -} - -void BoardLight_blockFlash(int times, int periodms) { - for (int i = 0; i < times; i++) { - BoardLight_setGreenLightState(true); - nrf_delay_ms(periodms); - BoardLight_setGreenLightState(false); - nrf_delay_ms(periodms); - } -} - -#endif - -void BoardLight_Init() { - // LED_GREEN_PIN - // LED_BLUE_PIN - // LED_RED_PIN - - znrf_gpio_cfg_output(LED_GREEN_PIN, NRF_GPIO_PIN_NOPULL); - znrf_gpio_cfg_output(LED_BLUE_PIN, NRF_GPIO_PIN_NOPULL); - znrf_gpio_cfg_output(LED_RED_PIN, NRF_GPIO_PIN_NOPULL); -} -void BoardLight_load() {} -void BoardLight_unload() {} - -void BoardLight_setGreenLightState(bool state) { - if (state) { - nrf_gpio_pin_set(LED_GREEN_PIN); - } else { - nrf_gpio_pin_clear(LED_GREEN_PIN); - } -} -void BoardLight_setRedLightState(bool state) { - if (state) { - nrf_gpio_pin_set(LED_RED_PIN); - } else { - nrf_gpio_pin_clear(LED_RED_PIN); - } -} -void BoardLight_setBlueLightState(bool state) { - if (state) { - nrf_gpio_pin_set(LED_BLUE_PIN); - } else { - nrf_gpio_pin_clear(LED_BLUE_PIN); - } -} - -void BoardLight_toggleGreenLightState() {} - -void BoardLight_setGreenLightEffect(LightEffect_t effect) {} -void BoardLight_blockFlash(int times, int periodms) {} - -void BoardLight_selftest() { - BoardLight_Init(); - while (true) { - BoardLight_setGreenLightState(true); - nrf_delay_ms(1000); - BoardLight_setGreenLightState(false); - nrf_delay_ms(1000); - - BoardLight_setRedLightState(true); - nrf_delay_ms(1000); - BoardLight_setRedLightState(false); - nrf_delay_ms(1000); - - BoardLight_setBlueLightState(true); - nrf_delay_ms(1000); - BoardLight_setBlueLightState(false); - nrf_delay_ms(1000); - } -} diff --git a/app/src/board/board_light_ctrl.h b/app/src/board/board_light_ctrl.h deleted file mode 100644 index 31ed0a4..0000000 --- a/app/src/board/board_light_ctrl.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include -#include - -#include "aproject_config/config.h" - -typedef enum { - kLightEffect_unset, - kLightEffect_close, - kLightEffect_open, - kLightEffect_slowFlash, - kLightEffect_quickFlash, -} LightEffect_t; - -void BoardLight_Init(); // main中初始化一遍 -void BoardLight_load(); -void BoardLight_unload(); - -void BoardLight_setGreenLightState(bool state); -void BoardLight_setRedLightState(bool state); -void BoardLight_setBlueLightState(bool state); - -void BoardLight_toggleGreenLightState(); - - -void BoardLight_setGreenLightEffect(LightEffect_t effect); -void BoardLight_blockFlash(int times, int periodms); - - -void BoardLight_selftest(); diff --git a/app/src/board/board_power_mgr.c b/app/src/board/board_power_mgr.c deleted file mode 100644 index 0d16e16..0000000 --- a/app/src/board/board_power_mgr.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "board_power_mgr.h" - -#define SCREEN_RESET_PIN 7 - -void board_power_mgr_init() { // - znrf_gpio_cfg_output(SCREEN_RESET_PIN, NRF_GPIO_PIN_NOPULL); -} - -void board_power_mgr_deinit() { // - nrf_gpio_cfg_default(SCREEN_RESET_PIN); -} -void board_power_mgr_main_power_supply_set(bool val) { - if (val) { - nrf_gpio_pin_set(SCREEN_RESET_PIN); - } else { - nrf_gpio_pin_clear(SCREEN_RESET_PIN); - } -} diff --git a/app/src/board/board_power_mgr.h b/app/src/board/board_power_mgr.h deleted file mode 100644 index 973879a..0000000 --- a/app/src/board/board_power_mgr.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -/******************************************************************************* - * INCLUDE * - *******************************************************************************/ -#include - -#include "znordic.h" - -void board_power_mgr_init(); -void board_power_mgr_deinit(); -void board_power_mgr_main_power_supply_set(bool val); \ No newline at end of file diff --git a/app/src/board/board_ssd1306_interface.c b/app/src/board/board_ssd1306_interface.c deleted file mode 100644 index f914fb6..0000000 --- a/app/src/board/board_ssd1306_interface.c +++ /dev/null @@ -1,98 +0,0 @@ -#include "board_ssd1306_interface.h" - -#include - -#include "znordic.h" -// -#include "app_timer.h" -#include "ff.h" -#include "nrf_block_dev_sdc.h" -#include "nrf_delay.h" -#include "nrf_gpio.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 -#define SCREEN_POWER_PIN 30 -#define SCREEN_A0PIN 31 -#define SCREEN_CS_PIN 29 -#define SCREEN_CLK_PIN 4 -#define SCREEN_MOSI_PIN 11 - -/******************************************************************************* - * SCREEN * - *******************************************************************************/ - -static const nrf_drv_spi_t m_screen_spi = NRF_DRV_SPI_INSTANCE(SCREEN_SPI_INSTANCE); /**< SPI instance. */ - -void board_screen_init() { - znrf_gpio_cfg_output(SCREEN_RESET_PIN, NRF_GPIO_PIN_NOPULL); - znrf_gpio_cfg_output(SCREEN_POWER_PIN, NRF_GPIO_PIN_NOPULL); - znrf_gpio_cfg_output(SCREEN_A0PIN, NRF_GPIO_PIN_NOPULL); - - nrf_gpio_pin_set(SCREEN_POWER_PIN); - // 参考 - // OLED驱动程序 : https://iflytop1.feishu.cn/wiki/OQ4Iwv0DpiQDJvkjftjcQHJBnCg - // nRF5_SDK-使用手册: https://iflytop1.feishu.cn/wiki/ThaAwZEGVi2bspkfGU9cbl9Enqd - nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; - spi_config.ss_pin = SCREEN_CS_PIN; // NRF_DRV_SPI_PIN_NOT_USED - spi_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED; - spi_config.mosi_pin = SCREEN_MOSI_PIN; - spi_config.sck_pin = SCREEN_CLK_PIN; - spi_config.frequency = NRF_DRV_SPI_FREQ_8M; - spi_config.mode = NRF_DRV_SPI_MODE_3; - ZERROR_CHECK(nrf_drv_spi_init(&m_screen_spi, &spi_config, NULL, NULL)); - ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0); -} - -void board_screen_deinit() { - nrf_gpio_cfg_default(SCREEN_RESET_PIN); - nrf_gpio_cfg_default(SCREEN_POWER_PIN); - nrf_gpio_cfg_default(SCREEN_A0PIN); - - ssd1306_basic_deinit(); - nrf_drv_spi_uninit(&m_screen_spi); -} - -uint8_t board_screen_spi_write_cmd(uint8_t *buf, uint16_t len) { // - ZERROR_CHECK(nrf_drv_spi_transfer(&m_screen_spi, buf, len, NULL, 0)); - return 0; -} -void board_screen_delay_ms(uint32_t ms) { nrf_delay_ms(ms); } -uint8_t board_spi_cmd_data_gpio_write(uint8_t value) { - if (value) { - nrf_gpio_pin_set(SCREEN_A0PIN); - } else { - nrf_gpio_pin_clear(SCREEN_A0PIN); - } - return 0; -} -uint8_t board_reset_gpio_write(uint8_t value) { - if (value) { - nrf_gpio_pin_set(SCREEN_RESET_PIN); - } else { - nrf_gpio_pin_clear(SCREEN_RESET_PIN); - } - return 0; -} - -/*********************************************************************************************************************** - * 对接 * - ***********************************************************************************************************************/ -uint8_t ssd1306_interface_iic_init(void) { return 0; } -uint8_t ssd1306_interface_iic_deinit(void) { return 0; } -uint8_t ssd1306_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len) { return 0; } -uint8_t ssd1306_interface_spi_init(void) { return 0; } -uint8_t ssd1306_interface_spi_deinit(void) { return 0; } -uint8_t ssd1306_interface_spi_write_cmd(uint8_t *buf, uint16_t len) { return board_screen_spi_write_cmd(buf, len); } -void ssd1306_interface_delay_ms(uint32_t ms) { board_screen_delay_ms(ms); } -void ssd1306_interface_debug_print(const char *const fmt, ...) {} -uint8_t ssd1306_interface_spi_cmd_data_gpio_init(void) { return 0; } -uint8_t ssd1306_interface_spi_cmd_data_gpio_deinit(void) { return 0; } -uint8_t ssd1306_interface_spi_cmd_data_gpio_write(uint8_t value) { return board_spi_cmd_data_gpio_write(value); } -uint8_t ssd1306_interface_reset_gpio_init(void) { return 0; } -uint8_t ssd1306_interface_reset_gpio_deinit(void) { return 0; } -uint8_t ssd1306_interface_reset_gpio_write(uint8_t value) { return board_reset_gpio_write(value); } diff --git a/app/src/board/board_ssd1306_interface.h b/app/src/board/board_ssd1306_interface.h deleted file mode 100644 index bbb2c9b..0000000 --- a/app/src/board/board_ssd1306_interface.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -/******************************************************************************* - * INCLUDE * - *******************************************************************************/ -#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/soc_public_res_mgr.c b/app/src/board/soc_public_res_mgr.c deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/board/soc_public_res_mgr.h b/app/src/board/soc_public_res_mgr.h deleted file mode 100644 index 6f70f09..0000000 --- a/app/src/board/soc_public_res_mgr.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/app/src/board/ssd1306/driver_ssd1306.c b/app/src/board/ssd1306/driver_ssd1306.c deleted file mode 100644 index ba880cb..0000000 --- a/app/src/board/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/board/ssd1306/driver_ssd1306.h b/app/src/board/ssd1306/driver_ssd1306.h deleted file mode 100644 index fa65147..0000000 --- a/app/src/board/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/board/ssd1306/driver_ssd1306_basic.c b/app/src/board/ssd1306/driver_ssd1306_basic.c deleted file mode 100644 index ff1fd58..0000000 --- a/app/src/board/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/board/ssd1306/driver_ssd1306_basic.h b/app/src/board/ssd1306/driver_ssd1306_basic.h deleted file mode 100644 index 2e1d706..0000000 --- a/app/src/board/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/board/ssd1306/driver_ssd1306_font.h b/app/src/board/ssd1306/driver_ssd1306_font.h deleted file mode 100644 index 1734127..0000000 --- a/app/src/board/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/board/ssd1306/driver_ssd1306_interface.h b/app/src/board/ssd1306/driver_ssd1306_interface.h deleted file mode 100644 index 093ed1d..0000000 --- a/app/src/board/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/board/ssd1306/fontlib.c b/app/src/board/ssd1306/fontlib.c deleted file mode 100644 index b2e6090..0000000 --- a/app/src/board/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/board/ssd1306/fontlib.h b/app/src/board/ssd1306/fontlib.h deleted file mode 100644 index 14113c6..0000000 --- a/app/src/board/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/board/ssd1306/wave_drawer.c b/app/src/board/ssd1306/wave_drawer.c deleted file mode 100644 index a98fe9f..0000000 --- a/app/src/board/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/board/ssd1306/wave_drawer.h b/app/src/board/ssd1306/wave_drawer.h deleted file mode 100644 index e42d3fb..0000000 --- a/app/src/board/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/one_conduction_main.c b/app/src/one_conduction_main.c index e41948e..e5e4b1d 100644 --- a/app/src/one_conduction_main.c +++ b/app/src/one_conduction_main.c @@ -136,12 +136,12 @@ void one_conduction_process_rx_packet(uint8_t* rx, int len) { receipt->drop_state0 = (0); receipt->drop_state1 = 0x00; receipt->device_state0.sampling_state = (zapp_state_machine_now_state() == kdevice_state_sampling); - receipt->device_state0.preview_state = zapp_get_gstate()->is_preview; - receipt->device_state0.low_battery = (BatteryMgrService_get_battery_level() < APP_LOW_BATTERY_WARNING_LIMIT); + receipt->device_state0.report_state = 0; + receipt->device_state0.low_battery = (0 < APP_LOW_BATTERY_WARNING_LIMIT); receipt->device_state0.full_storge = false; receipt->device_state1 = 0; - receipt->powerlevel = BatteryMgrService_get_battery_level(); + receipt->powerlevel = battery_mgr_service_get_battery_level(); receipt->storage_item_num = 0; zdatachannel_data_send2(bletxbuf, sendlen);