Skip to content

Commit

Permalink
[WIRED] Pass package info down to wired init functions
Browse files Browse the repository at this point in the history
Fixes #733
  • Loading branch information
darthcloud committed Aug 12, 2023
1 parent 157deda commit d6bd682
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 65 deletions.
12 changes: 10 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <freertos/task.h>
#include <esp_ota_ops.h>
#include <esp32/rom/ets_sys.h>
#include <soc/efuse_reg.h>
#include <esp_efuse.h>
#include "system/bare_metal_app_cpu.h"
#include "system/core0_stall.h"
#include "system/delay.h"
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 3 additions & 5 deletions main/system/led.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "soc/efuse_reg.h"
#include "esp_efuse.h"
#include <soc/efuse_reg.h>
#include "zephyr/atomic.h"
#include "system/gpio.h"
#include "driver/ledc.h"
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions main/system/led.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -8,7 +8,7 @@

#include <stdint.h>

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);
Expand Down
4 changes: 2 additions & 2 deletions main/wired/cdi_uart.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Jacques Gagnon
* Copyright (c) 2021-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions main/wired/cdi_uart.h
Original file line number Diff line number Diff line change
@@ -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_ */
5 changes: 3 additions & 2 deletions main/wired/jag_io.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdint.h>
#include "jag_io.h"
#include "sdkconfig.h"
#if defined (CONFIG_BLUERETRO_SYSTEM_JAG)
Expand Down Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions main/wired/jag_io.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright (c) 2021, Jacques Gagnon
* Copyright (c) 2021-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef _JAG_IO_H_
#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_ */
5 changes: 3 additions & 2 deletions main/wired/jvs_uart.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdint.h>
#include "jvs_uart.h"
#include "sdkconfig.h"
#if defined (CONFIG_BLUERETRO_SYSTEM_JVS)
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions main/wired/jvs_uart.h
Original file line number Diff line number Diff line change
@@ -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_ */
13 changes: 10 additions & 3 deletions main/wired/maple.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

#include <string.h>
#include <esp_timer.h>
#include <esp32/rom/ets_sys.h>
#include <soc/efuse_reg.h>
#include "zephyr/types.h"
#include "tools/util.h"
#include "adapter/adapter.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion main/wired/maple.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
4 changes: 2 additions & 2 deletions main/wired/npiso_io.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -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};

Expand Down
4 changes: 2 additions & 2 deletions main/wired/npiso_io.h
Original file line number Diff line number Diff line change
@@ -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_ */
2 changes: 1 addition & 1 deletion main/wired/nsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions main/wired/nsi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -8,7 +8,7 @@

#include <stdint.h>

void nsi_init(void);
void nsi_init(uint32_t package);
void nsi_port_cfg(uint16_t mask);

#endif /* _NSI_H_ */
4 changes: 2 additions & 2 deletions main/wired/pce_io.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Jacques Gagnon
* Copyright (c) 2021-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions main/wired/pce_io.h
Original file line number Diff line number Diff line change
@@ -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_ */
4 changes: 2 additions & 2 deletions main/wired/pcfx_spi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions main/wired/pcfx_spi.h
Original file line number Diff line number Diff line change
@@ -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_ */
4 changes: 2 additions & 2 deletions main/wired/ps_spi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, Jacques Gagnon
* Copyright (c) 2019-2023, Jacques Gagnon
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions main/wired/ps_spi.h
Original file line number Diff line number Diff line change
@@ -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_ */
Loading

0 comments on commit d6bd682

Please sign in to comment.