This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathemucheckcards.c
60 lines (46 loc) · 1.49 KB
/
emucheckcards.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* ATARI ST HDC Emulator
*
* File: emucheckcards.c
* Author: Steve Bradford
* Created: November 2022
*
*
*/
#include "emu.h"
#define INSERTED false
#define NOT_INSERTED true
extern DRIVES drv[];
extern void emumount ( int );
extern void emuunmount ( int );
void checkSDcards ( void )
{
static uint64_t elapsed = 0;
DRIVES *pdrv;
if ( (time_us_64 () - elapsed) > 1000000 ) /* only check once per second */
{
for ( int d = 0; d < MAX_DRIVES; d++ )
{
pdrv = &drv [d];
//printf ( "%s prevState = %d, ejected = %d, mounted = %d, cdgpio = %d\n", __func__, pdrv->prevState, pdrv->ejected, pdrv->pSD->mounted, pdrv->pSD->card_detect_gpio );
/* check to see if card has been removed then re-inserted */
if ( pdrv->prevState != gpio_get (pdrv->pSD->card_detect_gpio) )
{
pdrv->prevState = gpio_get (pdrv->pSD->card_detect_gpio);
if ( pdrv->ejected )
pdrv->ejected = false; /* reset ejected flag */
}
else if ( gpio_get (pdrv->pSD->card_detect_gpio) == INSERTED )
{
if ( ! pdrv->pSD->mounted && ! pdrv->ejected )
emumount (d);
}
else if ( gpio_get (pdrv->pSD->card_detect_gpio) == NOT_INSERTED )
{
if ( pdrv->pSD->mounted )
emuunmount (d);
}
}
elapsed = time_us_64 ();
}
}