-
Notifications
You must be signed in to change notification settings - Fork 2k
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
firas-hamdi
wants to merge
3
commits into
RIOT-OS:master
Choose a base branch
from
firas-hamdi:feat/implement_at6561_can_trx_driver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+135
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
USEMODULE += can_trx | ||
FEATURES_REQUIRED += periph_gpio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
} at6561_trx_t; | ||
|
||
/** | ||
* @brief AT6561 driver | ||
*/ | ||
extern const trx_driver_t at6561_driver; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* AT6561_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please swap to keep consistent with the other cantrx_drivers
There was a problem hiding this comment.
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 apptests/sys/can_trx
(I find it very error prone and it limits the freedom to define structure members)There was a problem hiding this comment.
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)