Skip to content

Commit

Permalink
arch: move "arch" files to the arch folder
Browse files Browse the repository at this point in the history
Each arch (ESP32, Pico, Linux) must implement them
  • Loading branch information
ricardoquesada committed Nov 24, 2023
1 parent fd8a942 commit 481f8a5
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 142 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Instead, "pc_debug" still exists, but internally uses "custom" platform.
- Allowlist: rename `uni_bt_allowlist_allow_addr()` to `uni_bt_allowlist_is_allowed_addr()`
- Folder organization:
- arch/: includes console, uart, property files (one for each: ESP32, Pico, Linux)
- bt/: includes all the Bluetooth related files
- platform/: includes all the platform files
- parser:/ includes all the parser files
Expand Down
4 changes: 3 additions & 1 deletion examples/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ clean_src:
rm -rf * ${BTSTACK_ROOT}/platform/embedded/*.o

bluepad32: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} ${SDP_CLIENT} btstack_ring_buffer.o btstack_hid_parser.o \
${BLUEPAD32_ROOT}/arch/uni_console_linux.o \
${BLUEPAD32_ROOT}/arch/uni_property_linux.o \
${BLUEPAD32_ROOT}/arch/uni_uart_linux.o \
${BLUEPAD32_ROOT}/bt/uni_bt.o \
${BLUEPAD32_ROOT}/bt/uni_bt_allowlist.o \
${BLUEPAD32_ROOT}/bt/uni_bt_bredr.o \
Expand Down Expand Up @@ -112,7 +115,6 @@ bluepad32: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} ${SDP_CLIENT} btstack_ring_b
${BLUEPAD32_ROOT}/uni_joystick.o \
${BLUEPAD32_ROOT}/uni_log.o \
${BLUEPAD32_ROOT}/uni_property.o \
${BLUEPAD32_ROOT}/uni_property_mem.o \
${BLUEPAD32_ROOT}/uni_utils.o \
${BLUEPAD32_ROOT}/uni_virtual_device.o
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
Expand Down
12 changes: 7 additions & 5 deletions src/components/bluepad32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ if(IDF_TARGET)
# This files call ESP-IDF functions and should be ported/converted
# so that can be called from other targets like Pico W
list(APPEND srcs
"uni_console.c"
"uni_esp32.c"
"arch/uni_console_esp32.c"
"arch/uni_property_esp32.c"
"arch/uni_uart_esp32.c"
"uni_gpio.c"
"uni_mouse_quadrature.c"
"uni_property_nvs.c")
"uni_mouse_quadrature.c")
elseif(PICO_SDK_VERSION_STRING)
list(APPEND srcs
"uni_property_mem.c")
"arch/uni_console_pico.c"
"arch/uni_property_pico.c"
"arch/uni_uart_pico.c")
endif()

if(CONFIG_IDF_TARGET_ESP32)
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions src/components/bluepad32/arch/uni_console_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Ricardo Quesada
// http://retro.moe/unijoysticle2

#include "uni_console.h"

void uni_console_init(void) {
// FIXME: Implement me
}
9 changes: 9 additions & 0 deletions src/components/bluepad32/arch/uni_console_pico.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Ricardo Quesada
// http://retro.moe/unijoysticle2

#include "uni_console.h"

void uni_console_init(void) {
// FIXME: Implement me
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/

#include "uni_property_nvs.h"
#include "uni_property.h"

#include <nvs.h>
#include <nvs_flash.h>
Expand All @@ -28,7 +28,7 @@ static const char* STORAGE_NAMESPACE = "bp32";

// Uses NVS for storage. Used in all ESP32 Bluepad32 platforms.

void uni_property_nvs_set(const char* key, uni_property_type_t type, uni_property_value_t value) {
void uni_property_set(const char* key, uni_property_type_t type, uni_property_value_t value) {
nvs_handle_t nvs_handle;
esp_err_t err;
uint32_t* float_alias;
Expand Down Expand Up @@ -69,7 +69,7 @@ void uni_property_nvs_set(const char* key, uni_property_type_t type, uni_propert
nvs_close(nvs_handle);
}

uni_property_value_t uni_property_nvs_get(const char* key, uni_property_type_t type, uni_property_value_t def) {
uni_property_value_t uni_property_get(const char* key, uni_property_type_t type, uni_property_value_t def) {
nvs_handle_t nvs_handle;
esp_err_t err;
uni_property_value_t ret;
Expand Down Expand Up @@ -111,7 +111,7 @@ uni_property_value_t uni_property_nvs_get(const char* key, uni_property_type_t t
return ret;
}

void uni_property_nvs_init() {
void uni_property_init() {
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
logi("Erasing flash\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/

#include "uni_property_mem.h"
#include "uni_property.h"

#include "uni_common.h"

// TODO: Implement a memory cache.
// Used only in non-ESP32 platforms.
// Short-term solution: just return the default value.

void uni_property_mem_set(const char* key, uni_property_type_t type, uni_property_value_t value) {
void uni_property_set(const char* key, uni_property_type_t type, uni_property_value_t value) {
ARG_UNUSED(key);
ARG_UNUSED(type);
ARG_UNUSED(value);
/* Nothing */
}

