[add] linux i2c example

This commit is contained in:
dianjixz
2024-05-20 09:25:03 +08:00
parent 4bb0d155a7
commit 45513ff918
7 changed files with 75 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
dist
build
.config.mk
.flash.conf.json
+4
View File
@@ -0,0 +1,4 @@
from pathlib import Path
import os
with open(str(Path(os.getcwd())/'..'/'..'/'tools'/'scons'/'project.py')) as f:
exec(f.read())
+6
View File
@@ -0,0 +1,6 @@
# CONFIG_COMPONENT1_ENABLED=y
CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin"
CONFIG_TOOLCHAIN_PREFIX="arm-linux-gnueabihf-"
CONFIG_DEVICE_DRIVER_ENABLED=y
CONFIG_DEVICE_I2C_ENABLED=y
View File
+34
View File
@@ -0,0 +1,34 @@
# project_root/src/SConscript
import os
# Import the environment from the SConstruct file
Import('env')
with open(env['PROJECT_TOOL_S']) as f:
exec(f.read())
SRCS = Glob('src/*.c*')
INCLUDE = [ADir('include'), ADir('.')]
PRIVATE_INCLUDE = []
REQUIREMENTS = ['pthread', "DeviceDriver"]
STATIC_LIB = []
DYNAMIC_LIB = []
DEFINITIONS = []
DEFINITIONS_PRIVATE = []
LDFLAGS = []
LINK_SEARCH_PATH = []
env['COMPONENTS'].append({'target':env['PROJECT_NAME'],
'SRCS':SRCS,
'INCLUDE':INCLUDE,
'PRIVATE_INCLUDE':PRIVATE_INCLUDE,
'REQUIREMENTS':REQUIREMENTS,
'STATIC_LIB':STATIC_LIB,
'DYNAMIC_LIB':DYNAMIC_LIB,
'DEFINITIONS':DEFINITIONS,
'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE,
'LDFLAGS':LDFLAGS,
'LINK_SEARCH_PATH':LINK_SEARCH_PATH,
'REGISTER':'project'
})
+1
View File
@@ -0,0 +1 @@
#pragma once
+24
View File
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "linux_i2c/linuxi2c.h"
LINUXI2CDevice i2cdev;
int main(int argc, char *argv[])
{
char i2c_bus[20] = "/dev/i2c-1";
linuxi2c_init_device(&i2cdev);
i2cdev.bus = linuxi2c_open(i2c_bus);
i2cdev.addr = 0x38;
uint8_t data[] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01, 0x02, 0x03};
// linuxi2c_write(&i2cdev, 0x05, data, sizeof(data));
linuxi2c_primitive_write(&i2cdev, data, 1, data, sizeof(data));
linuxi2c_close(i2cdev.bus);
return 0;
}