Skip to content

Commit

Permalink
Release v0.3.0.0
Browse files Browse the repository at this point in the history
Release v0.3.0.0

Co-Authored-By: Yong Shen <[email protected]>
Co-Authored-By: ma-loc <[email protected]>
  • Loading branch information
3 people committed Sep 6, 2022
1 parent 26f39f9 commit 5c07a8a
Show file tree
Hide file tree
Showing 13 changed files with 1,324 additions and 84 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ See [LICENSE](smi230/LICENSE) file
-------------------------------------------------------
Hardware
```
## Operation Examples <a name=examples></a>
## Usage

SMI230 HAL is a shared lib, which is dynamically linked to other Android programs.
* For convenient testing, it can be compiled as an executable to directly run on command line.
SMI230 HAL is a shared lib, compatable with android sensor 1.0 specification.
There are two ways to compile/build the lib.

### build with Android SDK

This way, the HAL lib is dynamically linked to other Android libs in its SDK.
For convenient testing, it can also be compiled as an executable to directly run on command line.

Integrate this repository into your build setup into location
```
Expand All @@ -48,3 +53,17 @@ Integrate this repository into your build setup into location
extend your build setup with smi230-hal and compile it.

For more information please refer to [android build system](https://source.android.com/setup/build/building)

### build independantly without Android SDK

The essecial header files from Android have already been placed in the repo and adapted for compiling the lib. The local libs instead of Android SDK libs would be used to link to the HAL lib in the build process.
Go to the folder where Makefile is located, and first clean the folder by issuing command:
```
make clean
```
Then simply issue command:
```
make
```
the Hal lib will be built in seconds.
Note: the Makefile is written for cross compiling on the host and with toolchain specified. If a different environment is used, a little change is needed to fit into new conditions.
2 changes: 1 addition & 1 deletion smi230/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/hal\
LOCAL_CFLAGS := -pthread -Wno-error=unused-local-typedef

ifeq ($(LOCAL_UNIT_TEST),true)
LOCAL_CPPFLAGS := -pthread -Wno-date-time -Wno-error=deprecated-declarations -Wno-error=unused-function -Wno-error=unused-local-typedef -Wno-error=unused-variable -DUNIT_TEST_ACTIVE
LOCAL_CPPFLAGS := -pthread -Wno-date-time -Wno-error=deprecated-declarations -Wno-error=unused-function -Wno-error=unused-local-typedef -Wno-error=unused-variable -DTEST_APP_ACTIVE
else
LOCAL_CPPFLAGS := -pthread -Wno-date-time -Wno-error=deprecated-declarations -Wno-error=unused-function -Wno-error=unused-local-typedef -Wno-error=unused-variable
endif
Expand Down
37 changes: 37 additions & 0 deletions smi230/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
TARGET ?= hal_test

SRCS := \
sensord/axis_remap.c\
sensord/sensord_hwcntl.cpp\
sensord/sensord_hwcntl_implement.cpp\
sensord/util_misc.c\
sensord/sensord_pltf.c\
sensord/sensord_cfg.cpp\
sensord/sensord_algo.cpp\
sensord/sensord.cpp\
sensord/boschsimple_list.cpp\
hal/sensors.cpp\
hal/BoschSensor.cpp

OBJS := $(addsuffix .o,$(basename $(SRCS)))
#DEPS := $(addsuffix .d,$(basename $(SRCS)))

INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))

HAL_TEST ?= true

ifeq ($(HAL_TEST), true)
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -DPLTF_LINUX_ENABLED -DTEST_APP_ACTIVE
LDFLAGS ?= -lpthread -lstdc++
else
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -DPLTF_LINUX_ENABLED
LDFLAGS ?= -lpthread -lstdc++ -shared
endif

hal_test: $(SRCS)
arm-linux-gnueabihf-gcc $(CPPFLAGS) -lpthread -lstdc++ $(SRCS) $(LDFLAGS) -o hal_test

.PHONY: clean
clean:
$(RM) $(TARGET) $(OBJS) $(DEPS) hal_test.d
6 changes: 3 additions & 3 deletions smi230/hal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main()
}

for (i = 0; i < sensorsNum; ++i) {
dev->device.batch((sensors_poll_device_1 *)dev, sSensorList[i].handle, 0, 10000000, 0);
dev->device.batch((sensors_poll_device_1 *)dev, sSensorList[i].handle, 0, 10000000, 1000000000);
dev->device.activate((sensors_poll_device_t *)dev, sSensorList[i].handle, 1);
}

Expand All @@ -57,11 +57,11 @@ int main()
printf("ending polling...\n");
goto END;
}else{
printf("get event, sensor id = %d\n", events[i].sensor);
;//printf("get event, sensor id = %d\n", events[i].sensor);
}
}

printf("==========================\n\n");
//printf("==========================\n\n");
}

END:
Expand Down
2 changes: 1 addition & 1 deletion smi230/hal/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ struct sensors_module_t HAL_MODULE_INFO_SYM =
#endif
};

#if defined(UNIT_TEST_ACTIVE)
#if defined(TEST_APP_ACTIVE)
#include "main.cpp"
#endif

244 changes: 244 additions & 0 deletions smi230/hardware/hardware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H
#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H

#include <stdint.h>
#include <sys/cdefs.h>

//#include <cutils/native_handle.h>
//#include <system/graphics.h>

