| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #ifndef _GPIO_H__
- #define _GPIO_H__
- #include "gd32f3x0.h"
- #include "gd32f3x0_libopt.h"
- #include "bsp/shark_bsp.h"
- void gpio_init(void);
- /*switch for temperature sensers */
- #define TEMP_OPEN(x) gpio_bit_write(GPIOF,GPIO_PIN_1,(bit_status)(x))
- /*switch for small current aux */
- #define AUX_VOL_OPEN(x) gpio_bit_write(GPIOB,GPIO_PIN_2,(bit_status)(x))
- #define AUX_VOL_IS_OPEN() (!!gpio_output_bit_get(GPIOB, GPIO_PIN_2))
- /*aux pwr is locked */
- #define IS_AUX_VOL_LOCKED() (!gpio_input_bit_get(GPIOB, GPIO_PIN_11))
- /*switch for larger current DCDC */
- #define DCDC_VOL_OPEN(x) gpio_bit_write(GPIOA,GPIO_PIN_11,(bit_status)(x))
- /* DCDC output power good detect */
- #define IS_DCDC_POWER_GOOD() (gpio_input_bit_get(GPIOF, GPIO_PIN_7) == RESET)
- /*detect for charger in/out */
- #define IS_CHARGER_IN() (!gpio_input_bit_get(GPIOB,GPIO_PIN_10))
- /*spi chip select for ml5238*/
- #define ml5238_cs(x) gpio_bit_write(GPIOA, GPIO_PIN_15, (bit_status)x)
- #if (CONFIG_BOARD_TYPE==SHARK_BOARD_SP700)
- /*power switch for cs110, low active */
- #define CS1180_PWR_ENABLE(x) gpio_bit_write(GPIOB,GPIO_PIN_12, x==1?RESET:SET)
- /*detect for CS1180 is ready */
- #define IS_CS1180_NOT_READY() !!gpio_input_bit_get(GPIOA, GPIO_PIN_0)
- /*spi chip select for cs1180*/
- #define cs1180_cs(x) gpio_bit_write(GPIOA, GPIO_PIN_9, (bit_status)x)
- /*switch for IR uart0 */
- #define UART0_IR_EN(x) gpio_bit_write(GPIOC,GPIO_PIN_14,(bit_status)(x))
- /*switch for IR uart1 */
- #define UART1_IR_EN(x) gpio_bit_write(GPIOF,GPIO_PIN_0,(bit_status)(x))
- /*detect hall 1&2 */
- #define IS_HALL1_DETECTED() (!gpio_input_bit_get(GPIOC, GPIO_PIN_15))
- #define IS_HALL2_DETECTED() (!gpio_input_bit_get(GPIOC, GPIO_PIN_13))
- #define DIANOCTIC_LED(s) gpio_bit_write(GPIOF,GPIO_PIN_6,(s == 0)?SET:RESET)
- #define LED0_ON(x) {}
- #define LED1_ON(x) {}
- #define LED2_ON(x) {}
- #define LED3_ON(x) {}
- #define LED4_ON(x) {}
- #elif (CONFIG_BOARD_TYPE==SHARK_BOARD_SP600)
- /*power switch for cs110, low active */
- #define CS1180_PWR_ENABLE(x) gpio_bit_write(GPIOC,GPIO_PIN_15, x==1?RESET:SET)
- /*detect for CS1180 is ready */
- #define IS_CS1180_NOT_READY() (!!gpio_input_bit_get(GPIOB, GPIO_PIN_12))
- /*spi chip select for cs1180*/
- #define cs1180_cs(x) gpio_bit_write(GPIOA, GPIO_PIN_8, (bit_status)x)
- /*rs485 power switch */
- #define RS485_PWR_ENABLE(x) gpio_bit_write(GPIOC, GPIO_PIN_14, x==1?SET:RESET)
- /* rs485¼ì²âÄ£Äâhall1, MUST 485 power(DCDC) on && GPIOF0 is detect */
- #define IS_HALL2_DETECTED() ((gpio_input_bit_get(GPIOF, GPIO_PIN_0)== RESET) && gpio_output_bit_get(GPIOA ,GPIO_PIN_11))
- /* other hall2 is always 0 */
- #define IS_HALL1_DETECTED() (0)
- #define LED0_ON(x) gpio_bit_write(GPIOA,GPIO_PIN_2, x==1?RESET:SET)
- #define LED1_ON(x) gpio_bit_write(GPIOA,GPIO_PIN_3, x==1?RESET:SET)
- #define LED2_ON(x) gpio_bit_write(GPIOF,GPIO_PIN_6, x==1?RESET:SET)
- #define LED3_ON(x) gpio_bit_write(GPIOA,GPIO_PIN_10, x==1?RESET:SET)
- #define LED4_ON(x) gpio_bit_write(GPIOA,GPIO_PIN_9, x==1?RESET:SET)
- #define UART0_IR_EN(x) RS485_PWR_ENABLE(x)
- #define UART1_IR_EN(x) {}
- #define DIANOCTIC_LED(s) {}
- #endif
- #define LED_ALL_ON(x) {LED0_ON(x); LED1_ON(x); LED2_ON(x); LED3_ON(x); LED4_ON(x);}
- static __inline__ void gpio_mode_analog_input(uint32_t gpio_periph, uint32_t pin){
- gpio_mode_set(gpio_periph, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, pin);
- }
- static __inline__ void gpio_mode_input(uint32_t gpio_periph, uint32_t pull_up_down, uint32_t pin){
- gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, pull_up_down, pin);
- }
- static __inline__ void gpio_mode_output(uint32_t gpio_periph, uint32_t pull_up_down, uint8_t otype, uint32_t speed, uint32_t pin){
- gpio_mode_set(gpio_periph, GPIO_MODE_OUTPUT, pull_up_down, pin);
- gpio_output_options_set(gpio_periph, otype, speed, pin);
- }
- static __inline__ void gpio_mode_af(uint32_t gpio_periph, uint32_t pull_up_down, uint32_t pin){
- gpio_mode_set(gpio_periph, GPIO_MODE_AF, pull_up_down, pin);
- }
- void enable_mcu_power(void);
- void charger_detect_irq_enable(int enable);
- void ml5238_irq_enable(int enable);
- void hall_1_detect_irq_enable(int enable);
- void hall_2_detect_irq_enable(int enable);
- void small_current_short_irq_enable(int enable);
- void dcdc_pwr_detect_irq_enable(int enable);
- void enable_gpio_key_irq(int enable);
- #endif /* _GPIO_H__ */
|