-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
545 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
# CONFIG_COMPONENT1_ENABLED=y | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
dist | ||
build | ||
.config.mk | ||
.flash.conf.json | ||
|
Oops, something went wrong.