From baa47e99f2cf6010f9d6958b3a3e1ef78a48961b Mon Sep 17 00:00:00 2001 From: Eve Redero Date: Tue, 5 Mar 2024 18:00:24 +0100 Subject: [PATCH] wip: rename api to propy_radio --- README.md | 4 +- app/src/main.c | 22 +++++------ drivers/nrf24l01/nrf24l01.c | 4 +- include/app/drivers/nrf24.h | 65 ------------------------------- include/app/drivers/propy_radio.h | 65 +++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 80 deletions(-) delete mode 100644 include/app/drivers/nrf24.h create mode 100644 include/app/drivers/propy_radio.h diff --git a/README.md b/README.md index 62254ce..1823134 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ This driver uses a minimalist custom API. ## Read ``` -int nrf24_read(const struct device *dev, uint8_t *buffer, uint8_t data_len) +int propy_radio_read(const struct device *dev, uint8_t *buffer, uint8_t data_len) ``` This methods reads data\_len bytes from the device dev, and places it in buffer. @@ -90,7 +90,7 @@ In polling mode, it will loop forever. # Write ``` -int nrf24_write(const struct device *dev, uint8_t *buffer, uint8_t data_len) +int propy_radio_write(const struct device *dev, uint8_t *buffer, uint8_t data_len) ``` This methods writes data\_len bytes from buffer, and sends it through device dev. diff --git a/app/src/main.c b/app/src/main.c index 15d7580..c1dc5b0 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL); #if !DT_NODE_EXISTS(DT_NODELABEL(radio0)) @@ -49,23 +49,23 @@ int main(void) while (true) { strncpy(buffer, "I am Alice, hi!", 16); #ifdef TRIGGER - while (nrf24_write(nrf24, buffer, data_len)) + while (propy_radio_write(nrf24, buffer, data_len)) { k_sleep(K_MSEC(10)); } #else for (i=0; i<10; i++) { - nrf24_write(nrf24, buffer, data_len); + propy_radio_write(nrf24, buffer, data_len); k_sleep(K_MSEC(10)); } #endif // TRIGGER LOG_HEXDUMP_INF(buffer, data_len, "Sent: "); LOG_DBG("Switch to read"); #ifdef TRIGGER - while (nrf24_read(nrf24, buffer, data_len)); + while (propy_radio_read(nrf24, buffer, data_len)); #else - nrf24_read(nrf24, buffer, data_len); + propy_radio_read(nrf24, buffer, data_len); #endif // TRIGGER LOG_HEXDUMP_INF(buffer, data_len, "Received: "); k_sleep(K_MSEC(1000)); @@ -77,23 +77,23 @@ int main(void) LOG_WRN("I am Bob!"); while (true) { #ifdef TRIGGER - while (nrf24_read(nrf24, buffer, data_len)); + while (propy_radio_read(nrf24, buffer, data_len)); #else - nrf24_read(nrf24, buffer, data_len); + propy_radio_read(nrf24, buffer, data_len); #endif // TRIGGER LOG_HEXDUMP_INF(buffer, data_len, "Received: "); LOG_DBG("Switch to write"); strncpy(buffer, "Hi Alice Im Bob", 16); k_sleep(K_MSEC(1000)); #ifdef TRIGGER - while (nrf24_write(nrf24, buffer, data_len)) + while (propy_radio_write(nrf24, buffer, data_len)) { k_sleep(K_MSEC(10)); } #else for (i=0; i<10; i++) { - nrf24_write(nrf24, buffer, data_len); + propy_radio_write(nrf24, buffer, data_len); k_sleep(K_MSEC(10)); } #endif // TRIGGER @@ -106,10 +106,10 @@ int main(void) LOG_WRN("I am Eve!"); while (true) { #ifdef TRIGGER - while (nrf24_read(nrf24, buffer, data_len)); + while (propy_radio_read(nrf24, buffer, data_len)); #else strncpy(buffer, " ", 16); - nrf24_read(nrf24, buffer, data_len); + propy_radio_read(nrf24, buffer, data_len); #endif // TRIGGER LOG_HEXDUMP_INF(buffer, data_len, "I spied: "); } diff --git a/drivers/nrf24l01/nrf24l01.c b/drivers/nrf24l01/nrf24l01.c index 67e3d16..7fcbf59 100644 --- a/drivers/nrf24l01/nrf24l01.c +++ b/drivers/nrf24l01/nrf24l01.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include "nrf24l01_defines.h" #define SPI_MAX_MSG_LEN 64 @@ -736,7 +736,7 @@ static int nrf24l01_write(const struct device *dev, uint8_t *buffer, uint8_t dat return ret; } -static const struct nrf24_api nrf24l01_api = { +static const struct propy_radio_api nrf24l01_api = { .read = nrf24l01_read, .write = nrf24l01_write, }; diff --git a/include/app/drivers/nrf24.h b/include/app/drivers/nrf24.h deleted file mode 100644 index 0fdcf84..0000000 --- a/include/app/drivers/nrf24.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - */ -#ifndef ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_WIRELESS_NRF24_H_ -#define ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_WIRELESS_NRF24_H_ - -#include -#include - -/** @cond INTERNAL_HIDDEN */ - -typedef int (*nrf24_read_t)(const struct device *dev, uint8_t *buffer, uint8_t data_len); -typedef int (*nrf24_write_t)(const struct device *dev, uint8_t *buffer, uint8_t data_len); - -__subsystem struct nrf24_api { - nrf24_read_t read; - nrf24_write_t write; -}; - -/** @endcond */ -/** - * @brief Read data. - * - * @param dev nrf24 instance. - * @param buf Read buffer. - * @param data_len Number of bytes to read - * - * @retval 0 On success. - * @retval -EIO Nothing in RX queue (trigger mode) - * @retval -errno Other negative errno in case of failure. - */ -__syscall int nrf24_read(const struct device *dev, uint8_t *buffer, uint8_t data_len); - -static inline int z_impl_nrf24_read(const struct device *dev, uint8_t *buffer, uint8_t data_len) -{ - const struct nrf24_api *api = - (const struct nrf24_api *)dev->api; - - return api->read(dev, buffer, data_len); -} - -/** - * @brief Write data. - * - * @param dev nrf24 instance. - * @param buf Write buffer. - * @param data_len Number of bytes to write - * - * @retval 0 On success. - * @retval -ETIME TX sending timed out (trigger mode) - * @retval -EIO Max retries exceeded (polling mode) - * @retval MAX_RT Message not acknowledged (trigger mode) - * @retval -errno Other negative errno in case of failure. - */ -__syscall int nrf24_write(const struct device *dev, uint8_t *buffer, uint8_t data_len); - -static inline int z_impl_nrf24_write(const struct device *dev, uint8_t *buffer, uint8_t data_len) -{ - const struct nrf24_api *api = - (const struct nrf24_api *)dev->api; - - return api->write(dev, buffer, data_len); -} - -#include -#endif /* ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_WIRELESS_NRF24_H_ */ diff --git a/include/app/drivers/propy_radio.h b/include/app/drivers/propy_radio.h new file mode 100644 index 0000000..7564775 --- /dev/null +++ b/include/app/drivers/propy_radio.h @@ -0,0 +1,65 @@ +/* + */ +#ifndef ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_WIRELESS_PROPY_RADIO_H_ +#define ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_WIRELESS_PROPY_RADIO_H_ + +#include +#include + +/** @cond INTERNAL_HIDDEN */ + +typedef int (*propy_radio_read_t)(const struct device *dev, uint8_t *buffer, uint8_t data_len); +typedef int (*propy_radio_write_t)(const struct device *dev, uint8_t *buffer, uint8_t data_len); + +__subsystem struct propy_radio_api { + propy_radio_read_t read; + propy_radio_write_t write; +}; + +/** @endcond */ +/** + * @brief Read data. + * + * @param dev propy_radio instance. + * @param buf Read buffer. + * @param data_len Number of bytes to read + * + * @retval 0 On success. + * @retval -EIO Nothing in RX queue (trigger mode) + * @retval -errno Other negative errno in case of failure. + */ +__syscall int propy_radio_read(const struct device *dev, uint8_t *buffer, uint8_t data_len); + +static inline int z_impl_propy_radio_read(const struct device *dev, uint8_t *buffer, uint8_t data_len) +{ + const struct propy_radio_api *api = + (const struct propy_radio_api *)dev->api; + + return api->read(dev, buffer, data_len); +} + +/** + * @brief Write data. + * + * @param dev propy_radio instance. + * @param buf Write buffer. + * @param data_len Number of bytes to write + * + * @retval 0 On success. + * @retval -ETIME TX sending timed out (trigger mode) + * @retval -EIO Max retries exceeded (polling mode) + * @retval MAX_RT Message not acknowledged (trigger mode) + * @retval -errno Other negative errno in case of failure. + */ +__syscall int propy_radio_write(const struct device *dev, uint8_t *buffer, uint8_t data_len); + +static inline int z_impl_propy_radio_write(const struct device *dev, uint8_t *buffer, uint8_t data_len) +{ + const struct propy_radio_api *api = + (const struct propy_radio_api *)dev->api; + + return api->write(dev, buffer, data_len); +} + +#include +#endif /* ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_WIRELESS_PROPY_RADIO_H_ */