/** * @file Demo1.c * @author Rick Chan * @brief * @version 0.1 * @date 2020-08-01 * * @copyright Copyright (c) 2020 * */ #include "Device.h" typedef struct DEMO1_OBJ { // Some private data for instance uint8_t ID; }ST_DEMO1_OBJ; ST_DEMO1_OBJ Demo1Obj[2]; static EU_ERR Demo1Init(ST_DEVICE* dev) { ST_DEMO1_OBJ* obj = (ST_DEMO1_OBJ*)dev->Prv; if(&Demo1Obj[0]==obj) { // Do something. return EC_OK; } else if(&Demo1Obj[1]==obj) { // Do something. return EC_OK; } return EC_ERESOURCES; } static EU_ERR Demo1Open(ST_DEVICE* dev) { ST_DEMO1_OBJ* obj = (ST_DEMO1_OBJ*)dev->Prv; if(&Demo1Obj[0]==obj) { // Do something. return EC_OK; } else if(&Demo1Obj[1]==obj) { // Do something. return EC_OK; } return EC_ERESOURCES; } /** * @brief * * @param dev * @param ex contains additional control information. * @param buf data pointer to be write. * @param nbytes data size. * @param timeout * @return int64_t real size readed. */ static int64_t Demo1Read(ST_DEVICE* dev, void* ex, void* buf, int64_t nbytes, uint32_t timeout) { ST_DEMO1_OBJ* obj = (ST_DEMO1_OBJ*)dev->Prv; int64_t rsize; UNUSED(timeout); if(&Demo1Obj[0]==obj) { // Do something. return nbytes; } else if(&Demo1Obj[1]==obj) { // Do something. return nbytes; } return EC_EPAM; } /** * @brief Same as Demo1Read * * @param dev * @param ex Same as Demo1Read * @param buf * @param nbytes * @param timeout * @return int64_t */ static int64_t Demo1Write(ST_DEVICE* dev, void* ex, void* buf, int64_t nbytes, uint32_t timeout) { ST_MFIS_OBJ* obj = (ST_MFIS_OBJ*)dev->Prv; UNUSED(timeout); if(&Demo1Obj[0]==obj) { // Do something. return nbytes; } else if(&Demo1Obj[1]==obj) { // Do something. return nbytes; } return EC_EPAM; } ST_DEVICE Demo1[2] = { { .Init = Demo1Init, .Open = Demo1Open, .Close = NULL, .Read = Demo1Read, .Write = Demo1Write, .Seek = NULL, .IOCtl = NULL, .PwCtl = NULL, .EnInt = NULL, .DisInt = NULL, .Prv = (void*)&Demo1Obj[0], }, { .Init = Demo1Init, .Open = Demo1Open, .Close = NULL, .Read = Demo1Read, .Write = Demo1Write, .Seek = NULL, .IOCtl = NULL, .PwCtl = NULL, .EnInt = NULL, .DisInt = NULL, .Prv = (void*)&Demo1Obj[1], } };