diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 223b435d7d..6305f83e4d 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -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 diff --git a/drivers/include/tja1042.h b/drivers/include/tja1042.h new file mode 100644 index 0000000000..7ca5f8a66b --- /dev/null +++ b/drivers/include/tja1042.h @@ -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 + * @author Vincent Dupont + */ +#ifndef TJA1042_H +#define TJA1042_H + +#include + +#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 */ +/** @} */ diff --git a/drivers/tja1042/Makefile b/drivers/tja1042/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/drivers/tja1042/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/drivers/tja1042/tja1042.c b/drivers/tja1042/tja1042.c new file mode 100644 index 0000000000..5552beb293 --- /dev/null +++ b/drivers/tja1042/tja1042.c @@ -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 + * @author Vincent Dupont + * + * @} + */ + +#include + +#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, +};