Skip to content

Commit

Permalink
Merge pull request #69 from xrobot-org/dev
Browse files Browse the repository at this point in the history
更新哨兵AI
  • Loading branch information
Jiu-xiao authored May 19, 2024
2 parents 2ed8fe1 + 841abde commit 198da2e
Show file tree
Hide file tree
Showing 43 changed files with 3,114 additions and 229 deletions.
Empty file added hw/bsp/esp32-s3-arduino/Kconfig
Empty file.
57 changes: 57 additions & 0 deletions hw/bsp/esp32-s3-arduino/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.16)

# Include for ESP-IDF build system functions
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)

add_compile_options(-Wno-missing-field-initializers -Wno-write-strings)
add_compile_definitions(ARDUINO_USB_CDC_ON_BOOT=1 ARDUINO_USB_MODE=1)

# Create idf::{target} and idf::freertos static libraries
idf_build_process("esp32s3"
# try and trim the build; additional components
# will be included as needed based on dependency tree
#
# although esptool_py does not generate static library,
# processing the component is needed for flashing related
# targets and file generation
COMPONENTS freertos esptool_py driver nvs_flash bt esp_http_client esp_https_ota arduino-esp32
SDKCONFIG ${BOARD_DIR}/sdkconfig
BUILD_DIR ${CMAKE_BINARY_DIR})

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(elf_file ${CMAKE_PROJECT_NAME}.elf)
add_executable(${elf_file} ${BOARD_DIR}/main.cpp)

# Link the static libraries to the executable
target_link_libraries(
${elf_file}
idf::bt
idf::freertos
idf::spi_flash
idf::driver
idf::nvs_flash
idf::esp_wifi
idf::esp_http_client
idf::esp_https_ota
idf::arduino-esp32
bsp
system
robot
)
# Attach additional targets to the executable file for flashing,
# linker script generation, partition_table generation, etc.
idf_build_executable(${elf_file})

add_subdirectory(${BOARD_DIR}/drivers)

# add_compile_options(-Wno-missing-field-initializers)

target_include_directories(
${PROJECT_NAME}.elf
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE $ENV{IDF_PATH}/components/esp_http_client/include
PRIVATE $<TARGET_PROPERTY:bsp,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE $<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE $<TARGET_PROPERTY:robot,INTERFACE_INCLUDE_DIRECTORIES>
)
94 changes: 94 additions & 0 deletions hw/bsp/esp32-s3-arduino/config/ble_net_config.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# CONFIG_auto_generated_config_prefix_board-esp32-c3-idf is not set
# CONFIG_auto_generated_config_prefix_board-c-mini is not set
# CONFIG_auto_generated_config_prefix_board-raspi_4b_with_ch348 is not set
# CONFIG_auto_generated_config_prefix_board-node_imu is not set
CONFIG_auto_generated_config_prefix_board-esp32-s3-arduino=y
# CONFIG_auto_generated_config_prefix_board-f103_can is not set
# CONFIG_auto_generated_config_prefix_board-MiniPC is not set
# CONFIG_auto_generated_config_prefix_board-rm-c is not set
# CONFIG_auto_generated_config_prefix_board-microswitch is not set
# CONFIG_auto_generated_config_prefix_board-Webots is not set
# CONFIG_auto_generated_config_prefix_board-wl_f103_can is not set
# CONFIG_auto_generated_config_prefix_board-demo-board is not set
# CONFIG_auto_generated_config_prefix_system-Linux_Webots is not set
CONFIG_auto_generated_config_prefix_system-FreeRTOS=y
# CONFIG_auto_generated_config_prefix_system-None is not set
# CONFIG_auto_generated_config_prefix_system-Linux is not set
CONFIG_INIT_TASK_STACK_DEPTH=4096

#
# FreeRTOS
#
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048
CONFIG_FREERTOS_USB_TASK_STACK_DEPTH=1024
CONFIG_FREERTOS_TERM_TASK_STACK_DEPTH=1024
# end of FreeRTOS

