AIC submodule included

This commit is contained in:
whowechina 2024-09-15 22:08:02 +08:00
parent 6f25ad299d
commit 3336f2139b
12 changed files with 96614 additions and 36 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "aic_pico"]
path = firmware/modules/aic_pico
url = https://github.com/whowechina/aic_pico

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,12 @@ cmake_minimum_required(VERSION 3.12)
include(pico_sdk_import.cmake)
project(geki_pico C CXX ASM)
set(CMAKE_C_STANDARD 11)
pico_sdk_init()
add_subdirectory(modules/aic_pico/firmware aic)
include_directories(modules/aic_pico/firmware/include)
add_subdirectory(src)

@ -0,0 +1 @@
Subproject commit 07ae53573addb7a15bd1350ce642a5bb746e705f

View File

@ -1,6 +1,3 @@
set(BTSTACK_ROOT ${PICO_SDK_PATH}/lib/btstack)
set(LWIP_ROOT ${PICO_SDK_PATH}/lib/lwip)
function(make_firmware board board_def)
pico_sdk_init()
add_executable(${board}
@ -14,15 +11,14 @@ function(make_firmware board board_def)
target_compile_options(${board} PRIVATE -Wall -Werror -Wfatal-errors -O3)
target_include_directories(${board} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(${board} PRIVATE
${BTSTACK_ROOT}/src
${LWIP_ROOT}/src/include)
target_link_libraries(${board} PRIVATE
pico_multicore pico_stdlib hardware_pio hardware_pwm hardware_flash
hardware_adc hardware_i2c hardware_watchdog
tinyusb_device tinyusb_board)
target_link_libraries(${board} PRIVATE aic)
pico_add_extra_outputs(${board})
add_custom_command(TARGET ${board} PRE_BUILD

View File

@ -52,6 +52,7 @@ void airkey_init()
gpio_init(scl);
gpio_init(sda);
i2c_init(tof_ports[i], TOF_I2C_FREQ);
gpio_set_function(scl, GPIO_FUNC_I2C);
gpio_set_function(sda, GPIO_FUNC_I2C);

View File

@ -13,11 +13,14 @@
#define SOUND_DEF { 8, 6 }
#define TOF_PORT_DEF { i2c1, i2c0 }
#define TOF_GPIO_DEF { 18, 19, 0, 1 }
#define TOF_I2C_FREQ 400*1000
#define AXIS_MUX_PIN_A 21
#define AXIS_MUX_PIN_B 20
#define ADC_CHANNEL 0
#define PN532_I2C_PORT i2c1
#define NKRO_KEYMAP "awsdjikl123"
#else

View File

@ -13,23 +13,14 @@
#include "gimbal.h"
#include "nfc.h"
#include "aime.h"
#include "usb_descriptors.h"
#define SENSE_LIMIT_MAX 9
#define SENSE_LIMIT_MIN -9
static void disp_axis()
{
}
static void disp_hid()
{
printf("[HID]\n");
printf(" Joy: %s, NKRO: %s.\n",
geki_cfg->hid.joy ? "on" : "off",
geki_cfg->hid.nkro ? "on" : "off" );
}
static inline int sprintf_hsv_rgb(char *buf, const rgb_hsv_t *color)
{
return sprintf(buf, "%s(%d,%d,%d)", color->rgb_hsv ? "hsv" : "rgb",
@ -69,12 +60,6 @@ static void disp_light()
printf(" aux_off: %s\n", color_str(&geki_cfg->light.aux_off, false));
}
static void disp_sound()
{
printf("[Sound]\n");
printf(" Status: %s.\n", geki_cfg->sound.enabled ? "on" : "off");
}
static void disp_gimbal()
{
printf("[Gimbal]\n");
@ -84,40 +69,62 @@ static void disp_gimbal()
geki_cfg->gimbal.min, geki_cfg->gimbal.max);
}
static void disp_sound()
{
printf("[Sound]\n");
printf(" Status: %s.\n", geki_cfg->sound.enabled ? "on" : "off");
}
static void disp_hid()
{
printf("[HID]\n");
printf(" Joy: %s, NKRO: %s.\n",
geki_cfg->hid.joy ? "on" : "off",
geki_cfg->hid.nkro ? "on" : "off" );
}
static void disp_aime()
{
printf("[AIME]\n");
printf(" NFC Module: %s\n", nfc_module_name());
printf(" Virtual AIC: %s\n", geki_cfg->aime.virtual_aic ? "ON" : "OFF");
printf(" Mode: %d\n", geki_cfg->aime.mode);
}
void handle_display(int argc, char *argv[])
{
const char *usage = "Usage: display [axis|light|sound|hid|gimbal]\n";
const char *usage = "Usage: display [light|sound|hid|gimbal|aime]\n";
if (argc > 1) {
printf(usage);
return;
}
if (argc == 0) {
disp_axis();
disp_light();
disp_gimbal();
disp_sound();
disp_hid();
disp_aime();
return;
}
const char *choices[] = {"axis", "light", "gimbal", "sound", "hid"};
const char *choices[] = {"light", "gimbal", "sound", "hid", "aime"};
switch (cli_match_prefix(choices, count_of(choices), argv[0])) {
case 0:
disp_axis();
break;
case 1:
disp_light();
break;
case 2:
case 1:
disp_gimbal();
break;
case 3:
case 2:
disp_sound();
break;
case 4:
case 3:
disp_hid();
break;
case 4:
disp_aime();
break;
default:
printf(usage);
break;
@ -376,6 +383,75 @@ static void handle_factory_reset()
printf("Factory reset done.\n");
}
static void handle_nfc()
{
nfc_init();
printf("NFC module: %s\n", nfc_module_name());
nfc_rf_field(true);
nfc_card_t card = nfc_detect_card();
nfc_rf_field(false);
printf("Card: %s", nfc_card_type_str(card.card_type));
for (int i = 0; i < card.len; i++) {
printf(" %02x", card.uid[i]);
}
printf("\n");
}
static bool handle_aime_mode(const char *mode)
{
if (strcmp(mode, "0") == 0) {
geki_cfg->aime.mode = 0;
} else if (strcmp(mode, "1") == 0) {
geki_cfg->aime.mode = 1;
} else {
return false;
}
aime_sub_mode(geki_cfg->aime.mode);
config_changed();
return true;
}
static bool handle_aime_virtual(const char *onoff)
{
if (strcasecmp(onoff, "on") == 0) {
geki_cfg->aime.virtual_aic = 1;
} else if (strcasecmp(onoff, "off") == 0) {
geki_cfg->aime.virtual_aic = 0;
} else {
return false;
}
aime_virtual_aic(geki_cfg->aime.virtual_aic);
config_changed();
return true;
}
static void handle_aime(int argc, char *argv[])
{
const char *usage = "Usage:\n"
" aime mode <0|1>\n"
" aime virtual <on|off>\n";
if (argc != 2) {
printf("%s", usage);
return;
}
const char *commands[] = { "mode", "virtual" };
int match = cli_match_prefix(commands, 2, argv[0]);
bool ok = false;
if (match == 0) {
ok = handle_aime_mode(argv[1]);
} else if (match == 1) {
ok = handle_aime_virtual(argv[1]);
}
if (ok) {
disp_aime();
} else {
printf("%s", usage);
}
}
void commands_init()
{
cli_register("display", handle_display, "Display all config.");
@ -386,4 +462,6 @@ void commands_init()
cli_register("sound", handle_sound, "Enable/disable sound.");
cli_register("save", handle_save, "Save config to flash.");
cli_register("factory", handle_factory_reset, "Reset everything to default.");
cli_register("nfc", handle_nfc, "NFC debug.");
cli_register("aime", handle_aime, "AIME settings.");
}

View File

@ -40,6 +40,10 @@ typedef struct __attribute__((packed)) {
uint8_t joy : 4;
uint8_t nkro : 4;
} hid;
struct {
uint8_t mode : 4;
uint8_t virtual_aic : 4;
} aime;
} geki_cfg_t;
typedef struct {

View File

@ -21,6 +21,9 @@
#include "tusb.h"
#include "usb_descriptors.h"
#include "aime.h"
#include "nfc.h"
#include "board_defs.h"
#include "save.h"
@ -99,6 +102,25 @@ static void run_sound()
sound_set(1, airkey_get(1));
}
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];
uint32_t count = tud_cdc_n_read(aime_intf, buf, sizeof(buf));
for (int i = 0; i < count; i++) {
aime_feed(buf[i]);
}
}
}
static mutex_t core1_io_lock;
static void core1_loop()
{
@ -120,7 +142,8 @@ static void core0_loop()
tud_task();
cli_run();
aime_run();
save_loop();
cli_fps_count(0);
@ -178,6 +201,12 @@ void init()
airkey_init();
sound_init();
nfc_attach_i2c(PN532_I2C_PORT);
nfc_init();
aime_init(cdc_aime_putc);
aime_virtual_aic(geki_cfg->aime.virtual_aic);
aime_sub_mode(geki_cfg->aime.mode);
cli_init("geki_pico>", "\n << Geki Pico Controller >>\n"
" https://github.com/whowechina\n\n");
@ -192,7 +221,6 @@ int main(void)
return 0;
}
struct __attribute__((packed)) {
uint16_t buttons;
uint8_t HAT;

View File

@ -30,11 +30,15 @@ void pwm_interrupt_handler()
{
for (int i = 0; i < 2; i++) {
pwm_clear_irq(slice_num[i]);
uint8_t gpio = sound_gpio[i];
if (!active[i]) {
wav_pos[i] = 0;
pwm_set_gpio_level(gpio, 0);
continue;
}
uint8_t gpio = sound_gpio[i];
int len = wav_len[i];
const uint8_t *data = wav_data[i];
if (wav_pos[i] < (len << 3) - 1) {