|
/**
|
* @file Ems_pin.c
|
* @author your name (you@domain.com)
|
* @brief
|
* @version 0.1
|
* @date 2023-04-05
|
*
|
* @copyright Copyright (c) 2023
|
*
|
*/
|
#include <string.h>
|
#include "dev_pin.h"
|
#include "ems_assert.h"
|
|
#ifdef __cplusplus
|
extern "C" {
|
#endif
|
|
EMS_TAG("EMS_PIN")
|
|
static ems_ops_t _obj_ops =
|
{
|
.open = NULL,
|
.close = NULL,
|
.read = NULL,
|
.write = NULL,
|
};
|
|
/**
|
* @brief EMS pin initialization.
|
* @param me this pointer
|
* @param name pin's name.
|
* @param mode pin's mode.
|
* @retval None
|
*/
|
void ems_pin_register(ems_pin_t * const me,
|
const char *name,
|
const ems_pin_ops_t *ops,
|
void *user_data)
|
{
|
ems_assert(me != NULL);
|
ems_assert(name != NULL);
|
ems_assert(ops != NULL);
|
|
ems_obj_attr_t attr =
|
{
|
.user_data = user_data,
|
.standlone = true,
|
.type = EMS_OBJ_PIN,
|
};
|
|
ems_register(&me->super, name, &_obj_ops, &attr);
|
|
me->ops = ops;
|
me->ops->init(me);
|
me->status = me->ops->get_status(me);
|
}
|
|
/**
|
* @brief
|
*
|
* @param me
|
* @param mode
|
*/
|
void ems_pin_set_mode(ems_object_t * const me, uint8_t mode)
|
{
|
ems_assert(me != NULL);
|
|
ems_pin_t *pin = (ems_pin_t *)me;
|
if (pin->mode != mode)
|
{
|
pin->ops->set_mode(pin, mode);
|
pin->mode = mode;
|
}
|
}
|
|
|
/**
|
* @brief
|
*
|
* @param me
|
* @return true
|
* @return false
|
*/
|
bool ems_pin_get_status(ems_object_t * const me)
|
{
|
ems_assert(me != NULL);
|
ems_pin_t *pin = (ems_pin_t *)me;
|
|
pin->status = pin->ops->get_status(pin);
|
|
return pin->status;
|
}
|
|
/**
|
* @brief
|
*
|
* @param me
|
* @param status
|
*/
|
void ems_pin_set_status(ems_object_t * const me, bool status)
|
{
|
ems_assert(me != NULL);
|
|
ems_pin_t *pin = (ems_pin_t *)me;
|
ems_assert(pin->mode == PIN_MODE_OUTPUT || pin->mode == PIN_MODE_OUTPUT_OD);
|
|
if (status != pin->status)
|
{
|
pin->ops->set_status(pin, status);
|
ems_pin_get_status(me);
|
ems_assert(pin->status == status);
|
}
|
}
|
|
#ifdef __cplusplus
|
}
|
#endif
|
|
/* ----------------------------- end of file -------------------------------- */
|