TactilityKernel improvements and more (#459)
This commit is contained in:
committed by
GitHub
parent
96eccbdc8d
commit
dfe2c865d1
@@ -8,12 +8,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <Tactility/concurrent/Mutex.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Error.h"
|
||||
#include <Tactility/concurrent/Mutex.h>
|
||||
|
||||
struct Driver;
|
||||
|
||||
/** Enables discovering devices of the same type */
|
||||
@@ -52,24 +53,26 @@ struct Device {
|
||||
/**
|
||||
* Initialize the properties of a device.
|
||||
*
|
||||
* @param[in] dev a device with all non-internal properties set
|
||||
* @return the result code (0 for success)
|
||||
* @param[in] device a device with all non-internal properties set
|
||||
* @retval ERROR_OUT_OF_MEMORY
|
||||
* @retval ERROR_NONE
|
||||
*/
|
||||
int device_construct(struct Device* device);
|
||||
error_t device_construct(struct Device* device);
|
||||
|
||||
/**
|
||||
* Deinitialize the properties of a device.
|
||||
* This fails when a device is busy or has children.
|
||||
*
|
||||
* @param[in] dev
|
||||
* @return the result code (0 for success)
|
||||
* @param[in] device
|
||||
* @retval ERROR_INVALID_STATE
|
||||
* @retval ERROR_NONE
|
||||
*/
|
||||
int device_destruct(struct Device* device);
|
||||
error_t device_destruct(struct Device* device);
|
||||
|
||||
/**
|
||||
* Indicates whether the device is in a state where its API is available
|
||||
*
|
||||
* @param[in] dev non-null device pointer
|
||||
* @param[in] device non-null device pointer
|
||||
* @return true if the device is ready for use
|
||||
*/
|
||||
static inline bool device_is_ready(const struct Device* device) {
|
||||
@@ -83,9 +86,10 @@ static inline bool device_is_ready(const struct Device* device) {
|
||||
* - a bus (if any)
|
||||
*
|
||||
* @param[in] device non-null device pointer
|
||||
* @return 0 on success
|
||||
* @retval ERROR_INVALID_STATE
|
||||
* @retval ERROR_NONE
|
||||
*/
|
||||
int device_add(struct Device* device);
|
||||
error_t device_add(struct Device* device);
|
||||
|
||||
/**
|
||||
* Deregister a device. Remove it from all relevant systems:
|
||||
@@ -94,26 +98,32 @@ int device_add(struct Device* device);
|
||||
* - a bus (if any)
|
||||
*
|
||||
* @param[in] device non-null device pointer
|
||||
* @return 0 on success
|
||||
* @retval ERROR_INVALID_STATE
|
||||
* @retval ERROR_NOT_FOUND
|
||||
* @retval ERROR_NONE
|
||||
*/
|
||||
int device_remove(struct Device* device);
|
||||
error_t device_remove(struct Device* device);
|
||||
|
||||
/**
|
||||
* Attach the driver.
|
||||
*
|
||||
* @warning must call device_construct() and device_add() first
|
||||
* @param device
|
||||
* @return ERROR_INVALID_STATE or otherwise the value of the driver binding result (0 on success)
|
||||
* @retval ERROR_INVALID_STATE
|
||||
* @retval ERROR_RESOURCE when driver binding fails
|
||||
* @retval ERROR_NONE
|
||||
*/
|
||||
int device_start(struct Device* device);
|
||||
error_t device_start(struct Device* device);
|
||||
|
||||
/**
|
||||
* Detach the driver.
|
||||
*
|
||||
* @param device
|
||||
* @return ERROR_INVALID_STATE or otherwise the value of the driver unbinding result (0 on success)
|
||||
* @retval ERROR_INVALID_STATE
|
||||
* @retval ERROR_RESOURCE when driver unbinding fails
|
||||
* @retval ERROR_NONE
|
||||
*/
|
||||
int device_stop(struct Device* device);
|
||||
error_t device_stop(struct Device* device);
|
||||
|
||||
/**
|
||||
* Set or unset a parent.
|
||||
@@ -147,7 +157,7 @@ static inline void device_lock(struct Device* device) {
|
||||
mutex_lock(&device->internal.mutex);
|
||||
}
|
||||
|
||||
static inline int device_try_lock(struct Device* device) {
|
||||
static inline bool device_try_lock(struct Device* device) {
|
||||
return mutex_try_lock(&device->internal.mutex);
|
||||
}
|
||||
|
||||
@@ -156,7 +166,7 @@ static inline void device_unlock(struct Device* device) {
|
||||
}
|
||||
|
||||
static inline const struct DeviceType* device_get_type(struct Device* device) {
|
||||
return device->internal.driver ? device->internal.driver->device_type : NULL;
|
||||
return device->internal.driver ? device->internal.driver->deviceType : NULL;
|
||||
}
|
||||
/**
|
||||
* Iterate through all the known devices
|
||||
@@ -167,18 +177,18 @@ void for_each_device(void* callback_context, bool(*on_device)(struct Device* dev
|
||||
|
||||
/**
|
||||
* Iterate through all the child devices of the specified device
|
||||
* @param callback_context the parameter to pass to the callback. NULL is valid.
|
||||
* @param callbackContext the parameter to pass to the callback. NULL is valid.
|
||||
* @param on_device the function to call for each filtered device. return true to continue iterating or false to stop.
|
||||
*/
|
||||
void for_each_device_child(struct Device* device, void* callback_context, bool(*on_device)(struct Device* device, void* context));
|
||||
void for_each_device_child(struct Device* device, void* callbackContext, bool(*on_device)(struct Device* device, void* context));
|
||||
|
||||
/**
|
||||
* Iterate through all the known devices of a specific type
|
||||
* @param type the type to filter
|
||||
* @param callback_context the parameter to pass to the callback. NULL is valid.
|
||||
* @param callbackContext the parameter to pass to the callback. NULL is valid.
|
||||
* @param on_device the function to call for each filtered device. return true to continue iterating or false to stop.
|
||||
*/
|
||||
void for_each_device_of_type(const struct DeviceType* type, void* callback_context, bool(*on_device)(struct Device* device, void* context));
|
||||
void for_each_device_of_type(const struct DeviceType* type, void* callbackContext, bool(*on_device)(struct Device* device, void* context));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user