platform_hw_config.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2023 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. #ifdef ZULUSCSI_HARDWARE_CONFIG
  22. #include "platform_hw_config.h"
  23. #include "ZuluSCSI_platform.h"
  24. #include "ZuluSCSI_config.h"
  25. HardwareConfig g_hw_config;
  26. S2S_CFG_TYPE hw_config_selected_device()
  27. {
  28. return g_hw_config.device_type();
  29. };
  30. bool hw_config_is_active()
  31. {
  32. return g_hw_config.is_active();
  33. }
  34. void hw_config_init_gpios()
  35. {
  36. g_hw_config.init_gpios();
  37. }
  38. void hw_config_init_state()
  39. {
  40. g_hw_config.init_state();
  41. }
  42. void HardwareConfig::init_gpios()
  43. {
  44. // SCSI ID dip switch
  45. gpio_init(DIPSW_SCSI_ID_BIT_PORT, GPIO_MODE_IPD, 0, DIPSW_SCSI_ID_BIT_PINS);
  46. // Device select BCD rotary dip switch
  47. gpio_init(DIPROT_DEVICE_SEL_BIT_PORT, GPIO_MODE_IPD, 0, DIPROT_DEVICE_SEL_BIT_PINS);
  48. // Direct/Raw Mode Select
  49. gpio_init(DIPSW_DIRECT_MODE_PORT, GPIO_MODE_IPD, 0, DIPSW_DIRECT_MODE_PIN);
  50. LED_EJECT_OFF();
  51. gpio_init(LED_EJECT_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED_EJECT_PIN);
  52. }
  53. void HardwareConfig::init_state()
  54. {
  55. m_is_active = RESET == gpio_input_bit_get(DIPSW_DIRECT_MODE_PORT, DIPSW_DIRECT_MODE_PIN);
  56. m_scsi_id = (gpio_input_port_get(DIPSW_SCSI_ID_BIT_PORT) & DIPSW_SCSI_ID_BIT_PINS) >> DIPSW_SCSI_ID_BIT_SHIFT;
  57. uint8_t rotary_select = (gpio_input_port_get(DIPROT_DEVICE_SEL_BIT_PORT) & DIPROT_DEVICE_SEL_BIT_PINS) >> DIPROT_DEVICE_SEL_BIT_SHIFT;
  58. switch (rotary_select)
  59. {
  60. case 0:
  61. m_device_type = S2S_CFG_FIXED;
  62. break;
  63. case 1:
  64. m_device_type = S2S_CFG_SEQUENTIAL;
  65. break;
  66. case 2:
  67. m_device_type = S2S_CFG_OPTICAL;
  68. break;
  69. case 3:
  70. m_device_type = S2S_CFG_MO;
  71. break;
  72. default:
  73. m_device_type = S2S_CFG_FIXED;
  74. }
  75. if (m_device_type == S2S_CFG_OPTICAL)
  76. {
  77. m_blocksize = DEFAULT_BLOCKSIZE_OPTICAL;
  78. }
  79. else
  80. {
  81. m_blocksize = RAW_FALLBACK_BLOCKSIZE;
  82. }
  83. }
  84. #endif // ZULUSCSI_HARDWARE_CONFIG