Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions include/juno/buff/buff_queue_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
MIT License

Copyright (c) 2025 Robin A. Onsay

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
*/

/**
This API has been generated by LibJuno:
https://www.robinonsay.com/libjuno/
*/

/**
This header contains the juno_buff_queue library API
@author
*/
#ifndef JUNO_BUFF_QUEUE_API_H
#define JUNO_BUFF_QUEUE_API_H
#include "juno/macros.h"
#include "juno/memory/memory_api.h"
#include "juno/status.h"
#include "juno/module.h"
#ifdef __cplusplus
extern "C"
{
#endif

typedef struct JUNO_BUFF_QUEUE_API_TAG JUNO_BUFF_QUEUE_API_T;
typedef struct JUNO_BUFF_QUEUE_TAG JUNO_BUFF_QUEUE_T;


struct JUNO_BUFF_QUEUE_TAG
{
size_t iStartIndex;
size_t zLength;
size_t zCapacity;
JUNO_FAILURE_HANDLER_T JUNO_FAILURE_HANDLER;
JUNO_USER_DATA_T *JUNO_FAILURE_USER_DATA;
};

static inline JUNO_STATUS_T JunoBuff_QueueInit(JUNO_BUFF_QUEUE_T *ptQueue, size_t zCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData)
{
ASSERT_EXISTS(ptQueue);
ptQueue->iStartIndex = 0;
ptQueue->zLength = 0;
ptQueue->zCapacity = zCapacity;
ptQueue->_pfcnFailureHandler = pfcnFailureHdlr;
ptQueue->_pvFailurUserData = pvFailureUserData;
return JUNO_STATUS_SUCCESS;
}

static inline JUNO_STATUS_T JunoBuff_QueueEnqueue(JUNO_BUFF_QUEUE_T *ptQueue, size_t *ptRetIndex)
{
ASSERT_EXISTS(ptQueue);
if(ptQueue->zLength < ptQueue->zCapacity)
{
ptQueue->zLength += 1;
}
else
{
FAIL(JUNO_STATUS_INVALID_SIZE_ERROR, ptQueue->_pfcnFailureHandler, ptQueue->_pvFailurUserData, "Failed to enqueue data");
return JUNO_STATUS_INVALID_SIZE_ERROR;
}
if(ptRetIndex)
{
*ptRetIndex = ptQueue->zLength % ptQueue->zCapacity;
}
return JUNO_STATUS_SUCCESS;
}

static inline JUNO_STATUS_T JunoBuff_QueueDequeue(JUNO_BUFF_QUEUE_T *ptQueue, size_t *ptRetIndex)
{
ASSERT_EXISTS(ptQueue);
if(ptQueue->zLength > 0)
{
ptQueue->iStartIndex = (ptQueue->iStartIndex + 1) % ptQueue->zCapacity;
ptQueue->zLength -= 1;
if(ptRetIndex)
{
*ptRetIndex = ptQueue->iStartIndex;
}
return JUNO_STATUS_SUCCESS;
}
FAIL(JUNO_STATUS_ERR, ptQueue->_pfcnFailureHandler, ptQueue->_pvFailurUserData, "Queue is empty");
return JUNO_STATUS_ERR;
}

static inline JUNO_STATUS_T JunoBuff_QueueGetIndex(JUNO_BUFF_QUEUE_T *ptQueue, size_t *ptRetIndex)
{
ASSERT_EXISTS(ptQueue);
if(*ptRetIndex)
{
*ptRetIndex = ptQueue->iStartIndex;
}
return JUNO_STATUS_SUCCESS;
}


#ifdef __cplusplus
}
#endif
#endif // JUNO_BUFF_QUEUE_API_H
107 changes: 107 additions & 0 deletions include/juno/buff/buff_stack_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
MIT License

Copyright (c) 2025 Robin A. Onsay

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
*/

/**
This API has been generated by LibJuno:
https://www.robinonsay.com/libjuno/
*/

