LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
i2c_io_api.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
32#ifndef JUNO_I2C_IO_API_H
33#define JUNO_I2C_IO_API_H
34#include "juno/status.h"
35#include "juno/module.h"
36#include <stdbool.h>
37#include <stddef.h>
38#include <stdint.h>
39#ifdef __cplusplus
40extern "C"
41{
42#endif
43
49JUNO_MODULE_ROOT_DECLARE(JUNO_I2C_IO_ROOT_T);
50
57
63
70
77
84
85#define ReadMsg(iAddr, pcBuff, zBuffSize) \
86(JUNO_I2C_IO_MSG_T) \
87{ \
88 .tRead = (JUNO_I2C_IO_MSG_R_T) \
89 { \
90 .tHdr = {JUNO_I2C_IO_MSG_TYPE_R, iAddr}, \
91 .ptReadBuff = pcBuff, \
92 .zReadBuffSize = zBuffSize \
93 } \
94}
95
96#define WriteMsg(iAddr, pvBuff, zBuffSize) \
97(JUNO_I2C_IO_MSG_T) \
98{ \
99 .tWrite = (JUNO_I2C_IO_MSG_W_T) \
100 { \
101 .tHdr = {JUNO_I2C_IO_MSG_TYPE_W, iAddr}, \
102 .ptWriteBuff = pvBuff, \
103 .zWriteBuffSize = zBuffSize \
104 } \
105}
106
108
109#define JUNO_I2C_IO_TRANSFER(...) (JUNO_I2C_IO_MSG_T[]){__VA_ARGS__}
110
112{
132 JUNO_STATUS_T (*Transfer)(JUNO_I2C_IO_ROOT_T *ptI2c, const JUNO_I2C_IO_MSG_T *ptArrMsgs, size_t zMsgArrLen);
133};
134
135#ifdef __cplusplus
136}
137#endif
138#endif // JUNO_I2C_IO_API_H
#define JUNO_MODULE_ROOT_DECLARE(NAME_T)
Forward-declare a module root struct type.
Definition module.h:67
#define JUNO_MODULE_EMPTY
Helper for module definitions with no additional members.
Definition module.h:86
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:126
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:49
enum JUNO_I2C_IO_MSG_TYPE_TAG JUNO_I2C_IO_MSG_TYPE_T
JUNO_I2C_IO_MSG_TYPE_TAG
Definition i2c_io_api.h:52
@ JUNO_I2C_IO_MSG_TYPE_R
Definition i2c_io_api.h:55
@ JUNO_I2C_IO_MSG_TYPE_RESERVED
Definition i2c_io_api.h:53
@ JUNO_I2C_IO_MSG_TYPE_W
Definition i2c_io_api.h:54
Module system and dependency injection primitives for LibJuno.
Status codes and failure-handling helpers for LibJuno.
Definition i2c_io_api.h:112
JUNO_STATUS_T(* Transfer)(JUNO_I2C_IO_ROOT_T *ptI2c, const JUNO_I2C_IO_MSG_T *ptArrMsgs, size_t zMsgArrLen)
Perform an I2C transfer composed of one or more messages. Example usage:
Definition i2c_io_api.h:132
Definition i2c_io_api.h:59
JUNO_I2C_IO_MSG_TYPE_T tType
Definition i2c_io_api.h:60
uint8_t iAddr
Definition i2c_io_api.h:61
Definition i2c_io_api.h:65
uint8_t * ptReadBuff
Definition i2c_io_api.h:67
size_t zReadBuffSize
Definition i2c_io_api.h:68
JUNO_I2C_IO_MSG_HDR_T tHdr
Definition i2c_io_api.h:66
Definition i2c_io_api.h:72
const void * ptWriteBuff
Definition i2c_io_api.h:74
JUNO_I2C_IO_MSG_HDR_T tHdr
Definition i2c_io_api.h:73
size_t zWriteBuffSize
Definition i2c_io_api.h:75
Definition i2c_io_api.h:79
JUNO_I2C_IO_MSG_W_T tWrite
Definition i2c_io_api.h:81
JUNO_I2C_IO_MSG_HDR_T tHdr
Definition i2c_io_api.h:80
JUNO_I2C_IO_MSG_R_T tRead
Definition i2c_io_api.h:82