Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
u1f992 committed Oct 14, 2024
2 parents ded9f92 + b5ccc83 commit 4457b6b
Show file tree
Hide file tree
Showing 34 changed files with 2,646 additions and 561 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
BasedOnStyle: LLVM
IndentWidth: 4
...
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.vscode
dist
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/nthaka"]
path = lib/nthaka
url = https://github.com/U-1F992/nthaka.git
[submodule "lib/Bluewhale"]
path = lib/Bluewhale
url = https://github.com/mizuyoukanao/Bluewhale.git
10 changes: 0 additions & 10 deletions .vscode/extensions.json

This file was deleted.

72 changes: 0 additions & 72 deletions .vscode/settings.json

This file was deleted.

22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Jiangtun (江豚)

GC automation alternative firmware for Raspberry Pi Pico.
GameCube automation alternative firmware for RP2040.

- [NX Macro Controller](https://blog.bzl-web.com/entry/2020/01/20/165719)
- [Poke-Controller Modified](https://github.com/Moi-poke/Poke-Controller-Modified)
- [ORCA GC Controller](https://github.com/yatsuna827/Orca-GC-Controller) (experimental)
- [ORCA GC Controller](https://github.com/yatsuna827/Orca-GC-Controller)

Use GameCube: `GPIO5`, Servo: `GPIO6`. ([WHALE](https://github.com/mizuyoukanao/Bluewhale) compatible)
## Pin assignment

| Pico | XIAO RP2040 | Function |
| :---: | :---------: | :----------------: |
| 7 | D5 | GameCube DATA |
| 0 | D6 | Servo |
| 3 | D10 | Reset (Active Low) |

## Button mapping

Expand All @@ -18,14 +24,14 @@ Use GameCube: `GPIO5`, Servo: `GPIO6`. ([WHALE](https://github.com/mizuyoukanao/
| X | X |
| L | L |
| R | R |
| ZL | (none) |
| ZL | |
| ZR | Z |
| - | (none) |
| - | |
| + | Start |
| L Click | (none) |
| R Click | (none) |
| L Click | |
| R Click | |
| Home | Reset |
| Capture | (none) |
| Capture | |

## Development

Expand Down
1 change: 0 additions & 1 deletion lib/Bluewhale
Submodule Bluewhale deleted from eefedb
4 changes: 4 additions & 0 deletions lib/jiangtun-core/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
BasedOnStyle: LLVM
IndentWidth: 4
...
14 changes: 14 additions & 0 deletions lib/jiangtun-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
build
.vscode
25 changes: 25 additions & 0 deletions lib/jiangtun-core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.10)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(jiangtun-core VERSION 0.1.0)
set(CMAKE_C_STANDARD 90)
set(CMAKE_C_EXTENSIONS OFF)

file(GLOB_RECURSE SRC_FILES src/*.c)
add_library(jiangtun-core STATIC ${SRC_FILES})
target_include_directories(jiangtun-core PUBLIC include)
target_compile_options(jiangtun-core PRIVATE -Wall -Wextra -Wpedantic -Werror)

enable_testing()

add_executable(jiangtun-core_test_command test/command.c)
target_link_libraries(jiangtun-core_test_command jiangtun-core)
target_compile_options(jiangtun-core_test_command PRIVATE -Wall -Wextra -Wpedantic -Werror)
add_test(NAME jiangtun-core_test_command COMMAND jiangtun-core_test_command)

add_executable(jiangtun-core_test_arduino test/arduino.c)
target_link_libraries(jiangtun-core_test_arduino jiangtun-core)
target_compile_options(jiangtun-core_test_arduino PRIVATE -Wall -Wextra -Wpedantic -Werror)
add_test(NAME jiangtun-core_test_arduino COMMAND jiangtun-core_test_arduino)
30 changes: 30 additions & 0 deletions lib/jiangtun-core/LoopTimeMeasurement/LoopTimeMeasurement.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <Arduino.h>

#include <stdio.h>

static unsigned long start_time = 0;
static unsigned int loop_count = 0;

void setup(void) {
Serial.begin();
start_time = micros();
}

void loop_(void) {
}

void loop(void) {
loop_();

if (loop_count++ >= 1000) {
unsigned long total_time = micros() - start_time;
double average_time = (double)total_time / 1000.0;
char buffer[256];

sprintf(buffer, "Average time per loop: %lf\n", average_time);
Serial.print(buffer);

start_time = micros();
loop_count = 0;
}
}
67 changes: 67 additions & 0 deletions lib/jiangtun-core/include/jiangtun.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef JIANGTUN_H
#define JIANGTUN_H

#include "jiangtun/board.h"
#include "jiangtun/command.h"
#include "jiangtun/compat.h"
#include "jiangtun/optional.h"
#include "jiangtun/report.h"

#ifdef __cplusplus
extern "C" {
#endif

#define JIANGTUN_LOOPS_FOR_TIMEOUT 5
#define JIANGTUN_LED_ON_MILLIS 100
#define JIANGTUN_RESET_BLOCKING_MILLIS 500

typedef jiangtun_uint32_t jiangtun_feature_flag_t;
#define JIANGTUN_FEATURE_ENABLE_LED_BLINK ((jiangtun_feature_flag_t)(1 << 4))
#define JIANGTUN_FEATURE_ENABLE_NXMC2 ((jiangtun_feature_flag_t)(1 << 3))
#define JIANGTUN_FEATURE_ENABLE_POKECON ((jiangtun_feature_flag_t)(1 << 2))
#define JIANGTUN_FEATURE_ENABLE_ORCA ((jiangtun_feature_flag_t)(1 << 1))
#define JIANGTUN_FEATURE_ENABLE_DOL ((jiangtun_feature_flag_t)(1 << 0))

typedef enum jiangtun_log_level_t {
JIANGTUN_LOG_LEVEL_WARN,
JIANGTUN_LOG_LEVEL_INFO,
JIANGTUN_LOG_LEVEL_DEBUG
} jiangtun_log_level_t;

typedef struct jiangtun_t {
jiangtun_board_t *board;
jiangtun_feature_flag_t features;

jiangtun_nxmc2_command_t nxmc2;
jiangtun_pokecon_command_t pokecon;
jiangtun_orca_command_t orca;
jiangtun_dol_command_t dol;
jiangtun_command_t *commands[4];

jiangtun_report_mode3_t reports[4];
jiangtun_report_mode3_t *recently_patched;

jiangtun_bool_t any_pending;

jiangtun_optional_uint8_t carry_over;

jiangtun_uint32_t timeout_loop;

jiangtun_optional_uint32_t led_on_start_time;
jiangtun_optional_uint32_t reset_blocking_start_time;

jiangtun_log_level_t log_level;

char buffer[128];
char log_buffer[128];
} jiangtun_t;

void jiangtun_init(jiangtun_t *, jiangtun_board_t *, jiangtun_feature_flag_t,
jiangtun_log_level_t);
void jiangtun_loop(jiangtun_t *);

#ifdef __cplusplus
}
#endif

#endif /* JIANGTUN_H */
47 changes: 47 additions & 0 deletions lib/jiangtun-core/include/jiangtun/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef JIANGTUN_BOARD_H
#define JIANGTUN_BOARD_H

#include "compat.h"
#include "report.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct jiangtun_board_t {
jiangtun_bool_t (*serial_getc)(struct jiangtun_board_t *,
jiangtun_uint8_t *);
void (*serial_puts)(struct jiangtun_board_t *, const char *);
jiangtun_bool_t (*gamecube_send)(struct jiangtun_board_t *, jiangtun_bool_t,
jiangtun_report_mode3_t *);
void (*led_set)(struct jiangtun_board_t *, jiangtun_bool_t);
jiangtun_uint32_t (*get_millis)(struct jiangtun_board_t *);
} jiangtun_board_t;

typedef jiangtun_bool_t (*jiangtun_serial_getc_t)(jiangtun_board_t *,
jiangtun_uint8_t *);
typedef void (*jiangtun_serial_puts_t)(jiangtun_board_t *, const char *);
typedef jiangtun_bool_t (*jiangtun_gamecube_send_t)(jiangtun_board_t *,
jiangtun_bool_t,
jiangtun_report_mode3_t *);
typedef void (*jiangtun_led_set_t)(jiangtun_board_t *, jiangtun_bool_t);
typedef jiangtun_uint32_t (*jiangtun_get_millis_t)(jiangtun_board_t *);

jiangtun_bool_t jiangtun_board_serial_getc(jiangtun_board_t *,
jiangtun_uint8_t *);
void jiangtun_board_serial_puts(jiangtun_board_t *, const char *);
jiangtun_bool_t jiangtun_board_gamecube_send(jiangtun_board_t *,
jiangtun_bool_t,
jiangtun_report_mode3_t *);
void jiangtun_board_led_set(jiangtun_board_t *, jiangtun_bool_t);
jiangtun_uint32_t jiangtun_board_get_millis(jiangtun_board_t *);

void jiangtun_board_init(jiangtun_board_t *, jiangtun_serial_getc_t,
jiangtun_serial_puts_t, jiangtun_gamecube_send_t,
jiangtun_led_set_t, jiangtun_get_millis_t);

#ifdef __cplusplus
}
#endif

#endif /* JIANGTUN_BOARD_H */
Loading

0 comments on commit 4457b6b

Please sign in to comment.