/**
This header contains the juno_buff_stack library API
@author
*/
#ifndef JUNO_BUFF_STACK_API_H
#define JUNO_BUFF_STACK_API_H
#include "juno/macros.h"
#include "juno/memory/memory_api.h"
#include "juno/status.h"
#include "juno/module.h"
#ifdef __cplusplus
extern "C"
{
#endif

typedef struct JUNO_BUFF_STACK_API_TAG JUNO_BUFF_STACK_API_T;
typedef struct JUNO_BUFF_STACK_TAG JUNO_BUFF_STACK_T;

struct JUNO_BUFF_STACK_TAG
{
size_t zLength;
size_t zCapacity;
JUNO_FAILURE_HANDLER_T JUNO_FAILURE_HANDLER;
JUNO_USER_DATA_T *JUNO_FAILURE_USER_DATA;
};

static inline JUNO_STATUS_T JunoBuff_StackInit(JUNO_BUFF_STACK_T *ptStack, size_t zCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData)
{
ASSERT_EXISTS(ptStack);
ptStack->zLength = 0;
ptStack->zCapacity = zCapacity;
ptStack->_pfcnFailureHandler = pfcnFailureHdlr;
ptStack->_pvFailurUserData = pvFailureUserData;
return JUNO_STATUS_SUCCESS;
}

static inline JUNO_STATUS_T JunoBuff_StackPush(JUNO_BUFF_STACK_T *ptStack, size_t *ptRetIndex)
{
ASSERT_EXISTS(ptStack);
if(ptStack->zLength < ptStack->zCapacity)
{
if(ptRetIndex)
{
*ptRetIndex = ptStack->zLength;
}
ptStack->zLength += 1;
}
else
{
FAIL(JUNO_STATUS_INVALID_SIZE_ERROR, ptStack->_pfcnFailureHandler, ptStack->_pvFailurUserData, "Failed to enqueue data");
return JUNO_STATUS_INVALID_SIZE_ERROR;
}
return JUNO_STATUS_SUCCESS;
}

static inline JUNO_STATUS_T JunoBuff_StackPop(JUNO_BUFF_STACK_T *ptStack, size_t *ptRetIndex)
{
ASSERT_EXISTS(ptStack);
if(ptStack->zLength > 0)
{
ptStack->zLength -= 1;
if(ptRetIndex)
{
*ptRetIndex = ptStack->zLength;
}
return JUNO_STATUS_SUCCESS;
}
return JUNO_STATUS_INVALID_SIZE_ERROR;
}

static inline JUNO_STATUS_T JunoBuff_StackPeek(JUNO_BUFF_STACK_T *ptStack, size_t *ptRetIndex)
{
ASSERT_EXISTS(ptStack);
if(*ptRetIndex)
{
*ptRetIndex = ptStack->zLength;
}
return JUNO_STATUS_SUCCESS;
}


#ifdef __cplusplus
}
#endif
#endif // JUNO_BUFF_STACK_API_H
1 change: 1 addition & 0 deletions include/juno/io/async_io_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "juno/status.h"
#include "juno/module.h"
#include "juno/time/time_api.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
Expand Down
126 changes: 126 additions & 0 deletions include/juno/io/i2c_io_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
MIT License

Copyright (c) 2025 Robin A. Onsay

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
*/

/**
This API has been generated by LibJuno:
https://www.robinonsay.com/libjuno/
*/

/**
This header contains the io library API
@author
*/
#ifndef JUNO_I2C_IO_API_H
#define JUNO_I2C_IO_API_H
#include "juno/status.h"
#include "juno/module.h"
#include "juno/time/time_api.h"
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif

