void SWITCH_management(void){ Nop(); Nop(); Nop(); set_port_pin(&PORTB, 0); clear_port_pin(&PORTB, 0); }
/* * 74hc164 上升沿锁存数据 * 先发送低bit数据 * * 164输出高电平时, led点亮 * */ void write_32bit_to_74hc164(unsigned long data) { int cnt; for (cnt=31; cnt>=0; --cnt) { if (0 != (data & (1<<cnt))) set_port_pin(s2p_74hc164_data_gpio, s2p_74hc164_data_pin); else clr_port_pin(s2p_74hc164_data_gpio, s2p_74hc164_data_pin); clr_port_pin(s2p_74hc164_clk_gpio, s2p_74hc164_clk_pin); set_port_pin(s2p_74hc164_clk_gpio, s2p_74hc164_clk_pin); } clr_port_pin(s2p_74hc164_clk_gpio, s2p_74hc164_clk_pin); return; }
/* * Shutdown input pin. 0–V DD V digital input. SDN should be = 0 in all modes except Shutdown mode. When * SDN =1 the chip will be completely shutdown and the contents of the registers will be lost. * */ void shutdown_si443x_or_not(int shutdown) { if (0 != shutdown) { set_port_pin(SI4432_SDN_GPIO, SI4432_SDN_PIN); } else { clr_port_pin(SI4432_SDN_GPIO, SI4432_SDN_PIN); } return; }
void touch_pins_cfg(void) { GPIO_InitTypeDef GPIO_InitStructure; /* touch pad interrupt, PB1 touch INT */ GPIO_InitStructure.GPIO_Pin = TOUCH_INT_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(TOUCH_INT_PORT, &GPIO_InitStructure); /* touch chip busy pin */ GPIO_InitStructure.GPIO_Pin = TOUCH_BUSY_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(TOUCH_BUSY_PORT, &GPIO_InitStructure); /* touch CS */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = TOUCH_CS_PIN; GPIO_Init(TOUCH_CS_PORT, &GPIO_InitStructure); set_port_pin(TOUCH_CS_PORT, TOUCH_CS_PIN); #if 0==TOUCH_USE_PHONY_SPI /* Configure SPI pins: SCK, MISO and MOSI */ GPIO_InitStructure.GPIO_Pin = TOUCH_SPI_SCK | TOUCH_SPI_MISO | TOUCH_SPI_MOSI; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(TOUCH_SPI_PORT, &GPIO_InitStructure); #else // Set as Output push-pull - SCK and MOSI GPIO_InitStructure.GPIO_Pin = TOUCH_SPI_SCK | TOUCH_SPI_MOSI; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(TOUCH_SPI_PORT, &GPIO_InitStructure); clr_spip_sck(); //SPI_MISO GPIO_InitStructure.GPIO_Pin = TOUCH_SPI_MISO; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(TOUCH_SPI_PORT, &GPIO_InitStructure); #endif }
/* * CPU中所对应SD卡接口 SD卡接口 * 引脚号 管脚 注释 引脚号 注释 备注 * 78 PC10 SDIO-D2 1 PC10-SDIO-D2 * 79 PC11 SDIO-D3 2 PC11-SDIO-D3 * 83 PD2 SDIO-CMD 3 PD2-SDIO-CMD * 80 PC12 SDIO-CK 5 PC12-SDIO-CK * 65 PC8 SDIO-D0 7 PC8-SDIO-D0 * 66 PC9 SDIO-D1 8 PC9-SDIO-D1 */ static void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; uart_pins_cfg(); /* led */ #if EM_MULTI_BASE GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = led1_pin; GPIO_Init(led1_gpio, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = led2_pin; GPIO_Init(led2_gpio, &GPIO_InitStructure); led_off(led1_gpio, led1_pin); led_off(led2_gpio, led2_pin); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = s2p_74hc164_clk_pin; GPIO_Init(s2p_74hc164_clk_gpio, &GPIO_InitStructure); clr_port_pin(s2p_74hc164_clk_gpio, s2p_74hc164_clk_pin); GPIO_InitStructure.GPIO_Pin = s2p_74hc164_data_pin; GPIO_Init(s2p_74hc164_data_gpio, &GPIO_InitStructure); clr_port_pin(s2p_74hc164_data_gpio, s2p_74hc164_data_pin); decoder_pins_cfg(); double_mbus_indication_pins_cfg(); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = ade7880_range_switch_pin; GPIO_Init(ade7880_range_switch_gpio, &GPIO_InitStructure); //set_7880_to_lagre_scale(); set_7880_to_small_scale(); #else GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = led1_pin; GPIO_Init(led1_gpio, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = led2_pin; GPIO_Init(led2_gpio, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = led3_pin; GPIO_Init(led3_gpio, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = led4_pin; GPIO_Init(led4_gpio, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = led5_pin; GPIO_Init(led5_gpio, &GPIO_InitStructure); led_off(led1_gpio, led1_pin); led_off(led2_gpio, led2_pin); led_off(led3_gpio, led3_pin); led_off(led4_gpio, led4_pin); led_off(led5_gpio, led5_pin); #endif #if 0 /* buzzer */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = buzzer_pin; GPIO_Init(buzzer_gpio, &GPIO_InitStructure); #endif /* 485en-1 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = driver_oen_485_1_pin; GPIO_Init(driver_oen_485_1_gpio, &GPIO_InitStructure); tx_disable_rev_en_485_1(); /* 485en-2 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = driver_oen_485_2_pin; GPIO_Init(driver_oen_485_2_gpio, &GPIO_InitStructure); tx_disable_rev_en_485_2(); /* 485en-3 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = driver_oen_485_3_pin; GPIO_Init(driver_oen_485_3_gpio, &GPIO_InitStructure); tx_disable_rev_en_485_3(); #if RT_USING_ENC28J60 /* ENC28J60 */ /* * stm32f103ve使用SPI2与ENC28J60连接 * NSS -- PB12 * SCK -- PB13 * MISO -- PB14 * MOSI -- PB15 * * ENC28J60的/int引脚连接至stm32f103ve的PA8 * ENC28J60的/RST引脚连接至stm32f103ve的PC6 * * ENC28J60的/int引脚连接至stm32f103ve的PB10 * ENC28J60的/RST引脚连接至stm32f103ve的PB11 */ /* Configure SPI pins: SCK, MISO and MOSI */ GPIO_InitStructure.GPIO_Pin = ENC28J60_SPI_SCK | ENC28J60_SPI_MISO | ENC28J60_SPI_MOSI; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(ENC28J60_SPI_PORT, &GPIO_InitStructure); /* (ENC28J60_CS_PORT, ENC28J60_CS_PIN), Configure SPI2 pin: NSS */ GPIO_InitStructure.GPIO_Pin = ENC28J60_SPI_NSS; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(ENC28J60_SPI_NSS_PORT, &GPIO_InitStructure); GPIO_SetBits(ENC28J60_SPI_NSS_PORT, ENC28J60_SPI_NSS); /* /int */ GPIO_InitStructure.GPIO_Pin = ENC28J60_INT_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(ENC28J60_INT_PORT, &GPIO_InitStructure); /* /rst */ GPIO_InitStructure.GPIO_Pin = ENC28J60_RST_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(ENC28J60_RST_PORT, &GPIO_InitStructure); GPIO_SetBits(ENC28J60_RST_PORT, ENC28J60_RST_PIN); #endif #if RT_USING_SERIAL_FLASH /* spi flash */ /* Configure SPI pins: SCK, MISO and MOSI */ GPIO_InitStructure.GPIO_Pin = SF_SPI_SCK | SF_SPI_MISO | SF_SPI_MOSI; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(SF_SPI_PORT, &GPIO_InitStructure); /* (SF_CS_PORT, SF_CS_PIN), Configure SPI2 pin: NSS */ GPIO_InitStructure.GPIO_Pin = SF_SPI_NSS; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(SF_SPI_NSS_PORT, &GPIO_InitStructure); GPIO_SetBits(SF_SPI_NSS_PORT, SF_SPI_NSS); /* /hold */ GPIO_InitStructure.GPIO_Pin = SF_HOLD_PIN ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(SF_HOLD_PORT, &GPIO_InitStructure); GPIO_SetBits(SF_HOLD_PORT, SF_HOLD_PIN); /* /wp */ GPIO_InitStructure.GPIO_Pin = SF_WP_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(SF_WP_PORT, &GPIO_InitStructure); GPIO_SetBits(SF_WP_PORT, SF_WP_PIN); #endif #if RT_USING_ADE7880 cfg_spi_pin_used_by_ade7880(); #if ADE7880_USE_I2C_HSDC GPIO_InitStructure.GPIO_Pin = I2C2_SCL | I2C2_SDA; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_Init(I2C2_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = ADE7880_CS_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(ADE7880_CS_PORT, &GPIO_InitStructure); GPIO_SetBits(ADE7880_CS_PORT, ADE7880_CS_PIN); #endif ade7880_GPIO_Configuration(); #endif #if RT_USING_SI4432_MAC /* SI4432 */ /* 与ade7880共用spi3 */ GPIO_InitStructure.GPIO_Pin = SI4432_SPI_SCK | SI4432_SPI_MISO | SI4432_SPI_MOSI; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(SI4432_SPI_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SI4432_CS_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(SI4432_CS_PORT, &GPIO_InitStructure); set_port_pin(SI4432_CS_PORT, SI4432_CS_PIN); GPIO_InitStructure.GPIO_Pin = SI4432_SDN_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SI4432_SDN_GPIO, &GPIO_InitStructure); shutdown_si443x_or_not(1); #endif #if EM_ALL_TYPE_BASE /* 电能脉冲输入接口 */ GPIO_InitStructure.GPIO_Pin = EM_ACTIVE_ENERGY_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(EM_ACTIVE_ENERGY_GPIO, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = EM_REACTIVE_ENERGY_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(EM_REACTIVE_ENERGY_GPIO, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = ADE7880_ACTIVE_ENERGY_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(ADE7880_ACTIVE_ENERGY_GPIO, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = ADE7880_REACTIVE_ENERGY_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(ADE7880_REACTIVE_ENERGY_GPIO, &GPIO_InitStructure); #endif }