From 345e4b1b1c9e9774bd3ceae1f359590ad23dae8f Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Wed, 18 Jan 2023 21:43:14 +0100 Subject: [PATCH] libsi24: basic setup - header file logic - basic functions - basic CMake --- .gitignore | 1 + CMakeLists.txt | 36 +++++++++++++++++++++++++++++ libsi24.c | 38 +++++++++++++++++++++++++++++++ libsi24.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ libsi24reg.h | 32 ++++++++++++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 libsi24.c create mode 100644 libsi24.h create mode 100644 libsi24reg.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..15484ff --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.5) +project(libsi24 + VERSION 0.30.0 + LANGUAGES C +) +set(PROJECT_DESCRIPTION "si24r1 library") +set(PROJECT_HOMEPAGE_URL https://github.com/robinkrens/libsi24) + +add_compile_options(-Wall -Wextra -pedantic -Werror) + +add_library(libsi24 libsi24.c) + +target_include_directories(libsi24 + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +include(GNUInstallDirs) + +install(TARGETS libsi24 + EXPORT libsi24-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) +install(FILES libsi24.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +install(EXPORT libsi24-export + FILE libsi24.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libsi24 +) + +include(CPack) diff --git a/libsi24.c b/libsi24.c new file mode 100644 index 0000000..43ef472 --- /dev/null +++ b/libsi24.c @@ -0,0 +1,38 @@ +/** + * File : libsi24.c + * Author : Robin Krens + * Date : 18.01.2023 + * Last Modified Date: 18.01.2023 + * Last Modified By : Robin Krens + */ + +#include +#include +#include +#include + +#include "libsi24.h" +#include "libsi24reg.h" + +struct si24_t { + const si24_opts_t *opts; + const si24_ioctl_t *ctl; + si24_event_handler_t eh; +}; + +si24_t* si24_init(const si24_opts_t *opts, si24_event_handler_t eh) +{ + struct si24_t *si = (si24_t*) calloc(1, sizeof(si24_t)); + if (si == 0) + return 0; + + si->opts = opts; + si->ctl = opts->ioctl; + si->eh = eh; + + return si; +} + +int main(void) +{ +} diff --git a/libsi24.h b/libsi24.h new file mode 100644 index 0000000..5e2f53c --- /dev/null +++ b/libsi24.h @@ -0,0 +1,72 @@ +/** + * File : libsi24.h + * Author : Robin Krens + * Date : 18.01.2023 + * Last Modified Date: 18.01.2023 + * Last Modified By : Robin Krens + */ + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +enum si24_status_t { + SHUTDOWN = 0, + STANDBY, + IDLETX, + TX, + RX +}; + +typedef enum si24_status_t si24_status_t; + +enum si24_type_t { + RECV = 0, + SEND +}; + +typedef enum si24_type_t si24_type_t; + +enum si24_crc_t { + ONE_BYTE = 1, + TWO_BYTE = 2 +}; + +typedef enum si24_crc_t si24_crc_t; + +enum si24_event_t { + TEST = 0 +}; + +typedef enum si24_event_t si24_event_t; + +/* low level IO control */ +typedef struct { + size_t (*read)(unsigned char* buf, size_t size); + size_t (*write)(const unsigned char* buf, size_t size); +} si24_ioctl_t; + +typedef struct { + si24_type_t type; + unsigned enable_ack; + si24_crc_t crc; + si24_ioctl_t *ioctl; + unsigned msg_len; +} si24_opts_t; + +/* private data structure */ +typedef struct si24_t si24_t; + +typedef void (*si24_event_handler_t)(si24_t* si24, si24_event_t* event); + +extern si24_t* si24_init(const si24_opts_t* si24opts, si24_event_handler_t eh); +extern void si24_free(si24_t* si24); +extern void si24_send(si24_t* si24, const char* buf, size_t size); +extern void si24_recv(si24_t* si24, char* buf, size_t size); +extern void si24_reset(si24_t* si24); + +#if defined(__cplusplus) +} +#endif diff --git a/libsi24reg.h b/libsi24reg.h new file mode 100644 index 0000000..ff9cdf3 --- /dev/null +++ b/libsi24reg.h @@ -0,0 +1,32 @@ +/** + * File : libsi24reg.h + * Author : Robin Krens + * Date : 18.01.2023 + * Last Modified Date: 18.01.2023 + * Last Modified By : Robin Krens + */ + + +#define SI24_READ_REG 0x00 +#define SI24_WRITE_REG 0x20 +#define SI24_R_RX_PAYLOAD 0x61 +#define SI24_W_TX_PAYLOAD 0xA0 +#define SI24_FLUSH_TX 0xE1 + +typedef struct { + union { + unsigned char byte; + struct { + unsigned PRIM_XR : 1; + unsigned PWR_UP : 1; + unsigned CRCO : 1; + unsigned EN_CRC : 1; + unsigned MASK_MAX_RT : 1; + unsigned MASK_TX_DS : 1; + unsigned MAKS_RX_DS : 1; + unsigned _RESERVED : 1; + } bits; + }; +} config_reg_t; + + -- 2.7.4