Просмотр исходного кода

add gpio command for pcba test

Signed-off-by: FuangCao <cavan.cao@foxmail.com>
FuangCao 4 лет назад
Родитель
Сommit
7bfee8c6d1
1 измененных файлов с 53 добавлено и 0 удалено
  1. 53 0
      Application/app/pcba_test.c

+ 53 - 0
Application/app/pcba_test.c

@@ -10,6 +10,10 @@ static void pcba_test_timer_handler(shark_timer_t *timer);
 static shark_timer_t pcba_test_timer = {.handler = pcba_test_timer_handler};
 static shark_timer_t pcba_test_timer = {.handler = pcba_test_timer_handler};
 static int pcba_test_item = -1;
 static int pcba_test_item = -1;
 static int powerdown_flags = 0;
 static int powerdown_flags = 0;
+
+const rcu_periph_enum shark_gpio_rcus[] = { RCU_GPIOA, RCU_GPIOB, RCU_GPIOC, RCU_GPIOD, RCU_GPIOF, RCU_GPIOF };
+const u32 shark_gpio_ports[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOF, GPIOF };
+
 static void pcba_test_timer_handler(shark_timer_t *timer) {
 static void pcba_test_timer_handler(shark_timer_t *timer) {
 	if (pcba_test_item == 1) {
 	if (pcba_test_item == 1) {
 		UART0_IR_EN(1);
 		UART0_IR_EN(1);
@@ -184,7 +188,56 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 		}
 		}
 	}else if (cmd == 0x21) {
 	}else if (cmd == 0x21) {
 		response[resp_len ++] = powerdown_flags;
 		response[resp_len ++] = powerdown_flags;
+	} else if (cmd == 0xE1 && len > 4) { // gpio control
+		u8 index = (data[4] >> 4) & 0x0F;
+		u32 pin = 1 << (data[4] & 0x0F);
+		u32 port = shark_gpio_ports[index];
+		rcu_periph_enum rcu = shark_gpio_rcus[index];
+
+		rcu_periph_clock_enable(rcu);
+		response[resp_len++] = data[4];
+
+		if (len < 6 || data[5] == 0x00) { // input get
+			response[resp_len++] = gpio_input_bit_get(port, pin);
+		} else if (data[5] == 0x01) { // output set and get
+			if (len > 6) {
+				if (data[6] != 0x00) {
+					gpio_bit_set(port, pin);
+				} else {
+					gpio_bit_reset(port, pin);
+				}
+			}
+
+			response[resp_len++] = gpio_output_bit_get(port, pin);
+		} else if (data[5] == 0x02) { // input get
+			gpio_mode_input(port, GPIO_PUPD_NONE, pin);
+			response[resp_len++] = gpio_input_bit_get(port, pin);
+		} else if (data[5] == 0x03 && len > 6) { // output set and get
+			if (data[6] != 0x00) {
+				gpio_bit_set(port, pin);
+			} else {
+				gpio_bit_reset(port, pin);
+			}
+
+			gpio_mode_output(port, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
+			response[resp_len++] = gpio_output_bit_get(port, pin);
+		} else if (data[5] == 0x04 && len > 6) { // input get
+			gpio_mode_input(port, data[6], pin);
+			response[resp_len++] = gpio_input_bit_get(port, pin);
+		} else if (data[5] == 0x05 && len > 8) { // output set
+			if (data[6] != 0x00) {
+				gpio_bit_set(port, pin);
+			} else {
+				gpio_bit_reset(port, pin);
+			}
+
+			gpio_mode_output(port, data[7], data[8], GPIO_OSPEED_50MHZ, pin);
+			response[resp_len++] = gpio_output_bit_get(port, pin);
+		} else {
+			response[resp_len++] = 0xFF;
+		}
 	}
 	}
+
 	response[2] = resp_len - 2;
 	response[2] = resp_len - 2;
 
 
 	return resp_len;
 	return resp_len;