From fcb97bc2c0a018fd015b571d1cf1431f9d9297ff Mon Sep 17 00:00:00 2001 From: Firas Hamdi Date: Mon, 18 Mar 2024 16:02:38 +0100 Subject: [PATCH 1/3] drivers/at6561: write driver for AT6561 CAN transceiver --- drivers/at6561/Makefile | 1 + drivers/at6561/Makefile.dep | 2 ++ drivers/at6561/at6561.c | 62 +++++++++++++++++++++++++++++++++++++ drivers/include/at6561.h | 32 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 drivers/at6561/Makefile create mode 100644 drivers/at6561/Makefile.dep create mode 100644 drivers/at6561/at6561.c create mode 100644 drivers/include/at6561.h diff --git a/drivers/at6561/Makefile b/drivers/at6561/Makefile new file mode 100644 index 000000000000..9c9ae9884ad6 --- /dev/null +++ b/drivers/at6561/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/drivers/at6561/Makefile.dep b/drivers/at6561/Makefile.dep new file mode 100644 index 000000000000..24d0af52b588 --- /dev/null +++ b/drivers/at6561/Makefile.dep @@ -0,0 +1,2 @@ +USEMODULE += can_trx +FEATURES_REQUIRED += periph_gpio \ No newline at end of file diff --git a/drivers/at6561/at6561.c b/drivers/at6561/at6561.c new file mode 100644 index 000000000000..3dd6c1095ec2 --- /dev/null +++ b/drivers/at6561/at6561.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_at6561 + * + * @file + * @brief Driver for AT6561 CAN transceiver + * + * @author Firas Hamdi + */ + +#include "can/can_trx.h" +#include "at6561.h" +#include "periph/gpio.h" +#include "assert.h" +#include "container.h" + +static int _init(can_trx_t *can_trx); +static int _set_mode(can_trx_t *can_trx, can_trx_mode_t mode); + +const trx_driver_t at6561_driver = { + .init = _init, + .set_mode = _set_mode, +}; + +static int _init(can_trx_t *can_trx) +{ + at6561_trx_t *dev = container_of(can_trx, at6561_trx_t, trx); + + gpio_init(dev->stby_pin, GPIO_OUT); + /* A high level on the standby pin of the CAN transceiver will + select the standby mode. Check AT6560/1 datasheet, table 1-1 */ + gpio_set(dev->stby_pin); + + return 1; +} + +/* Set the mode of the CAN transceiver */ +static int _set_mode(can_trx_t *can_trx, can_trx_mode_t mode) +{ + at6561_trx_t *dev = container_of(can_trx, at6561_trx_t, trx); + + /* Check AT6560/1 datasheet, table 1-1 */ + switch (mode) { + case TRX_NORMAL_MODE: + gpio_clear(dev->stby_pin); + break; + case TRX_SLEEP_MODE: + gpio_set(dev->stby_pin); + break; + default: + assert(0); + } + + return 1; +} diff --git a/drivers/include/at6561.h b/drivers/include/at6561.h new file mode 100644 index 000000000000..27ee2c8f1393 --- /dev/null +++ b/drivers/include/at6561.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_at6561 + * + * @file + * @brief Driver for AT6561 CAN transceiver + * + * @author Firas Hamdi + */ + +#include "periph/gpio.h" +#include "can/can_trx.h" + +/** + * @brief AT6561 CAN transceiver descriptor + */ +typedef struct at6561_trx { + /* AT6561 standby pin */ + gpio_t stby_pin; + /* AT6561 interface */ + can_trx_t trx; +} at6561_trx_t; + +/* AT6561 driver */ +extern const trx_driver_t at6561_driver; \ No newline at end of file From 438debebd15f3015f8299d3c9637afe5f9d94b7d Mon Sep 17 00:00:00 2001 From: Firas Hamdi Date: Tue, 19 Mar 2024 08:53:06 +0100 Subject: [PATCH 2/3] tests/sys/can_trx: integrate AT6561 into the CAN transceiver test app --- tests/sys/can_trx/Makefile | 7 +++++++ tests/sys/can_trx/main.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/sys/can_trx/Makefile b/tests/sys/can_trx/Makefile index 0ae854763423..9556c0c52a1d 100644 --- a/tests/sys/can_trx/Makefile +++ b/tests/sys/can_trx/Makefile @@ -24,4 +24,11 @@ ifneq (,$(filter ncv7356,$(TRX_TO_BUILD))) CFLAGS += -DNCV7356_MODE1_PIN=$(NCV7356_MODE1_PIN) endif +ifneq (, $(filter at6561, $(TRX_TO_BUILD))) + USEMODULE += at6561 + AT6561_STBY_PIN ?= GPIO_PIN\(0,0\) + + CFLAGS += -DAT6561_STBY_PIN=$(AT6561_STBY_PIN) +endif + include $(RIOTBASE)/Makefile.include diff --git a/tests/sys/can_trx/main.c b/tests/sys/can_trx/main.c index 89e211066f11..fac23d9011c6 100644 --- a/tests/sys/can_trx/main.c +++ b/tests/sys/can_trx/main.c @@ -40,12 +40,22 @@ ncv7356_trx_t ncv7356 ={ .trx.driver = &ncv7356_driver, }; #endif +#ifdef MODULE_AT6561 +#include "at6561.h" +at6561_trx_t at6561 = { .stby_pin = AT6561_STBY_PIN, + .trx.driver = &at6561_driver +}; +#endif + static can_trx_t *devs[] = { #ifdef MODULE_TJA1042 (can_trx_t *)&tja1042, #endif #ifdef MODULE_NCV7356 (can_trx_t *)&ncv7356, +#endif +#ifdef MODULE_AT6561 + &at6561.trx, #endif NULL, }; From ccd7fecde7accf9a6448748234361a6893924add Mon Sep 17 00:00:00 2001 From: Firas Hamdi Date: Tue, 19 Mar 2024 09:28:25 +0100 Subject: [PATCH 3/3] fix CI check errors --- drivers/at6561/at6561.c | 49 +++++++++++++++++++++------------------- drivers/include/at6561.h | 34 +++++++++++++++++++++------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/drivers/at6561/at6561.c b/drivers/at6561/at6561.c index 3dd6c1095ec2..7a5b9b61a0fa 100644 --- a/drivers/at6561/at6561.c +++ b/drivers/at6561/at6561.c @@ -9,10 +9,13 @@ /** * @ingroup drivers_at6561 * + * @{ * @file * @brief Driver for AT6561 CAN transceiver * * @author Firas Hamdi + * + * @} */ #include "can/can_trx.h" @@ -25,38 +28,38 @@ static int _init(can_trx_t *can_trx); static int _set_mode(can_trx_t *can_trx, can_trx_mode_t mode); const trx_driver_t at6561_driver = { - .init = _init, - .set_mode = _set_mode, + .init = _init, + .set_mode = _set_mode, }; static int _init(can_trx_t *can_trx) { - at6561_trx_t *dev = container_of(can_trx, at6561_trx_t, trx); + at6561_trx_t *dev = container_of(can_trx, at6561_trx_t, trx); - gpio_init(dev->stby_pin, GPIO_OUT); - /* A high level on the standby pin of the CAN transceiver will - select the standby mode. Check AT6560/1 datasheet, table 1-1 */ - gpio_set(dev->stby_pin); + gpio_init(dev->stby_pin, GPIO_OUT); + /* A high level on the standby pin of the CAN transceiver will + select the standby mode. Check AT6560/1 datasheet, table 1-1 */ + gpio_set(dev->stby_pin); - return 1; + return 1; } /* Set the mode of the CAN transceiver */ static int _set_mode(can_trx_t *can_trx, can_trx_mode_t mode) { - at6561_trx_t *dev = container_of(can_trx, at6561_trx_t, trx); - - /* Check AT6560/1 datasheet, table 1-1 */ - switch (mode) { - case TRX_NORMAL_MODE: - gpio_clear(dev->stby_pin); - break; - case TRX_SLEEP_MODE: - gpio_set(dev->stby_pin); - break; - default: - assert(0); - } - - return 1; + at6561_trx_t *dev = container_of(can_trx, at6561_trx_t, trx); + + /* Check AT6560/1 datasheet, table 1-1 */ + switch (mode) { + case TRX_NORMAL_MODE: + gpio_clear(dev->stby_pin); + break; + case TRX_SLEEP_MODE: + gpio_set(dev->stby_pin); + break; + default: + assert(0); + } + + return 1; } diff --git a/drivers/include/at6561.h b/drivers/include/at6561.h index 27ee2c8f1393..461646f35ce5 100644 --- a/drivers/include/at6561.h +++ b/drivers/include/at6561.h @@ -7,26 +7,44 @@ */ /** - * @ingroup drivers_at6561 + * @defgroup drivers_at6561 AT6561 CAN transceiver driver + * @ingroup drivers_can + * @ingroup drivers_can_trx * - * @file * @brief Driver for AT6561 CAN transceiver + * @{ + * + * @file * * @author Firas Hamdi */ +#ifndef AT6561_H +#define AT6561_H + #include "periph/gpio.h" #include "can/can_trx.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief AT6561 CAN transceiver descriptor */ typedef struct at6561_trx { - /* AT6561 standby pin */ - gpio_t stby_pin; - /* AT6561 interface */ - can_trx_t trx; + gpio_t stby_pin; /**< AT6561 standby pin */ + can_trx_t trx; /**< AT6561 interface */ } at6561_trx_t; -/* AT6561 driver */ -extern const trx_driver_t at6561_driver; \ No newline at end of file +/** + * @brief AT6561 driver + */ +extern const trx_driver_t at6561_driver; + +#ifdef __cplusplus +} +#endif + +#endif /* AT6561_H */ +/** @} */