diff --git a/Makefile.include b/Makefile.include index 299cd8733e..bdfd27b2b4 100644 --- a/Makefile.include +++ b/Makefile.include @@ -38,17 +38,12 @@ MCUFW_MODULE_DIRS = " \ motion_control/engines \ motion_control/filters \ motion_control/metas \ - drivers \ lib \ - planners \ platforms \ sys \ " -# All directories starting with 'shell_' are shell modules. -# List them to add their parent directory to EXTERNAL_MODULE_DIRS. -shell_module_dirs = $(wildcard $(MCUFW_MODULE_DIRS:%=$(MCUFIRMWAREBASE)/%/*/shell_*/.)) -EXTERNAL_MODULE_DIRS += $(MCUFW_MODULE_DIRS:%=$(MCUFIRMWAREBASE)/%/) $(shell_module_dirs:%=%/..) +EXTERNAL_MODULE_DIRS += $(MCUFW_MODULE_DIRS:%=$(MCUFIRMWAREBASE)/%/) # Use C++20 by default CXXEXFLAGS := $(filter-out -std=%, $(CXXEXFLAGS)) diff --git a/applications/cup2024-pami/Makefile b/applications/cup2024-pami/Makefile deleted file mode 100644 index 5c7d53fc07..0000000000 --- a/applications/cup2024-pami/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -APPLICATION = cup2024-pami - -BOARD ?= cogip-board-pami -#BOARD ?= cogip-native - -# Platform -USEMODULE += pf-pami - -# Update maximum number of motors for actuators -CFLAGS += -DCONFIG_MOTOR_DRIVER_MAX=3 - -include ../../Makefile.include diff --git a/applications/cup2024-pami/app.cpp b/applications/cup2024-pami/app.cpp deleted file mode 100644 index 8e6a599390..0000000000 --- a/applications/cup2024-pami/app.cpp +++ /dev/null @@ -1,6 +0,0 @@ -/* Project includes */ -#include "app.hpp" - -void app_init(void) -{ -} diff --git a/applications/cup2024-pami/include/app.hpp b/applications/cup2024-pami/include/app.hpp deleted file mode 100644 index 3e7cb91951..0000000000 --- a/applications/cup2024-pami/include/app.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -/* - * Machine parameters - */ - -#define USART_CONSOLE USARTC0 - -void app_init(void); diff --git a/applications/cup2024-pami/include/real/app_conf.hpp b/applications/cup2024-pami/include/real/app_conf.hpp deleted file mode 100644 index d6c3cae5f1..0000000000 --- a/applications/cup2024-pami/include/real/app_conf.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -// Project includes -#include "etl/numeric.h" - -// Linear pose PID -constexpr double linear_pose_pid_kp = 1; -constexpr double linear_pose_pid_ki = 0; -constexpr double linear_pose_pid_kd = 0; -// Angular pose PID -constexpr double angular_pose_pid_kp = 1; -constexpr double angular_pose_pid_ki = 0; -constexpr double angular_pose_pid_kd = 0; -// Linear speed PID -constexpr double linear_speed_pid_kp = 100; -constexpr double linear_speed_pid_ki = 10; -constexpr double linear_speed_pid_kd = 0; -// Angular speed PID -constexpr double angular_speed_pid_kp = 100; -constexpr double angular_speed_pid_ki = 10; -constexpr double angular_speed_pid_kd = 0; - -// Linear pose PID integral limit -constexpr double linear_pose_pid_integral_limit = etl::numeric_limits::max(); -// Angular pose PID integral limit -constexpr double angular_pose_pid_integral_limit = etl::numeric_limits::max(); -// Linear speed PID integral limit -constexpr double linear_speed_pid_integral_limit = etl::numeric_limits::max(); -// Angular speed PID integral limit -constexpr double angular_speed_pid_integral_limit = etl::numeric_limits::max(); - -// Linear threshold -constexpr double linear_threshold = 3; -// Angular threshold -constexpr double angular_threshold = 2; -// Angular intermediate threshold (when the robot turns on itself to go straight to its destination) -constexpr double angular_intermediate_threshold = 5; - diff --git a/applications/cup2024-pami/include/simulation/app_conf.hpp b/applications/cup2024-pami/include/simulation/app_conf.hpp deleted file mode 100644 index 69a6e17c96..0000000000 --- a/applications/cup2024-pami/include/simulation/app_conf.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -// Project includes -#include "etl/numeric.h" - -// Linear pose PID -constexpr double linear_pose_pid_kp = 0.0325; -constexpr double linear_pose_pid_ki = 0; -constexpr double linear_pose_pid_kd = 0; -// Angular pose PID -constexpr double angular_pose_pid_kp = 0.06; -constexpr double angular_pose_pid_ki = 0; -constexpr double angular_pose_pid_kd = 0; -// Linear speed PID -constexpr double linear_speed_pid_kp = 0; -constexpr double linear_speed_pid_ki = 0; -constexpr double linear_speed_pid_kd = 0; -// Angular speed PID -constexpr double angular_speed_pid_kp = 0; -constexpr double angular_speed_pid_ki = 0; -constexpr double angular_speed_pid_kd = 0; - -// Linear pose PID integral limit -constexpr double linear_pose_pid_integral_limit = etl::numeric_limits::max(); -// Angular pose PID integral limit -constexpr double angular_pose_pid_integral_limit = etl::numeric_limits::max(); -// Linear speed PID integral limit -constexpr double linear_speed_pid_integral_limit = etl::numeric_limits::max(); -//constexpr double linear_speed_pid_integral_limit = 2000; -// Angular speed PID integral limit -constexpr double angular_speed_pid_integral_limit = etl::numeric_limits::max(); -//constexpr double angular_speed_pid_integral_limit = 2000; - -// Linear threshold -constexpr double linear_threshold = 3; -// Angular threshold -constexpr double angular_threshold = 2; -// Angular intermediate threshold (when the robot turns on itself to go straight to its destination) -constexpr double angular_intermediate_threshold = 5; diff --git a/applications/cup2024-pami/main.cpp b/applications/cup2024-pami/main.cpp deleted file mode 100644 index 0ac7b26baa..0000000000 --- a/applications/cup2024-pami/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "app.hpp" -#include "platform.hpp" - -int main(void) -{ - pf_init(); - app_init(); - - pf_init_tasks(); - - return 0; -} diff --git a/boards/cogip-board-pami/Makefile b/boards/cogip-board-pami/Makefile deleted file mode 100644 index f8fcbb53a0..0000000000 --- a/boards/cogip-board-pami/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = board - -include $(RIOTBASE)/Makefile.base diff --git a/boards/cogip-board-pami/Makefile.dep b/boards/cogip-board-pami/Makefile.dep deleted file mode 100644 index c1304845fa..0000000000 --- a/boards/cogip-board-pami/Makefile.dep +++ /dev/null @@ -1,3 +0,0 @@ -USEMODULE += mpu_stack_guard -USEMODULE += pcf8575 -USEMODULE += pcf857x_irq diff --git a/boards/cogip-board-pami/Makefile.features b/boards/cogip-board-pami/Makefile.features deleted file mode 100644 index d5e565fecc..0000000000 --- a/boards/cogip-board-pami/Makefile.features +++ /dev/null @@ -1,13 +0,0 @@ -# Define the cpu used -CPU = stm32 -CPU_MODEL = stm32f446re - -# Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_gpio -FEATURES_PROVIDED += periph_i2c -FEATURES_PROVIDED += periph_pwm -FEATURES_PROVIDED += periph_qdec -FEATURES_PROVIDED += periph_timer -FEATURES_PROVIDED += periph_uart - --include $(RIOTCPU)/stm32/Makefile.features diff --git a/boards/cogip-board-pami/Makefile.include b/boards/cogip-board-pami/Makefile.include deleted file mode 100644 index 5018a9f4ae..0000000000 --- a/boards/cogip-board-pami/Makefile.include +++ /dev/null @@ -1,8 +0,0 @@ -# We use shared STM32 configuration snippets -INCLUDES += -I$(RIOTBOARD)/common/stm32/include - -# Default board USB port on host (FTDI based) -PORT = "/dev/ttyUSB0" - -# Setup of programmer and serial is shared between STM32 based boards -include $(RIOTMAKE)/boards/stm32.inc.mk diff --git a/boards/cogip-board-pami/board.c b/boards/cogip-board-pami/board.c deleted file mode 100644 index a9fbfdc9ad..0000000000 --- a/boards/cogip-board-pami/board.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2024 COGIP Robotics association - * - * 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_cogip-board-pami - * @{ - * - * @file - * @brief Board initialization code for cogip-board-pami - * - * @author Gilles DOFFE - * - * @} - */ - -#include "board.h" - -/** - * Start of the heap - */ -extern char _sheap; -/** - * End of the heap - */ -extern char _eheap; - -/** - * Pointer to start of the heap - */ -char *__sheap = &_sheap; -/** - * Pointer to end of the heap - */ -char *__eheap = &_eheap; - -/** - * Board init - */ -void board_init(void) -{ - // Setup and set heartbit LED - gpio_init(HEARTBEAT_LED, GPIO_OUT); - gpio_set(HEARTBEAT_LED); - - puts("Board successfully initialized."); -} diff --git a/boards/cogip-board-pami/dist/openocd.cfg b/boards/cogip-board-pami/dist/openocd.cfg deleted file mode 100644 index b295d46ef8..0000000000 --- a/boards/cogip-board-pami/dist/openocd.cfg +++ /dev/null @@ -1,4 +0,0 @@ -set WORKAREASIZE 0x10000 -source [find target/stm32f4x.cfg] -reset_config srst_only -$_TARGETNAME configure -rtos auto diff --git a/boards/cogip-board-pami/include/board.h b/boards/cogip-board-pami/include/board.h deleted file mode 100644 index 473c4368e8..0000000000 --- a/boards/cogip-board-pami/include/board.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2024 COGIP Robotics association - * - * 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 boards_cogip-board-pami COGIP 2024 PAMI robots board - * @ingroup boards_cogip-board-ng - * @brief Support for the COGIP 2024 PAMI robots embedded board - * @{ - * - * @file - * @brief Common pin definitions and board configuration options - * - * @author Gilles DOFFE - */ - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Not connected GPIO for fake use */ -#define GPIO_OUTPUT_UNUSED GPIO_PIN(PORT_B, 15) - -/* LEDs */ -#define HEARTBEAT_LED GPIO_PIN(PORT_A, 0) - -/* GPIOs expander */ -#define PCF857X_PORT_0 0 - -/* Servomotors */ -#define LX_DIR_PIN GPIO_PIN(PORT_B, 3) -#define LX_UART_DEV 2 - -/** - * @brief Initialize board specific hardware, including clock, LEDs and std-IO - */ -void board_init(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/boards/cogip-board-pami/include/periph_conf.h b/boards/cogip-board-pami/include/periph_conf.h deleted file mode 100644 index 4f2fb7a8fc..0000000000 --- a/boards/cogip-board-pami/include/periph_conf.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2024 COGIP Robotics association - * - * 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_cogip-board-pami - * @{ - * - * @file - * @brief Peripheral MCU configuration for the cogip-board-pami board - * - * @author Gilles DOFFE - */ - -#pragma once - -#include "periph_cpu.h" -#include "clk_conf.h" -#include "cfg_timer_tim5.h" -#include "cfg_i2c1_pb8_pb9.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @name DMA streams configuration - * @{ - */ -static const dma_conf_t dma_config[] = { - { .stream = 11 }, /* DMA2 Stream 3 - SPI1_TX */ - { .stream = 10 }, /* DMA2 Stream 2 - SPI1_RX */ - { .stream = 4 }, /* DMA1 Stream 4 - SPI2_TX */ - { .stream = 3 }, /* DMA1 Stream 3 - SPI2_RX */ - { .stream = 5 }, /* DMA1 Stream 5 - SPI3_TX */ - { .stream = 0 }, /* DMA1 Stream 0 - SPI3_RX */ -}; - -#define DMA_0_ISR isr_dma2_stream3 -#define DMA_1_ISR isr_dma2_stream2 -#define DMA_2_ISR isr_dma1_stream4 -#define DMA_3_ISR isr_dma1_stream3 -#define DMA_4_ISR isr_dma1_stream5 -#define DMA_5_ISR isr_dma1_stream0 - -#define DMA_NUMOF ARRAY_SIZE(dma_config) -/** @} */ - -/** - * @name UART configuration - * @{ - */ -static const uart_conf_t uart_config[] = { - { - /* Console */ - .dev = USART2, - .rcc_mask = RCC_APB1ENR_USART2EN, - .rx_pin = GPIO_PIN(PORT_A, 3), - .tx_pin = GPIO_PIN(PORT_A, 2), - .rx_af = GPIO_AF7, - .tx_af = GPIO_AF7, - .bus = APB1, - .irqn = USART2_IRQn, -#ifdef MODULE_PERIPH_DMA - .dma = DMA_STREAM_UNDEF, - .dma_chan = UINT8_MAX, -#endif - }, - { - /* Protobuf */ - .dev = USART1, - .rcc_mask = RCC_APB2ENR_USART1EN, - .rx_pin = GPIO_PIN(PORT_A, 10), - .tx_pin = GPIO_PIN(PORT_A, 9), - .rx_af = GPIO_AF7, - .tx_af = GPIO_AF7, - .bus = APB2, - .irqn = USART1_IRQn, -#ifdef MODULE_PERIPH_DMA - .dma = DMA_STREAM_UNDEF, - .dma_chan = UINT8_MAX, -#endif - }, - { - /* Servomotors */ - .dev = UART5, - .rcc_mask = RCC_APB1ENR_UART5EN, - .rx_pin = GPIO_PIN(PORT_D, 2), - .tx_pin = GPIO_PIN(PORT_C, 12), - .rx_af = GPIO_AF8, - .tx_af = GPIO_AF8, - .bus = APB1, - .irqn = UART5_IRQn, -#ifdef MODULE_PERIPH_DMA - .dma = DMA_STREAM_UNDEF, - .dma_chan = UINT8_MAX, -#endif - } -}; - -#define UART_0_ISR (isr_usart2) -#define UART_1_ISR (isr_usart1) -#define UART_2_ISR (isr_uart5) - -#define UART_NUMOF ARRAY_SIZE(uart_config) -/** @} */ - -/** - * @name PWM configuration - * @{ - */ -static const pwm_conf_t pwm_config[] = { - /* Motion motors */ - { - .dev = TIM2, - .rcc_mask = RCC_APB1ENR_TIM2EN, - .chan = { - /* Left motor PWM */ - { .pin = GPIO_PIN(PORT_A, 1), .cc_chan = 1 }, - /* Right motor PWM */ - { .pin = GPIO_PIN(PORT_A, 5), .cc_chan = 0 } - }, - .af = GPIO_AF1, - .bus = APB1 - }, - /* Actuators */ - { - .dev = TIM8, - .rcc_mask = RCC_APB2ENR_TIM8EN, - .chan = { - { .pin = GPIO_PIN(PORT_C, 6), .cc_chan = 0 }, - { .pin = GPIO_PIN(PORT_C, 7), .cc_chan = 1 }, - { .pin = GPIO_PIN(PORT_C, 8), .cc_chan = 2 }, - { .pin = GPIO_PIN(PORT_C, 9), .cc_chan = 3 } - }, - .af = GPIO_AF3, - .bus = APB2 - }, -}; - -#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) -/** @} */ - -/** - * @name QDEC configuration - * @{ - */ -static const qdec_conf_t qdec_config[] = { - /* Left encoder */ - { - .dev = TIM4, - .max = 0xffffffff, - .rcc_mask = RCC_APB1ENR_TIM4EN, - .chan = { { .pin = GPIO_PIN(PORT_B, 6), .cc_chan = 0 }, - { .pin = GPIO_PIN(PORT_B, 7), .cc_chan = 1 } }, - .af = GPIO_AF2, - .bus = APB1, - .irqn = TIM4_IRQn - }, - /* Right encoder */ - { - .dev = TIM3, - .max = 0xffffffff, - .rcc_mask = RCC_APB1ENR_TIM3EN, - .chan = { { .pin = GPIO_PIN(PORT_A, 6), .cc_chan = 0 }, - { .pin = GPIO_PIN(PORT_A, 7), .cc_chan = 1 } }, - .af = GPIO_AF2, - .bus = APB1, - .irqn = TIM3_IRQn - }, -}; - -#define QDEC_0_ISR isr_tim3 -#define QDEC_1_ISR isr_tim4 - -#define QDEC_NUMOF (sizeof(qdec_config) / sizeof(qdec_config[0])) -/** @} */ - -/** - * @name I2C configuration - * @{ - */ - -#define I2C_0_ISR isr_i2c1_ev - -#define I2C_NUMOF ARRAY_SIZE(i2c_config) -/** @} */ - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/boards/cogip-board/Makefile.include b/boards/cogip-board/Makefile.include index 5018a9f4ae..9004253567 100644 --- a/boards/cogip-board/Makefile.include +++ b/boards/cogip-board/Makefile.include @@ -6,3 +6,6 @@ PORT = "/dev/ttyUSB0" # Setup of programmer and serial is shared between STM32 based boards include $(RIOTMAKE)/boards/stm32.inc.mk + +# Set onboard transceiver loop delay +CFLAGS += -DCONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY=130 diff --git a/boards/cogip-board/board.c b/boards/cogip-board/board.c index 534bec920a..7655397e22 100644 --- a/boards/cogip-board/board.c +++ b/boards/cogip-board/board.c @@ -19,6 +19,7 @@ */ #include "board.h" +#include /** * Start of the heap diff --git a/boards/cogip-native/Makefile.features b/boards/cogip-native/Makefile.features index 504a29f997..eb319cbf98 100644 --- a/boards/cogip-native/Makefile.features +++ b/boards/cogip-native/Makefile.features @@ -13,4 +13,4 @@ FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart # Various other features (if any) -FEATURES_PROVIDED += ethernet +FEATURES_PROVIDED += netif_ethernet diff --git a/boards/cogip-native/Makefile.include b/boards/cogip-native/Makefile.include index c2b543db0b..aba8ce4d56 100644 --- a/boards/cogip-native/Makefile.include +++ b/boards/cogip-native/Makefile.include @@ -1,2 +1,5 @@ NATIVEINCLUDES += -DBOARD_NATIVE include $(RIOTBASE)/boards/native/Makefile.include + +# Set onboard transceiver loop delay, mandatory so set fake value +CFLAGS += -DCONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY=0 diff --git a/drivers/doxygen.txt b/drivers/doxygen.txt deleted file mode 100644 index d66de90c50..0000000000 --- a/drivers/doxygen.txt +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (C) 2020 COGIP Robotics association - * - * 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 Drivers - */ diff --git a/drivers/lds01/Makefile b/drivers/lds01/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/lds01/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/lds01/Makefile.dep b/drivers/lds01/Makefile.dep deleted file mode 100644 index 51fe6bc46b..0000000000 --- a/drivers/lds01/Makefile.dep +++ /dev/null @@ -1 +0,0 @@ -FEATURES_REQUIRED += periph_uart diff --git a/drivers/lds01/Makefile.include b/drivers/lds01/Makefile.include deleted file mode 100644 index 0d93a16715..0000000000 --- a/drivers/lds01/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -USEMODULE_INCLUDES_lds01 := $(LAST_MAKEFILEDIR)/include -USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_lds01) diff --git a/drivers/lds01/include/lds01.h b/drivers/lds01/include/lds01.h deleted file mode 100644 index 8d983be40a..0000000000 --- a/drivers/lds01/include/lds01.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2021 COGIP Robotics association - * - * 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 driver_lds01 LDS01 LiDAR driver - * @ingroup drivers - * @brief LDS01 (aka HLS-LFCD2) LiDAR driver - * - * The LDS01 (aka HLS-LFCD2) device is a 360° 2D LiDAR distance sensor. - * See specifications [here](https://emanual.robotis.com/assets/docs/LDS_Basic_Specification.pdf). - * - * Distances are reported in millimeters. - * - * @{ - * @file - * @brief Public API for LDS01 driver - * - * @author Eric Courtois - */ - -#pragma once - -/* Standard includes */ -#include -#include - -/* RIOT includes */ -#include "mutex.h" -#include "ringbuffer.h" - -/* Periph includes */ -#include "periph/uart.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define LDS01_NB_ANGLES (360U) /**< number of angles (360°) */ - -typedef void (*lds01_new_frame_cb_t)(void); /**< new frame callback signature */ - -/** - * @brief LDS01 parameters - */ -typedef struct { - uart_t uart; /**< UART device */ - lds01_new_frame_cb_t new_frame_cb; /**< function called when a new frame is available */ - bool invert_data; /**< invert data (false by default) */ -} lds01_params_t; - -/** - * @brief Default LDS01 identifier definition - */ -typedef unsigned int lds01_t; - -/** - * @brief Initialize LDS01 device - * - * @param[in] lds01 lds01 device id to initialize - * @param[in] params lds01 parameters - * - * @return 0 on success, not 0 otherwise - */ -int lds01_init(const lds01_t lds01, const lds01_params_t *params); - -/** - * @brief Update data arrays - * - * Get the last fame and update corresponding indexes in data arrays - * - * @param[in] lds01 lds01 device id - */ -void lds01_update_last_frame(const lds01_t lds01); - -/** - * @brief Start LDS01 device - * - * @param[in] lds01 lds01 device id - */ -void lds01_start(const lds01_t lds01); - -/** - * @brief Stop LDS01 device - * - * @param[in] lds01 lds01 device id - */ -void lds01_stop(const lds01_t lds01); - -/** - * @brief Set new distance filter value - * - * @param[in] lds01 lds01 device id - * @param[in] new_filter value of the new filter, in millimeters, 0 means no filter - */ -void lds01_set_distance_filter(const lds01_t lds01, uint16_t new_filter); - -/** - * @brief Set new minimun intensity value used to validate distances - * - * @param[in] lds01 lds01 device id - * @param[in] new_filter value of the new minimun intensity - */ -void lds01_set_min_intensity(const lds01_t lds01, uint16_t new_min_intensity); - -/** - * @brief Get distance data - * - * @param[in] lds01 lds01 device id - * @param[out] distances array pointer to copy distance data - */ -void lds01_get_distances(const lds01_t lds01, uint16_t *distances); - -/** - * @brief Get intentity data - * - * @param[in] lds01 lds01 device id - * @param[out] intensities array pointer to copy intensity data - */ -void lds01_get_intensities(const lds01_t lds01, uint16_t *intensities); - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/drivers/lds01/include/lds01_params.h.template b/drivers/lds01/include/lds01_params.h.template deleted file mode 100644 index c30dcf413e..0000000000 --- a/drivers/lds01/include/lds01_params.h.template +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2021 COGIP Robotics association - * - * 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 driver_lds01 - * @{ - * - * @file - * @brief Default parameters for LDS01 driver - * - * @author Eric Courtois - */ - -#error This default header should not be included. \ - Create your own lds01_params.h in your application folder. - -/* Code below is given as example */ -#pragma once - -#include "lds01.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief LDS01 configuration - */ -static const lds01_params_t lds01_params[] = { - { - .uart = UART_DEV(2), - .new_frame_cb = NULL, - .invert_data = false - } -}; - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/drivers/lds01/lds01.c b/drivers/lds01/lds01.c deleted file mode 100644 index 4ed14c9015..0000000000 --- a/drivers/lds01/lds01.c +++ /dev/null @@ -1,261 +0,0 @@ -#include "lds01.h" -#include "lds01_params.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#include - -#define LDS01_NUMOF ARRAY_SIZE(lds01_params) /**< number of used lds01 devices */ -#define LDS01_FRAME_SYNC_BYTE (0xFA) /**< first byte of a frame */ -#define LDS01_NB_FRAMES (40U) /**< number of frames to get all angles */ -#define LDS01_NB_ANGLES_BY_FRAME (6U) /**< number of angles in one frame */ - -#define LDS01_UART_BAUD (230400U) /**< lds01 UART baud rate */ -#define LDS01_FRAME_SIZE (sizeof(lds01_frame_t)) /**< lds01 frame size */ -#define LDS01_BUFFER_SIZE (LDS01_FRAME_SIZE * 4) /**< size of the ringbuffer used to store raw data from UART */ - -/** - * @brief LDS01 offset - */ -typedef struct { - uint8_t intensity[2]; /**< intentity bytes */ - uint8_t distance[2]; /**< distance bytes */ - // cppcheck-suppress unusedStructMember - uint8_t reserved[2]; /**< reserved bytes */ -} lds01_offset_t; - -/** - * @brief LDS01 frame - */ -typedef struct { - uint8_t sync; /**< begin frame byte (0xAF) */ - uint8_t index; /**< frame index */ - uint8_t rpm[2]; /**< rpm (unused)*/ - lds01_offset_t offsets[6]; /**< frame offsets */ - uint8_t checksum[2]; /**< frame checksum */ -} lds01_frame_t; - -/** - * @brief LDS01 descriptor - */ -typedef struct { - lds01_params_t params; /**< parameters */ - bool running; /**< set to true if lds01 is running */ - uint16_t filter; /**< distance filter in millimeters */ - uint16_t min_intensity; /**< minimum intensity to consider the data valid */ - mutex_t data_lock; /**< lock protecting data access */ - uint16_t distances[LDS01_NB_ANGLES]; /**< distance data */ - uint16_t intensities[LDS01_NB_ANGLES]; /**< intensity data */ - char rx_mem[LDS01_BUFFER_SIZE]; /**< raw frame buffer */ - ringbuffer_t rx_buf; /**< frame ringbuffer */ - uint8_t remaining_bytes_in_frame; /**< number of bytes to read for a full frame */ -} lds01_dev_t; - -/* Allocate memory for the device descriptor */ -lds01_dev_t lds01_devs[LDS01_NUMOF]; - -static void lds01_rx_cb(void *arg, uint8_t data) -{ - lds01_dev_t *lds01_dev = (lds01_dev_t *)arg; - - if (data == LDS01_FRAME_SYNC_BYTE && lds01_dev->remaining_bytes_in_frame == 0) { - lds01_dev->remaining_bytes_in_frame = LDS01_FRAME_SIZE; - } - if (lds01_dev->remaining_bytes_in_frame == 0) { - return; - } - - ringbuffer_add_one(&(lds01_dev->rx_buf), data); - lds01_dev->remaining_bytes_in_frame--; - - if (lds01_dev->remaining_bytes_in_frame == 0) { - if (lds01_dev->params.new_frame_cb) { - lds01_dev->params.new_frame_cb(); - } - else { - ringbuffer_remove(&(lds01_dev->rx_buf), LDS01_FRAME_SIZE); - } - } -} - -static void lds01_reset_data(lds01_dev_t *lds01_dev) -{ - lds01_dev->remaining_bytes_in_frame = 0; - memset((void *)lds01_dev->distances, 0, LDS01_NB_ANGLES * sizeof(uint16_t)); - memset((void *)lds01_dev->intensities, 0, LDS01_NB_ANGLES * sizeof(uint16_t)); - ringbuffer_init(&(lds01_dev->rx_buf), lds01_dev->rx_mem, LDS01_BUFFER_SIZE); -} - -static int lds01_is_frame_valid(const lds01_frame_t *frame) -{ - int sum = 0; - - for (unsigned int i = 0; i < LDS01_NB_FRAMES; i++) { - sum += ((const char *)frame)[i]; - } - sum &= 0xFF; - return frame->checksum[0] == 0xFF - sum; -} - -static uint16_t lds01_get_filtered_distance(lds01_dev_t *lds01_dev, uint16_t distance, uint16_t intensity) -{ - if (lds01_dev->filter == 0) { - return distance; - } - if (intensity < lds01_dev->min_intensity || distance == 0 || distance > lds01_dev->filter) { - return lds01_dev->filter; - } - return distance; -} - -void lds01_update_last_frame(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_frame_t frame; - uint16_t distances_tmp[LDS01_NB_ANGLES_BY_FRAME]; - uint16_t intensities_tmp[LDS01_NB_ANGLES_BY_FRAME]; - unsigned bytes_read = ringbuffer_get(&(lds01_dev->rx_buf), (char *)&frame, LDS01_FRAME_SIZE); - - if (bytes_read != LDS01_FRAME_SIZE) { - printf("Read error: %u\n", bytes_read); - } - if (!lds01_is_frame_valid(&frame)) { - return; - } - - /* Compute new values in a local array */ - for (unsigned int i = 0; i < LDS01_NB_ANGLES_BY_FRAME; i++) { - uint16_t distance = (frame.offsets[i].distance[1] << 8) + frame.offsets[i].distance[0]; - uint16_t intensity = (frame.offsets[i].intensity[1] << 8) + frame.offsets[i].intensity[0]; - distances_tmp[i] = lds01_get_filtered_distance(lds01_dev, distance, intensity); - intensities_tmp[i] = intensity; - } - - uint8_t index = frame.index - 0xA0; - - /* Update values in arrays given in parameters*/ - mutex_lock(&lds01_dev->data_lock); - memcpy( - (void *)(&lds01_dev->distances[index * LDS01_NB_ANGLES_BY_FRAME]), - (void *)distances_tmp, LDS01_NB_ANGLES_BY_FRAME * sizeof(uint16_t)); - memcpy( - (void *)(&lds01_dev->intensities[index * LDS01_NB_ANGLES_BY_FRAME]), - (void *)intensities_tmp, LDS01_NB_ANGLES_BY_FRAME * sizeof(uint16_t)); - mutex_unlock(&lds01_dev->data_lock); -} - -int lds01_init(const lds01_t lds01, const lds01_params_t *params) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->params = *params; - lds01_dev->filter = 0; - lds01_dev->min_intensity = 0; - lds01_reset_data(lds01_dev); - mutex_init(&lds01_dev->data_lock); - - int res = uart_init(lds01_dev->params.uart, LDS01_UART_BAUD, lds01_rx_cb, (void *)lds01_dev); - - if (res == UART_NOBAUD) { - printf("Error: Given baudrate (%u) not possible\n", LDS01_UART_BAUD); - return 1; - } - else if (res != UART_OK) { - puts("Error: Unable to initialize UART device"); - return 1; - } - - lds01_dev->running = true; /* force stop on startup */ - lds01_stop(lds01); - - DEBUG("LDS01 UART initialized\n"); - - return 0; -} - -void lds01_start(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - if (lds01_dev->running) { - return; - } - lds01_reset_data(lds01_dev); - lds01_dev->running = true; - uart_write(lds01_dev->params.uart, (uint8_t *)"b", 1); -} - -void lds01_stop(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - if (!lds01_dev->running) { - return; - } - uart_write(lds01_dev->params.uart, (uint8_t *)"e", 1); - lds01_dev->running = false; -} - -void lds01_set_distance_filter(const lds01_t lds01, uint16_t new_filter) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->filter = new_filter; -} - -void lds01_set_min_intensity(const lds01_t lds01, uint16_t new_min_intensity) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->min_intensity = new_min_intensity; -} - -void lds01_get_distances(const lds01_t lds01, uint16_t *distances) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - mutex_lock(&lds01_dev->data_lock); - if (lds01_dev->params.invert_data) { - for (uint16_t i = 0; i < LDS01_NB_ANGLES; i++) { - distances[i] = lds01_dev->distances[(LDS01_NB_ANGLES - i) % LDS01_NB_ANGLES]; - } - } - else { - memcpy((void *)distances, (void *)lds01_dev->distances, LDS01_NB_ANGLES * sizeof(uint16_t)); - } - mutex_unlock(&lds01_dev->data_lock); -} - -void lds01_get_intensities(const lds01_t lds01, uint16_t *intensities) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - mutex_lock(&lds01_dev->data_lock); - if (lds01_dev->params.invert_data) { - for (uint16_t i = 0; i < LDS01_NB_ANGLES; i++) { - intensities[i] = lds01_dev->intensities[(LDS01_NB_ANGLES - i) % LDS01_NB_ANGLES]; - } - } - else { - memcpy((void *)intensities, (void *)lds01_dev->intensities, LDS01_NB_ANGLES * sizeof(uint16_t)); - } - mutex_unlock(&lds01_dev->data_lock); -} diff --git a/drivers/lds01_dma/Makefile b/drivers/lds01_dma/Makefile deleted file mode 100644 index c449a6b47e..0000000000 --- a/drivers/lds01_dma/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -ifeq ($(CPU),native) - SRC=lds01_native.c -else - SRC=lds01.c -endif - -include $(RIOTBASE)/Makefile.base diff --git a/drivers/lds01_dma/Makefile.dep b/drivers/lds01_dma/Makefile.dep deleted file mode 100644 index ea7e6e60fe..0000000000 --- a/drivers/lds01_dma/Makefile.dep +++ /dev/null @@ -1,7 +0,0 @@ -ifeq ($(CPU),native) - USEMODULE += shmem -else - FEATURES_REQUIRED += periph_dma -endif - -FEATURES_REQUIRED += periph_uart diff --git a/drivers/lds01_dma/Makefile.include b/drivers/lds01_dma/Makefile.include deleted file mode 100644 index f8226865f7..0000000000 --- a/drivers/lds01_dma/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -USEMODULE_INCLUDES_lds01_dma := $(LAST_MAKEFILEDIR)/include -USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_lds01_dma) diff --git a/drivers/lds01_dma/include/lds01.h b/drivers/lds01_dma/include/lds01.h deleted file mode 100644 index c69f146c2c..0000000000 --- a/drivers/lds01_dma/include/lds01.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2021 COGIP Robotics association - * - * 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 driver_lds01_dma LDS01 LiDAR driver - * @ingroup drivers - * @brief LDS01 (aka HLS-LFCD2) LiDAR driver - * - * The LDS01 (aka HLS-LFCD2) device is a 360° 2D LiDAR distance sensor. - * See specifications [here](https://emanual.robotis.com/assets/docs/LDS_Basic_Specification.pdf). - * - * Distances are reported in millimeters. - * - * This driver is not generic, it considers using our boards - * (based on nucleo-f446re), with LDS01 device connected to USART3, - * using DMA 1, Stream 1, Channel 4 for peripheral to memory transfers. - * - * @{ - * @file - * @brief Public API for LDS01 driver - * - * @author Eric Courtois - */ - -#pragma once - -/* Standard includes */ -#include -#include - -/* RIOT includes */ -#include "mutex.h" -#include "ringbuffer.h" - -/* Periph includes */ -#include "periph/uart.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define LDS01_NB_ANGLES (360U) /**< number of angles (360°) */ - -typedef void (*lds01_new_frame_cb_t)(void); /**< new frame callback signature */ - -/** - * @brief LDS01 parameters - */ -typedef struct { - uart_t uart; /**< UART device */ - lds01_new_frame_cb_t new_frame_cb; /**< function called when a new frame is available */ - bool invert_data; /**< invert data (false by default) */ -} lds01_params_t; - -/** - * @brief Default LDS01 identifier definition - */ -typedef unsigned int lds01_t; - -/** - * @brief Initialize LDS01 device - * - * @param[in] lds01 lds01 device id to initialize - * @param[in] params lds01 parameters - * - * @return 0 on success, not 0 otherwise - */ -int lds01_init(const lds01_t lds01, const lds01_params_t *params); - -/** - * @brief Update data arrays - * - * Get the last fame and update corresponding indexes in data arrays - * - * @param[in] lds01 lds01 device id - */ -void lds01_update_last_frame(const lds01_t lds01); - -/** - * @brief Start LDS01 device - * - * @param[in] lds01 lds01 device id - */ -void lds01_start(const lds01_t lds01); - -/** - * @brief Stop LDS01 device - * - * @param[in] lds01 lds01 device id - */ -void lds01_stop(const lds01_t lds01); - -/** - * @brief Set new distance filter value - * - * @param[in] lds01 lds01 device id - * @param[in] new_filter value of the new filter, in millimeters, 0 means no filter - */ -void lds01_set_distance_filter(const lds01_t lds01, uint16_t new_filter); - -/** - * @brief Set new minimun intensity value used to validate distances - * - * @param[in] lds01 lds01 device id - * @param[in] new_filter value of the new minimun intensity - */ -void lds01_set_min_intensity(const lds01_t lds01, uint16_t new_min_intensity); - -/** - * @brief Get distance data - * - * @param[in] lds01 lds01 device id - * @param[out] distances array pointer to copy distance data - */ -void lds01_get_distances(const lds01_t lds01, uint16_t *distances); - -/** - * @brief Get intentity data - * - * @param[in] lds01 lds01 device id - * @param[out] intensities array pointer to copy intensity data - */ -void lds01_get_intensities(const lds01_t lds01, uint16_t *intensities); - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/drivers/lds01_dma/include/lds01_params.h.template b/drivers/lds01_dma/include/lds01_params.h.template deleted file mode 100644 index bad0084b76..0000000000 --- a/drivers/lds01_dma/include/lds01_params.h.template +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 COGIP Robotics association - * - * 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 driver_lds01_dma - * @{ - * - * @file - * @brief Default parameters for LDS01 driver - * - * @author Eric Courtois - */ - - -#error This default header should not be included. \ - Create your own lds01_params.h in your application folder. - -/* Code below is given as example */ - -#pragma once - -#include "lds01.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief LDS01 configuration - */ -static const lds01_params_t lds01_params[] = { - { - .uart = UART_DEV(2), - .new_frame_cb = NULL, - .invert_data = false - } -}; - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/drivers/lds01_dma/lds01.c b/drivers/lds01_dma/lds01.c deleted file mode 100644 index b3b1c3aa3f..0000000000 --- a/drivers/lds01_dma/lds01.c +++ /dev/null @@ -1,324 +0,0 @@ -#include "lds01.h" -#include "lds01_params.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#include - -#include "cpu.h" -#include "periph/uart.h" -#include "periph/gpio.h" -#include "stm32f446xx.h" - -#define LDS01_NUMOF ARRAY_SIZE(lds01_params) /**< number of used lds01 devices */ -#define LDS01_FRAME_SYNC_BYTE (0xFA) /**< first byte of a frame */ -#define LDS01_NB_FRAMES (40U) /**< number of frames to get all angles */ -#define LDS01_NB_ANGLES_BY_FRAME (6U) /**< number of angles in one frame */ - -#define USART3_RX_DMA_STREAM DMA1_Stream1 -#define USART3_RX_DMA_CHAN 4 - -#define LDS01_UART_BAUD (230400U) /**< lds01 UART baud rate */ -#define LDS01_FRAME_SIZE (sizeof(lds01_frame_t)) /**< lds01 frame size */ -#define LDS01_BUFFER_SIZE (LDS01_FRAME_SIZE * 4) /**< size of the ringbuffer used to store raw data from UART */ - -/** - * @brief LDS01 offset - */ -typedef struct { - uint8_t intensity[2]; /**< intentity bytes */ - uint8_t distance[2]; /**< distance bytes */ - // cppcheck-suppress unusedStructMember - uint8_t reserved[2]; /**< reserved bytes */ -} lds01_offset_t; - -/** - * @brief LDS01 frame - */ -typedef struct { - uint8_t sync; /**< begin frame byte (0xAF) */ - uint8_t index; /**< frame index */ - uint8_t rpm[2]; /**< rpm (unused)*/ - lds01_offset_t offsets[6]; /**< frame offsets */ - uint8_t checksum[2]; /**< frame checksum */ -} lds01_frame_t; - -/** - * @brief LDS01 descriptor - */ -typedef struct { - lds01_params_t params; /**< parameters */ - bool running; /**< set to true if lds01 is running */ - uint16_t filter; /**< distance filter in millimeters */ - uint16_t min_intensity; /**< minimum intensity to consider the data valid */ - mutex_t data_lock; /**< lock protecting data access */ - uint16_t distances[LDS01_NB_ANGLES]; /**< distance data */ - uint16_t intensities[LDS01_NB_ANGLES]; /**< intensity data */ - char rx_mem[LDS01_BUFFER_SIZE]; /**< raw frame buffer */ - ringbuffer_t rx_buf; /**< frame ringbuffer */ - uint8_t dma_rx_buf[LDS01_FRAME_SIZE * 2]; /**< DMA read buffer */ -} lds01_dev_t; - -/* Allocate memory for the device descriptor */ -lds01_dev_t lds01_devs[LDS01_NUMOF]; - -void isr_dma1_stream1(void) -{ - lds01_dev_t *lds01_dev = &lds01_devs[0]; - uint8_t *buf_ptr = NULL; - - /* Handle half transfer interrupt */ - if (DMA1->LISR & DMA_LISR_HTIF1_Msk) { - buf_ptr = lds01_dev->dma_rx_buf; - } - - /* Handle transfer complete interrupt */ - if (DMA1->LISR & DMA_LISR_TCIF1_Msk) { - buf_ptr = lds01_dev->dma_rx_buf + LDS01_FRAME_SIZE; - } - - /* Copy transfered data in ringbuffer and send an event to the thread */ - if (buf_ptr) { - ringbuffer_add(&(lds01_dev->rx_buf), (const char *)buf_ptr, LDS01_FRAME_SIZE); - if (lds01_dev->params.new_frame_cb) { - lds01_dev->params.new_frame_cb(); - } - else { - ringbuffer_remove(&(lds01_dev->rx_buf), LDS01_FRAME_SIZE); - } - } - - DMA1->LIFCR = ( - DMA_LISR_FEIF0 | DMA_LISR_DMEIF0 | - DMA_LISR_TEIF0 | DMA_LISR_HTIF0 | - DMA_LISR_TCIF0 - ) << 6; - - cortexm_isr_end(); -} - -static void lds01_reset_data(lds01_dev_t *lds01_dev) -{ - memset((void *)lds01_dev->dma_rx_buf, 0, 42 * 2); - memset((void *)lds01_dev->distances, 0, LDS01_NB_ANGLES * sizeof(uint16_t)); - memset((void *)lds01_dev->intensities, 0, LDS01_NB_ANGLES * sizeof(uint16_t)); - ringbuffer_init(&(lds01_dev->rx_buf), lds01_dev->rx_mem, LDS01_BUFFER_SIZE); -} - -static int lds01_is_frame_valid(const lds01_frame_t *frame) -{ - int sum = 0; - - for (unsigned int i = 0; i < LDS01_NB_FRAMES; i++) { - sum += ((const char *)frame)[i]; - } - sum &= 0xFF; - return frame->checksum[0] == 0xFF - sum; -} - -static uint16_t lds01_get_filtered_distance(lds01_dev_t *lds01_dev, uint16_t distance, uint16_t intensity) -{ - if (lds01_dev->filter == 0) { - return distance; - } - if (intensity < lds01_dev->min_intensity || distance == 0 || distance > lds01_dev->filter) { - return lds01_dev->filter; - } - return distance; -} - -void lds01_update_last_frame(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_frame_t frame; - uint16_t distances_tmp[LDS01_NB_ANGLES_BY_FRAME]; - uint16_t intensities_tmp[LDS01_NB_ANGLES_BY_FRAME]; - unsigned bytes_read; - - bool skip = false; - - while (!ringbuffer_empty(&(lds01_dev->rx_buf)) && - ringbuffer_peek_one(&(lds01_dev->rx_buf)) != LDS01_FRAME_SYNC_BYTE) { - ringbuffer_get_one(&(lds01_dev->rx_buf)); - skip = true; - } - if (skip) { - return; - } - - bytes_read = ringbuffer_get(&(lds01_dev->rx_buf), (char *)&frame, LDS01_FRAME_SIZE); - - if (bytes_read != LDS01_FRAME_SIZE) { - printf("Read error: %u\n", bytes_read); - } - if (!lds01_is_frame_valid(&frame)) { - return; - } - - /* Compute new values in a local array */ - for (unsigned int i = 0; i < LDS01_NB_ANGLES_BY_FRAME; i++) { - uint16_t distance = (frame.offsets[i].distance[1] << 8) + frame.offsets[i].distance[0]; - uint16_t intensity = (frame.offsets[i].intensity[1] << 8) + frame.offsets[i].intensity[0]; - distances_tmp[i] = lds01_get_filtered_distance(lds01_dev, distance, intensity); - intensities_tmp[i] = intensity; - } - - uint8_t index = frame.index - 0xA0; - - /* Update values in arrays given in parameters*/ - mutex_lock(&lds01_dev->data_lock); - memcpy( - (void *)(&lds01_dev->distances[index * LDS01_NB_ANGLES_BY_FRAME]), - (void *)distances_tmp, LDS01_NB_ANGLES_BY_FRAME * sizeof(uint16_t)); - memcpy( - (void *)(&lds01_dev->intensities[index * LDS01_NB_ANGLES_BY_FRAME]), - (void *)intensities_tmp, LDS01_NB_ANGLES_BY_FRAME * sizeof(uint16_t)); - mutex_unlock(&lds01_dev->data_lock); -} - -int lds01_init(const lds01_t lds01, const lds01_params_t *params) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->params = *params; - lds01_dev->filter = 0; - lds01_dev->min_intensity = 0; - lds01_reset_data(lds01_dev); - mutex_init(&lds01_dev->data_lock); - - int res = uart_init(lds01_dev->params.uart, LDS01_UART_BAUD, NULL, NULL); - - if (res == UART_NOBAUD) { - printf("Error: Given baudrate (%u) not possible\n", LDS01_UART_BAUD); - return 1; - } - else if (res != UART_OK) { - puts("Error: Unable to initialize UART device"); - return 1; - } - - /* Initialize UART RX */ - gpio_init(uart_config[lds01_dev->params.uart].rx_pin, GPIO_IN_PU); - gpio_init_af(uart_config[lds01_dev->params.uart].rx_pin, \ - uart_config[lds01_dev->params.uart].rx_af); - - USART3->CR1 |= USART_CR1_RE | USART_CR1_RXNEIE; - USART3->CR3 |= USART_CR3_DMAR; - - /* Initialize DMA */ - NVIC_EnableIRQ(DMA1_Stream1_IRQn); - - USART3_RX_DMA_STREAM->FCR = 0; /* Disable FIFO mode => enable direct mode */ - - USART3_RX_DMA_STREAM->PAR = (uint32_t)&(USART3->DR); /* Set periph address to UART data register */ - USART3_RX_DMA_STREAM->M0AR = (uint32_t)lds01_dev->dma_rx_buf; /* Set memory address to local buffer */ - USART3_RX_DMA_STREAM->NDTR = LDS01_FRAME_SIZE * 2; /* Set transfert size (2 frames) */ - - USART3_RX_DMA_STREAM->CR = 0; /* Reset control register */ - USART3_RX_DMA_STREAM->CR |= USART3_RX_DMA_CHAN << DMA_SxCR_CHSEL_Pos; /* Channel selection */ - USART3_RX_DMA_STREAM->CR |= 0 << DMA_SxCR_PSIZE_Pos; /* Peripheral data size = 8-bit */ - USART3_RX_DMA_STREAM->CR |= 0 << DMA_SxCR_MSIZE_Pos; /* Memory data size = 8-bit */ - USART3_RX_DMA_STREAM->CR |= 0 << DMA_SxCR_PINC_Pos; /* Don't auto-increment periph pointer */ - USART3_RX_DMA_STREAM->CR |= 1 << DMA_SxCR_MINC_Pos; /* Auto-increment memory pointer */ - USART3_RX_DMA_STREAM->CR |= DMA_PERIPH_TO_MEM << DMA_SxCR_DIR_Pos; /* Data transfer direction */ - USART3_RX_DMA_STREAM->CR |= DMA_SxCR_CIRC; /* Enable circular mode */ - USART3_RX_DMA_STREAM->CR |= DMA_SxCR_TCIE; /* Enable complete transfer interruption */ - USART3_RX_DMA_STREAM->CR |= DMA_SxCR_HTIE; /* Enable half transfer interruption */ - USART3_RX_DMA_STREAM->CR |= DMA_SxCR_TEIE; /* Enable transfer error interrupt */ - - lds01_dev->running = true; /* force stop on startup */ - lds01_stop(lds01); - - DEBUG("LDS01 UART initialized\n"); - - return 0; -} - -void lds01_start(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - if (lds01_dev->running) { - return; - } - lds01_reset_data(lds01_dev); - lds01_dev->running = true; - uart_write(lds01_dev->params.uart, (uint8_t *)"b", 1); - USART3_RX_DMA_STREAM->CR |= DMA_SxCR_EN; -} - -void lds01_stop(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - if (!lds01_dev->running) { - return; - } - uart_write(lds01_dev->params.uart, (uint8_t *)"e", 1); - USART3_RX_DMA_STREAM->CR &= ~DMA_SxCR_EN; - lds01_dev->running = false; -} - -void lds01_set_distance_filter(const lds01_t lds01, uint16_t new_filter) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->filter = new_filter; -} - -void lds01_set_min_intensity(const lds01_t lds01, uint16_t new_min_intensity) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->min_intensity = new_min_intensity; -} - -void lds01_get_distances(const lds01_t lds01, uint16_t *distances) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - mutex_lock(&lds01_dev->data_lock); - if (lds01_dev->params.invert_data) { - for (uint16_t i = 0; i < LDS01_NB_ANGLES; i++) { - distances[i] = lds01_dev->distances[(LDS01_NB_ANGLES - i) % LDS01_NB_ANGLES]; - } - } - else { - memcpy((void *)distances, (void *)lds01_dev->distances, LDS01_NB_ANGLES * sizeof(uint16_t)); - } - mutex_unlock(&lds01_dev->data_lock); -} - -void lds01_get_intensities(const lds01_t lds01, uint16_t *intensities) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - mutex_lock(&lds01_dev->data_lock); - if (lds01_dev->params.invert_data) { - for (uint16_t i = 0; i < LDS01_NB_ANGLES; i++) { - intensities[i] = lds01_dev->intensities[(LDS01_NB_ANGLES - i) % LDS01_NB_ANGLES]; - } - } - else { - memcpy((void *)intensities, (void *)lds01_dev->intensities, LDS01_NB_ANGLES * sizeof(uint16_t)); - } - mutex_unlock(&lds01_dev->data_lock); -} diff --git a/drivers/lds01_dma/lds01_native.c b/drivers/lds01_dma/lds01_native.c deleted file mode 100644 index 325a4f52f4..0000000000 --- a/drivers/lds01_dma/lds01_native.c +++ /dev/null @@ -1,133 +0,0 @@ -#include "lds01.h" -#include "lds01_params.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#include - -#include "shmem.h" - -const shmem_data_t *shared_data = NULL; - -#define LDS01_NUMOF ARRAY_SIZE(lds01_params) /**< number of used lds01 devices */ - -/** - * @brief LDS01 native descriptor - */ -typedef struct { - lds01_params_t params; /**< parameters */ - bool running; /**< set to true if lds01 is running */ - uint16_t filter; /**< distance filter in millimeters */ - uint16_t distances[LDS01_NB_ANGLES]; /**< distance data */ - uint16_t intensities[LDS01_NB_ANGLES]; /**< intensity data */ -} lds01_dev_t; - -/* Allocate memory for the device descriptor */ -lds01_dev_t lds01_devs[LDS01_NUMOF]; - -static uint16_t lds01_get_filtered_distance(lds01_dev_t *lds01_dev, uint16_t distance, uint16_t intensity) -{ - if (lds01_dev->filter == 0) { - return distance; - } - if (intensity == 0 || distance == 0 || distance > lds01_dev->filter) { - return lds01_dev->filter; - } - return distance; -} - -void lds01_update_last_frame(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); -} - -int lds01_init(const lds01_t lds01, const lds01_params_t *params) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->params = *params; - lds01_dev->filter = 0; - lds01_dev->running = false; - - for (unsigned int i = 0; i < LDS01_NB_ANGLES; i++) { - lds01_dev->distances[i] = 0; - lds01_dev->intensities[i] = 1000; - } - - DEBUG("LDS01 native initialized\n"); - - return 0; -} - -void lds01_start(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - if (lds01_dev->running) { - return; - } - lds01_dev->running = true; -} - -void lds01_stop(const lds01_t lds01) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->running = false; -} - -void lds01_set_distance_filter(const lds01_t lds01, uint16_t new_filter) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - lds01_dev->filter = new_filter; -} - -void lds01_set_min_intensity(const lds01_t lds01, uint16_t new_min_intensity) -{ - (void)new_min_intensity; - assert(lds01 < LDS01_NUMOF); -} - -void lds01_get_distances(const lds01_t lds01, uint16_t *distances) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - if (shared_data == NULL) { - shared_data = shmem_get_data(); - } - - if (shared_data) { - for (unsigned int i = 0; i < LDS01_NB_ANGLES; i++) { - uint16_t distance = shared_data->lidar_distances[i]; - if (lds01_dev->params.invert_data) { - lds01_dev->distances[(LDS01_NB_ANGLES - i) % LDS01_NB_ANGLES] = lds01_get_filtered_distance(lds01_dev, distance, 1); - } - else { - lds01_dev->distances[i] = lds01_get_filtered_distance(lds01_dev, distance, 1); - } - } - } - - memcpy((void *)distances, (void *)lds01_dev->distances, LDS01_NB_ANGLES * sizeof(uint16_t)); -} - -void lds01_get_intensities(const lds01_t lds01, uint16_t *intensities) -{ - assert(lds01 < LDS01_NUMOF); - - lds01_dev_t *lds01_dev = &lds01_devs[lds01]; - - memcpy((void *)intensities, (void *)lds01_dev->intensities, LDS01_NB_ANGLES * sizeof(uint16_t)); -} diff --git a/drivers/lx_servo/Makefile b/drivers/lx_servo/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/lx_servo/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/lx_servo/Makefile.dep b/drivers/lx_servo/Makefile.dep deleted file mode 100644 index c6a96692f9..0000000000 --- a/drivers/lx_servo/Makefile.dep +++ /dev/null @@ -1 +0,0 @@ -USEMODULE += uart_half_duplex diff --git a/drivers/lx_servo/Makefile.include b/drivers/lx_servo/Makefile.include deleted file mode 100644 index a07650fa67..0000000000 --- a/drivers/lx_servo/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -USEMODULE_INCLUDES_lx_servo := $(LAST_MAKEFILEDIR)/include -USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_lx_servo) diff --git a/drivers/lx_servo/include/lx_servo.h b/drivers/lx_servo/include/lx_servo.h deleted file mode 100644 index 12ee09be3d..0000000000 --- a/drivers/lx_servo/include/lx_servo.h +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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 driver_lx-servo LX servomotors driver - * @ingroup drivers_actuators - * @brief LX servomotors device driver - * - * LX servomotors uses one-wire serial half-duplex protocol. - * LX-15D and LX-16A are well known servomotors working with this driver, - * however this API should work with all LX HiWonder servomotors. - * - * This driver is inspired by Feetech driver written by - * Loïc Dauphin - * - * @{ - * - * @file - * @brief LX servomotors interface API definition - * - * @author Gilles DOFFE - */ - -#ifndef LX_SERVOS_H -#define LX_SERVOS_H - -#include -#include - -/* RIOT includes */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef uint8_t lx_id_t; /**< device id type */ - -#define LX_UART_BUFFER_SIZE 10 - -/** - * @brief Descriptor struct for a lx-servos device - */ -typedef struct { - uart_half_duplex_t *stream; /**< the stream used */ - lx_id_t id; /**< the device address */ -} lx_t; - -/** - * @brief Serial communication errors - */ -typedef enum { - LX_OK = 0, /**< success */ - LX_TIMEOUT, /**< no response from the device */ - LX_BUFFER_TOO_SMALL, /**< buffer is too small for the message */ - LX_INVALID_MESSAGE, /**< invalid message received */ - LX_INVALID_VALUE, /**< invalid value received/written */ -} lx_comm_error_t; - -/** - * @brief Servomotor errors - */ -typedef enum { - LX_SERVO_ERROR_OVER_TEMPERATURE = 1, /**< over temperature */ - LX_SERVO_ERROR_OVER_VOLTAGE = 2, /**< over voltage */ - LX_SERVO_ERROR_STALLED = 4 /**< servomotor is blocked */ -} lx_error_t; - -/** - * @brief Servomotor led status (on/off) - */ -typedef enum { - LX_SERVO_LED_ON = 0, /**< led on */ - LX_SERVO_LED_OFF = 1, /**< led off */ -} lx_led_status_t; - -/** - * @brief Servomotor load modes - */ -typedef enum { - LX_SERVO_UNLOADED = 0, /**< led on */ - LX_SERVO_LOADED = 1, /**< led off */ -} lx_load_mode_t; - -/** - * @brief Send a PING message to a device - * - * @param[in] device the device address - * - * @return lx_comm_error_t - * - */ -lx_comm_error_t lx_ping(lx_t *device); - -/** - * @brief Initialize LX servomotor - * - * @param[out] device the LX device - * @param[in] stream the half duplex stream - * @param[in] id servomotor id - */ -void lx_init(lx_t *device, uart_half_duplex_t *stream, lx_id_t id); - -/** - * @brief Go to the position in a given time - * - * @param[in] device the LX device - * @param[in] position the target position - * @param[in] time the movement time - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_move_time_write(const lx_t *device, const uint16_t position, const uint16_t time); - -/** - * @brief Read last position/time order - * - * @param[in] device the LX device - * @param[out] position the target position - * @param[out] time the movement time - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_move_time_read(const lx_t *device, uint16_t *position, uint16_t *time); - -/** - * @brief Register position and moving time - * - * @param[in] device the LX device - * @param[in] position the target position - * @param[in] time the movement time - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_move_time_wait_write(const lx_t *device, const uint16_t position, const uint16_t time); - -/** - * @brief Go to registered position - * - * @param[in] device the LX device - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_move_start(const lx_t *device); - -/** - * @brief Stop the motion - * - * @param[in] device the LX device - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_move_stop(const lx_t *device); - -/** - * @brief Set new servomotor ID - * - * @param[in] device the LX device - * @param[in] id new ID (range 0 - 253) - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_id_write(const lx_t *device, const lx_id_t id); - -/** - * @brief Read servomotor ID - * - * @param[in] device the LX device - * @param[out] id ID read - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_id_read(const lx_t *device, lx_id_t *id); - -/** - * @brief Set position offset (use lx_servo_position_offset_write() to save it permanently) - * - * @param[in] device the LX device - * @param[out] offset position offset - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_position_offset_adjust(const lx_t *device, const int8_t offset); - -/** - * @brief Save position offset in memory - * - * @param[in] device the LX device - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_position_offset_write(const lx_t *device); - -/** - * @brief Read position offset from memory - * - * @param[in] device the LX device - * @param[out] offset position offset - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_position_offset_read(const lx_t *device, int8_t *offset); - -/** - * @brief Set position min/max limits - * - * @param[in] device the LX device - * @param[in] position_min minimum position limit - * @param[in] position_max maximum position limit - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_position_limit_write(const lx_t *device, const uint16_t position_min, const uint16_t position_max); - -/** - * @brief Read position min/max limits - * - * @param[in] device the LX device - * @param[out] position_min minimum position limit - * @param[out] position_max maximum position limit - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_position_limit_read(const lx_t *device, uint16_t *position_min, uint16_t *position_max); - -/** - * @brief Set voltage min/max limits - * - * @param[in] device the LX device - * @param[in] vin_min minimum voltage limit - * @param[in] vin_max maximum voltage limit - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_vin_limit_write(const lx_t *device, const uint16_t vin_min, const uint16_t vin_max); - -/** - * @brief Read voltage min/max limits - * - * @param[in] device the LX device - * @param[out] vin_min minimum voltage limit - * @param[out] vin_max maximum voltage limit - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_vin_limit_read(const lx_t *device, uint16_t *vin_min, uint16_t *vin_max); - -/** - * @brief Set temperature max limit - * - * @param[in] device the LX device - * @param[in] temp_max maximum temperature limit - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_temp_max_limit_write(const lx_t *device, const uint8_t temp_max); - -/** - * @brief Read temperature max limit - * - * @param[in] device the LX device - * @param[out] temp_max maximum temperature limit - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_temp_max_limit_read(const lx_t *device, uint8_t *temp_max); - -/** - * @brief Read current temperature - * - * @param[in] device the LX device - * @param[out] temp current temperature - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_temp_read(const lx_t *device, uint8_t *temp); - -/** - * @brief Read current voltage - * - * @param[in] device the LX device - * @param[out] vin current voltage - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_vin_read(const lx_t *device, uint16_t *vin); - -/** - * @brief Read current position - * - * @param[in] device the LX device - * @param[out] pos current position - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_pos_read(const lx_t *device, int16_t *pos); - -/** - * @brief Set servomotor or motor mode. - * Set also the speed used only in motor mode. - * - * @param[in] device the LX device - * @param[in] mode 0 for servomotor mode, 1 for motor mode - * @param[in] speed motor mode speed (range -1000 to 1000) - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_or_motor_mode_write(const lx_t *device, const bool mode, const int16_t speed); - -/** - * @brief Read servomotor mode and speed - * - * @param[in] device the LX device - * @param[out] mode current motor mode - * @param[out] speed current motor mode speed - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_or_motor_mode_read(const lx_t *device, bool *mode, int16_t *speed); - -/** - * @brief Set servomotor load - * - * @param[in] device the LX device - * @param[in] load_mode 0 for unloaded (no torque applied), 1 for loaded - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_load_or_unload_write(const lx_t *device, const lx_load_mode_t load_mode); - -/** - * @brief Read servomotor load state - * - * @param[in] device the LX device - * @param[out] load_mode 0 for unloaded (no torque applied), 1 for loaded - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_load_or_unload_read(const lx_t *device, lx_load_mode_t *load_mode); - -/** - * @brief Set status led on/off - * - * @param[in] device the LX device - * @param[in] led_ctrl LX_SERVO_LED_ON led is on, LX_SERVO_LED_OFF led is off - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_led_ctrl_write(const lx_t *device, const lx_led_status_t led_ctrl); - -/** - * @brief Read status led configuration - * - * @param[in] device the LX device - * @param[out] led_ctrl LX_SERVO_LED_ON led is on, LX_SERVO_LED_OFF led is off - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_led_ctrl_read(const lx_t *device, lx_led_status_t *led_ctrl); - -/** - * @brief Setup error led - * - * @param[in] device the LX device - * @param[in] led_error See lx_error_t - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_led_error_write(const lx_t *device, const lx_error_t led_error); - -/** - * @brief Read error led configuration - * - * @param[in] device the LX device - * @param[out] led_error See lx_error_t - * @return lx_comm_error_t - */ -lx_comm_error_t lx_servo_led_error_read(const lx_t *device, lx_error_t *led_error); - -#ifdef __cplusplus -} -#endif - -#endif /* LX_SERVOS_H */ -/** @} */ diff --git a/drivers/lx_servo/lx_protocol.h b/drivers/lx_servo/lx_protocol.h deleted file mode 100644 index 132463a65d..0000000000 --- a/drivers/lx_servo/lx_protocol.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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 driver_lx_servo LX servomotors serial communication protocol - * @ingroup drivers - * @brief LX servomotors serial communication protocol - * - * LX servomotors use a one-wire serial half-duplex protocol. - * Each packet is formatted as following: - * _________________________________________________________________________________ - * | HEADER | SERVO_ID | DATA_LENGTH | COMMAND | PARAMETERS | CHECKSUM | - * | (2 bytes) | (1 byte) | (1 byte) | (1 byte) | (X bytes) | (1 byte) | - * |---------------------------------------------------------------------------------| - * | | 0 - 254 | 1 + Command length | | PARAM_1 + | | - * | 0x55 0x55 | | + Parameters length | Command ID | ......... | (2) | - * | | (1) | + Checksum length | | + PARAM_N | | - * --------------------------------------------------------------------------------- - * (1) Servo ID 254 is reserved to broadcast packet - * (2) CHECKSUM = ~(SERVO_ID + DATA_LENGTH + PARAM_1 + ... + PARAM_N) & 0xFF - * - * There are two kinds of commands: - * - Read commands - * - Write commands - * - * Read commands are executed in 2 steps: - * - A write on serial bus (TX) to indicate to the servomotor which parameter to read. - * - A read on serial bus (RX) to get the servomotor answer. - * - * As the bus is a one-wire serial half-duplex bus, read commands cannot be performed in - * broadcast. - * - * @{ - * - * @file - * @brief LX servomotors private protocol API - * - * @author Gilles DOFFE - */ - -#ifndef LX_PROTOCOL_H -#define LX_PROTOCOL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define LX_START (0x55) /**< packet header */ - -#define LX_BROADCAST_ID 254 /**< broadcast ID for write - commands only */ - -#define LX_PACKET_HEADER_SIZE 3 /**< packet header size - (HEADER + SERVO_ID) */ - -#define LX_PACKET_PAYLOAD_HEADER_SIZE 3 /**< packet payload header size - (DATA_LENGTH + COMMAND - + CHECKSUM) */ - -#define LX_PACKET_PAYLOAD_SIZE(len) \ - (LX_PACKET_PAYLOAD_HEADER_SIZE + len) /**< packet full payload size - (DATA_LENGTH + COMMAND + - CHECKSUM + PARAMETERS) */ - -#define LX_PACKET_SIZE(len) \ - (LX_PACKET_HEADER_SIZE \ - + LX_PACKET_PAYLOAD_SIZE(len)) /**< full packet size */ - -/** - * @brief Available baudrates for LX servomotors - */ -typedef enum { - LX_B_115200 = 0, /**< 115200 bauds */ -} lx_baudrate_t; - -#define LX_SERVO_POSITION_LIMIT_MAX 1000 /**< maximum position */ -#define LX_SERVO_LED_ERROR_LIMIT_MAX 7 /**< maximum led error value */ -#define LX_SERVO_OFFSET_LIMIT_MIN -125 /**< minimum position offset */ -#define LX_SERVO_OFFSET_LIMIT_MAX 125 /**< maximum position offset */ -#define LX_SERVO_SPEED_LIMIT_MIN -1000 /**< minimum speed */ -#define LX_SERVO_SPEED_LIMIT_MAX 1000 /**< maximum speed */ -#define LX_SERVO_TIME_LIMIT_MAX 30000 /**< maximum move duration */ -#define LX_SERVO_TEMP_MAX_LIMIT_MIN 50 /**< minimum temperature */ -#define LX_SERVO_TEMP_MAX_LIMIT_MAX 100 /**< maximum temperature */ -#define LX_SERVO_VIN_LIMIT_MIN 4500 /**< minimum supply voltage */ -#define LX_SERVO_VIN_LIMIT_MAX 12000 /**< maximum supply voltage */ - -typedef enum { - LX_SERVO_MOVE_TIME_WRITE = 1, /**< go to position in a given time */ - LX_SERVO_MOVE_TIME_WAIT_WRITE = 7, /**< register position & move time */ - LX_SERVO_MOVE_START = 11, /**< go to registered position */ - LX_SERVO_MOVE_STOP = 12, /**< stop the motion */ - LX_SERVO_ID_WRITE = 13, /**< set new servomotor ID */ - LX_SERVO_ANGLE_OFFSET_ADJUST = 17, /**< set position offset */ - LX_SERVO_ANGLE_OFFSET_WRITE = 18, /**< save position offset */ - LX_SERVO_ANGLE_LIMIT_WRITE = 20, /**< set position min/max limits */ - LX_SERVO_VIN_LIMIT_WRITE = 22, /**< set voltage min/max limits */ - LX_SERVO_TEMP_MAX_LIMIT_WRITE = 24, /**< set temperature max limit */ - LX_SERVO_OR_MOTOR_MODE_WRITE = 29, /**< set servomotor or speed mode */ - LX_SERVO_LOAD_OR_UNLOAD_WRITE = 31, /**< set servomotor load */ - LX_SERVO_LED_CTRL_WRITE = 33, /**< set status led (on/off) */ - LX_SERVO_LED_ERROR_WRITE = 35, /**< setup error led */ -} lx_write_command_t; - -typedef enum { - LX_SERVO_MOVE_TIME_READ = 2, /**< read last position/time order */ - LX_SERVO_MOVE_TIME_WAIT_READ = 8, /**< NOT IMPLEMENTED ON SERVOMOTOR */ - LX_SERVO_ID_READ = 14, /**< read servomotor ID */ - LX_SERVO_ANGLE_OFFSET_READ = 19, /**< read position offset */ - LX_SERVO_ANGLE_LIMIT_READ = 21, /**< read position min/max limits */ - LX_SERVO_VIN_LIMIT_READ = 23, /**< read voltage min/max limits */ - LX_SERVO_TEMP_MAX_LIMIT_READ = 25, /**< read temperature max limit */ - LX_SERVO_TEMP_READ = 26, /**< read current temperature */ - LX_SERVO_VIN_READ = 27, /**< read current voltage */ - LX_SERVO_POS_READ = 28, /**< read current position */ - LX_SERVO_OR_MOTOR_MODE_READ = 30, /**< read servomotor mode */ - LX_SERVO_LOAD_OR_UNLOAD_READ = 32, /**< read servomotor load state */ - LX_SERVO_LED_CTRL_READ = 34, /**< read status led configuration */ - LX_SERVO_LED_ERROR_READ = 36, /**< read error led configuration */ -} lx_read_command_t; - - -#ifdef __cplusplus -} -#endif - -#endif /* LX_PROTOCOL_H */ -/** @} */ diff --git a/drivers/lx_servo/lx_reader.h b/drivers/lx_servo/lx_reader.h deleted file mode 100644 index 598e67bcce..0000000000 --- a/drivers/lx_servo/lx_reader.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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_lx_servos - * - * @{ - * - * @file - * @brief Interface definition for LX-Servos packet reader - * - * @author Gilles DOFFE - */ - -#ifndef LX_READER_H -#define LX_READER_H - -#include "lx_protocol.h" - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief LX-Servos packet reader struct - */ -typedef struct { - const uint8_t *buffer; /**< data buffer */ - size_t size; /**< data buffer's size */ -} lx_reader_t; - -/** - * @brief Initialize the LX-Servos packet reader - * - * @param[out] reader the packet reader - * @param[in] buffer the buffer used to store data - * @param[in] size the size of the buffer - */ -static inline void lx_reader_init(lx_reader_t *reader, const uint8_t *buffer, size_t size) -{ - reader->buffer = buffer; - reader->size = size; -} - -/** - * @brief Compute the packet's sum - * - * @param[in] reader the packet reader - * - * @return the sum of the packet - */ -uint8_t lx_reader_compute_sum(const lx_reader_t *reader); - -/** - * @brief Check if the packet has the minimum required size - * - * @param[in] reader the packet reader - * - * @return true if the packet has the minimum required size - * @return false otherwise - */ -static inline bool lx_reader_check_minsize(const lx_reader_t *reader) -{ - return LX_PACKET_SIZE(0) < reader->size; -} - -/** - * @brief Check if the packet begins with 2 LX_START bits - * - * @param[in] reader the packet reader - * - * @return true if the packet begins with 2 LX_START bits - * @return false otherwise - */ -static inline bool lx_reader_check_start(const lx_reader_t *reader) -{ - return - reader->buffer[0] == LX_START && - reader->buffer[1] == LX_START; -} - -/** - * @brief Check if the packet's size is the same as the buffer's size - * - * @param[in] reader the packet reader - * - * @return true if the packet's size is the same as the buffer's size - * @return false otherwise - */ -static inline bool lx_reader_check_size(const lx_reader_t *reader) -{ - return reader->size == (size_t)(reader->buffer[3] + LX_PACKET_HEADER_SIZE); -} - -/** - * @brief Check if the computed sum and the sum of the packet are equal - * - * @param[in] reader the packet reader - * - * @return true if the computed sum and the sum of the packet are equal - * @return false otherwise - */ -static inline bool lx_reader_check_sum(const lx_reader_t *reader) -{ - return lx_reader_compute_sum(reader) == reader->buffer[reader->size - 1]; -} - -/** - * @brief Check if the packet is valid - * - * @param[in] reader the packet reader - * - * @return true if the packet is valid - * @return false otherwise - */ -bool lx_reader_is_valid(const lx_reader_t *reader); - -/** - * @brief Get the packet's device id - * - * @param[in] reader the packet reader - * - * @return the packet's device id - */ -static inline uint8_t lx_reader_get_id(const lx_reader_t *reader) -{ - return reader->buffer[2]; -} - -/** - * @brief Get the packet's instruction code - * - * @param[in] reader the packet reader - * - * @return the packet's instruction code - */ -static inline uint8_t lx_reader_get_instr(const lx_reader_t *reader) -{ - return reader->buffer[4]; -} - -/** - * @brief Get the packet's payload (response) - * - * @param[in] reader the packet reader - * - * @return the address of the beginning of the payload - */ -static inline const uint8_t *lx_reader_response_get_payload(const lx_reader_t *reader) -{ - return &reader->buffer[5]; -} - -/** - * @brief Get the packet's payload size (response) - * - * @param[in] reader the packet reader - * - * @return the size of the payload - */ -static inline size_t lx_reader_response_get_payload_size(const lx_reader_t *reader) -{ - return reader->buffer[3]; -} - -/** - * @brief Get the packet's READ size - * - * @param[in] reader the packet reader - * - * @return the READ size - */ -static inline size_t lx_reader_read_get_size(const lx_reader_t *reader) -{ - return reader->buffer[6]; -} - -#ifdef __cplusplus -} -#endif - -#endif /* LX_READER_H */ -/** @} */ diff --git a/drivers/lx_servo/lx_servos.c b/drivers/lx_servo/lx_servos.c deleted file mode 100644 index 2a80330d44..0000000000 --- a/drivers/lx_servo/lx_servos.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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_lx_servos - * @{ - * - * @file - * @brief Driver implementation for LX-Servos devices - * - * @author Gilles DOFFE - * - * @} - */ - -#define ENABLE_DEBUG (0) -#include - -#include - -#include "lx_protocol.h" -#include "lx_reader.h" -#include "lx_writer.h" - -#include "periph/uart.h" -#include "byteorder.h" - -#include - -#define set_move_time_wait_write(x) ((move_time_wait_check[x / 8] |= 0x1 << (x % 8))) -#define check_move_time_wait_write(x) ((move_time_wait_check[x / 8] >> (x % 8)) & 0x1) - -static uint8_t move_time_wait_check[32]; - -void lx_init(lx_t *device, uart_half_duplex_t *stream, lx_id_t id) -{ - device->stream = stream; - device->id = id; -} - -lx_comm_error_t lx_ping(lx_t *device) -{ - lx_id_t id = 0; - - return lx_servo_id_read(device, &id); -} - -static int lx_write(const lx_t *device, lx_write_command_t command, const uint8_t *data, size_t length) -{ - uart_half_duplex_set_tx(device->stream); - if (device->stream->size < LX_PACKET_SIZE(length)) { - DEBUG("%s: Buffer too small on device %u!\n", __func__, device->id); - return LX_BUFFER_TOO_SMALL; - } - - lx_writer_t pw; - - lx_writer_init(&pw, device->stream->buffer, device->stream->size); - lx_writer_write_make(&pw, device->id, command, data, length); - if (uart_half_duplex_send(device->stream, pw.size) != pw.size) { - DEBUG("%s: Timeout error on device %u!\n", __func__, device->id); - return LX_TIMEOUT; - } - - return LX_OK; -} - -static int lx_read(const lx_t *device, lx_read_command_t command, uint8_t *data, size_t length) -{ - uart_half_duplex_set_tx(device->stream); - if (device->stream->size < LX_PACKET_SIZE(length)) { - DEBUG("%s: Buffer too small on device %u!\n", __func__, device->id); - return LX_BUFFER_TOO_SMALL; - } - - lx_writer_t pw; - - lx_writer_init(&pw, device->stream->buffer, device->stream->size); - lx_writer_read_make(&pw, device->id, command); - uart_half_duplex_send(device->stream, pw.size); - - uart_half_duplex_set_rx(device->stream); - const size_t esize = LX_PACKET_SIZE(length); - - if (uart_half_duplex_recv(device->stream, esize) != esize) { - DEBUG("%s: Timeout error on device %u!\n", __func__, device->id); - return LX_TIMEOUT; - } - - lx_reader_t pr; - - lx_reader_init(&pr, device->stream->buffer, esize); - - if (!lx_reader_is_valid(&pr)) { - DEBUG("%s: Invalid message from device %u!\n", __func__, device->id); - return LX_INVALID_MESSAGE; - } - - if (lx_reader_response_get_payload_size(&pr) != LX_PACKET_PAYLOAD_SIZE(length)) { - DEBUG("%s: Invalid payload from device %u!\n", __func__, device->id); - return LX_INVALID_MESSAGE; - } - - memcpy(data, lx_reader_response_get_payload(&pr), length); - - return LX_OK; -} - -lx_comm_error_t lx_servo_move_time_write(const lx_t *device, const uint16_t position, - const uint16_t time) -{ - uint8_t data[4]; - - if (position > LX_SERVO_POSITION_LIMIT_MAX) { - return LX_INVALID_VALUE; - } - - data[0] = (uint8_t)(position & 0xFF); - data[1] = (uint8_t)((position >> 8) & 0xFF); - data[2] = (uint8_t)(time & 0xFF); - data[3] = (uint8_t)((time >> 8) & 0xFF); - - return lx_write(device, LX_SERVO_MOVE_TIME_WRITE, data, 4); -} - -lx_comm_error_t lx_servo_move_time_read(const lx_t *device, uint16_t *position, uint16_t *time) -{ - uint8_t data[4]; - - lx_comm_error_t ret = lx_read(device, LX_SERVO_MOVE_TIME_READ, data, 4); - - if (ret == LX_OK) { - *position = data[0] + (data[1] << 8); - *time = data[2] + (data[3] << 8); - } - - return ret; -} - -lx_comm_error_t lx_servo_move_time_wait_write(const lx_t *device, const uint16_t position, - const uint16_t time) -{ - uint8_t data[4]; - lx_comm_error_t res = LX_INVALID_MESSAGE; - - if (position > LX_SERVO_POSITION_LIMIT_MAX) { - return LX_INVALID_VALUE; - } - - data[0] = (uint8_t)(position & 0xFF); - data[1] = (uint8_t)((position >> 8) & 0xFF); - data[2] = (uint8_t)(time & 0xFF); - data[3] = (uint8_t)((time >> 8) & 0xFF); - - res = lx_write(device, LX_SERVO_MOVE_TIME_WAIT_WRITE, data, 4); - - if (res == LX_OK) { - set_move_time_wait_write(device->id); - } - - return res; -} - -lx_comm_error_t lx_servo_move_start(const lx_t *device) -{ - if (check_move_time_wait_write(device->id)) { - return lx_write(device, LX_SERVO_MOVE_START, NULL, 0); - } - else { - return LX_INVALID_MESSAGE; - } -} - -lx_comm_error_t lx_servo_move_stop(const lx_t *device) -{ - return lx_write(device, LX_SERVO_MOVE_STOP, NULL, 0); -} - -lx_comm_error_t lx_servo_id_write(const lx_t *device, const lx_id_t id) -{ - return lx_write(device, LX_SERVO_ID_WRITE, &id, 1); -} - -lx_comm_error_t lx_servo_id_read(const lx_t *device, lx_id_t *id) -{ - return lx_read(device, LX_SERVO_ID_READ, id, 1); -} - -lx_comm_error_t lx_servo_position_offset_adjust(const lx_t *device, const int8_t offset) -{ - if ((offset > LX_SERVO_OFFSET_LIMIT_MAX) || (offset < LX_SERVO_OFFSET_LIMIT_MIN)) { - return LX_INVALID_VALUE; - } - - return lx_write(device, LX_SERVO_ANGLE_OFFSET_ADJUST, (uint8_t *)&offset, 1); -} - -lx_comm_error_t lx_servo_position_offset_write(const lx_t *device) -{ - return lx_write(device, LX_SERVO_ANGLE_OFFSET_WRITE, NULL, 0); -} - -lx_comm_error_t lx_servo_position_offset_read(const lx_t *device, int8_t *offset) -{ - return lx_read(device, LX_SERVO_ANGLE_OFFSET_READ, (uint8_t *)offset, 1); -} - -lx_comm_error_t lx_servo_position_limit_write(const lx_t *device, const uint16_t position_min, - const uint16_t position_max) -{ - uint8_t data[4]; - - if ((position_max > LX_SERVO_POSITION_LIMIT_MAX) || (position_min >= position_max)) { - return LX_INVALID_VALUE; - } - - data[0] = (uint8_t)(position_min & 0xFF); - data[1] = (uint8_t)((position_min >> 8) & 0xFF); - data[2] = (uint8_t)(position_max & 0xFF); - data[3] = (uint8_t)((position_max >> 8) & 0xFF); - - return lx_write(device, LX_SERVO_ANGLE_LIMIT_WRITE, data, 4); -} - -lx_comm_error_t lx_servo_position_limit_read(const lx_t *device, uint16_t *position_min, uint16_t *position_max) -{ - uint8_t data[4]; - - lx_comm_error_t ret = lx_read(device, LX_SERVO_ANGLE_LIMIT_READ, data, 4); - - if (ret == LX_OK) { - *position_min = data[0] + (data[1] << 8); - *position_max = data[2] + (data[3] << 8); - } - - return ret; -} - -lx_comm_error_t lx_servo_vin_limit_write(const lx_t *device, const uint16_t vin_min, - const uint16_t vin_max) -{ - uint8_t data[4]; - - if ((vin_max > LX_SERVO_VIN_LIMIT_MAX) || (vin_min >= vin_max) || (vin_min < LX_SERVO_VIN_LIMIT_MIN)) { - return LX_INVALID_VALUE; - } - - data[0] = (uint8_t)(vin_min & 0xFF); - data[1] = (uint8_t)((vin_min >> 8) & 0xFF); - data[2] = (uint8_t)(vin_max & 0xFF); - data[3] = (uint8_t)((vin_max >> 8) & 0xFF); - - return lx_write(device, LX_SERVO_VIN_LIMIT_WRITE, data, 4); -} - -lx_comm_error_t lx_servo_vin_limit_read(const lx_t *device, uint16_t *vin_min, uint16_t *vin_max) -{ - uint8_t data[4]; - - lx_comm_error_t ret = lx_read(device, LX_SERVO_VIN_LIMIT_READ, data, 4); - - if (ret == LX_OK) { - *vin_min = data[0] + (data[1] << 8); - *vin_max = data[2] + (data[3] << 8); - } - - return ret; -} - -lx_comm_error_t lx_servo_temp_max_limit_write(const lx_t *device, const uint8_t temp_max) -{ - if ((temp_max > LX_SERVO_TEMP_MAX_LIMIT_MAX) || (temp_max < LX_SERVO_TEMP_MAX_LIMIT_MIN)) { - return LX_INVALID_VALUE; - } - - return lx_write(device, LX_SERVO_TEMP_MAX_LIMIT_WRITE, &temp_max, 1); -} - -lx_comm_error_t lx_servo_temp_max_limit_read(const lx_t *device, uint8_t *temp_max) -{ - return lx_read(device, LX_SERVO_TEMP_MAX_LIMIT_READ, temp_max, 1); -} - -lx_comm_error_t lx_servo_temp_read(const lx_t *device, uint8_t *temp) -{ - return lx_read(device, LX_SERVO_TEMP_READ, temp, 1); -} - -lx_comm_error_t lx_servo_vin_read(const lx_t *device, uint16_t *vin) -{ - uint8_t data[2]; - - lx_comm_error_t ret = lx_read(device, LX_SERVO_VIN_READ, data, 2); - - if (ret == LX_OK) { - *vin = data[0] + (data[1] << 8); - } - - return ret; -} - -lx_comm_error_t lx_servo_pos_read(const lx_t *device, int16_t *pos) -{ - uint8_t data[2]; - - lx_comm_error_t ret = lx_read(device, LX_SERVO_POS_READ, data, 2); - - if (ret == LX_OK) { - *pos = data[0] | (data[1] << 8); - } - - return ret; -} - -lx_comm_error_t lx_servo_or_motor_mode_write(const lx_t *device, const bool mode, - const int16_t speed) -{ - uint8_t data[4]; - - if ((speed > LX_SERVO_SPEED_LIMIT_MAX) || (speed < LX_SERVO_SPEED_LIMIT_MIN)) { - return LX_INVALID_VALUE; - } - - data[0] = (uint8_t)(mode); - data[1] = 0; - data[2] = (uint8_t)(speed & 0xFF); - data[3] = (uint8_t)(((uint16_t)speed >> 8) & 0xFF); - - return lx_write(device, LX_SERVO_OR_MOTOR_MODE_WRITE, data, 4); -} - -lx_comm_error_t lx_servo_or_motor_mode_read(const lx_t *device, bool *mode, int16_t *speed) -{ - uint8_t data[4]; - - lx_comm_error_t ret = lx_read(device, LX_SERVO_OR_MOTOR_MODE_READ, data, 4); - - if (ret == LX_OK) { - *mode = data[0]; - *speed = data[2] + (data[3] << 8); - } - - return ret; -} - -lx_comm_error_t lx_servo_load_or_unload_write(const lx_t *device, const lx_load_mode_t load_mode) -{ - return lx_write(device, LX_SERVO_LOAD_OR_UNLOAD_WRITE, (const uint8_t *)&load_mode, 1); -} - -lx_comm_error_t lx_servo_load_or_unload_read(const lx_t *device, lx_load_mode_t *load_mode) -{ - return lx_read(device, LX_SERVO_LOAD_OR_UNLOAD_READ, (uint8_t *)load_mode, 1); -} - -lx_comm_error_t lx_servo_led_ctrl_write(const lx_t *device, const lx_led_status_t led_ctrl) -{ - return lx_write(device, LX_SERVO_LED_CTRL_WRITE, (const uint8_t *)&led_ctrl, 1); -} - -lx_comm_error_t lx_servo_led_ctrl_read(const lx_t *device, lx_led_status_t *led_ctrl) -{ - return lx_read(device, LX_SERVO_LED_CTRL_READ, (uint8_t *)led_ctrl, 1); -} - -lx_comm_error_t lx_servo_led_error_write(const lx_t *device, const lx_error_t led_error) -{ - if (led_error > LX_SERVO_LED_ERROR_LIMIT_MAX) { - return LX_INVALID_VALUE; - } - - return lx_write(device, LX_SERVO_LED_ERROR_WRITE, (const uint8_t *)&led_error, 1); -} - -lx_comm_error_t lx_servo_led_error_read(const lx_t *device, lx_error_t *led_error) -{ - return lx_read(device, LX_SERVO_LED_ERROR_READ, (uint8_t *)led_error, 1); -} diff --git a/drivers/lx_servo/lx_writer.h b/drivers/lx_servo/lx_writer.h deleted file mode 100644 index 3baef93540..0000000000 --- a/drivers/lx_servo/lx_writer.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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_lx_servos - * - * @{ - * - * @file - * @brief Interface definition for LX-Servos packet writer - * - * @author Gilles DOFFE - */ - -#ifndef LX_WRITER_H -#define LX_WRITER_H - -#include "lx_protocol.h" - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief LX-Servos packet writer struct - */ -typedef struct { - uint8_t *buffer; /**< data buffer */ - size_t size; /**< packet's size */ - size_t buffer_max_size; /**< data buffer's size */ -} lx_writer_t; - -/** - * @brief Initialize the LX-Servos packet writer - * - * @param[out] writer the packet writer - * @param[in] buffer the buffer used to store data - * @param[in] buffer_max_size the size of the buffer (= maximum packet size) - */ -void lx_writer_init(lx_writer_t *writer, uint8_t *buffer, size_t buffer_max_size); - -/** - * @brief Get the data buffer to send - * - * @param[out] writer the packet writer - * - * @return the beginning address of the buffer - */ -const uint8_t *lx_writer_get_data(const lx_writer_t *writer); - -/** - * @brief Get the data buffer's size to send - * - * @param[out] writer the packet writer - * - * @return the buffer's size - */ -size_t lx_writer_get_size(const lx_writer_t *writer); - -/** - * @brief Build a WRITE packet - * - * @param[out] writer the packet writer - * @param[in] id the destination's id - * @param[in] write_command the parameter write command - * @param[in] buffer the data buffer to write - * @param[in] size the data buffer's size - */ -void lx_writer_write_make(lx_writer_t *writer, uint8_t id, lx_write_command_t write_command, const uint8_t *buffer, size_t size); - -/** - * @brief Build a READ packet - * - * @param[out] writer the packet writer - * @param[in] id the destination's id - * @param[in] read_command the parameter read command - */ -void lx_writer_read_make(lx_writer_t *writer, uint8_t id, lx_read_command_t read_command); - -#ifdef __cplusplus -} -#endif - -#endif /* LX_WRITER_H */ -/** @} */ diff --git a/drivers/lx_servo/reader.c b/drivers/lx_servo/reader.c deleted file mode 100644 index 57be638536..0000000000 --- a/drivers/lx_servo/reader.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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_lx_servos - * @{ - * - * @file - * @brief LX-Servos messages reader - * - * @author Gilles DOFFE - * - * @} - */ - -#include "lx_reader.h" - -static uint8_t _compute_sum(const lx_reader_t *reader) -{ - uint8_t sum = 0; - - for (size_t i = 2; i < reader->size - 1; i++) { - sum += reader->buffer[i]; - } - return sum; -} - -uint8_t lx_reader_compute_sum(const lx_reader_t *reader) -{ - return ~_compute_sum(reader); -} - -bool lx_reader_is_valid(const lx_reader_t *reader) -{ - return - lx_reader_check_minsize(reader) && - lx_reader_check_start(reader) && - lx_reader_check_size(reader) && - lx_reader_check_sum(reader); -} diff --git a/drivers/lx_servo/writer.c b/drivers/lx_servo/writer.c deleted file mode 100644 index 0403cba4d4..0000000000 --- a/drivers/lx_servo/writer.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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_lx_servos - * @{ - * - * @file - * @brief LX-Servos messages writer - * - * @author Gilles DOFFE - * - * @} - */ - -#include "lx_writer.h" - -void lx_writer_init(lx_writer_t *writer, uint8_t *buffer, size_t buffer_max_size) -{ - writer->buffer = buffer; - writer->size = 0; - writer->buffer_max_size = buffer_max_size; -} - -const uint8_t *lx_writer_get_data(const lx_writer_t *writer) -{ - return (const uint8_t *)writer->buffer; -} - -size_t lx_writer_get_size(const lx_writer_t *writer) -{ - return writer->size; -} - -void lx_writer_write_make(lx_writer_t *writer, uint8_t id, lx_write_command_t write_command, const uint8_t *buffer, size_t size) -{ - const size_t len = 3 + size; - - if (len + 3 <= writer->buffer_max_size) { - writer->size = len + 3; - - uint8_t sum = 0; - - writer->buffer[0] = LX_START; - writer->buffer[1] = LX_START; - sum += writer->buffer[2] = id; - sum += writer->buffer[3] = len; - sum += writer->buffer[4] = write_command; - - for (size_t i = 0; i < size; i++) { - sum += writer->buffer[5 + i] = buffer[i]; - } - - writer->buffer[writer->size - 1] = ~sum; - } - else { - writer->size = 0; - } -} - -void lx_writer_read_make(lx_writer_t *writer, uint8_t id, lx_read_command_t read_command) -{ - const size_t len = 3; - - if (len + 3 <= writer->buffer_max_size) { - writer->size = len + 3; - - uint8_t sum = 0; - - writer->buffer[0] = LX_START; - writer->buffer[1] = LX_START; - sum += writer->buffer[2] = id; - sum += writer->buffer[3] = len; - sum += writer->buffer[4] = read_command; - writer->buffer[5] = ~sum; - } - else { - writer->size = 0; - } -} diff --git a/drivers/pca9548/Makefile b/drivers/pca9548/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/pca9548/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/pca9548/Makefile.dep b/drivers/pca9548/Makefile.dep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/drivers/pca9548/Makefile.include b/drivers/pca9548/Makefile.include deleted file mode 100644 index ee7d23a6cb..0000000000 --- a/drivers/pca9548/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -USEMODULE_INCLUDES_pca9548 := $(LAST_MAKEFILEDIR)/include -USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_pca9548) diff --git a/drivers/pca9548/include/pca9548.h b/drivers/pca9548/include/pca9548.h deleted file mode 100644 index fd13c88cf9..0000000000 --- a/drivers/pca9548/include/pca9548.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2019 COGIP Robotics association - * - * 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 I2C switch PCA9548 driver - * @ingroup drivers - * @brief I2C switch PCA9548 driver - * - * The PCA9548 is an 8 channels I2C switch. It allows to drive up to 8 I2C - * devices that shares the same I2C address. - * - * The PCA9548 has a default address of 0x70 defined on 7 bits. - * Using three hardware pins, I2C address can be steup between 0x70 and 0x77. - * - * @{ - * @file - * @brief Common controllers API and datas - * - * @author Gilles DOFFE - */ - -#pragma once - -/* RIOT includes */ -#include "periph/i2c.h" - -/** - * @brief PCA9548 maximum channel number - */ -#define PCA9548_CHANNEL_MAX 8 -/** - * @brief PCA9548 default channel - */ -#define PCA9548_DEFAULT_CHANNEL 0 - -/** - * @brief PCA9548 id - */ -typedef unsigned int pca9548_t; - -/** - * @brief PCA9548 configuration - */ -typedef struct { - i2c_t i2c_dev_id; /**< I2C bus */ - uint16_t i2c_address; /**< I2C board address */ - i2c_speed_t i2c_speed_khz; /**< I2C bus speed */ - uint8_t channel_numof; /**< Channels number */ -} pca9548_conf_t; - - -/** - * @brief Initialize PCA9548 driver according to static configuration. - * - * @return - */ -void pca9548_init(void); - -/** - * @brief Set current channel - * - * @param[in] dev PCA9548 device id - * @param[in] channel New channel - * - * @return - */ -void pca9548_set_current_channel(pca9548_t dev, uint8_t channel); - -/** - * @brief Get current channel - * - * @param[in] dev PCA9548 device id - * - * @return PCA9548 current channel - */ -uint8_t pca9548_get_current_channel(pca9548_t dev); - -/** @} */ diff --git a/drivers/pca9548/pca9548.c b/drivers/pca9548/pca9548.c deleted file mode 100644 index 9c34841d1d..0000000000 --- a/drivers/pca9548/pca9548.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include "pca9548.h" - -#ifdef MODULE_SHELL_PCA9548 -# include "shell_pca9548.h" -#endif - -static uint8_t pca9548_current_channel[PCA9548_NUMOF]; - -void pca9548_set_current_channel(pca9548_t dev, uint8_t channel) -{ - assert(dev < PCA9548_NUMOF); - - const pca9548_conf_t *pca9548 = &pca9548_config[dev]; - - assert(channel < pca9548->channel_numof); - - i2c_acquire(pca9548->i2c_dev_id); - - int err = 1; - - err = i2c_write_byte(pca9548->i2c_dev_id, pca9548->i2c_address, 1 << channel, 0); - - i2c_release(pca9548->i2c_dev_id); - - if (!err) { - pca9548_current_channel[dev] = channel; - } -} - -uint8_t pca9548_get_current_channel(pca9548_t dev) -{ - assert(dev < PCA9548_NUMOF); - - return pca9548_current_channel[dev]; -} - -void pca9548_init(void) -{ - for (pca9548_t dev = 0; dev < PCA9548_NUMOF; dev++) { - const pca9548_conf_t *pca9548 = &pca9548_config[dev]; - - assert(pca9548->channel_numof <= PCA9548_CHANNEL_MAX); - - pca9548_set_current_channel(dev, 0); - } - -#ifdef MODULE_SHELL_PCA9548 - pca9548_shell_init(); -#endif -} diff --git a/drivers/sd21/Makefile b/drivers/sd21/Makefile deleted file mode 100644 index 241c8f5aea..0000000000 --- a/drivers/sd21/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = sd21 - -include $(RIOTBASE)/Makefile.base diff --git a/drivers/sd21/Makefile.dep b/drivers/sd21/Makefile.dep deleted file mode 100644 index e67057d463..0000000000 --- a/drivers/sd21/Makefile.dep +++ /dev/null @@ -1 +0,0 @@ -FEATURES_REQUIRED += periph_i2c diff --git a/drivers/sd21/Makefile.include b/drivers/sd21/Makefile.include deleted file mode 100644 index 54df491fba..0000000000 --- a/drivers/sd21/Makefile.include +++ /dev/null @@ -1,3 +0,0 @@ -USEMODULE_INCLUDES_sd21 := $(LAST_MAKEFILEDIR)/include -USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_sd21) - diff --git a/drivers/sd21/include/sd21.h b/drivers/sd21/include/sd21.h deleted file mode 100644 index facfc8505d..0000000000 --- a/drivers/sd21/include/sd21.h +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (C) 2019 COGIP Robotics association - * - * 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 sd21 Servomotors SD21 board driver - * @ingroup drivers - * @brief Servomotors SD21 board driver - * - * Servomotors SD21 board drives analogic servomotors. It offers servomotors - * control trough an I2C bus. - * - * Each servomotor can be configured with 3 bytes: - * * byte 0: speed - * * byte 1: position LSB in milliseconds - * * byte 2: position MSB in milliseconds - * - * The driver setup the I2C address to request according to servomotor id and - * add the byte offset to configure. - * * servomotor_id * 3 - * - * Two functions can be used to drive a given servomotor: - * * sd21_servo_control: drive the servo to a given poition at a given - * speed - * * sd21_servo_reach_position: drive the servo to a pre defined position at - * default servomotor speed - * - * Two SD21 specific register can be accessed to get SD21 firmware version and - * battery voltage. Two functions are provided for that purpose: - * * sd21_get_version - * * sd21_get_battery_voltage - * - * Position has to be setup in one I2C request of 2 bytes. - * - * @{ - * @file - * @brief Common controllers API and datas - * - * @author Gilles DOFFE - * @author Yannick GICQUEL - * @author Stephen CLYMANS - */ - -#pragma once - -/* RIOT includes */ -#include "periph/i2c.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Note: All following macros can be overrided by setting CFLAGS variable in - * Makefile. Example - * CFLAGS += -DSD21_SERVO_POS_NUMOF=3 - */ - -/** - * @brief Maximum number of servos by board - */ -#ifndef SD21_SERVO_NUMOF -#define SD21_SERVO_NUMOF 21 -#endif /* SD21_SERVO_NUMOF */ - -/** - * @brief Number of predefined positions, at least 2, opened and closed - */ -#ifndef SD21_SERVO_POS_NUMOF -#define SD21_SERVO_POS_NUMOF 2 -#endif /* SD21_SERVO_POS_NUMOF */ - -/** - * @brief Minimal position (in microseconds) - */ -#ifndef SD21_SERVO_POS_MIN -#define SD21_SERVO_POS_MIN 1000 -#endif /* SD21_SERVO_POS_MIN */ - -/** - * @brief Maximal position (in microseconds) - */ -#ifndef SD21_SERVO_POS_MAX -#define SD21_SERVO_POS_MAX 2000 -#endif /* SD21_SERVO_POS_MAX */ - -/** - * @brief Centered position (in microseconds) - */ -#define SD21_SERVO_POS_MID ((SD21_SERVO_POS_MAX + SD21_SERVO_POS_MIN) / 2) - -/** - * @brief Name string maximum length - */ -#define SD21_SERVO_NAME_LENGTH 64 - -/** - * @brief SD21 I2C board id - */ -typedef unsigned int sd21_t; - -/** - * @brief Servotmotors pre-defined positions - */ -typedef enum { - SD21_SERVO_POS_OPEN, /**< Servomotor opened position */ - SD21_SERVO_POS_CLOSE, /**< Servomotor closed position */ -} sd21_servo_pos_t; - -/** - * @brief Servomotor properties - */ -typedef struct { - uint16_t positions[SD21_SERVO_POS_NUMOF]; /**< Predifined positions */ - sd21_servo_pos_t default_position; /**< Default reset position */ - uint8_t default_speed; /**< Default speed */ - char name[SD21_SERVO_NAME_LENGTH]; /**< Servomotor name */ -} sd21_servo_t; - -/** - * @brief SD21 configuration - */ -typedef struct { - i2c_t i2c_dev_id; /**< I2C bus */ - uint16_t i2c_address; /**< I2C board address */ - i2c_speed_t i2c_speed_khz; /**< I2C bus speed */ - - uint8_t servos_nb; /**< number of servomotors */ - sd21_servo_t servos[SD21_SERVO_NUMOF]; /**< servomotors properties */ -} sd21_conf_t; - - -/** - * @brief Initialize SD21 board driver according to static configuration. - * - * @param[in] sd21_config_new SD21 configuration - * - * @return - */ -void sd21_init(const sd21_conf_t *sd21_config_new); - -/** - * @brief Servomotor driving function - * - * @param[in] dev SD21 device id - * @param[in] servo_id Servomotor id - * @param[in] position Servomotor position in ms - * - * @return 0 on success - * not 0 on failure - */ -int sd21_servo_control_position(sd21_t dev, uint8_t servo_id, - uint16_t position); - -/** - * @brief Drive servomotor to given pre defined position - * - * @param[in] dev SD21 device id - * @param[in] servo_id Servomotor id - * @param[in] pos_index Servomotor pre defined position index - * - * @return 0 on success - * not 0 on failure - */ -int sd21_servo_reach_position(sd21_t dev, uint8_t servo_id, - uint8_t pos_index); - -/** - * @brief Drive servomotor to reset position - * - * @param[in] dev SD21 device id - * @param[in] servo_id Servomotor id - * - * @return 0 on success - * not 0 on failure - */ -int sd21_servo_reset_position(sd21_t dev, uint8_t servo_id); - -/** - * @brief Get SD21 firmware version. - * - * @param[in] dev SD21 device id - * - * @return SD21 version number - */ -uint8_t sd21_get_version(sd21_t dev); - -/** - * @brief Get SD21 firmware version. - * - * @param[in] dev SD21 device id - * - * @return SD21 battery voltage (V unit) - */ -double sd21_get_battery_voltage(sd21_t dev); - -/** - * @brief Get Servomotor current position. - * - * @param[in] dev SD21 device id - * @param[in] servo_id Servomotor id - * @param[out] position Servomotor position in ms - * - * @return 0 on success - * not 0 on failure - */ -int sd21_servo_get_position(sd21_t dev, uint8_t servo_id, uint16_t *position); - -/** - * @brief Get Servomotor name. - * - * @param[in] dev SD21 device id - * @param[in] servo_id Servomotor id - * - * @return Servomotor name - */ -const char *sd21_servo_get_name(sd21_t dev, uint8_t servo_id); - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/drivers/sd21/sd21.c b/drivers/sd21/sd21.c deleted file mode 100644 index 84f86c6066..0000000000 --- a/drivers/sd21/sd21.c +++ /dev/null @@ -1,172 +0,0 @@ -/* System includes */ -#include -#include - -/* RIOT includes */ -#include - -/* Project includes */ -#include "sd21.h" - -#ifdef MODULE_SHELL_SD21 -#include "shell_sd21.h" -#endif /* MODULE_SHELL_SD21 */ - -static const sd21_conf_t *sd21_config = NULL; -static size_t sd21_numof = 0; - -static const sd21_servo_t *sd21_get_servo(sd21_t dev, uint8_t servo_id) -{ - assert(sd21_config != NULL); - - assert(dev < sd21_numof); - - const sd21_conf_t *sd21 = &sd21_config[dev]; - - assert(servo_id < sd21->servos_nb); - - return &sd21->servos[servo_id]; -} - -static int sd21_write_twi_cmd(sd21_t dev, uint8_t servo_id, - const uint16_t *data, uint8_t offset) -{ - const sd21_conf_t *sd21 = &sd21_config[dev]; - - uint8_t reg = (servo_id) * 3 + offset; - int ret = 0; - - irq_disable(); - - ret = i2c_acquire(sd21->i2c_dev_id); - if (ret) { - goto sd21_write_twi_cmd_err; - } - - ret = i2c_write_regs(sd21->i2c_dev_id, sd21->i2c_address, reg, data, 2, - 0); - if (ret) { - goto sd21_write_twi_cmd_err; - } - - i2c_release(sd21->i2c_dev_id); - - irq_enable(); - - return 0; - -sd21_write_twi_cmd_err: - irq_enable(); - return -1; -} - -static int sd21_read_twi_cmd(sd21_t dev, uint8_t servo_id, uint16_t *data, - uint8_t offset) -{ - const sd21_conf_t *sd21 = &sd21_config[dev]; - uint8_t tmp[3]; /* 1 byte for address + 2 bytes for data */ - - uint8_t reg = (servo_id) * 3 + offset; - int ret = 0; - - irq_disable(); - - ret = i2c_acquire(sd21->i2c_dev_id); - if (ret) { - goto sd21_read_twi_cmd_err; - } - - ret = i2c_read_regs(sd21->i2c_dev_id, sd21->i2c_address, reg, tmp, - 3, 0); - - if (ret) { - goto sd21_read_twi_cmd_err; - } - - *data = (tmp[2] << 8) + tmp[1]; - - i2c_release(sd21->i2c_dev_id); - - irq_enable(); - -sd21_read_twi_cmd_err: - irq_enable(); - return -1; -} - -int sd21_servo_control_position(sd21_t dev, uint8_t servo_id, - uint16_t position) -{ - /* Limit position */ - if (position < SD21_SERVO_POS_MIN) { - position = SD21_SERVO_POS_MIN; - } - if (position > SD21_SERVO_POS_MAX) { - position = SD21_SERVO_POS_MAX; - } - - return sd21_write_twi_cmd(dev, servo_id, &position, 1); -} - -int sd21_servo_reach_position(sd21_t dev, uint8_t servo_id, uint8_t pos_index) -{ - assert(pos_index < SD21_SERVO_POS_NUMOF); - - const sd21_servo_t *servo = sd21_get_servo(dev, servo_id); - - return sd21_servo_control_position(dev, servo_id, - servo->positions[pos_index]); -} - -int sd21_servo_reset_position(sd21_t dev, uint8_t servo_id) -{ - const sd21_servo_t *servo = sd21_get_servo(dev, servo_id); - - assert(servo->default_position < SD21_SERVO_POS_NUMOF); - - return sd21_servo_control_position(dev, servo_id, - servo->positions[servo->default_position]); -} - -int sd21_servo_get_position(sd21_t dev, uint8_t servo_id, uint16_t *position) -{ - if (!position) { - return -EINVAL; - } - - sd21_get_servo(dev, servo_id); - - return sd21_read_twi_cmd(dev, servo_id, (void *)position, 1); -} - -const char *sd21_servo_get_name(sd21_t dev, uint8_t servo_id) -{ - const sd21_servo_t *servo = sd21_get_servo(dev, servo_id); - - return servo->name; -} - -void sd21_init(const sd21_conf_t *sd21_config_new) -{ - sd21_config = sd21_config_new; - - sd21_numof = sizeof(*sd21_config) / sizeof(sd21_config[0]); - - for (sd21_t dev = 0; dev < sd21_numof; dev++) { - ztimer_sleep(ZTIMER_MSEC, 250); - /* Close all servomotors */ - for (uint8_t servo_id = 0; servo_id < sd21_config[dev].servos_nb; - servo_id++) { - if (sd21_servo_reset_position(dev, servo_id)) { - printf("Servo %u from board %u init failed !", servo_id, - dev); - } - /* Wait a small tempo to avoid current peak */ - ztimer_sleep(ZTIMER_MSEC, 50); - } - } - -#ifdef MODULE_SHELL_SD21 - sd21_shell_init(sd21_config); -#endif -} diff --git a/drivers/vacuum_pump/Makefile b/drivers/vacuum_pump/Makefile deleted file mode 100644 index 48422e909a..0000000000 --- a/drivers/vacuum_pump/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/drivers/vacuum_pump/Makefile.dep b/drivers/vacuum_pump/Makefile.dep deleted file mode 100644 index b6ba302301..0000000000 --- a/drivers/vacuum_pump/Makefile.dep +++ /dev/null @@ -1 +0,0 @@ -FEATURES_REQUIRED += periph_gpio diff --git a/drivers/vacuum_pump/Makefile.include b/drivers/vacuum_pump/Makefile.include deleted file mode 100644 index eb6d46108e..0000000000 --- a/drivers/vacuum_pump/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -USEMODULE_INCLUDES_vacuum_pump := $(LAST_MAKEFILEDIR)/include -USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_vacuum_pump) diff --git a/drivers/vacuum_pump/include/vacuum_pump.h b/drivers/vacuum_pump/include/vacuum_pump.h deleted file mode 100644 index 37f040ab21..0000000000 --- a/drivers/vacuum_pump/include/vacuum_pump.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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 driver_vacuum_pump COGIP vacuum pump driver - * @ingroup drivers - * @brief COGIP vacuum pump driver - * - * The COGIP vacuum pump board is driven by a GPIO to enable/disable the pump. - * The board also has a vacuum sensor that can be connected to an other test - * GPIO. - * - start/stop GPIO (output): 1 for start, 0 for stop - * - test GPIO (input): 1 for under vacuum pressure, 0 for no pressure - * - * @{ - * @file - * @brief Public API for COGIP vacuum pump driver - * - * @author Gilles DOFFE - */ - -#pragma once - -/* Standard includes */ -#include -#include - -/* RIOT includes */ -#include "periph/gpio.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief COGIP vacuum pump parameters - */ -typedef struct { - gpio_t gpio_enable; /**< start/stop pump */ - gpio_t gpio_test; /**< vacuum sensor */ -} vacuum_pump_params_t; - -/** - * @brief Default COGIP vacuum pump identifier definition - */ -typedef unsigned int vacuum_pump_t; - -/** - * @brief Initialize COGIP vacuum pump device - * - * @param[in] vacuum_pump vacuum_pump device id to initialize - * @param[in] params vacuum_pump parameters - * - * @return 0 on success, not 0 otherwise - */ -int vacuum_pump_init(const vacuum_pump_t vacuum_pump, const vacuum_pump_params_t *params); - -/** - * @brief Start COGIP vacuum pump device - * - * @param[in] vacuum_pump vacuum_pump device id - */ -void vacuum_pump_start(const vacuum_pump_t vacuum_pump); - -/** - * @brief Stop COGIP vacuum pump device - * - * @param[in] vacuum_pump vacuum_pump device id - */ -void vacuum_pump_stop(const vacuum_pump_t vacuum_pump); - -/** - * @brief Get vacuum sensor state - * - * @param[in] vacuum_pump vacuum_pump device id - * - * @return vacuum sensor state, 1 under pressure, 0 otherwise - */ -bool vacuum_pump_is_under_pressure(const vacuum_pump_t vacuum_pump); - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/drivers/vacuum_pump/include/vacuum_pump_params.h.template b/drivers/vacuum_pump/include/vacuum_pump_params.h.template deleted file mode 100644 index f62e89d7e7..0000000000 --- a/drivers/vacuum_pump/include/vacuum_pump_params.h.template +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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 driver_vacuum_pump - * @{ - * - * @file - * @brief Default parameters for COGIP vacuum pump driver - * - * @author Gilles DOFFE - */ - -#error This default header should not be included. \ - Create your own vacuum_pump_params.h in your application folder. - -/* Code below is given as example */ -#pragma once - -#include "vacuum_pump.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Vacuum pump configuration - */ -static const vacuum_pump_params_t vacuum_pump_params[] = { - { - .gpio_enable = GPIO_UNDEF, - .gpio_test = GPIO_UNDEF, - } -}; - -#ifdef __cplusplus -} -#endif - -/** @} */ \ No newline at end of file diff --git a/drivers/vacuum_pump/vacuum_pump.c b/drivers/vacuum_pump/vacuum_pump.c deleted file mode 100644 index 9e2e81aa0c..0000000000 --- a/drivers/vacuum_pump/vacuum_pump.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "vacuum_pump.h" -#include "vacuum_pump_params.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#define VACUUM_PUMP_NUMOF ARRAY_SIZE(vacuum_pump_params) /**< number of used vaccum pumps */ - -/** - * @brief COGIP vacuum_pump descriptor - */ -typedef struct { - vacuum_pump_params_t params; /**< parameters */ -} vacuum_pump_dev_t; - -/* Allocate memory for the device descriptor */ -vacuum_pump_dev_t vacuum_pump_devs[VACUUM_PUMP_NUMOF]; - -int vacuum_pump_init(const vacuum_pump_t vacuum_pump, const vacuum_pump_params_t *params) -{ - assert(vacuum_pump < VACUUM_PUMP_NUMOF); - - vacuum_pump_dev_t *vacuum_pump_dev = &vacuum_pump_devs[vacuum_pump]; - - vacuum_pump_dev->params = *params; - - int res = gpio_init(vacuum_pump_dev->params.gpio_enable, GPIO_OUT); - - if (res) { - printf("Error: Cannot initialize vacuum pump enable GPIO\n"); - return -1; - } - - res = gpio_init(vacuum_pump_dev->params.gpio_test, GPIO_IN); - if (res) { - printf("Error: Cannot initialize vacuum pump test GPIO\n"); - return -1; - } - - return 0; -} - -void vacuum_pump_start(const vacuum_pump_t vacuum_pump) -{ - assert(vacuum_pump < VACUUM_PUMP_NUMOF); - - vacuum_pump_dev_t *vacuum_pump_dev = &vacuum_pump_devs[vacuum_pump]; - - gpio_set(vacuum_pump_dev->params.gpio_enable); -} - -void vacuum_pump_stop(const vacuum_pump_t vacuum_pump) -{ - assert(vacuum_pump < VACUUM_PUMP_NUMOF); - - vacuum_pump_dev_t *vacuum_pump_dev = &vacuum_pump_devs[vacuum_pump]; - - gpio_clear(vacuum_pump_dev->params.gpio_enable); -} - -bool vacuum_pump_is_under_pressure(const vacuum_pump_t vacuum_pump) -{ - assert(vacuum_pump < VACUUM_PUMP_NUMOF); - - vacuum_pump_dev_t *vacuum_pump_dev = &vacuum_pump_devs[vacuum_pump]; - - return gpio_read(vacuum_pump_dev->params.gpio_test); -} diff --git a/examples/driver_lx_servo/Makefile b/examples/driver_lx_servo/Makefile deleted file mode 100644 index 8808eb9cdb..0000000000 --- a/examples/driver_lx_servo/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -APPLICATION = driver_lx_servos_example - -BOARD ?= nucleo-f446re - -USEMODULE += lx_servo -USEMODULE += shell - -include ../../Makefile.include diff --git a/examples/driver_lx_servo/README.md b/examples/driver_lx_servo/README.md deleted file mode 100644 index 7720edd6ee..0000000000 --- a/examples/driver_lx_servo/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# About - -This application is intended for testing LX servo serial bus. - -# Usage - -To have the list of available commands: -``` -help -``` - -You will need to initialize one UART at 115200 baudrate (if the servomotor is in factory configuration): -``` -init 2 115200 -``` - -To ping the servomotor: -``` -ping 1 -``` - -Be careful! - - If 2 servomotors with the same ID are connected on the same bus, you will have no response or corrupted one. - - There is no acknowledgement of write commands - -Factory configuration ID is 1, you need to change this to connect an other servo. - -To scan every connected servomotors (IDs from 0 to 253): -``` -scan -``` - -To move a servo to a given position at full speed: -``` -m 1 2000 -``` - -To get the status of a servo: -``` -status 1 -``` diff --git a/examples/driver_lx_servo/main.c b/examples/driver_lx_servo/main.c deleted file mode 100644 index 4e4d76ed09..0000000000 --- a/examples/driver_lx_servo/main.c +++ /dev/null @@ -1,780 +0,0 @@ -/* - * Copyright (C) 2022 COGIP Robotics association - * - * 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. - */ - -/* Firmware includes */ -#include "lx_servo.h" -#include "shell.h" -#include "stdio_uart.h" - -/* System includes */ -#include -#include - -#ifndef LX_DIR_PIN -#define LX_DIR_PIN GPIO_UNDEF -#endif - -static void dir_init(uart_t uart) -{ - (void)uart; - gpio_init(LX_DIR_PIN, GPIO_OUT); -} - -static void dir_enable_tx(uart_t uart) -{ - (void)uart; - gpio_set(LX_DIR_PIN); -} - -static void dir_disable_tx(uart_t uart) -{ - (void)uart; - gpio_clear(LX_DIR_PIN); -} - -static const int32_t baudrates[] = { - 115200L, -}; - -static uint8_t lx_servos_buffer[10]; -static uart_half_duplex_t stream; - -static int parse_uart(char *arg) -{ - unsigned uart = atoi(arg); - - if (uart >= UART_NUMOF) { - printf("Error: Invalid UART_DEV device specified (%u).\n", uart); - return -1; - } - else if (UART_DEV(uart) == STDIO_UART_DEV) { - printf("Error: The selected UART_DEV(%u) is used for the shell!\n", uart); - return -2; - } - return uart; -} - -static int32_t parse_baud(char *arg) -{ - int32_t baud = atoi(arg); - - for (size_t i = 0; i < ARRAY_SIZE(baudrates); i++) { - if (baud == baudrates[i]) { - return baud; - } - } - - printf("Error: Invalid baudrate (%s)\n", arg); - return -1; -} - -static int parse_dev(char *arg) -{ - int dev = atoi(arg); - - if (dev < 0 || 254 < dev) { - printf("Error: Invalid device id (%s)\n", arg); - return -1; - } - return dev; -} - -static int parse_angle(char *arg) -{ - int angle = atoi(arg); - - if (angle < 0 || 1000 < angle) { - printf("Error: Invalid angle (%s)\n", arg); - return -1; - } - return angle; -} - -static int parse_time(char *arg) -{ - int time = atoi(arg); - - if (time < 0 || 30000 < time) { - printf("Error: Invalid time (%s)\n", arg); - return -1; - } - return time; -} - -static int parse_u8(char *arg) -{ - int u8 = atoi(arg); - - if (u8 < 0 || 7 < u8) { - printf("Error: Invalid unsigned char (%s)\n", arg); - return -1; - } - return u8; -} - -static int cmd_init(int argc, char **argv) -{ - int uart = -1; - int baud = -1; - uint32_t timeout = -1; - - if (argc != 3 && argc != 4) { - printf("usage: %s []\n", argv[0]); - puts("available baudrates :"); - for (size_t i = 0; i < ARRAY_SIZE(baudrates); i++) { - printf("\t%ld\n", (long int)baudrates[i]); - } - return 1; - } - /* parse parameters */ - uart = parse_uart(argv[1]); - if (uart < 0) { - return -1; - } - - baud = parse_baud(argv[2]); - if (baud < 0) { - return -1; - } - - if (argc == 4) { - timeout = (uint32_t)atol(argv[3]); - if (timeout == 0) { - printf("Error : Invalid timeout (%s)", argv[3]); - return -1; - } - } - - /* init */ - uart_half_duplex_params_t params = { - .uart = uart, - .baudrate = baud, - .dir = { dir_init, dir_enable_tx, dir_disable_tx }, - }; - - int ret = uart_half_duplex_init(&stream, lx_servos_buffer, ARRAY_SIZE(lx_servos_buffer), ¶ms); - - if (argc == 4) { - stream.timeout_us = timeout; - } - - if (ret == UART_HALF_DUPLEX_NODEV) { - puts("Error: invalid UART device given"); - return -1; - } - if (ret == UART_HALF_DUPLEX_NOBAUD) { - puts("Error: given baudrate is not applicable"); - return -1; - } - if (ret == UART_HALF_DUPLEX_INTERR) { - puts("Error: internal error"); - return -1; - } - if (ret == UART_HALF_DUPLEX_NOMODE) { - puts("Error: given mode is not applicable"); - return -1; - } - if (ret == UART_HALF_DUPLEX_NOBUFF) { - puts("Error: invalid buffer given"); - return -1; - } - - printf("Successfully initialized LX Servos TTL bus UART_DEV(%i)\n", uart); - return 0; -} - -static int cmd_write_id(int argc, char **argv) -{ - int id = -1; - int new_id = -1; - lx_t device; - - if (argc != 3) { - printf("usage: %s \n", argv[0]); - return 1; - } - /* parse parameters */ - id = parse_dev(argv[1]); - new_id = parse_dev(argv[2]); - if ((id < 0) || (new_id < 0)) { - return -1; - } - - device.stream = &stream; - device.id = id; - - /* ping */ - if (lx_servo_id_write(&device, new_id) == LX_OK) { - printf("Device id %i change request successfully sent to: %i\n", id, new_id); - } - else { - printf("No response from device %i\n", id); - } - return 0; -} - -static int cmd_load_on(int argc, char **argv) -{ - int id = -1; - lx_t device; - - if (argc != 2) { - printf("usage: %s \n", argv[0]); - return 1; - } - /* parse parameters */ - id = parse_dev(argv[1]); - if (id < 0) { - return -1; - } - - device.stream = &stream; - device.id = id; - - /* Turn led on */ - if (lx_servo_load_or_unload_write(&device, LX_SERVO_LOADED) == LX_OK) { - printf("Device id %i led has been loaded on\n", id); - } - else { - printf("No response from device %i\n", id); - } - return 0; -} - -static int cmd_load_off(int argc, char **argv) -{ - int id = -1; - lx_t device; - - if (argc != 2) { - printf("usage: %s \n", argv[0]); - return 1; - } - /* parse parameters */ - id = parse_dev(argv[1]); - if (id < 0) { - return -1; - } - - device.stream = &stream; - device.id = id; - - /* Turn led on */ - if (lx_servo_load_or_unload_write(&device, LX_SERVO_UNLOADED) == LX_OK) { - printf("Device id %i led has been unloaded on\n", id); - } - else { - printf("No response from device %i\n", id); - } - return 0; -} - -static int cmd_led_on(int argc, char **argv) -{ - int id = -1; - lx_t device; - - if (argc != 2) { - printf("usage: %s \n", argv[0]); - return 1; - } - /* parse parameters */ - id = parse_dev(argv[1]); - if (id < 0) { - return -1; - } - - device.stream = &stream; - device.id = id; - - /* Turn led on */ - if (lx_servo_led_ctrl_write(&device, LX_SERVO_LED_ON) == LX_OK) { - printf("Device id %i led has been turned on\n", id); - } - else { - printf("No response from device %i\n", id); - } - return 0; -} - -static int cmd_led_off(int argc, char **argv) -{ - int id = -1; - lx_t device; - - if (argc != 2) { - printf("usage: %s \n", argv[0]); - return 1; - } - /* parse parameters */ - id = parse_dev(argv[1]); - if (id < 0) { - return -1; - } - - device.stream = &stream; - device.id = id; - - /* Turn led on */ - if (lx_servo_led_ctrl_write(&device, LX_SERVO_LED_OFF) == LX_OK) { - printf("Device id %i led has been turned off\n", id); - } - else { - printf("No response from device %i\n", id); - } - return 0; -} - -static int cmd_led_conf(int argc, char **argv) -{ - int id = -1; - int led_conf; - lx_t device; - - if (argc != 3) { - printf("usage: %s \n", argv[0]); - return 1; - } - /* parse parameters */ - id = parse_dev(argv[1]); - if (id < 0) { - return -1; - } - led_conf = parse_u8(argv[2]); - if (led_conf < 0) { - return -1; - } - - device.stream = &stream; - device.id = id; - - /* Turn led on */ - if (lx_servo_led_error_write(&device, led_conf) == LX_OK) { - printf("Device id %i error led has been configured\n", id); - } - else { - printf("No response from device %i\n", id); - } - return 0; -} - -static int cmd_move_time(int argc, char **argv) -{ - int id = -1; - int angle = -1; - int time = -1; - lx_t device; - - if (argc != 4) { - printf("usage: %s