# CONFIG_auto_generated_config_prefix_robot-udp_to_uart is not set
# CONFIG_auto_generated_config_prefix_robot-hero is not set
# CONFIG_auto_generated_config_prefix_robot-balance_infantry is not set
# CONFIG_auto_generated_config_prefix_robot-sentry is not set
# CONFIG_auto_generated_config_prefix_robot-dart is not set
CONFIG_auto_generated_config_prefix_robot-ble_net_config=y
# CONFIG_auto_generated_config_prefix_robot-can_to_uart is not set
# CONFIG_auto_generated_config_prefix_robot-infantry is not set
# CONFIG_auto_generated_config_prefix_robot-sim_mecanum is not set
# CONFIG_auto_generated_config_prefix_robot-blink is not set
# CONFIG_auto_generated_config_prefix_robot-microswitch is not set
# CONFIG_auto_generated_config_prefix_robot-sim_balance is not set
# CONFIG_auto_generated_config_prefix_robot-engineer is not set
# CONFIG_auto_generated_config_prefix_robot-wearlab_imu is not set
# CONFIG_auto_generated_config_prefix_robot-demo-robot is not set

#
# 组件
#
# CONFIG_auto_generated_config_prefix_component-demo-component is not set
# end of 组件

#
# 设备
#
# CONFIG_auto_generated_config_prefix_device-servo is not set
# CONFIG_auto_generated_config_prefix_device-simulator is not set
# CONFIG_auto_generated_config_prefix_device-cap is not set
# CONFIG_auto_generated_config_prefix_device-led_rgb is not set
# CONFIG_auto_generated_config_prefix_device-referee is not set
# CONFIG_auto_generated_config_prefix_device-laser is not set
# CONFIG_auto_generated_config_prefix_device-can is not set
# CONFIG_auto_generated_config_prefix_device-motor is not set
# CONFIG_auto_generated_config_prefix_device-bmi088 is not set
# CONFIG_auto_generated_config_prefix_device-mech is not set
# CONFIG_auto_generated_config_prefix_device-buzzer is not set
# CONFIG_auto_generated_config_prefix_device-tof is not set
CONFIG_auto_generated_config_prefix_device-blink_led=y
# CONFIG_auto_generated_config_prefix_device-dr16 is not set
# CONFIG_auto_generated_config_prefix_device-ahrs is not set
# CONFIG_auto_generated_config_prefix_device-ai is not set
CONFIG_auto_generated_config_prefix_device-net_config=y
# CONFIG_auto_generated_config_prefix_device-wearlab is not set
# CONFIG_auto_generated_config_prefix_device-imu is not set
# CONFIG_auto_generated_config_prefix_device-microswitch is not set
# CONFIG_auto_generated_config_prefix_device-demo-device is not set
# end of 设备

#
# 模块
#
# CONFIG_auto_generated_config_prefix_module-gimbal is not set
# CONFIG_auto_generated_config_prefix_module-balance is not set
# CONFIG_auto_generated_config_prefix_module-chassis is not set
# CONFIG_auto_generated_config_prefix_module-dart_launcher is not set
CONFIG_auto_generated_config_prefix_module-ble_net_config=y
# CONFIG_auto_generated_config_prefix_module-launcher is not set
# CONFIG_auto_generated_config_prefix_module-ore_collect is not set
# CONFIG_auto_generated_config_prefix_module-can_usart is not set
# CONFIG_auto_generated_config_prefix_module-uart_udp is not set
CONFIG_auto_generated_config_prefix_module-topic_share_uart=y
# CONFIG_auto_generated_config_prefix_module-microswitch is not set
# CONFIG_auto_generated_config_prefix_module-can_imu is not set
# CONFIG_auto_generated_config_prefix_module-wheel_leg is not set
# CONFIG_auto_generated_config_prefix_module-dart_gimbal is not set
# CONFIG_auto_generated_config_prefix_module-wl_can_usart is not set
# CONFIG_auto_generated_config_prefix_module-demo-module is not set
# end of 模块
58 changes: 58 additions & 0 deletions hw/bsp/esp32-s3-arduino/config/blink.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
CONFIG_auto_generated_config_prefix_board-esp32-s3-arduino=y
# CONFIG_auto_generated_config_prefix_board-node_imu is not set
# CONFIG_auto_generated_config_prefix_board-MiniPC is not set
# CONFIG_auto_generated_config_prefix_board-rm-c is not set
# CONFIG_auto_generated_config_prefix_board-Webots is not set
# CONFIG_auto_generated_config_prefix_system-Linux_Webots is not set
CONFIG_auto_generated_config_prefix_system-FreeRTOS=y
# CONFIG_auto_generated_config_prefix_system-Linux is not set
CONFIG_INIT_TASK_STACK_DEPTH=2048

