2015-12-06 21:53:51 -05:00
|
|
|
/* gc_n64_usb : Gamecube or N64 controller to USB adapter firmware
|
2016-10-10 15:01:22 -04:00
|
|
|
Copyright (C) 2007-2016 Raphael Assenat <raph@raphnet.net>
|
2015-12-06 21:53:51 -05:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
2015-08-23 02:51:10 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include "eeprom.h"
|
|
|
|
#include "requests.h"
|
|
|
|
|
|
|
|
struct eeprom_data_struct g_eeprom_data;
|
|
|
|
|
|
|
|
/* Called by the eeprom driver if the content
|
|
|
|
* was invalid and it needs to write defaults
|
|
|
|
* values. */
|
|
|
|
void eeprom_app_write_defaults(void)
|
|
|
|
{
|
2015-09-09 21:41:41 -04:00
|
|
|
int i;
|
2015-08-23 02:51:10 -04:00
|
|
|
const char default_serial[SERIAL_NUM_LEN] = { '0','0','0','0','0','1' };
|
|
|
|
|
|
|
|
memcpy(g_eeprom_data.cfg.serial, default_serial, SERIAL_NUM_LEN);
|
|
|
|
g_eeprom_data.cfg.mode = CFG_MODE_STANDARD;
|
2015-09-09 21:41:41 -04:00
|
|
|
|
|
|
|
for (i=0; i<NUM_CHANNELS; i++) {
|
|
|
|
g_eeprom_data.cfg.poll_interval[i] = 5; // 5ms default
|
|
|
|
}
|
2015-08-23 02:51:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void config_set_serial(char serial[SERIAL_NUM_LEN])
|
|
|
|
{
|
|
|
|
memcpy(g_eeprom_data.cfg.serial, serial, SERIAL_NUM_LEN);
|
|
|
|
eeprom_commit();
|
|
|
|
}
|
|
|
|
|
2017-11-22 09:35:59 -05:00
|
|
|
struct paramAndFlag {
|
|
|
|
uint8_t param; // CFG_PARAM_* (requests.h)
|
|
|
|
uint32_t flag; // FLAG_* (config.h)
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct paramAndFlag paramsAndFlags[] = {
|
|
|
|
{ CFG_PARAM_INVERT_TRIG, FLAG_GC_INVERT_TRIGS },
|
|
|
|
{ CFG_PARAM_FULL_SLIDERS, FLAG_GC_FULL_SLIDERS },
|
|
|
|
{ CFG_PARAM_TRIGGERS_AS_BUTTONS, FLAG_GC_SLIDERS_AS_BUTTONS },
|
|
|
|
{ CFG_PARAM_DISABLE_ANALOG_TRIGGERS, FLAG_DISABLE_ANALOG_TRIGGERS },
|
|
|
|
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
uint8_t config_getSupportedParams(uint8_t *dst)
|
|
|
|
{
|
|
|
|
uint8_t n = 0, i;
|
|
|
|
|
|
|
|
dst[n++] = CFG_PARAM_MODE;
|
|
|
|
dst[n++] = CFG_PARAM_SERIAL;
|
|
|
|
for (i=0; i<NUM_CHANNELS; i++) {
|
|
|
|
dst[n++] = CFG_PARAM_POLL_INTERVAL0 + i;
|
|
|
|
}
|
|
|
|
for (i=0; paramsAndFlags[i].flag; i++) {
|
|
|
|
dst[n++] = paramsAndFlags[i].param;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2015-08-23 02:51:10 -04:00
|
|
|
unsigned char config_getParam(unsigned char param, unsigned char *value, unsigned char max_len)
|
|
|
|
{
|
2017-11-22 09:35:59 -05:00
|
|
|
int i;
|
|
|
|
|
2015-08-23 02:51:10 -04:00
|
|
|
switch (param)
|
|
|
|
{
|
|
|
|
case CFG_PARAM_MODE:
|
|
|
|
*value = g_eeprom_data.cfg.mode;
|
|
|
|
return 1;
|
|
|
|
case CFG_PARAM_SERIAL:
|
|
|
|
memcpy(value, g_eeprom_data.cfg.serial, SERIAL_NUM_LEN);
|
|
|
|
return SERIAL_NUM_LEN;
|
2015-09-09 21:41:41 -04:00
|
|
|
case CFG_PARAM_POLL_INTERVAL0:
|
|
|
|
*value = g_eeprom_data.cfg.poll_interval[0];
|
|
|
|
return 1;
|
|
|
|
#if NUM_CHANNELS > 1
|
|
|
|
case CFG_PARAM_POLL_INTERVAL1:
|
|
|
|
*value = g_eeprom_data.cfg.poll_interval[1];
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
#if NUM_CHANNELS > 2
|
|
|
|
case CFG_PARAM_POLL_INTERVAL2:
|
|
|
|
*value = g_eeprom_data.cfg.poll_interval[2];
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
#if NUM_CHANNELS > 3
|
|
|
|
case CFG_PARAM_POLL_INTERVAL3:
|
|
|
|
*value = g_eeprom_data.cfg.poll_interval[3];
|
|
|
|
return 1;
|
|
|
|
#endif
|
2017-11-22 09:35:59 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
for (i=0; paramsAndFlags[i].flag; i++) {
|
|
|
|
if (param == paramsAndFlags[i].param) {
|
|
|
|
*value = (g_eeprom_data.cfg.flags & paramsAndFlags[i].flag) ? 1 : 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2015-08-23 02:51:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char config_setParam(unsigned char param, const unsigned char *value)
|
|
|
|
{
|
2017-11-22 09:35:59 -05:00
|
|
|
int i;
|
|
|
|
|
2015-08-23 02:51:10 -04:00
|
|
|
if (!value)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (param)
|
|
|
|
{
|
|
|
|
case CFG_PARAM_MODE:
|
|
|
|
g_eeprom_data.cfg.mode = value[0];
|
2015-10-15 23:42:30 -04:00
|
|
|
break;
|
2015-08-23 02:51:10 -04:00
|
|
|
case CFG_PARAM_SERIAL:
|
|
|
|
config_set_serial((char*)value);
|
2015-10-15 23:42:30 -04:00
|
|
|
break;
|
2015-09-09 21:41:41 -04:00
|
|
|
case CFG_PARAM_POLL_INTERVAL0:
|
|
|
|
g_eeprom_data.cfg.poll_interval[0] = value[0];
|
2015-10-15 23:42:30 -04:00
|
|
|
break;
|
2015-09-09 21:41:41 -04:00
|
|
|
#if NUM_CHANNELS > 1
|
|
|
|
case CFG_PARAM_POLL_INTERVAL1:
|
|
|
|
g_eeprom_data.cfg.poll_interval[1] = value[0];
|
2015-10-15 23:42:30 -04:00
|
|
|
break;
|
2015-09-09 21:41:41 -04:00
|
|
|
#endif
|
|
|
|
#if NUM_CHANNELS > 2
|
|
|
|
case CFG_PARAM_POLL_INTERVAL2:
|
|
|
|
g_eeprom_data.cfg.poll_interval[2] = value[0];
|
2015-10-15 23:42:30 -04:00
|
|
|
break;
|
2015-09-09 21:41:41 -04:00
|
|
|
#endif
|
|
|
|
#if NUM_CHANNELS > 3
|
|
|
|
case CFG_PARAM_POLL_INTERVAL3:
|
|
|
|
g_eeprom_data.cfg.poll_interval[3] = value[0];
|
2015-10-15 23:42:30 -04:00
|
|
|
break;
|
2015-09-09 21:41:41 -04:00
|
|
|
#endif
|
2017-11-22 09:35:59 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
for (i=0; paramsAndFlags[i].flag; i++) {
|
|
|
|
if (param == paramsAndFlags[i].param) {
|
|
|
|
if (value[0]) {
|
|
|
|
g_eeprom_data.cfg.flags |= paramsAndFlags[i].flag;
|
|
|
|
} else {
|
|
|
|
g_eeprom_data.cfg.flags &= ~paramsAndFlags[i].flag;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-10-17 23:18:56 -04:00
|
|
|
}
|
2017-11-22 09:35:59 -05:00
|
|
|
|
|
|
|
// if we made it through the list without finding
|
|
|
|
// a matching parameter, do nothing.
|
|
|
|
if (!paramsAndFlags[i].flag) {
|
|
|
|
return 0;
|
2017-08-14 17:58:40 -04:00
|
|
|
}
|
2015-08-23 02:51:10 -04:00
|
|
|
}
|
|
|
|
|
2015-10-15 23:42:30 -04:00
|
|
|
eeprom_commit();
|
|
|
|
|
|
|
|
return 1;
|
2015-08-23 02:51:10 -04:00
|
|
|
}
|