ZuluSCSI_platform_gpio_Blaster.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 12
  28. #define SCSI_IO_DB1 13
  29. #define SCSI_IO_DB2 14
  30. #define SCSI_IO_DB3 15
  31. #define SCSI_IO_DB4 16
  32. #define SCSI_IO_DB5 17
  33. #define SCSI_IO_DB6 18
  34. #define SCSI_IO_DB7 19
  35. #define SCSI_IO_DBP 20
  36. #define SCSI_IO_DATA_MASK 0x1FF000
  37. #define SCSI_IO_SHIFT 12
  38. // Data direction control
  39. #define SCSI_DATA_DIR 22
  40. // SCSI output status lines
  41. #define SCSI_OUT_IO 7
  42. #define SCSI_OUT_CD 23
  43. #define SCSI_OUT_MSG 26
  44. #define SCSI_OUT_RST 47
  45. #define SCSI_OUT_BSY 45
  46. #define SCSI_OUT_REQ 21
  47. #define SCSI_OUT_SEL 44
  48. // SCSI input status signals
  49. #define SCSI_IN_SEL 23
  50. #define SCSI_IN_ACK 27
  51. #define SCSI_IN_ATN 6
  52. #define SCSI_IN_BSY 26
  53. #define SCSI_IN_RST 46
  54. // Status line outputs for initiator mode
  55. #define SCSI_OUT_ACK 27
  56. #define SCSI_OUT_ATN 6
  57. // Status line inputs for initiator mode
  58. #define SCSI_IN_IO 7
  59. #define SCSI_IN_CD 23
  60. #define SCSI_IN_MSG 26
  61. #define SCSI_IN_REQ 21
  62. // Status LED pins
  63. #define LED_PIN 33
  64. // SD card pins in SDIO mode
  65. #define SDIO_CLK 34
  66. #define SDIO_CMD 35
  67. #define SDIO_D0 36
  68. #define SDIO_D1 37
  69. #define SDIO_D2 38
  70. #define SDIO_D3 39
  71. // SD card pins in SPI mode
  72. #define SD_SPI spi0
  73. #define SD_SPI_SCK SDIO_CLK
  74. #define SD_SPI_MOSI SDIO_CMD
  75. #define SD_SPI_MISO SDIO_D0
  76. #define SD_SPI_CS SDIO_D3
  77. #ifndef ENABLE_AUDIO_OUTPUT_SPDIF
  78. // IO expander I2C
  79. #define GPIO_I2C_SDA 30
  80. #define GPIO_I2C_SCL 31
  81. #else
  82. // IO expander I2C pins being used as SPI for audio
  83. #define AUDIO_SPI spi1
  84. #define GPIO_EXP_SPARE 30
  85. #define GPIO_EXP_AUDIO 31
  86. #endif
  87. #ifdef ENABLE_AUDIO_OUTPUT_I2S
  88. #define GPIO_I2S_BCLK 8
  89. #define GPIO_I2S_WS 9
  90. #define GPIO_I2S_DOUT 10
  91. #define I2S_DMA_IRQ_NUM DMA_IRQ_2
  92. #endif
  93. // Other pins
  94. #define SWO_PIN 32
  95. // DIP switch pins
  96. #define HAS_DIP_SWITCHES
  97. #define DIP_INITIATOR SCSI_OUT_ACK
  98. #define DIP_DBGLOG SWO_PIN
  99. #define DIP_TERM SCSI_OUT_REQ
  100. // Below are GPIO access definitions that are used from scsiPhy.cpp.
  101. // Write a single SCSI pin.
  102. // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
  103. #define SCSI_OUT(pin, state) \
  104. ((SCSI_OUT_ ## pin) > 31 ? \
  105. *(state ? &sio_hw->gpio_hi_clr : &sio_hw->gpio_hi_set) = 1 << ((SCSI_OUT_ ## pin) - 32) \
  106. : \
  107. *(state ? &sio_hw->gpio_clr : &sio_hw->gpio_set) = 1 << (SCSI_OUT_ ## pin) \
  108. )
  109. // Read a single SCSI pin.
  110. // Example use: SCSI_IN(ATN), returns 1 for active low state.
  111. #define SCSI_IN(pin) \
  112. ((SCSI_IN_ ## pin) > 31 ? \
  113. ((sio_hw->gpio_hi_in & (1 << ((SCSI_IN_ ## pin) - 32))) ? 0 : 1) \
  114. : \
  115. ((sio_hw->gpio_in & (1 << (SCSI_IN_ ## pin))) ? 0 : 1) \
  116. )
  117. // Set pin directions for initiator vs. target mode
  118. #define SCSI_ENABLE_INITIATOR() \
  119. (sio_hw->gpio_oe_set = (1 << SCSI_OUT_ACK) | \
  120. (1 << SCSI_OUT_ATN)), \
  121. (sio_hw->gpio_oe_clr = (1 << SCSI_IN_IO) | \
  122. (1 << SCSI_IN_CD) | \
  123. (1 << SCSI_IN_MSG) | \
  124. (1 << SCSI_IN_REQ))
  125. // Enable driving of shared control pins
  126. #define SCSI_ENABLE_CONTROL_OUT() \
  127. (sio_hw->gpio_oe_set = (1 << SCSI_OUT_CD) | \
  128. (1 << SCSI_OUT_MSG))
  129. // Set SCSI data bus to output
  130. #define SCSI_ENABLE_DATA_OUT() \
  131. (sio_hw->gpio_clr = (1 << SCSI_DATA_DIR), \
  132. sio_hw->gpio_oe_set = SCSI_IO_DATA_MASK)
  133. // Write SCSI data bus, also sets REQ to inactive.
  134. #define SCSI_OUT_DATA(data) \
  135. gpio_put_masked(SCSI_IO_DATA_MASK | (1 << SCSI_OUT_REQ), \
  136. (g_scsi_parity_lookup[(uint8_t)(data)] << SCSI_IO_SHIFT) | (1 << SCSI_OUT_REQ)), \
  137. SCSI_ENABLE_DATA_OUT()
  138. // Release SCSI data bus and REQ signal
  139. #define SCSI_RELEASE_DATA_REQ() \
  140. (sio_hw->gpio_oe_clr = SCSI_IO_DATA_MASK, \
  141. sio_hw->gpio_set = (1 << SCSI_DATA_DIR) | (1 << SCSI_OUT_REQ))
  142. // Release all SCSI outputs
  143. #define SCSI_RELEASE_OUTPUTS() \
  144. SCSI_RELEASE_DATA_REQ(), \
  145. sio_hw->gpio_oe_clr = (1 << SCSI_OUT_CD) | \
  146. (1 << SCSI_OUT_MSG), \
  147. sio_hw->gpio_set = (1 << SCSI_OUT_IO) | \
  148. (1 << SCSI_OUT_CD) | \
  149. (1 << SCSI_OUT_MSG) | \
  150. (1 << SCSI_OUT_REQ), \
  151. sio_hw->gpio_hi_set = (1 << (SCSI_OUT_RST - 32)) | \
  152. (1 << (SCSI_OUT_BSY - 32)) | \
  153. (1 << (SCSI_OUT_SEL - 32))
  154. // Read SCSI data bus
  155. #define SCSI_IN_DATA() \
  156. (~sio_hw->gpio_in & SCSI_IO_DATA_MASK) >> SCSI_IO_SHIFT