Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
dianjixz committed Aug 24, 2023
1 parent f7c0bc5 commit 3ca9e66
Show file tree
Hide file tree
Showing 35 changed files with 545 additions and 111 deletions.
4 changes: 2 additions & 2 deletions components/DeviceDriver/party/linux_i2c/linuxi2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void linuxi2c_init_device(LINUXI2CDevice *device)
/* 7 bit device address */
device->tenbit = 0;

/* 1ms delay */
device->delay = 1;
/* no delay */
device->delay = 0;

/* 8 bytes per page */
device->page_bytes = 8;
Expand Down
50 changes: 50 additions & 0 deletions components/DeviceDriver/party/linux_uart/linux_uart.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Copyright(C), 2020-2023, Red Hat Inc.
* File name:
* Author: dianjixz
* Version: v 1.0.0
* Date:
* Description:
* Function List:
* History:
*/


#ifndef __LINUX_UART_H
#define __LINUX_UART_H

Expand All @@ -17,18 +29,56 @@ do{\
printf("\r\n");\
} while (0);


typedef struct{
int baud;
int data_bits;
int stop_bits;
char parity;
}uart_t;

/**
* @brief 初始化uart
* @note
* @param [in] dev 设备名
* @param [in] param 参数
* @retval [return] [>0] 打开的设备号索引
* @retval [return] [<=0] 失败代码.
*/
int linux_uart_init(char* dev, void* param);

/**
* @brief 关闭uart
* @note
* @param [in] fd 设备号索引
* @retval
*/
void linux_uart_deinit(int fd);

/**
* @brief 从 uart 读取数据
* @note
* @param [in] fd 设备号索引
* @param [in] cnt 缓冲区大小
* @param [in] buf 缓冲区指针
* @retval [return] [>0] 读取的数据的大小
* @retval [return] [<0] 读取失败代码
*/
int linux_uart_read(int fd, int cnt, uint8_t* buf);

/**
* @brief 从 uart 发送数据
* @note
* @param [in] fd 设备号索引
* @param [in] cnt 缓冲区大小
* @param [in] buf 缓冲区指针
* @retval [return] [>0] 发送的数据的大小
* @retval [return] [<0] 发送失败代码
*/
int linux_uart_write(int fd, int cnt, uint8_t* buf);

#if __cplusplus
}
#endif

#endif /* __LINUX_UART_H */
115 changes: 115 additions & 0 deletions doc/组件文档/DeviceDriver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# DeviceDriver
用于 linux 平台的设备驱动,包含一些小的传感器和执行器等,运行在应用层的程序.



## linux_uart
linux 的非标 c 串口库,读写 /dev 目录下的串口设备.用于 linux 串口的使用.

库存放在 components/DeviceDriver/party/linux_uart 中,

临时起用(可被 make distclean 清除)

使用 `make menuconfig` 命令开启 Enable DeviceDriver -> compile uart lib

永久起用 (make 的时候自动包含)

在项目中的 config_defaults.mk 文件中添加:
```
CONFIG_DEVICE_DRIVER_ENABLED=y
CONFIG_DEVICE_UART_ENABLED=y
```
启用库.

使用例程查看 examples/linux_uart


## linux_i2c

linux 的非标 i2c 串口库,读写 /dev 目录下的串口设备.用于 linux i2c 的使用.

库存放在 components/DeviceDriver/party/linux_i2c 中,

临时起用(可被 make distclean 清除)

使用 `make menuconfig` 命令开启 Enable DeviceDriver -> compile i2c lib

永久起用 (make 的时候自动包含)

在项目中的 config_defaults.mk 文件中添加:
```
CONFIG_DEVICE_DRIVER_ENABLED=y
CONFIG_DEVICE_I2C_ENABLED=y
```
启用库.

在 components/DeviceDriver/party/linux_i2c 文件中有两个 i2c 通信库.linux_i2c.h 和 linuxi2c.h
两个库用法不同,请参考例程使用.


使用例程查看 examples/linux_i2c

## linux_spi

linux 的非标 spi 串口库,读写 /dev 目录下的串口设备.用于 linux spi 的使用.

库存放在 components/DeviceDriver/party/linux_spi 中,

临时起用(可被 make distclean 清除)

使用 `make menuconfig` 命令开启 Enable DeviceDriver -> compile spi lib

永久起用 (make 的时候自动包含)

在项目中的 config_defaults.mk 文件中添加:
```
CONFIG_DEVICE_DRIVER_ENABLED=y
CONFIG_DEVICE_SPI_ENABLED=y
```
启用库.

使用例程查看 examples/linux_spi

## framebuffer

linux 的非标 framebuffer 串口库,读写 /dev 目录下的串口设备.用于在 linux 屏幕上绘画.

库存放在 components/DeviceDriver/party/framebuffer 中,

临时起用(可被 make distclean 清除)

使用 `make menuconfig` 命令开启 Enable DeviceDriver -> compile framebuffer lib

永久起用 (make 的时候自动包含)

在项目中的 config_defaults.mk 文件中添加:
```
CONFIG_DEVICE_DRIVER_ENABLED=y
CONFIG_DEVICE_FRAMEBUFFER_ENABLED=y
```
启用库.

使用例程查看 examples/linux_framebuffer

## ptmx

linux 的非标 pts 串口库,读写 /dev 目录下的串口设备.用于 linux 虚拟终端的使用,可用于操作其他进程的标准输入输出.在守护程序中很有用.

