Description: update firmware source working around quilt
Author: A. Maitland Bottoms <bottoms@debian.org>

diff -p1 -u -r firmware/common/hackrf_core.c firmware/common/hackrf_core.c
--- a/firmware/common/hackrf_core.c	2016-04-26 11:03:24.405330926 -0400
+++ b/firmware/common/hackrf_core.c	2016-01-22 15:29:16.052653337 -0500
@@ -829,19 +829,17 @@ void pin_setup(void) {
 	/* Configure all GPIO as Input (safe state) */
-	GPIO0_DIR = 0;
-	GPIO1_DIR = 0;
-	GPIO2_DIR = 0;
-	GPIO3_DIR = 0;
-	GPIO4_DIR = 0;
-	GPIO5_DIR = 0;
-	GPIO6_DIR = 0;
-	GPIO7_DIR = 0;
+	gpio_init();
 
-	/* Configure GPIO2[1/2/8] (P4_1/2 P6_12) as output. */
-	GPIO2_DIR |= (PIN_LED1 | PIN_LED2 | PIN_LED3);
+	gpio_output(&gpio_led[0]);
+	gpio_output(&gpio_led[1]);
+	gpio_output(&gpio_led[2]);
 
-	/* GPIO3[6] on P6_10  as output. */
-	GPIO3_DIR |= PIN_EN1V8;
+	gpio_output(&gpio_1v8_enable);
 
-	spi_bus_start(&spi_bus_ssp1, &ssp_config_max2837);
-	spi_bus_start(&spi_bus_rffc5071, NULL);
+#ifdef HACKRF_ONE
+	/* Configure RF power supply (VAA) switch control signal as output */
+	gpio_output(&gpio_vaa_disable);
+
+	/* Safe state: start with VAA turned off: */
+	disable_rf_power();
+#endif
 
@@ -850,3 +848,6 @@ void pin_setup(void) {
 
-	rf_path_pin_setup();
+	spi_bus_start(&spi_bus_ssp1, &ssp_config_max2837);
+	spi_bus_start(&spi_bus_rffc5071, &rffc5071_spi_config);
+
+	rf_path_pin_setup(&rf_path);
 	
@@ -855,3 +856,3 @@ void pin_setup(void) {
 
-	sgpio_configure_pin_functions();
+	sgpio_configure_pin_functions(&sgpio_config);
 }
@@ -859,3 +860,3 @@ void pin_setup(void) {
 void enable_1v8_power(void) {
-	gpio_set(PORT_EN1V8, PIN_EN1V8);
+	gpio_set(&gpio_1v8_enable);
 }
@@ -863,3 +864,3 @@ void enable_1v8_power(void) {
 void disable_1v8_power(void) {
-	gpio_clear(PORT_EN1V8, PIN_EN1V8);
+	gpio_clear(&gpio_1v8_enable);
 }
@@ -868,3 +869,3 @@ void disable_1v8_power(void) {
 void enable_rf_power(void) {
-	gpio_clear(PORT_NO_VAA_ENABLE, PIN_NO_VAA_ENABLE);
+	gpio_clear(&gpio_vaa_disable);
 }
@@ -872,4 +873,16 @@ void enable_rf_power(void) {
 void disable_rf_power(void) {
-	gpio_set(PORT_NO_VAA_ENABLE, PIN_NO_VAA_ENABLE);
+	gpio_set(&gpio_vaa_disable);
 }
 #endif
+
+void led_on(const led_t led) {
+	gpio_set(&gpio_led[led]);
+}
+
+void led_off(const led_t led) {
+	gpio_clear(&gpio_led[led]);
+}
+
+void led_toggle(const led_t led) {
+	gpio_toggle(&gpio_led[led]);
+}
diff -p1 -u -r firmware/common/hackrf_core.h firmware/common/hackrf_core.h
--- a/firmware/common/hackrf_core.h	2016-04-26 11:01:46.853330432 -0400
+++ b/firmware/common/hackrf_core.h	2016-01-22 15:29:16.052653337 -0500
@@ -35,3 +35,2 @@ extern "C"
 #include "si5351c.h"
-
 #include "spi_ssp.h"
@@ -230,9 +229,15 @@ void delay(uint32_t duration);
 
-extern const ssp1_config_t ssp1_config_max2837;
-extern const ssp1_config_t ssp1_config_max5864;
+/* TODO: Hide these configurations */
+extern si5351c_driver_t clock_gen;
+extern const ssp_config_t ssp_config_w25q80bv;
+extern const ssp_config_t ssp_config_max2837;
+extern const ssp_config_t ssp_config_max5864;
 
 extern max2837_driver_t max2837;
+extern max5864_driver_t max5864;
 extern rffc5071_driver_t rffc5072;
-
-extern si5351c_driver_t clock_gen;
+extern w25q80bv_driver_t spi_flash;
+extern sgpio_config_t sgpio_config;
+extern rf_path_t rf_path;
+extern jtag_t jtag_cpld;
 
@@ -241,3 +246,2 @@ void cpu_clock_pll1_low_speed(void);
 void cpu_clock_pll1_max_speed(void);
-void ssp1_init(void);
 void ssp1_set_mode_max2837(void);
diff -p1 -u -r firmware/common/rf_path.c firmware/common/rf_path.c
--- a/firmware/common/rf_path.c	2016-04-26 11:03:41.885331014 -0400
+++ b/firmware/common/rf_path.c	2016-01-22 15:29:16.052653337 -0500
@@ -262,3 +262,3 @@ void rf_path_set_direction(rf_path_t* co
 		max2837_rx(&max2837);
-		sgpio_configure(SGPIO_DIRECTION_RX);
+		sgpio_configure(&sgpio_config, SGPIO_DIRECTION_RX);
 		break;
@@ -268,3 +268,3 @@ void rf_path_set_direction(rf_path_t* co
 #ifdef HACKRF_ONE
-		rf_path_set_antenna(0);
+		rf_path_set_antenna(rf_path, 0);
 #endif
@@ -272,3 +272,3 @@ void rf_path_set_direction(rf_path_t* co
 		/* Set RF path to receive direction when "off" */
-		switchctrl &= ~SWITCHCTRL_TX;
+		rf_path->switchctrl &= ~SWITCHCTRL_TX;
 		rffc5071_disable(&rffc5072);
@@ -278,3 +278,3 @@ void rf_path_set_direction(rf_path_t* co
 		max2837_set_mode(&max2837, MAX2837_MODE_STANDBY);
-		sgpio_configure(SGPIO_DIRECTION_RX);
+		sgpio_configure(&sgpio_config, SGPIO_DIRECTION_RX);
 		break;
@@ -282,6 +282,6 @@ void rf_path_set_direction(rf_path_t* co
 
-	switchctrl_set(switchctrl);
+	switchctrl_set(rf_path, rf_path->switchctrl);
 }
 
-void rf_path_set_filter(const rf_path_filter_t filter) {
+void rf_path_set_filter(rf_path_t* const rf_path, const rf_path_filter_t filter) {
 	switch(filter) {
@@ -289,3 +289,3 @@ void rf_path_set_filter(const rf_path_fi
 	case RF_PATH_FILTER_BYPASS:
-		switchctrl |= SWITCHCTRL_MIX_BYPASS;
+		rf_path->switchctrl |= SWITCHCTRL_MIX_BYPASS;
 		rffc5071_disable(&rffc5072);
@@ -294,3 +294,3 @@ void rf_path_set_filter(const rf_path_fi
 	case RF_PATH_FILTER_LOW_PASS:
-		switchctrl &= ~(SWITCHCTRL_HP | SWITCHCTRL_MIX_BYPASS);
+		rf_path->switchctrl &= ~(SWITCHCTRL_HP | SWITCHCTRL_MIX_BYPASS);
 		rffc5071_enable(&rffc5072);
@@ -299,4 +299,4 @@ void rf_path_set_filter(const rf_path_fi
 	case RF_PATH_FILTER_HIGH_PASS:
-		switchctrl &= ~SWITCHCTRL_MIX_BYPASS;
-		switchctrl |= SWITCHCTRL_HP;
+		rf_path->switchctrl &= ~SWITCHCTRL_MIX_BYPASS;
+		rf_path->switchctrl |= SWITCHCTRL_HP;
 		rffc5071_enable(&rffc5072);
@@ -305,15 +305,15 @@ void rf_path_set_filter(const rf_path_fi
 
-	switchctrl_set(switchctrl);
+	switchctrl_set(rf_path, rf_path->switchctrl);
 }
 
-void rf_path_set_lna(const uint_fast8_t enable) {
+void rf_path_set_lna(rf_path_t* const rf_path, const uint_fast8_t enable) {
 	if( enable ) {
-		if( switchctrl & SWITCHCTRL_TX ) {
+		if( rf_path->switchctrl & SWITCHCTRL_TX ) {
 			/* AMP_BYPASS=0, NO_RX_AMP_PWR=1, NO_TX_AMP_PWR=0 */
-			switchctrl |= SWITCHCTRL_NO_RX_AMP_PWR;
-			switchctrl &= ~(SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_TX_AMP_PWR);
+			rf_path->switchctrl |= SWITCHCTRL_NO_RX_AMP_PWR;
+			rf_path->switchctrl &= ~(SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_TX_AMP_PWR);
 		} else {
 			/* AMP_BYPASS=0, NO_RX_AMP_PWR=0, NO_TX_AMP_PWR=1 */
-			switchctrl |= SWITCHCTRL_NO_TX_AMP_PWR;
-			switchctrl &= ~(SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_RX_AMP_PWR);
+			rf_path->switchctrl |= SWITCHCTRL_NO_TX_AMP_PWR;
+			rf_path->switchctrl &= ~(SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_RX_AMP_PWR);
 		}
@@ -321,6 +321,6 @@ void rf_path_set_lna(const uint_fast8_t
 		/* AMP_BYPASS=1, NO_RX_AMP_PWR=1, NO_TX_AMP_PWR=1 */
-		switchctrl |= SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_TX_AMP_PWR | SWITCHCTRL_NO_RX_AMP_PWR;
+		rf_path->switchctrl |= SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_TX_AMP_PWR | SWITCHCTRL_NO_RX_AMP_PWR;
 	}
 	
-	switchctrl_set(switchctrl);
+	switchctrl_set(rf_path, rf_path->switchctrl);
 }
@@ -328,10 +328,10 @@ void rf_path_set_lna(const uint_fast8_t
 /* antenna port power control */
-void rf_path_set_antenna(const uint_fast8_t enable) {
+void rf_path_set_antenna(rf_path_t* const rf_path, const uint_fast8_t enable) {
 	if (enable) {
-		switchctrl |= SWITCHCTRL_ANT_PWR;
+		rf_path->switchctrl |= SWITCHCTRL_ANT_PWR;
 	} else {
-		switchctrl &= ~(SWITCHCTRL_ANT_PWR);
+		rf_path->switchctrl &= ~(SWITCHCTRL_ANT_PWR);
 	}
 
-	switchctrl_set(switchctrl);
+	switchctrl_set(rf_path, rf_path->switchctrl);
 }
diff -p1 -u -r firmware/common/w25q80bv.c firmware/common/w25q80bv.c
--- a/firmware/common/w25q80bv.c	2016-04-26 11:04:01.333331113 -0400
+++ b/firmware/common/w25q80bv.c	2016-01-22 15:29:16.052653337 -0500
@@ -36,2 +36,4 @@
 
+#define W25Q80BV_READ_DATA    0x03
+#define W25Q80BV_FAST_READ    0x0b
 #define W25Q80BV_WRITE_ENABLE 0x06
diff -p1 -u -r firmware/common/w25q80bv.h firmware/common/w25q80bv.h
--- a/firmware/common/w25q80bv.h	2016-04-26 11:03:33.025330969 -0400
+++ b/firmware/common/w25q80bv.h	2016-01-22 15:29:16.052653337 -0500
@@ -57,2 +57,3 @@ uint8_t w25q80bv_get_device_id(w25q80bv_
 void w25q80bv_get_unique_id(w25q80bv_driver_t* const drv, w25q80bv_unique_id_t* unique_id);
+void w25q80bv_read(w25q80bv_driver_t* const drv, uint32_t addr, uint32_t len, uint8_t* const data);
 
diff -p1 -u -r firmware/hackrf-common.cmake firmware/hackrf-common.cmake
--- a/firmware/hackrf-common.cmake	2016-04-26 11:03:28.605330947 -0400
+++ b/firmware/hackrf-common.cmake	2016-01-22 15:29:16.052653337 -0500
@@ -143,2 +143,4 @@ macro(DeclareTargets)
 		${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071.c
+		${PATH_HACKRF_FIRMWARE_COMMON}/i2c_bus.c
+		${PATH_HACKRF_FIRMWARE_COMMON}/i2c_lpc.c
 		${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071_spi.c
diff -p1 -u -r firmware/hackrf_usb/usb_api_spiflash.c firmware/hackrf_usb/usb_api_spiflash.c
--- a/firmware/hackrf_usb/usb_api_spiflash.c	2016-04-26 11:03:41.933331014 -0400
+++ b/firmware/hackrf_usb/usb_api_spiflash.c	2016-01-22 15:29:16.052653337 -0500
@@ -38,4 +38,2 @@ usb_request_status_t usb_vendor_request_
 {
-	//FIXME This should refuse to run if executing from SPI flash.
-
 	if (stage == USB_TRANSFER_STAGE_SETUP) {
@@ -46,3 +44,2 @@ usb_request_status_t usb_vendor_request_
 		usb_transfer_schedule_ack(endpoint->in);
-		//FIXME probably should undo w25q80bv_setup()
 	}
diff -p1 -u -r firmware/sgpio-rx/sgpio-rx.c firmware/sgpio-rx/sgpio-rx.c
--- a/firmware/sgpio-rx/sgpio-rx.c	2016-04-26 11:03:56.493331088 -0400
+++ b/firmware/sgpio-rx/sgpio-rx.c	2016-01-22 15:29:16.052653337 -0500
@@ -28,5 +28,2 @@
 void tx_test() {
-	sgpio_set_slice_mode(&sgpio_config, false);
-	sgpio_configure(&sgpio_config, TRANSCEIVER_MODE_TX);
-	
 	// LSB goes out first, samples are 0x<Q1><I1><Q0><I0>
@@ -40,2 +37,3 @@ void tx_test() {
 
+    rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_TX);
 	sgpio_cpld_stream_enable(&sgpio_config);
@@ -50,5 +48,2 @@ void tx_test() {
 void rx_test() {
-	sgpio_set_slice_mode(&sgpio_config, false);
-	sgpio_configure(&sgpio_config, TRANSCEIVER_MODE_RX);
-
     volatile uint32_t buffer[4096];
@@ -58,2 +53,3 @@ void rx_test() {
 
+    rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_RX);
     sgpio_cpld_stream_enable(&sgpio_config);
@@ -73,3 +69,3 @@ void rx_test() {
 		/* illuminate LED3 only when magsq exceeds threshold */
-		if (magsq > 0x3c00)
+		if (magsq > 0x1000)
 			led_on(LED3);
@@ -93,3 +89,2 @@ int main(void) {
     rf_path_init(&rf_path);
-    rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_RX);
 
