/**
|
* @file Ems_object.h
|
* @author your name (you@domain.com)
|
* @brief
|
* @version 0.1
|
* @date 2023-04-05
|
*
|
* @copyright Copyright (c) 2023
|
*
|
*/
|
|
#ifndef Ems_OBJECT_H
|
#define Ems_OBJECT_H
|
|
/* includes ----------------------------------------------------------------- */
|
#include <stdbool.h>
|
#include <stdint.h>
|
#include "Ems_def.h"
|
|
#ifdef __cplusplus
|
extern "C" {
|
#endif
|
|
/* public define ------------------------------------------------------------ */
|
enum ems_obect_type
|
{
|
EMS_OBJ_PIN = 0,
|
EMS_OBJ_PWM,
|
EMS_OBJ_ADC,
|
EMS_OBJ_DAC,
|
EMS_OBJ_UART,
|
EMS_OBJ_SPI,
|
EMS_OBJ_I2C,
|
EMS_OBJ_CAN,
|
EMS_OBJ_MAX
|
};
|
|
/* public typedef ----------------------------------------------------------- */
|
typedef struct ems_obj_attr
|
{
|
void *user_data;
|
uint8_t type;
|
bool standlone;
|
} ems_obj_attr_t;
|
|
typedef struct ems_object
|
{
|
struct ems_object *next;
|
const char *name;
|
const struct ems_ops *ops;
|
uint16_t count_open;
|
ems_obj_attr_t attr;
|
} ems_object_t;
|
|
typedef struct ems_ops
|
{
|
ems_err_t (* open)(ems_object_t * const me);
|
ems_err_t (* close)(ems_object_t * const me);
|
int32_t (* read)(ems_object_t * const me, void *buffer, uint32_t size);
|
int32_t (* write)(ems_object_t * const me, const void *buffer, uint32_t size);
|
} ems_ops_t;
|
|
|
/* For io-level driver. */
|
void ems_register(ems_object_t * const me, const char *name,
|
const ems_ops_t *ops,
|
ems_obj_attr_t *attr);
|
|
/* For high-level code. */
|
ems_object_t *ems_find(const char *name);
|
ems_err_t ems_open(ems_object_t * const me);
|
ems_err_t ems_close(ems_object_t * const me);
|
int32_t ems_read(ems_object_t * const me, void *buffer, uint32_t size);
|
int32_t ems_write(ems_object_t * const me, const void *buffer, uint32_t size);
|
|
#ifdef __cplusplus
|
}
|
#endif
|
|
#endif /* EMS_OBJECT_H */
|