add working Ultrasonic tests
This commit is contained in:
@@ -25,6 +25,8 @@ set(KPIROVER_COMPONENTS
|
||||
PCA9685_Test
|
||||
Servos
|
||||
Servos_Test
|
||||
Ultrasonic
|
||||
Ultrasonic_Test
|
||||
)
|
||||
|
||||
foreach(arb ${KPIROVER_ARBITERS})
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "ulMotorsController.h"
|
||||
#include "PCA9685_Test.h"
|
||||
#include "Servos_Test.h"
|
||||
#include "Ultrasonic_Test.h"
|
||||
//#include "Storage/ulStorage.h"
|
||||
//#include "ulAdc.h"
|
||||
|
||||
@@ -83,6 +84,7 @@ void KPIRover_Init(void) {
|
||||
arbI2C_Init();
|
||||
(void) PCA9685_Test_Init();
|
||||
Servos_Test_Init();
|
||||
Ultrasonic_Test_Init();
|
||||
ulLEDMode_Start();
|
||||
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
set(KPI_Rover_Ultrasonic_Inc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
set(KPI_Rover_Ultrasonic_Src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hwUltrasonic.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drvUltrasonic.c
|
||||
)
|
||||
|
||||
add_library(KPI_Rover_Ultrasonic STATIC)
|
||||
|
||||
target_include_directories(KPI_Rover_Ultrasonic PRIVATE
|
||||
${KPI_Rover_Ultrasonic_Inc}
|
||||
)
|
||||
|
||||
target_sources(KPI_Rover_Ultrasonic PRIVATE
|
||||
${KPI_Rover_Ultrasonic_Src}
|
||||
)
|
||||
|
||||
target_link_libraries(KPI_Rover_Ultrasonic PRIVATE
|
||||
HAL_H
|
||||
)
|
||||
|
||||
add_library(KPI_Rover_Ultrasonic_H INTERFACE)
|
||||
target_include_directories(KPI_Rover_Ultrasonic_H INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "main.h"
|
||||
#include "drvUltrasonic.h"
|
||||
#include "hwUltrasonic.h"
|
||||
|
||||
bool drvUltrasonic_Init(void)
|
||||
{
|
||||
hwUltrasonic_Init();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef __DRV_ULTRASONIC
|
||||
#define __DRV_ULTRASONIC
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool drvUltrasonic_Init(void);
|
||||
|
||||
#endif /* __DRV_ULTRASONIC */
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "main.h"
|
||||
#include "hwUltrasonic.h"
|
||||
|
||||
void hwUltrasonic_Init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef __HW_ULTRASONIC
|
||||
#define __HW_ULTRASONIC
|
||||
|
||||
#include "main.h"
|
||||
|
||||
void hwUltrasonic_Init(void);
|
||||
|
||||
#endif /* __HW_ULTRASONIC */
|
||||
@@ -0,0 +1,29 @@
|
||||
set(KPI_Rover_Ultrasonic_Test_Inc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
set(KPI_Rover_Ultrasonic_Test_Src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Ultrasonic_Test.c
|
||||
)
|
||||
|
||||
add_library(KPI_Rover_Ultrasonic_Test STATIC)
|
||||
|
||||
target_include_directories(KPI_Rover_Ultrasonic_Test PRIVATE
|
||||
${KPI_Rover_Ultrasonic_Test_Inc}
|
||||
)
|
||||
|
||||
target_sources(KPI_Rover_Ultrasonic_Test PRIVATE
|
||||
${KPI_Rover_Ultrasonic_Test_Src}
|
||||
)
|
||||
|
||||
target_link_libraries(KPI_Rover_Ultrasonic_Test PRIVATE
|
||||
HAL_H
|
||||
KPI_Rover_Ultrasonic_H
|
||||
KPI_Rover_Ultrasonic
|
||||
FREERTOS_H
|
||||
)
|
||||
|
||||
add_library(KPI_Rover_Ultrasonic_Test_H INTERFACE)
|
||||
target_include_directories(KPI_Rover_Ultrasonic_Test_H INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "Ultrasonic_Test.h"
|
||||
#include "drvUltrasonic.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "main.h"
|
||||
|
||||
static const osThreadAttr_t task_attrs = {
|
||||
.stack_size = 256
|
||||
};
|
||||
|
||||
static void Ultrasonic_Test_Task(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_SET);
|
||||
osDelay(20);
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET);
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void Ultrasonic_Test_Init(void)
|
||||
{
|
||||
(void) drvUltrasonic_Init();
|
||||
|
||||
osThreadNew(Ultrasonic_Test_Task, (void *) 0, &task_attrs);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef __TEST_ULTRASONIC
|
||||
#define __TEST_ULTRASONIC
|
||||
|
||||
void Ultrasonic_Test_Init(void);
|
||||
|
||||
#endif /* __TEST_ULTRASONIC */
|
||||
Reference in New Issue
Block a user