#
# FreeRTOS
#
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=1024
CONFIG_FREERTOS_USB_TASK_STACK_DEPTH=1024
CONFIG_FREERTOS_TERM_TASK_STACK_DEPTH=1024
# end of FreeRTOS

# CONFIG_auto_generated_config_prefix_robot-balance_infantry is not set
# CONFIG_auto_generated_config_prefix_robot-infantry is not set
# CONFIG_auto_generated_config_prefix_robot-sim_mecanum is not set
CONFIG_auto_generated_config_prefix_robot-blink=y
CONFIG_auto_generated_config_prefix_module-performance=y
# CONFIG_auto_generated_config_prefix_robot-sim_balance is not set
# CONFIG_auto_generated_config_prefix_robot-wearlab_imu is not set

#
# 设备
#
# CONFIG_auto_generated_config_prefix_device-servo is not set
# CONFIG_auto_generated_config_prefix_device-simulator is not set
# CONFIG_auto_generated_config_prefix_device-cap is not set
# CONFIG_auto_generated_config_prefix_device-led_rgb is not set
# CONFIG_auto_generated_config_prefix_device-referee is not set
# CONFIG_auto_generated_config_prefix_device-laser is not set
# CONFIG_auto_generated_config_prefix_device-can is not set
# CONFIG_auto_generated_config_prefix_device-motor is not set
# CONFIG_auto_generated_config_prefix_device-bmi088 is not set
# CONFIG_auto_generated_config_prefix_device-buzzer is not set
# CONFIG_auto_generated_config_prefix_device-tof is not set
CONFIG_auto_generated_config_prefix_device-blink_led=y
# CONFIG_auto_generated_config_prefix_device-dr16 is not set
# CONFIG_auto_generated_config_prefix_device-ahrs is not set
# CONFIG_auto_generated_config_prefix_device-ai is not set
# CONFIG_auto_generated_config_prefix_device-wearlab is not set
# CONFIG_auto_generated_config_prefix_device-imu is not set
# end of 设备

#
# 模块
#
# CONFIG_auto_generated_config_prefix_module-gimbal is not set
# CONFIG_auto_generated_config_prefix_module-balance is not set
# CONFIG_auto_generated_config_prefix_module-chassis is not set
# CONFIG_auto_generated_config_prefix_module-launcher is not set
# CONFIG_auto_generated_config_prefix_module-can_imu is not set
# CONFIG_auto_generated_config_prefix_module-wheel_leg is not set
# end of 模块
36 changes: 36 additions & 0 deletions hw/bsp/esp32-s3-arduino/debug/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"configurations": [
{
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/build/xrobot.elf",
"name": "Debug with OpenOCD",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"configFiles": [
"board/esp32c3-builtin.cfg"
],
"gdbPath": "riscv32-esp-elf-gdb",
"searchDir": [],
"runToEntryPoint": "app_main",
"postLaunchCommands": [
"mon reset halt",
"flushregs",
"mon program_esp build/bootloader/bootloader.bin 0x0 verify",
"mon program_esp build/partition_table/partition-table.bin 0x8000 verify",
"mon program_esp build/xrobot.bin 0x10000 verify",
"set remote hardware-watchpoint-limit 2",
"mon reset halt",
"flushregs"
]
}
]
}
35 changes: 35 additions & 0 deletions hw/bsp/esp32-s3-arduino/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
project(bsp)

file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")

file(GLOB ${PROJECT_NAME}_SOURCES_CPP "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")

add_library(${PROJECT_NAME} STATIC)

target_sources(${PROJECT_NAME}
PRIVATE ${${PROJECT_NAME}_SOURCES}
PRIVATE ${${PROJECT_NAME}_SOURCES_CPP}
)

