+DIP, add mode switching at boot

This commit is contained in:
2026-11-10 17:18:10 +02:00
parent 2c348030ab
commit 188e9af392
12 changed files with 165 additions and 5 deletions
+29
View File
@@ -0,0 +1,29 @@
set(KPI_Rover_DIP_Inc
${CMAKE_CURRENT_SOURCE_DIR}
)
set(KPI_Rover_DIP_Src
${CMAKE_CURRENT_SOURCE_DIR}/hwDIP.c
${CMAKE_CURRENT_SOURCE_DIR}/drvDip.c
${CMAKE_CURRENT_SOURCE_DIR}/ulDip.c
)
add_library(KPI_Rover_DIP STATIC)
target_include_directories(KPI_Rover_DIP PRIVATE
${KPI_Rover_DIP_Inc}
)
target_sources(KPI_Rover_DIP PRIVATE
${KPI_Rover_DIP_Src}
)
target_link_libraries(KPI_Rover_DIP PRIVATE
FREERTOS_H
HAL_H
)
add_library(KPI_Rover_DIP_H INTERFACE)
target_include_directories(KPI_Rover_DIP_H INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)
+12
View File
@@ -0,0 +1,12 @@
#include "main.h"
#include "hwDIP.h"
void drvDip_Init(void)
{
HW_DIP_Init();
}
unsigned char drvDip_read(void)
{
return (unsigned char) (GPIOE->IDR >> 12);
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef __DRV_DIP_H
#define __DRV_DIP_H
void drvDip_Init(void);
unsigned char drvDip_read(void);
#endif /* __DRV_DIP_H */
+11
View File
@@ -0,0 +1,11 @@
#include "main.h"
void HW_DIP_Init(void)
{
__HAL_RCC_GPIOE_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef __HW_DIP_H
#define __HW_DIP_H
void HW_DIP_Init(void);
#endif /* __HW_DIP_H */
+22
View File
@@ -0,0 +1,22 @@
#include "ulDip.h"
#include "drvDip.h"
bool ulDip_Init(void)
{
drvDip_Init();
return true;
}
bool ulDip_Read(bool * const target)
{
unsigned char v = drvDip_read();
for (int i = 0; i < 4; i++)
{
target[i] = !(v & 1);
v >>= 1;
}
return true;
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef __UL_DIP_H
#define __UL_DIP_H
#include <stdbool.h>
bool ulDip_Init(void);
bool ulDip_Read(bool * const target);
#endif /* __UL_DIP_H */