Browse Source

esp32: move pin definitions to a header file

It is good to have them in a single place...
H. Peter Anvin 1 year ago
parent
commit
30a38c6163
6 changed files with 49 additions and 30 deletions
  1. 1 6
      esp32/max80/fpgajtag.c
  2. 1 6
      esp32/max80/fpgasvc.c
  3. 2 3
      esp32/max80/led.c
  4. 1 3
      esp32/max80/max80.ino
  5. 34 0
      esp32/max80/pins.h
  6. 10 12
      esp32/max80/spiflash.c

+ 1 - 6
esp32/max80/fpgajtag.c

@@ -1,6 +1,7 @@
 #define MODULE "fpga"
 
 #include "common.h"
+#include "pins.h"
 #include "jtag.h"
 #include "fpga.h"
 #include "spz.h"
@@ -52,12 +53,6 @@ enum JTAG_IR {
 #define JTAG_FPGA_MS	((JTAG_FPGA_HZ+999)/1000)
 #define JTAG_FPGA_US	((JTAG_FPGA_HZ+999999)/1000000)
 
-#define PIN_FPGA_TDI	16
-#define PIN_FPGA_TDO	17
-#define PIN_FPGA_TMS	14
-#define PIN_FPGA_TCK	18
-#define PIN_FPGA_nCE	26
-
 static const struct jtag_config jtag_config_fpga = {
     .hz      = JTAG_FPGA_HZ,
     .pin_tdi = PIN_FPGA_TDI,

+ 1 - 6
esp32/max80/fpgasvc.c

@@ -1,5 +1,6 @@
 #include "common.h"
 #include "config.h"
+#include "pins.h"
 #include "fpga.h"
 #include "esplink.h"
 #include "xmalloc.h"
@@ -8,12 +9,6 @@
 #include <driver/spi_common.h>
 #include <driver/spi_master.h>
 
-#define PIN_FPGA_INT	 9
-#define PIN_FPGA_CS	10
-#define PIN_FPGA_IO0	11
-#define PIN_FPGA_CLK	12
-#define PIN_FPGA_IO1	13
-
 #define FPGA_SPI_HOST	FSPI	/* SPI2 */
 
 #define FPGA_PRIORITY	10

+ 2 - 3
esp32/max80/led.c

@@ -1,4 +1,5 @@
 #include "common.h"
+#include "pins.h"
 #include "led.h"
 
 #include <driver/ledc.h>
@@ -8,8 +9,6 @@
  * seems to insist on using a high frequency clock source...
  */
 
-#define LED_PIN_BASE 2
-
 void led_set(int led, enum led_mode mode)
 {
     static const struct {
@@ -29,7 +28,7 @@ void led_set(int led, enum led_mode mode)
 	.intr_type             = LEDC_INTR_DISABLE,
 	.channel               = led,
 	.timer_sel             = led,
-	.gpio_num              = led + LED_PIN_BASE,
+	.gpio_num              = led + PIN_LED_0,
 	.duty                  = led_modes[mode].duty
     };
     ledc_timer_config_t timer_config = {

+ 1 - 3
esp32/max80/max80.ino

@@ -4,6 +4,7 @@
 
 #include "common.h"
 
+#include "pins.h"
 #include "fpga.h"
 #include "wifi.h"
 #include "config.h"
@@ -20,9 +21,6 @@
 #include <HardwareSerial.h>
 #include <core_version.h>
 
-#define PIN_USB_PWR_EN		7
-#define PIN_USB_PWR_SINK	8
-
 volatile bool do_log_config_status;
 
 uint8_t efuse_default_mac[6];

+ 34 - 0
esp32/max80/pins.h

@@ -0,0 +1,34 @@
+/*
+ * pins.h
+ *
+ * Pin configuration
+ */
+
+#pragma once
+
+#define PIN_FPGA_TDI		16
+#define PIN_FPGA_TDO		17
+#define PIN_FPGA_TMS		14
+#define PIN_FPGA_TCK		18
+#define PIN_FPGA_nCE		26
+
+#define PIN_FPGA_INT		 9
+#define PIN_FPGA_CS		10
+#define PIN_FPGA_CLK		12
+#define PIN_FPGA_IO0		11
+#define PIN_FPGA_IO1		13
+
+#define PIN_LED_0		 2
+#define PIN_LED_1		 3
+#define PIN_LED_2		 4
+
+#define PIN_USB_PWR_EN		 7
+#define PIN_USB_PWR_SINK	 8
+
+/* These are applicable only for the bypass FPGA image */
+#define PIN_BYPASS_READY	 9
+#define PIN_BYPASS_BOARD_ID	 1
+#define PIN_BYPASS_CS		10
+#define PIN_BYPASS_MOSI		12
+#define PIN_BYPASS_MISO		13
+#define PIN_BYPASS_CLK		11

+ 10 - 12
esp32/max80/spiflash.c

@@ -2,6 +2,7 @@
 #define DEBUG 1
 
 #include "common.h"
+#include "pins.h"
 #include "spiflash.h"
 #include "spz.h"
 #include "fw.h"
@@ -14,10 +15,10 @@
 
 static const struct jtag_config jtag_config_spiflash = {
     .hz      = JTAG_SPIFLASH_HZ,
-    .pin_tms = 10,		/* CS# */
-    .pin_tdi = 12,		/* MOSI */
-    .pin_tdo = 13,		/* MISO */
-    .pin_tck = 11,		/* SCLK */
+    .pin_tms = PIN_BYPASS_CS,	/* CS# */
+    .pin_tdi = PIN_BYPASS_MOSI,	/* MOSI */
+    .pin_tdo = PIN_BYPASS_MISO,	/* MISO */
+    .pin_tck = PIN_BYPASS_CLK,	/* SCLK */
     .be      = true		/* Bit order within bytes */
 };
 
@@ -334,9 +335,6 @@ static void spiflash_show_status(void)
 	spiflash_read_status(ROM_READ_SR3));
 }
 
-#define PIN_FPGA_READY		9
-#define PIN_FPGA_BOARD_ID	1
-
 /* Set data and data_len if the data to be written is not from the spz */
 int spiflash_write_spz(spz_stream *spz,
 		       const void *data, unsigned int data_left)
@@ -351,19 +349,19 @@ int spiflash_write_spz(spz_stream *spz,
     if (!data_left || spz->err)
 	return spz->err;
 
-    pinMode(PIN_FPGA_READY,    INPUT);
-    pinMode(PIN_FPGA_BOARD_ID, INPUT);
+    pinMode(PIN_BYPASS_READY,    INPUT);
+    pinMode(PIN_BYPASS_BOARD_ID, INPUT);
 
-    if (digitalRead(PIN_FPGA_READY) == LOW) {
+    if (digitalRead(PIN_BYPASS_READY) == LOW) {
 	MSG("waiting for FPGA bypass to be ready..");
-	while (digitalRead(PIN_FPGA_READY) != LOW) {
+	while (digitalRead(PIN_BYPASS_READY) != LOW) {
 	    CMSG(".");
 	    yield();
 	}
 	CMSG("\n");
     }
     MSG("FPGA bypass ready, board version v%c.\n",
-	digitalRead(PIN_FPGA_BOARD_ID) ? '1' : '2');
+	digitalRead(PIN_BYPASS_BOARD_ID) ? '1' : '2');
 
     jtag_enable(&jtag_config_spiflash);