mirror of
https://github.com/openharmony/vendor_lockzhiner.git
synced 2026-07-01 21:34:03 -04:00
修改编译服务器上的vendor_lockzhiner的BUG,规范化代码
Signed-off-by: lockzhiner_wang-xiaobin <wangxb@fzlzdz.com>
This commit is contained in:
@@ -132,10 +132,9 @@ 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);
|
||||
|
||||
*endRecordsPtr = 0;
|
||||
|
||||
// read the first page to see where is the end of the Records.
|
||||
if (ret == true) {
|
||||
// if the first byte is equals to NDEF_START_BYTE there are some records
|
||||
@@ -179,8 +178,8 @@ bool NT3HEraseAllTag(void)
|
||||
{
|
||||
bool ret = true;
|
||||
uint8_t erase[NFC_PAGE_SIZE + 1] = {USER_START_REG, 0x03, 0x03, 0xD0, 0x00, 0x00, 0xFE};
|
||||
ret = writeTimeout(erase, sizeof(erase));
|
||||
|
||||
ret = writeTimeout(erase, sizeof(erase));
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_ERASE_USER_MEMORY_PAGE;
|
||||
}
|
||||
@@ -205,14 +204,15 @@ bool getSessionReg(void)
|
||||
bool NT3HReadUserData(uint8_t page)
|
||||
{
|
||||
uint8_t reg = USER_START_REG + page;
|
||||
bool ret;
|
||||
|
||||
// if the requested page is out of the register exit with error
|
||||
if (reg > USER_END_REG) {
|
||||
errNo = NT3HERROR_INVALID_USER_MEMORY_PAGE;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = readTimeout(reg, nfcPageBuffer);
|
||||
|
||||
ret = readTimeout(reg, nfcPageBuffer);
|
||||
if (ret == false) {
|
||||
errNo = NT3HERROR_READ_USER_MEMORY_PAGE;
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ bool NT3HwriteRecord(const NDEFDataStr *data)
|
||||
NT3HReadHeaderNfc(&recordLength, &mbMe);
|
||||
addPage.page = (recordLength + sizeof(NDEFHeaderStr) + 1) / NFC_PAGE_SIZE;
|
||||
|
||||
//remove the NDEF_END_BYTE byte because it will overwrite by the new Record
|
||||
// remove the NDEF_END_BYTE byte because it will overwrite by the new Record
|
||||
addPage.usedBytes = (recordLength + sizeof(NDEFHeaderStr) + 1) % NFC_PAGE_SIZE - 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,15 +18,18 @@
|
||||
|
||||
static void rtdHeader(uint8_t type, NDEFRecordStr *ndefRecord, uint8_t *I2CMsg)
|
||||
{
|
||||
#define I2CMSG_OFFSET_HEADER 0
|
||||
#define I2CMSG_OFFSET_TYPE_LENGTH 1
|
||||
#define I2CMSG_OFFSET_TYPE_CODE 3
|
||||
ndefRecord->header |= 1;
|
||||
ndefRecord->header |= BIT_SR;
|
||||
I2CMsg[0] = ndefRecord->header;
|
||||
I2CMsg[I2CMSG_OFFSET_HEADER] = ndefRecord->header;
|
||||
|
||||
ndefRecord->typeLength = 1;
|
||||
I2CMsg[1] = ndefRecord->typeLength;
|
||||
I2CMsg[I2CMSG_OFFSET_TYPE_LENGTH] = ndefRecord->typeLength;
|
||||
|
||||
ndefRecord->type.typeCode = type;
|
||||
I2CMsg[3] = ndefRecord->type.typeCode;
|
||||
I2CMsg[I2CMSG_OFFSET_TYPE_CODE] = ndefRecord->type.typeCode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -122,13 +122,15 @@ unsigned int eeprom_get_blocksize(void)
|
||||
***************************************************************/
|
||||
unsigned int eeprom_readbyte(unsigned int addr, unsigned char *data)
|
||||
{
|
||||
#define LZ_I2C_MSG_MAXSIZE 2
|
||||
unsigned int ret = 0;
|
||||
unsigned char buffer[1];
|
||||
LzI2cMsg msgs[2];
|
||||
LzI2cMsg msgs[LZ_I2C_MSG_MAXSIZE];
|
||||
|
||||
/* 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);
|
||||
printf("%s, %s, %d: addr(0x%x) >= EEPROM_ADDRESS_MAX(0x%x)\n",
|
||||
__FILE__, __func__, __LINE__, addr, EEPROM_ADDRESS_MAX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -144,7 +146,7 @@ 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);
|
||||
ret = LzI2cTransfer(EEPROM_I2C_BUS, msgs, LZ_I2C_MSG_MAXSIZE);
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cTransfer failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
@@ -163,13 +165,16 @@ unsigned int eeprom_readbyte(unsigned int addr, unsigned char *data)
|
||||
***************************************************************/
|
||||
unsigned int eeprom_writebyte(unsigned int addr, unsigned char data)
|
||||
{
|
||||
#define BUFFER_MAXSIZE 2 /* 字符串长度 */
|
||||
#define K24C02_WRITE_WAIT_USEC 1000 /* K24C02芯片写完成的等待时间 */
|
||||
unsigned int ret = 0;
|
||||
LzI2cMsg msgs[1];
|
||||
unsigned char buffer[2];
|
||||
unsigned char buffer[BUFFER_MAXSIZE];
|
||||
|
||||
/* 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);
|
||||
printf("%s, %s, %d: addr(0x%x) >= EEPROM_ADDRESS_MAX(0x%x)\n",
|
||||
__FILE__, __func__, __LINE__, addr, EEPROM_ADDRESS_MAX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -179,7 +184,7 @@ unsigned int eeprom_writebyte(unsigned int addr, unsigned char data)
|
||||
msgs[0].addr = EEPROM_I2C_ADDRESS;
|
||||
msgs[0].flags = 0;
|
||||
msgs[0].buf = &buffer[0];
|
||||
msgs[0].len = 2;
|
||||
msgs[0].len = BUFFER_MAXSIZE;
|
||||
|
||||
ret = LzI2cTransfer(EEPROM_I2C_BUS, msgs, 1);
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
@@ -188,7 +193,7 @@ unsigned int eeprom_writebyte(unsigned int addr, unsigned char data)
|
||||
}
|
||||
|
||||
/* K24C02芯片需要时间完成写操作,在此之前不响应其他操作 */
|
||||
eeprog_delay_usec(1000);
|
||||
eeprog_delay_usec(K24C02_WRITE_WAIT_USEC);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,9 @@ static LzSpiConfig m_spiConf = {
|
||||
/* 寄存器最高位 */
|
||||
#define REG_BITS_HIGH (0x80)
|
||||
|
||||
/* sizey的字体单位大小 */
|
||||
#define SIZEY_UNIT 8
|
||||
|
||||
/* uint16取值 */
|
||||
#define UINT16_TO_H(val) (((val) & 0xFF00) >> 8)
|
||||
#define UINT16_TO_L(val) ((val) & 0x00FF)
|
||||
@@ -196,7 +199,13 @@ static uint32_t mypow(uint8_t m, uint8_t n)
|
||||
* @mode: 0为非叠加模式;1为叠加模式
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
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)
|
||||
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;
|
||||
uint16_t k;
|
||||
@@ -262,7 +271,13 @@ static void lcd_show_chinese_12x12(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
* @mode: 0为非叠加模式;1为叠加模式
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
static void lcd_show_chinese_16x16(uint16_t x, uint16_t y, uint8_t *s, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode)
|
||||
static void lcd_show_chinese_16x16(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;
|
||||
uint16_t k;
|
||||
@@ -270,7 +285,7 @@ static void lcd_show_chinese_16x16(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
uint16_t TypefaceNum; /* 一个字符所占字节大小 */
|
||||
uint16_t x0 = x;
|
||||
|
||||
TypefaceNum = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * sizey;
|
||||
TypefaceNum = (sizey / SIZEY_UNIT + ((sizey % SIZEY_UNIT) ? 1 : 0)) * sizey;
|
||||
/* 统计汉字数目 */
|
||||
HZnum = sizeof(tfont16) / sizeof(typFNT_GB16);
|
||||
|
||||
@@ -309,7 +324,7 @@ static void lcd_show_chinese_16x16(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
}
|
||||
}
|
||||
|
||||
break; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
|
||||
break; /* 查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响 */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +343,13 @@ static void lcd_show_chinese_16x16(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
* @mode: 0为非叠加模式;1为叠加模式
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
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)
|
||||
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;
|
||||
uint16_t k;
|
||||
@@ -375,7 +396,7 @@ static void lcd_show_chinese_24x24(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
}
|
||||
}
|
||||
|
||||
break; //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
|
||||
break; /* 查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响 */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,15 +415,21 @@ static void lcd_show_chinese_24x24(uint16_t x, uint16_t y, uint8_t *s, uint16_t
|
||||
* @mode: 0为非叠加模式;1为叠加模式
|
||||
* 返 回 值: 无
|
||||
***************************************************************/
|
||||
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)
|
||||
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;
|
||||
uint16_t k;
|
||||
uint16_t HZnum;//汉字数目
|
||||
uint16_t TypefaceNum;//一个字符所占字节大小
|
||||
uint16_t HZnum; /* 汉字数目 */
|
||||
uint16_t TypefaceNum; /* 一个字符所占字节大小 */
|
||||
uint16_t x0 = x;
|
||||
|
||||
TypefaceNum = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * sizey;
|
||||
TypefaceNum = (sizey / SIZEY_UNIT + ((sizey % SIZEY_UNIT) ? 1 : 0)) * sizey;
|
||||
/* 统计汉字数目 */
|
||||
HZnum = sizeof(tfont32) / sizeof(typFNT_GB32);
|
||||
|
||||
@@ -827,8 +854,9 @@ void lcd_show_char(uint16_t x, uint16_t y, uint8_t num, uint16_t fc, uint16_t bc
|
||||
uint16_t i;
|
||||
uint16_t TypefaceNum; /* 一个字符所占字节大小 */
|
||||
uint16_t x0 = x;
|
||||
uint16_t size_y2x = 2;
|
||||
|
||||
sizex = sizey / 2;
|
||||
sizex = sizey / size_y2x;
|
||||
TypefaceNum = (sizex / BYTE_TO_BITS + ((sizex % BYTE_TO_BITS) ? 1 : 0)) * sizey;
|
||||
|
||||
/* 得到偏移后的值 */
|
||||
@@ -925,12 +953,14 @@ 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 base = 48; /* ASCII字符'0' */
|
||||
uint8_t power_base = 10;
|
||||
uint8_t power_remainder = 10;
|
||||
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;
|
||||
temp = (num / mypow(power_base, len - t - 1)) % power_remainder;
|
||||
if (enshow == 0 && t < (len - 1)) {
|
||||
if (temp == 0) {
|
||||
lcd_show_char(x + t * sizex, y, ' ', fc, bc, sizey, 0);
|
||||
|
||||
@@ -217,13 +217,14 @@ static inline void write_iic_data(unsigned char iic_data)
|
||||
***************************************************************/
|
||||
static inline void write_iic_command(unsigned char iic_command)
|
||||
{
|
||||
unsigned char buffer[2];
|
||||
#define BUFFER_MAXSIZE 2 /* 字符串长度 */
|
||||
unsigned char buffer[BUFFER_MAXSIZE];
|
||||
unsigned int ret;
|
||||
|
||||
/* 填充数据,第一个字节是通知OLED芯片,下一个字节是命令 */
|
||||
buffer[0] = 0x00;
|
||||
buffer[1] = iic_command;
|
||||
ret = LzI2cWrite(OLED_I2C_BUS, OLED_I2C_ADDRESS, buffer, 2);
|
||||
ret = LzI2cWrite(OLED_I2C_BUS, OLED_I2C_ADDRESS, buffer, BUFFER_MAXSIZE);
|
||||
if (ret != 0) {
|
||||
printf("%s, %s, %d: LzI2cWrite failed(%d)!\n", __FILE__, __func__, __LINE__, ret);
|
||||
}
|
||||
@@ -283,8 +284,9 @@ static inline void oled_wr_byte(unsigned dat, unsigned cmd)
|
||||
***************************************************************/
|
||||
static inline void oled_set_pos(unsigned char x, unsigned char y)
|
||||
{
|
||||
#define BYTE_DIV 4 /* 截取字节部分 */
|
||||
oled_wr_byte(0xb0 + y, OLED_CMD);
|
||||
oled_wr_byte(((x & 0xf0) >> 4) | 0x10, OLED_CMD);
|
||||
oled_wr_byte(((x & 0xf0) >> BYTE_DIV) | 0x10, OLED_CMD);
|
||||
oled_wr_byte((x & 0x0f), OLED_CMD);
|
||||
}
|
||||
|
||||
@@ -296,6 +298,7 @@ static inline void oled_set_pos(unsigned char x, unsigned char y)
|
||||
***************************************************************/
|
||||
unsigned int oled_init(void)
|
||||
{
|
||||
uint32_t sleep_msec = 200;
|
||||
#if !OLED_I2C_ENABLE
|
||||
/* GPIO0_C1 => I2C1_SDA_M1 */
|
||||
LzGpioInit(GPIO_I2C_SDA);
|
||||
@@ -314,7 +317,7 @@ unsigned int oled_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
LOS_Msleep(200);
|
||||
LOS_Msleep(sleep_msec);
|
||||
|
||||
oled_wr_byte(0xAE, OLED_CMD); // --display off
|
||||
oled_wr_byte(0x00, OLED_CMD); // ---set low column address
|
||||
@@ -438,13 +441,14 @@ void oled_show_char(uint8_t x, uint8_t y, uint8_t chr, uint8_t chr_size)
|
||||
#define F6X8_LINE_DATA 6
|
||||
#define BYTE_BITS 8
|
||||
#define CHAR_LEN 16
|
||||
#define Y_OFFSET 2
|
||||
unsigned char c = 0, i = 0;
|
||||
|
||||
c = chr - ' '; // 得到偏移后的值
|
||||
|
||||
if (x > (OLED_COLUMN_MAX - 1)) {
|
||||
x = 0;
|
||||
y = y + 2;
|
||||
y = y + Y_OFFSET;
|
||||
}
|
||||
|
||||
if (chr_size == OLED_CHR_SIZE_16) {
|
||||
@@ -478,12 +482,14 @@ 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)
|
||||
{
|
||||
#define POWER_BASE 10 /* oled_power的基数 */
|
||||
#define POWER_REMINDER 10 /* oled_power的取余 */
|
||||
uint8_t div = 2;
|
||||
uint8_t t, temp;
|
||||
uint8_t enshow = 0;
|
||||
|
||||
for (t = 0; t < len; t++) {
|
||||
temp = (num / oled_pow(10, len - t - 1)) % 10;
|
||||
temp = (num / oled_pow(POWER_BASE, len - t - 1)) % POWER_REMINDER;
|
||||
if (enshow == 0 && t < (len - 1)) {
|
||||
if (temp == 0) {
|
||||
oled_show_char(x + (size2 / div)*t, y, ' ', size2);
|
||||
@@ -509,12 +515,13 @@ 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)
|
||||
{
|
||||
uint8_t x_offset = 8;
|
||||
unsigned char j = 0;
|
||||
uint8_t offset = 2;
|
||||
|
||||
while (chr[j] != '\0') {
|
||||
oled_show_char(x, y, chr[j], chr_size);
|
||||
x += 8;
|
||||
x += x_offset;
|
||||
if (x > OLED_COLUMN_MAX) {
|
||||
x = 0;
|
||||
y += offset;
|
||||
|
||||
@@ -120,7 +120,7 @@ void tcp_server_msg_handle(int fd)
|
||||
}
|
||||
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);
|
||||
snprintf(buf, sizeof(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
|
||||
}
|
||||
@@ -190,7 +190,8 @@ void tcp_client_msg_handle(int fd_src, struct sockaddr* dst)
|
||||
|
||||
while (1) {
|
||||
char buf[BUFF_LEN];
|
||||
sprintf(buf, "TCP TEST cilent send:%d", ++cnt);
|
||||
|
||||
snprintf(buf, sizeof(buf), "TCP TEST cilent send:%d", ++cnt);
|
||||
count = send(fd, buf, strlen(buf), 0); // 发送数据给server
|
||||
// count = lwip_write(fd, buf, strlen(buf)); // 发送数据给server
|
||||
printf("------------------------------------------------------------\n");
|
||||
|
||||
@@ -120,7 +120,7 @@ void udp_server_msg_handle(int fd)
|
||||
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);
|
||||
snprintf(buf, sizeof(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
|
||||
}
|
||||
@@ -200,11 +200,13 @@ void udp_client_msg_handle(int fd, struct sockaddr* dst)
|
||||
if (count == -1) {
|
||||
printf("[udp client] No server message!!!\n");
|
||||
} else {
|
||||
printf("[udp client] remote addr:%s port:%u\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
|
||||
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);
|
||||
snprintf(buf, sizeof(buf), "UDP TEST cilent send:%d", ++cnt);
|
||||
/* 发送数据给server */
|
||||
count = sendto(fd, buf, strlen(buf), 0, (struct sockaddr*)&client_addr, len);
|
||||
printf("[udp client] send:%s\n", buf);
|
||||
|
||||
@@ -34,4 +34,4 @@ void e53_ia_read_data(e53_ia_data_t *p_data);
|
||||
void light_set(SWITCH_STATUS_ENUM status);
|
||||
void motor_status_set(SWITCH_STATUS_ENUM status);
|
||||
|
||||
#endif /*__E53_INTELLIGENT_AGRICULTURE_H__*/
|
||||
#endif /* __E53_INTELLIGENT_AGRICULTURE_H__ */
|
||||
|
||||
@@ -236,6 +236,9 @@ void e53_ia_init(void)
|
||||
***************************************************************/
|
||||
void e53_ia_read_data(e53_ia_data_t *pData)
|
||||
{
|
||||
#define SHT30_CRC_STRING_MAXSIZE 3 /* SHT30的CRC字符串长度 */
|
||||
#define SHT30_CRC_DATA_MAXSIZE 2 /* CRC校验的数据长度 */
|
||||
#define SHT30_CRC_OFFSET 2 /* CRC校验的数组偏移量 */
|
||||
uint32_t wait_start_hb1750 = 180;
|
||||
float luminance_rate = 1.2;
|
||||
uint16_t high_byte_bit = 8;
|
||||
@@ -250,7 +253,7 @@ void e53_ia_read_data(e53_ia_data_t *pData)
|
||||
pData->luminance = (float)(((recv_data[0] << high_byte_bit) + recv_data[1]) / luminance_rate);
|
||||
|
||||
/* checksum verification */
|
||||
uint8_t data[3];
|
||||
uint8_t data[SHT30_CRC_STRING_MAXSIZE];
|
||||
uint16_t tmp;
|
||||
/* byte 0,1 is temperature byte 4,5 is humidity */
|
||||
uint8_t SHT30_Data_Buffer[EOFFSET_SHT30_REG_MAX];
|
||||
@@ -265,7 +268,7 @@ void e53_ia_read_data(e53_ia_data_t *pData)
|
||||
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]);
|
||||
rc = sht30_check_crc(data, SHT30_CRC_DATA_MAXSIZE, data[SHT30_CRC_OFFSET]);
|
||||
if (!rc) {
|
||||
tmp = ((uint16_t)data[0] << high_byte_bit) | data[1];
|
||||
pData->temperature = sht30_calc_temperature(tmp);
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __E53_SMART_CITY_H__
|
||||
#define __E53_SMART_CITY_H__
|
||||
#ifndef _E53_SMART_CITY_H_
|
||||
#define _E53_SMART_CITY_H_
|
||||
|
||||
#include "lz_hardware.h"
|
||||
|
||||
@@ -62,4 +62,4 @@ void e53_sc_read_data(e53_sc_data_t *p_data);
|
||||
void led_d1_set(SWITCH_STATUS_ENUM status);
|
||||
void led_d2_set(SWITCH_STATUS_ENUM status);
|
||||
|
||||
#endif /* __E53_SMART_CITY_H__ */
|
||||
#endif /* _E53_SMART_CITY_H_ */
|
||||
@@ -69,7 +69,14 @@ static uint32_t *m_ptimer5_current_value_low = (uint32_t *)(TIMER5_ADDRESS);
|
||||
/* Buzzer定义 */
|
||||
#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},
|
||||
.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,
|
||||
};
|
||||
|
||||
@@ -346,13 +346,14 @@ static uint8_t paj7620U2_write_null(void)
|
||||
***************************************************************/
|
||||
static uint8_t paj7620u2_write_data(uint8_t addr, uint8_t data)
|
||||
{
|
||||
#define BUFFER_MAXSIZE 2 /* 字符串长度 */
|
||||
unsigned int ret = 0;
|
||||
unsigned char buffer[2];
|
||||
unsigned char buffer[BUFFER_MAXSIZE];
|
||||
|
||||
/* write value to reg */
|
||||
buffer[0] = addr;
|
||||
buffer[1] = data;
|
||||
ret = LzI2cWrite(E53_I2C_BUS, PAJ7620U2_I2C_SLAVE_ADDRESS, buffer, 2);
|
||||
ret = LzI2cWrite(E53_I2C_BUS, PAJ7620U2_I2C_SLAVE_ADDRESS, buffer, BUFFER_MAXSIZE);
|
||||
if (ret != LZ_HARDWARE_SUCCESS) {
|
||||
printf("%s, %s, %d: LzI2cWrite failed(%d)\n", __FILE__, __func__, __LINE__, ret);
|
||||
return 0;
|
||||
@@ -435,15 +436,16 @@ static uint8_t paj7620u2_get_bank_id(void)
|
||||
***************************************************************/
|
||||
static uint32_t paj7620u2_wake_up(void)
|
||||
{
|
||||
#define PAJ7620U2_WRITE_WAIT_USEC 1000 /* PAJ7620U2等待唤醒时间 */
|
||||
uint8_t ret = 0;
|
||||
uint8_t data = 0;
|
||||
|
||||
/* 查询PAJ7620U2,用于唤醒它 */
|
||||
paj7620U2_write_null();
|
||||
paj7620u2_delay_usec(1000);
|
||||
paj7620u2_delay_usec(PAJ7620U2_WRITE_WAIT_USEC);
|
||||
/* 多唤醒1次 */
|
||||
paj7620U2_write_null();
|
||||
paj7620u2_delay_usec(1000);
|
||||
paj7620u2_delay_usec(PAJ7620U2_WRITE_WAIT_USEC);
|
||||
|
||||
/* 读取bank0 addr 0x0,返回一定是0x20 */
|
||||
paj7620u2_select_bank(BANK0);
|
||||
@@ -485,6 +487,8 @@ static void paj7620u2_suspend(void)
|
||||
***************************************************************/
|
||||
static VOID paj7620u2_poll_task(VOID *args)
|
||||
{
|
||||
#define BYTE_BITS 8 /* 字节移位 */
|
||||
#define POLL_WAIT_MSEC 100 /* Poll操作等待时间 */
|
||||
uint8_t int_flag1 = 0;
|
||||
uint8_t int_flag2 = 0;
|
||||
uint16_t value = 0;
|
||||
@@ -500,14 +504,14 @@ static VOID paj7620u2_poll_task(VOID *args)
|
||||
value |= (uint16_t)(int_flag1);
|
||||
}
|
||||
if (int_flag2 != 0) {
|
||||
value |= (uint16_t)(int_flag2 << 8);
|
||||
value |= (uint16_t)(int_flag2 << BYTE_BITS);
|
||||
}
|
||||
|
||||
if (value != 0) {
|
||||
FifoPut(&m_fifo_intflags, value);
|
||||
}
|
||||
|
||||
LOS_Msleep(100);
|
||||
LOS_Msleep(POLL_WAIT_MSEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,6 +586,7 @@ static void paj7620u2_poll_task_init(void)
|
||||
***************************************************************/
|
||||
static void paj7620u2_init_config(void)
|
||||
{
|
||||
#define UINT16_TO_UINT8 2 /* uint16_t转化2个uint8_t */
|
||||
uint8_t ret = 0;
|
||||
uint32_t size;
|
||||
|
||||
@@ -591,13 +596,13 @@ static void paj7620u2_init_config(void)
|
||||
}
|
||||
|
||||
/* 初始化PAJ7620U2 */
|
||||
size = sizeof(m_Paj7620u2_InitRegisterConfig) / (sizeof(uint8_t) * 2);
|
||||
size = sizeof(m_Paj7620u2_InitRegisterConfig) / (sizeof(uint8_t) * UINT16_TO_UINT8);
|
||||
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);
|
||||
size = sizeof(m_Paj7620u2_SetGestureModeConfig) / (sizeof(uint8_t) * UINT16_TO_UINT8);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
paj7620u2_write_data(m_Paj7620u2_SetGestureModeConfig[i][0], m_Paj7620u2_SetGestureModeConfig[i][1]);
|
||||
}
|
||||
@@ -614,10 +619,11 @@ static void paj7620u2_init_config(void)
|
||||
***************************************************************/
|
||||
unsigned int e53_gs_init(void)
|
||||
{
|
||||
#define PAJ7620U2_READY_WAIT_USEC 700 /* 等待PAJ7620U2准备时间 */
|
||||
/* 初始化LED */
|
||||
e53_gs_led_init();
|
||||
/* 上电后,等待PAJ7620U2 700usec */
|
||||
paj7620u2_delay_usec(700);
|
||||
paj7620u2_delay_usec(PAJ7620U2_READY_WAIT_USEC);
|
||||
/* 初始化i2c */
|
||||
paj7620u2_i2c_init();
|
||||
/* 初始化寄存器配置和工作模式 */
|
||||
|
||||
Reference in New Issue
Block a user