platform_hw_config.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. HardwareConfig g_hw_config;
  27. S2S_CFG_TYPE hw_config_selected_device()
  28. {
  29. return g_hw_config.device_type();
  30. };
  31. bool hw_config_is_active()
  32. {
  33. return g_hw_config.is_active();
  34. }
  35. void hw_config_init_gpios()
  36. {
  37. g_hw_config.init_gpios();
  38. }
  39. void hw_config_init_state(bool is_active)
  40. {
  41. g_hw_config.init_state(is_active);
  42. }
  43. void HardwareConfig::init_gpios()
  44. {
  45. // SCSI ID dip switch
  46. gpio_init(DIPSW_SCSI_ID_BIT_PORT, GPIO_MODE_IPD, 0, DIPSW_SCSI_ID_BIT_PINS);
  47. // Device select BCD rotary dip switch
  48. gpio_init(DIPROT_DEVICE_SEL_BIT_PORT, GPIO_MODE_IPD, 0, DIPROT_DEVICE_SEL_BIT_PINS);
  49. LED_EJECT_OFF();
  50. gpio_init(LED_EJECT_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED_EJECT_PIN);
  51. }
  52. void HardwareConfig::init_state(bool is_active)
  53. {
  54. m_is_active = is_active;
  55. m_scsi_id = (gpio_input_port_get(DIPSW_SCSI_ID_BIT_PORT) & DIPSW_SCSI_ID_BIT_PINS) >> DIPSW_SCSI_ID_BIT_SHIFT;
  56. logmsg("SCSI ID set via DIP switch to ", 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. m_device_type = S2S_CFG_FIXED;
  62. break;
  63. case 1:
  64. m_device_type = S2S_CFG_OPTICAL;
  65. break;
  66. case 2:
  67. m_device_type = S2S_CFG_FLOPPY_14MB;
  68. break;
  69. case 3:
  70. m_device_type = S2S_CFG_REMOVABLE;
  71. break;
  72. case 4:
  73. m_device_type = S2S_CFG_MO;
  74. break;
  75. case 5:
  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. #endif // ZULUSCSI_HARDWARE_CONFIG