typedef struct JUNO_I2C_IO_API_TAG JUNO_I2C_IO_API_T;
typedef struct JUNO_I2C_IO_MSG_R_TAG JUNO_I2C_IO_MSG_R_T;
typedef struct JUNO_I2C_IO_MSG_W_TAG JUNO_I2C_IO_MSG_W_T;
typedef struct JUNO_I2C_IO_MSG_HDR_TAG JUNO_I2C_IO_MSG_HDR_T;
typedef union JUNO_I2C_IO_MSG_TAG JUNO_I2C_IO_MSG_T;
JUNO_MODULE_DECLARE(JUNO_I2C_IO_T);
JUNO_MODULE_BASE_DECLARE(JUNO_I2C_IO_BASE_T);

typedef enum JUNO_I2C_IO_MSG_TYPE_TAG
{
JUNO_I2C_IO_MSG_TYPE_RESERVED = 0,
JUNO_I2C_IO_MSG_TYPE_W = 1,
JUNO_I2C_IO_MSG_TYPE_R = 2,
} JUNO_I2C_IO_MSG_TYPE_T;

struct JUNO_I2C_IO_MSG_HDR_TAG
{
JUNO_I2C_IO_MSG_TYPE_T tType;
uint8_t iAddr;
};

struct JUNO_I2C_IO_MSG_R_TAG
{
JUNO_I2C_IO_MSG_HDR_T tHdr;
uint8_t *ptReadBuff;
size_t zReadBuffSize;
};

struct JUNO_I2C_IO_MSG_W_TAG
{
JUNO_I2C_IO_MSG_HDR_T tHdr;
const void *ptWriteBuff;
size_t zWriteBuffSize;
};

union JUNO_I2C_IO_MSG_TAG
{
JUNO_I2C_IO_MSG_HDR_T tHdr;
JUNO_I2C_IO_MSG_W_T tWrite;
JUNO_I2C_IO_MSG_R_T tRead;
};

#define ReadMsg(iAddr, pcBuff, zBuffSize) \
(JUNO_I2C_IO_MSG_T) \
{ \
.tRead = (JUNO_I2C_IO_MSG_R_T) \
{ \
.tHdr = {JUNO_I2C_IO_MSG_TYPE_R, iAddr}, \
.ptReadBuff = pcBuff, \
.zReadBuffSize = zBuffSize \
} \
}

#define WriteMsg(iAddr, pvBuff, zBuffSize) \
(JUNO_I2C_IO_MSG_T) \
{ \
.tWrite = (JUNO_I2C_IO_MSG_W_T) \
{ \
.tHdr = {JUNO_I2C_IO_MSG_TYPE_W, iAddr}, \
.ptWriteBuff = pvBuff, \
.zWriteBuffSize = zBuffSize \
} \
}

JUNO_MODULE_BASE(JUNO_I2C_IO_BASE_T, JUNO_I2C_IO_API_T, JUNO_MODULE_EMPTY);

#define JUNO_I2C_IO_TRANSFER(...) (JUNO_I2C_IO_MSG_T[]){__VA_ARGS__}

struct JUNO_I2C_IO_API_TAG
{
/**
Perform an I2C transfer.
A typical call would look like:

```
ptApi->Transfer(ptI2c, JUNO_I2C_IO_TRANSFER{WriteMsg(0xFF, ptMyWriteBuff, sizeof(ptMyWriteBuff))}, 1)
// OR
JUNO_I2C_IO_MSG_T ptArrTransfer[] = JUNO_I2C_IO_TRANSFER{WriteMsg(0xFF, ptMyWriteBuff, sizeof(ptMyWriteBuff))};
ptApi->Transfer(ptI2c, ptArrTransfer, sizeof(ptArrTransfer) / sizeof(ptArrTransfer[0]));
```
*/
JUNO_STATUS_T (*Transfer)(JUNO_I2C_IO_T *ptI2c, const JUNO_I2C_IO_MSG_T *ptArrMsgs, size_t zMsgArrLen);
};

#ifdef __cplusplus
}
#endif
#endif // JUNO_I2C_IO_API_H
Loading