From: Robin Krens Date: Tue, 24 Jan 2023 19:17:23 +0000 (+0100) Subject: libsi24: compile as lib and remove example code from lib X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=926b20c60eabfc61fd22b408b7202a2cad30dcfc;p=libsi24 libsi24: compile as lib and remove example code from lib --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d2e3b60..2fd6f5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(PROJECT_HOMEPAGE_URL https://github.com/robinkrens/libsi24) add_compile_options(-Wall -Wextra -pedantic) -add_executable(libsi24 libsi24.c) +add_library(libsi24 libsi24.c) target_include_directories(libsi24 PUBLIC diff --git a/libsi24.c b/libsi24.c index f85326c..ba6dee3 100644 --- a/libsi24.c +++ b/libsi24.c @@ -293,71 +293,3 @@ void si24_free(si24_t * si) { free(si); } - -/* hardware linkage */ -int spi_w_r(unsigned char *data, size_t sz) -{ - if (sz >= 2) - data[1] = (1 << RX_DR); - return sz; -} - -void ce(unsigned val) -{ - (void) val; -} - -void eh(si24_t *si, si24_event_t * e) -{ - (void) si; - - switch(e->type) { - case EV_TX_COMPLETE: - printf("SENT SUCCESFUL\n"); - break; - case EV_RX_COMPLETE: - printf("RECV COMPLETE\n"); - break; - case EV_RX_EMPTY: - printf("NO NEW DATA\n"); - break; - case EV_ERR_TIMEOUT: - printf("TIMEOUT\n"); - break; - default: - printf("EVENT: %x\n", e->type); - break; - } -} - -int main(void) -{ - /* const unsigned char buf[] = "THIS IS A WIRELESS TEST MESSAGE!";*/ - unsigned char recv_buf[29]; - - si24_ioctl_t ctl = { - .write_and_read = spi_w_r, - .chip_enable = ce, - }; - - const si24_opts_t opts = { - .mode = RECV_MODE, - .enable_ack = 1, - .non_blocking = 0, - .enable_crc = 1, - .enable_dynpd = 1, - .crc = TWO_BYTE, - .ioctl = &ctl, - .speed = MBPS2, - .txpwr = PLUS4DB, - .payload = 5, - .timeout = 1, - .retries = 5, - .mac_addr = 0xAAAAAAAAAA - }; - - struct si24_t * si = si24_init(&opts, eh); - /* si24_send(si, buf, sizeof(buf)); */ - printf("READ: %ld\n", si24_recv(si, recv_buf, sizeof(recv_buf))); - -}