1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tja1042: add driver for tja1042 CAN transceiver

This commit is contained in:
Vincent Dupont 2016-12-15 11:57:24 +01:00
parent e4cc780f71
commit cf34161789
4 changed files with 159 additions and 0 deletions

View File

@ -245,3 +245,8 @@ ifneq (,$(filter adc%1c,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
USEMODULE += adcxx1c
endif
ifneq (,$(filter tja1042,$(USEMODULE)))
USEMODULE += can_trx
FEATURES_REQUIRED += periph_gpio
endif

82
drivers/include/tja1042.h Normal file
View File

@ -0,0 +1,82 @@
/*
* Copyright (C) 2016-2018 OTA keys S.A.
*
* 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_tja1042 TJA1042
* @ingroup drivers
* @ingroup trx_can
* @brief tja1042 High Speed CAN transceiver driver
*
* @{
*
* @file
* @brief tja1042 generic CAN transceiver interface initialization
*
* @author Aurelien Gonce <aurelien.gonce@altran.com>
* @author Vincent Dupont <vincent@otakeys.com>
*/
#ifndef TJA1042_H
#define TJA1042_H
#include <stdio.h>
#include "periph/gpio.h"
#include "can/can_trx.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief tja1042 CAN trx descriptor
*/
typedef struct tja1042_trx {
/**
* set mode interface
*/
can_trx_t trx;
/**
* Mode pin of tja1042 device
*/
gpio_t stb_pin;
} tja1042_trx_t;
/**
* @brief Set mode interface
*
* @param[in] dev Pointer to the tja1042 descriptor
* @param[in] mode mode to set
*
* @return 0 on success
* @return -1 on error
*/
int tja1042_trx_set_mode(can_trx_t *dev, can_trx_mode_t mode);
/**
* @brief Initialize the given tja1042
*
* @param[in] dev Pointer to the tja1042 descriptor
*
* @return 0 on success
* @return -1 on error
*/
int tja1042_trx_init(can_trx_t *dev);
/**
* @brief tja1042 driver
*/
extern const trx_driver_t tja1042_driver;
#ifdef __cplusplus
}
#endif
#endif /* TJA1042_H */
/** @} */

1
drivers/tja1042/Makefile Normal file
View File

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

71
drivers/tja1042/tja1042.c Normal file
View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2016-2018 OTA keys S.A.
*
* 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_tja1042
* @{
*
* @file
* @brief generic CAN transceiver implementation for tja1042
*
* @author Aurelien Gonce <aurelien.gonce@altran.com>
* @author Vincent Dupont <vincent@otakeys.com>
*
* @}
*/
#include <assert.h>
#define ENABLE_DEBUG (0)
#include "debug.h"
#include "tja1042.h"
int tja1042_trx_set_mode(can_trx_t *dev, can_trx_mode_t mode)
{
tja1042_trx_t *tja1042 = (tja1042_trx_t *)dev;
int ret;
DEBUG("tja1042_trx_set_mode: dev=%p, mode=%d\n", (void *)dev, (int)mode);
switch (mode) {
case TRX_NORMAL_MODE:
case TRX_SILENT_MODE:
gpio_clear(tja1042->stb_pin);
ret = 0;
break;
case TRX_SLEEP_MODE:
gpio_set(tja1042->stb_pin);
ret = 0;
break;
default:
ret = -1;
break;
}
return ret;
}
int tja1042_trx_init(can_trx_t *dev)
{
assert(dev != NULL);
tja1042_trx_t *tja1042 = (tja1042_trx_t *)dev;
gpio_init(tja1042->stb_pin, GPIO_OUT);
tja1042_trx_set_mode(dev, TRX_NORMAL_MODE);
return 0;
}
const trx_driver_t tja1042_driver = {
.init = tja1042_trx_init,
.set_mode = tja1042_trx_set_mode,
};