Skip to content

Commit e137eac

Browse files
committed
amiga: Synchronize amiga pin 34 to /MTR when motor-delay is configured.
Output ungated open-collector /DD density signal on JC. Refs #354
1 parent 620ee33 commit e137eac

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

inc/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ unsigned int board_get_buttons(void);
173173
#define B_LEFT 1
174174
#define B_RIGHT 2
175175
#define B_SELECT 4
176+
void board_jc_set_mode(unsigned int mode);
176177
bool_t board_jc_strapped(void);
177178

178179
/* Build info. */

src/floppy.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static time_t prefetch_start_time;
3434
static uint32_t max_prefetch_us;
3535

3636
struct drive;
37+
static always_inline void drive_change_pin(
38+
struct drive *drv, uint8_t pin, bool_t assert);
3739
static always_inline void drive_change_output(
3840
struct drive *drv, uint8_t outp, bool_t assert);
3941

@@ -130,13 +132,20 @@ static void drive_change_output(
130132

131133
static void update_amiga_id(struct drive *drv, bool_t amiga_hd_id)
132134
{
133-
/* Only for the Amiga interface, with hacked RDY (pin 34) signal. */
134-
if (fintf_mode != FINTF_AMIGA)
135+
/* JC and pin 34 are overridden only for the Amiga interface. */
136+
if (fintf_mode != FINTF_AMIGA) {
137+
drv->amiga_pin34 = FALSE;
138+
board_jc_set_mode(GPI_pull_up);
135139
return;
140+
}
136141

142+
/* JC and HDEN are set according to Amiga density. */
143+
board_jc_set_mode(GPO_opendrain(_2MHz, amiga_hd_id));
137144
drive_change_output(drv, outp_hden, amiga_hd_id);
138145

139-
if (pin34 != outp_unused)
146+
/* If pin 34 is explicitly configured, we do not mess with it. */
147+
drv->amiga_pin34 = (pin34 == outp_unused);
148+
if (!drv->amiga_pin34)
140149
return;
141150

142151
IRQ_global_disable();
@@ -151,7 +160,8 @@ static void update_amiga_id(struct drive *drv, bool_t amiga_hd_id)
151160
* the HD-ID sequence 101010... with the host poll loop. It turns out that
152161
* starting with pin 34 asserted when the HD image is mounted seems to
153162
* generally work! */
154-
drive_change_pin(&drive, pin_34, TRUE);
163+
if (ff_cfg.motor_delay == MOTOR_ignore)
164+
drive_change_pin(&drive, pin_34, TRUE);
155165
}
156166

157167
void floppy_cancel(void)
@@ -613,6 +623,10 @@ static void motor_spinup_timer(void *_drv)
613623
struct drive *drv = _drv;
614624

615625
drv->motor.on = TRUE;
626+
if (drv->amiga_pin34) {
627+
IRQ_global_disable();
628+
drive_change_pin(drv, pin_34, TRUE);
629+
}
616630
drive_change_output(drv, outp_rdy, TRUE);
617631
}
618632

src/floppy_generic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static struct drive {
5151
bool_t writing;
5252
bool_t sel;
5353
bool_t index_suppressed; /* disable IDX while writing to USB stick */
54+
bool_t amiga_pin34;
5455
uint8_t outp;
5556
volatile bool_t inserted;
5657
struct timer chgrst_timer;

src/gotek/board.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ void board_setup_rotary_exti(void)
144144
exti->imr |= m;
145145
}
146146

147+
void board_jc_set_mode(unsigned int mode)
148+
{
149+
if (mcu_package == MCU_QFN32) {
150+
#if !defined(NDEBUG)
151+
/* PA9 is used for serial tx */
152+
#else
153+
gpio_configure_pin(gpioa, 9, mode);
154+
#endif
155+
} else {
156+
gpio_configure_pin(gpiob, 1, mode);
157+
}
158+
}
159+
147160
bool_t board_jc_strapped(void)
148161
{
149162
if (mcu_package == MCU_QFN32) {

src/gotek/floppy.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ static void IRQ_WGATE_rotary(void)
394394
static void IRQ_MOTOR(struct drive *drv)
395395
{
396396
GPIO gpio = gotek_enhanced() ? gpioa : gpiob;
397+
bool_t mtr_asserted = !(gpio->idr & m(pin_motor));
398+
399+
if (drv->amiga_pin34 && (ff_cfg.motor_delay != MOTOR_ignore)) {
400+
IRQ_global_disable();
401+
drive_change_pin(drv, pin_34, !mtr_asserted);
402+
}
397403

398404
timer_cancel(&drv->motor.timer);
399405
drv->motor.on = FALSE;
@@ -405,7 +411,7 @@ static void IRQ_MOTOR(struct drive *drv)
405411
/* Motor signal ignored -- MOTOR ON */
406412
drv->motor.on = TRUE;
407413
drive_change_output(drv, outp_rdy, TRUE);
408-
} else if (gpio->idr & m(pin_motor)) {
414+
} else if (!mtr_asserted) {
409415
/* Motor signal off -- MOTOR OFF */
410416
drive_change_output(drv, outp_rdy, FALSE);
411417
} else {

0 commit comments

Comments
 (0)