platform_hw_config.cpp 3.0 KB

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