diff --git a/boards/native/Makefile.features b/boards/native/Makefile.features index 88ae4e0079..d9c8a64df1 100644 --- a/boards/native/Makefile.features +++ b/boards/native/Makefile.features @@ -3,8 +3,8 @@ FEATURES_PROVIDED += periph_rtc FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart FEATURES_PROVIDED += periph_gpio -FEATURES_PROVIDED += periph_qdec FEATURES_PROVIDED += periph_pwm +FEATURES_PROVIDED += periph_qdec # Various other features (if any) FEATURES_PROVIDED += ethernet diff --git a/boards/native/board.c b/boards/native/board.c new file mode 100644 index 0000000000..a079e5b58b --- /dev/null +++ b/boards/native/board.c @@ -0,0 +1,54 @@ +/** + * Native Board board implementation + * + * Copyright (C) 2018 Gilles DOFFE + * + * 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 boards_native + * @{ + * @file + * @author Gilles DOFFE + * @} + */ +#include +#include + +/* RIOT includes */ +#include +#include + +extern int32_t qdecs_value[QDEC_NUMOF]; + +void native_motor_driver_qdec_simulation( + const motor_driver_t motor_driver, uint8_t motor_id, + int32_t pwm_duty_cycle) +{ + uint32_t id = 0; + + for (uint32_t i = 0; i < motor_driver; i++) { + const motor_driver_config_t motor_driver_conf = + motor_driver_config[motor_driver]; + id += motor_driver_conf.nb_motors; + } + id += motor_id; + + if (id < QDEC_NUMOF) { + qdecs_value[id] = pwm_duty_cycle; + + LOG_DEBUG("MOTOR-DRIVER=%u" \ + " MOTOR_ID = %u" \ + " PWM_VALUE = %d" \ + " QDEC_ID = %"PRIu32"" \ + " QDEC_VALUE = %d\n", \ + motor_driver, motor_id, pwm_duty_cycle, id, pwm_duty_cycle); + } + else { + LOG_ERROR("MOTOR-DRIVER=%u" \ + " MOTOR_ID = %u" \ + " no QDEC device associated\n", \ + motor_driver, motor_id); + } +} diff --git a/boards/native/include/board.h b/boards/native/include/board.h index 5209ec4eb8..1dcc586447 100644 --- a/boards/native/include/board.h +++ b/boards/native/include/board.h @@ -24,6 +24,9 @@ #include +/* RIOT includes */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -124,6 +127,19 @@ extern mtd_dev_t *mtd0; /** @} */ #endif +/** + * @brief Simulate QDEC on motor_set() calls + * + * @param[in] motor_driver motor driver to which motor is attached + * @param[in] motor_id motor ID on driver + * @param[in] pwm_duty_cycle Signed PWM duty_cycle to set motor speed and direction + * + * @return 0 on success + */ +void native_motor_driver_qdec_simulation( \ + const motor_driver_t motor_driver, uint8_t motor_id, \ + int32_t pwm_duty_cycle); + #ifdef __cplusplus } #endif