ZuluSCSI_platform_gpio_Pico.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2022 Rabbit Hole Computing™
  3. *
  4. * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
  5. *
  6. * https://www.gnu.org/licenses/gpl-3.0.html
  7. * ----
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version. 
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. * GNU General Public License for more details. 
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  20. **/
  21. // GPIO definitions for ZuluSCSI RP2040-based hardware
  22. #pragma once
  23. #include <hardware/gpio.h>
  24. // SCSI data input/output port.
  25. // The data bus uses external bidirectional buffer, with
  26. // direction controlled by DATA_DIR pin.
  27. #define SCSI_IO_DB0 0
  28. #define SCSI_IO_DB1 1
  29. #define SCSI_IO_DB2 2
  30. #define SCSI_IO_DB3 3
  31. #define SCSI_IO_DB4 4
  32. #define SCSI_IO_DB5 5
  33. #define SCSI_IO_DB6 6
  34. #define SCSI_IO_DB7 7
  35. #define SCSI_IO_DBP 8
  36. #define SCSI_IO_DATA_MASK 0x1FF
  37. #define SCSI_IO_SHIFT 0
  38. // Data direction control
  39. #define SCSI_DATA_DIR 9
  40. // SCSI output status lines
  41. #define SCSI_OUT_IO 22
  42. #define SCSI_OUT_CD 18
  43. #define SCSI_OUT_MSG 20
  44. #define SCSI_OUT_RST 21
  45. #define SCSI_OUT_BSY 27
  46. #define SCSI_OUT_REQ 17
  47. #define SCSI_OUT_SEL 19
  48. // SCSI input status signals
  49. #define SCSI_IN_SEL 18
  50. #define SCSI_IN_ACK 26
  51. #define SCSI_IN_ATN 28
  52. #define SCSI_IN_BSY 20
  53. #define SCSI_IN_RST 21
  54. // Status line outputs for initiator mode
  55. #define SCSI_OUT_ACK 26
  56. #define SCSI_OUT_ATN 28
  57. // Status line inputs for initiator mode
  58. #define SCSI_IN_IO 22
  59. #define SCSI_IN_CD 18
  60. #define SCSI_IN_MSG 20
  61. #define SCSI_IN_REQ 17
  62. // Status LED pins
  63. #define LED_PIN 16
  64. #ifdef ZULUSCSI_DAYNAPORT // disable LEDs, workaround to boot correctly
  65. # define LED_ON() (void)0
  66. # define LED_OFF() (void)0
  67. #else
  68. # define LED_ON() sio_hw->gpio_set = 1 << LED_PIN
  69. # define LED_OFF() sio_hw->gpio_clr = 1 << LED_PIN
  70. #endif
  71. // SD card pins in SDIO mode
  72. #define SDIO_CLK 10
  73. #define SDIO_CMD 11
  74. #define SDIO_D0 12
  75. #define SDIO_D1 13
  76. #define SDIO_D2 14
  77. #define SDIO_D3 15
  78. // SD card pins in SPI mode
  79. #define SD_SPI spi0
  80. #define SD_SPI_SCK 10
  81. #define SD_SPI_MOSI 11
  82. #define SD_SPI_MISO 12
  83. #define SD_SPI_CS 15
  84. #ifndef ENABLE_AUDIO_OUTPUT
  85. // No spare pins for I2C
  86. // IO expander I2C
  87. // #define GPIO_I2C_SDA 14
  88. // #define GPIO_I2C_SCL 15
  89. #else
  90. // IO expander I2C pins being used as SPI for audio
  91. #define AUDIO_SPI spi1
  92. #define GPIO_EXP_SPARE 14
  93. #define GPIO_EXP_AUDIO 15
  94. #endif
  95. // DIP switch pins
  96. #define HAS_DIP_SWITCHES
  97. #define DIP_INITIATOR 28
  98. #define DIP_DBGLOG 17
  99. #define DIP_TERM 22
  100. // Other pins
  101. #define SWO_PIN 16
  102. // Below are GPIO access definitions that are used from scsiPhy.cpp.
  103. // Write a single SCSI pin.
  104. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  105. #define SCSI_OUT(pin, state) \
  106. *(state ? &sio_hw->gpio_clr : &sio_hw->gpio_set) = 1 << (SCSI_OUT_ ## pin)
  107. // Read a single SCSI pin.
  108. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  109. #define SCSI_IN(pin) \
  110. ((sio_hw->gpio_in & (1 << (SCSI_IN_ ## pin))) ? 0 : 1)
  111. // Set pin directions for initiator vs. target mode
  112. #define SCSI_ENABLE_INITIATOR() \
  113. (sio_hw->gpio_oe_set = (1 << SCSI_OUT_ACK) | \
  114. (1 << SCSI_OUT_ATN)), \
  115. (sio_hw->gpio_oe_clr = (1 << SCSI_IN_IO) | \
  116. (1 << SCSI_IN_CD) | \
  117. (1 << SCSI_IN_MSG) | \
  118. (1 << SCSI_IN_REQ))
  119. // Enable driving of shared control pins
  120. #define SCSI_ENABLE_CONTROL_OUT() \
  121. (sio_hw->gpio_oe_set = (1 << SCSI_OUT_CD) | \
  122. (1 << SCSI_OUT_MSG))
  123. // Set SCSI data bus to output
  124. #define SCSI_ENABLE_DATA_OUT() \
  125. (sio_hw->gpio_clr = (1 << SCSI_DATA_DIR), \
  126. sio_hw->gpio_oe_set = SCSI_IO_DATA_MASK)
  127. // Write SCSI data bus, also sets REQ to inactive.
  128. #define SCSI_OUT_DATA(data) \
  129. gpio_put_masked(SCSI_IO_DATA_MASK | (1 << SCSI_OUT_REQ), \
  130. g_scsi_parity_lookup[(uint8_t)(data)] | (1 << SCSI_OUT_REQ)), \
  131. SCSI_ENABLE_DATA_OUT()
  132. // Release SCSI data bus and REQ signal
  133. #define SCSI_RELEASE_DATA_REQ() \
  134. (sio_hw->gpio_oe_clr = SCSI_IO_DATA_MASK, \
  135. sio_hw->gpio_set = (1 << SCSI_DATA_DIR) | (1 << SCSI_OUT_REQ))
  136. // Release all SCSI outputs
  137. #define SCSI_RELEASE_OUTPUTS() \
  138. SCSI_RELEASE_DATA_REQ(), \
  139. sio_hw->gpio_oe_clr = (1 << SCSI_OUT_CD) | \
  140. (1 << SCSI_OUT_MSG), \
  141. sio_hw->gpio_set = (1 << SCSI_OUT_IO) | \
  142. (1 << SCSI_OUT_CD) | \
  143. (1 << SCSI_OUT_MSG) | \
  144. (1 << SCSI_OUT_RST) | \
  145. (1 << SCSI_OUT_BSY) | \
  146. (1 << SCSI_OUT_REQ) | \
  147. (1 << SCSI_OUT_SEL)
  148. // Read SCSI data bus
  149. #define SCSI_IN_DATA() \
  150. (~sio_hw->gpio_in & SCSI_IO_DATA_MASK) >> SCSI_IO_SHIFT