platform_hw_config.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #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. scsi_device_settings_t &cfg_dev = *g_scsi_settings.getDevice(m_scsi_id);
  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. cfg_dev.deviceType = S2S_CFG_FIXED;
  62. break;
  63. case 1:
  64. cfg_dev.deviceType = S2S_CFG_OPTICAL;
  65. break;
  66. case 2:
  67. cfg_dev.deviceType = S2S_CFG_FLOPPY_14MB;
  68. break;
  69. case 3:
  70. cfg_dev.deviceType = S2S_CFG_REMOVABLE;
  71. break;
  72. case 4:
  73. cfg_dev.deviceType = S2S_CFG_MO;
  74. break;
  75. case 5:
  76. m_device_preset = DEV_PRESET_ST32430N;
  77. cfg_dev.deviceType = S2S_CFG_FIXED;
  78. break;
  79. case 6:
  80. cfg_dev.deviceType = S2S_CFG_SEQUENTIAL;
  81. break;
  82. default:
  83. cfg_dev.deviceType = S2S_CFG_FIXED;
  84. }
  85. if (cfg_dev.deviceType == S2S_CFG_OPTICAL)
  86. {
  87. m_blocksize = DEFAULT_BLOCKSIZE_OPTICAL;
  88. }
  89. else
  90. {
  91. m_blocksize = RAW_FALLBACK_BLOCKSIZE;
  92. }
  93. }
  94. }
  95. #endif // ZULUSCSI_HARDWARE_CONFIG