1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2024-11-24 14:00:09 +01:00

Sega AIME IO working

This commit is contained in:
whowechina 2023-11-05 21:23:28 +08:00
parent bb06b22eca
commit baa6a42b2c
4 changed files with 41 additions and 34 deletions

View File

@ -13,6 +13,7 @@
#include "hardware/i2c.h"
#include "pn532.h"
#include "aime.h"
#define FRAME_TIMEOUT 200000
@ -80,6 +81,12 @@ static struct {
const uint8_t syscode[2];
} virtual_aic = { true, false, "", "\x00\xf1\x00\x00\x00\x01\x43\x00", "\x88\xb4" };
static void putc_trap(uint8_t byte)
{
}
static aime_putc_func aime_putc = putc_trap;
void aime_set_baudrate(int mode)
{
baudrate_mode = (mode == 0) ? 0 : 1;
@ -90,11 +97,9 @@ void aime_set_virtual_aic(bool enable)
virtual_aic.enabled = enable;
}
static int aime_interface = -1;
void aime_init(int interface)
void aime_init(aime_putc_func putc_func)
{
aime_interface = interface;
aime_putc = putc_func;
pn532_config_sam();
}
@ -158,23 +163,21 @@ static void build_response(int payload_len)
static void send_response()
{
uint8_t checksum = 0;
uint8_t sync = 0xe0;
tud_cdc_n_write(aime_interface, &sync, 1);
aime_putc(sync);
for (int i = 0; i < response.len; i++) {
uint8_t c = response.raw[i];
checksum += c;
if (c == 0xe0 || c == 0xd0) {
uint8_t escape = 0xd0;
tud_cdc_n_write(aime_interface, &escape, 1);
aime_putc(escape);
c--;
}
tud_cdc_n_write(aime_interface, &c, 1);
aime_putc(c);
}
tud_cdc_n_write(aime_interface, &checksum, 1);
tud_cdc_n_write_flush(aime_interface);
aime_putc(checksum);
}
static void send_simple_response(uint8_t status)
@ -643,7 +646,7 @@ static void aime_handle_frame()
}
}
static bool aime_feed(int c)
bool aime_feed(int c)
{
if (c == 0xe0) {
req_ctx.active = true;
@ -683,21 +686,6 @@ static bool aime_feed(int c)
return true;
}
void aime_update()
{
if (req_ctx.active && time_us_64() - req_ctx.time > FRAME_TIMEOUT) {
req_ctx.active = false;
}
if (tud_cdc_n_available(aime_interface)) {
uint8_t buf[32];
uint32_t count = tud_cdc_n_read(aime_interface, buf, sizeof(buf));
for (int i = 0; i < count; i++) {
aime_feed(buf[i]);
}
}
}
uint32_t aime_led_color()
{
return led_color;

View File

@ -6,8 +6,12 @@
#ifndef AIME_H
#define AIME_H
void aime_init(int interface);
void aime_update();
/* return true if accepts a byte, false if rejects */
typedef void (*aime_putc_func)(uint8_t byte);
void aime_init(aime_putc_func putc_func);
bool aime_feed(int c);
uint32_t aime_led_color();
// mode 0 or 1

View File

@ -111,13 +111,28 @@ void detect_card()
memset(cardio.current, 0, 9);
}
const int aime_intf = 1;
static void cdc_aime_putc(uint8_t byte)
{
tud_cdc_n_write(aime_intf, &byte, 1);
tud_cdc_n_write_flush(aime_intf);
}
static void aime_run()
{
if (tud_cdc_n_available(aime_intf)) {
uint8_t buf[32];
int count = tud_cdc_n_read(aime_intf, buf, sizeof(buf));
for (int i = 0; i < count; i++) {
aime_feed(buf[i]);
}
}
}
void wait_loop()
{
tud_task();
cli_run();
aime_update();
cli_fps_count(0);
}
@ -127,7 +142,7 @@ static void core0_loop()
tud_task();
cli_run();
aime_update();
aime_run();
save_loop();
cli_fps_count(0);
@ -154,7 +169,7 @@ void init()
pn532_init(I2C_PORT, I2C_SCL, I2C_SDA, I2C_FREQ);
pn532_set_wait_loop(wait_loop);
aime_init(1);
aime_init(cdc_aime_putc);
cli_init("aic_pico>", "\n << AIC Pico >>\n"
" https://github.com/whowechina\n\n");

View File

@ -111,7 +111,7 @@ static void generate_color_wheel()
old_level = aic_cfg->led.level;
for (int i = 0; i < COLOR_WHEEL_SIZE; i++) {
color_wheel[i] = rgb32_from_hsv(i, 250, 255);
color_wheel[i] = rgb32_from_hsv(i, 208, 255);
color_wheel[i] = apply_level(color_wheel[i]);
}
}