uni_property_value_t uni_property_mem_get(const char* key, uni_property_type_t type, uni_property_value_t def) {
uni_property_value_t uni_property_get(const char* key, uni_property_type_t type, uni_property_value_t def) {
ARG_UNUSED(key);
ARG_UNUSED(type);

return def;
}

void uni_property_mem_init(void) {
void uni_property_init(void) {
/* Nothing */
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@ See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/

#ifndef UNI_PROPERTY_MEM_H
#define UNI_PROPERTY_MEM_H

#include "uni_property.h"

void uni_property_mem_init(void);
void uni_property_mem_set(const char* key, uni_property_type_t type, uni_property_value_t value);
uni_property_value_t uni_property_mem_get(const char* key, uni_property_type_t type, uni_property_value_t def);
#include "uni_common.h"

// TODO: Implement a memory cache.
// Used only in non-ESP32 platforms.
// Short-term solution: just return the default value.

void uni_property_set(const char* key, uni_property_type_t type, uni_property_value_t value) {
ARG_UNUSED(key);
ARG_UNUSED(type);
ARG_UNUSED(value);
/* Nothing */
}

uni_property_value_t uni_property_get(const char* key, uni_property_type_t type, uni_property_value_t def) {
ARG_UNUSED(key);
ARG_UNUSED(type);

return def;
}

#endif // UNI_PROPERTY_MEM_H
void uni_property_init(void) {
/* Nothing */
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
/****************************************************************************
http://retro.moe/unijoysticle2
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019-2023 Ricardo Quesada
// http://retro.moe/unijoysticle2

Copyright 2019 Ricardo Quesada
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/

#include "uni_esp32.h"
#include "uni_uart.h"

#include "sdkconfig.h"

Expand All @@ -36,7 +22,6 @@ limitations under the License.
#include <hci_dump_embedded_stdout.h>

#include "uni_config.h"
#include "uni_init.h"

#ifdef UNI_ENABLE_BREDR
_Static_assert(CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN >= 2, "Max ACL must be >= 2");
Expand Down Expand Up @@ -77,7 +62,7 @@ void uni_esp32_enable_uart_output(bool enabled) {
#endif // CONFIG_IDF_TARGET_ESP32
}

void uni_esp32_init(void) {
void uni_uart_init(void) {
#ifdef CONFIG_BLUEPAD32_UART_OUTPUT_ENABLE
uni_esp32_enable_uart_output(1);
#else
Expand All @@ -86,4 +71,4 @@ void uni_esp32_init(void) {
// noise and can break the communication with the controller.
uni_esp32_enable_uart_output(0);
#endif
}
}
15 changes: 15 additions & 0 deletions src/components/bluepad32/arch/uni_uart_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019-2023 Ricardo Quesada
// http://retro.moe/unijoysticle2

#include "uni_uart.h"

#include "uni_common.h"

void uni_uart_enable_output(bool enabled) {
ARG_UNUSED(enabled);

// Fixme: Implement me
}

void uni_uart_init(void) {}
15 changes: 15 additions & 0 deletions src/components/bluepad32/arch/uni_uart_pico.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019-2023 Ricardo Quesada
// http://retro.moe/unijoysticle2

#include "uni_uart.h"

#include "uni_common.h"

void uni_uart_enable_output(bool enabled) {
ARG_UNUSED(enabled);

// Fixme: Implement me
}

void uni_uart_init(void) {}
2 changes: 0 additions & 2 deletions src/components/bluepad32/include/uni.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ extern "C" {
#include "uni_log.h"
#include "uni_mouse_quadrature.h"
#include "uni_property.h"
#include "uni_property_mem.h"
#include "uni_property_nvs.h"
#include "uni_utils.h"
#include "uni_virtual_device.h"

Expand Down
3 changes: 3 additions & 0 deletions src/components/bluepad32/include/uni_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ limitations under the License.
#ifndef UNI_CONSOLE_H
#define UNI_CONSOLE_H

// Interface
// Each arch needs to implement these functions

void uni_console_init(void);

#endif // UNI_CONSOLE_H
27 changes: 0 additions & 27 deletions src/components/bluepad32/include/uni_esp32.h

This file was deleted.

16 changes: 9 additions & 7 deletions src/components/bluepad32/include/uni_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ typedef enum {
UNI_PROPERTY_TYPE_STRING,
} uni_property_type_t;

typedef union {
uint8_t u8;
uint32_t u32;
float f32;
char* str;
} uni_property_value_t;

// Bluepad32-global properties
// Keep them sorted
extern const char* UNI_PROPERTY_KEY_ALLOWLIST_ENABLED;
Expand All @@ -52,13 +59,8 @@ extern const char* UNI_PROPERTY_KEY_UNI_MOUSE_EMULATION;
extern const char* UNI_PROPERTY_KEY_UNI_SERIAL_NUMBER;
extern const char* UNI_PROPERTY_KEY_UNI_VENDOR;

typedef union {
uint8_t u8;
uint32_t u32;
float f32;
char* str;
} uni_property_value_t;

// Interface
// Each arch needs to implement these functions
void uni_property_init(void);
void uni_property_set(const char* key, uni_property_type_t type, uni_property_value_t value);
uni_property_value_t uni_property_get(const char* key, uni_property_type_t type, uni_property_value_t def);
Expand Down
28 changes: 0 additions & 28 deletions src/components/bluepad32/include/uni_property_nvs.h

This file was deleted.

16 changes: 16 additions & 0 deletions src/components/bluepad32/include/uni_uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019-2023 Ricardo Quesada
// http://retro.moe/unijoysticle2

#ifndef UNI_UART_H
#define UNI_UART_H

#include <stdbool.h>

// Interface
// Each arch needs to implement these functions

void uni_uart_init(void);
void uni_uart_enable_output(bool enabled);

#endif // UNI_UART_H
Loading

0 comments on commit 481f8a5

Please sign in to comment.