diff --git a/main/main.c b/main/main.c index 71e9595c..90d30267 100644 --- a/main/main.c +++ b/main/main.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "system/bare_metal_app_cpu.h" #include "system/core0_stall.h" #include "system/delay.h" @@ -24,6 +26,8 @@ #include "system/manager.h" #include "sdkconfig.h" +static uint32_t chip_package = EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6; + static void wired_init_task(void) { #ifdef CONFIG_BLUERETRO_SYSTEM_UNIVERSAL detect_init(); @@ -66,16 +70,20 @@ static void wired_init_task(void) { adapter_q_fb(&fb_data); if (wired_adapter.system_id < WIRED_MAX) { - wired_bare_init(); + wired_bare_init(chip_package); } } static void wl_init_task(void *arg) { uint32_t err = 0; + const esp_partition_t *running = esp_ota_get_running_partition(); esp_ota_img_states_t ota_state; esp_ota_get_state_partition(running, &ota_state); - err_led_init(); + + chip_package = esp_efuse_get_pkg_ver(); + + err_led_init(chip_package); core0_stall_init(); diff --git a/main/system/led.c b/main/system/led.c index 0f79f06e..702da80f 100644 --- a/main/system/led.c +++ b/main/system/led.c @@ -1,12 +1,11 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #include #include -#include "soc/efuse_reg.h" -#include "esp_efuse.h" +#include #include "zephyr/atomic.h" #include "system/gpio.h" #include "driver/ledc.h" @@ -47,7 +46,7 @@ static void err_led_task(void *param) { } } -void err_led_init(void) { +void err_led_init(uint32_t package) { ledc_timer_config_t ledc_timer = { .duty_resolution = LEDC_TIMER_13_BIT, .freq_hz = 5000, @@ -64,7 +63,6 @@ void err_led_init(void) { .timer_sel = LEDC_TIMER_0, }; - uint32_t package = esp_efuse_get_pkg_ver(); if (package == EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302) { ledc_channel.gpio_num = PICO_ERR_LED_PIN; err_led_pin = PICO_ERR_LED_PIN; diff --git a/main/system/led.h b/main/system/led.h index c14039c9..bfc3a846 100644 --- a/main/system/led.h +++ b/main/system/led.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -8,7 +8,7 @@ #include -void err_led_init(void); +void err_led_init(uint32_t package); void err_led_set(void); void err_led_clear(void); void err_led_pulse(void); diff --git a/main/wired/cdi_uart.c b/main/wired/cdi_uart.c index 80462aef..39eaadc7 100644 --- a/main/wired/cdi_uart.c +++ b/main/wired/cdi_uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -264,7 +264,7 @@ static unsigned isr_dispatch(unsigned cause) { return 0; } -void cdi_uart_init(void) { +void cdi_uart_init(uint32_t package) { gpio_config_t io_conf = {0}; for (uint32_t i = 0; i < CDI_PORT_MAX; i++) { diff --git a/main/wired/cdi_uart.h b/main/wired/cdi_uart.h index 6063a8eb..1fc6a60a 100644 --- a/main/wired/cdi_uart.h +++ b/main/wired/cdi_uart.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2021, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _CDI_UART_H_ #define _CDI_UART_H_ -void cdi_uart_init(void); +void cdi_uart_init(uint32_t package); #endif /* _CDI_UART_H_ */ diff --git a/main/wired/jag_io.c b/main/wired/jag_io.c index 417e17cd..f15e785e 100644 --- a/main/wired/jag_io.c +++ b/main/wired/jag_io.c @@ -1,8 +1,9 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ +#include #include "jag_io.h" #include "sdkconfig.h" #if defined (CONFIG_BLUERETRO_SYSTEM_JAG) @@ -448,7 +449,7 @@ void jag_io_force_update(void) { #endif /* defined (CONFIG_BLUERETRO_SYSTEM_JAG */ } -void jag_io_init(void) { +void jag_io_init(uint32_t package) { #if defined (CONFIG_BLUERETRO_SYSTEM_JAG) gpio_config_t io_conf = {0}; uint8_t inputs[] = {P1_J0_PIN, P1_J1_PIN, P1_J2_PIN, P1_J3_PIN}; diff --git a/main/wired/jag_io.h b/main/wired/jag_io.h index 0791d2d0..66e2f984 100644 --- a/main/wired/jag_io.h +++ b/main/wired/jag_io.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +7,6 @@ #define _JAG_IO_H_ void jag_io_force_update(void); -void jag_io_init(void); +void jag_io_init(uint32_t package); #endif /* _JAG_IO_H_ */ diff --git a/main/wired/jvs_uart.c b/main/wired/jvs_uart.c index 6203262b..ca425c94 100644 --- a/main/wired/jvs_uart.c +++ b/main/wired/jvs_uart.c @@ -1,8 +1,9 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ +#include #include "jvs_uart.h" #include "sdkconfig.h" #if defined (CONFIG_BLUERETRO_SYSTEM_JVS) @@ -283,7 +284,7 @@ static unsigned uart_rx(unsigned cause) { } #endif /* defined (CONFIG_BLUERETRO_SYSTEM_JVS */ -void jvs_init(void) { +void jvs_init(uint32_t package) { #if defined (CONFIG_BLUERETRO_SYSTEM_JVS) gpio_config_t jvs_sense_conf = { .intr_type = GPIO_INTR_DISABLE, diff --git a/main/wired/jvs_uart.h b/main/wired/jvs_uart.h index c02bb466..c79245d2 100644 --- a/main/wired/jvs_uart.h +++ b/main/wired/jvs_uart.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _JVS_UART_H_ #define _JVS_UART_H_ -void jvs_init(void); +void jvs_init(uint32_t package); #endif /* _JVS_UART_H_ */ diff --git a/main/wired/maple.c b/main/wired/maple.c index 7c9cbeea..cfd682be 100644 --- a/main/wired/maple.c +++ b/main/wired/maple.c @@ -1,11 +1,12 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #include #include #include +#include #include "zephyr/types.h" #include "tools/util.h" #include "adapter/adapter.h" @@ -149,6 +150,7 @@ static uint32_t cur_us = 0, pre_us = 0; static struct maple_pkt pkt; static uint32_t rumble_max = 0x00020013; static uint32_t rumble_val = 0x10E0073B; +static uint32_t port_cnt = ARRAY_SIZE(gpio_pin); static inline void load_mouse_axes(uint8_t port, uint16_t *axes) { uint8_t *relative = (uint8_t *)(wired_adapter.data[port].output + 4); @@ -608,8 +610,13 @@ static unsigned maple_rx(unsigned cause) { return 0; } -void maple_init(void) +void maple_init(uint32_t package) { +#ifdef CONFIG_BLUERETRO_SYSTEM_DC + if (package == EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302) { + port_cnt = 1; + } +#endif maple_port_cfg(0x0); intexc_alloc_iram(ETS_GPIO_INTR_SOURCE, 19, maple_rx); } @@ -621,7 +628,7 @@ void maple_port_cfg(uint16_t mask) { io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; io_conf.pull_up_en = GPIO_PULLUP_DISABLE; - for (uint32_t i = 0; i < ARRAY_SIZE(gpio_pin); i++) { + for (uint32_t i = 0; i < port_cnt; i++) { if (mask & 0x1) { for (uint32_t j = 0; j < ARRAY_SIZE(gpio_pin[0]); j++) { diff --git a/main/wired/maple.h b/main/wired/maple.h index 228d3916..31a26f86 100644 --- a/main/wired/maple.h +++ b/main/wired/maple.h @@ -6,7 +6,7 @@ #ifndef _MAPLE_H_ #define _MAPLE_H_ -void maple_init(void); +void maple_init(uint32_t package); void maple_port_cfg(uint16_t mask); #endif /* _MAPLE_H_ */ diff --git a/main/wired/npiso_io.c b/main/wired/npiso_io.c index 01a20fe5..c421dd80 100644 --- a/main/wired/npiso_io.c +++ b/main/wired/npiso_io.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -498,7 +498,7 @@ static unsigned npiso_sfc_snes_5p_isr(unsigned cause) { return 0; } -void npiso_init(void) +void npiso_init(uint32_t package) { gpio_config_t io_conf = {0}; diff --git a/main/wired/npiso_io.h b/main/wired/npiso_io.h index 3fe436a1..2e46d5d6 100644 --- a/main/wired/npiso_io.h +++ b/main/wired/npiso_io.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2019-2020, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _NPISO_H_ #define _NPISO_H_ -void npiso_init(void); +void npiso_init(uint32_t package); #endif /* _NPISO_H_ */ diff --git a/main/wired/nsi.c b/main/wired/nsi.c index 32226d82..82abea2a 100644 --- a/main/wired/nsi.c +++ b/main/wired/nsi.c @@ -665,7 +665,7 @@ static unsigned gc_isr(unsigned cause) { return 0; } -void nsi_init(void) { +void nsi_init(uint32_t package) { uint32_t system = (wired_adapter.system_id == N64) ? 0 : 1; periph_ll_enable_clk_clear_rst(PERIPH_RMT_MODULE); diff --git a/main/wired/nsi.h b/main/wired/nsi.h index 74b7200e..87e362cd 100644 --- a/main/wired/nsi.h +++ b/main/wired/nsi.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -8,7 +8,7 @@ #include -void nsi_init(void); +void nsi_init(uint32_t package); void nsi_port_cfg(uint16_t mask); #endif /* _NSI_H_ */ diff --git a/main/wired/pce_io.c b/main/wired/pce_io.c index 0942f952..b332b9a1 100644 --- a/main/wired/pce_io.c +++ b/main/wired/pce_io.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -294,7 +294,7 @@ static unsigned pce_mouse_oe_isr(unsigned cause) { return 0; } -void pce_io_init(void) { +void pce_io_init(uint32_t package) { gpio_config_t io_conf = {0}; /* SEL */ diff --git a/main/wired/pce_io.h b/main/wired/pce_io.h index 30673c0a..24c216fa 100644 --- a/main/wired/pce_io.h +++ b/main/wired/pce_io.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2021, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _PCE_IO_H_ #define _PCE_IO_H_ -void pce_io_init(void); +void pce_io_init(uint32_t package); #endif /* _PCE_IO_H_ */ diff --git a/main/wired/pcfx_spi.c b/main/wired/pcfx_spi.c index a6058994..d8137246 100644 --- a/main/wired/pcfx_spi.c +++ b/main/wired/pcfx_spi.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -202,7 +202,7 @@ static unsigned latch_isr(unsigned cause) { return 0; } -void pcfx_spi_init(void) { +void pcfx_spi_init(uint32_t package) { gpio_config_t io_conf = {0}; for (uint32_t i = 0; i < PCFX_PORT_MAX; i++) { diff --git a/main/wired/pcfx_spi.h b/main/wired/pcfx_spi.h index dec7a797..44194a65 100644 --- a/main/wired/pcfx_spi.h +++ b/main/wired/pcfx_spi.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2021, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _PCFX_SPI_H_ #define _PCFX_SPI_H_ -void pcfx_spi_init(void); +void pcfx_spi_init(uint32_t package); #endif /* _PCFX_SPI_H_ */ diff --git a/main/wired/ps_spi.c b/main/wired/ps_spi.c index c5f74e67..7f1bbfa0 100644 --- a/main/wired/ps_spi.c +++ b/main/wired/ps_spi.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -665,7 +665,7 @@ static unsigned isr_dispatch(unsigned cause) { return 0; } -void ps_spi_init(void) { +void ps_spi_init(uint32_t package) { for (uint32_t i = 0; i < PS_PORT_MAX; i++) { memset(ps_ctrl_ports[i].dev_id, 0x41, sizeof(ps_ctrl_ports[0].dev_id)); memset(ps_ctrl_ports[i].pend_dev_id, 0x41, sizeof(ps_ctrl_ports[0].pend_dev_id)); diff --git a/main/wired/ps_spi.h b/main/wired/ps_spi.h index dd699464..f9134118 100644 --- a/main/wired/ps_spi.h +++ b/main/wired/ps_spi.h @@ -1,12 +1,12 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _PS_SPI_H_ #define _PS_SPI_H_ -void ps_spi_init(void); +void ps_spi_init(uint32_t package); void ps_spi_port_cfg(uint16_t mask); #endif /* _PS_SPI_H_ */ diff --git a/main/wired/real_spi.c b/main/wired/real_spi.c index d9b874fe..0244df5c 100644 --- a/main/wired/real_spi.c +++ b/main/wired/real_spi.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -190,7 +190,7 @@ static void cs_generator(void) { } } -void real_spi_init(void) { +void real_spi_init(uint32_t package) { gpio_config_t io_conf = {0}; /* CS Generator loopback */ diff --git a/main/wired/real_spi.h b/main/wired/real_spi.h index 9bf3e2ff..aabc7898 100644 --- a/main/wired/real_spi.h +++ b/main/wired/real_spi.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2021, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _REAL_SPI_H_ #define _REAL_SPI_H_ -void real_spi_init(void); +void real_spi_init(uint32_t package); #endif /* _REAL_SPI_H_ */ diff --git a/main/wired/sega_io.c b/main/wired/sega_io.c index 440f4d56..d474ef07 100644 --- a/main/wired/sega_io.c +++ b/main/wired/sega_io.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -935,7 +935,7 @@ static void ea_genesis_task(void) { } } -void sega_io_init(void) { +void sega_io_init(uint32_t package) { gpio_config_t io_conf = {0}; uint8_t port_cnt = 0; diff --git a/main/wired/sega_io.h b/main/wired/sega_io.h index 3046d3e6..65c7483d 100644 --- a/main/wired/sega_io.h +++ b/main/wired/sega_io.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2019-2020, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ #ifndef _SEGA_IO_H_ #define _SEGA_IO_H_ -void sega_io_init(void); +void sega_io_init(uint32_t package); #endif /* _SEGA_IO_H_ */ diff --git a/main/wired/wii_i2c.c b/main/wired/wii_i2c.c index c9c0f4b6..66c1c0af 100644 --- a/main/wired/wii_i2c.c +++ b/main/wired/wii_i2c.c @@ -292,7 +292,7 @@ static unsigned isr_dispatch(unsigned cause) { } #endif /* defined(CONFIG_BLUERETRO_SYSTEM_WII_EXT) || defined(CONFIG_BLUERETRO_SYSTEM_UNIVERSAL) */ -void wii_i2c_init(void) { +void wii_i2c_init(uint32_t package) { #if defined (CONFIG_BLUERETRO_SYSTEM_WII_EXT) || defined(CONFIG_BLUERETRO_SYSTEM_UNIVERSAL) for (uint32_t i = 0; i < WII_PORT_MAX; i++) { struct wii_ctrl_port *p = &wii_ctrl_ports[i]; diff --git a/main/wired/wii_i2c.h b/main/wired/wii_i2c.h index 80068e4b..7dd66435 100644 --- a/main/wired/wii_i2c.h +++ b/main/wired/wii_i2c.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, Jacques Gagnon + * Copyright (c) 2019-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -8,7 +8,7 @@ #include -void wii_i2c_init(void); +void wii_i2c_init(uint32_t package); void wii_i2c_port_cfg(uint16_t mask); #endif /* _WII_I2C_H_ */ diff --git a/main/wired/wired_bare.c b/main/wired/wired_bare.c index fcd09b6d..2176998e 100644 --- a/main/wired/wired_bare.c +++ b/main/wired/wired_bare.c @@ -1,8 +1,9 @@ /* - * Copyright (c) 2021-2022, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include "npiso_io.h" #include "cdi_uart.h" @@ -22,7 +23,7 @@ #define SPI_LL_RST_MASK (SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST) #define SPI_LL_UNUSED_INT_MASK (SPI_INT_EN | SPI_SLV_WR_STA_DONE | SPI_SLV_RD_STA_DONE | SPI_SLV_WR_BUF_DONE | SPI_SLV_RD_BUF_DONE) -typedef void (*wired_init_t)(void); +typedef void (*wired_init_t)(uint32_t package); typedef void (*wired_port_cfg_t)(uint16_t mask); static const char *sys_name[WIRED_MAX] = { @@ -106,9 +107,9 @@ static const wired_port_cfg_t wired_port_cfg[WIRED_MAX] = { NULL, /* SEA_BOARD */ }; -void wired_bare_init(void) { +void wired_bare_init(uint32_t package) { if (wired_init[wired_adapter.system_id]) { - wired_init[wired_adapter.system_id](); + wired_init[wired_adapter.system_id](package); } } diff --git a/main/wired/wired_bare.h b/main/wired/wired_bare.h index e5730d2a..f650e394 100644 --- a/main/wired/wired_bare.h +++ b/main/wired/wired_bare.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Jacques Gagnon + * Copyright (c) 2021-2023, Jacques Gagnon * SPDX-License-Identifier: Apache-2.0 */ @@ -56,10 +56,6 @@ #define HARDCODED_SYS SPI #endif -void wired_bare_init(void); -void wired_bare_port_cfg(uint16_t mask); -const char *wired_get_sys_name(void); - struct spi_cfg { spi_dev_t *hw; uint32_t write_bit_order; @@ -75,7 +71,7 @@ struct spi_cfg { uint32_t inten; }; -void wired_bare_init(void); +void wired_bare_init(uint32_t package); void wired_bare_port_cfg(uint16_t mask); const char *wired_get_sys_name(void); void spi_init(struct spi_cfg *cfg);