commit f91b45706694c9650f3ccdb45355ef471e0067c3 Author: cfif Date: Tue Sep 30 15:52:33 2025 +0300 Добавлены интерфейсы и драйверы diff --git a/Inc/BaseTypes.h b/Inc/BaseTypes.h new file mode 100644 index 0000000..5522bb5 --- /dev/null +++ b/Inc/BaseTypes.h @@ -0,0 +1,11 @@ +// +// Created by cfif on 13.10.22. +// + +#ifndef BASETYPES_H +#define BASETYPES_H + +#include "BaseTypes/String.h" +#include "BaseTypes/Strings.h" + +#endif //BASETYPES_H diff --git a/Inc/BaseTypes/String.h b/Inc/BaseTypes/String.h new file mode 100644 index 0000000..a8c787b --- /dev/null +++ b/Inc/BaseTypes/String.h @@ -0,0 +1,24 @@ +// +// Created by xemon on 10.11.22. +// + +#ifndef UVEOS_ON_NATION_STRING_H +#define UVEOS_ON_NATION_STRING_H + +#include "stdint.h" + +typedef struct { + uint8_t length; + uint8_t max_length; + uint8_t readonly; + char str[32]; +} tString; + + +uint8_t getStrLen(char *str); + +void vInitStringOnlyLength(tString *tstr, uint8_t length); + +void vInitString(tString *tstr, void *str, uint8_t length, uint8_t max_length, uint8_t readonly); + +#endif //UVEOS_ON_NATION_STRING_H diff --git a/Inc/BaseTypes/Strings.h b/Inc/BaseTypes/Strings.h new file mode 100644 index 0000000..00103ba --- /dev/null +++ b/Inc/BaseTypes/Strings.h @@ -0,0 +1,81 @@ +// +// Created by xemon on 10.11.22. +// + +#ifndef UVEOS_ON_NATION_STRINGS_H +#define UVEOS_ON_NATION_STRINGS_H + +#include "stdint.h" + +#define tString(T) \ +typedef struct { \ + uint8_t length; \ + char data[T]; \ +} tString##T; + +tString(8) +tString(16) +tString(32) +tString(64) +tString(128) +tString(255) + +typedef struct { + uint8_t length; + char *data; +} tStringStatic; + +typedef struct { + uint8_t *length; + char *data; +} tStringLink; + + +#define StringGetLinkTemplateD(T) \ +tStringLink String##T##GetLink(tString##T *string); + +StringGetLinkTemplateD(8) + +StringGetLinkTemplateD(16) + +StringGetLinkTemplateD(32) + +StringGetLinkTemplateD(64) + +StringGetLinkTemplateD(128) + +StringGetLinkTemplateD(255) + +StringGetLinkTemplateD(Static) + + +#define StringStaticInit(STR) (tStringStatic){.data = (char*)(STR), .length = sizeof(STR)-1} +#define StringArrInit(STR) (tStringStatic){.data = (char*)(STR), .length = sizeof(STR)} + + +#define StringCopyTD(T) \ +void String##T##Copy(tString##T *dest, char *source, uint8_t sourceLen); + +StringCopyTD(8) + +StringCopyTD(16) + +StringCopyTD(32) + +StringCopyTD(64) + +StringCopyTD(128) + +StringCopyTD(255) + +#define StringCopyStaticTemplate(T) \ + String##T##Copy(DEST,STR,sizeof(STR)-1) + +#define String8CopyStatic(DEST, STR) String8Copy(DEST,STR,sizeof(STR)-1) +#define String16CopyStatic(DEST, STR) String16Copy(DEST,STR,sizeof(STR)-1) +#define String32CopyStatic(DEST, STR) String32Copy(DEST,STR,sizeof(STR)-1) +#define String64CopyStatic(DEST, STR) String64Copy(DEST,STR,sizeof(STR)-1) +#define String128CopyStatic(DEST, STR) String128Copy(DEST,STR,sizeof(STR)-1) +#define String255CopyStatic(DEST, STR) String128Copy(DEST,STR,sizeof(STR)-1) + +#endif //UVEOS_ON_NATION_STRINGS_H diff --git a/Src/BaseTypes.c b/Src/BaseTypes.c new file mode 100644 index 0000000..edb4717 --- /dev/null +++ b/Src/BaseTypes.c @@ -0,0 +1,27 @@ +// +// Created by cfif on 13.10.22. +// + +#include +#include "BaseTypes.h" + +uint8_t getStrLen(char *str) { + uint8_t len = 0; + while (str[len]) { + ++len; + } + return len; +} + +void vInitString(tString *tstr, void *str, uint8_t length, uint8_t max_length, uint8_t readonly) { + + tstr->length = length; + tstr->max_length = max_length; + tstr->readonly = readonly; + memcpy(tstr->str, str, length); + +} + +void vInitStringOnlyLength(tString *tstr, uint8_t length) { + tstr->length = length; +} \ No newline at end of file diff --git a/Src/Strings.c b/Src/Strings.c new file mode 100644 index 0000000..b3ca2b4 --- /dev/null +++ b/Src/Strings.c @@ -0,0 +1,43 @@ +// +// Created by xemon on 11.11.22. +// + +#include "BaseTypes/Strings.h" +#include "memory.h" + +#define StringGetLinkTemplate(T) \ +tStringLink String##T##GetLink(tString##T *string) { \ + return (tStringLink) {.length = &string->length, .data = string->data}; \ +} + +StringGetLinkTemplate(8) + +StringGetLinkTemplate(16) + +StringGetLinkTemplate(32) + +StringGetLinkTemplate(64) + +StringGetLinkTemplate(128) + +StringGetLinkTemplate(Static) + + +#define StringStaticInit(STR) (tStringStatic){.data = STR, .length = sizeof(STR)-1} + + +#define StringCopyT(T) \ +void String##T##Copy(tString##T *dest, char *source, uint8_t sourceLen) { \ + dest->length = sourceLen > T ? T : sourceLen; \ + memcpy(dest->data, source, dest->length); \ +} + +StringCopyT(8) + +StringCopyT(16) + +StringCopyT(32) + +StringCopyT(64) + +StringCopyT(128) diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..71971cd --- /dev/null +++ b/modular.json @@ -0,0 +1,10 @@ +{ + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file