// ----------------------------------------------------------------------------- /// @file IODevice.h /// @brief File description // ----------------------------------------------------------------------------- // Micro-Key bv // Industrieweg 28, 9804 TG Noordhorn // Postbus 92, 9800 AB Zuidhorn // The Netherlands // Tel: +31 594 503020 // Fax: +31 594 505825 // Email: support@microkey.nl // Web: www.microkey.nl // ----------------------------------------------------------------------------- /// $Revision$ /// $Author$ /// $Date$ // (c) 2017 Micro-Key bv // ----------------------------------------------------------------------------- /** * %IODevice implementation * \defgroup IODevice Package IODevice * \ingroup HAL * @{ */ #ifndef MISC_INC_IODEVICE_H_ #define MISC_INC_IODEVICE_H_ // ----------------------------------------------------------------------------- // Include files // ----------------------------------------------------------------------------- #include #include "stm32f10x.h" // ----------------------------------------------------------------------------- // Constant and macro definitions // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // Type definitions. // ----------------------------------------------------------------------------- struct IODevice; typedef ErrorStatus (*ReadFunction)(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength); typedef ErrorStatus (*WriteFunction)(const struct IODevice* self, const char* buffer, size_t length); struct IODevice { ReadFunction _read; WriteFunction _write; }; // ----------------------------------------------------------------------------- // Function declarations // ----------------------------------------------------------------------------- /** ---------------------------------------------------------------------------- * IODevice_construct * Constructor for a new IO Device * * @param self IO Device instance to create * @param read Pointer to read function * @param write Pointer to write function * * @return ErrorStatus SUCCESS if construction as successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus IODevice_construct (struct IODevice* self, ReadFunction read, WriteFunction write); /** ---------------------------------------------------------------------------- * IODevice_write * Writes a character buffer to IO Device * * @param self IO Device instance to create * @param buffer The character string to write to device * @param length length (in number of bytes) of buffer * * @return ErrorStatus SUCCESS if construction as successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus IODevice_write(const struct IODevice* self, const char* buffer, size_t length); /** ---------------------------------------------------------------------------- * IODevice_read * Reads from IO Device * * @param self IO Device instance to create * @param buffer Pointer to location where read data is * written to * @param length length (in number of bytes) of the read * request * @param actualLength actual length that has been read. Can * differ from argument length, but can only * be smaller or equal. * * @return ErrorStatus SUCCESS if construction as successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus IODevice_read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength); #endif /* MISC_INC_IODEVICE_H_ */ /** @} */