#ifndef __INTERFACE_H #define __INTERFACE_H #include "includes.h" #include "stm32f4xx_rcc.h" #include typedef enum { kI2C0 = 0, kI2C1, kI2C2, kADC0, kADC2, kSPI2, kUart1, kUart3, kCAN1, kCAN2, kEthernet, kInput, kOutput, kPMU, kDMA1, // kTIMER1, kInterfaceEnd, } interface_type; typedef enum { RCC_APB1Periph, RCC_APB2Periph, RCC_AHB1Periph, RCC_AHB2Periph, RCC_AHB3Periph, } enum_clock_type; typedef struct { interface_type type; enum_clock_type RCC_AXBPeriph; uint32_t AF_Clock; } Gpio_Clock; typedef enum { kRunLed, kPRelayCtr, kNRelayCtr, kPreRelayCtr, kFanCtr, kOut1Ctr, // charger kOut2Ctr, // charger heat kExtWatchDog, kExtRelayLed, kExtFaultLed, kISOPRelayCtr, kISONRelayCtr, kSoftI2C3_SDA, kSoftI2C3_SCL, kSoftI2C4_SDA, kSoftI2C4_SCL, kOutputEnd, } Output_Type; typedef enum { kLDetect, kInputEnd, } Input_type; typedef struct { GPIO_TypeDef *GPIOx; INT16U GPIO_PinSource; INT8U GPIO_AF; } GPIO_AF_Info; typedef struct { interface_type type; Output_Type Out_Type; Input_type In_Type; GPIO_TypeDef *GPIOx; INT32U GPIO_Pin; GPIOMode_TypeDef GPIO_Mode; GPIO_AF_Info AF_Info; GPIOOType_TypeDef GPIO_OType; GPIOSpeed_TypeDef GPIO_Speed; GPIOPuPd_TypeDef GPIO_PuPd; } Interface_struct; // // soft I2C // #define SI2C3_SDA_PIN GPIO_PIN_3 // #define SI2C3_SDA_PORT GPIOD // #define SI2C3_SCL_PIN GPIO_PIN_2 // #define SI2C3_SCL_PORT GPIOD // #define SI2C4_SDA_PIN GPIO_PIN_15 // #define SI2C4_SDA_PORT GPIOE // #define SI2C4_SCL_PIN GPIO_PIN_14 // #define SI2C4_SCL_PORT GPIOE // #define SI2C3_SDA_HIGH GPIO_SetBits(SI2C3_SDA_PORT, SI2C3_SDA_PIN) // #define SI2C3_SDA_LOW GPIO_ResetBits(SI2C3_SDA_PORT, SI2C3_SDA_PIN) // #define SI2C3_SCL_HIGH GPIO_SetBits(SI2C3_SCL_PORT, SI2C3_SCL_PIN) // #define SI2C3_SCL_LOW GPIO_ResetBits(SI2C3_SCL_PORT, SI2C3_SCL_PIN) // #define SI2C4_SDA_HIGH GPIO_SetBits(SI2C4_SDA_PORT, SI2C4_SDA_PIN) // #define SI2C4_SDA_LOW GPIO_ResetBits(SI2C4_SDA_PORT, SI2C4_SDA_PIN) // #define SI2C4_SCL_HIGH GPIO_SetBits(SI2C4_SCL_PORT, SI2C4_SCL_PIN) // #define SI2C4_SCL_LOW GPIO_ResetBits(SI2C4_SCL_PORT, SI2C4_SCL_PIN) // #define SI2C3_SDA_OUT gpio_mode_set(SI2C3_SDA_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SI2C3_SDA_PIN) // #define SI2C3_SDA_IN gpio_mode_set(SI2C3_SDA_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, SI2C3_SDA_PIN) // #define SI2C3_SDA_READ gpio_input_bit_get(SI2C3_SDA_PORT, SI2C3_SDA_PIN) // #define SI2C4_SDA_OUT gpio_mode_set(SI2C4_SDA_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SI2C4_SDA_PIN) // #define SI2C4_SDA_IN gpio_mode_set(SI2C4_SDA_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, SI2C4_SDA_PIN) // #define SI2C4_SDA_READ gpio_input_bit_get(SI2C4_SDA_PORT, SI2C4_SDA_PIN) // uart #define UART1_ENABLE_PORT GPIOA #define UART1_ENABLE_PIN GPIO_Pin_15 #define UART3_ENABLE_PORT GPIOB #define UART3_ENABLE_PIN GPIO_Pin_2 #define UART1_TX_ENABLE GPIO_SetBits(UART1_ENABLE_PORT, UART1_ENABLE_PIN) #define UART1_RX_ENABLE GPIO_ResetBits(UART1_ENABLE_PORT, UART1_ENABLE_PIN) #define UART3_TX_ENABLE GPIO_SetBits(UART3_ENABLE_PORT, UART3_ENABLE_PIN) #define UART3_RX_ENABLE GPIO_ResetBits(UART3_ENABLE_PORT, UART3_ENABLE_PIN) // // SPI // #define SPI2_CS_PORT GPIOA // #define SPI2_CS_PIN GPIO_PIN_15 // #define SPI2_CS_HIGH GPIO_SetBits(SPI2_CS_PORT, SPI2_CS_PIN) // #define SPI2_CS_LOW GPIO_ResetBits(SPI2_CS_PORT, SPI2_CS_PIN) // // ethernet // //#define ENET_REF_CLK GPIO_PIN_1 // //#define ENET_REF_CLK_Port GPIOA // //#define ENET_MDC GPIO_PIN_1 // //#define ENET_MDC_Port GPIOC // //#define ENET_MDIO GPIO_PIN_2 // //#define ENET_MDIO_Port GPIOA // //#define ENET_CRSDV GPIO_PIN_7 // //#define ENET_CRSDV_Port GPIOA // //#define ENET_RXD0 GPIO_PIN_4 // //#define ENET_RXD0_Port GPIOC // //#define ENET_RXD1 GPIO_PIN_5 // //#define ENET_RXD1_Port GPIOC // //#define ENET_TXEN GPIO_PIN_11 // //#define ENET_TXEN_Port GPIOG // //#define ENET_RXER GPIO_PIN_12 // //#define ENET_RXER_Port GPIOG // //#define ENET_TXD0 GPIO_PIN_13 // //#define ENET_TXD0_Port GPIOG // //#define ENET_TXD1 GPIO_PIN_14 // //#define ENET_TXD1_Port GPIOG #define ETH_RESET_PORT GPIOH #define ETH_RESET_PIN GPIO_Pin_6 // #define ETH_RXER_PORT GPIOG // #define ETH_RXER_PIN GPIO_PIN_12 #define ETH_RESET_ON GPIO_ResetBits(ETH_RESET_PORT, ETH_RESET_PIN) #define ETH_RESET_OFF GPIO_SetBits(ETH_RESET_PORT, ETH_RESET_PIN) // output #define LED0_RUN_PORT GPIOC #define LED0_RUN_PIN GPIO_Pin_2 #define LED1_RUN_PORT GPIOF #define LED1_RUN_PIN GPIO_Pin_7 #define LED2_RUN_PORT GPIOF #define LED2_RUN_PIN GPIO_Pin_8 #define LED3_RUN_PORT GPIOI #define LED3_RUN_PIN GPIO_Pin_10 // #define PRelayCtr_PORT GPIOD // #define PRelayCtr_PIN GPIO_PIN_6 // #define NRelayCtr_PORT GPIOD // #define NRelayCtr_PIN GPIO_PIN_5 // #define PreRelayCtr_PORT GPIOG // #define PreRelayCtr_PIN GPIO_PIN_9 // #define Fan_PORT GPIOG // #define Fan_PIN GPIO_PIN_10 // #define OUT1CTR_PORT GPIOD // #define OUT1CTR_PIN GPIO_PIN_7 // #define OUT2CTR_PORT GPIOE // #define OUT2CTR_PIN GPIO_PIN_1 // #define EXTWATCHDOG_PORT GPIOC // #define EXTWATCHDOG_PIN GPIO_PIN_3 // #define ExtRelayLed_PORT GPIOD // #define ExtRelayLed_PIN GPIO_PIN_11 // #define ExtFaultLed_PORT GPIOD // #define ExtFaultLed_PIN GPIO_PIN_10 // #define ISOPRelayCtr_PORT GPIOF // #define ISOPRelayCtr_PIN GPIO_PIN_14 // #define ISONRelayCtr_PORT GPIOF // #define ISONRelayCtr_PIN GPIO_PIN_15 // // input // #define LDetect1_PORT GPIOD // #define LDetect1_PIN GPIO_PIN_13 // output operation #define LED0_RUN_ON GPIO_SetBits(LED0_RUN_PORT, LED0_RUN_PIN) #define LED0_RUN_OFF GPIO_ResetBits(LED0_RUN_PORT, LED0_RUN_PIN) #define LED0_RUN_TOGGLE GPIO_ToggleBits(LED0_RUN_PORT, LED0_RUN_PIN) #define LED1_RUN_ON GPIO_SetBits(LED1_RUN_PORT, LED1_RUN_PIN) #define LED1_RUN_OFF GPIO_ResetBits(LED1_RUN_PORT, LED1_RUN_PIN) #define LED1_RUN_TOGGLE GPIO_ToggleBits(LED1_RUN_PORT, LED1_RUN_PIN) #define LED2_RUN_ON GPIO_SetBits(LED2_RUN_PORT, LED2_RUN_PIN) #define LED2_RUN_OFF GPIO_ResetBits(LED2_RUN_PORT, LED2_RUN_PIN) #define LED2_RUN_TOGGLE GPIO_ToggleBits(LED2_RUN_PORT, LED2_RUN_PIN) #define LED3_RUN_ON GPIO_SetBits(LED3_RUN_PORT, LED3_RUN_PIN) #define LED3_RUN_OFF GPIO_ResetBits(LED3_RUN_PORT, LED3_RUN_PIN) #define LED3_RUN_TOGGLE GPIO_ToggleBits(LED3_RUN_PORT, LED3_RUN_PIN) // #define PRelayCtr_ON GPIO_SetBits(PRelayCtr_PORT, PRelayCtr_PIN) // #define PRelayCtr_OFF GPIO_ResetBits(PRelayCtr_PORT, PRelayCtr_PIN) // #define NRelayCtr_ON GPIO_SetBits(NRelayCtr_PORT, NRelayCtr_PIN) // #define NRelayCtr_OFF GPIO_ResetBits(NRelayCtr_PORT, NRelayCtr_PIN) // #define PreRelayCtr_ON GPIO_SetBits(PreRelayCtr_PORT, PreRelayCtr_PIN) // #define PreRelayCtr_OFF GPIO_ResetBits(PreRelayCtr_PORT, PreRelayCtr_PIN) // #define FAN_ON GPIO_SetBits(Fan_PORT, Fan_PIN) // #define FAN_OFF GPIO_ResetBits(Fan_PORT, Fan_PIN) // #define OUT1CTR_ON GPIO_SetBits(OUT1CTR_PORT, OUT1CTR_PIN) // #define OUT1CTR_OFF GPIO_ResetBits(OUT1CTR_PORT, OUT1CTR_PIN) // #define OUT2CTR_ON GPIO_SetBits(OUT2CTR_PORT, OUT2CTR_PIN) // #define OUT2CTR_OFF GPIO_ResetBits(OUT2CTR_PORT, OUT2CTR_PIN) // #define FEED_DOG_ON GPIO_SetBits(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN) // #define FEED_DOG_OFF GPIO_ResetBits(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN) // #define FEED_DOG_TOGGLE GPIO_WriteBit(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN, (FlagStatus)(1 - (gpio_output_bit_get(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN)))) // #define ExtRelayLed_ON GPIO_SetBits(ExtRelayLed_PORT, ExtRelayLed_PIN) // #define ExtRelayLed_OFF GPIO_ResetBits(ExtRelayLed_PORT, ExtRelayLed_PIN) // #define ExtFaultLed_ON GPIO_SetBits(ExtFaultLed_PORT, ExtFaultLed_PIN) // #define ExtFaultLed_OFF GPIO_ResetBits(ExtFaultLed_PORT, ExtFaultLed_PIN) // #define ISOPRelay_ON GPIO_SetBits(ISOPRelayCtr_PORT, ISOPRelayCtr_PIN) // #define ISOPRelay_OFF GPIO_ResetBits(ISOPRelayCtr_PORT, ISOPRelayCtr_PIN) // #define ISONRelay_ON GPIO_SetBits(ISONRelayCtr_PORT, ISONRelayCtr_PIN) // #define ISONRelay_OFF GPIO_ResetBits(ISONRelayCtr_PORT, ISONRelayCtr_PIN) // // input result // #define L_IN1_IS_LOW (gpio_input_bit_get(LDetect1_PORT, LDetect1_PIN) == RESET) void interface_init(void); void gpio_clock_init(void); #endif