库存放在 components/DeviceDriver/party/ptmx 中,

临时起用(可被 make distclean 清除)

使用 `make menuconfig` 命令开启 Enable DeviceDriver -> compile ptmx lib

永久起用 (make 的时候自动包含)

在项目中的 config_defaults.mk 文件中添加:
```
CONFIG_DEVICE_DRIVER_ENABLED=y
CONFIG_DEVICE_PTMX_ENABLED=y
```
启用库.

使用例程查看 examples/linux_ptmx


4 changes: 0 additions & 4 deletions examples/linux_can/main/include/test.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
#pragma once

int can_test_main(int argc,char *argv[]);
int can_master_main(int argc,char *argv[]);


50 changes: 47 additions & 3 deletions examples/linux_can/main/src/main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
#include "test.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char *argv[])
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>

#include <linux/can.h>
#include <linux/can/raw.h>

int main(void)
{
int s;
int nbytes;
struct sockaddr_can addr;
struct can_frame frame;
struct ifreq ifr;

const char *ifname = "vcan0";

if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) == -1)
{
perror("Error while opening socket");
return -1;
}

strcpy(ifr.ifr_name, ifname);
ioctl(s, SIOCGIFINDEX, &ifr);

addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;

printf("%s at index %d\n", ifname, ifr.ifr_ifindex);

if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) == -1)
{
perror("Error in socket bind");
return -2;
}

frame.can_id = 0x123;
frame.can_dlc = 2;
frame.data[0] = 0x11;
frame.data[1] = 0x22;

nbytes = write(s, &frame, sizeof(struct can_frame));

can_test_main(argc, argv);
printf("Wrote %d bytes\n", nbytes);

return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/linux_can_test/config_defaults.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# CONFIG_COMPONENT1_ENABLED=y

66 changes: 66 additions & 0 deletions examples/linux_can_test/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
############### Add include ###################
list(APPEND ADD_INCLUDE "include"
)
list(APPEND ADD_PRIVATE_INCLUDE "")
###############################################

############ Add source files #################
# list(APPEND ADD_SRCS "src/main.c"
# "src/test.c"
# )
append_srcs_dir(ADD_SRCS "src") # append source file in src dir to var ADD_SRCS
# list(REMOVE_ITEM COMPONENT_SRCS "src/test2.c")
# FILE(GLOB_RECURSE EXTRA_SRC "src/*.c")
# FILE(GLOB EXTRA_SRC "src/*.c")
# list(APPEND ADD_SRCS ${EXTRA_SRC})
# aux_source_directory(src ADD_SRCS) # collect all source file in src dir, will set var ADD_SRCS
# append_srcs_dir(ADD_SRCS "src") # append source file in src dir to var ADD_SRCS
# list(REMOVE_ITEM COMPONENT_SRCS "src/test.c")
# set(ADD_ASM_SRCS "src/asm.S")
# list(APPEND ADD_SRCS ${ADD_ASM_SRCS})
# SET_PROPERTY(SOURCE ${ADD_ASM_SRCS} PROPERTY LANGUAGE C) # set .S ASM file as C language
# SET_SOURCE_FILES_PROPERTIES(${ADD_ASM_SRCS} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp -D BBBBB")
###############################################

###### Add required/dependent components ######
# list(APPEND ADD_REQUIREMENTS component1)
# if(CONFIG_COMPONENT2_ENABLED)
# list(APPEND ADD_REQUIREMENTS component2)
# endif()
# if(CONFIG_COMPONENT3_ENABLED)
# list(APPEND ADD_REQUIREMENTS component3)
# endif()
###############################################

###### Add link search path for requirements/libs ######
# list(APPEND ADD_LINK_SEARCH_PATH "${CONFIG_TOOLCHAIN_PATH}/lib")
# list(APPEND ADD_REQUIREMENTS pthread m) # add system libs, pthread and math lib for example here
# set (OpenCV_DIR opencv/lib/cmake/opencv4)
# find_package(OpenCV REQUIRED)
###############################################

############ Add static libs ##################
# list(APPEND ADD_STATIC_LIB "lib/libtest.a")
###############################################

#### Add compile option for this component ####
#### Just for this component, won't affect other
#### modules, including component that depend
#### on this component
# list(APPEND ADD_DEFINITIONS_PRIVATE -DAAAAA=1)

#### Add compile option for this component
#### and components denpend on this component
# list(APPEND ADD_DEFINITIONS -DAAAAA222=1
# -DAAAAA333=1)
###############################################

############ Add static libs ##################
#### Update parent's variables like CMAKE_C_LINK_FLAGS
# set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group lib/libtest.a -ltest2 -Wl,--end-group" PARENT_SCOPE)
###############################################



register_component()

File renamed without changes.
6 changes: 6 additions & 0 deletions examples/linux_can_test/main/include/test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

int can_test_main(int argc,char *argv[]);
int can_master_main(int argc,char *argv[]);


File renamed without changes.
10 changes: 10 additions & 0 deletions examples/linux_can_test/main/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "test.h"
#include <stdio.h>

int main(int argc, char *argv[])
{

can_test_main(argc, argv);

return 0;
}
File renamed without changes.
6 changes: 6 additions & 0 deletions examples/linux_framebuffer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

dist
build
.config.mk
.flash.conf.json

Loading

0 comments on commit 3ca9e66

Please sign in to comment.