commit edc6ddb3c7af1565bc2930b234251f74a6206a4c Author: cfif Date: Mon Jun 2 13:26:40 2025 +0300 Init diff --git a/Gpios.c b/Gpios.c new file mode 100644 index 0000000..906be26 --- /dev/null +++ b/Gpios.c @@ -0,0 +1,126 @@ + + +// +// Created by ilya on 22.03.24. +// + +#include "Gpios.h" +#include +#include "SystemDelayInterface.h" +#include "PwmSim7600e.h" + +tGpios GPIOS; + +void Gpios_InitMainPower(tMainPower *env){ + env->ecallOut= InitGpioPin(GPIOB, GPIO_PINS_2, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->garage = InitGpioPin(GPIOE, GPIO_PINS_7, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->muteP = InitGpioPin(GPIOD, GPIO_PINS_11, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->muteN = InitGpioPin(GPIOE, GPIO_PINS_8, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->Power12V = InitGpioPinOpenDrain(GPIOE, GPIO_PINS_13, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->inAnt = InitGpioPin(GPIOC, GPIO_PINS_6, GPIO_MODE_OUTPUT, GPIO_PIN_REVERSE); + env->ignition = InitGpioPin(GPIOD, GPIO_PINS_10, GPIO_MODE_INPUT, GPIO_PIN_REVERSE); + env->standby = InitGpioPin(GPIOD, GPIO_PINS_14, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); +} + +void Gpios_CanStandby(tCanStandby *env) { + env->can1_standby = InitGpioPin(GPIOD, GPIO_PINS_3, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->can2_standby = InitGpioPin(GPIOB, GPIO_PINS_7, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); +} + +static void Gpios_InitBattery(tBatteryPower *env) { + env->enable = InitGpioPin(GPIOD, GPIO_PINS_2, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->charge =InitGpioPin(GPIOC, GPIO_PINS_10, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); +} + +static void Gpios_InitBIP(tBipPins *env) { + crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE); + env->led.ledsBip = InitGpioPin(GPIOE, GPIO_PINS_14, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->led.red = InitGpioPin(GPIOA, GPIO_PINS_5, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->led.green = InitGpioPin(GPIOA, GPIO_PINS_6, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->Backlight = InitGpioPin(GPIOA, GPIO_PINS_4, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->Diagnost = InitGpioPin(GPIOC, GPIO_PINS_4, GPIO_MODE_INPUT, GPIO_PIN_REVERSE); + + env->buttons.additional = InitGpioPin(GPIOE, GPIO_PINS_1, GPIO_MODE_INPUT, GPIO_PIN_NOREVERSE); + env->buttons.emergency = InitGpioPin(GPIOE, GPIO_PINS_0, GPIO_MODE_INPUT, GPIO_PIN_NOREVERSE); + env->lastTestTime = 0; + GpioPinSet(&env->led.green, false); + GpioPinSet(&env->led.red, true); + +} + +void Gpios_DeviceLeds(tOnBoardLed *env){ + env->red1 = InitGpioPin(GPIOE, GPIO_PINS_2, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->green1 = InitGpioPin(GPIOE, GPIO_PINS_3, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->red2 = InitGpioPin(GPIOE, GPIO_PINS_4, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->green2 = InitGpioPin(GPIOE, GPIO_PINS_5, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); +} + +void Gpios_InitSim7600(tSim7600ePower *env) { + env->gsm.powerKey = InitGpioPin(GPIOE, GPIO_PINS_11, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->gsm.PowerGsm = InitGpioPin(GPIOA, GPIO_PINS_8, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->gsm.PowerCheckGsm = InitGpioPin(GPIOA, GPIO_PINS_10, GPIO_MODE_INPUT, GPIO_PIN_NOREVERSE); + env->powerStatus = InitGpioPin(GPIOA, GPIO_PINS_9, GPIO_MODE_INPUT, GPIO_PIN_NOREVERSE); + env->reset = InitGpioPin(GPIOE, GPIO_PINS_10, GPIO_MODE_INPUT, GPIO_PIN_NOREVERSE); + env->SimSelector = InitGpioPin(GPIOD, GPIO_PINS_15, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); +} + +void Gpios_AccelPins(tAccelPins *env){ + env->spiChipSelect = InitGpioPin(GPIOB, GPIO_PINS_12, GPIO_MODE_OUTPUT, GPIO_PIN_REVERSE); + env->int1 = InitGpioPin(GPIOA, GPIO_PINS_11, GPIO_MODE_INPUT, GPIO_PIN_NOREVERSE); + env->int2 = InitGpioPin(GPIOA, GPIO_PINS_12, GPIO_MODE_INPUT, GPIO_PIN_NOREVERSE); +} + +void Gpios_RS485DirectionPins(tRs485DirectionPins *env){ + env->transmit = InitGpioPin(GPIOB, GPIO_PINS_8, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->receive = InitGpioPin(GPIOB, GPIO_PINS_9, GPIO_MODE_OUTPUT, GPIO_PIN_REVERSE); +} + +void Gpios_InitAudio(tAudioPower *env){ + env->resetAmp = InitGpioPin(GPIOB, GPIO_PINS_0, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); +// env->powerAmp = InitGpioPinOpenDrain(GPIOE, GPIO_PINS_12, GPIO_MODE_OUTPUT, GPIO_PIN_REVERSE); +} + +void Gpios_InitTestAudio(tSpekTestPower *env){ + env->PowerCheckSpkOn = InitGpioPinOpenDrain(GPIOA, GPIO_PINS_7, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + env->PowerTestSpkIn = InitGpioPin(GPIOC, GPIO_PINS_5, GPIO_MODE_INPUT, GPIO_PIN_REVERSE); + env->speakTestAcsess = true; +} + +static void Gpios_InitPower(tPowerSusystem *env) { + env->PowerRS485 = InitGpioPin(GPIOC, GPIO_PINS_3, GPIO_MODE_OUTPUT, GPIO_PIN_NOREVERSE); + + Gpios_InitTestAudio(&env->SpekTestPower); + Gpios_InitSim7600(&env->sim7600); + + Gpios_InitAudio(&env->audio); + Gpios_InitMainPower(&env->main); + Gpios_InitBattery(&env->battery); +} + +void Gpios_ClcInit() { + crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE); + crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE); + crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE); + crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE); + crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE); + crm_periph_clock_enable(CRM_GPIOF_PERIPH_CLOCK, TRUE); + crm_periph_clock_enable(CRM_GPIOH_PERIPH_CLOCK, TRUE); + crm_periph_clock_enable(CRM_GPIOG_PERIPH_CLOCK, TRUE); +} + +void Gpios_Init() { + Gpios_ClcInit(); + + tGpios *env = &GPIOS; + + Gpios_AccelPins(&env->accel); + Gpios_DeviceLeds(&env->onBoardLed); + Gpios_RS485DirectionPins(&env->comIntDir); + Gpios_InitBIP(&env->bip); + + Gpios_InitPower(&env->powerSusystem); + Gpios_InitAudio(&env->powerSusystem.audio); + Gpios_InitSim7600(&env->powerSusystem.sim7600); + Gpios_CanStandby(&env->powerSusystem.canStandby); +} + diff --git a/Gpios.h b/Gpios.h new file mode 100644 index 0000000..dcdbd24 --- /dev/null +++ b/Gpios.h @@ -0,0 +1,39 @@ +// +// Created by ilya on 22.03.24. +// + +#ifndef SMART_COMPONENTS_GPIOS_H +#define SMART_COMPONENTS_GPIOS_H +#include +//#include "PowerManagement.h" +#include "UserInput.h" +#include "UserIndication.h" +#include "SpiPorts.h" +#include "PowerManagment.h" +//#include "PowerManagment.h" + +typedef struct { + tBipLed led; + tUserInputPins buttons; + tGpioPin Backlight; + tGpioPin Power; + tGpioPin Diagnost; + uint16_t lastTestTime; +} tBipPins; + +typedef struct { + tAccelPins accel; + tFlashPins flash; + tOnBoardLed onBoardLed; + tBipPins bip; + tRs485DirectionPins comIntDir; + + tPowerSusystem powerSusystem; +} tGpios; + +extern tGpios GPIOS; + +void Gpios_Init(); +void Gpios_CanStandby(tCanStandby *env); + +#endif //SMART_COMPONENTS_GPIOS_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..0dd1901 --- /dev/null +++ b/modular.json @@ -0,0 +1,10 @@ +{ + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file