-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheeprom.c
83 lines (66 loc) · 2.26 KB
/
eeprom.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* GC to N64 : Gamecube controller to N64 adapter firmware
Copyright (C) 2011-2017 Raphael Assenat <raph@raphnet.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/eeprom.h>
#include <string.h>
#include "eeprom.h"
struct eeprom_data_struct g_eeprom_data;
void eeprom_commit(void)
{
eeprom_write_block(&g_eeprom_data, (void*)0x00, sizeof(struct eeprom_data_struct));
}
static char magic[EEPROM_MAGIC_SIZE] = { 'G','C','2','N','6','4','v','8' };
void eeprom_writeDefaults(void)
{
memcpy(g_eeprom_data.magic, magic, EEPROM_MAGIC_SIZE);
g_eeprom_data.defmap = 0;
g_eeprom_data.deadzone_enabled = 0;
g_eeprom_data.old_v1_5_conversion = 0;
g_eeprom_data.conversion_mode = CONVERSION_MODE_V2;
// This fill lets default mappings be empty (-1,-1 being the terminator)
memset(g_eeprom_data.appdata, 0xff, EEPROM_APPDATA_SIZE);
eeprom_commit();
}
int eeprom_init(void)
{
eeprom_read_block(&g_eeprom_data, (void*)0x00, sizeof(struct eeprom_data_struct));
/* Check for magic number */
if (memcmp(g_eeprom_data.magic, magic, EEPROM_MAGIC_SIZE)) {
eeprom_writeDefaults();
return 1;
}
return 0;
}
void cycle_conversion_mode(void)
{
g_eeprom_data.conversion_mode++;
if (g_eeprom_data.conversion_mode > CONVERSION_MAX) {
g_eeprom_data.conversion_mode = CONVERSION_MODE_OLD_1v5;
}
// Emulate the old v1.5 field
if (g_eeprom_data.conversion_mode == CONVERSION_MODE_OLD_1v5) {
g_eeprom_data.old_v1_5_conversion = 1;
} else {
g_eeprom_data.old_v1_5_conversion = 0;
}
}
void toggleDeadzone(void)
{
g_eeprom_data.deadzone_enabled = !g_eeprom_data.deadzone_enabled;
eeprom_commit();
}
void setDefaultMapping(int id)
{
g_eeprom_data.defmap = id;
eeprom_commit();
}