1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-27 07:21:18 +01:00

boards/native: add qdec simulation callback

native_motor_driver_qdec_simulation() callback is called each time
motor_set() from motor_driver driver is called.
It set associated qdec value to the PWM duty cycle.
QDEC values are stored in qdecs_value[] array in the order motors
are described in board.h.
Then it is needed to configure in first motors that needs the QDEC in
board.h.

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
This commit is contained in:
Gilles DOFFE 2018-10-16 14:00:30 +02:00
parent 37981b5bc2
commit d04c21bb8b
3 changed files with 71 additions and 1 deletions

View File

@ -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

54
boards/native/board.c Normal file
View File

@ -0,0 +1,54 @@
/**
* Native Board board implementation
*
* Copyright (C) 2018 Gilles DOFFE <g.doffe@gmail.com>
*
* 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 <g.doffe@gmail.com>
* @}
*/
#include <inttypes.h>
#include <stdio.h>
/* RIOT includes */
#include <board.h>
#include <log.h>
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);
}
}

View File

@ -24,6 +24,9 @@
#include <stdint.h>
/* RIOT includes */
#include <motor_driver.h>
#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