diff --git a/Application/BSP/BSP_EE24.c b/Application/BSP/BSP_EE24.c index bebb7e1..1e77dae 100644 --- a/Application/BSP/BSP_EE24.c +++ b/Application/BSP/BSP_EE24.c @@ -9,7 +9,7 @@ #include "ee24.h" #include "i2c.h" #include "cmsis_os2.h" -#include "gpio.h" +#include "BSP_GPIO.h" #define BSP_EE24_I2C &hi2c2 #define BSP_EE24_ADDRESS EE24_ADDRESS_DEFAULT @@ -71,7 +71,7 @@ bool BSP_EE24_Init(void) { ee24_lock = osMutexNew(NULL); // wc control high disables write - HAL_GPIO_WritePin(EEPROM_WC_GPIO_Port, EEPROM_WC_Pin, GPIO_PIN_SET); + BSP_GPIO_EE24WriteProtectOn(); // Read the Partition Table header from the EEPROM BSP_EE24_TableHeader header = {0}; @@ -121,9 +121,9 @@ bool BSP_EE24_Read(uint32_t Address, uint8_t *Data, size_t Len) { */ bool BSP_EE24_Write(uint32_t Address, uint8_t *Data, size_t Len) { osMutexAcquire(ee24_lock,BSP_EE24_MUTEXT_TIMEOUT); - HAL_GPIO_WritePin(EEPROM_WC_GPIO_Port, EEPROM_WC_Pin, GPIO_PIN_RESET); // low enables write; + BSP_GPIO_EE24WriteProtectOff(); bool status = EE24_Write(&hee24,Address,Data,Len,BSP_EE24_TIMEOUT); - HAL_GPIO_WritePin(EEPROM_WC_GPIO_Port, EEPROM_WC_Pin, GPIO_PIN_SET); // high disables write; + BSP_GPIO_EE24WriteProtectOn(); osMutexRelease(ee24_lock); return status; } diff --git a/Application/BSP/BSP_GPIO.c b/Application/BSP/BSP_GPIO.c new file mode 100644 index 0000000..b37f8f0 --- /dev/null +++ b/Application/BSP/BSP_GPIO.c @@ -0,0 +1,78 @@ +#include "BSP_GPIO.h" +#include "main.h" +#include "gpio.h" + + +/** + * @brief Checks if the K15 pin is set. + * @return true if the K15 pin is set, false otherwise. + */ +bool BSP_GPIO_K15isSet() { + return HAL_GPIO_ReadPin(K15_Detect_GPIO_Port, K15_Detect_Pin) == GPIO_PIN_SET; +} + +/** + * @brief Turns on the CLS power. + */ +void BSP_GPIO_ClsOn() { + HAL_GPIO_WritePin(CLS_POWER_GPIO_Port, CLS_POWER_Pin, GPIO_PIN_SET); +} + +/** + * @brief Turns off the CLS power. + */ +void BSP_GPIO_ClsOff() { + HAL_GPIO_WritePin(CLS_POWER_GPIO_Port, CLS_POWER_Pin, GPIO_PIN_RESET); +} + +/** + * @brief Turns on the peripheral power. + */ +void BSP_GPIO_PeriperalsOn() { + HAL_GPIO_WritePin(Periph_Power_GPIO_Port,Periph_Power_Pin,GPIO_PIN_RESET); +} + +/** + * @brief Turns off the peripheral power. + */ +void BSP_GPIO_PeriperalsOff() { + HAL_GPIO_WritePin(Periph_Power_GPIO_Port,Periph_Power_Pin,GPIO_PIN_SET); +} + +/** + * @brief Turns on the radio. + * + * This function sets the GPIO pin to high, turning on the radio. + */ +void BSP_GPIO_RadioOn() { + HAL_GPIO_WritePin(K15_OUT_GPIO_Port, K15_OUT_Pin, GPIO_PIN_SET); +} + +/** + * @brief Turns off the radio. + * + * This function sets the GPIO pin to low, turning off the radio. + */ +void BSP_GPIO_RadioOff() { + HAL_GPIO_WritePin(K15_OUT_GPIO_Port, K15_OUT_Pin, GPIO_PIN_RESET); +} + +/** + * @brief Turns on the write protection for the EEPROM. + * + * This function sets the write protect pin of the EEPROM to high, + * enabling write protection for the EEPROM. + */ +void BSP_GPIO_EE24WriteProtectOn() { + HAL_GPIO_WritePin(EEPROM_WC_GPIO_Port, EEPROM_WC_Pin, GPIO_PIN_SET); +} + +/** + * @brief Turns off the write protection for the EEPROM. + * + * This function sets the write protect pin of the EEPROM to low, + * disabling write protection for the EEPROM. + */ +void BSP_GPIO_EE24WriteProtectOff() { + HAL_GPIO_WritePin(EEPROM_WC_GPIO_Port, EEPROM_WC_Pin, GPIO_PIN_RESET); +} diff --git a/Application/BSP/BSP_GPIO.h b/Application/BSP/BSP_GPIO.h index 0e2b917..6381a4a 100644 --- a/Application/BSP/BSP_GPIO.h +++ b/Application/BSP/BSP_GPIO.h @@ -1,3 +1,27 @@ // GPIOs access functions // External Interrupts -// Shordhand functions to read improtant pins \ No newline at end of file +// Shordhand functions to read improtant pins + + +#include "stdint.h" +#include "stdbool.h" + +// Check K15 input +bool BSP_GPIO_K15isSet(); + +// Set On / Off for CLS_Relay +void BSP_GPIO_ClsOn(); +void BSP_GPIO_ClsOff(); + + +// Set On / Off for peripheral +void BSP_GPIO_PeriperalsOn(); +void BSP_GPIO_PeriperalsOff(); + +// Set On / Off for 12V Radio Power +void BSP_GPIO_RadioOn(); +void BSP_GPIO_RadioOff(); + + +void BSP_GPIO_EE24WriteProtectOn(); +void BSP_GPIO_EE24WriteProtectOff(); diff --git a/Application/BSP/CMakeLists.txt b/Application/BSP/CMakeLists.txt index 8b75cb2..ed7b7e5 100644 --- a/Application/BSP/CMakeLists.txt +++ b/Application/BSP/CMakeLists.txt @@ -3,6 +3,7 @@ add_library(BSP STATIC BSP_EE24.c BSP_INA.c BSP_POWER.c +BSP_GPIO.c ) target_include_directories(BSP PUBLIC ./)