Browse Source

nanofury: Abstract both power gpios into a nanofury_power_enable function

Luke Dashjr 11 years ago
parent
commit
6e0fb0ea1c
1 changed files with 13 additions and 7 deletions
  1. 13 7
      driver-nanofury.c

+ 13 - 7
driver-nanofury.c

@@ -144,6 +144,18 @@ void nanofury_device_off(struct mcp2210_device * const mcp)
 		mcp2210_get_gpio_input(mcp, i);
 		mcp2210_get_gpio_input(mcp, i);
 }
 }
 
 
+static
+bool nanofury_power_enable(struct mcp2210_device * const mcp, const bool poweron)
+{
+	if (!mcp2210_set_gpio_output(mcp, NANOFURY_GP_PIN_PWR_EN, poweron ? MGV_HIGH : MGV_LOW))
+		return false;
+	
+	if (!mcp2210_set_gpio_output(mcp, NANOFURY_GP_PIN_PWR_EN0, poweron ? MGV_LOW : MGV_HIGH))
+		return false;
+	
+	return true;
+}
+
 static
 static
 bool nanofury_checkport(struct mcp2210_device * const mcp, const unsigned long baud)
 bool nanofury_checkport(struct mcp2210_device * const mcp, const unsigned long baud)
 {
 {
@@ -162,13 +174,7 @@ bool nanofury_checkport(struct mcp2210_device * const mcp, const unsigned long b
 	if (!mcp2210_set_gpio_output(mcp, NANOFURY_GP_PIN_LED, MGV_HIGH))
 	if (!mcp2210_set_gpio_output(mcp, NANOFURY_GP_PIN_LED, MGV_HIGH))
 		goto fail;
 		goto fail;
 	
 	
-	// PWR_EN
-	if (!mcp2210_set_gpio_output(mcp, NANOFURY_GP_PIN_PWR_EN, MGV_HIGH))
-		goto fail;
-	
-	// PWR_EN0
-	if (!mcp2210_set_gpio_output(mcp, NANOFURY_GP_PIN_PWR_EN0, MGV_LOW))
-		goto fail;
+	nanofury_power_enable(mcp, true);
 	
 	
 	// cancel any outstanding SPI transfers
 	// cancel any outstanding SPI transfers
 	mcp2210_spi_cancel(mcp);
 	mcp2210_spi_cancel(mcp);