1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-28 00:10:51 +01:00

sdvxio-kfca: Add KFCA sdvxio driver

This commit is contained in:
Will Xyen 2019-09-24 21:12:14 -04:00
parent bda056f0e4
commit 3436838b85
4 changed files with 171 additions and 0 deletions

View File

@ -130,6 +130,7 @@ include src/main/p4ioemu/Module.mk
include src/main/pcbidgen/Module.mk
include src/main/sdvxhook/Module.mk
include src/main/sdvxio/Module.mk
include src/main/sdvxio-kfca/Module.mk
include src/main/security/Module.mk
include src/main/unicorntail/Module.mk
include src/main/util/Module.mk
@ -402,6 +403,7 @@ $(zipdir)/sdvx.zip: \
build/bin/indep-32/eamio.dll \
build/bin/indep-32/geninput.dll \
build/bin/indep-32/sdvxio.dll \
build/bin/indep-32/sdvxio-kfca.dll \
dist/sdvx/config.bat \
dist/sdvx/gamestart.bat \
| $(zipdir)/

View File

@ -0,0 +1,10 @@
dlls += sdvxio-kfca
libs_sdvxio-kfca := \
geninput \
aciodrv \
util \
src_sdvxio-kfca := \
sdvxio.c \

View File

@ -0,0 +1,13 @@
LIBRARY sdvxio
EXPORTS
sdvx_io_fini
sdvx_io_get_input_gpio
sdvx_io_get_input_gpio_sys
sdvx_io_get_spinner_pos
sdvx_io_init
sdvx_io_read_input
sdvx_io_set_gpio_lights
sdvx_io_set_loggers
sdvx_io_set_pwm_light
sdvx_io_write_output

View File

@ -0,0 +1,146 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "bemanitools/glue.h"
#include "bemanitools/sdvxio.h"
#include "aciodrv/device.h"
#include "aciodrv/kfca.h"
#define LOG_MODULE "sdvxio-kfca"
#define log_misc(...) sdvx_io_log_misc(LOG_MODULE, __VA_ARGS__)
#define log_info(...) sdvx_io_log_info(LOG_MODULE, __VA_ARGS__)
#define log_warning(...) sdvx_io_log_warning(LOG_MODULE, __VA_ARGS__)
#define log_fatal(...) sdvx_io_log_fatal(LOG_MODULE, __VA_ARGS__)
static log_formatter_t sdvx_io_log_misc;
static log_formatter_t sdvx_io_log_info;
static log_formatter_t sdvx_io_log_warning;
static log_formatter_t sdvx_io_log_fatal;
static uint16_t sdvx_io_gpio[2];
static uint8_t sdvx_io_gpio_sys;
static uint16_t sdvx_io_analog[2];
static bool running;
static bool processing_io;
struct ac_io_kfca_poll_out pout_staging;
struct ac_io_kfca_poll_out pout_ready;
void sdvx_io_set_loggers(log_formatter_t misc, log_formatter_t info,
log_formatter_t warning, log_formatter_t fatal)
{
sdvx_io_log_misc = misc;
sdvx_io_log_info = info;
sdvx_io_log_warning = warning;
sdvx_io_log_fatal = fatal;
}
bool sdvx_io_init(thread_create_t thread_create, thread_join_t thread_join,
thread_destroy_t thread_destroy)
{
if (!aciodrv_device_open("COM3", 57600)) {
log_info("Opening acio device failed\n");
return -1;
}
log_info("Opening acio device successful\n");
uint8_t node_count = aciodrv_device_get_node_count();
log_info("Enumerated %d nodes\n", node_count);
aciodrv_kfca_init(0);
running = true;
return true;
}
void sdvx_io_fini(void)
{
running = false;
while(processing_io) {
}
}
void sdvx_io_set_gpio_lights(uint32_t gpio_lights)
{
pout_staging.gpio = gpio_lights;
pout_staging.gpio |= 1 << 0x16;
pout_staging.gpio = ac_io_u32(pout_staging.gpio);
}
void sdvx_io_set_pwm_light(uint8_t light_no, uint8_t intensity)
{
pout_staging.pwm[light_no] = intensity;
}
bool sdvx_io_write_output(void)
{
memcpy(&pout_ready, &pout_staging, sizeof(struct ac_io_kfca_poll_out));
return true;
}
bool sdvx_io_read_input(void)
{
struct ac_io_kfca_poll_in pin;
if (!running) {
return false;
}
processing_io = true;
if (!aciodrv_kfca_poll(0, &pout_ready, &pin)) {
return false;
}
processing_io = false;
pin.adc[0] = ac_io_u16(pin.adc[0]);
pin.adc[1] = ac_io_u16(pin.adc[1]);
pin.gpio[0] = ac_io_u16(pin.gpio[0]);
pin.gpio[1] = ac_io_u16(pin.gpio[1]);
sdvx_io_gpio_sys = pin.gpio_sys;
sdvx_io_analog[0] = (pin.adc[0] >> 6) & 0x3FF;
sdvx_io_analog[1] = (pin.adc[1] >> 6) & 0x3FF;
sdvx_io_gpio[0] = pin.gpio[0];
sdvx_io_gpio[1] = pin.gpio[1];
return true;
}
uint8_t sdvx_io_get_input_gpio_sys(void)
{
return sdvx_io_gpio_sys;
}
uint16_t sdvx_io_get_input_gpio(uint8_t gpio_bank)
{
if (gpio_bank > 1) {
return 0;
}
return sdvx_io_gpio[gpio_bank];
}
uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no)
{
if (spinner_no >= 2) {
return 0;
}
return sdvx_io_analog[spinner_no];
}