LibJuno 1.0.4
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
58// @{"req": ["REQ-IO-011", "REQ-IO-012"]}
64
71
78
85
86#define ReadMsg(iAddr, pcBuff, zBuffSize) \
87(JUNO_I2C_IO_MSG_T) \
88{ \
89 .tRead = (JUNO_I2C_IO_MSG_R_T) \
90 { \
91 .tHdr = {JUNO_I2C_IO_MSG_TYPE_R, iAddr}, \
92 .ptReadBuff = pcBuff, \
93 .zReadBuffSize = zBuffSize \
94 } \
95}
96
97#define WriteMsg(iAddr, pvBuff, zBuffSize) \
98(JUNO_I2C_IO_MSG_T) \
99{ \
100 .tWrite = (JUNO_I2C_IO_MSG_W_T) \
101 { \
102 .tHdr = {JUNO_I2C_IO_MSG_TYPE_W, iAddr}, \
103 .ptWriteBuff = pvBuff, \
104 .zWriteBuffSize = zBuffSize \
105 } \
106}
107
108// @{"req": ["REQ-IO-009"]}
110
111#define JUNO_I2C_IO_TRANSFER(...) (JUNO_I2C_IO_MSG_T[]){__VA_ARGS__}
112
114{
134 // @{"req": ["REQ-IO-010"]}
135 JUNO_STATUS_T (*Transfer)(JUNO_I2C_IO_ROOT_T *ptI2c, const JUNO_I2C_IO_MSG_T *ptArrMsgs, size_t zMsgArrLen);
136};
137
138#ifdef __cplusplus
139}
140#endif
141#endif // JUNO_I2C_IO_API_H
#define JUNO_MODULE_ROOT_DECLARE(NAME_T)
Forward-declare a module root struct type.
Definition module.h:68
#define JUNO_MODULE_EMPTY
Helper for module definitions with no additional members.
Definition module.h:87
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:129
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:51
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:114
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:135
Definition i2c_io_api.h:60
JUNO_I2C_IO_MSG_TYPE_T tType
Definition i2c_io_api.h:61
uint8_t iAddr
Definition i2c_io_api.h:62
Definition i2c_io_api.h:66
uint8_t * ptReadBuff
Definition i2c_io_api.h:68
size_t zReadBuffSize
Definition i2c_io_api.h:69
JUNO_I2C_IO_MSG_HDR_T tHdr
Definition i2c_io_api.h:67
Definition i2c_io_api.h:73
const void * ptWriteBuff
Definition i2c_io_api.h:75
JUNO_I2C_IO_MSG_HDR_T tHdr
Definition i2c_io_api.h:74
size_t zWriteBuffSize
Definition i2c_io_api.h:76
Definition i2c_io_api.h:80
JUNO_I2C_IO_MSG_W_T tWrite
Definition i2c_io_api.h:82
JUNO_I2C_IO_MSG_HDR_T tHdr
Definition i2c_io_api.h:81
JUNO_I2C_IO_MSG_R_T tRead
Definition i2c_io_api.h:83