Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement at6561 can trx driver #20480

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/at6561/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
2 changes: 2 additions & 0 deletions drivers/at6561/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USEMODULE += can_trx
FEATURES_REQUIRED += periph_gpio
65 changes: 65 additions & 0 deletions drivers/at6561/at6561.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 <[email protected]>
*
* @}
*/

#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;
}
50 changes: 50 additions & 0 deletions drivers/include/at6561.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*/

/**
* @defgroup drivers_at6561 AT6561 CAN transceiver driver
* @ingroup drivers_can
* @ingroup drivers_can_trx
*
* @brief Driver for AT6561 CAN transceiver
* @{
*
* @file
*
* @author Firas Hamdi <[email protected]>
*/

#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 {
gpio_t stby_pin; /**< AT6561 standby pin */
can_trx_t trx; /**< AT6561 interface */
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gpio_t stby_pin; /**< AT6561 standby pin */
can_trx_t trx; /**< AT6561 interface */
can_trx_t trx; /**< AT6561 interface */
gpio_t stby_pin; /**< AT6561 standby pin */

please swap to keep consistent with the other cantrx_drivers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no problem with swapping them, but I don't like the usage of can_trx_t *trx = &at6561 as other drivers are used in the test app tests/sys/can_trx (I find it very error prone and it limits the freedom to define structure members)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just swap -- so it won't fail if someone does it like can_trx_t *trx = &at6561 as they might if they looked at the other drivers ( make it more simmilar)

} at6561_trx_t;

/**
* @brief AT6561 driver
*/
extern const trx_driver_t at6561_driver;

#ifdef __cplusplus
}
#endif

#endif /* AT6561_H */
/** @} */
7 changes: 7 additions & 0 deletions tests/sys/can_trx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions tests/sys/can_trx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Loading