 // Write a 32-bit word to the flash chips
 void flash_write(uint32_t A, uint32_t D) {
   // Write a 32-bit word to the flash, leaving allowing_arm_access == 0
-  digitalWrite(CPLD_SS_PIN, LOW);
+  CPLD_SS_CLEAR();
   spi_transfer((uint8_t)(0x00 | ((A & 0x3f0000L) >> 16L)));  // allowing_arm_access, rnw, A[21:16]
   spi_transfer((uint8_t)((A & 0xff00L) >> 8L));  // A[15:8]
   spi_transfer((uint8_t)(A & 0xffL));  // A[7:0]

// Read a 32-bit word from the flash chips
uint32_t flash_read(uint32_t A) {
  // Read a 32-bit word from the flash, leaving allowing_arm_access == 0
  digitalWrite(CPLD_SS_PIN, LOW);
  spi_transfer((uint8_t)(0x40 | ((A & 0x3f0000) >> 16)));  // allowing_arm_access, rnw, A[21:16]
  spi_transfer((uint8_t)((A & 0xff00) >> 8));  // A[15:8]
  spi_transfer((uint8_t)(A & 0xff));  // A[7:0]

#define CPLD_SCK_PIN 23
// PA10 / SERCOM2.2 (SERCOM-ALT) - D34 - cpld_SS
#define CPLD_SS_PIN 34
#define CPLD_SS_PORT (PORT->Group[0])
#define CPLD_SS_PORT_BIT 10
#define CPLD_SS_SET() do { CPLD_SS_PORT.OUTSET.reg = 1 << CPLD_SS_PORT_BIT; } while (0)
#define CPLD_SS_CLEAR() do { CPLD_SS_PORT.OUTCLR.reg = 1 << CPLD_SS_PORT_BIT; } while (0)
// #define CPLD_SS_CLEAR() digitalWrite(CPLD_SS_PIN, LOW)
// #define CPLD_SS_SET() digitalWrite(CPLD_SS_PIN, HIGH)
// PA11 / SERCOM2.3 (SERCOM-ALT) - D22 - cpld_MISO
#define CPLD_MISO_PIN 22

