diff options
| author | Aditya Naik | 2020-08-03 14:42:06 -0400 |
|---|---|---|
| committer | Aditya Naik | 2020-08-03 14:42:06 -0400 |
| commit | 11a52e4e88bcad1e6bddcf02f78e1cc5eaaec508 (patch) | |
| tree | d7f725c30e618994a0650607ede73ab3efc72c67 /src/stream_i2c.c | |
| parent | 81b3f3d5336eab67e8eb21bb4011e552f3895a4e (diff) | |
RTOS skeleton with (UNIX) POSIX calls. Reorg of stream files
Diffstat (limited to 'src/stream_i2c.c')
| -rw-r--r-- | src/stream_i2c.c | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/src/stream_i2c.c b/src/stream_i2c.c deleted file mode 100644 index b149756..0000000 --- a/src/stream_i2c.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "stream_i2c.h" -#include "port.h" -#include "stream.h" - -int i2c_read(uint8_t* buf, size_t count, void **vptr, void *sptr) -{ - p_stream_t *stream = (p_stream_t*)sptr; - I2C_HandleTypeDef dev = *(I2C_HandleTypeDef*)stream->props[DEVICE]; - - uint16_t addr = *(uint16_t*)vptr[0]; - uint32_t timeout = *(uint32_t*)vptr[1]; - uint16_t AF_limit = *(uint32_t*)vptr[2]; - - int error, AF_counter = 0; - while (HAL_I2C_Master_Receive(&dev, addr, buf, count, timeout) != HAL_OK) { - if ((error = HAL_I2C_GetError(&dev)) != HAL_I2C_ERROR_AF) { - return error; - } - else if (++AF_counter > AF_limit) { - return HAL_I2C_ERROR_AF; - } - } - return 0; -} - -int i2c_write(uint8_t* buf, size_t count, void **vptr, void *sptr) -{ - p_stream_t *stream = (p_stream_t*)sptr; - I2C_HandleTypeDef dev = *(I2C_HandleTypeDef*)stream->props[DEVICE]; - uint16_t addr = *(uint16_t*)vptr[1]; - uint32_t timeout = *(uint32_t*)vptr[2]; - - while (HAL_I2C_Master_Transmit(&dev, addr, buf, count, timeout) != HAL_OK) { - return HAL_I2C_GetError(&dev); - } - return 0; -} |
