From bd407ece98dc6cf6df2caf1c367a0231b1e59898 Mon Sep 17 00:00:00 2001 From: acevest Date: Tue, 1 Oct 2019 17:18:54 +0800 Subject: [PATCH 01/10] add usart0, printf support for GD32VF103C_START board --- board/GD32VF103C_START/BSP/Inc/mcu_init.h | 9 ++ board/GD32VF103C_START/BSP/Inc/usart.h | 10 ++ board/GD32VF103C_START/BSP/Src/mcu_init.c | 11 ++ board/GD32VF103C_START/BSP/Src/usart.c | 30 +++++ .../eclipse/hello_world/.cproject | 2 + .../eclipse/hello_world/.project | 10 ++ .../.settings/language.settings.xml | 2 +- .../eclipse/hello_world/main.c | 124 ++++++++++-------- 8 files changed, 139 insertions(+), 59 deletions(-) create mode 100644 board/GD32VF103C_START/BSP/Inc/mcu_init.h create mode 100644 board/GD32VF103C_START/BSP/Inc/usart.h create mode 100644 board/GD32VF103C_START/BSP/Src/mcu_init.c create mode 100644 board/GD32VF103C_START/BSP/Src/usart.c diff --git a/board/GD32VF103C_START/BSP/Inc/mcu_init.h b/board/GD32VF103C_START/BSP/Inc/mcu_init.h new file mode 100644 index 00000000..7f906dd8 --- /dev/null +++ b/board/GD32VF103C_START/BSP/Inc/mcu_init.h @@ -0,0 +1,9 @@ +#ifndef __MCU_INIT_H +#define __MCU_INIT_H + +#include "gd32vf103.h" +#include "usart.h" + +void board_init(); + +#endif //__MCU_INIT_H diff --git a/board/GD32VF103C_START/BSP/Inc/usart.h b/board/GD32VF103C_START/BSP/Inc/usart.h new file mode 100644 index 00000000..bb5f1594 --- /dev/null +++ b/board/GD32VF103C_START/BSP/Inc/usart.h @@ -0,0 +1,10 @@ +#ifndef __USART_H +#define __USART_H + +#define USART0_GPIO_TX_PIN GPIO_PIN_9 +#define USART0_GPIO_RX_PIN GPIO_PIN_10 +#define USART0_GPIO_PORT GPIOA + +void usart0_init(int baud); + +#endif // __USART_H diff --git a/board/GD32VF103C_START/BSP/Src/mcu_init.c b/board/GD32VF103C_START/BSP/Src/mcu_init.c new file mode 100644 index 00000000..d6e2ddaf --- /dev/null +++ b/board/GD32VF103C_START/BSP/Src/mcu_init.c @@ -0,0 +1,11 @@ +#include "mcu_init.h" + +void board_init() { + rcu_periph_clock_enable(RCU_GPIOA); + + gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7); + + gpio_bit_reset(GPIOA, GPIO_PIN_7); + + usart0_init(115200); +} diff --git a/board/GD32VF103C_START/BSP/Src/usart.c b/board/GD32VF103C_START/BSP/Src/usart.c new file mode 100644 index 00000000..5c809db1 --- /dev/null +++ b/board/GD32VF103C_START/BSP/Src/usart.c @@ -0,0 +1,30 @@ +#include "gd32vf103.h" +#include "usart.h" +void usart0_init(int baud) +{ + uint32_t com = USART0; + + /* enable GPIO clock */ + rcu_periph_clock_enable(RCU_GPIOA); + + /* enable USART clock */ + rcu_periph_clock_enable(RCU_USART0); + + /* connect port to USARTx_Tx */ + gpio_init(USART0_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART0_GPIO_TX_PIN); + + /* connect port to USARTx_Rx */ + gpio_init(USART0_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART0_GPIO_RX_PIN); + + /* USART configure */ + usart_deinit(com); + usart_baudrate_set(com, baud); + usart_word_length_set(com, USART_WL_8BIT); + usart_stop_bit_set(com, USART_STB_1BIT); + usart_parity_config(com, USART_PM_NONE); + usart_hardware_flow_rts_config(com, USART_RTS_DISABLE); + usart_hardware_flow_cts_config(com, USART_CTS_DISABLE); + usart_receive_config(com, USART_RECEIVE_ENABLE); + usart_transmit_config(com, USART_TRANSMIT_ENABLE); + usart_enable(com); +} diff --git a/board/GD32VF103C_START/eclipse/hello_world/.cproject b/board/GD32VF103C_START/eclipse/hello_world/.cproject index f8d3eea4..33bcd505 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.cproject +++ b/board/GD32VF103C_START/eclipse/hello_world/.cproject @@ -144,6 +144,8 @@ + + diff --git a/board/GD32VF103C_START/eclipse/hello_world/.project b/board/GD32VF103C_START/eclipse/hello_world/.project index 646d74fd..bda85e3d 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.project +++ b/board/GD32VF103C_START/eclipse/hello_world/.project @@ -39,6 +39,16 @@ 2 virtual:/virtual + + Application/Inc + 2 + TOP_DIR/board/GD32VF103C_START/BSP/Inc + + + Application/Src + 2 + TOP_DIR/board/GD32VF103C_START/BSP/Src + Application/tos_config.h 1 diff --git a/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml b/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml index 140cae41..1c9fb7ba 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml +++ b/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml @@ -11,7 +11,7 @@ - + diff --git a/board/GD32VF103C_START/eclipse/hello_world/main.c b/board/GD32VF103C_START/eclipse/hello_world/main.c index 67072343..1c411df4 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/main.c +++ b/board/GD32VF103C_START/eclipse/hello_world/main.c @@ -1,58 +1,66 @@ -#include "gd32vf103.h" -#include "tos.h" - -#define TASK_SIZE 512 -k_task_t k_task_task1; -k_task_t k_task_task2; -uint8_t k_task1_stk[TASK_SIZE]; -uint8_t k_task2_stk[TASK_SIZE]; - -int share = 0xCBA7F9; -k_sem_t sem; - -void task1(void *pdata) -{ - int task_cnt1 = 0; - while (1) { - task_cnt1++; - tos_sem_pend(&sem, ~0U); - gpio_bit_write(GPIOA, GPIO_PIN_7, share % 2); - } -} - -void task2(void *pdata) -{ - int task_cnt2 = 0; - while (1) { - task_cnt2--; - share++; - tos_task_delay(1000); - tos_sem_post(&sem); - } -} - - -void main(void) { - rcu_periph_clock_enable(RCU_GPIOA); - - gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7); - - gpio_bit_reset(GPIOA, GPIO_PIN_7); - - tos_knl_init(); - - tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0); - tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0); - - k_err_t err = tos_sem_create(&sem, 1); - if (err != K_ERR_NONE) { - goto die; - } - - tos_knl_start(); - -die: - while (1) { - asm("wfi;"); - } -} +#include "mcu_init.h" +#include "tos.h" + +#define TASK_SIZE 1024 +k_task_t k_task_task1; +k_task_t k_task_task2; +uint8_t k_task1_stk[TASK_SIZE]; +uint8_t k_task2_stk[TASK_SIZE]; + +int share = 0xCBA7F9; +k_sem_t sem; + +void task1(void *pdata) +{ + int task_cnt1 = 0; + while (1) { + printf("hello world from %s cnt: %d\n", __func__, task_cnt1++); + tos_sem_pend(&sem, ~0U); + gpio_bit_write(GPIOA, GPIO_PIN_7, share % 2); + } +} + +void task2(void *pdata) +{ + int task_cnt2 = 0; + while (1) { + share++; + for(int i=0; i<5; i++) { + printf("hello world from %s cnt: %08x\n", __func__, task_cnt2--); + tos_task_delay(200); + } + tos_sem_post(&sem); + } +} + + +void main(void) { + board_init(); + + tos_knl_init(); + + tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0); + tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0); + + k_err_t err = tos_sem_create(&sem, 1); + if (err != K_ERR_NONE) { + goto die; + } + + tos_knl_start(); + +die: + while (1) { + asm("wfi;"); + } +} + + +int _put_char(int ch) +{ + usart_data_transmit(USART0, (uint8_t) ch ); + while (usart_flag_get(USART0, USART_FLAG_TBE)== RESET){ + } + + return ch; +} From 3c88162700b95a41ce3c2e74523fbaa293b0bbd9 Mon Sep 17 00:00:00 2001 From: acevest Date: Wed, 2 Oct 2019 11:05:04 +0800 Subject: [PATCH 02/10] move usart0_init to main --- board/GD32VF103C_START/BSP/Src/mcu_init.c | 2 - .../eclipse/hello_world/main.c | 44 ++++++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/board/GD32VF103C_START/BSP/Src/mcu_init.c b/board/GD32VF103C_START/BSP/Src/mcu_init.c index d6e2ddaf..57aa3861 100644 --- a/board/GD32VF103C_START/BSP/Src/mcu_init.c +++ b/board/GD32VF103C_START/BSP/Src/mcu_init.c @@ -6,6 +6,4 @@ void board_init() { gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7); gpio_bit_reset(GPIOA, GPIO_PIN_7); - - usart0_init(115200); } diff --git a/board/GD32VF103C_START/eclipse/hello_world/main.c b/board/GD32VF103C_START/eclipse/hello_world/main.c index 1c411df4..7248fd36 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/main.c +++ b/board/GD32VF103C_START/eclipse/hello_world/main.c @@ -12,47 +12,49 @@ k_sem_t sem; void task1(void *pdata) { - int task_cnt1 = 0; - while (1) { - printf("hello world from %s cnt: %d\n", __func__, task_cnt1++); - tos_sem_pend(&sem, ~0U); - gpio_bit_write(GPIOA, GPIO_PIN_7, share % 2); - } + int task_cnt1 = 0; + while (1) { + printf("hello world from %s cnt: %d\n", __func__, task_cnt1++); + tos_sem_pend(&sem, ~0U); + gpio_bit_write(GPIOA, GPIO_PIN_7, share % 2); + } } void task2(void *pdata) { - int task_cnt2 = 0; - while (1) { + int task_cnt2 = 0; + while (1) { share++; for(int i=0; i<5; i++) { printf("hello world from %s cnt: %08x\n", __func__, task_cnt2--); tos_task_delay(200); } - tos_sem_post(&sem); - } + tos_sem_post(&sem); + } } void main(void) { board_init(); - tos_knl_init(); + usart0_init(115200); - tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0); - tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0); + tos_knl_init(); - k_err_t err = tos_sem_create(&sem, 1); - if (err != K_ERR_NONE) { - goto die; - } + tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0); + tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0); - tos_knl_start(); + k_err_t err = tos_sem_create(&sem, 1); + if (err != K_ERR_NONE) { + goto die; + } + + tos_knl_start(); die: - while (1) { - asm("wfi;"); - } + while (1) { + asm("wfi;"); + } } From 3ef8f4eae5d4d913c46e63c85553d456bdd988fe Mon Sep 17 00:00:00 2001 From: acevest Date: Wed, 2 Oct 2019 16:41:23 +0800 Subject: [PATCH 03/10] detach risc-v kernel code from gd32v lib --- arch/risc-v/common/tos_cpu.c | 3 +-- arch/risc-v/rv32i/gcc/port_c.c | 1 - arch/risc-v/rv32i/gcc/port_s.S | 9 +++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/risc-v/common/tos_cpu.c b/arch/risc-v/common/tos_cpu.c index 366f9b26..d841eef6 100644 --- a/arch/risc-v/common/tos_cpu.c +++ b/arch/risc-v/common/tos_cpu.c @@ -1,5 +1,4 @@ #include -#include #include __KERNEL__ void cpu_systick_init(k_cycle_t cycle_per_tick) @@ -107,7 +106,7 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, regs->gp = (cpu_data_t)gp; // gp: global pointer regs->a0 = (cpu_data_t)arg; // a0: argument regs->ra = (cpu_data_t)0xACE00ACE; // ra: return address - regs->mstatus = (cpu_data_t)(MSTATUS_MPP | MSTATUS_MPIE); // return to machine mode and enable interrupt + regs->mstatus = (cpu_data_t)0x00001880; // return to machine mode and enable interrupt regs->epc = (cpu_data_t)entry; diff --git a/arch/risc-v/rv32i/gcc/port_c.c b/arch/risc-v/rv32i/gcc/port_c.c index 4ed13159..c53a1f80 100644 --- a/arch/risc-v/rv32i/gcc/port_c.c +++ b/arch/risc-v/rv32i/gcc/port_c.c @@ -1,5 +1,4 @@ #include -#include "riscv_encoding.h" #include "riscv_port.h" __PORT__ void port_systick_config(uint32_t cycle_per_tick) diff --git a/arch/risc-v/rv32i/gcc/port_s.S b/arch/risc-v/rv32i/gcc/port_s.S index 36ee2952..addd2981 100644 --- a/arch/risc-v/rv32i/gcc/port_s.S +++ b/arch/risc-v/rv32i/gcc/port_s.S @@ -15,8 +15,14 @@ .extern k_curr_task .extern k_next_task +#define MSTATUS_MIE 0x00000008 +#define MSTATUS_MPP 0x00001800 -#include "riscv_encoding.h" +#define MIE_MTIE (1 << 7) + +#define MIP_MTIP (1 << 7) + +#define REGBYTES 4 .text .align 2 @@ -59,7 +65,6 @@ port_systick_pending_reset: csrc mip, t0 ret -#define REGBYTES 4 .macro SAVE_CONTEXT addi sp, sp, -32*REGBYTES From a52bb94ed241c19eee517bfc0843e2143262fd6f Mon Sep 17 00:00:00 2001 From: acevest Date: Thu, 3 Oct 2019 15:01:46 +0800 Subject: [PATCH 04/10] initialize the clock tree of GD32VF103C_START to 108MHz --- arch/risc-v/bumblebee/gcc/riscv_port_c.c | 15 +++--- board/GD32VF103C_START/BSP/Src/mcu_init.c | 3 ++ .../GD32VF103C_START/TOS_CONFIG/tos_config.h | 48 +++++++++++++------ 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/arch/risc-v/bumblebee/gcc/riscv_port_c.c b/arch/risc-v/bumblebee/gcc/riscv_port_c.c index 2618918b..4ab8902d 100644 --- a/arch/risc-v/bumblebee/gcc/riscv_port_c.c +++ b/arch/risc-v/bumblebee/gcc/riscv_port_c.c @@ -1,4 +1,5 @@ -#include "tos.h" +#include +#include #define ECLIC_ADDR_BASE 0xD2000000 #define CLIC_INT_TMR 0x07 @@ -18,18 +19,18 @@ #define ECLIC_CFG_NLBITS_LSB 1 -static uint8_t elci_get_clic_int_ctl_bits() { +static uint8_t eclic_get_clic_int_ctl_bits() { uint32_t bits = *(volatile uint32_t*)(ECLIC_ADDR_BASE+ECLIC_INFO_OFFSET); bits >>= 21; return (uint8_t) bits; } -static uint8_t elci_get_nlbits() { +static uint8_t eclic_get_nlbits() { uint8_t nlbits = *(volatile uint8_t*)(ECLIC_ADDR_BASE+ECLIC_CFG_OFFSET); nlbits = (nlbits & ECLIC_CFG_NLBITS_MASK) >> ECLIC_CFG_NLBITS_LSB; - uint8_t cicbits = elci_get_clic_int_ctl_bits(); + uint8_t cicbits = eclic_get_clic_int_ctl_bits(); if(nlbits > cicbits) { nlbits = cicbits; } @@ -51,7 +52,7 @@ static void eclic_enable_interrupt(uint32_t source) { } static void eclic_set_irq_level(uint32_t source, uint8_t level) { - uint8_t nlbits = elci_get_nlbits(); + uint8_t nlbits = eclic_get_nlbits(); if (nlbits == 0) { return ; @@ -67,8 +68,8 @@ static void eclic_set_irq_level(uint32_t source, uint8_t level) { } static void eclic_set_irq_priority(uint32_t source, uint8_t priority) { - uint8_t nlbits = elci_get_nlbits(); - uint8_t cicbits= elci_get_clic_int_ctl_bits(); + uint8_t nlbits = eclic_get_nlbits(); + uint8_t cicbits= eclic_get_clic_int_ctl_bits(); if (nlbits >= cicbits) { return ; diff --git a/board/GD32VF103C_START/BSP/Src/mcu_init.c b/board/GD32VF103C_START/BSP/Src/mcu_init.c index 57aa3861..5bd037cb 100644 --- a/board/GD32VF103C_START/BSP/Src/mcu_init.c +++ b/board/GD32VF103C_START/BSP/Src/mcu_init.c @@ -1,6 +1,9 @@ #include "mcu_init.h" void board_init() { + + SystemInit(); + rcu_periph_clock_enable(RCU_GPIOA); gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7); diff --git a/board/GD32VF103C_START/TOS_CONFIG/tos_config.h b/board/GD32VF103C_START/TOS_CONFIG/tos_config.h index f9b6b070..939447d3 100644 --- a/board/GD32VF103C_START/TOS_CONFIG/tos_config.h +++ b/board/GD32VF103C_START/TOS_CONFIG/tos_config.h @@ -1,27 +1,38 @@ #ifndef INC_TOS_CONFIG_H_ #define INC_TOS_CONFIG_H_ +#include "gd32vf103.h" #include "stddef.h" -#define TOS_CFG_TASK_PRIO_MAX 10u // 配置TencentOS tiny默认支持的最大优先级数量 +// 配置TencentOS tiny默认支持的最大优先级数量 +#define TOS_CFG_TASK_PRIO_MAX 10u -#define TOS_CFG_ROUND_ROBIN_EN 0u // 配置TencentOS tiny的内核是否开启时间片轮转 +// 配置TencentOS tiny的内核是否开启时间片轮转 +#define TOS_CFG_ROUND_ROBIN_EN 0u -#define TOS_CFG_OBJECT_VERIFY 0u // 配置TencentOS tiny是否校验指针合法 +// 配置TencentOS tiny是否校验指针合法 +#define TOS_CFG_OBJECT_VERIFY 0u -#define TOS_CFG_EVENT_EN 1u // TencentOS tiny 事件模块功能宏 +// TencentOS tiny 事件模块功能宏 +#define TOS_CFG_EVENT_EN 1u -#define TOS_CFG_MMHEAP_EN 1u // 配置TencentOS tiny是否开启动态内存模块 +// 配置TencentOS tiny是否开启动态内存模块 +#define TOS_CFG_MMHEAP_EN 1u -#define TOS_CFG_MMHEAP_POOL_SIZE 8192 // 配置TencentOS tiny动态内存池大小 +// 配置TencentOS tiny动态内存池大小 +#define TOS_CFG_MMHEAP_POOL_SIZE 8192 -#define TOS_CFG_MUTEX_EN 1u // 配置TencentOS tiny是否开启互斥锁模块 +// 配置TencentOS tiny是否开启互斥锁模块 +#define TOS_CFG_MUTEX_EN 1u -#define TOS_CFG_QUEUE_EN 1u // 配置TencentOS tiny是否开启队列模块 +// 配置TencentOS tiny是否开启队列模块 +#define TOS_CFG_QUEUE_EN 1u -#define TOS_CFG_TIMER_EN 0u // 配置TencentOS tiny是否开启软件定时器模块 +// 配置TencentOS tiny是否开启软件定时器模块 +#define TOS_CFG_TIMER_EN 0u -#define TOS_CFG_SEM_EN 1u // 配置TencentOS tiny是否开启信号量模块 +// 配置TencentOS tiny是否开启信号量模块 +#define TOS_CFG_SEM_EN 1u #define TOS_CFG_CPU_SYSTICK_PRIO 0xF @@ -31,15 +42,22 @@ #define TOS_CFG_MSG_EN 0u #endif -#define TOS_CFG_MSG_POOL_SIZE 10u // 配置TencentOS tiny消息队列大小 +// 配置TencentOS tiny消息队列大小 +#define TOS_CFG_MSG_POOL_SIZE 10u -#define TOS_CFG_IDLE_TASK_STK_SIZE 512u // 配置TencentOS tiny空闲任务栈大小 +// 配置TencentOS tiny空闲任务栈大小 +#define TOS_CFG_IDLE_TASK_STK_SIZE 512u -#define TOS_CFG_CPU_TICK_PER_SECOND 1000u // 配置TencentOS tiny的tick频率 +// 配置TencentOS tiny的tick频率 +#define TOS_CFG_CPU_TICK_PER_SECOND 1000u -#define TOS_CFG_CPU_CLOCK (108000000/4) // 配置TencentOS tiny CPU频率 +// 配置TencentOS tiny CPU频率 +// 除4的原因是,Bumblebee内核通过core_clk_aon四分频来更新mtime寄存器 +// 具体信息参见《Bumblebee内核简明数据手册》 +#define TOS_CFG_CPU_CLOCK (SystemCoreClock/4) -#define TOS_CFG_TIMER_AS_PROC 1u // 配置是否将TIMER配置成函数模式 +// 配置是否将TIMER配置成函数模式 +#define TOS_CFG_TIMER_AS_PROC 1u #define TOS_CFG_VFS_EN 1u From 2e225ac46d0c9058efbe8a4fe7aedd8a695972a3 Mon Sep 17 00:00:00 2001 From: acevest Date: Fri, 4 Oct 2019 12:33:40 +0800 Subject: [PATCH 05/10] fix typo --- board/GD32VF103C_START/BSP/Src/usart.c | 30 ++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/board/GD32VF103C_START/BSP/Src/usart.c b/board/GD32VF103C_START/BSP/Src/usart.c index 5c809db1..9d6c0d6f 100644 --- a/board/GD32VF103C_START/BSP/Src/usart.c +++ b/board/GD32VF103C_START/BSP/Src/usart.c @@ -2,29 +2,27 @@ #include "usart.h" void usart0_init(int baud) { - uint32_t com = USART0; - /* enable GPIO clock */ rcu_periph_clock_enable(RCU_GPIOA); - /* enable USART clock */ + /* enable USART0 clock */ rcu_periph_clock_enable(RCU_USART0); - /* connect port to USARTx_Tx */ + /* connect port to USART0_Tx */ gpio_init(USART0_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART0_GPIO_TX_PIN); - /* connect port to USARTx_Rx */ + /* connect port to USART0_Rx */ gpio_init(USART0_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART0_GPIO_RX_PIN); - /* USART configure */ - usart_deinit(com); - usart_baudrate_set(com, baud); - usart_word_length_set(com, USART_WL_8BIT); - usart_stop_bit_set(com, USART_STB_1BIT); - usart_parity_config(com, USART_PM_NONE); - usart_hardware_flow_rts_config(com, USART_RTS_DISABLE); - usart_hardware_flow_cts_config(com, USART_CTS_DISABLE); - usart_receive_config(com, USART_RECEIVE_ENABLE); - usart_transmit_config(com, USART_TRANSMIT_ENABLE); - usart_enable(com); + /* USART0 configure */ + usart_deinit(USART0); + usart_baudrate_set(USART0, baud); + usart_word_length_set(USART0, USART_WL_8BIT); + usart_stop_bit_set(USART0, USART_STB_1BIT); + usart_parity_config(USART0, USART_PM_NONE); + usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE); + usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE); + usart_receive_config(USART0, USART_RECEIVE_ENABLE); + usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); + usart_enable(USART0); } From d22f427dcbf8d5a2bf6d6bce8e6a4faa4d6678c4 Mon Sep 17 00:00:00 2001 From: IllusionLee <1115451437@qq.com> Date: Fri, 4 Oct 2019 16:50:14 +0800 Subject: [PATCH 06/10] Fix warning about oledfont.h with 'missing braces around initializer'. --- .../BSP/Hardware/OLED/oledfont.h | 184 +++++++++--------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oledfont.h b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oledfont.h index b2f658c4..7d6675cc 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oledfont.h +++ b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oledfont.h @@ -8,98 +8,98 @@ /************************************6*8ĵ************************************/ const unsigned char F6x8[][6] = { -0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp -0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// ! -0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// " -0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// # -0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $ -0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// % -0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// & -0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ' -0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// ( -0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// ) -0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// * -0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// + -0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// , -0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// - -0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// . -0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// / -0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 -0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 -0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2 -0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 -0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 -0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5 -0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 -0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7 -0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8 -0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 -0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// : -0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ; -0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// < -0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// = -0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// > -0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ? -0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @ -0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A -0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B -0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C -0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D -0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E -0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F -0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G -0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H -0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I -0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J -0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K -0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L -0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M -0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N -0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O -0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P -0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q -0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R -0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S -0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T -0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U -0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V -0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W -0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X -0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y -0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z -0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [ -0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55 -0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ] -0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^ -0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _ -0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// ' -0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a -0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b -0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c -0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d -0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e -0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f -0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g -0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h -0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i -0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j -0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k -0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l -0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m -0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n -0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o -0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p -0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q -0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r -0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s -0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t -0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u -0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v -0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w -0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x -0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y -0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z -0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines +{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// sp +{0x00, 0x00, 0x00, 0x2f, 0x00, 0x00},// ! +{0x00, 0x00, 0x07, 0x00, 0x07, 0x00},// " +{0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14},// # +{0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12},// $ +{0x00, 0x62, 0x64, 0x08, 0x13, 0x23},// % +{0x00, 0x36, 0x49, 0x55, 0x22, 0x50},// & +{0x00, 0x00, 0x05, 0x03, 0x00, 0x00},// ' +{0x00, 0x00, 0x1c, 0x22, 0x41, 0x00},// ( +{0x00, 0x00, 0x41, 0x22, 0x1c, 0x00},// ) +{0x00, 0x14, 0x08, 0x3E, 0x08, 0x14},// * +{0x00, 0x08, 0x08, 0x3E, 0x08, 0x08},// + +{0x00, 0x00, 0x00, 0xA0, 0x60, 0x00},// , +{0x00, 0x08, 0x08, 0x08, 0x08, 0x08},// - +{0x00, 0x00, 0x60, 0x60, 0x00, 0x00},// . +{0x00, 0x20, 0x10, 0x08, 0x04, 0x02},// / +{0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E},// 0 +{0x00, 0x00, 0x42, 0x7F, 0x40, 0x00},// 1 +{0x00, 0x42, 0x61, 0x51, 0x49, 0x46},// 2 +{0x00, 0x21, 0x41, 0x45, 0x4B, 0x31},// 3 +{0x00, 0x18, 0x14, 0x12, 0x7F, 0x10},// 4 +{0x00, 0x27, 0x45, 0x45, 0x45, 0x39},// 5 +{0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30},// 6 +{0x00, 0x01, 0x71, 0x09, 0x05, 0x03},// 7 +{0x00, 0x36, 0x49, 0x49, 0x49, 0x36},// 8 +{0x00, 0x06, 0x49, 0x49, 0x29, 0x1E},// 9 +{0x00, 0x00, 0x36, 0x36, 0x00, 0x00},// : +{0x00, 0x00, 0x56, 0x36, 0x00, 0x00},// ; +{0x00, 0x08, 0x14, 0x22, 0x41, 0x00},// < +{0x00, 0x14, 0x14, 0x14, 0x14, 0x14},// = +{0x00, 0x00, 0x41, 0x22, 0x14, 0x08},// > +{0x00, 0x02, 0x01, 0x51, 0x09, 0x06},// ? +{0x00, 0x32, 0x49, 0x59, 0x51, 0x3E},// @ +{0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C},// A +{0x00, 0x7F, 0x49, 0x49, 0x49, 0x36},// B +{0x00, 0x3E, 0x41, 0x41, 0x41, 0x22},// C +{0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C},// D +{0x00, 0x7F, 0x49, 0x49, 0x49, 0x41},// E +{0x00, 0x7F, 0x09, 0x09, 0x09, 0x01},// F +{0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A},// G +{0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F},// H +{0x00, 0x00, 0x41, 0x7F, 0x41, 0x00},// I +{0x00, 0x20, 0x40, 0x41, 0x3F, 0x01},// J +{0x00, 0x7F, 0x08, 0x14, 0x22, 0x41},// K +{0x00, 0x7F, 0x40, 0x40, 0x40, 0x40},// L +{0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F},// M +{0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F},// N +{0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E},// O +{0x00, 0x7F, 0x09, 0x09, 0x09, 0x06},// P +{0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E},// Q +{0x00, 0x7F, 0x09, 0x19, 0x29, 0x46},// R +{0x00, 0x46, 0x49, 0x49, 0x49, 0x31},// S +{0x00, 0x01, 0x01, 0x7F, 0x01, 0x01},// T +{0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F},// U +{0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F},// V +{0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F},// W +{0x00, 0x63, 0x14, 0x08, 0x14, 0x63},// X +{0x00, 0x07, 0x08, 0x70, 0x08, 0x07},// Y +{0x00, 0x61, 0x51, 0x49, 0x45, 0x43},// Z +{0x00, 0x00, 0x7F, 0x41, 0x41, 0x00},// [ +{0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55},// 55 +{0x00, 0x00, 0x41, 0x41, 0x7F, 0x00},// ] +{0x00, 0x04, 0x02, 0x01, 0x02, 0x04},// ^ +{0x00, 0x40, 0x40, 0x40, 0x40, 0x40},// _ +{0x00, 0x00, 0x01, 0x02, 0x04, 0x00},// ' +{0x00, 0x20, 0x54, 0x54, 0x54, 0x78},// a +{0x00, 0x7F, 0x48, 0x44, 0x44, 0x38},// b +{0x00, 0x38, 0x44, 0x44, 0x44, 0x20},// c +{0x00, 0x38, 0x44, 0x44, 0x48, 0x7F},// d +{0x00, 0x38, 0x54, 0x54, 0x54, 0x18},// e +{0x00, 0x08, 0x7E, 0x09, 0x01, 0x02},// f +{0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C},// g +{0x00, 0x7F, 0x08, 0x04, 0x04, 0x78},// h +{0x00, 0x00, 0x44, 0x7D, 0x40, 0x00},// i +{0x00, 0x40, 0x80, 0x84, 0x7D, 0x00},// j +{0x00, 0x7F, 0x10, 0x28, 0x44, 0x00},// k +{0x00, 0x00, 0x41, 0x7F, 0x40, 0x00},// l +{0x00, 0x7C, 0x04, 0x18, 0x04, 0x78},// m +{0x00, 0x7C, 0x08, 0x04, 0x04, 0x78},// n +{0x00, 0x38, 0x44, 0x44, 0x44, 0x38},// o +{0x00, 0xFC, 0x24, 0x24, 0x24, 0x18},// p +{0x00, 0x18, 0x24, 0x24, 0x18, 0xFC},// q +{0x00, 0x7C, 0x08, 0x04, 0x04, 0x08},// r +{0x00, 0x48, 0x54, 0x54, 0x54, 0x20},// s +{0x00, 0x04, 0x3F, 0x44, 0x40, 0x20},// t +{0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C},// u +{0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C},// v +{0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C},// w +{0x00, 0x44, 0x28, 0x10, 0x28, 0x44},// x +{0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C},// y +{0x00, 0x44, 0x64, 0x54, 0x4C, 0x44},// z +{0x14, 0x14, 0x14, 0x14, 0x14, 0x14},// horiz lines }; /****************************************8*16ĵ************************************/ const unsigned char F8X16[]= From 6dd262ac09e9ab6444aa9400ab5587b36d4899e3 Mon Sep 17 00:00:00 2001 From: IllusionLee <1115451437@qq.com> Date: Fri, 4 Oct 2019 16:55:16 +0800 Subject: [PATCH 07/10] Fix warning about E53_IA1.c with 'array subscript has type char'. --- board/TencentOS_tiny_EVB_MX/BSP/Hardware/E53_IA1/E53_IA1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/E53_IA1/E53_IA1.c b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/E53_IA1/E53_IA1.c index 00415d6e..01882a75 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/E53_IA1/E53_IA1.c +++ b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/E53_IA1/E53_IA1.c @@ -91,7 +91,7 @@ uint8_t SHT3x_CheckCrc(char data[], char nbrOfBytes, char checksum) char crc = 0xFF; char bit = 0; - char byteCtr ; + unsigned char byteCtr; //calculates 8-Bit checksum with given polynomial for(byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr) From 3d5b7bd6a15e77cfd9c7667fc22a8f6420af8ec3 Mon Sep 17 00:00:00 2001 From: IllusionLee <1115451437@qq.com> Date: Fri, 4 Oct 2019 16:59:14 +0800 Subject: [PATCH 08/10] Fix warning about oled.c with 'this for clause does not guard'. --- board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c index 33c36183..3418797e 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c +++ b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c @@ -179,8 +179,10 @@ void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size) { OLED_Set_Pos(x,y); for(i=0;i<8;i++) + { OLED_WR_Byte(F8X16[c*16+i],OLED_DATA); - OLED_Set_Pos(x,y+1); + } + OLED_Set_Pos(x,y+1); for(i=0;i<8;i++) OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA); } From dba0bcf45247bfb21e8aef372f5d65a68d96ac22 Mon Sep 17 00:00:00 2001 From: IllusionLee <1115451437@qq.com> Date: Fri, 4 Oct 2019 17:23:41 +0800 Subject: [PATCH 09/10] Fix garbled code about bmp.h oled.c oled.h oledfont.h . --- .../BSP/Hardware/OLED/bmp.h | 6 +- .../BSP/Hardware/OLED/oled.c | 195 +++++++++--------- .../BSP/Hardware/OLED/oled.h | 34 ++- .../BSP/Hardware/OLED/oledfont.h | 46 ++--- 4 files changed, 138 insertions(+), 143 deletions(-) diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/bmp.h b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/bmp.h index 0775126f..9c852fa4 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/bmp.h +++ b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/bmp.h @@ -1,7 +1,7 @@ -////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////// // // -//洢ͼƬݣͼƬСΪ64*32 +//存储图片数据,图片大小为64*32像素 // ///////////////////////////////////////////////////////////////////////////////// @@ -71,7 +71,7 @@ unsigned char BMP1[] = 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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x40,0x40, -0x40,0x50,0x20,0x5F,0x80,0x00,0x1F,0x20,0x40,0x40,0x40,0x50,0x20,0x5F,0x80,0x00,/*"C:\Users\evk\Desktop\??2014.bmp",0*/ +0x40,0x50,0x20,0x5F,0x80,0x00,0x1F,0x20,0x40,0x40,0x40,0x50,0x20,0x5F,0x80,0x00, }; diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c index 3418797e..44b67bae 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c +++ b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c @@ -1,15 +1,15 @@ #include "oled.h" #include "stdlib.h" -#include "oledfont.h" -//OLEDԴ -//Ÿʽ. +#include "oledfont.h" +//OLED的显存 +//存放格式如下. //----------------------------------- -//|x[0,127] | -//| OLEDʾ | -//|y Χ | -//| | +//|x→[0,127] | +//| OLED显示坐标 | +//|y 范围 | +//|↓ | //|[0,31] | -//----------------------------------- +//----------------------------------- /********************************************** //IIC Start **********************************************/ @@ -46,7 +46,7 @@ void Write_IIC_Byte(unsigned char IIC_Byte) unsigned char m,da; da=IIC_Byte; OLED_SCLK_Clr(); - for(i=0;i<8;i++) + for(i=0;i<8;i++) { m=da; m=m&0x80; @@ -54,7 +54,7 @@ void Write_IIC_Byte(unsigned char IIC_Byte) { OLED_SDIN_Set(); } - else + else OLED_SDIN_Clr(); da=da<<1; OLED_SCLK_Set(); @@ -68,11 +68,11 @@ void Write_IIC_Command(unsigned char IIC_Command) { IIC_Start(); Write_IIC_Byte(0x78); //Slave address,SA0=0 - IIC_Wait_Ack(); + IIC_Wait_Ack(); Write_IIC_Byte(0x00); //write command - IIC_Wait_Ack(); - Write_IIC_Byte(IIC_Command); - IIC_Wait_Ack(); + IIC_Wait_Ack(); + Write_IIC_Byte(IIC_Command); + IIC_Wait_Ack(); IIC_Stop(); } /********************************************** @@ -82,11 +82,11 @@ void Write_IIC_Data(unsigned char IIC_Data) { IIC_Start(); Write_IIC_Byte(0x78); //D/C#=0; R/W#=0 - IIC_Wait_Ack(); + IIC_Wait_Ack(); Write_IIC_Byte(0x40); //write data - IIC_Wait_Ack(); + IIC_Wait_Ack(); Write_IIC_Byte(IIC_Data); - IIC_Wait_Ack(); + IIC_Wait_Ack(); IIC_Stop(); } void OLED_WR_Byte(unsigned dat,unsigned cmd) @@ -95,9 +95,9 @@ void OLED_WR_Byte(unsigned dat,unsigned cmd) { Write_IIC_Data(dat); } - else + else { - Write_IIC_Command(dat); + Write_IIC_Command(dat); } } @@ -120,96 +120,97 @@ void fill_picture(unsigned char fill_Data) } } -// -void OLED_Set_Pos(unsigned char x, unsigned char y) -{ +//坐标设置 +void OLED_Set_Pos(unsigned char x, unsigned char y) +{ OLED_WR_Byte(0xb0+y,OLED_CMD); OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD); - OLED_WR_Byte((x&0x0f),OLED_CMD); -} -//OLEDʾ + OLED_WR_Byte((x&0x0f),OLED_CMD); +} +//开启OLED显示 void OLED_Display_On(void) { - OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC + OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON } -//رOLEDʾ +//关闭OLED显示 void OLED_Display_Off(void) { - OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC + OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF -} -//ע⣺,,ĻǺɫ!ûһ!!! -void OLED_Clear(void) -{ - uint8_t i,n; - for(i=0;i<8;i++) - { - OLED_WR_Byte (0xb0+i,OLED_CMD); //ҳַ0~7 - OLED_WR_Byte (0x00,OLED_CMD); //ʾλáе͵ַ - OLED_WR_Byte (0x10,OLED_CMD); //ʾλáиߵַ +} +//注意:清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!! +void OLED_Clear(void) +{ + uint8_t i,n; + for(i=0;i<8;i++) + { + OLED_WR_Byte (0xb0+i,OLED_CMD); //设置页地址(0~7) + OLED_WR_Byte (0x00,OLED_CMD); //设置显示位置—列低地址 + OLED_WR_Byte (0x10,OLED_CMD); //设置显示位置—列高地址 for(n=0;n<128;n++) - OLED_WR_Byte(0,OLED_DATA); - } //ʾ + OLED_WR_Byte(0,OLED_DATA); + } //更新显示 } -void OLED_On(void) -{ - uint8_t i,n; - for(i=0;i<8;i++) - { - OLED_WR_Byte (0xb0+i,OLED_CMD); //ҳַ0~7 - OLED_WR_Byte (0x00,OLED_CMD); //ʾλáе͵ַ - OLED_WR_Byte (0x10,OLED_CMD); //ʾλáиߵַ - for(n=0;n<128;n++)OLED_WR_Byte(1,OLED_DATA); - } //ʾ +void OLED_On(void) +{ + uint8_t i,n; + for(i=0;i<8;i++) + { + OLED_WR_Byte (0xb0+i,OLED_CMD); //设置页地址(0~7) + OLED_WR_Byte (0x00,OLED_CMD); //设置显示位置—列低地址 + OLED_WR_Byte (0x10,OLED_CMD); //设置显示位置—列高地址 + for(n=0;n<128;n++)OLED_WR_Byte(1,OLED_DATA); + } //更新显示 } -//ָλʾһַ,ַ +//在指定位置显示一个字符,包括部分字符 //x:0~127 //y:0~63 -// -//size:ѡ 16/12 +// +//size:选择字体 16/12 void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size) -{ - unsigned char c=0,i=0; - c=chr-' ';//õƫƺֵ +{ + unsigned char c=0,i=0; + c=chr-' ';//得到偏移后的值 if(x>Max_Column-1){x=0;y=y+2;} if(Char_Size ==16) { - OLED_Set_Pos(x,y); + OLED_Set_Pos(x,y); for(i=0;i<8;i++) { OLED_WR_Byte(F8X16[c*16+i],OLED_DATA); } OLED_Set_Pos(x,y+1); - for(i=0;i<8;i++) + for(i=0;i<8;i++){ OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA); + } } - else - { + else + { OLED_Set_Pos(x,y); for(i=0;i<6;i++) OLED_WR_Byte(F6x8[c][i],OLED_DATA); } } -//m^n +//m^n函数 uint32_t oled_pow(uint8_t m,uint8_t n) { - uint32_t result=1; - while(n--)result*=m; + uint32_t result=1; + while(n--)result*=m; return result; -} -//ʾ2 -//x,y : -//len :ֵλ -//size:С +} +//显示2个数字 +//x,y :起点坐标 +//len :数字的位数 +//size:字体大小 // -//num:ֵ(0~4294967295); +//num:数值(0~4294967295); void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size2) -{ +{ uint8_t t,temp; - uint8_t enshow=0; + uint8_t enshow=0; for(t=0;t120) @@ -240,60 +241,60 @@ void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size) j++; } } -//ʾ +//显示汉字 void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no) -{ +{ uint8_t t,adder=0; - OLED_Set_Pos(x,y); + OLED_Set_Pos(x,y); for(t=0;t<16;t++) { OLED_WR_Byte(Hzk[2*no][t],OLED_DATA); adder+=1; - } - OLED_Set_Pos(x,y+1); + } + OLED_Set_Pos(x,y+1); for(t=0;t<16;t++) - { + { OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA); adder+=1; - } + } } -/***********ʾʾBMPͼƬ12864ʼ(x,y),xķΧ0127yΪҳķΧ07*****************/ +/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0〜127,y为页的范围0〜7*****************/ void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]) -{ +{ unsigned int j=0; unsigned char x,y; - if(y1%8==0) y=y1/8; + if(y1%8==0) y=y1/8; else y=y1/8+1; for(y=y0;y Date: Fri, 4 Oct 2019 22:41:09 +0800 Subject: [PATCH 10/10] fix typo --- .../BSP/Hardware/OLED/oled.c | 4 ++-- .../BSP/Hardware/OLED/oled.h | 2 +- .../BSP/Src/mcu_init.c | 18 +++++++++--------- .../BSP/Hardware/OLED/oled.c | 2 +- .../BSP/Hardware/OLED/oled.h | 2 +- board/TencentOS_tiny_EVB_MX/BSP/Src/mcu_init.c | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.c b/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.c index 1cdf685f..f7fa3067 100644 --- a/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.c +++ b/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.c @@ -209,14 +209,14 @@ void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr) } /*************************************************************** -* : OLED_ShowCHinese +* : OLED_ShowChinese * ˵ : ָλʾ * : xʼλx yʼλy noҪʾֿеıţŴ0ʼ * ֵ: ***************************************************************/ -void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no) +void OLED_ShowChinese(uint8_t x,uint8_t y,uint8_t no) { uint8_t t,adder=0; OLED_Set_Pos(x,y); diff --git a/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.h b/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.h index 0152bb1a..02a86942 100644 --- a/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.h +++ b/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Hardware/OLED/oled.h @@ -37,7 +37,7 @@ void OLED_Fill(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint8_t dot); void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr); void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size); void OLED_ShowString(uint8_t x,uint8_t y, uint8_t *p); -void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no); +void OLED_ShowChinese(uint8_t x,uint8_t y,uint8_t no); void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]); /**************************************************************/ /************** OLEDýӿ ************************/ diff --git a/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Src/mcu_init.c b/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Src/mcu_init.c index 6d3c81bd..ae297f30 100644 --- a/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Src/mcu_init.c +++ b/board/TOS_tiny_EVK_STM32L431CBT6/BSP/Src/mcu_init.c @@ -41,17 +41,17 @@ void board_init(void) OLED_Init(); Init_BH1750(); DHT11_Init(); - //OLED_ShowCHinese(0,0,0); - //OLED_ShowCHinese(18,0,1); - //OLED_ShowCHinese(38,0,2); - //OLED_ShowCHinese(56,0,3); - //OLED_ShowCHinese(74,0,4); + //OLED_ShowChinese(0,0,0); + //OLED_ShowChinese(18,0,1); + //OLED_ShowChinese(38,0,2); + //OLED_ShowChinese(56,0,3); + //OLED_ShowChinese(74,0,4); OLED_ShowString(10,0,(uint8_t*)"TencentOS tiny"); -// OLED_ShowCHinese(1,3,5); -// OLED_ShowCHinese(21,3,6); +// OLED_ShowChinese(1,3,5); +// OLED_ShowChinese(21,3,6); // OLED_ShowString(39,3,(uint8_t*)":25 C"); -// OLED_ShowCHinese(1,6,7); -// OLED_ShowCHinese(21,6,8); +// OLED_ShowChinese(1,6,7); +// OLED_ShowChinese(21,6,8); // OLED_ShowString(39,6,(uint8_t*)":88 RH%"); } diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c index 33c36183..efc0ce7b 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c +++ b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.c @@ -239,7 +239,7 @@ void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size) } } //ʾ -void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no) +void OLED_ShowChinese(uint8_t x,uint8_t y,uint8_t no) { uint8_t t,adder=0; OLED_Set_Pos(x,y); diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.h b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.h index 3c25a34e..2bec557a 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.h +++ b/board/TencentOS_tiny_EVB_MX/BSP/Hardware/OLED/oled.h @@ -27,7 +27,7 @@ //OLEDӿڿú void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size); void OLED_ShowString(uint8_t x,uint8_t y, uint8_t *p,uint8_t Char_Size); -void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no); +void OLED_ShowChinese(uint8_t x,uint8_t y,uint8_t no); void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]); diff --git a/board/TencentOS_tiny_EVB_MX/BSP/Src/mcu_init.c b/board/TencentOS_tiny_EVB_MX/BSP/Src/mcu_init.c index 73df039d..d18754e9 100644 --- a/board/TencentOS_tiny_EVB_MX/BSP/Src/mcu_init.c +++ b/board/TencentOS_tiny_EVB_MX/BSP/Src/mcu_init.c @@ -53,12 +53,12 @@ void board_init(void) DHT11_Init(); OLED_Init(); OLED_Clear(); - OLED_ShowCHinese(0,0,0); - OLED_ShowCHinese(18,0,1); - OLED_ShowCHinese(36,0,2); - OLED_ShowCHinese(54,0,3); - OLED_ShowCHinese(72,0,4); - OLED_ShowCHinese(90,0,5); + OLED_ShowChinese(0,0,0); + OLED_ShowChinese(18,0,1); + OLED_ShowChinese(36,0,2); + OLED_ShowChinese(54,0,3); + OLED_ShowChinese(72,0,4); + OLED_ShowChinese(90,0,5); OLED_ShowString(0,2,(uint8_t*)str,16); }