mirror of
https://github.com/openharmony/vendor_lockzhiner.git
synced 2026-07-01 21:34:03 -04:00
Executable → Regular
+23
-17
@@ -15,6 +15,16 @@
|
||||
|
||||
#include "los_task.h" // OpenHarmony LiteOS的任务管理头文件
|
||||
|
||||
/* 等待时间 */
|
||||
#define HELLOWORLD_WAIT_MSEC 1000
|
||||
#define OPENHARMONY_WAIT_MSEC 2000
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 2048
|
||||
/* 任务的优先级 */
|
||||
#define HELLWORLD_TASK_PRIO 24
|
||||
#define OPENHARMONY_TASK_PRIO 25
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: task_helloworld
|
||||
* 说 明: 线程函数helloworld
|
||||
@@ -23,11 +33,10 @@
|
||||
***************************************************************/
|
||||
void task_helloworld()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
printf("Hello World\n");
|
||||
/* 睡眠1秒。该函数为OpenHarmony LiteoS内核睡眠函数,单位为:毫秒 */
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(HELLOWORLD_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +48,10 @@ void task_helloworld()
|
||||
***************************************************************/
|
||||
void task_openharmony()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
printf("Hello OpenHarmony\n");
|
||||
/* 睡眠1秒。该函数为OpenHarmony内核睡眠函数,单位为:毫秒 */
|
||||
LOS_Msleep(2000);
|
||||
/* 睡眠2秒。该函数为OpenHarmony内核睡眠函数,单位为:毫秒 */
|
||||
LOS_Msleep(OPENHARMONY_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,24 +74,22 @@ void helloworld_example()
|
||||
|
||||
/* 创建HelloWorld任务 */
|
||||
task1.pfnTaskEntry = (TSK_ENTRY_FUNC)task_helloworld; // 运行函数入口
|
||||
task1.uwStackSize = 2048; // 堆栈大小
|
||||
task1.uwStackSize = TASK_STACK_SIZE; // 堆栈大小
|
||||
task1.pcName = "task_helloworld"; // 函数注册名称
|
||||
task1.usTaskPrio = 24; // 任务的优先级,从0~63
|
||||
task1.usTaskPrio = HELLWORLD_TASK_PRIO; // 任务的优先级,从0~63
|
||||
ret = LOS_TaskCreate(&thread_id1, &task1); // 创建任务
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task_helloworld ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task_helloworld ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task2.pfnTaskEntry = (TSK_ENTRY_FUNC)task_openharmony; // 运行函数入口
|
||||
task2.uwStackSize = 2048; // 堆栈大小
|
||||
task2.uwStackSize = TASK_STACK_SIZE; // 堆栈大小
|
||||
task2.pcName = "task_openharmony"; // 函数注册名称
|
||||
task2.usTaskPrio = 25; // 任务的优先级,从0~63
|
||||
task2.usTaskPrio = OPENHARMONY_TASK_PRIO; // 任务的优先级,从0~63
|
||||
ret = LOS_TaskCreate(&thread_id2, &task2); // 创建任务
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task_openharmony ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task_openharmony ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+22
-17
@@ -16,6 +16,16 @@
|
||||
#include "los_task.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 2048
|
||||
/* 任务的优先级 */
|
||||
#define TASK_ONE_PRIO 24
|
||||
#define TASK_TWO_PRIO 24
|
||||
|
||||
/* 等待时间 */
|
||||
#define TASK_ONE_WAIT_MSEC 1000
|
||||
#define TASK_TWO_WAIT_MSEC 2000
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: task_one
|
||||
* 说 明: 线程函数1
|
||||
@@ -24,10 +34,9 @@
|
||||
***************************************************************/
|
||||
void task_one()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
printf("This is %s\n", __func__);
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(TASK_ONE_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +48,9 @@ void task_one()
|
||||
***************************************************************/
|
||||
void task_two()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
printf("This is %s\n", __func__);
|
||||
LOS_Msleep(2000);
|
||||
LOS_Msleep(TASK_TWO_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,27 +69,24 @@ void task_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
task1.pfnTaskEntry = (TSK_ENTRY_FUNC)task_one;
|
||||
task1.uwStackSize = 2048;
|
||||
task1.uwStackSize = TASK_STACK_SIZE;
|
||||
task1.pcName = "Task_One";
|
||||
task1.usTaskPrio = 24;
|
||||
task1.usTaskPrio = TASK_ONE_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id1, &task1);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create Task_One ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create Task_One ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task2.pfnTaskEntry = (TSK_ENTRY_FUNC)task_two;
|
||||
task2.uwStackSize = 2048;
|
||||
task2.uwStackSize = TASK_STACK_SIZE;
|
||||
task2.pcName = "Task_Two";
|
||||
task2.usTaskPrio = 25;
|
||||
task2.usTaskPrio = TASK_TWO_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id2, &task2);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create Task_Two ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create Task_Two ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(task_example);
|
||||
|
||||
|
||||
Executable → Regular
+40
-38
@@ -16,7 +16,17 @@
|
||||
#include "los_sem.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
#define MAX_COUNT 4
|
||||
/* 信号量资源总数 */
|
||||
#define SEM_MAX_COUNT 4
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 2048
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 等待时间 */
|
||||
#define SEM_POST_WAIT_MSEC 1000
|
||||
#define SEM_PEND_WAIT_MSEC 100
|
||||
|
||||
static unsigned int m_sem;
|
||||
|
||||
@@ -28,25 +38,24 @@ static unsigned int m_sem;
|
||||
***************************************************************/
|
||||
void control_thread()
|
||||
{
|
||||
#define CYCLES 3
|
||||
unsigned int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/*释放两次信号量,sem_one_thread和sem_two_thread同步执行;
|
||||
释放一次信号量,sem_one_thread和sem_two_thread交替执行*/
|
||||
if (count++%3)
|
||||
{
|
||||
while (1) {
|
||||
/*
|
||||
* 释放两次信号量,sem_one_thread和sem_two_thread同步执行;
|
||||
* 释放一次信号量,sem_one_thread和sem_two_thread交替执行
|
||||
*/
|
||||
if ((count++) % CYCLES) {
|
||||
LOS_SemPost(m_sem);
|
||||
printf("control_thread Release once Semaphore\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOS_SemPost(m_sem);
|
||||
LOS_SemPost(m_sem);
|
||||
printf("control_thread Release twice Semaphore\n");
|
||||
}
|
||||
|
||||
LOS_Msleep(1000);
|
||||
|
||||
LOS_Msleep(SEM_POST_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,13 +67,12 @@ void control_thread()
|
||||
***************************************************************/
|
||||
void sem_one_thread()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
/*申请信号量*/
|
||||
LOS_SemPend(m_sem, LOS_WAIT_FOREVER);
|
||||
|
||||
printf("sem_one_thread get Semaphore\n");
|
||||
LOS_Msleep(100);
|
||||
LOS_Msleep(SEM_PEND_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,13 +84,12 @@ void sem_one_thread()
|
||||
***************************************************************/
|
||||
void sem_two_thread()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
/*申请信号量*/
|
||||
LOS_SemPend(m_sem, LOS_WAIT_FOREVER);
|
||||
|
||||
printf("sem_two_thread get Semaphore\n");
|
||||
LOS_Msleep(100);
|
||||
LOS_Msleep(SEM_PEND_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,46 +109,41 @@ void semaphore_example()
|
||||
TSK_INIT_PARAM_S task3 = {0};
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
ret = LOS_SemCreate(MAX_COUNT, &m_sem);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create Semaphore\n");
|
||||
ret = LOS_SemCreate(SEM_MAX_COUNT, &m_sem);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create Semaphore\n");
|
||||
return;
|
||||
}
|
||||
|
||||
task1.pfnTaskEntry = (TSK_ENTRY_FUNC)control_thread;
|
||||
task1.uwStackSize = 2048;
|
||||
task1.uwStackSize = TASK_STACK_SIZE;
|
||||
task1.pcName = "control_thread";
|
||||
task1.usTaskPrio = 24;
|
||||
task1.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_crtl, &task1);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create control_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create control_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task2.pfnTaskEntry = (TSK_ENTRY_FUNC)sem_one_thread;
|
||||
task2.uwStackSize = 2048;
|
||||
task2.uwStackSize = TASK_STACK_SIZE;
|
||||
task2.pcName = "sem_one_thread";
|
||||
task2.usTaskPrio = 24;
|
||||
task2.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id1, &task2);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create sem_one_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create sem_one_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task3.pfnTaskEntry = (TSK_ENTRY_FUNC)sem_two_thread;
|
||||
task3.uwStackSize = 2048;
|
||||
task3.uwStackSize = TASK_STACK_SIZE;
|
||||
task3.pcName = "sem_two_thread";
|
||||
task3.usTaskPrio = 24;
|
||||
task3.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id2, &task3);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create sem_two_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create sem_two_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(semaphore_example);
|
||||
|
||||
|
||||
Executable → Regular
+12
-17
@@ -16,6 +16,10 @@
|
||||
#include "los_swtmr.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
/* 定时器定时滴答数 */
|
||||
#define TIMER1_TICK 1000
|
||||
#define TIMER2_TICK 2000
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: timer1_timeout
|
||||
* 说 明: 定时器1超时函数
|
||||
@@ -49,38 +53,29 @@ void timer_example()
|
||||
unsigned int timer_id1, timer_id2;
|
||||
unsigned int ret;
|
||||
|
||||
ret = LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_PERIOD, timer1_timeout, &timer_id1, NULL);
|
||||
if (ret == LOS_OK)
|
||||
{
|
||||
ret = LOS_SwtmrCreate(TIMER1_TICK, LOS_SWTMR_MODE_PERIOD, timer1_timeout, &timer_id1, NULL);
|
||||
if (ret == LOS_OK) {
|
||||
ret = LOS_SwtmrStart(timer_id1);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
if (ret != LOS_OK) {
|
||||
printf("start timer1 fail ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("create timer1 fail ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = LOS_SwtmrCreate(2000, LOS_SWTMR_MODE_PERIOD, timer2_timeout, &timer_id2, NULL);
|
||||
if (ret == LOS_OK)
|
||||
{
|
||||
ret = LOS_SwtmrCreate(TIMER2_TICK, LOS_SWTMR_MODE_PERIOD, timer2_timeout, &timer_id2, NULL);
|
||||
if (ret == LOS_OK) {
|
||||
ret = LOS_SwtmrStart(timer_id2);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
if (ret != LOS_OK) {
|
||||
printf("start timer2 fail ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("create timer2 fail ret:0x%x\n"), ret;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(timer_example);
|
||||
|
||||
|
||||
Executable → Regular
+27
-23
@@ -16,6 +16,16 @@
|
||||
#include "los_task.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 2048
|
||||
/* 任务的优先级 */
|
||||
#define WRITE_TASK_PRIO 24
|
||||
#define READ_TASK_PRIO 25
|
||||
|
||||
/* 等待时间 */
|
||||
#define WRITE_WAIT_MSEC 3000
|
||||
#define READ_WAIT_MSEC 1000
|
||||
|
||||
static unsigned int m_mutex_id;
|
||||
static unsigned int m_data = 0;
|
||||
|
||||
@@ -27,14 +37,13 @@ static unsigned int m_data = 0;
|
||||
***************************************************************/
|
||||
void write_thread()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
LOS_MuxPend(m_mutex_id, LOS_WAIT_FOREVER);
|
||||
|
||||
m_data++;
|
||||
printf("write_thread write data:%u\n", m_data);
|
||||
|
||||
LOS_Msleep(3000);
|
||||
LOS_Msleep(WRITE_WAIT_MSEC);
|
||||
LOS_MuxPost(m_mutex_id);
|
||||
}
|
||||
}
|
||||
@@ -48,15 +57,14 @@ void write_thread()
|
||||
void read_thread()
|
||||
{
|
||||
/*delay 1s*/
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(READ_WAIT_MSEC);
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
LOS_MuxPend(m_mutex_id, LOS_WAIT_FOREVER);
|
||||
printf("read_thread read data:%u\n", m_data);
|
||||
|
||||
LOS_Msleep(1000);
|
||||
LOS_MuxPost(m_mutex_id);
|
||||
|
||||
LOS_Msleep(READ_WAIT_MSEC);
|
||||
LOS_MuxPost(READ_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,33 +83,29 @@ void mutex_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
ret = LOS_MuxCreate(&m_mutex_id);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create Mutex\n");
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create Mutex\n");
|
||||
}
|
||||
|
||||
task1.pfnTaskEntry = (TSK_ENTRY_FUNC)write_thread;
|
||||
task1.uwStackSize = 2048;
|
||||
task1.uwStackSize = TASK_STACK_SIZE;
|
||||
task1.pcName = "write_thread";
|
||||
task1.usTaskPrio = 24;
|
||||
task1.usTaskPrio = WRITE_TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id1, &task1);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create write_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create write_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task2.pfnTaskEntry = (TSK_ENTRY_FUNC)read_thread;
|
||||
task2.uwStackSize = 2048;
|
||||
task2.uwStackSize = TASK_STACK_SIZE;
|
||||
task2.pcName = "read_thread";
|
||||
task2.usTaskPrio = 25;
|
||||
task2.usTaskPrio = READ_TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id2, &task2);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create read_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create read_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(mutex_example);
|
||||
|
||||
|
||||
Executable → Regular
+29
-31
@@ -16,8 +16,18 @@
|
||||
#include "los_task.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
#define MSG_QUEUE_LENGTH 16
|
||||
#define BUFFER_LEN 50
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 2048
|
||||
/* 任务的优先级 */
|
||||
#define MSG_WRITE_TASK_PRIO 24
|
||||
#define MSG_READ_TASK_PRIO 25
|
||||
|
||||
/* 等待时间 */
|
||||
#define MSG_WRITE_WAIT_MSEC 1000
|
||||
|
||||
/* 消息队列长度 */
|
||||
#define MSG_QUEUE_LENGTH 16
|
||||
#define BUFFER_LEN 50
|
||||
|
||||
static unsigned int m_msg_queue;
|
||||
|
||||
@@ -32,21 +42,17 @@ void msg_write_thread(void *arg)
|
||||
unsigned int data = 0;
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
data++;
|
||||
ret = LOS_QueueWrite(m_msg_queue, (void *)&data, sizeof(data), LOS_WAIT_FOREVER);
|
||||
if (LOS_OK != ret)
|
||||
{
|
||||
if (LOS_OK != ret) {
|
||||
printf("%s write Message Queue msg fail ret:0x%x\n", __func__, ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("%s write Message Queue msg:%u\n", __func__, data);
|
||||
}
|
||||
|
||||
/*delay 1s*/
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(MSG_WRITE_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,17 +68,13 @@ void msg_read_thread(void *arg)
|
||||
unsigned int ret = LOS_OK;
|
||||
unsigned int *pData = NULL;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
/*wait for message*/
|
||||
ret = LOS_QueueRead(m_msg_queue, (void *)&addr, BUFFER_LEN, LOS_WAIT_FOREVER);
|
||||
if (ret == LOS_OK)
|
||||
{
|
||||
if (ret == LOS_OK) {
|
||||
pData = addr;
|
||||
printf("%s read Message Queue msg:%u\n", __func__, *pData);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("%s read Message Queue fail ret:0x%x\n", __func__, ret);
|
||||
}
|
||||
}
|
||||
@@ -93,34 +95,30 @@ void queue_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
ret = LOS_QueueCreate("queue", MSG_QUEUE_LENGTH, &m_msg_queue, 0, BUFFER_LEN);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create Message Queue ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create Message Queue ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task1.pfnTaskEntry = (TSK_ENTRY_FUNC)msg_write_thread;
|
||||
task1.uwStackSize = 2048;
|
||||
task1.uwStackSize = TASK_STACK_SIZE;
|
||||
task1.pcName = "msg_write_thread";
|
||||
task1.usTaskPrio = 24;
|
||||
task1.usTaskPrio = MSG_WRITE_TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id1, &task1);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create msg_write_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create msg_write_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task2.pfnTaskEntry = (TSK_ENTRY_FUNC)msg_read_thread;
|
||||
task2.uwStackSize = 2048;
|
||||
task2.uwStackSize = TASK_STACK_SIZE;
|
||||
task2.pcName = "msg_read_thread";
|
||||
task2.usTaskPrio = 25;
|
||||
task2.usTaskPrio = MSG_READ_TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id2, &task2);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create msg_read_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create msg_read_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(queue_example);
|
||||
|
||||
|
||||
Executable → Regular
+28
-22
@@ -17,7 +17,19 @@
|
||||
#include "los_task.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
#define EVENT_WAIT 0x00000001
|
||||
#define EVENT_WAIT 0x00000001
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 2048
|
||||
/* 任务的优先级 */
|
||||
#define TAKS_PRIO 5
|
||||
|
||||
/* 主程序进入循环前的等待时间 */
|
||||
#define MASTER_WAIT_DELAY_MSEC 1000
|
||||
/* 主程序event等待时间 */
|
||||
#define MASTER_EVENT_DELAY_MSEC 2000
|
||||
/* 从程序event等待时间 */
|
||||
#define SLAVE_EVENT_DELAY_MSEC 1000
|
||||
|
||||
static EVENT_CB_S m_event;
|
||||
|
||||
@@ -31,10 +43,9 @@ void event_master_thread()
|
||||
{
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(MASTER_WAIT_DELAY_MSEC);
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
printf("%s write event:0x%x\n", __func__, EVENT_WAIT);
|
||||
ret = LOS_EventWrite(&m_event, EVENT_WAIT);
|
||||
if (ret != LOS_OK) {
|
||||
@@ -42,7 +53,7 @@ void event_master_thread()
|
||||
}
|
||||
|
||||
/*delay 1s*/
|
||||
LOS_Msleep(2000);
|
||||
LOS_Msleep(EVENT_DELAY_MSEC);
|
||||
LOS_EventClear(&m_event, ~m_event.uwEventID);
|
||||
}
|
||||
}
|
||||
@@ -57,12 +68,11 @@ void event_slave_thread()
|
||||
{
|
||||
unsigned int event;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
/* 阻塞方式读事件,等待事件到达*/
|
||||
event = LOS_EventRead(&m_event, EVENT_WAIT, LOS_WAITMODE_AND, LOS_WAIT_FOREVER);
|
||||
printf("%s read event:0x%x\n", __func__, event);
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(SLAVE_EVENT_DELAY_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,34 +91,30 @@ void event_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
ret = LOS_EventInit(&m_event);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create EventFlags\n");
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create EventFlags\n");
|
||||
return;
|
||||
}
|
||||
|
||||
task1.pfnTaskEntry = (TSK_ENTRY_FUNC)event_master_thread;
|
||||
task1.uwStackSize = 2048;
|
||||
task1.uwStackSize = TASK_STACK_SIZE;
|
||||
task1.pcName = "event_master_thread";
|
||||
task1.usTaskPrio = 5;
|
||||
task1.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id1, &task1);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create event_master_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create event_master_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
task2.pfnTaskEntry = (TSK_ENTRY_FUNC)event_slave_thread;
|
||||
task2.uwStackSize = 2048;
|
||||
task2.uwStackSize = TASK_STACK_SIZE;
|
||||
task2.pcName = "event_slave_thread";
|
||||
task2.usTaskPrio = 5;
|
||||
task2.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id2, &task2);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create event_slave_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create event_slave_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(event_example);
|
||||
|
||||
|
||||
Executable → Regular
+30
-17
@@ -21,8 +21,16 @@
|
||||
#include "ohos_init.h"
|
||||
#include "lz_hardware.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 2048
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 1000
|
||||
|
||||
/* 定义ADC的通道号 */
|
||||
#define ADC_CHANNEL 5
|
||||
#define ADC_CHANNEL 5
|
||||
/* 定义ADC初始化的结构体 */
|
||||
static DevIo m_adcKey = {
|
||||
.isr = {.gpio = INVALID_GPIO},
|
||||
@@ -31,6 +39,15 @@ static DevIo m_adcKey = {
|
||||
.ctrl2 = {.gpio = INVALID_GPIO},
|
||||
};
|
||||
|
||||
/* 寄存器地址 */
|
||||
#define GRF_SOC_CON29_REG_ADDRESS (0x41050000U + 0x274U)
|
||||
/* 设置saradc的电压信号为AVDD,即参考外部电压为0V */
|
||||
#define BITS_SELECT_AVDD(value) ((value) & (~(0x1 << 4)))
|
||||
#define BITS_ENABLE_AVDD(value) ((value) | ((0x1 << 4) << 16))
|
||||
|
||||
/* ADC最大电压量程 */
|
||||
#define
|
||||
/* ADC最大档位 */
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: adc_dev_init
|
||||
@@ -41,14 +58,13 @@ static DevIo m_adcKey = {
|
||||
static unsigned int adc_dev_init()
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
uint32_t *pGrfSocCon29 = (uint32_t *)(0x41050000U + 0x274U);
|
||||
uint32_t *pGrfSocCon29 = (uint32_t *)(GRF_SOC_CON29_REG_ADDRESS);
|
||||
uint32_t ulValue;
|
||||
|
||||
PinctrlSet(GPIO0_PC5, MUX_FUNC1, PULL_NONE, DRIVE_KEEP);
|
||||
|
||||
ret = DevIoInit(m_adcKey);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: ADC Key IO Init fail\n", __FILE__, __func__, __LINE__);
|
||||
return __LINE__;
|
||||
}
|
||||
@@ -61,8 +77,8 @@ static unsigned int adc_dev_init()
|
||||
|
||||
/* 设置saradc的电压信号,选择AVDD */
|
||||
ulValue = *pGrfSocCon29;
|
||||
ulValue &= ~(0x1 << 4);
|
||||
ulValue |= ((0x1 << 4) << 16);
|
||||
ulValue = BITS_SELECT_AVDD(ulValue);
|
||||
ulValue = BITS_ENABLE_AVDD(ulValue);
|
||||
*pGrfSocCon29 = ulValue;
|
||||
|
||||
return 0;
|
||||
@@ -80,8 +96,7 @@ static float adc_get_voltage()
|
||||
unsigned int data = 0;
|
||||
|
||||
ret = LzSaradcReadValue(ADC_CHANNEL, &data);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: ADC Read Fail\n", __FILE__, __func__, __LINE__);
|
||||
return 0.0;
|
||||
}
|
||||
@@ -101,16 +116,15 @@ void adc_process()
|
||||
|
||||
/* 初始化adc设备 */
|
||||
adc_dev_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
printf("***************Adc Example*************\r\n");
|
||||
/*获取电压值*/
|
||||
voltage = adc_get_voltage();
|
||||
printf("vlt:%.3fV\n", voltage);
|
||||
|
||||
/* 睡眠1秒 */
|
||||
usleep(1000000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,13 +142,12 @@ void adc_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)adc_process;
|
||||
task.uwStackSize = 2048;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "adc process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+14
-11
@@ -17,6 +17,14 @@
|
||||
#include "los_task.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 10240
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 1000
|
||||
|
||||
#define TEXT "XiaoZhiPai!"
|
||||
#define WEB "fzlzdz.com"
|
||||
|
||||
@@ -31,27 +39,23 @@ void nfc_process(void)
|
||||
unsigned int ret = 0;
|
||||
|
||||
/* 初始化NFC设备 */
|
||||
printf("%s, %d: \n", __FILE__, __LINE__);
|
||||
nfc_init();
|
||||
|
||||
printf("%s, %d: \n", __FILE__, __LINE__);
|
||||
ret = nfc_store_text(NDEFFirstPos, (uint8_t *)TEXT);
|
||||
if (ret != 1) {
|
||||
printf("NFC Write Text Failed: %d\n", ret);
|
||||
}
|
||||
|
||||
printf("%s, %d: \n", __FILE__, __LINE__);
|
||||
ret = nfc_store_uri_http(NDEFLastPos, (uint8_t *)WEB);
|
||||
if (ret != 1) {
|
||||
printf("NFC Write Url Failed: %d\n", ret);
|
||||
}
|
||||
|
||||
printf("%s, %d: \n", __FILE__, __LINE__);
|
||||
|
||||
while (1) {
|
||||
printf("==============NFC Example==============\r\n");
|
||||
printf("Please use the mobile phone with NFC function close to the development board!\r\n");
|
||||
printf("\n\n");
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,13 +73,12 @@ void nfc_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)nfc_process;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "nfc process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+45
-49
@@ -26,10 +26,23 @@
|
||||
static unsigned int NFC_I2C_PORT = 2;
|
||||
|
||||
/* i2c配置 */
|
||||
static I2cBusIo m_i2c2m0 =
|
||||
{
|
||||
.scl = {.gpio = GPIO0_PD6, .func = MUX_FUNC1, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
.sda = {.gpio = GPIO0_PD5, .func = MUX_FUNC1, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
static I2cBusIo m_i2c2m0 = {
|
||||
.scl = {
|
||||
.gpio = GPIO0_PD6,
|
||||
.func = MUX_FUNC1,
|
||||
.type = PULL_NONE,
|
||||
.drv = DRIVE_KEEP,
|
||||
.dir = LZGPIO_DIR_KEEP,
|
||||
.val = LZGPIO_LEVEL_KEEP
|
||||
},
|
||||
.sda = {
|
||||
.gpio = GPIO0_PD5,
|
||||
.func = MUX_FUNC1,
|
||||
.type = PULL_NONE,
|
||||
.drv = DRIVE_KEEP,
|
||||
.dir = LZGPIO_DIR_KEEP,
|
||||
.val = LZGPIO_LEVEL_KEEP
|
||||
},
|
||||
.id = FUNC_ID_I2C2,
|
||||
.mode = FUNC_MODE_M0,
|
||||
};
|
||||
@@ -51,8 +64,7 @@ static bool writeTimeout( uint8_t *data, uint8_t dataSend)
|
||||
uint32_t status = 0;
|
||||
|
||||
status = LzI2cWrite(NFC_I2C_PORT, NT3H1X_SLAVE_ADDRESS, data, dataSend);
|
||||
if (status != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (status != LZ_HARDWARE_SUCCESS) {
|
||||
printf("===== Error: I2C write status1 = 0x%x! =====\r\n", status);
|
||||
return 0;
|
||||
}
|
||||
@@ -67,15 +79,13 @@ static bool readTimeout(uint8_t address, uint8_t *block_data)
|
||||
uint8_t buffer[1] = {address};
|
||||
|
||||
status = LzI2cWrite(NFC_I2C_PORT, NT3H1X_SLAVE_ADDRESS, &buffer[0], 1);
|
||||
if (status != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (status != LZ_HARDWARE_SUCCESS) {
|
||||
printf("===== Error: I2C write status1 = 0x%x! =====\r\n", status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = LzI2cRead(NFC_I2C_PORT, NT3H1X_SLAVE_ADDRESS, block_data, NFC_PAGE_SIZE);
|
||||
if (status != 0)
|
||||
{
|
||||
if (status != 0) {
|
||||
printf("===== Error: I2C write status = 0x%x! =====\r\n", status);
|
||||
return 0;
|
||||
}
|
||||
@@ -92,15 +102,12 @@ unsigned int NT3HI2cInit()
|
||||
ulValue &= ~((0x7 << 8) | (0x7 << 4));
|
||||
ulValue |= ((0x1 << 8) | (0x1 << 4));
|
||||
pGrf[7] = ulValue | (0xFFFF << 16);
|
||||
printf("%s, %d: GRF_GPIO0D_IOMUX_H(0x%x) = 0x%x\n", __func__, __LINE__, &pGrf[7], pGrf[7]);
|
||||
|
||||
if (I2cIoInit(m_i2c2m0) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (I2cIoInit(m_i2c2m0) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: I2cIoInit failed!\n", __FILE__, __func__, __LINE__);
|
||||
return __LINE__;
|
||||
}
|
||||
if (LzI2cInit(NFC_I2C_PORT, m_i2c2_freq) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (LzI2cInit(NFC_I2C_PORT, m_i2c2_freq) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cInit failed!\n", __FILE__, __func__, __LINE__);
|
||||
return __LINE__;
|
||||
}
|
||||
@@ -115,23 +122,24 @@ unsigned int NT3HI2cDeInit()
|
||||
|
||||
bool NT3HReadHeaderNfc(uint8_t *endRecordsPtr, uint8_t *ndefHeader)
|
||||
{
|
||||
#define STRING_OFFSET_NDEF_START 0
|
||||
#define STRING_OFFSET_NEND_RECORD 1
|
||||
#define STRING_OFFSET_NTAG_ERASED 2
|
||||
|
||||
*endRecordsPtr = 0;
|
||||
bool ret = NT3HReadUserData(0);
|
||||
|
||||
// read the first page to see where is the end of the Records.
|
||||
if (ret == true)
|
||||
{
|
||||
if (ret == true) {
|
||||
// if the first byte is equals to NDEF_START_BYTE there are some records
|
||||
// store theend of that
|
||||
if ((NDEF_START_BYTE == nfcPageBuffer[0]) && (NTAG_ERASED != nfcPageBuffer[2]))
|
||||
{
|
||||
*endRecordsPtr = nfcPageBuffer[1];
|
||||
*ndefHeader = nfcPageBuffer[2];
|
||||
if ((NDEF_START_BYTE == nfcPageBuffer[STRING_OFFSET_NDEF_START])
|
||||
&& (NTAG_ERASED != nfcPageBuffer[STRING_OFFSET_NTAG_ERASED])) {
|
||||
*endRecordsPtr = nfcPageBuffer[STRING_OFFSET_NEND_RECORD];
|
||||
*ndefHeader = nfcPageBuffer[STRING_OFFSET_NTAG_ERASED];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
errNo = NT3HERROR_READ_HEADER;
|
||||
}
|
||||
|
||||
@@ -144,19 +152,15 @@ bool NT3HWriteHeaderNfc(uint8_t endRecordsPtr, uint8_t ndefHeader)
|
||||
|
||||
// read the first page to see where is the end of the Records.
|
||||
bool ret = NT3HReadUserData(0);
|
||||
if (ret == true)
|
||||
{
|
||||
if (ret == true) {
|
||||
|
||||
nfcPageBuffer[1] = endRecordsPtr;
|
||||
nfcPageBuffer[2] = ndefHeader;
|
||||
ret = NT3HWriteUserData(0, nfcPageBuffer);
|
||||
if (ret == false)
|
||||
{
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_WRITE_HEADER;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
errNo = NT3HERROR_READ_HEADER;
|
||||
}
|
||||
|
||||
@@ -171,8 +175,7 @@ bool NT3HEraseAllTag(void)
|
||||
uint8_t erase[NFC_PAGE_SIZE + 1] = {USER_START_REG, 0x03, 0x03, 0xD0, 0x00, 0x00, 0xFE};
|
||||
ret = writeTimeout(erase, sizeof(erase));
|
||||
|
||||
if (ret == false)
|
||||
{
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_ERASE_USER_MEMORY_PAGE;
|
||||
}
|
||||
return ret;
|
||||
@@ -198,16 +201,14 @@ bool NT3HReadUserData(uint8_t page)
|
||||
{
|
||||
uint8_t reg = USER_START_REG + page;
|
||||
// if the requested page is out of the register exit with error
|
||||
if (reg > USER_END_REG)
|
||||
{
|
||||
if (reg > USER_END_REG) {
|
||||
errNo = NT3HERROR_INVALID_USER_MEMORY_PAGE;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = readTimeout(reg, nfcPageBuffer);
|
||||
|
||||
if (ret == false)
|
||||
{
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_READ_USER_MEMORY_PAGE;
|
||||
}
|
||||
|
||||
@@ -222,8 +223,7 @@ bool NT3HWriteUserData(uint8_t page, const uint8_t* data)
|
||||
uint8_t reg = USER_START_REG + page;
|
||||
|
||||
// if the requested page is out of the register exit with error
|
||||
if (reg > USER_END_REG)
|
||||
{
|
||||
if (reg > USER_END_REG) {
|
||||
errNo = NT3HERROR_INVALID_USER_MEMORY_PAGE;
|
||||
ret = false;
|
||||
goto end;
|
||||
@@ -232,8 +232,7 @@ bool NT3HWriteUserData(uint8_t page, const uint8_t* data)
|
||||
dataSend[0] = reg; // store the register
|
||||
memcpy(&dataSend[1], data, NFC_PAGE_SIZE);
|
||||
ret = writeTimeout(dataSend, sizeof(dataSend));
|
||||
if (ret == false)
|
||||
{
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_WRITE_USER_MEMORY_PAGE;
|
||||
goto end;
|
||||
}
|
||||
@@ -246,11 +245,9 @@ end:
|
||||
bool NT3HReadSram(void)
|
||||
{
|
||||
bool ret = false;
|
||||
for (int i = SRAM_START_REG, j = 0; i <= SRAM_END_REG; i++, j++)
|
||||
{
|
||||
for (int i = SRAM_START_REG, j = 0; i <= SRAM_END_REG; i++, j++) {
|
||||
ret = readTimeout(i, nfcPageBuffer);
|
||||
if (ret == false)
|
||||
{
|
||||
if (ret == false) {
|
||||
return ret;
|
||||
}
|
||||
//memcpy(&userData[offset], pageBuffer, sizeof(pageBuffer));
|
||||
@@ -261,12 +258,11 @@ bool NT3HReadSram(void)
|
||||
|
||||
void NT3HGetNxpSerialNumber(char* buffer)
|
||||
{
|
||||
#define MANUF_BUFFER_MAXSIZE 6
|
||||
uint8_t manuf[16];
|
||||
|
||||
if (NT3HReaddManufactoringData(manuf))
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (NT3HReaddManufactoringData(manuf)) {
|
||||
for (int i = 0; i < MANUF_BUFFER_MAXSIZE; i++) {
|
||||
buffer[i] = manuf[i];
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+3
-6
@@ -37,8 +37,7 @@
|
||||
|
||||
#define NFC_PAGE_SIZE 16
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
NT3HERROR_NO_ERROR,
|
||||
NT3HERROR_READ_HEADER,
|
||||
NT3HERROR_WRITE_HEADER,
|
||||
@@ -58,15 +57,13 @@ extern NT3HerrNo errNo;
|
||||
* This strucure is used in the ADD record functionality
|
||||
* to store the last nfc page information, in order to continue from that point.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
uint8_t page;
|
||||
uint8_t usedBytes;
|
||||
} UncompletePageStr;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
RecordPosEnu ndefPosition;
|
||||
uint8_t rtdType;
|
||||
uint8_t *rtdPayload;
|
||||
|
||||
Executable → Regular
+43
-74
@@ -22,26 +22,25 @@
|
||||
typedef uint8_t (*composeRtdPtr)(const NDEFDataStr *ndef, NDEFRecordStr *ndefRecord, uint8_t *I2CMsg);
|
||||
static composeRtdPtr composeRtd[] = {composeRtdText, composeRtdUri};
|
||||
|
||||
|
||||
static int16_t firstRecord(UncompletePageStr *page, const NDEFDataStr *data, RecordPosEnu rtdPosition)
|
||||
{
|
||||
|
||||
NDEFRecordStr record;
|
||||
NDEFHeaderStr header;
|
||||
uint8_t typeFunct = 0;
|
||||
|
||||
switch (data->rtdType)
|
||||
{
|
||||
case RTD_TEXT:
|
||||
typeFunct = 0;
|
||||
break;
|
||||
|
||||
case RTD_URI:
|
||||
typeFunct = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
switch (data->rtdType) {
|
||||
case RTD_TEXT:
|
||||
typeFunct = TYPE_FUNCT_TEXT;
|
||||
break;
|
||||
|
||||
case RTD_URI:
|
||||
typeFunct = TYPE_FUNCT_URI;
|
||||
break;
|
||||
|
||||
default:
|
||||
return TYPE_FUNCT_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
// clear all buffers
|
||||
@@ -60,7 +59,6 @@ static int16_t firstRecord(UncompletePageStr *page, const NDEFDataStr *data, Rec
|
||||
memcpy(nfcPageBuffer, &header, sizeof(NDEFHeaderStr));
|
||||
|
||||
return sizeof(NDEFHeaderStr) + recordLength;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -74,19 +72,18 @@ static int16_t addRecord(UncompletePageStr *pageToUse, const NDEFDataStr *data,
|
||||
|
||||
uint8_t typeFunct = 0;
|
||||
|
||||
switch (data->rtdType)
|
||||
{
|
||||
case RTD_TEXT:
|
||||
typeFunct = 0;
|
||||
break;
|
||||
|
||||
case RTD_URI:
|
||||
typeFunct = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
switch (data->rtdType) {
|
||||
case RTD_TEXT:
|
||||
typeFunct = 0;
|
||||
break;
|
||||
|
||||
case RTD_URI:
|
||||
typeFunct = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
// first Change the Header of the first Record
|
||||
@@ -101,13 +98,10 @@ static int16_t addRecord(UncompletePageStr *pageToUse, const NDEFDataStr *data,
|
||||
// prepare second record
|
||||
uint8_t recordLength = composeRtd[typeFunct](data, &record, tmpBuffer);
|
||||
|
||||
if (rtdPosition == NDEFMiddlePos)
|
||||
{
|
||||
if (rtdPosition == NDEFMiddlePos) {
|
||||
// this is a record in the middle adjust it on the buffet
|
||||
composeNDEFMBME(false, false, &record);
|
||||
}
|
||||
else if (rtdPosition == NDEFLastPos)
|
||||
{
|
||||
} else if (rtdPosition == NDEFLastPos) {
|
||||
// this is the last record adjust it on the buffet
|
||||
composeNDEFMBME(false, true, &record);
|
||||
}
|
||||
@@ -121,13 +115,10 @@ static int16_t addRecord(UncompletePageStr *pageToUse, const NDEFDataStr *data,
|
||||
|
||||
// use the last valid page and start to add the new record
|
||||
NT3HReadUserData(pageToUse->page);
|
||||
if (pageToUse->usedBytes + recordLength < NFC_PAGE_SIZE)
|
||||
{
|
||||
if (pageToUse->usedBytes + recordLength < NFC_PAGE_SIZE) {
|
||||
memcpy(&nfcPageBuffer[pageToUse->usedBytes], tmpBuffer, recordLength);
|
||||
return recordLength + pageToUse->usedBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint8_t byteToCopy = NFC_PAGE_SIZE - pageToUse->usedBytes;
|
||||
memcpy(&nfcPageBuffer[pageToUse->usedBytes], tmpBuffer, byteToCopy);
|
||||
NT3HWriteUserData(pageToUse->page, nfcPageBuffer);
|
||||
@@ -138,10 +129,8 @@ static int16_t addRecord(UncompletePageStr *pageToUse, const NDEFDataStr *data,
|
||||
memcpy(nfcPageBuffer, &tmpBuffer[byteToCopy], pageToUse->usedBytes);
|
||||
return pageToUse->usedBytes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static bool writeUserPayload(int16_t payloadPtr, const NDEFDataStr *data, UncompletePageStr *addPage)
|
||||
{
|
||||
uint8_t addedPayload;
|
||||
@@ -152,14 +141,10 @@ static bool writeUserPayload(int16_t payloadPtr, const NDEFDataStr *data, Uncomp
|
||||
uint8_t copyByte = 0;
|
||||
|
||||
// if the header is less then the NFC_PAGE_SIZE, fill it with the payload
|
||||
if (NFC_PAGE_SIZE > payloadPtr)
|
||||
{
|
||||
if (data->rtdPayloadlength > NFC_PAGE_SIZE - payloadPtr)
|
||||
{
|
||||
if (NFC_PAGE_SIZE > payloadPtr) {
|
||||
if (data->rtdPayloadlength > NFC_PAGE_SIZE - payloadPtr) {
|
||||
copyByte = NFC_PAGE_SIZE - payloadPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
copyByte = data->rtdPayloadlength;
|
||||
}
|
||||
}
|
||||
@@ -170,58 +155,44 @@ static bool writeUserPayload(int16_t payloadPtr, const NDEFDataStr *data, Uncomp
|
||||
|
||||
|
||||
//if it is sufficient one send add the NDEF_END_BYTE
|
||||
if ((addedPayload >= data->rtdPayloadlength) && ((payloadPtr + copyByte) < NFC_PAGE_SIZE))
|
||||
{
|
||||
if ((addedPayload >= data->rtdPayloadlength) && ((payloadPtr + copyByte) < NFC_PAGE_SIZE)) {
|
||||
nfcPageBuffer[(payloadPtr + copyByte)] = NDEF_END_BYTE;
|
||||
endRecord = true;
|
||||
}
|
||||
|
||||
ret = NT3HWriteUserData(addPage->page, nfcPageBuffer);
|
||||
|
||||
while (!endRecord)
|
||||
{
|
||||
while (!endRecord) {
|
||||
addPage->page++; // move to a new register
|
||||
memset(nfcPageBuffer, 0, NFC_PAGE_SIZE);
|
||||
|
||||
//special case just the NDEF_END_BYTE remain out
|
||||
if (addedPayload == data->rtdPayloadlength)
|
||||
{
|
||||
if (addedPayload == data->rtdPayloadlength) {
|
||||
nfcPageBuffer[0] = NDEF_END_BYTE;
|
||||
ret = NT3HWriteUserData(addPage->page, nfcPageBuffer);
|
||||
endRecord = true;
|
||||
if (ret == false)
|
||||
{
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_WRITE_NDEF_TEXT;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (addedPayload < data->rtdPayloadlength)
|
||||
{
|
||||
|
||||
if (addedPayload < data->rtdPayloadlength) {
|
||||
// add the NDEF_END_BYTE if there is enough space
|
||||
if ((data->rtdPayloadlength - addedPayload) < NFC_PAGE_SIZE)
|
||||
{
|
||||
if ((data->rtdPayloadlength - addedPayload) < NFC_PAGE_SIZE) {
|
||||
memcpy(nfcPageBuffer, &data->rtdPayload[addedPayload], (data->rtdPayloadlength - addedPayload));
|
||||
nfcPageBuffer[(data->rtdPayloadlength - addedPayload)] = NDEF_END_BYTE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
memcpy(nfcPageBuffer, &data->rtdPayload[addedPayload], NFC_PAGE_SIZE);
|
||||
}
|
||||
|
||||
addedPayload += NFC_PAGE_SIZE;
|
||||
ret = NT3HWriteUserData(addPage->page, nfcPageBuffer);
|
||||
|
||||
|
||||
if (ret == false)
|
||||
{
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_WRITE_NDEF_TEXT;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
endRecord = true;
|
||||
}
|
||||
}
|
||||
@@ -240,8 +211,7 @@ bool NT3HwriteRecord(const NDEFDataStr *data)
|
||||
addPage.page = 0;
|
||||
|
||||
// calculate the last used page
|
||||
if (data->ndefPosition != NDEFFirstPos )
|
||||
{
|
||||
if (data->ndefPosition != NDEFFirstPos) {
|
||||
NT3HReadHeaderNfc(&recordLength, &mbMe);
|
||||
addPage.page = (recordLength + sizeof(NDEFHeaderStr) + 1) / NFC_PAGE_SIZE;
|
||||
|
||||
@@ -252,8 +222,7 @@ bool NT3HwriteRecord(const NDEFDataStr *data)
|
||||
// call the appropriate function and consider the pointer
|
||||
// within the NFC_PAGE_SIZE that need to be used
|
||||
int16_t payloadPtr = addFunct[data->ndefPosition](&addPage, data, data->ndefPosition);
|
||||
if (payloadPtr == -1)
|
||||
{
|
||||
if (payloadPtr == -1) {
|
||||
errNo = NT3HERROR_TYPE_NOT_SUPPORTED;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
|
||||
#include "NT3H.h"
|
||||
|
||||
/* 定义报文类型 */
|
||||
#define TYPE_FUNCT_TEXT 0
|
||||
#define TYPE_FUNCT_URI 1
|
||||
#define TYPE_FUNCT_INVALID (-1)
|
||||
|
||||
bool NT3HwriteRecord(const NDEFDataStr *data);
|
||||
|
||||
|
||||
#endif /* NDEF_H_ */
|
||||
Executable → Regular
+8
-11
@@ -20,9 +20,10 @@
|
||||
#include "rtdUri.h"
|
||||
#include "ndef.h"
|
||||
|
||||
|
||||
/* 记录是否已经初始化 */
|
||||
static unsigned char m_nfc_is_init = 0;
|
||||
#define NFC_NOT_INIT 0
|
||||
#define NFC_IS_INIT 1
|
||||
static unsigned char m_nfc_is_init = NFC_NOT_INIT;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -38,8 +39,7 @@ bool nfc_store_uri_http(RecordPosEnu position, uint8_t *http)
|
||||
{
|
||||
NDEFDataStr data;
|
||||
|
||||
if (m_nfc_is_init == 0)
|
||||
{
|
||||
if (m_nfc_is_init == NFC_NOT_INIT) {
|
||||
printf("%s, %s, %d: NFC is not init!\n", __FILE__, __func__, __LINE__);
|
||||
return 0;
|
||||
}
|
||||
@@ -61,8 +61,7 @@ bool nfc_store_text(RecordPosEnu position, uint8_t *text)
|
||||
{
|
||||
NDEFDataStr data;
|
||||
|
||||
if (m_nfc_is_init == 0)
|
||||
{
|
||||
if (m_nfc_is_init == NFC_NOT_INIT) {
|
||||
printf("%s, %s, %d: NFC is not init!\n", __FILE__, __func__, __LINE__);
|
||||
return 0;
|
||||
}
|
||||
@@ -81,15 +80,13 @@ unsigned int nfc_init(void)
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
|
||||
if (m_nfc_is_init == 1)
|
||||
{
|
||||
if (m_nfc_is_init == NFC_IS_INIT) {
|
||||
printf("%s, %s, %d: Nfc readly init!\n", __FILE__, __func__, __LINE__);
|
||||
return __LINE__;
|
||||
}
|
||||
|
||||
ret = NT3HI2cInit();
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("%s, %s, %d: NT3HI2cInit failed!\n", __FILE__, __func__, __LINE__);
|
||||
return __LINE__;
|
||||
}
|
||||
@@ -107,7 +104,7 @@ unsigned int nfc_init(void)
|
||||
***************************************************************/
|
||||
unsigned int nfc_deinit(void)
|
||||
{
|
||||
m_nfc_is_init = 0;
|
||||
m_nfc_is_init = NFC_NOT_INIT;
|
||||
NT3HI2cDeInit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable → Regular
+4
-10
@@ -75,21 +75,15 @@ uint8_t composeRtdUri(const NDEFDataStr *ndef, NDEFRecordStr *ndefRecord, uint8_
|
||||
|
||||
void composeNDEFMBME(bool isFirstRecord, bool isLastRecord, NDEFRecordStr *ndefRecord)
|
||||
{
|
||||
if (isFirstRecord)
|
||||
{
|
||||
if (isFirstRecord) {
|
||||
ndefRecord->header |= BIT_MB;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ndefRecord->header &= ~MASK_MB;
|
||||
}
|
||||
|
||||
if (isLastRecord)
|
||||
{
|
||||
if (isLastRecord) {
|
||||
ndefRecord->header |= BIT_ME;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ndefRecord->header &= ~MASK_ME;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+6
-6
@@ -29,7 +29,7 @@
|
||||
typedef struct {
|
||||
uint8_t startByte;
|
||||
uint8_t payloadLength;
|
||||
}NDEFHeaderStr;
|
||||
} NDEFHeaderStr;
|
||||
|
||||
#define BIT_MB (1<<7)
|
||||
#define BIT_ME (1<<6)
|
||||
@@ -45,11 +45,11 @@ typedef struct {
|
||||
#define MASK_TNF 0x07
|
||||
|
||||
typedef struct {
|
||||
uint8_t header;
|
||||
uint8_t typeLength;
|
||||
uint8_t payloadLength;
|
||||
RTDTypeStr type;
|
||||
}NDEFRecordStr;
|
||||
uint8_t header;
|
||||
uint8_t typeLength;
|
||||
uint8_t payloadLength;
|
||||
RTDTypeStr type;
|
||||
} NDEFRecordStr;
|
||||
|
||||
uint8_t composeRtdText(const NDEFDataStr *ndef, NDEFRecordStr *ndefRecord, uint8_t *I2CMsg);
|
||||
uint8_t composeRtdUri(const NDEFDataStr *ndef, NDEFRecordStr *ndefRecord, uint8_t *I2CMsg);
|
||||
|
||||
Executable → Regular
Executable → Regular
+2
-2
@@ -28,13 +28,13 @@
|
||||
typedef struct {
|
||||
char *body;
|
||||
uint8_t bodyLength;
|
||||
}RtdTextUserPayload;
|
||||
} RtdTextUserPayload;
|
||||
|
||||
typedef struct {
|
||||
uint8_t status;
|
||||
uint8_t language[2];
|
||||
RtdTextUserPayload rtdPayload;
|
||||
}RtdTextTypeStr;
|
||||
} RtdTextTypeStr;
|
||||
|
||||
uint8_t addRtdText(RtdTextTypeStr *typeStr);
|
||||
void prepareText(NDEFDataStr *data, RecordPosEnu position, uint8_t *text);
|
||||
|
||||
Executable → Regular
+1
-1
@@ -30,6 +30,6 @@ typedef union {
|
||||
typedef struct {
|
||||
uint8_t typeCode;
|
||||
RTDTypeUnion typePayload;
|
||||
}RTDTypeStr;
|
||||
} RTDTypeStr;
|
||||
|
||||
#endif /* RTDTYPES_H_ */
|
||||
|
||||
Executable → Regular
Executable → Regular
+30
-33
@@ -18,39 +18,38 @@
|
||||
#ifndef RTDURI_H_
|
||||
#define RTDURI_H_
|
||||
|
||||
typedef enum
|
||||
{
|
||||
freeForm, //0x00 No prepending is done ... the entire URI is contained in the URI Field
|
||||
httpWWW, //0x01 http://www.
|
||||
httpsWWW, //0x02 https://www.
|
||||
http, //0x03 http://
|
||||
https, //0x04 https://
|
||||
tel, //0x05 tel:
|
||||
mailto, //0x06 mailto:
|
||||
ftpAnonymous,//0x07 ftp://anonymous:anonymous@
|
||||
ftpFtp, //0x08 ftp://ftp.
|
||||
ftps, //0x09 ftps://
|
||||
sftp, //0x0A sftp://
|
||||
smb, //0x0B smb://
|
||||
nfs, //0x0C nfs://
|
||||
ftp, //0x0D ftp://
|
||||
dav, //0x0E dav://
|
||||
news, //0x0F news:
|
||||
telnet, //0x10 telnet://
|
||||
imap, //0x11 imap:
|
||||
rtps, //0x12 rtsp://
|
||||
urn, //0x13 urn:
|
||||
typedef enum {
|
||||
freeForm, // 0x00 No prepending is done ... the entire URI is contained in the URI Field
|
||||
httpWWW, // 0x01 http://www.
|
||||
httpsWWW, // 0x02 https://www.
|
||||
http, // 0x03 http://
|
||||
https, // 0x04 https://
|
||||
tel, // 0x05 tel:
|
||||
mailto, // 0x06 mailto:
|
||||
ftpAnonymous, // 0x07 ftp://anonymous:anonymous@
|
||||
ftpFtp, // 0x08 ftp://ftp.
|
||||
ftps, // 0x09 ftps://
|
||||
sftp, // 0x0A sftp://
|
||||
smb, // 0x0B smb://
|
||||
nfs, // 0x0C nfs://
|
||||
ftp, // 0x0D ftp://
|
||||
dav, // 0x0E dav://
|
||||
news, // 0x0F news:
|
||||
telnet, // 0x10 telnet://
|
||||
imap, // 0x11 imap:
|
||||
rtps, // 0x12 rtsp://
|
||||
urn, // 0x13 urn:
|
||||
/*
|
||||
0x14 pop:
|
||||
0x15 sip:
|
||||
0x16 sips:
|
||||
0x17 tftp:
|
||||
0x18 btspp://
|
||||
0x19 btl2cap://
|
||||
0x1A btgoep://
|
||||
0x1B tcpobex://
|
||||
0x1C irdaobex://
|
||||
0x1D file://
|
||||
0x18 btspp: //
|
||||
0x19 btl2cap: //
|
||||
0x1A btgoep: //
|
||||
0x1B tcpobex: //
|
||||
0x1C irdaobex: //
|
||||
0x1D file: //
|
||||
0x1E urn:epc:id:
|
||||
0x1F urn:epc:tag:
|
||||
0x20 urn:epc:pat:
|
||||
@@ -60,20 +59,18 @@ typedef enum
|
||||
*/
|
||||
} UriTypeE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
char *body;
|
||||
uint8_t bodyLength;
|
||||
void *extraData; // herre should be stored specific URI msgs
|
||||
} RtdUriUserPayload;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
UriTypeE type;
|
||||
RtdUriUserPayload userPayload; // here should be stored specific URI msgs
|
||||
} RTDUriTypeStr;
|
||||
|
||||
uint8_t addRtdUriRecord(const NDEFDataStr *ndef, RTDUriTypeStr *typeStr);
|
||||
uint8_t addRtdUriRecord(const NDEFDataStr *ndef, RTDUriTypeStr *uriType);
|
||||
|
||||
void prepareUrihttp(NDEFDataStr *data, RecordPosEnu position, uint8_t *text);
|
||||
|
||||
|
||||
Executable → Regular
+29
-32
@@ -17,67 +17,67 @@
|
||||
#include "ohos_init.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 5000
|
||||
|
||||
void eeprom_proress(void *arg)
|
||||
{
|
||||
#define FOR_CHAR 30
|
||||
#define FOR_ADDRESS 32
|
||||
#define CHAR_START 0x21
|
||||
#define CHAR_END 0x7F
|
||||
#define ADDR_OFFSET_MAX 200
|
||||
unsigned int ret = 0;
|
||||
unsigned char data_offset = CHAR_START;
|
||||
unsigned int addr_offset = 3;
|
||||
unsigned char data;
|
||||
unsigned char buffer[FOR_CHAR];
|
||||
|
||||
|
||||
eeprom_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
printf("************ Eeprom Process ************\n");
|
||||
printf("BlockSize = 0x%x\n", eeprom_get_blocksize());
|
||||
|
||||
|
||||
/* 写EEPROM */
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
for (unsigned int i = 0; i < FOR_CHAR; i++)
|
||||
{
|
||||
for (unsigned int i = 0; i < FOR_CHAR; i++) {
|
||||
buffer[i] = data_offset + i;
|
||||
printf("Write Byte: %d = %c\n", addr_offset + i, buffer[i]);
|
||||
}
|
||||
ret = eeprom_write(addr_offset, buffer, FOR_CHAR);
|
||||
if (ret != FOR_CHAR)
|
||||
{
|
||||
if (ret != FOR_CHAR) {
|
||||
printf("EepromWrite failed(%d)\n", ret);
|
||||
}
|
||||
|
||||
|
||||
/* 读EEPROM */
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
ret = eeprom_read(addr_offset, buffer, FOR_CHAR);
|
||||
if (ret != FOR_CHAR)
|
||||
{
|
||||
if (ret != FOR_CHAR) {
|
||||
printf("Read Bytes: failed!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < FOR_CHAR; i++)
|
||||
{
|
||||
} else {
|
||||
for (unsigned int i = 0; i < FOR_CHAR; i++) {
|
||||
printf("Read Byte: %d = %c\n", addr_offset + i, buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data_offset++;
|
||||
if (data_offset >= CHAR_END)
|
||||
{
|
||||
if (data_offset >= CHAR_END) {
|
||||
data_offset = CHAR_START;
|
||||
}
|
||||
|
||||
|
||||
addr_offset += FOR_ADDRESS;
|
||||
if (addr_offset >= 200)
|
||||
{
|
||||
if (addr_offset >= ADDR_OFFSET_MAX) {
|
||||
addr_offset = 0;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
LOS_Msleep(5000);
|
||||
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,17 +88,14 @@ void eeprom_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)eeprom_proress;
|
||||
task.uwStackSize = 2048;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "eeprom process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(eeprom_example);
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+5
-5
@@ -42,7 +42,7 @@ unsigned int eeprom_get_blocksize();
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_readbyte
|
||||
* 说 明: EEPROM读一个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址
|
||||
* @data: 存放EERPOM的数据指针
|
||||
* 返 回 值: 返回读取字节的长度,反之为错误
|
||||
@@ -52,7 +52,7 @@ unsigned int eeprom_readbyte(unsigned int addr, unsigned char *data);
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_writebyte
|
||||
* 说 明: EEPROM写一个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址
|
||||
* @data: 写ERPOM的数据
|
||||
* 返 回 值: 返回写入数据的长度,反之为错误
|
||||
@@ -62,7 +62,7 @@ unsigned int eeprom_writebyte(unsigned int addr, unsigned char data);
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_writepage
|
||||
* 说 明: EEPROM写1个页字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址,必须是页地址
|
||||
* @data: 写ERPOM的数据指针
|
||||
* @data_len: 写EEPROM数据的长度,必须是小于或等于1个页大小
|
||||
@@ -73,7 +73,7 @@ unsigned int eeprom_writepage(unsigned int addr, unsigned char *data, unsigned i
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_read
|
||||
* 说 明: EEPROM读多个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EERPOM存储地址
|
||||
* @data: 存放EERPOM的数据指针
|
||||
* @data_len: 读取EERPOM数据的长度
|
||||
@@ -84,7 +84,7 @@ unsigned int eeprom_read(unsigned int addr, unsigned char *data, unsigned int da
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_write
|
||||
* 说 明: EEPROM写多个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址
|
||||
* @data: 写ERPOM的数据指针
|
||||
* @data_len: 写EEPROM数据的长度
|
||||
|
||||
Executable → Regular
+28
-25
@@ -30,19 +30,22 @@ static I2cBusIo m_i2cBus = {
|
||||
|
||||
static unsigned int m_i2c_freq = 100000;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
/* 等待时间 */
|
||||
#define EEPROG_DELAY_USEC 1
|
||||
#define K24C02_DELAY_USEC 1000
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: eeprog_delay_usec
|
||||
* 说 明: 忙等待usec
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @usec:等待时间,单位:usec
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
static inline void eeprog_delay_usec(unsigned int usec)
|
||||
{
|
||||
for (unsigned int i = 0; i < usec; i++)
|
||||
HAL_DelayUs(1);
|
||||
for (unsigned int i = 0; i < usec; i++) {
|
||||
HAL_DelayUs(EEPROG_DELAY_USEC);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -98,7 +101,7 @@ unsigned int eeprom_get_blocksize()
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_readbyte
|
||||
* 说 明: EEPROM读一个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址
|
||||
* @data: 存放EERPOM的数据指针
|
||||
* 返 回 值: 返回读取字节的长度,反之为错误
|
||||
@@ -127,11 +130,11 @@ unsigned int eeprom_readbyte(unsigned int addr, unsigned char *data)
|
||||
msgs[1].buf = data;
|
||||
msgs[1].len = 1;
|
||||
|
||||
ret = LzI2cTransfer(EEPROM_I2C_BUS, msgs, 2);
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cTransfer failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
ret = LzI2cTransfer(EEPROM_I2C_BUS, msgs, 2);
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cTransfer failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -139,7 +142,7 @@ unsigned int eeprom_readbyte(unsigned int addr, unsigned char *data)
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_writebyte
|
||||
* 说 明: EEPROM写一个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址
|
||||
* @data: 写EERPOM的数据
|
||||
* 返 回 值: 返回写入数据的长度,反之为错误
|
||||
@@ -166,8 +169,8 @@ unsigned int eeprom_writebyte(unsigned int addr, unsigned char data)
|
||||
|
||||
ret = LzI2cTransfer(EEPROM_I2C_BUS, msgs, 1);
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cTransfer failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
printf("%s, %s, %d: LzI2cTransfer failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* K24C02芯片需要时间完成写操作,在此之前不响应其他操作*/
|
||||
@@ -179,7 +182,7 @@ unsigned int eeprom_writebyte(unsigned int addr, unsigned char data)
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_writepage
|
||||
* 说 明: EEPROM写1个页字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址,必须是页地址
|
||||
* @data: 写EERPOM的数据指针
|
||||
* @data_len: 写EEPROM数据的长度,必须是小于1个页大小
|
||||
@@ -190,7 +193,7 @@ unsigned int eeprom_writepage(unsigned int addr, unsigned char *data, unsigned i
|
||||
unsigned int ret = 0;
|
||||
LzI2cMsg msgs[1];
|
||||
unsigned char buffer[EEPROM_PAGE + 1];
|
||||
|
||||
|
||||
/* K24C02的存储地址是0~255 */
|
||||
if (addr >= EEPROM_ADDRESS_MAX) {
|
||||
printf("%s, %s, %d: addr(0x%x) >= EEPROM_ADDRESS_MAX(0x%x)\n", __FILE__, __func__, __LINE__, addr, EEPROM_ADDRESS_MAX);
|
||||
@@ -214,7 +217,7 @@ unsigned int eeprom_writepage(unsigned int addr, unsigned char *data, unsigned i
|
||||
|
||||
buffer[0] = addr;
|
||||
memcpy(&buffer[1], data, data_len);
|
||||
|
||||
|
||||
msgs[0].addr = EEPROM_I2C_ADDRESS;
|
||||
msgs[0].flags = 0;
|
||||
msgs[0].buf = &buffer[0];
|
||||
@@ -222,12 +225,12 @@ unsigned int eeprom_writepage(unsigned int addr, unsigned char *data, unsigned i
|
||||
|
||||
ret = LzI2cTransfer(EEPROM_I2C_BUS, msgs, 1);
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cTransfer failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
printf("%s, %s, %d: LzI2cTransfer failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* K24C02芯片需要时间完成写操作,在此之前不响应其他操作*/
|
||||
eeprog_delay_usec(1000);
|
||||
eeprog_delay_usec(K24C02_DELAY_USEC);
|
||||
|
||||
return data_len;
|
||||
}
|
||||
@@ -235,13 +238,13 @@ unsigned int eeprom_writepage(unsigned int addr, unsigned char *data, unsigned i
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_read
|
||||
* 说 明: EEPROM读多个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EERPOM存储地址
|
||||
* @data: 存放EERPOM的数据指针
|
||||
* @data_len: 读取EERPOM数据的长度
|
||||
* 返 回 值: 返回读取字节的长度,反之为错误
|
||||
***************************************************************/
|
||||
unsigned int eeprom_read(unsigned int addr, unsigned char *data, unsigned int data_len)
|
||||
unsigned int eeprom_read(unsigned int addr, unsigned char *data, unsigned int data_len)
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
|
||||
@@ -253,7 +256,7 @@ unsigned int eeprom_read(unsigned int addr, unsigned char *data, unsigned int da
|
||||
if ((addr + data_len) > EEPROM_ADDRESS_MAX) {
|
||||
printf("%s, %s, %d: addr + len(0x%x) > EEPROM_ADDRESS_MAX(0x%x)\n", __FILE__, __func__, __LINE__, addr + data_len, EEPROM_ADDRESS_MAX);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ret = eeprom_readbyte(addr, data);
|
||||
if (ret != 1) {
|
||||
@@ -275,7 +278,7 @@ unsigned int eeprom_read(unsigned int addr, unsigned char *data, unsigned int da
|
||||
/***************************************************************
|
||||
* 函数名称: eeprom_write
|
||||
* 说 明: EEPROM写多个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: EEPROM存储地址
|
||||
* @data: 写EERPOM的数据指针
|
||||
* @data_len: 写EEPROM数据的长度
|
||||
@@ -315,7 +318,7 @@ unsigned int eeprom_write(unsigned int addr, unsigned char *data, unsigned int d
|
||||
}
|
||||
|
||||
offset_current = 0;
|
||||
|
||||
|
||||
/* 处理前面非页地址的数据,如果是页地址则不执行 */
|
||||
for (unsigned int i = addr; i < (page_start * EEPROM_PAGE); i++) {
|
||||
ret = eeprom_writebyte(i, data[offset_current]);
|
||||
@@ -332,7 +335,7 @@ unsigned int eeprom_write(unsigned int addr, unsigned char *data, unsigned int d
|
||||
if ((page == (page_end - 1)) && (is_data_back)) {
|
||||
len = (addr + data_len) % EEPROM_PAGE;
|
||||
}
|
||||
|
||||
|
||||
ret = eeprom_writepage(page * EEPROM_PAGE, &data[offset_current], len);
|
||||
if (ret != len) {
|
||||
printf("%s, %s, %d: EepromWritePage failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
|
||||
@@ -52,6 +52,11 @@
|
||||
#define LCD_LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
|
||||
#define LCD_LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
|
||||
|
||||
/* 字体大小 */
|
||||
#define LCD_FONT_SIZE12 12
|
||||
#define LCD_FONT_SIZE16 16
|
||||
#define LCD_FONT_SIZE24 24
|
||||
#define LCD_FONT_SIZE32 32
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: lcd_init
|
||||
|
||||
Executable → Regular
+1457
-424
File diff suppressed because it is too large
Load Diff
Executable → Regular
+118
-37
@@ -17,9 +17,81 @@
|
||||
#include "picture.h"
|
||||
#include "lcd.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 1000
|
||||
|
||||
/* 图片数据 */
|
||||
extern const unsigned char gImage_lingzhi[IMAGE_MAXSIZE_LINGZHI];
|
||||
|
||||
|
||||
/* LCD的位置 */
|
||||
#define LCD_FILL_X 0
|
||||
#define LCD_FILL_Y 0
|
||||
/* 图片的位置,长度和宽度 */
|
||||
#define LCD_PICTURE_X 15
|
||||
#define LCD_PICTURE_Y 0
|
||||
#define LCD_PICTURE_LENGTH 210
|
||||
#define LCD_PICTURE_WIDTH 62
|
||||
/* 字符串1的位置,长度和宽度 */
|
||||
#define LCD_STRING1_X 0
|
||||
#define LCD_STRING1_Y 130
|
||||
#define LCD_STRING1_SIZE 16
|
||||
#define LCD_STRING1_TEXT "Welcome to XiaoLingPai!"
|
||||
#define LCD_STRING1_MODE 0
|
||||
/* 字符串2的位置,长度和宽度 */
|
||||
#define LCD_STRING2_X 0
|
||||
#define LCD_STRING2_Y 130
|
||||
#define LCD_STRING2_SIZE 16
|
||||
#define LCD_STRING2_TEXT "URL: http://www.fzlzda.com"
|
||||
#define LCD_STRING2_MODE 0
|
||||
/* 字符串3的位置,长度和宽度 */
|
||||
#define LCD_STRING3_X 0
|
||||
#define LCD_STRING3_Y 160
|
||||
#define LCD_STRING3_SIZE 16
|
||||
#define LCD_STRING3_TEXT "LCD_W:"
|
||||
#define LCD_STRING3_MODE 0
|
||||
/* 数字1int的位置,长度和宽度 */
|
||||
#define LCD_INT1_X 128
|
||||
#define LCD_INT1_Y 160
|
||||
#define LCD_INT1_SIZE 16
|
||||
#define LCD_INT1_VALUE 3
|
||||
/* 字符串4的位置,长度和宽度 */
|
||||
#define LCD_STRING4_X 80
|
||||
#define LCD_STRING4_Y 160
|
||||
#define LCD_STRING4_SIZE 16
|
||||
#define LCD_STRING4_TEXT "LCD_H:"
|
||||
#define LCD_STRING4_MODE 0
|
||||
/* 数字2int的位置,长度和宽度 */
|
||||
#define LCD_INT2_X 128
|
||||
#define LCD_INT2_Y 160
|
||||
#define LCD_INT2_SIZE 16
|
||||
#define LCD_INT2_VALUE 3
|
||||
/* 字符串5的位置,长度和宽度 */
|
||||
#define LCD_STRING5_X 80
|
||||
#define LCD_STRING5_Y 160
|
||||
#define LCD_STRING5_SIZE 16
|
||||
#define LCD_STRING5_TEXT "LCD_H:"
|
||||
#define LCD_STRING5_MODE 0
|
||||
/* 字符串6的位置,长度和宽度 */
|
||||
#define LCD_STRING6_X 0
|
||||
#define LCD_STRING6_Y 190
|
||||
#define LCD_STRING6_SIZE 16
|
||||
#define LCD_STRING6_TEXT "Increaseing Num:"
|
||||
#define LCD_STRING6_MODE 0
|
||||
/* 数字float的位置,长度和宽度 */
|
||||
#define LCD_FLOAT1_X 128
|
||||
#define LCD_FLOAT1_Y 190
|
||||
#define LCD_FLOAT1_SIZE 16
|
||||
#define LCD_FLOAT1_NUM 4
|
||||
#define LCD_FLOAT1_INCREASE (0.11)
|
||||
/* 中文数字的位置,长度和宽度 */
|
||||
#define LCD_CHINESE_X 0
|
||||
#define LCD_CHINESE_Y 220
|
||||
#define LCD_CHINESE_MODE 0
|
||||
/***************************************************************
|
||||
* 函数名称: lcd_process
|
||||
* 说 明: lcd例程
|
||||
@@ -31,45 +103,55 @@ void lcd_process(void *arg)
|
||||
uint32_t ret = 0;
|
||||
float t = 0;
|
||||
uint8_t chinese_string[] = "小凌派";
|
||||
uint8_t cur_sizey = 12;
|
||||
uint8_t cur_sizey = SIZEY_12;
|
||||
|
||||
ret = lcd_init();
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("lcd_init failed(%d)\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
lcd_fill(0, 0, LCD_W, LCD_H, LCD_WHITE);
|
||||
lcd_fill(LCD_FILL_X, LCD_FILL_Y, LCD_W, LCD_H, LCD_WHITE);
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
printf("************Lcd Example***********\n");
|
||||
lcd_show_picture(15, 0, 210, 62, &gImage_lingzhi[0]);
|
||||
lcd_show_string(0, 100, "Welcome to XiaoLingPai!", LCD_RED, LCD_WHITE, 16, 0);
|
||||
lcd_show_string(0, 130, "URL: http://www.fzlzda.com", LCD_RED, LCD_WHITE, 16, 0);
|
||||
lcd_show_string(0, 160, "LCD_W:", LCD_BLUE, LCD_WHITE, 16, 0);
|
||||
lcd_show_int_num(48, 160, LCD_W, 3, LCD_BLUE, LCD_WHITE, 16);
|
||||
lcd_show_string(80, 160, "LCD_H:", LCD_BLUE, LCD_WHITE, 16, 0);
|
||||
lcd_show_int_num(128, 160, LCD_H, 3, LCD_BLUE, LCD_WHITE, 16);
|
||||
lcd_show_string(80, 160, "LCD_H:", LCD_BLUE, LCD_WHITE, 16, 0);
|
||||
lcd_show_string(0, 190, "Increaseing Num:", LCD_BLACK, LCD_WHITE, 16, 0);
|
||||
lcd_show_float_num1(128, 190, t, 4, LCD_BLACK, LCD_WHITE, 16);
|
||||
t += 0.11;
|
||||
|
||||
lcd_fill(0, 220, LCD_W, LCD_H, LCD_WHITE);
|
||||
lcd_show_chinese(0, 220, chinese_string, LCD_RED, LCD_WHITE, cur_sizey, 0);
|
||||
if (cur_sizey == 12)
|
||||
cur_sizey = 16;
|
||||
else if(cur_sizey == 16)
|
||||
cur_sizey = 24;
|
||||
else if(cur_sizey == 24)
|
||||
cur_sizey = 32;
|
||||
else
|
||||
cur_sizey = 12;
|
||||
|
||||
lcd_show_picture(LCD_PICTURE_X, LCD_PICTURE_Y, LCD_PICTURE_LENGTH,
|
||||
LCD_PICTURE_WIDTH, &gImage_lingzhi[0]);
|
||||
lcd_show_string(LCD_STRING1_X, LCD_STRING1_Y, LCD_STRING1_TEXT,
|
||||
LCD_RED, LCD_WHITE, LCD_STRING1_SIZE, LCD_STRING1_MODE);
|
||||
lcd_show_string(LCD_STRING2_X, LCD_STRING2_Y, LCD_STRING2_TEXT,
|
||||
LCD_RED, LCD_WHITE, LCD_STRING2_SIZE, LCD_STRING2_MODE);
|
||||
lcd_show_string(LCD_STRING3_X, LCD_STRING3_Y, LCD_STRING3_TEXT,
|
||||
LCD_BLUE, LCD_WHITE, LCD_STRING3_SIZE, LCD_STRING3_MODE);
|
||||
lcd_show_int_num(LCD_INT1_X, LCD_INT1_Y, LCD_W, LCD_INT1_VALUE,
|
||||
LCD_BLUE, LCD_WHITE, LCD_INT1_SIZE);
|
||||
lcd_show_string(LCD_STRING4_X, LCD_STRING4_Y, LCD_STRING4_TEXT,
|
||||
LCD_BLUE, LCD_WHITE, LCD_STRING4_SIZE, LCD_STRING4_MODE);
|
||||
lcd_show_int_num(LCD_INT2_X, LCD_INT2_Y, LCD_H, LCD_INT2_VALUE,
|
||||
LCD_BLUE, LCD_WHITE, LCD_INT2_SIZE);
|
||||
lcd_show_string(LCD_STRING5_X, LCD_STRING5_Y, LCD_STRING5_TEXT,
|
||||
LCD_BLUE, LCD_WHITE, LCD_STRING5_SIZE, LCD_STRING5_MODE);
|
||||
lcd_show_string(LCD_STRING6_X, LCD_STRING6_Y, LCD_STRING6_TEXT,
|
||||
LCD_BLACK, LCD_WHITE, LCD_STRING6_SIZE, LCD_STRING6_MODE);
|
||||
lcd_show_float_num1(LCD_FLOAT1_X, LCD_FLOAT1_Y, t,
|
||||
LCD_FLOAT1_NUM, LCD_BLACK, LCD_WHITE, LCD_FLOAT1_SIZE);
|
||||
t += LCD_FLOAT1_INCREASE;
|
||||
|
||||
lcd_fill(LCD_CHINESE_X, LCD_CHINESE_Y, LCD_W, LCD_H, LCD_WHITE);
|
||||
lcd_show_chinese(LCD_CHINESE_X, LCD_CHINESE_Y, chinese_string,
|
||||
LCD_RED, LCD_WHITE, cur_sizey, LCD_CHINESE_MODE);
|
||||
if (cur_sizey == LCD_FONT_SIZE12) {
|
||||
cur_sizey = LCD_FONT_SIZE16;
|
||||
} else if (cur_sizey == LCD_FONT_SIZE16) {
|
||||
cur_sizey = LCD_FONT_SIZE24;
|
||||
} else if (cur_sizey == LCD_FONT_SIZE24) {
|
||||
cur_sizey = LCD_FONT_SIZE32;
|
||||
} else {
|
||||
cur_sizey = LCD_FONT_SIZE12;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,15 +167,14 @@ void lcd_example()
|
||||
unsigned int thread_id;
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)lcd_process;
|
||||
task.uwStackSize = 20480;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "lcd process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+235
-349
@@ -56,10 +56,35 @@ static SpiBusIo m_spiBus = {
|
||||
};
|
||||
|
||||
static LzSpiConfig m_spiConf = {.bitsPerWord = SPI_PERWORD_8BITS, .firstBit = SPI_MSB, .mode = SPI_MODE_3,
|
||||
.csm = SPI_CMS_ONE_CYCLES, .speed = 50000000, .isSlave = false};
|
||||
.csm = SPI_CMS_ONE_CYCLES, .speed = 50000000, .isSlave = false
|
||||
};
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/* 寄存器定义 */
|
||||
#define REG_ADDRESS_COLUMN 0x2a
|
||||
#define REG_ADDRESS_LINE 0x2B
|
||||
#define REG_ADDRESS_WRITE 0x2C
|
||||
|
||||
/* 寄存器位数 */
|
||||
#define REG_BITS_MAXSIZE 8
|
||||
|
||||
/* 寄存器最高位 */
|
||||
#define REG_BITS_HIGH (0x80)
|
||||
|
||||
/* uint16取值 */
|
||||
#define UINT16_TO_H(val) (((val) & 0xFF00) >> 8)
|
||||
#define UINT16_TO_L(val) ((val) & 0x00FF)
|
||||
|
||||
/* 字节转化为bits */
|
||||
#define BYTE_TO_BITS 8
|
||||
|
||||
/* LCD配置模式 */
|
||||
#define LCD_HORIZONTAL_MODE1 1
|
||||
#define LCD_HORIZONTAL_MODE2 2
|
||||
|
||||
/* 中文转化为UTF-8的字节数 */
|
||||
#define CHINESE_TO_BYTES 2
|
||||
|
||||
|
||||
static void lcd_write_bus(uint8_t dat)
|
||||
{
|
||||
@@ -67,22 +92,18 @@ static void lcd_write_bus(uint8_t dat)
|
||||
LzSpiWrite(LCD_SPI_BUS, 0, &dat, 1);
|
||||
#else
|
||||
uint8_t i;
|
||||
|
||||
|
||||
LCD_CS_Clr();
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < REG_BITS_MAXSIZE; i++) {
|
||||
LCD_CLK_Clr();
|
||||
if (dat & 0x80)
|
||||
{
|
||||
if (dat & REG_BITS_HIGH) {
|
||||
LCD_MOSI_Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LCD_MOSI_Clr();
|
||||
}
|
||||
LCD_CLK_Set();
|
||||
dat<<=1;
|
||||
}
|
||||
dat <<= 1;
|
||||
}
|
||||
LCD_CS_Set();
|
||||
#endif
|
||||
}
|
||||
@@ -94,8 +115,8 @@ static void lcd_wr_data8(uint8_t dat)
|
||||
|
||||
static void lcd_wr_data(uint16_t dat)
|
||||
{
|
||||
lcd_write_bus(dat >> 8);
|
||||
lcd_write_bus(dat);
|
||||
lcd_write_bus(UINT16_TO_H(dat));
|
||||
lcd_write_bus(UINT16_TO_L(dat));
|
||||
}
|
||||
|
||||
static void lcd_wr_reg(uint8_t dat)
|
||||
@@ -108,26 +129,25 @@ static void lcd_wr_reg(uint8_t dat)
|
||||
static void lcd_address_set(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
||||
{
|
||||
/* 列地址设置 */
|
||||
lcd_wr_reg(0x2a);
|
||||
lcd_wr_reg(REG_ADDRESS_COLUMN);
|
||||
lcd_wr_data(x1);
|
||||
lcd_wr_data(x2);
|
||||
/* 行地址设置 */
|
||||
lcd_wr_reg(0x2b);
|
||||
lcd_wr_reg(REG_ADDRESS_LINE);
|
||||
lcd_wr_data(y1);
|
||||
lcd_wr_data(y2);
|
||||
/* 储存器写 */
|
||||
lcd_wr_reg(0x2c);
|
||||
lcd_wr_reg(REG_ADDRESS_WRITE);
|
||||
}
|
||||
|
||||
static uint32_t mypow(uint8_t m, uint8_t n)
|
||||
{
|
||||
uint32_t result = 1;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
|
||||
while (n--) {
|
||||
result *= m;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -147,55 +167,44 @@ static uint32_t mypow(uint8_t m, uint8_t n)
|
||||
***************************************************************/
|
||||
static void lcd_show_chinese_12x12(uint16_t x, uint16_t y, uint8_t *s, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode)
|
||||
{
|
||||
uint8_t i, j, m=0;
|
||||
uint8_t i, j, m = 0;
|
||||
uint16_t k;
|
||||
uint16_t HZnum;//汉字数目
|
||||
uint16_t TypefaceNum;//一个字符所占字节大小
|
||||
uint16_t x0 = x;
|
||||
|
||||
TypefaceNum = (sizey/8+((sizey%8)?1:0)) * sizey;
|
||||
|
||||
TypefaceNum = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * sizey;
|
||||
|
||||
/* 统计汉字数目 */
|
||||
HZnum = sizeof(tfont12) / sizeof(typFNT_GB12);
|
||||
|
||||
for (k = 0; k < HZnum; k++)
|
||||
{
|
||||
if ((tfont12[k].Index[0] == *(s)) && (tfont12[k].Index[1] == *(s+1)))
|
||||
{
|
||||
lcd_address_set(x, y, x+sizey-1, y+sizey-1);
|
||||
for (i = 0; i < TypefaceNum; i++)
|
||||
{
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if (!mode)
|
||||
{/* 非叠加方式 */
|
||||
if (tfont12[k].Msk[i] & (0x01<<j))
|
||||
{
|
||||
for (k = 0; k < HZnum; k++) {
|
||||
if ((tfont12[k].Index[0] == *(s)) && (tfont12[k].Index[1] == *(s + 1))) {
|
||||
lcd_address_set(x, y, x + sizey - 1, y + sizey - 1);
|
||||
for (i = 0; i < TypefaceNum; i++) {
|
||||
for (j = 0; j < BYTE_TO_BITS; j++) {
|
||||
if (!mode) {
|
||||
/* 非叠加方式 */
|
||||
if (tfont12[k].Msk[i] & (0x01 << j)) {
|
||||
lcd_wr_data(fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lcd_wr_data(bc);
|
||||
}
|
||||
|
||||
|
||||
m++;
|
||||
if ((m % sizey) == 0)
|
||||
{
|
||||
if ((m % sizey) == 0) {
|
||||
m = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{/* 叠加方式 */
|
||||
if (tfont12[k].Msk[i] & (0x01<<j))
|
||||
{
|
||||
} else {
|
||||
/* 叠加方式 */
|
||||
if (tfont12[k].Msk[i] & (0x01 << j)) {
|
||||
/* 画一个点 */
|
||||
lcd_draw_point(x,y,fc);
|
||||
lcd_draw_point(x, y, fc);
|
||||
}
|
||||
|
||||
|
||||
x++;
|
||||
if ((x - x0) == sizey)
|
||||
{
|
||||
if ((x - x0) == sizey) {
|
||||
x = x0;
|
||||
y++;
|
||||
break;
|
||||
@@ -207,7 +216,7 @@ static void lcd_show_chinese_12x12(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
break; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: lcd_show_chinese_16x16
|
||||
@@ -229,49 +238,38 @@ static void lcd_show_chinese_16x16(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
uint16_t HZnum;//汉字数目
|
||||
uint16_t TypefaceNum;//一个字符所占字节大小
|
||||
uint16_t x0 = x;
|
||||
|
||||
TypefaceNum = (sizey/8 + ((sizey%8)?1:0)) * sizey;
|
||||
|
||||
TypefaceNum = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * sizey;
|
||||
/* 统计汉字数目 */
|
||||
HZnum=sizeof(tfont16) / sizeof(typFNT_GB16);
|
||||
|
||||
for (k = 0; k < HZnum; k++)
|
||||
{
|
||||
if ((tfont16[k].Index[0] == *(s)) && (tfont16[k].Index[1] == *(s+1)))
|
||||
{
|
||||
lcd_address_set(x, y, x+sizey-1, y+sizey-1);
|
||||
for (i = 0; i < TypefaceNum; i++)
|
||||
{
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if (!mode)
|
||||
{/* 非叠加方式 */
|
||||
if (tfont16[k].Msk[i] & (0x01 << j))
|
||||
{
|
||||
HZnum = sizeof(tfont16) / sizeof(typFNT_GB16);
|
||||
|
||||
for (k = 0; k < HZnum; k++) {
|
||||
if ((tfont16[k].Index[0] == *(s)) && (tfont16[k].Index[1] == *(s + 1))) {
|
||||
lcd_address_set(x, y, x + sizey - 1, y + sizey - 1);
|
||||
for (i = 0; i < TypefaceNum; i++) {
|
||||
for (j = 0; j < BYTE_TO_BITS; j++) {
|
||||
if (!mode) {
|
||||
/* 非叠加方式 */
|
||||
if (tfont16[k].Msk[i] & (0x01 << j)) {
|
||||
lcd_wr_data(fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lcd_wr_data(bc);
|
||||
}
|
||||
|
||||
|
||||
m++;
|
||||
if (m%sizey == 0)
|
||||
{
|
||||
if (m % sizey == 0) {
|
||||
m = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{/* 叠加方式 */
|
||||
if (tfont16[k].Msk[i] & (0x01<<j))
|
||||
{
|
||||
} else {
|
||||
/* 叠加方式 */
|
||||
if (tfont16[k].Msk[i] & (0x01 << j)) {
|
||||
/* 画一个点 */
|
||||
lcd_draw_point(x,y,fc);
|
||||
lcd_draw_point(x, y, fc);
|
||||
}
|
||||
|
||||
|
||||
x++;
|
||||
if ((x - x0) == sizey)
|
||||
{
|
||||
if ((x - x0) == sizey) {
|
||||
x = x0;
|
||||
y++;
|
||||
break;
|
||||
@@ -283,7 +281,7 @@ static void lcd_show_chinese_16x16(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
break; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
@@ -301,54 +299,43 @@ static void lcd_show_chinese_16x16(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
***************************************************************/
|
||||
static void lcd_show_chinese_24x24(uint16_t x, uint16_t y, uint8_t *s, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode)
|
||||
{
|
||||
uint8_t i,j,m = 0;
|
||||
uint8_t i, j, m = 0;
|
||||
uint16_t k;
|
||||
uint16_t HZnum;//汉字数目
|
||||
uint16_t TypefaceNum;//一个字符所占字节大小
|
||||
uint16_t x0 = x;
|
||||
|
||||
TypefaceNum = (sizey/8 + ((sizey%8)?1:0)) * sizey;
|
||||
|
||||
TypefaceNum = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * sizey;
|
||||
/* 统计汉字数目 */
|
||||
HZnum = sizeof(tfont24) / sizeof(typFNT_GB24);
|
||||
|
||||
for (k = 0; k < HZnum; k++)
|
||||
{
|
||||
if ((tfont24[k].Index[0] == *(s)) && (tfont24[k].Index[1] == *(s+1)))
|
||||
{
|
||||
lcd_address_set(x, y, x+sizey-1, y+sizey-1);
|
||||
for (i = 0; i < TypefaceNum; i++)
|
||||
{
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if (!mode)
|
||||
{/* 非叠加方式 */
|
||||
if (tfont24[k].Msk[i] & (0x01<<j))
|
||||
{
|
||||
|
||||
for (k = 0; k < HZnum; k++) {
|
||||
if ((tfont24[k].Index[0] == *(s)) && (tfont24[k].Index[1] == *(s + 1))) {
|
||||
lcd_address_set(x, y, x + sizey - 1, y + sizey - 1);
|
||||
for (i = 0; i < TypefaceNum; i++) {
|
||||
for (j = 0; j < BYTE_TO_BITS; j++) {
|
||||
if (!mode) {
|
||||
/* 非叠加方式 */
|
||||
if (tfont24[k].Msk[i] & (0x01 << j)) {
|
||||
lcd_wr_data(fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lcd_wr_data(bc);
|
||||
}
|
||||
|
||||
|
||||
m++;
|
||||
if (m%sizey == 0)
|
||||
{
|
||||
if (m % sizey == 0) {
|
||||
m = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{/* 叠加方式 */
|
||||
if (tfont24[k].Msk[i] & (0x01 << j))
|
||||
{
|
||||
} else {
|
||||
/* 叠加方式 */
|
||||
if (tfont24[k].Msk[i] & (0x01 << j)) {
|
||||
/* 画一个点 */
|
||||
lcd_draw_point(x, y, fc);
|
||||
}
|
||||
|
||||
|
||||
x++;
|
||||
if ((x - x0) == sizey)
|
||||
{
|
||||
if ((x - x0) == sizey) {
|
||||
x = x0;
|
||||
y++;
|
||||
break;
|
||||
@@ -360,7 +347,7 @@ static void lcd_show_chinese_24x24(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
break; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
@@ -378,53 +365,42 @@ static void lcd_show_chinese_24x24(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
***************************************************************/
|
||||
static void lcd_show_chinese_32x32(uint16_t x, uint16_t y, uint8_t *s, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode)
|
||||
{
|
||||
uint8_t i,j,m = 0;
|
||||
uint8_t i, j, m = 0;
|
||||
uint16_t k;
|
||||
uint16_t HZnum;//汉字数目
|
||||
uint16_t TypefaceNum;//一个字符所占字节大小
|
||||
uint16_t x0 = x;
|
||||
|
||||
TypefaceNum = (sizey/8 + ((sizey%8)?1:0)) * sizey;
|
||||
|
||||
TypefaceNum = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * sizey;
|
||||
/* 统计汉字数目 */
|
||||
HZnum = sizeof(tfont32) / sizeof(typFNT_GB32);
|
||||
|
||||
for (k = 0; k < HZnum; k++)
|
||||
{
|
||||
if ((tfont32[k].Index[0] == *(s)) && (tfont32[k].Index[1] == *(s+1)))
|
||||
{
|
||||
lcd_address_set(x, y, x+sizey-1, y+sizey-1);
|
||||
for (i = 0; i < TypefaceNum; i++)
|
||||
{
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if (!mode)
|
||||
{/* 非叠加方式 */
|
||||
if (tfont32[k].Msk[i] & (0x01 << j))
|
||||
{
|
||||
|
||||
for (k = 0; k < HZnum; k++) {
|
||||
if ((tfont32[k].Index[0] == *(s)) && (tfont32[k].Index[1] == *(s + 1))) {
|
||||
lcd_address_set(x, y, x + sizey - 1, y + sizey - 1);
|
||||
for (i = 0; i < TypefaceNum; i++) {
|
||||
for (j = 0; j < BYTE_TO_BITS; j++) {
|
||||
if (!mode) {
|
||||
/* 非叠加方式 */
|
||||
if (tfont32[k].Msk[i] & (0x01 << j)) {
|
||||
lcd_wr_data(fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lcd_wr_data(bc);
|
||||
}
|
||||
|
||||
|
||||
m++;
|
||||
if (m%sizey == 0)
|
||||
{
|
||||
if (m % sizey == 0) {
|
||||
m = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{/* 叠加方式 */
|
||||
if (tfont32[k].Msk[i] & (0x01 << j))
|
||||
{
|
||||
} else {
|
||||
/* 叠加方式 */
|
||||
if (tfont32[k].Msk[i] & (0x01 << j)) {
|
||||
lcd_draw_point(x, y, fc);//画一个点
|
||||
}
|
||||
|
||||
|
||||
x++;
|
||||
if ((x-x0) == sizey)
|
||||
{
|
||||
if ((x - x0) == sizey) {
|
||||
x = x0;
|
||||
y++;
|
||||
break;
|
||||
@@ -495,20 +471,13 @@ unsigned int lcd_init()
|
||||
LOS_Msleep(100);
|
||||
/* 启动LCD配置,设置显示和颜色配置 */
|
||||
lcd_wr_reg(0X36);
|
||||
if (USE_HORIZONTAL == 0)
|
||||
{
|
||||
if (USE_HORIZONTAL == 0) {
|
||||
lcd_wr_data8(0x00);
|
||||
}
|
||||
else if (USE_HORIZONTAL == 1)
|
||||
{
|
||||
} else if (USE_HORIZONTAL == LCD_HORIZONTAL_MODE1) {
|
||||
lcd_wr_data8(0xC0);
|
||||
}
|
||||
else if (USE_HORIZONTAL == 2)
|
||||
{
|
||||
} else if (USE_HORIZONTAL == LCD_HORIZONTAL_MODE2) {
|
||||
lcd_wr_data8(0x70);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lcd_wr_data8(0xA0);
|
||||
}
|
||||
lcd_wr_reg(0X3A);
|
||||
@@ -598,7 +567,7 @@ unsigned int lcd_deinit()
|
||||
#endif
|
||||
LzGpioDeinit(LCD_PIN_RES);
|
||||
LzGpioDeinit(LCD_PIN_DC);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -619,12 +588,10 @@ void lcd_fill(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16
|
||||
uint16_t i, j;
|
||||
|
||||
/* 设置显示范围 */
|
||||
lcd_address_set(xsta, ysta, xend-1, yend-1);
|
||||
lcd_address_set(xsta, ysta, xend - 1, yend - 1);
|
||||
/* 填充颜色 */
|
||||
for (i = ysta; i < yend; i++)
|
||||
{
|
||||
for (j = xsta; j < xend; j++)
|
||||
{
|
||||
for (i = ysta; i < yend; i++) {
|
||||
for (j = xsta; j < xend; j++) {
|
||||
lcd_wr_data(color);
|
||||
}
|
||||
}
|
||||
@@ -661,8 +628,8 @@ void lcd_draw_point(uint16_t x, uint16_t y, uint16_t color)
|
||||
***************************************************************/
|
||||
void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
uint16_t t;
|
||||
int xerr=0, yerr=0, delta_x, delta_y, distance;
|
||||
uint16_t t;
|
||||
int xerr = 0, yerr = 0, delta_x, delta_y, distance;
|
||||
int incx, incy, uRow, uCol;
|
||||
|
||||
/* 计算坐标增量 */
|
||||
@@ -671,61 +638,45 @@ void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t
|
||||
/* 画线起点坐标 */
|
||||
uRow = x1;
|
||||
uCol = y1;
|
||||
|
||||
if (delta_x > 0)
|
||||
{
|
||||
|
||||
if (delta_x > 0) {
|
||||
/* 设置单步方向 */
|
||||
incx = 1;
|
||||
}
|
||||
else if (delta_x == 0)
|
||||
{
|
||||
} else if (delta_x == 0) {
|
||||
/* 垂直线 */
|
||||
incx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
incx = -1;
|
||||
delta_x = -delta_x;
|
||||
}
|
||||
|
||||
if (delta_y > 0)
|
||||
{
|
||||
|
||||
if (delta_y > 0) {
|
||||
incy = 1;
|
||||
}
|
||||
else if (delta_y == 0)
|
||||
{
|
||||
} else if (delta_y == 0) {
|
||||
/* 水平线 */
|
||||
incy = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
incy = -1;
|
||||
delta_y = -delta_y;
|
||||
}
|
||||
|
||||
if (delta_x > delta_y)
|
||||
{
|
||||
|
||||
if (delta_x > delta_y) {
|
||||
/* 选取基本增量坐标轴 */
|
||||
distance = delta_x;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
distance = delta_y;
|
||||
}
|
||||
|
||||
for (t = 0; t < distance+1; t++)
|
||||
{
|
||||
|
||||
for (t = 0; t < distance + 1; t++) {
|
||||
/* 画点 */
|
||||
lcd_draw_point(uRow, uCol, color);
|
||||
xerr += delta_x;
|
||||
yerr += delta_y;
|
||||
if (xerr > distance)
|
||||
{
|
||||
if (xerr > distance) {
|
||||
xerr -= distance;
|
||||
uRow += incx;
|
||||
}
|
||||
if (yerr > distance)
|
||||
{
|
||||
if (yerr > distance) {
|
||||
yerr -= distance;
|
||||
uCol += incy;
|
||||
}
|
||||
@@ -744,7 +695,7 @@ void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t
|
||||
* @color:指定点的颜色
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,uint16_t color)
|
||||
void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
lcd_draw_line(x1, y1, x2, y1, color);
|
||||
lcd_draw_line(x1, y1, x1, y2, color);
|
||||
@@ -766,24 +717,22 @@ void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,uint1
|
||||
void lcd_draw_circle(uint16_t x0, uint16_t y0, uint8_t r, uint16_t color)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
|
||||
a = 0;
|
||||
b = r;
|
||||
|
||||
while (a <= b)
|
||||
{
|
||||
lcd_draw_point(x0-b, y0-a, color);
|
||||
lcd_draw_point(x0+b, y0-a, color);
|
||||
lcd_draw_point(x0-a, y0+b, color);
|
||||
lcd_draw_point(x0-a, y0-b, color);
|
||||
lcd_draw_point(x0+b, y0+a, color);
|
||||
lcd_draw_point(x0+a, y0-b, color);
|
||||
lcd_draw_point(x0+a, y0+b, color);
|
||||
lcd_draw_point(x0-b, y0+a, color);
|
||||
|
||||
while (a <= b) {
|
||||
lcd_draw_point(x0 - b, y0 - a, color);
|
||||
lcd_draw_point(x0 + b, y0 - a, color);
|
||||
lcd_draw_point(x0 - a, y0 + b, color);
|
||||
lcd_draw_point(x0 - a, y0 - b, color);
|
||||
lcd_draw_point(x0 + b, y0 + a, color);
|
||||
lcd_draw_point(x0 + a, y0 - b, color);
|
||||
lcd_draw_point(x0 + a, y0 + b, color);
|
||||
lcd_draw_point(x0 - b, y0 + a, color);
|
||||
a++;
|
||||
/* 判断要画的点是否过远 */
|
||||
if ((a*a+b*b) > (r*r))
|
||||
{
|
||||
if ((a * a + b * b) > (r * r)) {
|
||||
b--;
|
||||
}
|
||||
}
|
||||
@@ -813,58 +762,19 @@ void lcd_show_chinese(uint16_t x, uint16_t y, uint8_t *s, uint16_t fc, uint16_t
|
||||
/* utf8格式汉字转化为ascii格式 */
|
||||
chinese_utf8_to_ascii(s, strlen(s), buffer, &buffer_len);
|
||||
|
||||
for (uint32_t i = 0; i < buffer_len; i += 2, x += sizey)
|
||||
{
|
||||
if (sizey == 12)
|
||||
{
|
||||
for (uint32_t i = 0; i < buffer_len; i += CHINESE_TO_BYTES, x += sizey) {
|
||||
if (sizey == LCD_FONT_SIZE12) {
|
||||
lcd_show_chinese_12x12(x, y, &buffer[i], fc, bc, sizey, mode);
|
||||
}
|
||||
else if (sizey == 16)
|
||||
{
|
||||
} else if (sizey == LCD_FONT_SIZE16) {
|
||||
lcd_show_chinese_16x16(x, y, &buffer[i], fc, bc, sizey, mode);
|
||||
}
|
||||
else if (sizey == 24)
|
||||
{
|
||||
} else if (sizey == LCD_FONT_SIZE24) {
|
||||
lcd_show_chinese_24x24(x, y, &buffer[i], fc, bc, sizey, mode);
|
||||
}
|
||||
else if (sizey == 32)
|
||||
{
|
||||
} else if (sizey == LCD_FONT_SIZE32) {
|
||||
lcd_show_chinese_32x32(x, y, &buffer[i], fc, bc, sizey, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
while (*s != 0)
|
||||
{
|
||||
if (sizey == 12)
|
||||
{
|
||||
lcd_show_chinese_12x12(x, y, s, fc, bc, sizey, mode);
|
||||
}
|
||||
else if (sizey == 16)
|
||||
{
|
||||
lcd_show_chinese_16x16(x, y, s, fc, bc, sizey, mode);
|
||||
}
|
||||
else if (sizey == 24)
|
||||
{
|
||||
lcd_show_chinese_24x24(x, y, s, fc, bc, sizey, mode);
|
||||
}
|
||||
else if (sizey == 32)
|
||||
{
|
||||
lcd_show_chinese_32x32(x, y, s, fc, bc, sizey, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
s += 2;
|
||||
x += sizey;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -884,84 +794,66 @@ void lcd_show_chinese(uint16_t x, uint16_t y, uint8_t *s, uint16_t fc, uint16_t
|
||||
***************************************************************/
|
||||
void lcd_show_char(uint16_t x, uint16_t y, uint8_t num, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode)
|
||||
{
|
||||
uint8_t temp,sizex,t,m = 0;
|
||||
uint8_t temp, sizex, t, m = 0;
|
||||
uint16_t i;
|
||||
uint16_t TypefaceNum;//一个字符所占字节大小
|
||||
uint16_t x0 = x;
|
||||
|
||||
sizex = sizey/2;
|
||||
TypefaceNum = (sizex/8 + ((sizex%8)?1:0)) * sizey;
|
||||
|
||||
sizex = sizey / 2;
|
||||
TypefaceNum = (sizex / 8 + ((sizex % 8) ? 1 : 0)) * sizey;
|
||||
|
||||
/* 得到偏移后的值 */
|
||||
num = num-' ';
|
||||
num = num - ' ';
|
||||
/* 设置光标位置 */
|
||||
lcd_address_set(x, y, x+sizex-1, y+sizey-1);
|
||||
|
||||
for (i = 0; i < TypefaceNum; i++)
|
||||
{
|
||||
if (sizey == 12)
|
||||
{
|
||||
lcd_address_set(x, y, x + sizex - 1, y + sizey - 1);
|
||||
|
||||
for (i = 0; i < TypefaceNum; i++) {
|
||||
if (sizey == LCD_FONT_SIZE12) {
|
||||
/* 调用6x12字体 */
|
||||
temp = ascii_1206[num][i];
|
||||
}
|
||||
else if (sizey == 16)
|
||||
{
|
||||
} else if (sizey == LCD_FONT_SIZE16) {
|
||||
/* 调用8x16字体 */
|
||||
temp = ascii_1608[num][i];
|
||||
}
|
||||
else if (sizey == 24)
|
||||
{
|
||||
} else if (sizey == LCD_FONT_SIZE24) {
|
||||
/* 调用12x24字体 */
|
||||
temp = ascii_2412[num][i];
|
||||
}
|
||||
else if (sizey == 32)
|
||||
{
|
||||
} else if (sizey == LCD_FONT_SIZE32) {
|
||||
/* 调用16x32字体 */
|
||||
temp = ascii_3216[num][i];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
for (t = 0; t < 8; t++)
|
||||
{
|
||||
if (!mode)
|
||||
{/* 非叠加模式 */
|
||||
if (temp & (0x01 << t))
|
||||
{
|
||||
|
||||
for (t = 0; t < BYTE_TO_BITS; t++) {
|
||||
if (!mode) {
|
||||
/* 非叠加模式 */
|
||||
if (temp & (0x01 << t)) {
|
||||
lcd_wr_data(fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lcd_wr_data(bc);
|
||||
}
|
||||
|
||||
|
||||
m++;
|
||||
if (m%sizex == 0)
|
||||
{
|
||||
if (m % sizex == 0) {
|
||||
m = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{/* 叠加模式 */
|
||||
if (temp & (0x01 << t))
|
||||
{
|
||||
} else {
|
||||
/* 叠加模式 */
|
||||
if (temp & (0x01 << t)) {
|
||||
/* 画一个点 */
|
||||
lcd_draw_point(x, y, fc);
|
||||
}
|
||||
|
||||
|
||||
x++;
|
||||
if ((x - x0) == sizex)
|
||||
{
|
||||
if ((x - x0) == sizex) {
|
||||
x = x0;
|
||||
y++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -970,7 +862,7 @@ void lcd_show_char(uint16_t x, uint16_t y, uint8_t num, uint16_t fc, uint16_t bc
|
||||
* 说 明: 显示字符串
|
||||
* 参 数:
|
||||
* @x:指定字符的起始位置X坐标
|
||||
* @y:指定字串的起始位置X坐标
|
||||
* @y:指定字串的起始位置Y坐标
|
||||
* @s:指定字串
|
||||
* @fc: 字的颜色
|
||||
* @bc: 字的背景色
|
||||
@@ -979,13 +871,13 @@ void lcd_show_char(uint16_t x, uint16_t y, uint8_t num, uint16_t fc, uint16_t bc
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void lcd_show_string(uint16_t x, uint16_t y, const uint8_t *p, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode)
|
||||
{
|
||||
while (*p != '\0')
|
||||
{
|
||||
{
|
||||
#define X_OFFSET(sizey) ((sizey) / 2) /* 根据字体大小偏移X轴坐标 */
|
||||
while (*p != '\0') {
|
||||
lcd_show_char(x, y, *p, fc, bc, sizey, mode);
|
||||
x += (sizey / 2);
|
||||
x += X_OFFSET(sizey);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1003,28 +895,24 @@ void lcd_show_string(uint16_t x, uint16_t y, const uint8_t *p, uint16_t fc, uint
|
||||
***************************************************************/
|
||||
void lcd_show_int_num(uint16_t x, uint16_t y, uint16_t num, uint8_t len, uint16_t fc, uint16_t bc, uint8_t sizey)
|
||||
{
|
||||
uint8_t t,temp;
|
||||
uint8_t enshow=0;
|
||||
uint8_t base = 48; /* ASCII字符'0' */
|
||||
uint8_t t, temp;
|
||||
uint8_t enshow = 0;
|
||||
uint8_t sizex = sizey / 2;
|
||||
|
||||
for (t=0; t<len; t++)
|
||||
{
|
||||
temp = (num/mypow(10,len-t-1)) % 10;
|
||||
if (enshow==0 && t<(len-1))
|
||||
{
|
||||
if (temp == 0)
|
||||
{
|
||||
lcd_show_char(x+t*sizex, y, ' ', fc, bc, sizey, 0);
|
||||
|
||||
for (t = 0; t < len; t++) {
|
||||
temp = (num / mypow(10, len - t - 1)) % 10;
|
||||
if (enshow == 0 && t < (len - 1)) {
|
||||
if (temp == 0) {
|
||||
lcd_show_char(x + t * sizex, y, ' ', fc, bc, sizey, 0);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
enshow = 1;
|
||||
}
|
||||
}
|
||||
lcd_show_char(x+t*sizex, y, temp+48, fc, bc, sizey, 0);
|
||||
lcd_show_char(x + t * sizex, y, temp + base, fc, bc, sizey, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
@@ -1039,23 +927,25 @@ void lcd_show_int_num(uint16_t x, uint16_t y, uint16_t num, uint8_t len, uint16_
|
||||
* @sizey: 字号,可选:16、24、32
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void lcd_show_float_num1(uint16_t x, uint16_t y,float num,uint8_t len,uint16_t fc,uint16_t bc,uint8_t sizey)
|
||||
void lcd_show_float_num1(uint16_t x, uint16_t y, float num, uint8_t len, uint16_t fc, uint16_t bc, uint8_t sizey)
|
||||
{
|
||||
uint8_t t,temp, sizex;
|
||||
#define X_OFFSET(sizey) ((sizey) / 2) /* 根据字体大小偏移X坐标移动点数 */
|
||||
#define FLOAT_TO_INT(num) ((num) * 100) /* 将float数值转化为int数值 */
|
||||
#define DECIMAL_TOW 2 /* 保留小数点后2个数值 */
|
||||
#define CHAR_0 ((uint8_t)('0'))
|
||||
uint8_t t, temp, sizex;
|
||||
uint16_t num1;
|
||||
|
||||
sizex = sizey / 2;
|
||||
num1 = num * 100;
|
||||
for (t=0; t<len; t++)
|
||||
{
|
||||
temp = (num1/mypow(10,len-t-1)) % 10;
|
||||
if (t == (len-2))
|
||||
{
|
||||
lcd_show_char(x+(len-2)*sizex, y, '.', fc, bc, sizey, 0);
|
||||
|
||||
sizex = X_OFFSET(sizey);
|
||||
num1 = FLOAT_TO_INT(num);
|
||||
for (t = 0; t < len; t++) {
|
||||
temp = (num1 / mypow(10, len - t - 1)) % 10;
|
||||
if (t == (len - DECIMAL_TOW)) {
|
||||
lcd_show_char(x + (len - DECIMAL_TOW)*sizex, y, '.', fc, bc, sizey, 0);
|
||||
t++;
|
||||
len += 1;
|
||||
}
|
||||
lcd_show_char(x+t*sizex, y, temp+48, fc, bc, sizey, 0);
|
||||
lcd_show_char(x + t * sizex, y, temp + CHAR_0, fc, bc, sizey, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1072,19 +962,15 @@ void lcd_show_float_num1(uint16_t x, uint16_t y,float num,uint8_t len,uint16_t f
|
||||
***************************************************************/
|
||||
void lcd_show_picture(uint16_t x, uint16_t y, uint16_t length, uint16_t width, const uint8_t *pic)
|
||||
{
|
||||
uint16_t i,j;
|
||||
uint16_t i, j;
|
||||
uint32_t k = 0;
|
||||
|
||||
lcd_address_set(x, y, x+length-1, y+width-1);
|
||||
for (i=0; i<length; i++)
|
||||
{
|
||||
for (j=0; j<width; j++)
|
||||
{
|
||||
lcd_wr_data8(pic[k*2]);
|
||||
lcd_wr_data8(pic[k*2+1]);
|
||||
|
||||
lcd_address_set(x, y, x + length - 1, y + width - 1);
|
||||
for (i = 0; i < length; i++) {
|
||||
for (j = 0; j < width; j++) {
|
||||
lcd_wr_data8(pic[k * 2]);
|
||||
lcd_wr_data8(pic[k * 2 + 1]);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+1628
-1628
File diff suppressed because it is too large
Load Diff
Executable → Regular
+9
-6
@@ -19,6 +19,10 @@
|
||||
#define OLED_COLUMN_MAX 128
|
||||
#define OLED_ROW_MAX 64
|
||||
|
||||
/* 定义OLED字体大小 */
|
||||
#define OLED_CHR_SIZE_12 12
|
||||
#define OLED_CHR_SIZE_16 16
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: oled_init
|
||||
* 说 明: oled初始化
|
||||
@@ -67,7 +71,7 @@ void oled_clear(void);
|
||||
/***************************************************************
|
||||
* 函数名称: oled_show_char
|
||||
* 说 明: oled显示字符
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x:字符的X轴坐标
|
||||
* @y:字符的Y轴坐标
|
||||
* @chr:字符
|
||||
@@ -80,7 +84,7 @@ void oled_show_char(uint8_t x, uint8_t y, uint8_t chr, uint8_t chr_size);
|
||||
/***************************************************************
|
||||
* 函数名称: oled_show_num
|
||||
* 说 明: oled显示数字
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x:数字的X轴坐标
|
||||
* @y:数字的Y轴坐标
|
||||
* @num:数字
|
||||
@@ -94,7 +98,7 @@ void oled_show_num(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size
|
||||
/***************************************************************
|
||||
* 函数名称: oled_show_string
|
||||
* 说 明: oled显示字符串
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x:字符串的X轴坐标
|
||||
* @y:字符串的Y轴坐标
|
||||
* @p:字符串
|
||||
@@ -107,7 +111,7 @@ void oled_show_string(uint8_t x, uint8_t y, uint8_t *p, uint8_t chr_size);
|
||||
/***************************************************************
|
||||
* 函数名称: oled_draw_bmp
|
||||
* 说 明: oled显示图片
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x0:图片的起始点X轴坐标,取值为0~127
|
||||
* @y0:图片的起始点Y轴坐标,取值为0~63
|
||||
* @x1:图片的结束点X轴坐标,取值为0~127
|
||||
@@ -118,5 +122,4 @@ void oled_show_string(uint8_t x, uint8_t y, uint8_t *p, uint8_t chr_size);
|
||||
void oled_draw_bmp(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char bmp[]);
|
||||
|
||||
|
||||
#endif
|
||||
/** @} */
|
||||
#endif /* _OLED_H_ */
|
||||
Executable → Regular
+198
-241
@@ -1,249 +1,206 @@
|
||||
#ifndef _OLED_FONT_H_
|
||||
#define _OLED_FONT_H_
|
||||
//常用ASCII表
|
||||
//偏移量32
|
||||
//ASCII字符集
|
||||
//偏移量32
|
||||
//大小:12*6
|
||||
|
||||
/* */
|
||||
#define F6X8_COLUMNS 6
|
||||
|
||||
// 常用ASCII表
|
||||
// 偏移量32
|
||||
// ASCII字符集
|
||||
// 偏移量32
|
||||
// 大小:12*6
|
||||
/************************************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
|
||||
const unsigned char F6x8[][F6X8_COLUMNS] = {
|
||||
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[]=
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
|
||||
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
|
||||
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
|
||||
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
|
||||
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
|
||||
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
|
||||
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
|
||||
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
|
||||
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
|
||||
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
|
||||
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
|
||||
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
|
||||
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
|
||||
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
|
||||
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
|
||||
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
|
||||
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
|
||||
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
|
||||
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
|
||||
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
|
||||
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
|
||||
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
|
||||
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
|
||||
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
|
||||
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
|
||||
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
|
||||
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
|
||||
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
|
||||
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
|
||||
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
|
||||
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
|
||||
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
|
||||
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
|
||||
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
|
||||
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
|
||||
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
|
||||
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
|
||||
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
|
||||
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
|
||||
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
|
||||
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
|
||||
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
|
||||
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
|
||||
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
|
||||
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
|
||||
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
|
||||
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
|
||||
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
|
||||
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
|
||||
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
|
||||
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
|
||||
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
|
||||
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
|
||||
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
|
||||
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
|
||||
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
|
||||
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
|
||||
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
|
||||
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
|
||||
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
|
||||
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
|
||||
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
|
||||
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
|
||||
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
|
||||
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
|
||||
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
|
||||
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
|
||||
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
|
||||
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
|
||||
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
|
||||
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
|
||||
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
|
||||
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
|
||||
};
|
||||
char Hzk[][32]={
|
||||
|
||||
{0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00},/*"中",0*/
|
||||
|
||||
{0x40,0x40,0x40,0x5F,0x55,0x55,0x55,0x75,0x55,0x55,0x55,0x5F,0x40,0x40,0x40,0x00},
|
||||
{0x00,0x40,0x20,0x0F,0x09,0x49,0x89,0x79,0x09,0x09,0x09,0x0F,0x20,0x40,0x00,0x00},/*"景",1*/
|
||||
|
||||
{0x00,0xFE,0x02,0x42,0x4A,0xCA,0x4A,0x4A,0xCA,0x4A,0x4A,0x42,0x02,0xFE,0x00,0x00},
|
||||
{0x00,0xFF,0x40,0x50,0x4C,0x43,0x40,0x40,0x4F,0x50,0x50,0x5C,0x40,0xFF,0x00,0x00},/*"园",2*/
|
||||
|
||||
{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00},/*"电",3*/
|
||||
|
||||
{0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"子",4*/
|
||||
|
||||
{0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,0x00},
|
||||
{0x08,0x06,0x01,0xFF,0x00,0x01,0x04,0x04,0x04,0x04,0x04,0xFF,0x02,0x02,0x02,0x00},/*"科",5*/
|
||||
|
||||
{0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00},
|
||||
{0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00},/*"?",0*/
|
||||
|
||||
{0x40,0x40,0x48,0x48,0x48,0xC8,0x78,0x4F,0x48,0x48,0x48,0x48,0x48,0x40,0x40,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x03,0x12,0x12,0x22,0x22,0x52,0x8A,0x06,0x00,0x00,0x00,0x00},/*"专",0*/
|
||||
|
||||
{0x00,0x10,0x60,0x80,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0xC0,0x30,0x00,0x00},
|
||||
{0x40,0x40,0x40,0x43,0x40,0x7F,0x40,0x40,0x40,0x7F,0x42,0x41,0x40,0x40,0x40,0x00},/*"业",1*/
|
||||
|
||||
{0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00},
|
||||
{0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00},/*"技",2*/
|
||||
|
||||
{0x00,0x10,0x10,0x10,0x10,0xD0,0x30,0xFF,0x30,0xD0,0x12,0x1C,0x10,0x10,0x00,0x00},
|
||||
{0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x00},/*"术",3*/
|
||||
|
||||
{0x00,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0xFE,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00},
|
||||
{0x80,0x60,0x1F,0x02,0x42,0x82,0x7F,0x00,0xFF,0x40,0x2F,0x10,0x2C,0x43,0x80,0x00},/*"服",4*/
|
||||
|
||||
{0x00,0x00,0x90,0x88,0x4C,0x57,0xA4,0x24,0x54,0x54,0x8C,0x84,0x00,0x00,0x00,0x00},
|
||||
{0x01,0x01,0x80,0x42,0x22,0x1A,0x07,0x02,0x42,0x82,0x42,0x3E,0x01,0x01,0x01,0x00},/*"务",5*/
|
||||
|
||||
{0x00,0x04,0xE4,0x24,0x2C,0xB4,0x25,0x26,0x24,0xB4,0x2C,0x24,0xE4,0x04,0x00,0x00},
|
||||
{0x00,0x00,0xFF,0x02,0x01,0x1E,0x12,0x12,0x12,0x1E,0x41,0x82,0x7F,0x00,0x00,0x00},/*"商",6*/
|
||||
|
||||
const unsigned char F8X16[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0
|
||||
0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x30, 0x00, 0x00, 0x00, // ! 1
|
||||
0x00, 0x10, 0x0C, 0x06, 0x10, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " 2
|
||||
0x40, 0xC0, 0x78, 0x40, 0xC0, 0x78, 0x40, 0x00, 0x04, 0x3F, 0x04, 0x04, 0x3F, 0x04, 0x04, 0x00, // # 3
|
||||
0x00, 0x70, 0x88, 0xFC, 0x08, 0x30, 0x00, 0x00, 0x00, 0x18, 0x20, 0xFF, 0x21, 0x1E, 0x00, 0x00, // $ 4
|
||||
0xF0, 0x08, 0xF0, 0x00, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x21, 0x1C, 0x03, 0x1E, 0x21, 0x1E, 0x00, // % 5
|
||||
0x00, 0xF0, 0x08, 0x88, 0x70, 0x00, 0x00, 0x00, 0x1E, 0x21, 0x23, 0x24, 0x19, 0x27, 0x21, 0x10, // & 6
|
||||
0x10, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ' 7
|
||||
0x00, 0x00, 0x00, 0xE0, 0x18, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x20, 0x40, 0x00, // ( 8
|
||||
0x00, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x18, 0x07, 0x00, 0x00, 0x00, // ) 9
|
||||
0x40, 0x40, 0x80, 0xF0, 0x80, 0x40, 0x40, 0x00, 0x02, 0x02, 0x01, 0x0F, 0x01, 0x02, 0x02, 0x00, // * 10
|
||||
0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x1F, 0x01, 0x01, 0x01, 0x00, // + 11
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xB0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, // , 12
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // - 13
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, // . 14
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x04, 0x00, 0x60, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, // / 15
|
||||
0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x10, 0x0F, 0x00, // 0 16
|
||||
0x00, 0x10, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // 1 17
|
||||
0x00, 0x70, 0x08, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x30, 0x28, 0x24, 0x22, 0x21, 0x30, 0x00, // 2 18
|
||||
0x00, 0x30, 0x08, 0x88, 0x88, 0x48, 0x30, 0x00, 0x00, 0x18, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // 3 19
|
||||
0x00, 0x00, 0xC0, 0x20, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x07, 0x04, 0x24, 0x24, 0x3F, 0x24, 0x00, // 4 20
|
||||
0x00, 0xF8, 0x08, 0x88, 0x88, 0x08, 0x08, 0x00, 0x00, 0x19, 0x21, 0x20, 0x20, 0x11, 0x0E, 0x00, // 5 21
|
||||
0x00, 0xE0, 0x10, 0x88, 0x88, 0x18, 0x00, 0x00, 0x00, 0x0F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // 6 22
|
||||
0x00, 0x38, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, // 7 23
|
||||
0x00, 0x70, 0x88, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x1C, 0x22, 0x21, 0x21, 0x22, 0x1C, 0x00, // 8 24
|
||||
0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x00, 0x31, 0x22, 0x22, 0x11, 0x0F, 0x00, // 9 25
|
||||
0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, // : 26
|
||||
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00, // ; 27
|
||||
0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, // < 28
|
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, // = 29
|
||||
0x00, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, // > 30
|
||||
0x00, 0x70, 0x48, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x36, 0x01, 0x00, 0x00, // ? 31
|
||||
0xC0, 0x30, 0xC8, 0x28, 0xE8, 0x10, 0xE0, 0x00, 0x07, 0x18, 0x27, 0x24, 0x23, 0x14, 0x0B, 0x00, // @ 32
|
||||
0x00, 0x00, 0xC0, 0x38, 0xE0, 0x00, 0x00, 0x00, 0x20, 0x3C, 0x23, 0x02, 0x02, 0x27, 0x38, 0x20, // A 33
|
||||
0x08, 0xF8, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // B 34
|
||||
0xC0, 0x30, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x07, 0x18, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, // C 35
|
||||
0x08, 0xF8, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // D 36
|
||||
0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x23, 0x20, 0x18, 0x00, // E 37
|
||||
0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, // F 38
|
||||
0xC0, 0x30, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x07, 0x18, 0x20, 0x20, 0x22, 0x1E, 0x02, 0x00, // G 39
|
||||
0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x21, 0x3F, 0x20, // H 40
|
||||
0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // I 41
|
||||
0x00, 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, 0x00, // J 42
|
||||
0x08, 0xF8, 0x88, 0xC0, 0x28, 0x18, 0x08, 0x00, 0x20, 0x3F, 0x20, 0x01, 0x26, 0x38, 0x20, 0x00, // K 43
|
||||
0x08, 0xF8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00, // L 44
|
||||
0x08, 0xF8, 0xF8, 0x00, 0xF8, 0xF8, 0x08, 0x00, 0x20, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x20, 0x00, // M 45
|
||||
0x08, 0xF8, 0x30, 0xC0, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x20, 0x00, 0x07, 0x18, 0x3F, 0x00, // N 46
|
||||
0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // O 47
|
||||
0x08, 0xF8, 0x08, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x01, 0x00, 0x00, // P 48
|
||||
0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x18, 0x24, 0x24, 0x38, 0x50, 0x4F, 0x00, // Q 49
|
||||
0x08, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x0C, 0x30, 0x20, // R 50
|
||||
0x00, 0x70, 0x88, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x38, 0x20, 0x21, 0x21, 0x22, 0x1C, 0x00, // S 51
|
||||
0x18, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x18, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // T 52
|
||||
0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // U 53
|
||||
0x08, 0x78, 0x88, 0x00, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x07, 0x38, 0x0E, 0x01, 0x00, 0x00, // V 54
|
||||
0xF8, 0x08, 0x00, 0xF8, 0x00, 0x08, 0xF8, 0x00, 0x03, 0x3C, 0x07, 0x00, 0x07, 0x3C, 0x03, 0x00, // W 55
|
||||
0x08, 0x18, 0x68, 0x80, 0x80, 0x68, 0x18, 0x08, 0x20, 0x30, 0x2C, 0x03, 0x03, 0x2C, 0x30, 0x20, // X 56
|
||||
0x08, 0x38, 0xC8, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // Y 57
|
||||
0x10, 0x08, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x20, 0x38, 0x26, 0x21, 0x20, 0x20, 0x18, 0x00, // Z 58
|
||||
0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x00, // [ 59
|
||||
0x00, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x38, 0xC0, 0x00, // \ 60
|
||||
0x00, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7F, 0x00, 0x00, 0x00, // ] 61
|
||||
0x00, 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ^ 62
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // _ 63
|
||||
0x00, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ` 64
|
||||
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x19, 0x24, 0x22, 0x22, 0x22, 0x3F, 0x20, // a 65
|
||||
0x08, 0xF8, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // b 66
|
||||
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x20, 0x11, 0x00, // c 67
|
||||
0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0xF8, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x10, 0x3F, 0x20, // d 68
|
||||
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x22, 0x22, 0x22, 0x22, 0x13, 0x00, // e 69
|
||||
0x00, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x18, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // f 70
|
||||
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x6B, 0x94, 0x94, 0x94, 0x93, 0x60, 0x00, // g 71
|
||||
0x08, 0xF8, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // h 72
|
||||
0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // i 73
|
||||
0x00, 0x00, 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, // j 74
|
||||
0x08, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x24, 0x02, 0x2D, 0x30, 0x20, 0x00, // k 75
|
||||
0x00, 0x08, 0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // l 76
|
||||
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x3F, 0x20, 0x00, 0x3F, // m 77
|
||||
0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // n 78
|
||||
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // o 79
|
||||
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xA1, 0x20, 0x20, 0x11, 0x0E, 0x00, // p 80
|
||||
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0xA0, 0xFF, 0x80, // q 81
|
||||
0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x20, 0x3F, 0x21, 0x20, 0x00, 0x01, 0x00, // r 82
|
||||
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x33, 0x24, 0x24, 0x24, 0x24, 0x19, 0x00, // s 83
|
||||
0x00, 0x80, 0x80, 0xE0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x00, 0x00, // t 84
|
||||
0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x10, 0x3F, 0x20, // u 85
|
||||
0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0E, 0x30, 0x08, 0x06, 0x01, 0x00, // v 86
|
||||
0x80, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80, 0x80, 0x0F, 0x30, 0x0C, 0x03, 0x0C, 0x30, 0x0F, 0x00, // w 87
|
||||
0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x31, 0x2E, 0x0E, 0x31, 0x20, 0x00, // x 88
|
||||
0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x81, 0x8E, 0x70, 0x18, 0x06, 0x01, 0x00, // y 89
|
||||
0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x21, 0x30, 0x2C, 0x22, 0x21, 0x30, 0x00, // z 90
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0x7C, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x40, // { 91
|
||||
0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, // | 92
|
||||
0x00, 0x02, 0x02, 0x7C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x00, 0x00, // } 93
|
||||
0x00, 0x06, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ~ 94
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Executable → Regular
+46
-17
@@ -16,26 +16,56 @@
|
||||
#include "ohos_init.h"
|
||||
#include "lz_hardware.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 1000
|
||||
|
||||
/* 字符串最大长度 */
|
||||
#define STRING_MAXSIZE 32
|
||||
|
||||
/* OLED显示字符串1的位置、长度和宽度 */
|
||||
#define OLED_STRING1_X 6
|
||||
#define OLED_STRING1_Y 0
|
||||
#define OLED_STRING1_TEXT "0.96' OLED TEST"
|
||||
#define OLED_STRING1_SIZE 16
|
||||
/* OLED显示字符串2的位置、长度和宽度 */
|
||||
#define OLED_STRING2_X 0
|
||||
#define OLED_STRING2_Y 3
|
||||
#define OLED_STRING2_TEXT "ASCII:"
|
||||
#define OLED_STRING2_SIZE 16
|
||||
/* OLED显示字符串3的位置、长度和宽度 */
|
||||
#define OLED_STRING3_X 64
|
||||
#define OLED_STRING3_Y 3
|
||||
#define OLED_STRING3_TEXT "CODE:"
|
||||
#define OLED_STRING3_SIZE 16
|
||||
/* OLED显示字符串4的位置、长度和宽度 */
|
||||
#define OLED_STRING4_X 40
|
||||
#define OLED_STRING4_Y 6
|
||||
#define OLED_STRING4_SIZE 16
|
||||
|
||||
void oled_process(void *arg)
|
||||
{
|
||||
unsigned char buffer[32];
|
||||
unsigned char buffer[STRING_MAXSIZE];
|
||||
int i = 0;
|
||||
|
||||
|
||||
oled_init();
|
||||
oled_clear();
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
printf("========= Oled Process =============\n");
|
||||
oled_show_string(6, 0, "0.96' OLED TEST", 16);
|
||||
oled_show_string(0, 3, "ASCII:", 16);
|
||||
oled_show_string(64, 3, "CODE:", 16);
|
||||
|
||||
oled_show_string(OLED_STRING1_X, OLED_STRING1_Y, OLED_STRING1_TEXT, OLED_STRING1_SIZE);
|
||||
oled_show_string(OLED_STRING2_X, OLED_STRING2_Y, OLED_STRING2_TEXT, OLED_STRING2_SIZE);
|
||||
oled_show_string(OLED_STRING3_X, OLED_STRING3_Y, OLED_STRING3_TEXT, OLED_STRING3_SIZE);
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "%d Sec!", i++);
|
||||
oled_show_string(40, 6, buffer, 16);
|
||||
|
||||
oled_show_string(OLED_STRING4_X, OLED_STRING4_Y, buffer, OLED_STRING4_SIZE);
|
||||
|
||||
printf("\n\n");
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +83,12 @@ void oled_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)oled_process;
|
||||
task.uwStackSize = 2048;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "oled process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+129
-146
@@ -44,10 +44,23 @@
|
||||
#define OLED_RST_Set()
|
||||
#else
|
||||
#define OLED_I2C_BUS 1
|
||||
static I2cBusIo m_i2cBus =
|
||||
{
|
||||
.scl = {.gpio = GPIO0_PC2, .func = MUX_FUNC5, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
.sda = {.gpio = GPIO0_PC1, .func = MUX_FUNC5, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
static I2cBusIo m_i2cBus = {
|
||||
.scl = {
|
||||
.gpio = GPIO0_PC2,
|
||||
.func = MUX_FUNC5,
|
||||
.type = PULL_NONE,
|
||||
.drv = DRIVE_KEEP,
|
||||
.dir = LZGPIO_DIR_KEEP,
|
||||
.val = LZGPIO_LEVEL_KEEP
|
||||
},
|
||||
.sda = {
|
||||
.gpio = GPIO0_PC1,
|
||||
.func = MUX_FUNC5,
|
||||
.type = PULL_NONE,
|
||||
.drv = DRIVE_KEEP,
|
||||
.dir = LZGPIO_DIR_KEEP,
|
||||
.val = LZGPIO_LEVEL_KEEP
|
||||
},
|
||||
.id = FUNC_ID_I2C1,
|
||||
.mode = FUNC_MODE_M1,
|
||||
};
|
||||
@@ -58,26 +71,25 @@ static unsigned int m_i2c_freq = 400000;
|
||||
#define OLED_CMD 0 // OLED的命令操作标记
|
||||
#define OLED_DATA 1 // OLED的数据操作标记
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
/* 字节的bits数目 */
|
||||
#define BYTE_TO_BITS 8
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: oled_pow
|
||||
* 说 明: 计算m^n
|
||||
* 参 数:
|
||||
* @m:
|
||||
* @n:
|
||||
* @m:计算m^n的m
|
||||
* @n:计算m^n中的n
|
||||
* 返 回 值: 计算结果值
|
||||
***************************************************************/
|
||||
static uint32_t oled_pow(uint8_t m, uint8_t n)
|
||||
{
|
||||
uint32_t result = 1;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
|
||||
while (n--) {
|
||||
result *= m;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -128,7 +140,7 @@ static inline void iic_wait_ack()
|
||||
/***************************************************************
|
||||
* 函数名称: write_iic_byte
|
||||
* 说 明: i2c写单个字节
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @IIC_Byte:数值
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -138,17 +150,13 @@ static inline 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 < BYTE_TO_BITS; i++) {
|
||||
m = da;
|
||||
//OLED_SCLK_Clr();
|
||||
m = m & 0x80;
|
||||
if (m == 0x80)
|
||||
{
|
||||
if (m == 0x80) {
|
||||
OLED_SDIN_Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
OLED_SDIN_Clr();
|
||||
}
|
||||
da = da << 1;
|
||||
@@ -161,7 +169,7 @@ static inline void write_iic_byte(unsigned char iic_byte)
|
||||
/***************************************************************
|
||||
* 函数名称: write_iic_command
|
||||
* 说 明: 通过i2c通信协议,往芯片写入一个命令
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @IIC_Command:命令数值
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -183,7 +191,7 @@ static inline void write_iic_command(unsigned char iic_command)
|
||||
/***************************************************************
|
||||
* 函数名称: write_iic_data
|
||||
* 说 明: 通过i2c通信协议,往芯片写入一个数据
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @IIC_Data:数据数值
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -204,7 +212,7 @@ static inline void write_iic_data(unsigned char iic_data)
|
||||
/***************************************************************
|
||||
* 函数名称: write_iic_command
|
||||
* 说 明: 通过i2c通信协议,往芯片写入一个命令
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @IIC_Command:命令数值
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -217,8 +225,7 @@ static inline void write_iic_command(unsigned char iic_command)
|
||||
buffer[0] = 0x00;
|
||||
buffer[1] = iic_command;
|
||||
ret = LzI2cWrite(OLED_I2C_BUS, OLED_I2C_ADDRESS, buffer, 2);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("%s, %s, %d: LzI2cWrite failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
}
|
||||
}
|
||||
@@ -227,7 +234,7 @@ static inline void write_iic_command(unsigned char iic_command)
|
||||
/***************************************************************
|
||||
* 函数名称: write_iic_data
|
||||
* 说 明: 通过i2c通信协议,往芯片写入一个数据
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @iic_data:数据数值
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -240,8 +247,7 @@ static inline void write_iic_data(unsigned char iic_data)
|
||||
buffer[0] = 0x40;
|
||||
buffer[1] = iic_data;
|
||||
ret = LzI2cWrite(OLED_I2C_BUS, OLED_I2C_ADDRESS, buffer, 2);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("%s, %s, %d: LzI2cWrite failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
}
|
||||
}
|
||||
@@ -251,23 +257,18 @@ static inline void write_iic_data(unsigned char iic_data)
|
||||
/***************************************************************
|
||||
* 函数名称: oled_wr_byte
|
||||
* 说 明: 往芯片写数据
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @data:数据数值
|
||||
* @cmd:该数据是命令,还是数据
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
static inline void oled_wr_byte(unsigned dat, unsigned cmd)
|
||||
{
|
||||
if (cmd == OLED_DATA)
|
||||
{
|
||||
if (cmd == OLED_DATA) {
|
||||
write_iic_data(dat);
|
||||
}
|
||||
else if (cmd == OLED_CMD)
|
||||
{
|
||||
} else if (cmd == OLED_CMD) {
|
||||
write_iic_command(dat);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("%s, %s, %d: cmd(%d) out of the range!\n", __FILE__, __func__, __LINE__, cmd);
|
||||
}
|
||||
}
|
||||
@@ -276,7 +277,7 @@ static inline void oled_wr_byte(unsigned dat, unsigned cmd)
|
||||
/***************************************************************
|
||||
* 函数名称: oled_set_pos
|
||||
* 说 明: 坐标设置
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x:X轴坐标
|
||||
* @y:Y轴坐标
|
||||
* 返 回 值: 无
|
||||
@@ -306,55 +307,53 @@ unsigned int oled_init()
|
||||
LzGpioInit(GPIO_I2C_SCL);
|
||||
LzGpioSetDir(GPIO_I2C_SCL, LZGPIO_DIR_OUT);
|
||||
#else
|
||||
if (I2cIoInit(m_i2cBus) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (I2cIoInit(m_i2cBus) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %d: I2cIoInit failed!\n", __FILE__, __LINE__);
|
||||
return __FILE__;
|
||||
}
|
||||
if (LzI2cInit(OLED_I2C_BUS, m_i2c_freq) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (LzI2cInit(OLED_I2C_BUS, m_i2c_freq) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %d: I2cIoInit failed!\n", __FILE__, __LINE__);
|
||||
return __FILE__;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
LOS_Msleep(200);
|
||||
|
||||
oled_wr_byte(0xAE, OLED_CMD); //--display off
|
||||
oled_wr_byte(0x00, OLED_CMD); //---set low column address
|
||||
oled_wr_byte(0x10, OLED_CMD); //---set high column address
|
||||
oled_wr_byte(0x40, OLED_CMD); //--set start line address
|
||||
oled_wr_byte(0xB0, OLED_CMD); //--set page address
|
||||
|
||||
oled_wr_byte(0xAE, OLED_CMD); // --display off
|
||||
oled_wr_byte(0x00, OLED_CMD); // ---set low column address
|
||||
oled_wr_byte(0x10, OLED_CMD); // ---set high column address
|
||||
oled_wr_byte(0x40, OLED_CMD); // --set start line address
|
||||
oled_wr_byte(0xB0, OLED_CMD); // --set page address
|
||||
oled_wr_byte(0x81, OLED_CMD); // contract control
|
||||
oled_wr_byte(0xFF, OLED_CMD); //--128
|
||||
oled_wr_byte(0xA1, OLED_CMD); //set segment remap
|
||||
oled_wr_byte(0xA6, OLED_CMD); //--normal / reverse
|
||||
oled_wr_byte(0xA8, OLED_CMD); //--set multiplex ratio(1 to 64)
|
||||
oled_wr_byte(0x3F, OLED_CMD); //--1/32 duty
|
||||
oled_wr_byte(0xC8, OLED_CMD); //Com scan direction
|
||||
oled_wr_byte(0xD3, OLED_CMD); //-set display offset
|
||||
oled_wr_byte(0x00, OLED_CMD); //
|
||||
|
||||
oled_wr_byte(0xD5, OLED_CMD); //set osc division
|
||||
oled_wr_byte(0x80, OLED_CMD); //
|
||||
|
||||
oled_wr_byte(0xD8, OLED_CMD); //set area color mode off
|
||||
oled_wr_byte(0x05, OLED_CMD); //
|
||||
|
||||
oled_wr_byte(0xD9, OLED_CMD); //Set Pre-Charge Period
|
||||
oled_wr_byte(0xF1, OLED_CMD); //
|
||||
|
||||
oled_wr_byte(0xDA, OLED_CMD); //set com pin configuartion
|
||||
oled_wr_byte(0x12, OLED_CMD); //
|
||||
|
||||
oled_wr_byte(0xDB, OLED_CMD); //set Vcomh
|
||||
oled_wr_byte(0x30, OLED_CMD); //
|
||||
|
||||
oled_wr_byte(0x8D, OLED_CMD); //set charge pump enable
|
||||
oled_wr_byte(0x14, OLED_CMD); //
|
||||
|
||||
oled_wr_byte(0xAF, OLED_CMD); //--turn on oled panel
|
||||
|
||||
oled_wr_byte(0xFF, OLED_CMD); // --128
|
||||
oled_wr_byte(0xA1, OLED_CMD); // set segment remap
|
||||
oled_wr_byte(0xA6, OLED_CMD); // --normal / reverse
|
||||
oled_wr_byte(0xA8, OLED_CMD); // --set multiplex ratio(1 to 64)
|
||||
oled_wr_byte(0x3F, OLED_CMD); // --1/32 duty
|
||||
oled_wr_byte(0xC8, OLED_CMD); // Com scan direction
|
||||
oled_wr_byte(0xD3, OLED_CMD); // -set display offset
|
||||
oled_wr_byte(0x00, OLED_CMD);
|
||||
|
||||
oled_wr_byte(0xD5, OLED_CMD); // set osc division
|
||||
oled_wr_byte(0x80, OLED_CMD);
|
||||
|
||||
oled_wr_byte(0xD8, OLED_CMD); // set area color mode off
|
||||
oled_wr_byte(0x05, OLED_CMD);
|
||||
|
||||
oled_wr_byte(0xD9, OLED_CMD); // Set Pre-Charge Period
|
||||
oled_wr_byte(0xF1, OLED_CMD);
|
||||
|
||||
oled_wr_byte(0xDA, OLED_CMD); // set com pin configuartion
|
||||
oled_wr_byte(0x12, OLED_CMD);
|
||||
|
||||
oled_wr_byte(0xDB, OLED_CMD); // set Vcomh
|
||||
oled_wr_byte(0x30, OLED_CMD);
|
||||
|
||||
oled_wr_byte(0x8D, OLED_CMD); // set charge pump enable
|
||||
oled_wr_byte(0x14, OLED_CMD);
|
||||
|
||||
oled_wr_byte(0xAF, OLED_CMD); // --turn on oled panel
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -386,14 +385,12 @@ unsigned int oled_deinit()
|
||||
void oled_clear()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
|
||||
for (i = 0; i < BYTE_TO_BITS; 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 < OLED_COLUMN_MAX; n++) {
|
||||
oled_wr_byte(0, OLED_DATA);
|
||||
}
|
||||
}
|
||||
@@ -408,9 +405,9 @@ void oled_clear()
|
||||
***************************************************************/
|
||||
void oled_display_on(void)
|
||||
{
|
||||
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_wr_byte(0X8D, OLED_CMD); // SET DCDC命令
|
||||
oled_wr_byte(0X14, OLED_CMD); // DCDC ON
|
||||
oled_wr_byte(0XAF, OLED_CMD); // DISPLAY ON
|
||||
}
|
||||
|
||||
|
||||
@@ -422,16 +419,16 @@ void oled_display_on(void)
|
||||
***************************************************************/
|
||||
void oled_display_off(void)
|
||||
{
|
||||
oled_wr_byte(0X8D, OLED_CMD); //SET DCDC命令
|
||||
oled_wr_byte(0X10, OLED_CMD); //DCDC OFF
|
||||
oled_wr_byte(0XAE, OLED_CMD); //DISPLAY OFF
|
||||
oled_wr_byte(0X8D, OLED_CMD); // SET DCDC命令
|
||||
oled_wr_byte(0X10, OLED_CMD); // DCDC OFF
|
||||
oled_wr_byte(0XAE, OLED_CMD); // DISPLAY OFF
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: oled_show_char
|
||||
* 说 明: oled显示字符
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x:字符的X轴坐标
|
||||
* @y:字符的Y轴坐标
|
||||
* @chr:字符
|
||||
@@ -440,37 +437,33 @@ void oled_display_off(void)
|
||||
***************************************************************/
|
||||
void oled_show_char(uint8_t x, uint8_t y, uint8_t chr, uint8_t chr_size)
|
||||
{
|
||||
#define F8X16_LINE_DATA 8
|
||||
#define F6X8_LINE_DATA 6
|
||||
#define BYTE_BITS 8
|
||||
#define CHAR_LEN 16
|
||||
unsigned char c = 0, i = 0;
|
||||
|
||||
c = chr - ' '; //得到偏移后的值
|
||||
|
||||
if (x > (OLED_COLUMN_MAX - 1))
|
||||
{
|
||||
|
||||
c = chr - ' '; // 得到偏移后的值
|
||||
|
||||
if (x > (OLED_COLUMN_MAX - 1)) {
|
||||
x = 0;
|
||||
y = y + 2;
|
||||
}
|
||||
|
||||
if (chr_size == 16)
|
||||
{
|
||||
|
||||
if (chr_size == OLED_CHR_SIZE_16) {
|
||||
oled_set_pos(x, y);
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
for (i = 0; i < F8X16_LINE_DATA; i++) {
|
||||
oled_wr_byte(F8X16[c * 16 + i], OLED_DATA);
|
||||
}
|
||||
oled_set_pos(x, y + 1);
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
oled_wr_byte(F8X16[c * 16 + i + 8], OLED_DATA);
|
||||
for (i = 0; i < F8X16_LINE_DATA; i++) {
|
||||
oled_wr_byte(F8X16[c * CHAR_LEN + i + BYTE_BITS], OLED_DATA);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
oled_set_pos(x, y);
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
for (i = 0; i < F6X8_LINE_DATA; i++) {
|
||||
oled_wr_byte(F6x8[c][i], OLED_DATA);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,7 +471,7 @@ void oled_show_char(uint8_t x, uint8_t y, uint8_t chr, uint8_t chr_size)
|
||||
/***************************************************************
|
||||
* 函数名称: oled_show_num
|
||||
* 说 明: oled显示数字
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x:数字的X轴坐标
|
||||
* @y:数字的Y轴坐标
|
||||
* @num:数字
|
||||
@@ -488,26 +481,22 @@ void oled_show_char(uint8_t x, uint8_t y, uint8_t chr, uint8_t chr_size)
|
||||
***************************************************************/
|
||||
void oled_show_num(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size2)
|
||||
{
|
||||
uint8_t div = 2;
|
||||
uint8_t t, temp;
|
||||
uint8_t enshow = 0;
|
||||
|
||||
for (t = 0; t < len; t++)
|
||||
{
|
||||
|
||||
for (t = 0; t < len; t++) {
|
||||
temp = (num / oled_pow(10, len - t - 1)) % 10;
|
||||
if (enshow == 0 && t < (len - 1))
|
||||
{
|
||||
if (temp == 0)
|
||||
{
|
||||
oled_show_char(x + (size2 / 2)*t, y, ' ', size2);
|
||||
if (enshow == 0 && t < (len - 1)) {
|
||||
if (temp == 0) {
|
||||
oled_show_char(x + (size2 / div)*t, y, ' ', size2);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
enshow = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
oled_show_char(x + (size2 / 2)*t, y, temp + '0', size2);
|
||||
oled_show_char(x + (size2 / div)*t, y, temp + '0', size2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +504,7 @@ void oled_show_num(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size
|
||||
/***************************************************************
|
||||
* 函数名称: oled_show_string
|
||||
* 说 明: oled显示字符串
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x:字符串的X轴坐标
|
||||
* @y:字符串的Y轴坐标
|
||||
* @p:字符串
|
||||
@@ -525,13 +514,11 @@ void oled_show_num(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size
|
||||
void oled_show_string(uint8_t x, uint8_t y, uint8_t *chr, uint8_t chr_size)
|
||||
{
|
||||
unsigned char j = 0;
|
||||
|
||||
while (chr[j] != '\0')
|
||||
{
|
||||
|
||||
while (chr[j] != '\0') {
|
||||
oled_show_char(x, y, chr[j], chr_size);
|
||||
x += 8;
|
||||
if (x > 120)
|
||||
{
|
||||
if (x > OLED_COLUMN_MAX) {
|
||||
x = 0;
|
||||
y += 2;
|
||||
}
|
||||
@@ -543,7 +530,7 @@ void oled_show_string(uint8_t x, uint8_t y, uint8_t *chr, uint8_t chr_size)
|
||||
/***************************************************************
|
||||
* 函数名称: oled_draw_bmp
|
||||
* 说 明: oled显示图片
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @x0:图片的起始点X轴坐标,取值为0~127
|
||||
* @y0:图片的起始点Y轴坐标,取值为0~63
|
||||
* @x1:图片的结束点X轴坐标,取值为0~127
|
||||
@@ -553,24 +540,20 @@ void oled_show_string(uint8_t x, uint8_t y, uint8_t *chr, uint8_t chr_size)
|
||||
***************************************************************/
|
||||
void oled_draw_bmp(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char bmp[])
|
||||
{
|
||||
unsigned char xy_points = 8;
|
||||
unsigned int j = 0;
|
||||
unsigned char x, y;
|
||||
|
||||
if (y1 % 8 == 0)
|
||||
{
|
||||
y = y1 / 8;
|
||||
|
||||
if (y1 % xy_points == 0) {
|
||||
y = y1 / xy_points;
|
||||
} else {
|
||||
y = y1 / xy_points + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = y1 / 8 + 1;
|
||||
}
|
||||
|
||||
for (y = y0; y < y1; y++)
|
||||
{
|
||||
|
||||
for (y = y0; y < y1; y++) {
|
||||
oled_set_pos(x0, y);
|
||||
|
||||
for (x = x0; x < x1; x++)
|
||||
{
|
||||
for (x = x0; x < x1; x++) {
|
||||
oled_wr_byte(bmp[j++], OLED_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+24
-15
@@ -16,12 +16,24 @@
|
||||
#include "ohos_init.h"
|
||||
#include "lz_hardware.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 2000
|
||||
|
||||
|
||||
/* E53模块中
|
||||
* UART0_RX_M0 -> GPIO0_B6
|
||||
* UART0_TX_M0 -> GPIO0_B7
|
||||
*/
|
||||
#define UART_ID 0
|
||||
|
||||
/* 串口波特率 */
|
||||
#define UART_BAUD_RATE 115200
|
||||
|
||||
void uart_process(void)
|
||||
{
|
||||
unsigned int ret;
|
||||
@@ -29,33 +41,31 @@ void uart_process(void)
|
||||
unsigned char str[] = "HelloWorld!\n";
|
||||
|
||||
LzUartDeinit(UART_ID);
|
||||
|
||||
attr.baudRate = 115200;
|
||||
|
||||
attr.baudRate = UART_BAUD_RATE;
|
||||
attr.dataBits = UART_DATA_BIT_8;
|
||||
attr.pad = FLOW_CTRL_NONE;
|
||||
attr.parity = UART_PARITY_NONE;
|
||||
attr.rxBlock = UART_BLOCK_STATE_NONE_BLOCK;
|
||||
attr.stopBits = UART_STOP_BIT_1;
|
||||
attr.txBlock = UART_BLOCK_STATE_NONE_BLOCK;
|
||||
|
||||
|
||||
PinctrlSet(GPIO0_PB6, MUX_FUNC2, PULL_KEEP, DRIVE_LEVEL2);
|
||||
PinctrlSet(GPIO0_PB7, MUX_FUNC2, PULL_KEEP, DRIVE_LEVEL2);
|
||||
|
||||
|
||||
ret = LzUartInit(UART_ID, &attr);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %d: LzUartInit(%d) failed!\n", __FILE__, __LINE__, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
printf("%s, %d: uart write!\n", __FILE__, __LINE__);
|
||||
LzUartWrite(UART_ID, str, strlen(str));
|
||||
|
||||
LOS_Msleep(2000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,13 +82,12 @@ void uart_example()
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)uart_process;
|
||||
task.uwStackSize = 2048;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "uart process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create task ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create task ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+82
-75
@@ -27,13 +27,26 @@
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/inet_chksum.h"
|
||||
|
||||
#define LOG_TAG "tcp"
|
||||
int get_wifi_info(WifiLinkedInfo *info);
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
#define OC_SERVER_IP "192.168.2.156"
|
||||
#define SERVER_PORT 6666
|
||||
/* 循环等待时间 */
|
||||
#define GET_WIFI_WAIT_MSEC 1000
|
||||
#define SERVER_WAIT_MSEC 2000
|
||||
#define CLIENT_WAIT_MSEC 3000
|
||||
|
||||
#define BUFF_LEN 256
|
||||
#define LOG_TAG "tcp"
|
||||
|
||||
/* 服务器IP地址和端口 */
|
||||
#define OC_SERVER_IP "192.168.2.156"
|
||||
#define SERVER_PORT 6666
|
||||
/* 服务器监听数量 */
|
||||
#define SERVER_LISTEN_MAX 64
|
||||
|
||||
/* 缓冲区大小 */
|
||||
#define BUFF_LEN 256
|
||||
|
||||
int get_wifi_info(WifiLinkedInfo *info)
|
||||
{
|
||||
@@ -42,14 +55,14 @@ int get_wifi_info(WifiLinkedInfo *info)
|
||||
memset(info, 0, sizeof(WifiLinkedInfo));
|
||||
unsigned int retry = 15;
|
||||
struct in_addr addr;
|
||||
|
||||
|
||||
while (retry) {
|
||||
if (GetLinkedInfo(info) == WIFI_SUCCESS) {
|
||||
if (info->connState == WIFI_CONNECTED) {
|
||||
if (info->ipAddress != 0) {
|
||||
addr.s_addr = (in_addr_t)info->ipAddress;
|
||||
LZ_HARDWARE_LOGD(LOG_TAG, "rknetwork IP (%s)", inet_ntoa(addr));
|
||||
|
||||
|
||||
if (WIFI_SUCCESS == GetLocalWifiGw(&gw)) {
|
||||
addr.s_addr = (in_addr_t)gw;
|
||||
LZ_HARDWARE_LOGD(LOG_TAG, "network GW (%s)", inet_ntoa(addr));
|
||||
@@ -74,7 +87,7 @@ int get_wifi_info(WifiLinkedInfo *info)
|
||||
}
|
||||
}
|
||||
}
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(GET_WIFI_WAIT_MSEC);
|
||||
retry--;
|
||||
}
|
||||
|
||||
@@ -90,31 +103,29 @@ void tcp_server_msg_handle(int fd)
|
||||
int cnt = 0, count;
|
||||
int client_fd;
|
||||
struct sockaddr_in client_addr = {0};
|
||||
|
||||
|
||||
printf("waitting for client connect...\n");
|
||||
/* 监听socket 此处会阻塞 */
|
||||
client_fd = accept(fd, (struct sockaddr*)&client_addr, &client_addr_len);
|
||||
// client_fd = lwip_accept(fd, (struct sockaddr*)&client_addr, &client_addr_len);
|
||||
printf("[tcp server] accept <%s:%d>\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
memset(buf, 0, BUFF_LEN);
|
||||
printf("-------------------------------------------------------\n");
|
||||
printf("[tcp server] waitting client msg\n");
|
||||
count = recv(client_fd, buf, BUFF_LEN, 0); //read是阻塞函数,没有数据就一直阻塞
|
||||
// count = lwip_read(client_fd, buf, BUFF_LEN); //read是阻塞函数,没有数据就一直阻塞
|
||||
if (count == -1)
|
||||
{
|
||||
count = recv(client_fd, buf, BUFF_LEN, 0); // read是阻塞函数,没有数据就一直阻塞
|
||||
// count = lwip_read(client_fd, buf, BUFF_LEN); // read是阻塞函数,没有数据就一直阻塞
|
||||
if (count == -1) {
|
||||
printf("[tcp server] recieve data fail!\n");
|
||||
LOS_Msleep(3000);
|
||||
LOS_Msleep(SERVER_WAIT_MSEC);
|
||||
break;
|
||||
}
|
||||
printf("[tcp server] rev client msg:%s\n", buf);
|
||||
memset(buf, 0, BUFF_LEN);
|
||||
sprintf(buf, "I have recieved %d bytes data! recieved cnt:%d", count, ++cnt);
|
||||
printf("[tcp server] send msg:%s\n", buf);
|
||||
send(client_fd, buf, strlen(buf), 0); //发送信息给client
|
||||
// lwip_write(client_fd, buf, strlen(buf)); //发送信息给client
|
||||
send(client_fd, buf, strlen(buf), 0); // 发送信息给client
|
||||
// lwip_write(client_fd, buf, strlen(buf)); // 发送信息给client
|
||||
}
|
||||
lwip_close(client_fd);
|
||||
lwip_close(fd);
|
||||
@@ -124,83 +135,79 @@ int wifi_server(void* arg)
|
||||
{
|
||||
int server_fd, ret;
|
||||
|
||||
while(1)
|
||||
{
|
||||
server_fd = socket(AF_INET, SOCK_STREAM, 0); //AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
// server_fd = lwip_socket(AF_INET, SOCK_STREAM, 0); //AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
if (server_fd < 0)
|
||||
{
|
||||
while (1) {
|
||||
server_fd = socket(AF_INET, SOCK_STREAM, 0); // AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
// server_fd = lwip_socket(AF_INET, SOCK_STREAM, 0); // AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
if (server_fd < 0) {
|
||||
printf("create socket fail!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*设置调用close(socket)后,仍可继续重用该socket。调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。*/
|
||||
/* 设置调用close(socket)后,仍可继续重用该socket。
|
||||
* 调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。
|
||||
*/
|
||||
int flag = 1;
|
||||
ret = setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int));
|
||||
if (ret != 0) {
|
||||
printf("[CommInitTcpServer]setsockopt fail, ret[%d]!\n", ret);
|
||||
}
|
||||
|
||||
|
||||
struct sockaddr_in serv_addr = {0};
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); //IP地址,需要进行网络序转换,INADDR_ANY:本地地址
|
||||
// serv_addr.sin_addr.s_addr = inet_addr(OC_SERVER_IP); //IP地址,需要进行网络序转换,INADDR_ANY:本地地址
|
||||
serv_addr.sin_port = htons(SERVER_PORT); //端口号,需要网络序转换
|
||||
/* IP地址,需要进行网络序转换,INADDR_ANY:本地地址 */
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
// serv_addr.sin_addr.s_addr = inet_addr(OC_SERVER_IP);
|
||||
/* 端口号,需要网络序转换 */
|
||||
serv_addr.sin_port = htons(SERVER_PORT);
|
||||
/* 绑定服务器地址结构 */
|
||||
ret = bind(server_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
|
||||
// ret = lwip_bind(server_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
|
||||
if (ret < 0)
|
||||
{
|
||||
if (ret < 0) {
|
||||
printf("socket bind fail!\n");
|
||||
lwip_close(server_fd);
|
||||
return -1;
|
||||
}
|
||||
/* 监听socket 此处不阻塞 */
|
||||
ret = listen(server_fd, 64);
|
||||
ret = listen(server_fd, SERVER_LISTEN_MAX);
|
||||
// ret = lwip_listen(server_fd, 64);
|
||||
if(ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("socket listen fail!\n");
|
||||
lwip_close(server_fd);
|
||||
return -1;
|
||||
}
|
||||
printf("[tcp server] listen:%d<%s:%d>\n",server_fd, inet_ntoa(serv_addr.sin_addr), ntohs(serv_addr.sin_port));
|
||||
tcp_server_msg_handle(server_fd); //处理接收到的数据
|
||||
LOS_Msleep(1000);
|
||||
printf("[tcp server] listen:%d<%s:%d>\n", server_fd, inet_ntoa(serv_addr.sin_addr), ntohs(serv_addr.sin_port));
|
||||
/* 处理接收到的数据 */
|
||||
tcp_server_msg_handle(server_fd);
|
||||
LOS_Msleep(SERVER_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tcp_client_msg_handle(int fd, struct sockaddr* dst)
|
||||
{
|
||||
socklen_t len = sizeof(*dst);
|
||||
|
||||
int cnt = 0, count = 0;
|
||||
while (connect(fd, dst, len) < 0)
|
||||
{
|
||||
while (connect(fd, dst, len) < 0) {
|
||||
printf("connect server failed...%d\n", ++count);
|
||||
lwip_close(fd);
|
||||
LOS_Msleep(5000);
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0); //AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
LOS_Msleep(CLIENT_WAIT_MSEC);
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0); // AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
char buf[BUFF_LEN];
|
||||
sprintf(buf, "TCP TEST cilent send:%d", ++cnt);
|
||||
count = send(fd, buf, strlen(buf), 0); //发送数据给server
|
||||
// count = lwip_write(fd, buf, strlen(buf)); //发送数据给server
|
||||
count = send(fd, buf, strlen(buf), 0); // 发送数据给server
|
||||
// count = lwip_write(fd, buf, strlen(buf)); // 发送数据给server
|
||||
printf("------------------------------------------------------------\n");
|
||||
printf("[tcp client] send:%s\n", buf);
|
||||
printf("[tcp client] client sendto msg to server %d,waitting server respond msg!!!\n", count);
|
||||
memset(buf, 0, BUFF_LEN);
|
||||
count = recv(fd, buf, BUFF_LEN, 0); //接收来自server的信息
|
||||
// count = lwip_read(fd, buf, BUFF_LEN); //接收来自server的信息
|
||||
if(count == -1)
|
||||
{
|
||||
count = recv(fd, buf, BUFF_LEN, 0); // 接收来自server的信息
|
||||
// count = lwip_read(fd, buf, BUFF_LEN); // 接收来自server的信息
|
||||
if (count == -1) {
|
||||
printf("[tcp client] recieve data fail!\n");
|
||||
LOS_Msleep(3000);
|
||||
LOS_Msleep(CLIENT_WAIT_MSEC);
|
||||
break;
|
||||
}
|
||||
printf("[tcp client] rev:%s\n", buf);
|
||||
@@ -212,33 +219,34 @@ int wifi_client(void* arg)
|
||||
{
|
||||
int client_fd, ret;
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
while(1)
|
||||
{
|
||||
client_fd = socket(AF_INET, SOCK_STREAM, 0);//AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
if (client_fd < 0)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
client_fd = socket(AF_INET, SOCK_STREAM, 0); // AF_INET:IPV4;SOCK_STREAM:TCP
|
||||
if (client_fd < 0) {
|
||||
printf("create socket fail!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*设置调用close(socket)后,仍可继续重用该socket。调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。*/
|
||||
/*
|
||||
* 设置调用close(socket)后,仍可继续重用该socket。
|
||||
* 调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。
|
||||
*/
|
||||
int flag = 1;
|
||||
ret = setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int));
|
||||
if (ret != 0) {
|
||||
printf("[CommInitTcpServer]setsockopt fail, ret[%d]!\n", ret);
|
||||
}
|
||||
|
||||
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = inet_addr(OC_SERVER_IP);
|
||||
serv_addr.sin_port = htons(SERVER_PORT);
|
||||
printf("[tcp client] connect:%d<%s:%d>\n",client_fd, inet_ntoa(serv_addr.sin_addr), ntohs(serv_addr.sin_port));
|
||||
|
||||
|
||||
printf("[tcp client] connect:%d<%s:%d>\n", client_fd, inet_ntoa(serv_addr.sin_addr),
|
||||
ntohs(serv_addr.sin_port));
|
||||
|
||||
tcp_client_msg_handle(client_fd, (struct sockaddr*)&serv_addr);
|
||||
|
||||
LOS_Msleep(1000);
|
||||
|
||||
LOS_Msleep(CLIENT_WAIT_MSEC);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -249,12 +257,14 @@ void wifi_process(void *args)
|
||||
{
|
||||
unsigned int threadID_client, threadID_server;
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
|
||||
WifiLinkedInfo info;
|
||||
|
||||
/* 开启WiFi连接任务 */
|
||||
ExternalTaskConfigNetwork();
|
||||
while(get_wifi_info(&info) != 0) ;
|
||||
while (get_wifi_info(&info) != 0) {
|
||||
/* 什么都不做,等待 */
|
||||
}
|
||||
|
||||
CreateThread(&threadID_client, wifi_client, NULL, "client@ process");
|
||||
CreateThread(&threadID_server, wifi_server, NULL, "server@ process");
|
||||
@@ -266,19 +276,16 @@ void wifi_tcp_example(void)
|
||||
unsigned int ret = LOS_OK;
|
||||
unsigned int thread_id;
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
printf("%s start ....\n", __FUNCTION__);
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)wifi_process;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "wifi_process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create wifi_process ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create wifi_process ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(wifi_tcp_example);
|
||||
|
||||
|
||||
Executable → Regular
+100
-68
@@ -23,13 +23,27 @@
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/inet_chksum.h"
|
||||
|
||||
#define LOG_TAG "udp"
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
#define OC_SERVER_IP "192.168.2.49"
|
||||
#define SERVER_PORT 6666
|
||||
#define CLIENT_LOCAL_PORT 8888
|
||||
/* 循环等待时间 */
|
||||
#define GET_WIFI_WAIT_MSEC 1000
|
||||
#define SERVER_WAIT_MSEC 2000
|
||||
#define CLIENT_WAIT_MSEC 100
|
||||
|
||||
#define BUFF_LEN 256
|
||||
/* 打印信息 */
|
||||
#define LOG_TAG "udp"
|
||||
|
||||
/* UDP服务端IP地址和端口号 */
|
||||
#define OC_SERVER_IP "192.168.2.49"
|
||||
#define SERVER_PORT 6666
|
||||
/* UDP客户端端口号 */
|
||||
#define CLIENT_LOCAL_PORT 8888
|
||||
|
||||
/* 字节缓冲区大小 */
|
||||
#define BUFF_LEN 256
|
||||
|
||||
WifiLinkedInfo wifiinfo;
|
||||
|
||||
@@ -72,7 +86,7 @@ int udp_get_wifi_info(WifiLinkedInfo *info)
|
||||
}
|
||||
}
|
||||
}
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(GET_WIFI_WAIT_MSEC);
|
||||
retry--;
|
||||
}
|
||||
|
||||
@@ -87,25 +101,28 @@ void udp_server_msg_handle(int fd)
|
||||
socklen_t len;
|
||||
int cnt = 0, count;
|
||||
struct sockaddr_in client_addr = {0};
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
memset(buf, 0, BUFF_LEN);
|
||||
len = sizeof(client_addr);
|
||||
|
||||
printf("[udp server]------------------------------------------------\n");
|
||||
printf("[udp server] waitting client message!!!\n");
|
||||
count = recvfrom(fd, buf, BUFF_LEN, 0, (struct sockaddr*)&client_addr, &len); //recvfrom是阻塞函数,没有数据就一直阻塞
|
||||
if (count == -1)
|
||||
{
|
||||
|
||||
/* recvfrom是阻塞函数,没有数据就一直阻塞 */
|
||||
count = recvfrom(fd, buf, BUFF_LEN, 0, (struct sockaddr*)&client_addr, &len);
|
||||
if (count == -1) {
|
||||
printf("[udp server] recieve data fail!\n");
|
||||
LOS_Msleep(3000);
|
||||
LOS_Msleep(SERVER_WAIT_MSEC);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("[udp server] remote addr:%s port:%u\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
|
||||
printf("[udp server] rev:%s\n", buf);
|
||||
memset(buf, 0, BUFF_LEN);
|
||||
sprintf(buf, "I have recieved %d bytes data! recieved cnt:%d", count, ++cnt);
|
||||
printf("[udp server] send:%s\n", buf);
|
||||
sendto(fd, buf, strlen(buf), 0, (struct sockaddr*)&client_addr, len); //发送信息给client
|
||||
sendto(fd, buf, strlen(buf), 0, (struct sockaddr*)&client_addr, len); // 发送信息给client
|
||||
}
|
||||
lwip_close(fd);
|
||||
}
|
||||
@@ -115,40 +132,44 @@ int wifi_udp_server(void* arg)
|
||||
int server_fd, ret;
|
||||
struct in_addr addr;
|
||||
|
||||
while(1)
|
||||
{
|
||||
server_fd = socket(AF_INET, SOCK_DGRAM, 0); //AF_INET:IPV4;SOCK_DGRAM:UDP
|
||||
if (server_fd < 0)
|
||||
{
|
||||
while (1) {
|
||||
server_fd = socket(AF_INET, SOCK_DGRAM, 0); // AF_INET:IPV4;SOCK_DGRAM:UDP
|
||||
if (server_fd < 0) {
|
||||
printf("create socket fail!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*设置调用close(socket)后,仍可继续重用该socket。调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。*/
|
||||
/*
|
||||
* 设置调用close(socket)后,仍可继续重用该socket。
|
||||
* 调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。
|
||||
*/
|
||||
int flag = 1;
|
||||
|
||||
ret = setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int));
|
||||
if (ret != 0) {
|
||||
printf("[CommInitUdpServer]setsockopt fail, ret[%d]!\n", ret);
|
||||
}
|
||||
|
||||
|
||||
struct sockaddr_in serv_addr = {0};
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); //IP地址,需要进行网络序转换,INADDR_ANY:本地地址
|
||||
// serv_addr.sin_addr.s_addr = wifiinfo.ipAddress;
|
||||
serv_addr.sin_port = htons(SERVER_PORT); //端口号,需要网络序转换
|
||||
/* IP地址,需要进行网络序转换,INADDR_ANY:本地地址 */
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
/* 端口号,需要网络序转换 */
|
||||
serv_addr.sin_port = htons(SERVER_PORT);
|
||||
/* 绑定服务器地址结构 */
|
||||
ret = bind(server_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
|
||||
if (ret < 0)
|
||||
{
|
||||
if (ret < 0) {
|
||||
printf("socket bind fail!\n");
|
||||
lwip_close(server_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr.s_addr = (in_addr_t)wifiinfo.ipAddress;
|
||||
printf("[udp server] local addr:%s,port:%u\n", inet_ntoa(addr), ntohs(serv_addr.sin_port));
|
||||
|
||||
udp_server_msg_handle(server_fd); //处理接收到的数据
|
||||
LOS_Msleep(1000);
|
||||
/* 处理接收到的数据 */
|
||||
udp_server_msg_handle(server_fd);
|
||||
LOS_Msleep(SERVER_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,36 +180,39 @@ void udp_client_msg_handle(int fd, struct sockaddr* dst)
|
||||
socklen_t len = sizeof(*dst);
|
||||
|
||||
struct sockaddr_in client_addr;
|
||||
int cnt = 0,count = 0;
|
||||
printf("[udp client] remote addr:%s port:%u\n", inet_ntoa(((struct sockaddr_in*)dst)->sin_addr), ntohs(((struct sockaddr_in*)dst)->sin_port));
|
||||
connect(fd, dst, len);
|
||||
getsockname(fd, (struct sockaddr*)&client_addr,&len);
|
||||
int cnt = 0, count = 0;
|
||||
|
||||
printf("[udp client] remote addr:%s port:%u\n", inet_ntoa(((struct sockaddr_in*)dst)->sin_addr),
|
||||
ntohs(((struct sockaddr_in*)dst)->sin_port));
|
||||
connect(fd, dst, len);
|
||||
getsockname(fd, (struct sockaddr*)&client_addr, &len);
|
||||
printf("[udp client] local addr:%s port:%u\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
char buf[BUFF_LEN];
|
||||
|
||||
printf("[udp client]------------------------------------------------\n");
|
||||
printf("[udp client] waitting server message!!!\n");
|
||||
// count = recv(fd, buf, BUFF_LEN, 0); //接收来自server的信息
|
||||
count = recvfrom(fd, buf, BUFF_LEN, 0, (struct sockaddr*)&client_addr, &len); //recvfrom是阻塞函数,没有数据就一直阻塞
|
||||
if(count == -1)
|
||||
{
|
||||
|
||||
/*
|
||||
* recv接收来server的消息
|
||||
* recvfrom是阻塞函数,没有数据就一直阻塞
|
||||
*/
|
||||
count = recvfrom(fd, buf, BUFF_LEN, 0, (struct sockaddr*)&client_addr, &len);
|
||||
if (count == -1) {
|
||||
printf("[udp client] No server message!!!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("[udp client] remote addr:%s port:%u\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
|
||||
printf("[udp client] rev:%s\n", buf);
|
||||
}
|
||||
memset(buf, 0, BUFF_LEN);
|
||||
sprintf(buf, "UDP TEST cilent send:%d", ++cnt);
|
||||
// count = send(fd, buf, strlen(buf), 0); //发送数据给server
|
||||
count = sendto(fd, buf, strlen(buf), 0, (struct sockaddr*)&client_addr, len); //发送信息给client
|
||||
/* 发送数据给server */
|
||||
count = sendto(fd, buf, strlen(buf), 0, (struct sockaddr*)&client_addr, len);
|
||||
printf("[udp client] send:%s\n", buf);
|
||||
printf("[udp client] client sendto msg to server %dbyte,waitting server respond msg!!!\n", count);
|
||||
|
||||
LOS_Msleep(100);
|
||||
LOS_Msleep(CLIENT_WAIT_MSEC);
|
||||
}
|
||||
lwip_close(fd);
|
||||
}
|
||||
@@ -198,38 +222,46 @@ int wifi_udp_client(void* arg)
|
||||
{
|
||||
int client_fd, ret;
|
||||
struct sockaddr_in serv_addr, local_addr;
|
||||
|
||||
while(1)
|
||||
{
|
||||
client_fd = socket(AF_INET, SOCK_DGRAM, 0);//AF_INET:IPV4;SOCK_DGRAM:UDP
|
||||
if (client_fd < 0)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
client_fd = socket(AF_INET, SOCK_DGRAM, 0); // AF_INET:IPV4;SOCK_DGRAM:UDP
|
||||
if (client_fd < 0) {
|
||||
printf("create socket fail!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*设置调用close(socket)后,仍可继续重用该socket。调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。*/
|
||||
/*
|
||||
* 设置调用close(socket)后,仍可继续重用该socket。
|
||||
* 调用close(socket)一般不会立即关闭socket,而经历TIME_WAIT的过程。
|
||||
*/
|
||||
int flag = 1;
|
||||
ret = setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int));
|
||||
if (ret != 0) {
|
||||
printf("[CommInitUdpServer]setsockopt fail, ret[%d]!\n", ret);
|
||||
close(client_fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
memset(&local_addr, 0, sizeof(local_addr));
|
||||
local_addr.sin_family = AF_INET;
|
||||
local_addr.sin_addr.s_addr = wifiinfo.ipAddress;
|
||||
local_addr.sin_port = htons(CLIENT_LOCAL_PORT);
|
||||
//绑定本地ip端口号
|
||||
/* 绑定本地ip端口号 */
|
||||
ret = bind(client_fd, (struct sockaddr*)&local_addr, sizeof(local_addr));
|
||||
if (ret == -1) {
|
||||
printf("client bind failed(%d)\n", ret);
|
||||
close(client_fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); //IP地址,需要进行网络序转换,INADDR_ANY:本地地址
|
||||
// serv_addr.sin_addr.s_addr = inet_addr(OC_SERVER_IP); //指定ip接收
|
||||
serv_addr.sin_port = htons(SERVER_PORT);
|
||||
/* IP地址,需要进行网络序转换,INADDR_ANY:本地地址 */
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serv_addr.sin_port = htons(SERVER_PORT);
|
||||
udp_client_msg_handle(client_fd, (struct sockaddr*)&serv_addr);
|
||||
|
||||
LOS_Msleep(1000);
|
||||
|
||||
LOS_Msleep(CLIENT_WAIT_MSEC);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -240,18 +272,20 @@ void wifi_udp_process(void *args)
|
||||
{
|
||||
unsigned int threadID_client, threadID_server;
|
||||
unsigned int ret = LOS_OK;
|
||||
|
||||
|
||||
WifiLinkedInfo info;
|
||||
|
||||
/* 开启WiFi连接任务 */
|
||||
ExternalTaskConfigNetwork();
|
||||
while(udp_get_wifi_info(&info) != 0) ;
|
||||
while (udp_get_wifi_info(&info) != 0) {
|
||||
/* 等待,不做任何事情 */
|
||||
}
|
||||
|
||||
wifiinfo = info;
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
|
||||
CreateThread(&threadID_client, wifi_udp_client, NULL, "udp client@ process");
|
||||
CreateThread(&threadID_server, wifi_udp_server, NULL, "udp server@ process");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -260,19 +294,17 @@ void wifi_udp_example(void)
|
||||
unsigned int ret = LOS_OK;
|
||||
unsigned int thread_id;
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
printf("%s start ....\n", __FUNCTION__);
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)wifi_udp_process;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "wifi_process";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create wifi_process ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create wifi_process ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(wifi_udp_example);
|
||||
|
||||
APP_FEATURE_INIT(wifi_udp_example);
|
||||
|
||||
Executable → Regular
+26
-18
@@ -17,6 +17,21 @@
|
||||
#include "los_task.h"
|
||||
#include "e53_intelligent_agriculture.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 2000
|
||||
|
||||
/* 亮度报警数值 */
|
||||
#define LUMINANCE_ALARM 20
|
||||
/* 湿度报警数值 */
|
||||
#define HUMIDITY_ALARM 60
|
||||
/* 温度报警数值 */
|
||||
#define TEMPERATURE_ALARM 30
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: e53_ia_thread
|
||||
* 说 明: 智慧农业线程
|
||||
@@ -29,36 +44,30 @@ void e53_ia_thread()
|
||||
|
||||
e53_ia_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
e53_ia_read_data(&data);
|
||||
|
||||
printf("\nLuminance is %.2f\n", data.luminance);
|
||||
printf("\nHumidity is %.2f\n", data.humidity);
|
||||
printf("\nTemperature is %.2f\n", data.temperature);
|
||||
|
||||
if (data.luminance < 20)
|
||||
{
|
||||
if (data.luminance < LUMINANCE_ALARM) {
|
||||
light_set(ON);
|
||||
printf("light on\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
light_set(OFF);
|
||||
printf("light off\n");
|
||||
}
|
||||
|
||||
if ((data.humidity > 60) || (data.temperature > 30))
|
||||
{
|
||||
if ((data.humidity > HUMIDITY_ALARM) || (data.temperature > TEMPERATURE_ALARM)) {
|
||||
motor_set_status(ON);
|
||||
printf("motor on\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
motor_set_status(OFF);
|
||||
printf("motor off\n");
|
||||
}
|
||||
LOS_Msleep(2000);
|
||||
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,13 +84,12 @@ void e53_ia_example()
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)e53_ia_thread;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "e53_ia_thread";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create e53_ia_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create e53_ia_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+5
-7
@@ -18,15 +18,13 @@
|
||||
|
||||
#include "lz_hardware.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float luminance;/*亮度*/
|
||||
float humidity;/*湿度*/
|
||||
float temperature;/*温度*/
|
||||
typedef struct {
|
||||
float luminance; /* 亮度 */
|
||||
float humidity; /* 湿度 */
|
||||
float temperature; /* 温度 */
|
||||
} e53_ia_data_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
OFF = 0,
|
||||
ON
|
||||
} SWITCH_STATUS_ENUM;
|
||||
|
||||
Executable → Regular
+80
-69
@@ -16,9 +16,14 @@
|
||||
#include "e53_intelligent_agriculture.h"
|
||||
#include "lz_hardware.h"
|
||||
|
||||
#define IA_I2C0 0
|
||||
#define BH1750_ADDR 0x23
|
||||
#define SHT30_ADDR 0x44
|
||||
/* i2c的设备编号 */
|
||||
#define IA_I2C0 0
|
||||
/* i2c的通信速率 */
|
||||
#define I2C_RATE 100000
|
||||
/* BH1750的i2c从设备地址 */
|
||||
#define BH1750_ADDR 0x23
|
||||
/* sht30的i2c从设备地址 */
|
||||
#define SHT30_ADDR 0x44
|
||||
|
||||
static I2cBusIo m_ia_i2c0m2 = {
|
||||
.scl = {.gpio = GPIO0_PA1, .func = MUX_FUNC3, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
@@ -27,6 +32,17 @@ static I2cBusIo m_ia_i2c0m2 = {
|
||||
.mode = FUNC_MODE_M2,
|
||||
};
|
||||
|
||||
/* 读取SHT30的SHT30_ADDR寄存器位移定义 */
|
||||
enum enum_offset_sht30_reg {
|
||||
EOFFSET_SHT30_REG_TEMP_H = 0, /* 温度寄存器数值高位 */
|
||||
EOFFSET_SHT30_REG_TEMP_L, /* 温度寄存器数值低位 */
|
||||
EOFFSET_SHT30_REG_TEMP_CRC, /* 温度寄存器数值校验位 */
|
||||
EOFFSET_SHT30_REG_HUMIDITY_H, /* 湿度寄存器数值高位 */
|
||||
EOFFSET_SHT30_REG_HUMIDITY_L, /* 湿度寄存器数值低位 */
|
||||
EOFFSET_SHT30_REG_HUMIDITY_CRC, /* 湿度寄存器数值校验位 */
|
||||
EOFFSET_SHT30_REG_MAX
|
||||
};
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: init_sht30
|
||||
* 说 明: 初始化SHT30,设置测量周期
|
||||
@@ -38,7 +54,7 @@ void init_sht30()
|
||||
uint8_t send_data[2] = {0x22, 0x36};
|
||||
uint32_t send_len = 2;
|
||||
|
||||
LzI2cWrite(IA_I2C0, SHT30_ADDR, send_data, send_len);
|
||||
LzI2cWrite(IA_I2C0, SHT30_ADDR, send_data, send_len);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -52,7 +68,7 @@ void init_bh1750()
|
||||
uint8_t send_data[1] = {0x01};
|
||||
uint32_t send_len = 1;
|
||||
|
||||
LzI2cWrite(IA_I2C0, BH1750_ADDR, send_data, send_len);
|
||||
LzI2cWrite(IA_I2C0, BH1750_ADDR, send_data, send_len);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -79,10 +95,10 @@ float sht30_calc_RH(uint16_t u16sRH)
|
||||
{
|
||||
float humidityRH = 0;
|
||||
|
||||
/*clear bits [1..0] (status bits)*/
|
||||
/* clear bits [1..0] (status bits) */
|
||||
u16sRH &= ~0x0003;
|
||||
/*calculate relative humidity [%RH]*/
|
||||
/*RH = rawValue / (2^16-1) * 10*/
|
||||
/* calculate relative humidity [%RH] */
|
||||
/* RH = rawValue / (2^16-1) * 10 */
|
||||
humidityRH = (100 * (float)u16sRH / 65535);
|
||||
|
||||
return humidityRH;
|
||||
@@ -98,10 +114,10 @@ float sht30_calc_temperature(uint16_t u16sT)
|
||||
{
|
||||
float temperature = 0;
|
||||
|
||||
/*clear bits [1..0] (status bits)*/
|
||||
/* clear bits [1..0] (status bits) */
|
||||
u16sT &= ~0x0003;
|
||||
/*calculate temperature [℃]*/
|
||||
/*T = -45 + 175 * rawValue / (2^16-1)*/
|
||||
/* calculate temperature [℃] */
|
||||
/* T = -45 + 175 * rawValue / (2^16-1) */
|
||||
temperature = (175 * (float)u16sT / 65535 - 45);
|
||||
|
||||
return temperature;
|
||||
@@ -117,26 +133,30 @@ float sht30_calc_temperature(uint16_t u16sT)
|
||||
***************************************************************/
|
||||
uint8_t sht30_check_crc(uint8_t *data, uint8_t nbrOfBytes, uint8_t checksum)
|
||||
{
|
||||
uint8_t byte_to_bits = 8;
|
||||
uint8_t high_bit = 0x80;
|
||||
uint8_t crc = 0xFF;
|
||||
uint8_t bit = 0;
|
||||
uint8_t byteCtr ;
|
||||
const int16_t POLYNOMIAL = 0x131;
|
||||
|
||||
/*calculates 8-Bit checksum with given polynomial*/
|
||||
for(byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr)
|
||||
{
|
||||
/* calculates 8-Bit checksum with given polynomial */
|
||||
for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr) {
|
||||
crc ^= (data[byteCtr]);
|
||||
for ( bit = 8; bit > 0; --bit)
|
||||
{
|
||||
if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;
|
||||
else crc = (crc << 1);
|
||||
for (bit = byte_to_bits; bit > 0; --bit) {
|
||||
if (crc & high_bit) {
|
||||
crc = (crc << 1) ^ POLYNOMIAL;
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(crc != checksum)
|
||||
if (crc != checksum) {
|
||||
return 1;
|
||||
else
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -149,33 +169,29 @@ void e53_ia_io_init()
|
||||
{
|
||||
uint32_t ret = LZ_HARDWARE_FAILURE;
|
||||
|
||||
/*初始化紫光灯GPIO*/
|
||||
/* 初始化紫光灯GPIO */
|
||||
LzGpioInit(GPIO0_PA2);
|
||||
/*初始化电机GPIO*/
|
||||
/* 初始化电机GPIO */
|
||||
LzGpioInit(GPIO1_PD0);
|
||||
|
||||
/*设置GPIO0_PA2为输出模式*/
|
||||
/* 设置GPIO0_PA2为输出模式 */
|
||||
ret = LzGpioSetDir(GPIO0_PA2, LZGPIO_DIR_OUT);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("set GPIO0_PA2 Direction fail\n");
|
||||
}
|
||||
|
||||
/*设置GPIO1_PD0为输出模式*/
|
||||
/* 设置GPIO1_PD0为输出模式 */
|
||||
ret = LzGpioSetDir(GPIO1_PD0, LZGPIO_DIR_OUT);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("set GPIO0_PD0 Direction fail\n");
|
||||
}
|
||||
|
||||
/*初始化I2C*/
|
||||
if (I2cIoInit(m_ia_i2c0m2) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
/* 初始化I2C */
|
||||
if (I2cIoInit(m_ia_i2c0m2) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("init I2C I2C0 io fail\n");
|
||||
}
|
||||
/*I2C时钟频率100K*/
|
||||
if (LzI2cInit(IA_I2C0, 100000) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
/* I2C时钟频率100K */
|
||||
if (LzI2cInit(IA_I2C0, I2C_RATE) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("init I2C I2C0 fail\n");
|
||||
}
|
||||
}
|
||||
@@ -201,6 +217,7 @@ void e53_ia_init()
|
||||
***************************************************************/
|
||||
void e53_ia_read_data(e53_ia_data_t *pData)
|
||||
{
|
||||
uint16_t high_byte_bit = 8;
|
||||
uint8_t recv_data[2] = {0};
|
||||
uint32_t receive_len = 2;
|
||||
uint8_t rc;
|
||||
@@ -209,41 +226,39 @@ void e53_ia_read_data(e53_ia_data_t *pData)
|
||||
LOS_Msleep(180);
|
||||
|
||||
LzI2cRead(IA_I2C0, BH1750_ADDR, recv_data, receive_len);
|
||||
pData->luminance = (float)(((recv_data[0]<<8) + recv_data[1])/1.2);
|
||||
//printf("BH1750 data:0x%x%x", recv_data[0], recv_data[1]);
|
||||
pData->luminance = (float)(((recv_data[0] << 8) + recv_data[1]) / 1.2);
|
||||
// printf("BH1750 data:0x%x%x", recv_data[0], recv_data[1]);
|
||||
|
||||
/*checksum verification*/
|
||||
/* checksum verification */
|
||||
uint8_t data[3];
|
||||
uint16_t tmp;
|
||||
/*byte 0,1 is temperature byte 4,5 is humidity*/
|
||||
uint8_t SHT30_Data_Buffer[6];
|
||||
/* byte 0,1 is temperature byte 4,5 is humidity */
|
||||
uint8_t SHT30_Data_Buffer[EOFFSET_SHT30_REG_MAX];
|
||||
memset(SHT30_Data_Buffer, 0, 6);
|
||||
uint8_t send_data[2] = {0xE0, 0x00};
|
||||
uint32_t send_len = 2;
|
||||
LzI2cWrite(IA_I2C0, SHT30_ADDR, send_data, send_len);
|
||||
receive_len = 6;
|
||||
LzI2cRead(IA_I2C0, SHT30_ADDR, SHT30_Data_Buffer, receive_len);
|
||||
//printf("SHT30 data:0x%x%x%x)", SHT30_Data_Buffer[0], SHT30_Data_Buffer[1], SHT30_Data_Buffer[2]);
|
||||
// printf("SHT30 data:0x%x%x%x)", SHT30_Data_Buffer[0], SHT30_Data_Buffer[1], SHT30_Data_Buffer[2]);
|
||||
|
||||
/*check temperature*/
|
||||
data[0] = SHT30_Data_Buffer[0];
|
||||
data[1] = SHT30_Data_Buffer[1];
|
||||
data[2] = SHT30_Data_Buffer[2];
|
||||
/* check temperature */
|
||||
data[0] = SHT30_Data_Buffer[EOFFSET_SHT30_REG_TEMP_H];
|
||||
data[1] = SHT30_Data_Buffer[EOFFSET_SHT30_REG_TEMP_L];
|
||||
data[2] = SHT30_Data_Buffer[EOFFSET_SHT30_REG_TEMP_CRC];
|
||||
rc = sht30_check_crc(data, 2, data[2]);
|
||||
if(!rc)
|
||||
{
|
||||
tmp = ((uint16_t)data[0] << 8) | data[1];
|
||||
if (!rc) {
|
||||
tmp = ((uint16_t)data[0] << high_byte_bit) | data[1];
|
||||
pData->temperature = sht30_calc_temperature(tmp);
|
||||
}
|
||||
|
||||
/*check humidity*/
|
||||
data[0] = SHT30_Data_Buffer[3];
|
||||
data[1] = SHT30_Data_Buffer[4];
|
||||
data[2] = SHT30_Data_Buffer[5];
|
||||
|
||||
/* check humidity */
|
||||
data[0] = SHT30_Data_Buffer[EOFFSET_SHT30_REG_HUMIDITY_H];
|
||||
data[1] = SHT30_Data_Buffer[EOFFSET_SHT30_REG_HUMIDITY_L];
|
||||
data[2] = SHT30_Data_Buffer[EOFFSET_SHT30_REG_HUMIDITY_CRC];
|
||||
rc = sht30_check_crc(data, 2, data[2]);
|
||||
if(!rc)
|
||||
{
|
||||
tmp = ((uint16_t)data[0] << 8) | data[1];
|
||||
if (!rc) {
|
||||
tmp = ((uint16_t)data[0] << high_byte_bit) | data[1];
|
||||
pData->humidity = sht30_calc_RH(tmp);
|
||||
}
|
||||
}
|
||||
@@ -251,21 +266,19 @@ void e53_ia_read_data(e53_ia_data_t *pData)
|
||||
/***************************************************************
|
||||
* 函数名称: light_set
|
||||
* 说 明: 紫光灯控制
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* OFF,关
|
||||
* ON,开
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void light_set(SWITCH_STATUS_ENUM status)
|
||||
{
|
||||
if(status == ON)
|
||||
{
|
||||
/*设置GPIO0_PA2输出高电平点亮灯*/
|
||||
if (status == ON) {
|
||||
/* 设置GPIO0_PA2输出高电平点亮灯 */
|
||||
LzGpioSetVal(GPIO0_PA2, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
if(status == OFF)
|
||||
{
|
||||
/*设置GPIO0_PA2输出低电平关闭灯*/
|
||||
if (status == OFF) {
|
||||
/* 设置GPIO0_PA2输出低电平关闭灯 */
|
||||
LzGpioSetVal(GPIO0_PA2, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -273,21 +286,19 @@ void light_set(SWITCH_STATUS_ENUM status)
|
||||
/***************************************************************
|
||||
* 函数名称: motor_set_status
|
||||
* 说 明: 电机控制
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* OFF,关
|
||||
* ON,开
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void motor_set_status(SWITCH_STATUS_ENUM status)
|
||||
{
|
||||
if(status == ON)
|
||||
{
|
||||
/*设置GPIO0_PD0输出高电平打开电机*/
|
||||
if (status == ON) {
|
||||
/* 设置GPIO0_PD0输出高电平打开电机 */
|
||||
LzGpioSetVal(GPIO1_PD0, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
if(status == OFF)
|
||||
{
|
||||
/*设置GPIO0_PD0输出低电平关闭电机*/
|
||||
if (status == OFF) {
|
||||
/* 设置GPIO0_PD0输出低电平关闭电机 */
|
||||
LzGpioSetVal(GPIO1_PD0, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+30
-26
@@ -17,6 +17,15 @@
|
||||
#include "los_task.h"
|
||||
#include "e53_smart_covers.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 2000
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: e53_sc_thread
|
||||
* 说 明: E53智慧井盖线程
|
||||
@@ -32,41 +41,37 @@ void e53_sc_thread()
|
||||
led_d1_set(OFF);
|
||||
led_d2_set(OFF);
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
e53_sc_read_data(&data);
|
||||
printf("x is %d\n", (int)data.accel[0]);
|
||||
printf("y is %d\n", (int)data.accel[1]);
|
||||
printf("z is %d\n", (int)data.accel[2]);
|
||||
printf("x is %d\n", (int)data.accel[EACCEL_X]);
|
||||
printf("y is %d\n", (int)data.accel[EACCEL_Y]);
|
||||
printf("z is %d\n", (int)data.accel[EACCEL_Z]);
|
||||
printf("init x:%d y:%d z:%d\n", x, y, z);
|
||||
|
||||
if (x == 0 && y == 0 && z == 0)
|
||||
{
|
||||
x = (int)data.accel[0];
|
||||
y = (int)data.accel[1];
|
||||
z = (int)data.accel[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((x + DELTA) < data.accel[0] || (x - DELTA) > data.accel[0] ||
|
||||
(y + DELTA) < data.accel[1] || (y - DELTA) > data.accel[1] ||
|
||||
(z + DELTA) < data.accel[2] || (z - DELTA) > data.accel[2])
|
||||
{
|
||||
if (x == 0 && y == 0 && z == 0) {
|
||||
x = (int)data.accel[EACCEL_X];
|
||||
y = (int)data.accel[EACCEL_Y];
|
||||
z = (int)data.accel[EACCEL_Z];
|
||||
} else {
|
||||
if ((x + DELTA) < data.accel[EACCEL_X]
|
||||
|| (x - DELTA) > data.accel[EACCEL_X]
|
||||
|| (y + DELTA) < data.accel[EACCEL_Y]
|
||||
|| (y - DELTA) > data.accel[EACCEL_Y]
|
||||
|| (z + DELTA) < data.accel[EACCEL_Z]
|
||||
|| (z - DELTA) > data.accel[EACCEL_Z]) {
|
||||
/*倾斜告警*/
|
||||
led_d1_set(OFF);
|
||||
led_d2_set(ON);
|
||||
data.tilt_status = 1;
|
||||
printf("tilt warning \nLED1 OFF LED2 On\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
led_d1_set(ON);
|
||||
led_d2_set(OFF);
|
||||
data.tilt_status = 0;
|
||||
printf("normal \nLED1 ON LED2 OFF\n");
|
||||
}
|
||||
}
|
||||
LOS_Msleep(2000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,13 +88,12 @@ void e53_sc_example()
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)e53_sc_thread;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "e53_sc_thread";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create e53_sc_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create e53_sc_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+18
-13
@@ -18,35 +18,40 @@
|
||||
|
||||
#include "lz_hardware.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short accel[3];
|
||||
enum enum_accel {
|
||||
EACCEL_X = 0,
|
||||
EACCEL_Y,
|
||||
EACCEL_Z,
|
||||
EACCEL_MAX
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
short accel[EACCEL_MAX];
|
||||
unsigned int tilt_status;
|
||||
} e53_sc_data_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
OFF = 0,
|
||||
ON
|
||||
} SWITCH_STATUS_ENUM;
|
||||
|
||||
#define DELTA 100
|
||||
|
||||
#define MPU6050_GYRO_OUT 0x43 //MPU6050陀螺仪数据寄存器地址
|
||||
#define MPU6050_ACC_OUT 0x3B //MPU6050加速度数据寄存器地址
|
||||
#define MPU6050_SLAVE_ADDRESS 0x68 //MPU6050器件读地址
|
||||
#define MPU6050_ADDRESS_AD0_LOW 0x68 //address pin low (GND), default for InvenSense evaluation board
|
||||
#define MPU6050_GYRO_OUT 0x43 // MPU6050陀螺仪数据寄存器地址
|
||||
#define MPU6050_ACC_OUT 0x3B // MPU6050加速度数据寄存器地址
|
||||
#define MPU6050_SLAVE_ADDRESS 0x68 // MPU6050器件读地址
|
||||
#define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board
|
||||
#define MPU6050_RA_CONFIG 0x1A
|
||||
#define MPU6050_RA_ACCEL_CONFIG 0x1C
|
||||
#define MPU6050_RA_FF_THR 0x1D
|
||||
#define MPU6050_RA_FF_DUR 0x1E
|
||||
#define MPU6050_RA_MOT_THR 0x1F //运动检测阀值设置寄存器
|
||||
#define MPU6050_RA_MOT_DUR 0x20 //运动检测时间阀值
|
||||
#define MPU6050_RA_MOT_THR 0x1F // 运动检测阀值设置寄存器
|
||||
#define MPU6050_RA_MOT_DUR 0x20 // 运动检测时间阀值
|
||||
#define MPU6050_RA_ZRMOT_THR 0x21
|
||||
#define MPU6050_RA_ZRMOT_DUR 0x22
|
||||
#define MPU6050_RA_FIFO_EN 0x23
|
||||
#define MPU6050_RA_INT_PIN_CFG 0x37 //中断/旁路设置寄存器
|
||||
#define MPU6050_RA_INT_ENABLE 0x38 //中断使能寄存器
|
||||
#define MPU6050_RA_INT_PIN_CFG 0x37 // 中断/旁路设置寄存器
|
||||
#define MPU6050_RA_INT_ENABLE 0x38 // 中断使能寄存器
|
||||
#define MPU6050_RA_TEMP_OUT_H 0x41
|
||||
#define MPU6050_RA_USER_CTRL 0x6A
|
||||
#define MPU6050_RA_PWR_MGMT_1 0x6B
|
||||
|
||||
Executable → Regular
+92
-75
@@ -15,12 +15,27 @@
|
||||
|
||||
#include "e53_smart_covers.h"
|
||||
|
||||
#define SC_I2C0 0
|
||||
|
||||
|
||||
/* 传感器与CPU连接的I2C口 */
|
||||
#define SC_I2C0 0
|
||||
/* I2C通信频率 */
|
||||
#define I2C_RATE 400000
|
||||
static I2cBusIo m_sc_i2c0m2 = {
|
||||
.scl = {.gpio = GPIO0_PA1, .func = MUX_FUNC3, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
.sda = {.gpio = GPIO0_PA0, .func = MUX_FUNC3, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
.scl = {
|
||||
.gpio = GPIO0_PA1,
|
||||
.func = MUX_FUNC3,
|
||||
.type = PULL_NONE,
|
||||
.drv = DRIVE_KEEP,
|
||||
.dir = LZGPIO_DIR_KEEP,
|
||||
.val = LZGPIO_LEVEL_KEEP
|
||||
},
|
||||
.sda = {
|
||||
.gpio = GPIO0_PA0,
|
||||
.func = MUX_FUNC3,
|
||||
.type = PULL_NONE,
|
||||
.drv = DRIVE_KEEP,
|
||||
.dir = LZGPIO_DIR_KEEP,
|
||||
.val = LZGPIO_LEVEL_KEEP
|
||||
},
|
||||
.id = FUNC_ID_I2C0,
|
||||
.mode = FUNC_MODE_M2,
|
||||
};
|
||||
@@ -35,35 +50,31 @@ void e53_sc_io_init()
|
||||
{
|
||||
unsigned int ret = LZ_HARDWARE_SUCCESS;
|
||||
|
||||
/*led1 gpio init*/
|
||||
/* led1 gpio init */
|
||||
LzGpioInit(GPIO0_PA5);
|
||||
/*led2 gpio init*/
|
||||
LzGpioInit(GPIO1_PD0);
|
||||
|
||||
/*设置GPIO0_PA5为输出模式*/
|
||||
/* 设置GPIO0_PA5为输出模式 */
|
||||
ret = LzGpioSetDir(GPIO0_PA5, LZGPIO_DIR_OUT);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("set GPIO0_PA5 Direction fail ret:%d\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
/*设置GPIO1_PD0为输出模式*/
|
||||
/* 设置GPIO1_PD0为输出模式 */
|
||||
ret = LzGpioSetDir(GPIO1_PD0, LZGPIO_DIR_OUT);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("set GPIO1_PD0 Direction fail ret:%d\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
if (I2cIoInit(m_sc_i2c0m2) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (I2cIoInit(m_sc_i2c0m2) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("init I2C I2C0 io fail\n");
|
||||
return;
|
||||
}
|
||||
/*I2c时钟频率400K*/
|
||||
if (LzI2cInit(SC_I2C0, 400000) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
/* I2c时钟频率400K */
|
||||
if (LzI2cInit(SC_I2C0, I2C_RATE) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("init I2C I2C0 fail\n");
|
||||
return;
|
||||
}
|
||||
@@ -79,19 +90,18 @@ void e53_sc_io_init()
|
||||
***************************************************************/
|
||||
uint8_t MPU6050_Read_Buffer(uint8_t reg, uint8_t *p_buffer, uint16_t length)
|
||||
{
|
||||
|
||||
|
||||
uint32_t status = 0;
|
||||
uint8_t buffer[1] = {reg};
|
||||
|
||||
status = LzI2cWrite(SC_I2C0, MPU6050_SLAVE_ADDRESS, buffer, 1);
|
||||
if (status != 0)
|
||||
{
|
||||
status = LzI2cWrite(SC_I2C0, MPU6050_SLAVE_ADDRESS, buffer, sizeof(buffer));
|
||||
if (status != 0) {
|
||||
printf("Error: I2C write status:0x%x\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
LzI2cRead(SC_I2C0, MPU6050_SLAVE_ADDRESS, p_buffer, length);
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -105,7 +115,7 @@ void mpu6050_write_reg(uint8_t reg, uint8_t data)
|
||||
{
|
||||
uint8_t send_data[2] = {reg, data};
|
||||
|
||||
LzI2cWrite(SC_I2C0, MPU6050_SLAVE_ADDRESS, send_data, 2);
|
||||
LzI2cWrite(SC_I2C0, MPU6050_SLAVE_ADDRESS, send_data, sizeof(send_data));
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -129,11 +139,21 @@ void mpu6050_read_data(uint8_t reg, unsigned char *buf, uint8_t length)
|
||||
***************************************************************/
|
||||
void mpu6050_read_acc(short *acc_data)
|
||||
{
|
||||
/* 加速度数据位置定义 */
|
||||
#define REG_ACCEL_X_H 0
|
||||
#define REG_ACCEL_X_L 1
|
||||
#define REG_ACCEL_Y_H 2
|
||||
#define REG_ACCEL_Y_L 3
|
||||
#define REG_ACCEL_Z_H 4
|
||||
#define REG_ACCEL_Z_L 5
|
||||
/* 高8位移位 */
|
||||
#define HIGH_BYTE_SHIFT 8
|
||||
uint8_t buf[6];
|
||||
mpu6050_read_data(MPU6050_ACC_OUT, buf, 6);
|
||||
acc_data[0] = (buf[0] << 8) | buf[1];
|
||||
acc_data[1] = (buf[2] << 8) | buf[3];
|
||||
acc_data[2] = (buf[4] << 8) | buf[5];
|
||||
|
||||
mpu6050_read_data(MPU6050_ACC_OUT, buf, sizeof(buf));
|
||||
acc_data[EACCEL_X] = (buf[REG_ACCEL_X_H] << HIGH_BYTE_SHIFT) | buf[REG_ACCEL_X_L];
|
||||
acc_data[EACCEL_Y] = (buf[REG_ACCEL_Y_H] << HIGH_BYTE_SHIFT) | buf[REG_ACCEL_Y_L];
|
||||
acc_data[EACCEL_Z] = (buf[REG_ACCEL_Z_H] << HIGH_BYTE_SHIFT) | buf[REG_ACCEL_Z_L];
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -144,8 +164,8 @@ void mpu6050_read_acc(short *acc_data)
|
||||
***************************************************************/
|
||||
void action_interrupt()
|
||||
{
|
||||
mpu6050_write_reg(MPU6050_RA_MOT_THR,0x03);//运动阈值
|
||||
mpu6050_write_reg(MPU6050_RA_MOT_DUR,0x14);//检测时间20ms 单位1ms
|
||||
mpu6050_write_reg(MPU6050_RA_MOT_THR, 0x03); // 运动阈值
|
||||
mpu6050_write_reg(MPU6050_RA_MOT_DUR, 0x14); // 检测时间20ms 单位1ms
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -156,27 +176,27 @@ void action_interrupt()
|
||||
***************************************************************/
|
||||
void mpu6050_init()
|
||||
{
|
||||
#define DELAY_COUNT 1000000
|
||||
#define RESET_DELAY_MSEC 20 /* 复位等待设备重启完毕 */
|
||||
int i = 0, j = 0;
|
||||
/*在初始化之前要延时一段时间,若没有延时,则断电后再上电数据可能会出错*/
|
||||
for(i=0;i<1000;i++)
|
||||
{
|
||||
for(j=0;j<1000;j++)
|
||||
{
|
||||
|
||||
}
|
||||
/* 在初始化之前要延时一段时间,若没有延时,则断电后再上电数据可能会出错 */
|
||||
for (i = 0; i < DELAY_COUNT; i++) {
|
||||
/* 延时等待 */
|
||||
}
|
||||
mpu6050_write_reg(MPU6050_RA_PWR_MGMT_1, 0X80); //复位MPU6050
|
||||
usleep(20000);
|
||||
mpu6050_write_reg(MPU6050_RA_PWR_MGMT_1, 0X00); //唤醒MPU6050
|
||||
mpu6050_write_reg(MPU6050_RA_INT_ENABLE, 0X00); //关闭所有中断
|
||||
mpu6050_write_reg(MPU6050_RA_USER_CTRL, 0X00); //I2C主模式关闭
|
||||
mpu6050_write_reg(MPU6050_RA_FIFO_EN, 0X00); //关闭FIFO
|
||||
mpu6050_write_reg(MPU6050_RA_INT_PIN_CFG, 0X80); //中断的逻辑电平模式,设置为0,中断信号为高电;设置为1,中断信号为低电平时。
|
||||
action_interrupt(); //运动中断
|
||||
mpu6050_write_reg(MPU6050_RA_CONFIG, 0x04); //配置外部引脚采样和DLPF数字低通滤波器
|
||||
mpu6050_write_reg(MPU6050_RA_ACCEL_CONFIG, 0x1C);//加速度传感器量程和高通滤波器配置
|
||||
mpu6050_write_reg(MPU6050_RA_INT_PIN_CFG, 0X1C); //INT引脚低电平平时
|
||||
mpu6050_write_reg(MPU6050_RA_INT_ENABLE, 0x40); //中断使能寄存器
|
||||
|
||||
mpu6050_write_reg(MPU6050_RA_PWR_MGMT_1, 0X80); // 复位MPU6050
|
||||
LOS_Msleep(RESET_DELAY_MSEC);
|
||||
mpu6050_write_reg(MPU6050_RA_PWR_MGMT_1, 0X00); // 唤醒MPU6050
|
||||
mpu6050_write_reg(MPU6050_RA_INT_ENABLE, 0X00); // 关闭所有中断
|
||||
mpu6050_write_reg(MPU6050_RA_USER_CTRL, 0X00); // I2C主模式关闭
|
||||
mpu6050_write_reg(MPU6050_RA_FIFO_EN, 0X00); // 关闭FIFO
|
||||
mpu6050_write_reg(MPU6050_RA_INT_PIN_CFG, 0X80); // 中断的逻辑电平模式,设置为0,中断信号为高电;设置为1,中断信号为低电平时。
|
||||
action_interrupt(); // 运动中断
|
||||
mpu6050_write_reg(MPU6050_RA_CONFIG, 0x04); // 配置外部引脚采样和DLPF数字低通滤波器
|
||||
mpu6050_write_reg(MPU6050_RA_ACCEL_CONFIG, 0x1C);// 加速度传感器量程和高通滤波器配置
|
||||
mpu6050_write_reg(MPU6050_RA_INT_PIN_CFG, 0X1C); // INT引脚低电平平时
|
||||
mpu6050_write_reg(MPU6050_RA_INT_ENABLE, 0x40); // 中断使能寄存器
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -184,18 +204,16 @@ void mpu6050_init()
|
||||
* 输入参数: 无
|
||||
* 返 回 值: 无
|
||||
* 说 明: 无
|
||||
***************************************************************/
|
||||
***************************************************************/
|
||||
uint8_t mpu6050_read_id()
|
||||
{
|
||||
unsigned char buff = 0;
|
||||
|
||||
mpu6050_read_data(MPU6050_RA_WHO_AM_I, &buff, 1);
|
||||
if(buff != 0x68)
|
||||
{
|
||||
if (buff != MPU6050_SLAVE_ADDRESS) {
|
||||
printf("MPU6050 dectected error Re:%u\n", buff);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -208,9 +226,10 @@ uint8_t mpu6050_read_id()
|
||||
***************************************************************/
|
||||
void e53_sc_init()
|
||||
{
|
||||
#define WAIT_MPU6050_INIT_MSEC 1000
|
||||
e53_sc_io_init();
|
||||
mpu6050_init();
|
||||
usleep(1000000);
|
||||
LOS_Msleep(WAIT_MPU6050_INIT_MSEC);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -221,17 +240,21 @@ void e53_sc_init()
|
||||
***************************************************************/
|
||||
void e53_sc_read_data(e53_sc_data_t *p_data)
|
||||
{
|
||||
#define MPU6050_READ_DELAY_MSEC 50
|
||||
short accel[3];
|
||||
short temp;
|
||||
if (mpu6050_read_id() == 0)
|
||||
{
|
||||
while(1);
|
||||
int i;
|
||||
|
||||
/* 等待读取设备地址正常 */
|
||||
if (mpu6050_read_id() == 0) {
|
||||
while (1);
|
||||
}
|
||||
|
||||
mpu6050_read_acc(accel);
|
||||
p_data->accel[0] = accel[0];
|
||||
p_data->accel[1] = accel[1];
|
||||
p_data->accel[2] = accel[2];
|
||||
usleep(50000);
|
||||
p_data->accel[EACCEL_X] = accel[EACCEL_X];
|
||||
p_data->accel[EACCEL_Y] = accel[EACCEL_Y];
|
||||
p_data->accel[EACCEL_Z] = accel[EACCEL_Z];
|
||||
LOS_Msleep(MPU6050_READ_DELAY_MSEC);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -243,14 +266,11 @@ void e53_sc_read_data(e53_sc_data_t *p_data)
|
||||
***************************************************************/
|
||||
void led_d1_set(SWITCH_STATUS_ENUM status)
|
||||
{
|
||||
if(status == ON)
|
||||
{
|
||||
/*设置GPIO0_PA5输出低电平点亮灯*/
|
||||
if (status == ON) {
|
||||
/* 设置GPIO0_PA5输出低电平点亮灯 */
|
||||
LzGpioSetVal(GPIO0_PA5, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
else if(status == OFF)
|
||||
{
|
||||
/*设置GPIO0_PA5输出高电平关闭灯*/
|
||||
} else if (status == OFF) {
|
||||
/* 设置GPIO0_PA5输出高电平关闭灯 */
|
||||
LzGpioSetVal(GPIO0_PA5, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
}
|
||||
@@ -264,14 +284,11 @@ void led_d1_set(SWITCH_STATUS_ENUM status)
|
||||
***************************************************************/
|
||||
void led_d2_set(SWITCH_STATUS_ENUM status)
|
||||
{
|
||||
if(status == ON)
|
||||
{
|
||||
/*设置GPIO1_PD0输出低电平点亮灯*/
|
||||
if (status == ON) {
|
||||
/* 设置GPIO1_PD0输出低电平点亮灯 */
|
||||
LzGpioSetVal(GPIO1_PD0, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
else if(status == OFF)
|
||||
{
|
||||
/*设置GPIO1_PD0输出高电平关闭灯*/
|
||||
} else if (status == OFF) {
|
||||
/* 设置GPIO1_PD0输出高电平关闭灯 */
|
||||
LzGpioSetVal(GPIO1_PD0, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+19
-13
@@ -17,6 +17,17 @@
|
||||
#include "los_task.h"
|
||||
#include "e53_intelligent_street_lamp.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 2000
|
||||
|
||||
/* 光强度报警值 */
|
||||
#define LUMN_ALARM 20.0
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: e53_isl_thread
|
||||
* 说 明: E53智慧路灯线程
|
||||
@@ -29,24 +40,20 @@ void e53_isl_thread()
|
||||
|
||||
e53_isl_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
lum = e53_isl_read_data();
|
||||
|
||||
printf("luminance value is %.2f\n", lum);
|
||||
|
||||
if (lum < 20)
|
||||
{
|
||||
if (lum < LUMN_ALARM) {
|
||||
isl_light_set_status(ON);
|
||||
printf("light on\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
isl_light_set_status(OFF);
|
||||
printf("light off\n");
|
||||
}
|
||||
|
||||
LOS_Msleep(2000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,13 +70,12 @@ void e53_isl_example()
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)e53_isl_thread;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "e53_isl_thread";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create e53_isl_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create e53_isl_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+1
-2
@@ -17,8 +17,7 @@
|
||||
|
||||
#include "lz_hardware.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
OFF = 0,
|
||||
ON
|
||||
} SWITCH_STATUS_ENUM;
|
||||
|
||||
Executable → Regular
+22
-19
@@ -15,8 +15,13 @@
|
||||
|
||||
#include "e53_intelligent_street_lamp.h"
|
||||
|
||||
#define ISL_I2C0 0
|
||||
#define BH1750_ADDR 0x23
|
||||
/* i2c编号 */
|
||||
#define ISL_I2C0 0
|
||||
/* i2c通信速度 */
|
||||
#define I2C_RATE 400000
|
||||
|
||||
/* 从设备地址 */
|
||||
#define BH1750_ADDR 0x23
|
||||
|
||||
static I2cBusIo m_isl_i2c0m2 = {
|
||||
.scl = {.gpio = GPIO0_PA1, .func = MUX_FUNC3, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
@@ -25,6 +30,7 @@ static I2cBusIo m_isl_i2c0m2 = {
|
||||
.mode = FUNC_MODE_M2,
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: e53_isl_io_init
|
||||
* 说 明: E53_ISL初始化
|
||||
@@ -36,12 +42,10 @@ void e53_isl_io_init(void)
|
||||
LzGpioInit(GPIO0_PA5);
|
||||
LzGpioSetDir(GPIO0_PA5, LZGPIO_DIR_OUT);
|
||||
|
||||
if (I2cIoInit(m_isl_i2c0m2) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (I2cIoInit(m_isl_i2c0m2) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("init I2C I2C0 io failed\n");
|
||||
}
|
||||
if (LzI2cInit(ISL_I2C0, 400000) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (LzI2cInit(ISL_I2C0, I2C_RATE) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("init I2C I2C0 failed\n");
|
||||
}
|
||||
}
|
||||
@@ -57,7 +61,7 @@ void init_bh1750()
|
||||
uint8_t send_data[1] = {0x01};
|
||||
uint32_t send_len = 1;
|
||||
|
||||
LzI2cWrite(ISL_I2C0, BH1750_ADDR, send_data, send_len);
|
||||
LzI2cWrite(ISL_I2C0, BH1750_ADDR, send_data, send_len);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@@ -94,17 +98,18 @@ void e53_isl_init(void)
|
||||
***************************************************************/
|
||||
float e53_isl_read_data()
|
||||
{
|
||||
/* 等待从设备准备完毕 */
|
||||
#define WAIT_SLAVE_DEVICE_START_MSEC 180
|
||||
/* 读取光强度寄存器数值,计算出实际光强度数值 */
|
||||
#define CALC_LIGHT(data) ((float)((((data[0]) << 8) + (data[1])) / 1.2))
|
||||
float lum = 0;
|
||||
uint8_t recv_data[2] = {0};
|
||||
|
||||
start_bh1750();
|
||||
LOS_Msleep(180);
|
||||
LOS_Msleep(WAIT_SLAVE_DEVICE_START_MSEC);
|
||||
|
||||
uint8_t recv_data[2] = {0};
|
||||
uint32_t receive_len = 2;
|
||||
LzI2cRead(ISL_I2C0, BH1750_ADDR, recv_data, receive_len);
|
||||
lum = (float)(((recv_data[0]<<8) + recv_data[1])/1.2);
|
||||
|
||||
//printf("data %x %x\n", recv_data[0], recv_data[1]);
|
||||
LzI2cRead(ISL_I2C0, BH1750_ADDR, recv_data, sizeof(recv_data));
|
||||
lum = CALC_LIGHT(recv_data);
|
||||
|
||||
return lum;
|
||||
}
|
||||
@@ -112,20 +117,18 @@ float e53_isl_read_data()
|
||||
/***************************************************************
|
||||
* 函数名称: isl_light_set_status
|
||||
* 说 明: 紫光灯控制
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* OFF,关
|
||||
* ON,开
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void isl_light_set_status(SWITCH_STATUS_ENUM status)
|
||||
{
|
||||
if(status == ON)
|
||||
{
|
||||
if (status == ON) {
|
||||
/*设置GPIO0_PA5输出高电平点亮灯*/
|
||||
LzGpioSetVal(GPIO0_PA5, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
if(status == OFF)
|
||||
{
|
||||
if (status == OFF) {
|
||||
/*设置GPIO0_PA5输出低电平关闭灯*/
|
||||
LzGpioSetVal(GPIO0_PA5, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
|
||||
Executable → Regular
+51
-27
@@ -17,44 +17,70 @@
|
||||
#include "los_task.h"
|
||||
#include "e53_intelligent_vehicle_01.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 2000
|
||||
|
||||
/* PWM配置,周期时间,单位为纳秒 */
|
||||
#define PWM_CYCLE_NS 1000000
|
||||
/* PWM配置,高电平时间,单位为纳秒 */
|
||||
#define PWM_DUTY_NS 500000
|
||||
/* PWM配置,开启PWM */
|
||||
#define PWM_ON 1
|
||||
/* PWM配置,关闭PWM */
|
||||
#define PWM_OFF 0
|
||||
|
||||
/* LED配置,打开LED */
|
||||
#define LED_ON 1
|
||||
/* LED配置,关闭LED */
|
||||
#define LED_OFF 0
|
||||
|
||||
/* 最大报警距离 */
|
||||
#define DISTANCE_MAX_ALARM (20.0)
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_process
|
||||
* 说 明: 智慧农业例程
|
||||
* 参 数: 无
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_iv01_process(void *arg)
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
/* 每个周期为200usec,占空比为100usec */
|
||||
unsigned int duty_ns = 500000;
|
||||
unsigned int cycle_ns = 1000000;
|
||||
unsigned int duty_ns = PWM_DUTY_NS;
|
||||
unsigned int cycle_ns = PWM_CYCLE_NS;
|
||||
float distance_cm = 0.0;
|
||||
|
||||
|
||||
e53_iv01_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
printf("========== E53 IV Example ==========\n");
|
||||
|
||||
ret = e53_iv01_get_distance(&distance_cm);
|
||||
if (ret == 1)
|
||||
{
|
||||
if (ret == 1) {
|
||||
printf("distance cm: %f\n", distance_cm);
|
||||
|
||||
if (distance_cm <= 20.0)
|
||||
{
|
||||
e53_iv01_buzzer_set(1, duty_ns, cycle_ns);
|
||||
e53_iv01_led_warning_set(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
e53_iv01_buzzer_set(0, duty_ns, cycle_ns);
|
||||
e53_iv01_led_warning_set(0);
|
||||
|
||||
if (distance_cm <= DISTANCE_MAX_ALARM) {
|
||||
e53_iv01_buzzer_set(PWM_ON, duty_ns, cycle_ns);
|
||||
e53_iv01_led_warning_set(LED_ON);
|
||||
} else {
|
||||
e53_iv01_buzzer_set(PWM_OFF, duty_ns, cycle_ns);
|
||||
e53_iv01_led_warning_set(LED_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
LOS_Msleep(2000);
|
||||
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_example
|
||||
* 说 明: 智慧农业例程
|
||||
* 说 明: 智慧农业开机启动任务
|
||||
* 参 数: 无
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -65,17 +91,15 @@ void e53_iv01_example()
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)e53_iv01_process;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "e53_iv01_process";
|
||||
task.usTaskPrio = 25;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create e53_ia_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create e53_ia_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
APP_FEATURE_INIT(e53_iv01_example);
|
||||
|
||||
|
||||
Executable → Regular
+3
-3
@@ -36,7 +36,7 @@ void e53_iv01_deinit();
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_get_distance
|
||||
* 说 明: 智慧车载发起1次超声波测距
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @distance_meter:测距的距离,单位为厘米
|
||||
* 返 回 值: 返回1为成功,0为失败
|
||||
***************************************************************/
|
||||
@@ -46,7 +46,7 @@ unsigned int e53_iv01_get_distance(float *distance_cm);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_led_warning_set
|
||||
* 说 明: 智慧车载的Led灯控制
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:Led灯控制,0为灭,1为亮
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -56,7 +56,7 @@ void e53_iv01_led_warning_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_buzzer_set
|
||||
* 说 明: 智慧车载的PWM控制
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:PWM控制,0为关闭,1为开启
|
||||
* @duty_ns:高电平的占比,以nsec为单位
|
||||
* @cycle_ns:PWM周期,以nsec为单位
|
||||
|
||||
Executable → Regular
+48
-62
@@ -29,22 +29,19 @@
|
||||
/* 系统时钟定时器主频40MHz,定时器5作为系统时钟源,每秒24MHz,从0一直累加 */
|
||||
#define ECHO_TIMER_FREQ 40000000UL
|
||||
/* 定义每次中断对应的采集动作 */
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
EECHO_FLAG_CAPTURE_RISE = 0, /* 准备采集上升沿,即开始时间 */
|
||||
EECHO_FLAG_CAPTURE_FALL, /* 准备采集下降沿,即结束时间 */
|
||||
EECHO_FLAG_CAPTURE_SUCCESS, /* 采集成功 */
|
||||
EECHO_FLAG_MAX
|
||||
} echo_flag_e;
|
||||
/* 定义与中断相关的采集动作和采集时间相关信息 */
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
echo_flag_e flag; /* 中断采集动作 */
|
||||
uint32_t time_rise; /* 采集上升沿,即开始时间 */
|
||||
uint32_t time_fall; /* 采集下降沿,即结束时间 */
|
||||
} e53_iv01_echo_info_s;
|
||||
static e53_iv01_echo_info_s m_echo_info =
|
||||
{
|
||||
static e53_iv01_echo_info_s m_echo_info = {
|
||||
.flag = EECHO_FLAG_CAPTURE_RISE,
|
||||
.time_rise = 0,
|
||||
.time_fall = 0,
|
||||
@@ -54,7 +51,8 @@ static UINT32 m_task_sem;
|
||||
/* 定义轮询任务id */
|
||||
static UINT32 m_task_id = 0;
|
||||
/* 定时器5的CURRENT_VALUE_LOW的基地址 */
|
||||
static uint32_t *m_ptimer5_current_value_low = (uint32_t *)(0x400000A0U + 0x8U);
|
||||
#define TIMER5_ADDRESS (0x400000A0U + 0x8U)
|
||||
static uint32_t *m_ptimer5_current_value_low = (uint32_t *)(TIMER5_ADDRESS);
|
||||
|
||||
/* Trig引脚电平设置 */
|
||||
#define E53_IV01_TRIG_Set() LzGpioSetVal(E53_IV01_TRIG_GPIO, LZGPIO_LEVEL_HIGH)
|
||||
@@ -65,9 +63,8 @@ static uint32_t *m_ptimer5_current_value_low = (uint32_t *)(0x400000A0U + 0x8U);
|
||||
#define E53_IV01_LED_WARNING_Clr() LzGpioSetVal(E53_IV01_LED_WARNING_GPIO, LZGPIO_LEVEL_LOW)
|
||||
|
||||
/* Buzzer定义 */
|
||||
#define E53_IV01_PWM_IO 7
|
||||
static PwmBusIo m_buzzer_config =
|
||||
{
|
||||
#define E53_IV01_PWM_IO 7
|
||||
static PwmBusIo m_buzzer_config = {
|
||||
.pwm = {.gpio = E53_IV01_BUZZER_GPIO, .func = MUX_FUNC2, .type = PULL_DOWN, .drv = DRIVE_KEEP, .dir = LZGPIO_DIR_KEEP, .val = LZGPIO_LEVEL_KEEP},
|
||||
.id = FUNC_ID_PWM7,
|
||||
.mode = FUNC_MODE_NONE,
|
||||
@@ -78,7 +75,7 @@ static PwmBusIo m_buzzer_config =
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_delay_usec
|
||||
* 说 明: 延时函数
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @usec,延时时间,以usec为单位
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -90,7 +87,7 @@ static inline void e53_iv01_delay_usec(uint32_t usec)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_calc_cm
|
||||
* 说 明: 计算超声波测距
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @time:节拍数
|
||||
* @freq:节拍频率,以Hz为单位
|
||||
* @meter:距离差,以厘米为单位
|
||||
@@ -98,11 +95,14 @@ static inline void e53_iv01_delay_usec(uint32_t usec)
|
||||
***************************************************************/
|
||||
static inline void e53_iv01_calc_cm(uint32_t time, uint32_t freq, float *cmeter)
|
||||
{
|
||||
#define SOUND_SPEED 340.0 /* 声音速度 */
|
||||
#define M_TO_CM 100.0 /* 长度单位米转化为厘米 */
|
||||
#define BACK_AND_FORTH 2.0 /* 来回2次 */
|
||||
float f_time = (float)time;
|
||||
float f_freq = (float)freq;
|
||||
|
||||
|
||||
/* 距离 = 时间差 * 340米/秒 / 2(超时波来回2次) * 100厘米/米 */
|
||||
*cmeter = f_time / f_freq * 170.0 * 100.0;
|
||||
*cmeter = f_time / f_freq * SOUND_SPEED * M_TO_CM / BACK_AND_FORTH;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,25 +115,21 @@ static inline void e53_iv01_calc_cm(uint32_t time, uint32_t freq, float *cmeter)
|
||||
static VOID e53_iv01_task_echo_func(VOID *arg)
|
||||
{
|
||||
uint8_t value = 0;
|
||||
|
||||
|
||||
m_echo_info.flag = EECHO_FLAG_CAPTURE_RISE;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
LzGpioGetVal(E53_IV01_ECHO0_GPIO, &value);
|
||||
if (value == LZGPIO_LEVEL_HIGH)
|
||||
{
|
||||
if (value == LZGPIO_LEVEL_HIGH) {
|
||||
m_echo_info.time_rise = *m_ptimer5_current_value_low;
|
||||
m_echo_info.flag = EECHO_FLAG_CAPTURE_FALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
LzGpioGetVal(E53_IV01_ECHO0_GPIO, &value);
|
||||
if (value == LZGPIO_LEVEL_LOW)
|
||||
{
|
||||
if (value == LZGPIO_LEVEL_LOW) {
|
||||
m_echo_info.time_fall = *m_ptimer5_current_value_low;
|
||||
m_echo_info.flag = EECHO_FLAG_CAPTURE_SUCCESS;
|
||||
break;
|
||||
@@ -155,7 +151,7 @@ static void e53_iv01_task_create_echo()
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
TSK_INIT_PARAM_S task;
|
||||
|
||||
|
||||
/* 锁任务调度 */
|
||||
LOS_TaskLock();
|
||||
|
||||
@@ -166,8 +162,7 @@ static void e53_iv01_task_create_echo()
|
||||
/* 优先级比当前线程低 */
|
||||
task.usTaskPrio = 30;
|
||||
ret = LOS_TaskCreate(&m_task_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
if (ret != LOS_OK) {
|
||||
printf("%s, %d: LOS_TaskCreate failed(%d)\n", __func__, __LINE__, ret);
|
||||
/* 解锁任务调度 */
|
||||
LOS_TaskUnlock();
|
||||
@@ -223,7 +218,7 @@ static void e53_iv01_init_gpio()
|
||||
LzGpioInit(E53_IV01_TRIG_GPIO);
|
||||
LzGpioSetDir(E53_IV01_TRIG_GPIO, LZGPIO_DIR_OUT);
|
||||
E53_IV01_TRIG_Clr();
|
||||
|
||||
|
||||
/* LED_WARNING灯引脚设置为GPIO输出模式 */
|
||||
PinctrlSet(E53_IV01_LED_WARNING_GPIO, MUX_FUNC0, PULL_KEEP, DRIVE_KEEP);
|
||||
LzGpioInit(E53_IV01_LED_WARNING_GPIO);
|
||||
@@ -254,7 +249,7 @@ static unsigned int e53_iv01_init_pwm()
|
||||
PinctrlSet(E53_IV01_BUZZER_GPIO, MUX_FUNC2, PULL_DOWN, DRIVE_KEEP);
|
||||
PwmIoInit(m_buzzer_config);
|
||||
LzPwmInit(E53_IV01_PWM_IO);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -278,10 +273,10 @@ static void e53_iv01_deinit_pwm()
|
||||
static void e53_iv01_init_interrupt()
|
||||
{
|
||||
//LzI2cInit(0, 400000);
|
||||
|
||||
|
||||
/* 创建信号量 */
|
||||
LOS_SemCreate(0, &m_task_sem);
|
||||
|
||||
|
||||
/* Echo引脚设置为GPIO输入模式 */
|
||||
PinctrlSet(E53_IV01_ECHO0_GPIO, MUX_FUNC0, PULL_KEEP, DRIVE_KEEP);
|
||||
LzGpioInit(E53_IV01_ECHO0_GPIO);
|
||||
@@ -310,17 +305,16 @@ static void e53_iv01_deinit_interrupt()
|
||||
unsigned int e53_iv01_init()
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
|
||||
|
||||
e53_iv01_init_gpio();
|
||||
|
||||
|
||||
ret = e53_iv01_init_pwm();
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("%s, %s, %d: e53_iv01_init_pwm failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
e53_iv01_deinit_gpio();
|
||||
return __LINE__;
|
||||
}
|
||||
|
||||
|
||||
e53_iv01_init_interrupt();
|
||||
return 0;
|
||||
}
|
||||
@@ -341,37 +335,37 @@ void e53_iv01_deinit()
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_get_distance
|
||||
* 说 明: E53_IntelligentVehicle01发起1次超声波测距
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @distance_meter:测距的距离,单位为厘米
|
||||
* 返 回 值: 返回1为成功,0为失败
|
||||
***************************************************************/
|
||||
unsigned int e53_iv01_get_distance(float *distance_cm)
|
||||
{
|
||||
/* 多久时间测量完毕 */
|
||||
#define MAX_TEST_TIM_MSEC 200
|
||||
/* 定时器5最大数值 */
|
||||
#define TIMER5_MAX_VALUE (0xFFFFFFFF)
|
||||
|
||||
uint32_t time_diff = 0;
|
||||
|
||||
e53_iv01_task_create_echo();
|
||||
/* 发送10Usec的高电平 */
|
||||
e53_iv01_send_trig();
|
||||
/* 等待200msec,整个测距最长为66msec */
|
||||
LOS_SemPend(m_task_sem, LOS_MS2Tick(200));
|
||||
LOS_SemPend(m_task_sem, LOS_MS2Tick(MAX_TEST_TIM_MSEC));
|
||||
e53_iv01_task_delete_echo();
|
||||
|
||||
if (m_echo_info.flag == EECHO_FLAG_CAPTURE_SUCCESS)
|
||||
{/* 如果是采集成功,则计算距离 */
|
||||
if (m_echo_info.time_rise <= m_echo_info.time_fall)
|
||||
{
|
||||
if (m_echo_info.flag == EECHO_FLAG_CAPTURE_SUCCESS) {
|
||||
/* 如果是采集成功,则计算距离 */
|
||||
if (m_echo_info.time_rise <= m_echo_info.time_fall) {
|
||||
time_diff = m_echo_info.time_fall - m_echo_info.time_rise;
|
||||
}
|
||||
else
|
||||
{
|
||||
time_diff = 0xFFFFFFFF - m_echo_info.time_rise + m_echo_info.time_fall + 1;
|
||||
} else {
|
||||
time_diff = TIMER5_MAX_VALUE - m_echo_info.time_rise + m_echo_info.time_fall + 1;
|
||||
}
|
||||
|
||||
e53_iv01_calc_cm(time_diff, ECHO_TIMER_FREQ, distance_cm);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("%s, %d: flag(%d) is error!\n", __func__, __LINE__, m_echo_info.flag);
|
||||
return 0;
|
||||
}
|
||||
@@ -380,19 +374,16 @@ unsigned int e53_iv01_get_distance(float *distance_cm)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_led_warning_set
|
||||
* 说 明: E53_IntelligentVehicle01的Led灯控制
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:Led灯控制,0为灭,1为亮
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_iv01_led_warning_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
/* LED Warning灯低电平有效 */
|
||||
E53_IV01_LED_WARNING_Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
E53_IV01_LED_WARNING_Clr();
|
||||
}
|
||||
}
|
||||
@@ -400,7 +391,7 @@ void e53_iv01_led_warning_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_iv01_buzzer_set
|
||||
* 说 明: 智慧车载的PWM控制
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:PWM控制,0为关闭,1为开启
|
||||
* @duty_ns:高电平的占比,以nsec为单位
|
||||
* @cycle_ns:PWM周期,以nsec为单位
|
||||
@@ -408,17 +399,12 @@ void e53_iv01_led_warning_set(unsigned char is_on)
|
||||
***************************************************************/
|
||||
void e53_iv01_buzzer_set(unsigned char is_on, unsigned int duty_ns, unsigned int cycle_ns)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
/* 关闭蜂鸣器 */
|
||||
LzPwmStop(E53_IV01_PWM_IO);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* 打开蜂鸣器 */
|
||||
LzPwmStart(E53_IV01_PWM_IO, duty_ns, cycle_ns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+21
-15
@@ -17,6 +17,15 @@
|
||||
#include "los_task.h"
|
||||
#include "e53_body_induction.h"
|
||||
|
||||
/* 任务的堆栈大小 */
|
||||
#define TASK_STACK_SIZE 20480
|
||||
/* 任务的优先级 */
|
||||
#define TASK_PRIO 24
|
||||
|
||||
/* 循环等待时间 */
|
||||
#define WAIT_MSEC 1000
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* 函数名称: e53_bi_thread
|
||||
* 说 明: 人体感应模块线程
|
||||
@@ -30,26 +39,24 @@ void e53_bi_thread()
|
||||
|
||||
e53_bi_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
ret = LzGpioGetVal(GPIO0_PA5, &val);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("get gpio value failed ret:%d\n", ret);
|
||||
}
|
||||
if (val_last != val)
|
||||
{
|
||||
if (val == LZGPIO_LEVEL_HIGH)
|
||||
{
|
||||
|
||||
if (val_last != val) {
|
||||
if (val == LZGPIO_LEVEL_HIGH) {
|
||||
buzzer_set_status(ON);
|
||||
printf("buzzer on\n");
|
||||
LOS_Msleep(1000);
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
buzzer_set_status(OFF);
|
||||
printf("buzzer off\n");
|
||||
}
|
||||
val_last = val;
|
||||
}
|
||||
LOS_Msleep(1000);
|
||||
|
||||
LOS_Msleep(WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,13 +73,12 @@ void e53_bi_example()
|
||||
TSK_INIT_PARAM_S task = {0};
|
||||
|
||||
task.pfnTaskEntry = (TSK_ENTRY_FUNC)e53_bi_thread;
|
||||
task.uwStackSize = 10240;
|
||||
task.uwStackSize = TASK_STACK_SIZE;
|
||||
task.pcName = "e53_bi_thread";
|
||||
task.usTaskPrio = 24;
|
||||
task.usTaskPrio = TASK_PRIO;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create e53_bi_thread ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create e53_bi_thread ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+1
-2
@@ -18,8 +18,7 @@
|
||||
|
||||
#include "lz_hardware.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
OFF = 0,
|
||||
ON
|
||||
} SWITCH_STATUS_ENUM;
|
||||
|
||||
Executable → Regular
+11
-26
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "e53_body_induction.h"
|
||||
|
||||
#define BI_I2C0 0
|
||||
#define BI_I2C0 0
|
||||
#define BI_PWM7 7
|
||||
|
||||
static I2cBusIo m_bi_i2c0m2 = {
|
||||
@@ -40,31 +40,15 @@ static PwmBusIo m_buzzer = {
|
||||
void e53_bi_init()
|
||||
{
|
||||
uint32_t ret = LZ_HARDWARE_SUCCESS;
|
||||
#if 0
|
||||
/*初始化I2C*/
|
||||
ret = I2cIoInit(m_bi_i2c0m2);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
printf("init I2C I2C0 io fail ret:%d\n", ret);
|
||||
return;
|
||||
}
|
||||
ret = LzI2cInit(BI_I2C0, 400000);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
printf("init I2C I2C0 fail ret:%d\n", ret);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = PwmIoInit(m_buzzer);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("PwmIoInit failed ret:%d\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = LzPwmInit(BI_PWM7);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("LzPwmInit 7 failed ret:%d\n", ret);
|
||||
return;
|
||||
}
|
||||
@@ -86,13 +70,14 @@ void e53_bi_init()
|
||||
***************************************************************/
|
||||
void buzzer_set_status(SWITCH_STATUS_ENUM status)
|
||||
{
|
||||
if(status == ON)
|
||||
{
|
||||
LzPwmStart(BI_PWM7, 500000, 1000000);
|
||||
}
|
||||
if(status == OFF)
|
||||
{
|
||||
#define PWM_DUTY_NS 500000 /* PWM配置,高电平占用时间,单位为纳秒 */
|
||||
#define PWM_CYCLE_NS 1000000 /* PWM配置,整个周期占用时间,单位为纳秒 */
|
||||
if (status == ON) {
|
||||
LzPwmStart(BI_PWM7, PWM_DUTY_NS, PWM_CYCLE_NS);
|
||||
} else if (status == OFF) {
|
||||
LzPwmStop(BI_PWM7);
|
||||
} else {
|
||||
printf("status(%d) is error!\n", status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+17
-31
@@ -21,52 +21,41 @@ void e53_gs_process(void *arg)
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
unsigned short flag = 0;
|
||||
|
||||
|
||||
e53_gs_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
ret = e53_gs_get_gesture_state(&flag);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("Get Gesture Statu: 0x%x\n", flag);
|
||||
if (flag & GES_UP)
|
||||
{
|
||||
if (flag & GES_UP) {
|
||||
printf("\tUp\n");
|
||||
}
|
||||
if (flag & GES_DOWM)
|
||||
{
|
||||
if (flag & GES_DOWM) {
|
||||
printf("\tDown\n");
|
||||
}
|
||||
if (flag & GES_LEFT)
|
||||
{
|
||||
if (flag & GES_LEFT) {
|
||||
printf("\tLeft\n");
|
||||
}
|
||||
if (flag & GES_RIGHT)
|
||||
{
|
||||
if (flag & GES_RIGHT) {
|
||||
printf("\tRight\n");
|
||||
}
|
||||
if (flag & GES_FORWARD)
|
||||
{
|
||||
if (flag & GES_FORWARD) {
|
||||
printf("\tForward\n");
|
||||
}
|
||||
if (flag & GES_BACKWARD)
|
||||
{
|
||||
if (flag & GES_BACKWARD) {
|
||||
printf("\tBackward\n");
|
||||
}
|
||||
if (flag & GES_CLOCKWISE)
|
||||
{
|
||||
if (flag & GES_CLOCKWISE) {
|
||||
printf("\tClockwise\n");
|
||||
}
|
||||
if (flag & GES_COUNT_CLOCKWISE)
|
||||
{
|
||||
if (flag & GES_COUNT_CLOCKWISE) {
|
||||
printf("\tCount Clockwise\n");
|
||||
}
|
||||
if (flag & GES_WAVE)
|
||||
{
|
||||
if (flag & GES_WAVE) {
|
||||
printf("\tWave\n");
|
||||
}
|
||||
|
||||
|
||||
e53_gs_led_up_set((flag & GES_UP) ? (1) : (0));
|
||||
e53_gs_led_down_set((flag & GES_DOWM) ? (1) : (0));
|
||||
e53_gs_led_left_set((flag & GES_LEFT) ? (1) : (0));
|
||||
@@ -76,9 +65,7 @@ void e53_gs_process(void *arg)
|
||||
e53_gs_led_cw_set((flag & GES_CLOCKWISE) ? (1) : (0));
|
||||
e53_gs_led_ccw_set((flag & GES_COUNT_CLOCKWISE) ? (1) : (0));
|
||||
e53_gs_led_wave_set((flag & GES_WAVE) ? (1) : (0));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* 如果没有数据,则多等待 */
|
||||
LOS_Msleep(100);
|
||||
}
|
||||
@@ -96,9 +83,8 @@ void e53_gs_example()
|
||||
task.pcName = "e53 getsture sensor process";
|
||||
task.usTaskPrio = 24;
|
||||
ret = LOS_TaskCreate(&thread_id, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
printf("Failed to create Task_One ret:0x%x\n", ret);
|
||||
if (ret != LOS_OK) {
|
||||
printf("Falied to create Task_One ret:0x%x\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+10
-10
@@ -37,7 +37,7 @@ unsigned int e53_gs_init();
|
||||
/***************************************************************
|
||||
* 函数名称: gs_led_up_set
|
||||
* 说 明: 手势感应模块向上LED设置
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -46,7 +46,7 @@ void e53_gs_led_up_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_down_set
|
||||
* 说 明: 手势感应模块向下LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -55,7 +55,7 @@ void e53_gs_led_down_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_left_set
|
||||
* 说 明: 手势感应模块向左LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -64,7 +64,7 @@ void e53_gs_led_left_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_right_set
|
||||
* 说 明: 手势感应模块向右LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -73,7 +73,7 @@ void e53_gs_led_right_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_forward_set
|
||||
* 说 明: 手势感应模块向前LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -82,7 +82,7 @@ void e53_gs_led_forward_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: gesture_sensor_led_backward_set
|
||||
* 说 明: 手势感应模块向后LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -91,7 +91,7 @@ void e53_gs_led_backward_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_cw_set
|
||||
* 说 明: 手势感应模块顺时针转圈LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -100,7 +100,7 @@ void e53_gs_led_cw_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_ccw_set
|
||||
* 说 明: 手势感应模块逆时针转圈LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -109,7 +109,7 @@ void e53_gs_led_ccw_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_wave_set
|
||||
* 说 明: 手势感应模块挥手LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -118,7 +118,7 @@ void e53_gs_led_wave_set(unsigned char is_on);
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_get_gesture_state
|
||||
* 说 明: 获取手势感应模块手势
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @flag:获取当前手势
|
||||
* 返 回 值: 1为成功,0为失败
|
||||
***************************************************************/
|
||||
|
||||
Executable → Regular
+184
-229
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "los_sem.h"
|
||||
#include "lz_hardware.h"
|
||||
|
||||
@@ -44,7 +44,7 @@ static unsigned int m_i2c_freq = 400000;
|
||||
typedef enum {
|
||||
BANK0 = 0, /* Bank0寄存器 */
|
||||
BANK1, /* Bank1寄存器 */
|
||||
}BankId;
|
||||
} BankId;
|
||||
|
||||
/* BANK的寄存器地址和BANK0~1 */
|
||||
#define PAJ_REG_BANK_SEL 0xEF //BANK选择寄存器
|
||||
@@ -69,9 +69,9 @@ typedef enum {
|
||||
/* BANK1 寄存器组 */
|
||||
#define PAJ_REG_SET_PS_GAIN 0x44 //设置检测增益大小 (0:1x gain 1:2x gain)
|
||||
#define PAJ_REG_SET_IDLE_S1_STEP_0 0x67 //设置S1的响应因子
|
||||
#define PAJ_REG_SET_IDLE_S1_STEP_1 0x68
|
||||
#define PAJ_REG_SET_IDLE_S1_STEP_1 0x68
|
||||
#define PAJ_REG_SET_IDLE_S2_STEP_0 0x69 //设置S2的响应因子
|
||||
#define PAJ_REG_SET_IDLE_S2_STEP_1 0x6A
|
||||
#define PAJ_REG_SET_IDLE_S2_STEP_1 0x6A
|
||||
#define PAJ_REG_SET_OP_TO_S1_STEP_0 0x6B //设置OP到S1的过度时间
|
||||
#define PAJ_REG_SET_OP_TO_S1_STEP_1 0x6C
|
||||
#define PAJ_REG_SET_S1_TO_S2_STEP_0 0x6D //设置S1到S2的过度时间
|
||||
@@ -79,121 +79,121 @@ typedef enum {
|
||||
#define PAJ_REG_OPERATION_ENABLE 0x72 //设置PAJ7620U2使能寄存器
|
||||
|
||||
static uint8_t m_Paj7620u2_InitRegisterConfig[][2] = {
|
||||
{0xEF,0x00}, //切换bank0
|
||||
{0x37,0x07}, //
|
||||
{0x38,0x17},
|
||||
{0x39,0x06},
|
||||
{0x41,0x00},
|
||||
{0x42,0x00},
|
||||
{0x46,0x2D},
|
||||
{0x47,0x0F},
|
||||
{0x48,0x3C},
|
||||
{0x49,0x00},
|
||||
{0x4A,0x1E},
|
||||
{0x4C,0x20},
|
||||
{0x51,0x10},
|
||||
{0x5E,0x10},
|
||||
{0x60,0x27},
|
||||
{0x80,0x42},
|
||||
{0x81,0x44},
|
||||
{0x82,0x04},
|
||||
{0x8B,0x01},
|
||||
{0x90,0x06},
|
||||
{0x95,0x0A},
|
||||
{0x96,0x0C},
|
||||
{0x97,0x05},
|
||||
{0x9A,0x14},
|
||||
{0x9C,0x3F},
|
||||
{0xA5,0x19},
|
||||
{0xCC,0x19},
|
||||
{0xCD,0x0B},
|
||||
{0xCE,0x13},
|
||||
{0xCF,0x64},
|
||||
{0xD0,0x21},
|
||||
{0xEF,0x01},
|
||||
{0x02,0x0F},
|
||||
{0x03,0x10},
|
||||
{0x04,0x02},
|
||||
{0x25,0x01},
|
||||
{0x27,0x39},
|
||||
{0x28,0x7F},
|
||||
{0x29,0x08},
|
||||
{0x3E,0xFF},
|
||||
{0x5E,0x3D},
|
||||
{0x65,0x96},
|
||||
{0x67,0x97},
|
||||
{0x69,0xCD},
|
||||
{0x6A,0x01},
|
||||
{0x6D,0x2C},
|
||||
{0x6E,0x01},
|
||||
{0x72,0x01},
|
||||
{0x73,0x35},
|
||||
{0x74,0x00},
|
||||
{0x77,0x01},
|
||||
{0xEF, 0x00}, //切换bank0
|
||||
{0x37, 0x07}, //
|
||||
{0x38, 0x17},
|
||||
{0x39, 0x06},
|
||||
{0x41, 0x00},
|
||||
{0x42, 0x00},
|
||||
{0x46, 0x2D},
|
||||
{0x47, 0x0F},
|
||||
{0x48, 0x3C},
|
||||
{0x49, 0x00},
|
||||
{0x4A, 0x1E},
|
||||
{0x4C, 0x20},
|
||||
{0x51, 0x10},
|
||||
{0x5E, 0x10},
|
||||
{0x60, 0x27},
|
||||
{0x80, 0x42},
|
||||
{0x81, 0x44},
|
||||
{0x82, 0x04},
|
||||
{0x8B, 0x01},
|
||||
{0x90, 0x06},
|
||||
{0x95, 0x0A},
|
||||
{0x96, 0x0C},
|
||||
{0x97, 0x05},
|
||||
{0x9A, 0x14},
|
||||
{0x9C, 0x3F},
|
||||
{0xA5, 0x19},
|
||||
{0xCC, 0x19},
|
||||
{0xCD, 0x0B},
|
||||
{0xCE, 0x13},
|
||||
{0xCF, 0x64},
|
||||
{0xD0, 0x21},
|
||||
{0xEF, 0x01},
|
||||
{0x02, 0x0F},
|
||||
{0x03, 0x10},
|
||||
{0x04, 0x02},
|
||||
{0x25, 0x01},
|
||||
{0x27, 0x39},
|
||||
{0x28, 0x7F},
|
||||
{0x29, 0x08},
|
||||
{0x3E, 0xFF},
|
||||
{0x5E, 0x3D},
|
||||
{0x65, 0x96},
|
||||
{0x67, 0x97},
|
||||
{0x69, 0xCD},
|
||||
{0x6A, 0x01},
|
||||
{0x6D, 0x2C},
|
||||
{0x6E, 0x01},
|
||||
{0x72, 0x01},
|
||||
{0x73, 0x35},
|
||||
{0x74, 0x00},
|
||||
{0x77, 0x01},
|
||||
};
|
||||
|
||||
static uint8_t m_Paj7620u2_SetPSModeConfig[][2] = {
|
||||
{0xEF,0x00},
|
||||
{0x41,0x00},
|
||||
{0x42,0x02},
|
||||
{0x48,0x20},
|
||||
{0x49,0x00},
|
||||
{0x51,0x13},
|
||||
{0x83,0x00},
|
||||
{0x9F,0xF8},
|
||||
{0x69,0x96},
|
||||
{0x6A,0x02},
|
||||
{0xEF,0x01},
|
||||
{0x01,0x1E},
|
||||
{0x02,0x0F},
|
||||
{0x03,0x10},
|
||||
{0x04,0x02},
|
||||
{0x41,0x50},
|
||||
{0x43,0x34},
|
||||
{0x65,0xCE},
|
||||
{0x66,0x0B},
|
||||
{0x67,0xCE},
|
||||
{0x68,0x0B},
|
||||
{0x69,0xE9},
|
||||
{0x6A,0x05},
|
||||
{0x6B,0x50},
|
||||
{0x6C,0xC3},
|
||||
{0x6D,0x50},
|
||||
{0x6E,0xC3},
|
||||
{0x74,0x05},
|
||||
{0xEF, 0x00},
|
||||
{0x41, 0x00},
|
||||
{0x42, 0x02},
|
||||
{0x48, 0x20},
|
||||
{0x49, 0x00},
|
||||
{0x51, 0x13},
|
||||
{0x83, 0x00},
|
||||
{0x9F, 0xF8},
|
||||
{0x69, 0x96},
|
||||
{0x6A, 0x02},
|
||||
{0xEF, 0x01},
|
||||
{0x01, 0x1E},
|
||||
{0x02, 0x0F},
|
||||
{0x03, 0x10},
|
||||
{0x04, 0x02},
|
||||
{0x41, 0x50},
|
||||
{0x43, 0x34},
|
||||
{0x65, 0xCE},
|
||||
{0x66, 0x0B},
|
||||
{0x67, 0xCE},
|
||||
{0x68, 0x0B},
|
||||
{0x69, 0xE9},
|
||||
{0x6A, 0x05},
|
||||
{0x6B, 0x50},
|
||||
{0x6C, 0xC3},
|
||||
{0x6D, 0x50},
|
||||
{0x6E, 0xC3},
|
||||
{0x74, 0x05},
|
||||
};
|
||||
|
||||
static uint8_t m_Paj7620u2_SetGestureModeConfig[][2] = {
|
||||
{0xEF,0x00},
|
||||
{0x41,0x00},
|
||||
{0x42,0x00},
|
||||
{0xEF,0x00},
|
||||
{0x48,0x3C},
|
||||
{0x49,0x00},
|
||||
{0x51,0x10},
|
||||
{0x83,0x20},
|
||||
{0x9F,0xF9},
|
||||
{0xEF,0x01},
|
||||
{0x01,0x1E},
|
||||
{0x02,0x0F},
|
||||
{0x03,0x10},
|
||||
{0x04,0x02},
|
||||
{0x41,0x40},
|
||||
{0x43,0x30},
|
||||
{0x65,0x96},
|
||||
{0x66,0x00},
|
||||
{0x67,0x97},
|
||||
{0x68,0x01},
|
||||
{0x69,0xCD},
|
||||
{0x6A,0x01},
|
||||
{0x6B,0xB0},
|
||||
{0x6C,0x04},
|
||||
{0x6D,0x2C},
|
||||
{0x6E,0x01},
|
||||
{0x74,0x00},
|
||||
{0xEF,0x00},
|
||||
{0x41,0xFF},
|
||||
{0x42,0x01},
|
||||
{0xEF, 0x00},
|
||||
{0x41, 0x00},
|
||||
{0x42, 0x00},
|
||||
{0xEF, 0x00},
|
||||
{0x48, 0x3C},
|
||||
{0x49, 0x00},
|
||||
{0x51, 0x10},
|
||||
{0x83, 0x20},
|
||||
{0x9F, 0xF9},
|
||||
{0xEF, 0x01},
|
||||
{0x01, 0x1E},
|
||||
{0x02, 0x0F},
|
||||
{0x03, 0x10},
|
||||
{0x04, 0x02},
|
||||
{0x41, 0x40},
|
||||
{0x43, 0x30},
|
||||
{0x65, 0x96},
|
||||
{0x66, 0x00},
|
||||
{0x67, 0x97},
|
||||
{0x68, 0x01},
|
||||
{0x69, 0xCD},
|
||||
{0x6A, 0x01},
|
||||
{0x6B, 0xB0},
|
||||
{0x6C, 0x04},
|
||||
{0x6D, 0x2C},
|
||||
{0x6E, 0x01},
|
||||
{0x74, 0x00},
|
||||
{0xEF, 0x00},
|
||||
{0x41, 0xFF},
|
||||
{0x42, 0x01},
|
||||
};
|
||||
|
||||
/* 定义先进先出队列 */
|
||||
@@ -202,7 +202,7 @@ typedef struct {
|
||||
uint16_t buffer[FIFO_MAXSIZE]; /* 相关bit定义参考paj7620u2.h的“手势识别效果” */
|
||||
uint16_t offset_read;
|
||||
uint16_t offset_write;
|
||||
}fifo_s;
|
||||
} fifo_s;
|
||||
static fifo_s m_fifo_intflags;
|
||||
|
||||
/* 轮询方式访问 */
|
||||
@@ -223,8 +223,9 @@ static inline void FifoPut(fifo_s *fifo, uint16_t flag)
|
||||
|
||||
static inline uint16_t FifoGet(fifo_s *fifo, uint16_t *flag)
|
||||
{
|
||||
if (fifo->offset_read == fifo->offset_write)
|
||||
if (fifo->offset_read == fifo->offset_write) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*flag = fifo->buffer[fifo->offset_read];
|
||||
fifo->offset_read = (fifo->offset_read + 1) % FIFO_MAXSIZE;
|
||||
@@ -289,7 +290,7 @@ static void e53_gs_led_init()
|
||||
/***************************************************************
|
||||
* 函数名称: paj7620u2_delay_usec
|
||||
* 说 明: 忙等待
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @usec: 忙等待的微秒数
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
@@ -308,10 +309,9 @@ static inline void paj7620u2_delay_usec(uint32_t usec)
|
||||
static uint8_t paj7620U2_write_null()
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
|
||||
|
||||
ret = LzI2cWrite(E53_I2C_BUS, PAJ7620U2_I2C_SLAVE_ADDRESS, NULL, 0);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cWrite failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
@@ -322,7 +322,7 @@ static uint8_t paj7620U2_write_null()
|
||||
/***************************************************************
|
||||
* 函数名称: paj7620u2_write_data
|
||||
* 说 明: 使用i2c往PAJ7620U2写入数据
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: 寄存器地址
|
||||
* @data: 数值
|
||||
* 返 回 值: 返回1为成功
|
||||
@@ -336,8 +336,7 @@ static uint8_t paj7620u2_write_data(uint8_t addr, uint8_t data)
|
||||
buffer[0] = addr;
|
||||
buffer[1] = data;
|
||||
ret = LzI2cWrite(E53_I2C_BUS, PAJ7620U2_I2C_SLAVE_ADDRESS, buffer, 2);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cWrite failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
@@ -348,7 +347,7 @@ static uint8_t paj7620u2_write_data(uint8_t addr, uint8_t data)
|
||||
/***************************************************************
|
||||
* 函数名称: paj7620u2_read_data
|
||||
* 说 明: 使用i2c读取PAJ7620U2的寄存器数据
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @addr: 寄存器地址
|
||||
* @data: 数值
|
||||
* 返 回 值: 返回1为成功
|
||||
@@ -361,15 +360,13 @@ static uint8_t paj7620u2_read_data(uint8_t addr, uint8_t *data)
|
||||
/* 发送地址给PAJ7620U2 */
|
||||
buffer[0] = addr;
|
||||
ret = LzI2cWrite(E53_I2C_BUS, PAJ7620U2_I2C_SLAVE_ADDRESS, buffer, 1);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cWrite failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = LzI2cRead(E53_I2C_BUS, PAJ7620U2_I2C_SLAVE_ADDRESS, data, 1);
|
||||
if (ret != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cRead failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
}
|
||||
@@ -380,23 +377,22 @@ static uint8_t paj7620u2_read_data(uint8_t addr, uint8_t *data)
|
||||
/***************************************************************
|
||||
* 函数名称: paj7620u2_select_bank
|
||||
* 说 明: 选择PAJ7620U2 BANK区域
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @bank:bank区域[0,1]
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
static void paj7620u2_select_bank(BankId bank)
|
||||
{
|
||||
switch (bank)
|
||||
{
|
||||
case BANK0:
|
||||
paj7620u2_write_data(PAJ_REG_BANK_SEL, PAJ_REB_BANK_SEL_BANK0);
|
||||
break;
|
||||
case BANK1:
|
||||
paj7620u2_write_data(PAJ_REG_BANK_SEL, PAJ_REB_BANK_SEL_BANK1);
|
||||
break;
|
||||
default:
|
||||
printf("%s, %s, %d: bank(%d) out of the range!\n", __FILE__, __func__, __LINE__, bank);
|
||||
break;
|
||||
switch (bank) {
|
||||
case BANK0:
|
||||
paj7620u2_write_data(PAJ_REG_BANK_SEL, PAJ_REB_BANK_SEL_BANK0);
|
||||
break;
|
||||
case BANK1:
|
||||
paj7620u2_write_data(PAJ_REG_BANK_SEL, PAJ_REB_BANK_SEL_BANK1);
|
||||
break;
|
||||
default:
|
||||
printf("%s, %s, %d: bank(%d) out of the range!\n", __FILE__, __func__, __LINE__, bank);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +405,7 @@ static void paj7620u2_select_bank(BankId bank)
|
||||
static uint8_t paj7620u2_get_bank_id()
|
||||
{
|
||||
uint8_t bankId = 0;
|
||||
|
||||
|
||||
paj7620u2_read_data(PAJ_REG_BANK_SEL, &bankId);
|
||||
return bankId;
|
||||
}
|
||||
@@ -424,7 +420,7 @@ static uint32_t paj7620u2_wake_up()
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
uint8_t data = 0;
|
||||
|
||||
|
||||
/* 查询PAJ7620U2,用于唤醒它 */
|
||||
paj7620U2_write_null();
|
||||
paj7620u2_delay_usec(1000);
|
||||
@@ -435,13 +431,11 @@ static uint32_t paj7620u2_wake_up()
|
||||
/* 读取bank0 addr 0x0,返回一定是0x20 */
|
||||
paj7620u2_select_bank(BANK0);
|
||||
ret = paj7620u2_read_data(0x00, &data);
|
||||
if (ret != 1)
|
||||
{
|
||||
if (ret != 1) {
|
||||
printf("%s, %s, %d: paj7620u2_read_data failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
return __LINE__;
|
||||
}
|
||||
if (data != 0x20)
|
||||
{
|
||||
if (data != 0x20) {
|
||||
printf("%s, %s, %d: paj7620u2_read_data 0x%x != 0x20\n", __FILE__, __func__, __LINE__, data);
|
||||
return __LINE__;
|
||||
}
|
||||
@@ -477,26 +471,24 @@ static VOID paj7620u2_poll_task(VOID *args)
|
||||
uint8_t int_flag1 = 0;
|
||||
uint8_t int_flag2 = 0;
|
||||
uint16_t value = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
while (1) {
|
||||
/* 读取Paj7620U2的手势中断寄存器 */
|
||||
paj7620u2_select_bank(BANK0);
|
||||
paj7620u2_read_data(PAJ_REG_GET_INT_FLAG1, &int_flag1);
|
||||
paj7620u2_read_data(PAJ_REG_GET_INT_FLAG2, &int_flag2);
|
||||
|
||||
value = 0;
|
||||
if (int_flag1 != 0)
|
||||
{
|
||||
if (int_flag1 != 0) {
|
||||
value |= (uint16_t)(int_flag1);
|
||||
}
|
||||
if (int_flag2 != 0)
|
||||
{
|
||||
if (int_flag2 != 0) {
|
||||
value |= (uint16_t)(int_flag2 << 8);
|
||||
}
|
||||
|
||||
if (value != 0)
|
||||
if (value != 0) {
|
||||
FifoPut(&m_fifo_intflags, value);
|
||||
}
|
||||
|
||||
LOS_Msleep(100);
|
||||
}
|
||||
@@ -510,13 +502,11 @@ static VOID paj7620u2_poll_task(VOID *args)
|
||||
***************************************************************/
|
||||
static void paj7620u2_i2c_init()
|
||||
{
|
||||
if (I2cIoInit(m_i2cBus) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (I2cIoInit(m_i2cBus) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %d: I2cIoInit failed!\n", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
if (LzI2cInit(E53_I2C_BUS, m_i2c_freq) != LZ_HARDWARE_SUCCESS)
|
||||
{
|
||||
if (LzI2cInit(E53_I2C_BUS, m_i2c_freq) != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %d: I2cIoInit failed!\n", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
@@ -536,7 +526,7 @@ static void paj7620u2_poll_task_init()
|
||||
TSK_INIT_PARAM_S task;
|
||||
uint8_t int_flag1, int_flag2;
|
||||
UINT32 ret;
|
||||
|
||||
|
||||
/* 初始化先进先出缓冲区 */
|
||||
m_fifo_intflags.offset_read = 0;
|
||||
m_fifo_intflags.offset_write = 0;
|
||||
@@ -551,8 +541,7 @@ static void paj7620u2_poll_task_init()
|
||||
task.uwStackSize = 0x400;
|
||||
task.usTaskPrio = 10;
|
||||
ret = LOS_TaskCreate(&m_pollTaskId, &task);
|
||||
if (ret != LOS_OK)
|
||||
{
|
||||
if (ret != LOS_OK) {
|
||||
printf("%s, %d: LOS_TaskCreate failed(%d)\n", __func__, __LINE__, ret);
|
||||
/* 解锁任务调度 */
|
||||
LOS_TaskUnlock();
|
||||
@@ -578,24 +567,21 @@ static void paj7620u2_init_config()
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
uint32_t size;
|
||||
|
||||
|
||||
ret = paj7620u2_wake_up();
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 0) {
|
||||
printf("%s, %s, %d: paj7620u2_wake_up failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
}
|
||||
|
||||
/* 初始化PAJ7620U2 */
|
||||
size = sizeof(m_Paj7620u2_InitRegisterConfig) / (sizeof(uint8_t) * 2);
|
||||
for (uint32_t i = 0; i < size; i++)
|
||||
{
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
paj7620u2_write_data(m_Paj7620u2_InitRegisterConfig[i][0], m_Paj7620u2_InitRegisterConfig[i][1]);
|
||||
}
|
||||
|
||||
/* 设置为手势识别模式 */
|
||||
size = sizeof(m_Paj7620u2_SetGestureModeConfig) / (sizeof(uint8_t) * 2);
|
||||
for (uint32_t i = 0; i < size; i++)
|
||||
{
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
paj7620u2_write_data(m_Paj7620u2_SetGestureModeConfig[i][0], m_Paj7620u2_SetGestureModeConfig[i][1]);
|
||||
}
|
||||
|
||||
@@ -617,7 +603,7 @@ unsigned int e53_gs_init()
|
||||
e53_gs_led_init();
|
||||
/* 上电后,等待PAJ7620U2 700usec */
|
||||
paj7620u2_delay_usec(700);
|
||||
/* 初始化i2c */
|
||||
/* 初始化i2c */
|
||||
paj7620u2_i2c_init();
|
||||
/* 初始化寄存器配置和工作模式 */
|
||||
paj7620u2_init_config();
|
||||
@@ -628,18 +614,15 @@ unsigned int e53_gs_init()
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_up_set
|
||||
* 说 明: 手势感应模块向上LED设置
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_up_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_UP, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_UP, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -647,18 +630,15 @@ void e53_gs_led_up_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_down_set
|
||||
* 说 明: 手势感应模块向上LED设置
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_down_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_DOWN, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_DOWN, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -666,18 +646,15 @@ void e53_gs_led_down_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_left_set
|
||||
* 说 明: 手势感应模块向左LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_left_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_LEFT, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_LEFT, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -685,18 +662,15 @@ void e53_gs_led_left_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_right_set
|
||||
* 说 明: 手势感应模块向右LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_right_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_RIGHT, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_RIGHT, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -704,18 +678,15 @@ void e53_gs_led_right_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_forward_set
|
||||
* 说 明: 手势感应模块向前LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_forward_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_FORWARD, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_FORWARD, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -723,18 +694,15 @@ void e53_gs_led_forward_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_backward_set
|
||||
* 说 明: 手势感应模块向后LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_backward_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_BACKWARD, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_BACKWARD, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -742,18 +710,15 @@ void e53_gs_led_backward_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_cw_set
|
||||
* 说 明: 手势感应模块顺时针转圈LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_cw_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_CW, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_CW, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -761,18 +726,15 @@ void e53_gs_led_cw_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_ccw_set
|
||||
* 说 明: 手势感应模块逆时针转圈LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_ccw_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_CCW, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_CCW, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -780,18 +742,15 @@ void e53_gs_led_ccw_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_led_wave_set
|
||||
* 说 明: 手势感应模块挥手LED亮起
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @is_on:1为开启,0为关闭
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
void e53_gs_led_wave_set(unsigned char is_on)
|
||||
{
|
||||
if (is_on == 0)
|
||||
{
|
||||
if (is_on == 0) {
|
||||
LzGpioSetVal(GPIO_LED_WAVE, LZGPIO_LEVEL_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LzGpioSetVal(GPIO_LED_WAVE, LZGPIO_LEVEL_LOW);
|
||||
}
|
||||
}
|
||||
@@ -799,7 +758,7 @@ void e53_gs_led_wave_set(unsigned char is_on)
|
||||
/***************************************************************
|
||||
* 函数名称: e53_gs_get_gesture_state
|
||||
* 说 明: 获取手势感应模块手势
|
||||
* 参 数:
|
||||
* 参 数:
|
||||
* @flag:获取当前手势
|
||||
* 返 回 值: 1为成功,0为失败
|
||||
***************************************************************/
|
||||
@@ -807,14 +766,10 @@ unsigned int e53_gs_get_gesture_state(unsigned short *flag)
|
||||
{
|
||||
*flag = 0;
|
||||
|
||||
if (FifoGet(&m_fifo_intflags, flag) != 0)
|
||||
{
|
||||
if (FifoGet(&m_fifo_intflags, flag) != 0) {
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user