include(${MCU_DIR}/default/CMakeLists.txt)

target_link_libraries(${PROJECT_NAME}
PUBLIC idf::arduino-esp32
PUBLIC idf::bt
)

target_include_directories(
${PROJECT_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC $<TARGET_PROPERTY:OneMessage,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC $<TARGET_PROPERTY:idf::freertos,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC $<TARGET_PROPERTY:idf::driver,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC $<TARGET_PROPERTY:idf::nvs_flash,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC $<TARGET_PROPERTY:idf::esp_timer,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC $<TARGET_PROPERTY:idf::bt,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC $<TARGET_PROPERTY:idf::arduino-esp32,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC $ENV{IDF_PATH}/components/freertos/include/freertos
PUBLIC $ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos
)

# add_dependencies(${PROJECT_NAME})
12 changes: 12 additions & 0 deletions hw/bsp/esp32-s3-arduino/drivers/bsp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "bsp.h"

#include "bsp_time.h"
#include "bsp_uart.h"
#include "driver/gpio.h"

void bsp_init() {
bsp_time_init();
gpio_reset_pin(GPIO_NUM_8);
gpio_set_direction(GPIO_NUM_8, GPIO_MODE_OUTPUT);
bsp_uart_init();
}
18 changes: 18 additions & 0 deletions hw/bsp/esp32-s3-arduino/drivers/bsp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "bsp_def.h"

typedef struct {
void (*fn)(void *);
void *arg;
} bsp_callback_t;

void bsp_init(void);

#ifdef __cplusplus
}
#endif
57 changes: 57 additions & 0 deletions hw/bsp/esp32-s3-arduino/drivers/bsp_ble_server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "bsp_ble_server.h"

#include <stdint.h>

#include "Arduino.h"
#include "BLEDevice.h"
#include "om.h"
#include "om_fifo.h"

#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define WIFI_CONFIG_UUID "5fafc202-2fb5-469e-8fcc-c5c9c332914b"

static om_fifo_t rx_fifo;
static uint8_t buff[100];
static BLECharacteristic *p_wifi_config_characteristic;

class WifiConfigCallback : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
om_fifo_writes(&rx_fifo, pCharacteristic->getData(),
pCharacteristic->getLength());
}
};

void bsp_ble_server_init(const char *name) {
om_fifo_create(&rx_fifo, buff, sizeof(buff), sizeof(uint8_t));
BLEDevice::init(name);
BLEServer *p_server = BLEDevice::createServer();
BLEService *p_service = p_server->createService(SERVICE_UUID);
p_wifi_config_characteristic = p_service->createCharacteristic(
WIFI_CONFIG_UUID,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);

p_wifi_config_characteristic->setCallbacks(new WifiConfigCallback());

p_service->start();
BLEAdvertising *p_advertising = BLEDevice::getAdvertising();
p_advertising->addServiceUUID(SERVICE_UUID);
p_advertising->setScanResponse(true);
p_advertising->setMinPreferred(0x06);
p_advertising->setMinPreferred(0x12);

BLEDevice::startAdvertising();
}

uint32_t bsp_ble_server_avaliable() {
return om_fifo_readable_item_count(&rx_fifo);
}

bsp_status_t bsp_ble_server_transmit(const uint8_t *data, size_t size) {
memcpy(buff, data, size);
p_wifi_config_characteristic->setValue(buff, size);
return BSP_OK;
}

uint32_t bsp_ble_server_receive(uint8_t *data, size_t size) {
return om_fifo_reads(&rx_fifo, data, size) == OM_OK ? 0 : size;
}
11 changes: 11 additions & 0 deletions hw/bsp/esp32-s3-arduino/drivers/bsp_ble_server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "bsp.h"

void bsp_ble_server_init(const char *name);

uint32_t bsp_ble_server_avaliable();

bsp_status_t bsp_ble_server_transmit(const uint8_t *data, size_t size);

uint32_t bsp_ble_server_receive(uint8_t *data, size_t size);
Loading

0 comments on commit 198da2e

Please sign in to comment.