__BEGIN_DECLS

/*
* Value for the hw_module_t.tag field
*/

#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))

#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')

#define HARDWARE_MAKE_API_VERSION(maj,min) \
((((maj) & 0xff) << 8) | ((min) & 0xff))

#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff


/*
* The current HAL API version.
*
* All module implementations must set the hw_module_t.hal_api_version field
* to this value when declaring the module with HAL_MODULE_INFO_SYM.
*
* Note that previous implementations have always set this field to 0.
* Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
* to be 100% binary compatible.
*
*/
#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)

/*
* Helper macros for module implementors.
*
* The derived modules should provide convenience macros for supported
* versions so that implementations can explicitly specify module/device
* versions at definition time.
*
* Use this macro to set the hw_module_t.module_api_version field.
*/
#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)

/*
* Use this macro to set the hw_device_t.version field
*/
#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)

struct hw_module_t;
struct hw_module_methods_t;
struct hw_device_t;

/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
typedef struct hw_module_t {
/** tag must be initialized to HARDWARE_MODULE_TAG */
uint32_t tag;

/**
* The API version of the implemented module. The module owner is
* responsible for updating the version when a module interface has
* changed.
*
* The derived modules such as gralloc and audio own and manage this field.
* The module user must interpret the version field to decide whether or
* not to inter-operate with the supplied module implementation.
* For example, SurfaceFlinger is responsible for making sure that
* it knows how to manage different versions of the gralloc-module API,
* and AudioFlinger must know how to do the same for audio-module API.
*
* The module API version should include a major and a minor component.
* For example, version 1.0 could be represented as 0x0100. This format
* implies that versions 0x0100-0x01ff are all API-compatible.
*
* In the future, libhardware will expose a hw_get_module_version()
* (or equivalent) function that will take minimum/maximum supported
* versions as arguments and would be able to reject modules with
* versions outside of the supplied range.
*/
uint16_t module_api_version;
#define version_major module_api_version
/**
* version_major/version_minor defines are supplied here for temporary
* source code compatibility. They will be removed in the next version.
* ALL clients must convert to the new version format.
*/

/**
* The API version of the HAL module interface. This is meant to
* version the hw_module_t, hw_module_methods_t, and hw_device_t
* structures and definitions.
*
* The HAL interface owns this field. Module users/implementations
* must NOT rely on this value for version information.
*
* Presently, 0 is the only valid value.
*/
uint16_t hal_api_version;
#define version_minor hal_api_version

/** Identifier of module */
const char *id;

/** Name of this module */
const char *name;

/** Author/owner/implementor of the module */
const char *author;

/** Modules methods */
struct hw_module_methods_t* methods;

/** module's dso */
void* dso;

#ifdef __LP64__
uint64_t reserved[32-7];
#else
/** padding to 128 bytes, reserved for future use */
uint32_t reserved[32-7];
#endif

} hw_module_t;

typedef struct hw_module_methods_t {
/** Open a specific device */
int (*open)(const struct hw_module_t* module, const char* id,
struct hw_device_t** device);

} hw_module_methods_t;

/**
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
typedef struct hw_device_t {
/** tag must be initialized to HARDWARE_DEVICE_TAG */
uint32_t tag;

/**
* Version of the module-specific device API. This value is used by
* the derived-module user to manage different device implementations.
*
* The module user is responsible for checking the module_api_version
* and device version fields to ensure that the user is capable of
* communicating with the specific module implementation.
*
* One module can support multiple devices with different versions. This
* can be useful when a device interface changes in an incompatible way
* but it is still necessary to support older implementations at the same
* time. One such example is the Camera 2.0 API.
*
* This field is interpreted by the module user and is ignored by the
* HAL interface itself.
*/
uint32_t version;

/** reference to the module this device belongs to */
struct hw_module_t* module;

/** padding reserved for future use */
#ifdef __LP64__
uint64_t reserved[12];
#else
uint32_t reserved[12];
#endif

/** Close this device */
int (*close)(struct hw_device_t* device);

} hw_device_t;

#ifdef __cplusplus
#define TO_HW_DEVICE_T_OPEN(x) reinterpret_cast<struct hw_device_t**>(x)
#else
#define TO_HW_DEVICE_T_OPEN(x) (struct hw_device_t**)(x)
#endif

/**
* Name of the hal_module_info
*/
#define HAL_MODULE_INFO_SYM HMI

/**
* Name of the hal_module_info as a string
*/
#define HAL_MODULE_INFO_SYM_AS_STR "HMI"

/**
* Get the module info associated with a module by id.
*
* @return: 0 == success, <0 == error and *module == NULL
*/
int hw_get_module(const char *id, const struct hw_module_t **module);

/**
* Get the module info associated with a module instance by class 'class_id'
* and instance 'inst'.
*
* Some modules types necessitate multiple instances. For example audio supports
* multiple concurrent interfaces and thus 'audio' is the module class
* and 'primary' or 'a2dp' are module interfaces. This implies that the files
* providing these modules would be named audio.primary.<variant>.so and
* audio.a2dp.<variant>.so
*
* @return: 0 == success, <0 == error and *module == NULL
*/
int hw_get_module_by_class(const char *class_id, const char *inst,
const struct hw_module_t **module);

__END_DECLS

#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
Loading

0 comments on commit 5c07a8a

Please sign in to comment.