Skip to content

Commit

Permalink
feat: transports list, new device support
Browse files Browse the repository at this point in the history
* refactor: use transports list

* refactor: transports list, secondary serial for we2

* refactor: support transports list

* refactor: disable mirror/flip

* chore: add dev board

* fix: signed compare
  • Loading branch information
iChizer0 committed Mar 14, 2024
1 parent 223733e commit 41cf3f1
Show file tree
Hide file tree
Showing 18 changed files with 456 additions and 73 deletions.
10 changes: 5 additions & 5 deletions core/algorithm/el_algorithm_yolo_pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ bool AlgorithmYOLOPOSE::is_model_valid(const EngineType* engine) {
auto it = std::find_if(anchor_strides_1.begin(),
anchor_strides_1.end(),
[&output_shape](const types::anchor_stride_t& anchor_stride) {
return anchor_stride.size == output_shape.dims[1];
return static_cast<int>(anchor_stride.size) == output_shape.dims[1];
});
if (it == anchor_strides_1.end())
return false;
Expand All @@ -225,7 +225,7 @@ bool AlgorithmYOLOPOSE::is_model_valid(const EngineType* engine) {
auto it = std::find_if(anchor_strides_2.begin(),
anchor_strides_2.end(),
[&output_shape](const types::anchor_stride_t& anchor_stride) {
return anchor_stride.size == output_shape.dims[1];
return static_cast<int>(anchor_stride.size) == output_shape.dims[1];
});
if (it == anchor_strides_2.end())
return false;
Expand All @@ -234,7 +234,7 @@ bool AlgorithmYOLOPOSE::is_model_valid(const EngineType* engine) {
} break;
default:
if (output_shape.dims[2] % 3 != 0) return false;
if (output_shape.dims[1] != sum) return false;
if (output_shape.dims[1] != static_cast<int>(sum)) return false;
}
}

Expand Down Expand Up @@ -311,15 +311,15 @@ inline void AlgorithmYOLOPOSE::init() {
switch (dim_2) {
case 1:
for (size_t j = 0; j < _anchor_variants; ++j) {
if (dim_1 == _anchor_strides[j].size) {
if (dim_1 == static_cast<int>(_anchor_strides[j].size)) {
_output_scores_ids[j] = i;
break;
}
}
break;
case 64:
for (size_t j = 0; j < _anchor_variants; ++j) {
if (dim_1 == _anchor_strides[j].size) {
if (dim_1 == static_cast<int>(_anchor_strides[j].size)) {
_output_bboxes_ids[j] = i;
break;
}
Expand Down
7 changes: 7 additions & 0 deletions core/el_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ typedef struct EL_ATTR_PACKED el_model_info_t {

typedef uint8_t el_model_id_t;

typedef enum {
EL_TRANSPORT_UNKNOWN = 0,
EL_TRANSPORT_UART,
EL_TRANSPORT_SPI,
EL_TRANSPORT_I2C,
} el_transport_type_t;

#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 6 additions & 9 deletions porting/el_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class Device {

Camera* get_camera() { return _camera; }
Display* get_display() { return _display; }
Serial* get_serial() { return _serial; }

const std::forward_list<Transport*>& get_transports() { return _transports; }

Network* get_network() { return _network; }
Wire* get_wire() { return _wire; }
SSPI* get_sspi() { return _sspi; }

el_sensor_info_t get_sensor_info(uint8_t id) const {
auto it = std::find_if(_registered_sensors.begin(), _registered_sensors.end(), [&](const el_sensor_info_t& s) {
Expand Down Expand Up @@ -110,22 +110,19 @@ class Device {
_revision_id(0),
_camera(nullptr),
_display(nullptr),
_serial(nullptr),
_network{nullptr},
_sspi(nullptr),
_wire(nullptr) {}
_transports{},
_registered_sensors{} {}

const char* _device_name;
uint32_t _device_id;
uint32_t _revision_id;

Camera* _camera;
Display* _display;
Serial* _serial;
Network* _network;
SSPI* _sspi;
Wire* _wire;

std::forward_list<Transport*> _transports;
std::forward_list<el_sensor_info_t> _registered_sensors;
};

Expand Down
4 changes: 3 additions & 1 deletion porting/el_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ namespace edgelab {
// No status transport protocol (framed), TCP alternative should have a server class, a connection could derive from Transport
class Transport {
public:
Transport() : _is_present(false) {}
el_transport_type_t type;

Transport() : type(EL_TRANSPORT_UNKNOWN), _is_present(false) {}
virtual ~Transport() = default;

virtual std::size_t read_bytes(char* buffer, size_t size) = 0;
Expand Down
2 changes: 1 addition & 1 deletion porting/espressif/el_device_esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void DeviceEsp::init() {
static SerialEsp serial{
usb_serial_jtag_driver_config_t{.tx_buffer_size = 8192, .rx_buffer_size = 8192}
};
this->_serial = &serial;
this->_transports.emplace_front(&serial);

static NetworkEsp network{};
this->_network = &network;
Expand Down
2 changes: 1 addition & 1 deletion porting/himax/we1/el_device_we1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void DeviceWE1::init() {
.id = ++sensor_id, .type = el_sensor_type_t::EL_SENSOR_TYPE_CAM, .state = el_sensor_state_t::EL_SENSOR_STA_REG});

static SerialWE1 serial{};
this->_serial = &serial;
this->_transports.emplace_front(&serial);
}

void DeviceWE1::restart() {
Expand Down
80 changes: 80 additions & 0 deletions porting/himax/we2/boards/dev_board/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* The MIT License (MIT)
*
* Copyright (c) Seeed Technology Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#ifndef _BOARD_DEV_BOARD_WE2_H_
#define _BOARD_DEV_BOARD_WE2_H_

#define PRODUCT_NAME_PREFIX "dev_board"
#define PRODUCT_NAME_SUFFIX "v1"
#define DEVICE_NAME (PRODUCT_NAME_PREFIX "_" PRODUCT_NAME_SUFFIX)
#define PORT_DEVICE_NAME "Dev Board"

#ifdef __cplusplus
extern "C" {
#endif

#include <WE2_device.h>
#include <hx_drv_gpio.h>
#include <hx_drv_scu.h>
#include <hx_drv_scu_export.h>

#ifdef TRUSTZONE_SEC
#if (__ARM_FEATURE_CMSE & 1) == 0
#error "Need ARMv8-M security extensions"
#elif (__ARM_FEATURE_CMSE & 2) == 0
#error "Compile with --cmse"
#endif

#include <arm_cmse.h>

#ifdef NSC
#include <veneer_table.h>
#endif
/* Trustzone config. */

#ifndef TRUSTZONE_SEC_ONLY
/* FreeRTOS includes. */
#include <secure_port_macros.h>
#endif
#endif

#define CONFIG_EL_CAMERA_PWR_CTRL_INIT_F \
{ \
hx_drv_gpio_set_output(AON_GPIO1, GPIO_OUT_LOW); \
hx_drv_scu_set_PA1_pinmux(SCU_PA1_PINMUX_AON_GPIO1, 0); \
hx_drv_gpio_set_out_value(AON_GPIO1, GPIO_OUT_LOW); \
}

#define CONFIG_EL_SPI_CS_INIT_F \
{ hx_drv_scu_set_PB5_pinmux(SCU_PB5_PINMUX_SPI_S_CS, 1); }
#define CONFIG_EL_SPI_CTRL_INIT_F \
{ hx_drv_scu_set_PB8_pinmux(SCU_PB8_PINMUX_GPIO2_1, 1); }
#define CONFIG_EL_SPI_CTRL_PIN GPIO21

#ifdef __cplusplus
}
#endif

#endif
18 changes: 16 additions & 2 deletions porting/himax/we2/boards/grove_vision_ai_we2/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@
#ifndef _BOARD_GROVE_VISION_AI_WE2_H_
#define _BOARD_GROVE_VISION_AI_WE2_H_


#define PRODUCT_NAME_PREFIX "grove_vision_ai"
#define PRODUCT_NAME_SUFFIX "v2"
#define DEVICE_NAME (PRODUCT_NAME_PREFIX "_" PRODUCT_NAME_SUFFIX)
#define PORT_DEVICE_NAME "Grove Vision AI (V2)"


#ifdef __cplusplus
extern "C" {
#endif

#include <WE2_device.h>
#include <hx_drv_gpio.h>
#include <hx_drv_scu.h>
#include <hx_drv_scu_export.h>

#ifdef TRUSTZONE_SEC
#if (__ARM_FEATURE_CMSE & 1) == 0
Expand All @@ -59,6 +60,19 @@ extern "C" {
#endif
#endif

#define CONFIG_EL_CAMERA_PWR_CTRL_INIT_F \
{ \
hx_drv_gpio_set_output(AON_GPIO1, GPIO_OUT_HIGH); \
hx_drv_scu_set_PA1_pinmux(SCU_PA1_PINMUX_AON_GPIO1, 0); \
hx_drv_gpio_set_out_value(AON_GPIO1, GPIO_OUT_HIGH); \
}

#define CONFIG_EL_SPI_CS_INIT_F \
{ hx_drv_scu_set_PB11_pinmux(SCU_PB11_PINMUX_SPI_S_CS, 1); }
#define CONFIG_EL_SPI_CTRL_INIT_F \
{ hx_drv_scu_set_PA0_pinmux(SCU_PA0_PINMUX_AON_GPIO0_2, 1); }
#define CONFIG_EL_SPI_CTRL_PIN AON_GPIO0

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion porting/himax/we2/drivers/OV5647_mipi_2lane_1296x972.i
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@
{HX_CIS_I2C_Action_W, 0x4837, 0x16},
{HX_CIS_I2C_Action_W, 0x4800, 0x24},
{HX_CIS_I2C_Action_W, 0x3503, 0x00},

{HX_CIS_I2C_Action_W, 0x3820, 0x41},
{HX_CIS_I2C_Action_W, 0x3821, 0x07},
{HX_CIS_I2C_Action_W, 0x3821, 0x00},

{HX_CIS_I2C_Action_W, 0x350a, 0x00},
{HX_CIS_I2C_Action_W, 0x350b, 0x10},
{HX_CIS_I2C_Action_W, 0x3500, 0x00},
Expand Down
12 changes: 7 additions & 5 deletions porting/himax/we2/drivers/drv_ov5647.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,9 @@ el_err_code_t drv_ov5647_init(uint16_t width, uint16_t height) {
EL_LOGD("mclk DIV3, xshutdown_pin=%d", DEAULT_XHSUTDOWN_PIN);

// OV5647 Enable
hx_drv_gpio_set_output(AON_GPIO1, GPIO_OUT_HIGH);
hx_drv_scu_set_PA1_pinmux(SCU_PA1_PINMUX_AON_GPIO1, 0);
hx_drv_gpio_set_out_value(AON_GPIO1, GPIO_OUT_HIGH);
EL_LOGD("Set PA1(AON_GPIO1) to High");
CONFIG_EL_CAMERA_PWR_CTRL_INIT_F;

EL_LOGD("Init PA1(AON_GPIO1)");

hx_drv_cis_set_slaveID(CIS_I2C_ID);
EL_LOGD("hx_drv_cis_set_slaveID(0x%02X)", CIS_I2C_ID);
Expand Down Expand Up @@ -371,7 +370,10 @@ el_err_code_t drv_ov5647_init(uint16_t width, uint16_t height) {
jpeg_cfg.enc_width = width;
jpeg_cfg.enc_height = height;
jpeg_cfg.jpeg_enctype = JPEG_ENC_TYPE_YUV422;
jpeg_cfg.jpeg_encqtable = JPEG_ENC_QTABLE_10X;
jpeg_cfg.jpeg_encqtable = JPEG_ENC_QTABLE_4X;
if (width > 240 && height > 240) {
jpeg_cfg.jpeg_encqtable = JPEG_ENC_QTABLE_10X;
}

// sensordplib_set_int_hw5x5rgb_jpeg_wdma23(hw5x5_cfg, jpeg_cfg, 1, NULL);
sensordplib_set_int_hw5x5_jpeg_wdma23(hw5x5_cfg, jpeg_cfg, 1, NULL);
Expand Down
4 changes: 3 additions & 1 deletion porting/himax/we2/el_config_porting.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
#ifndef CONFIG_EL_TARGET_HIMAX
#error "Please specify porting target"
#else
#if defined(CONFIG_EL_BOARD_GRIVE_VISION_AI_WE2)
#if defined(CONFIG_EL_BOARD_GROVE_VISION_AI_WE2)
#include "boards/grove_vision_ai_we2/board.h"
#elif defined(CONFIG_EL_BOARD_DEV_BOARD_WE2)
#include "boards/dev_board/board.h"
#else
#error "Please specify porting board"
#endif
Expand Down
19 changes: 14 additions & 5 deletions porting/himax/we2/el_device_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ extern "C" {
#include "core/el_debug.h"
#include "el_camera_we2.h"
#include "el_config_porting.h"
#include "el_serial2_we2.h"
#include "el_serial_we2.h"
#include "el_wire_we2.h"
#include "el_sspi_we2.h"
#include "el_wire_we2.h"
#include "porting/el_flash.h"

#define U55_BASE BASE_ADDR_APB_U55_CTRL_ALIAS
Expand Down Expand Up @@ -146,14 +147,22 @@ void DeviceWE2::init() {
.id = ++sensor_id, .type = el_sensor_type_t::EL_SENSOR_TYPE_CAM, .state = el_sensor_state_t::EL_SENSOR_STA_REG});

static SerialWE2 serial{};
this->_serial = &serial;
serial.type = EL_TRANSPORT_UART;
this->_transports.emplace_front(&serial);

static Serial2WE2 serial2{};
serial2.type = EL_TRANSPORT_UART;
this->_transports.emplace_front(&serial2);

this->_network = nullptr;
static sspiWE2 sspi{};
this->_sspi = &sspi;

static sspiWE2 spi{};
spi.type = EL_TRANSPORT_SPI;
this->_transports.emplace_front(&spi);

static WireWE2 wire{0x62};
this->_wire = &wire;
wire.type = EL_TRANSPORT_I2C;
this->_transports.emplace_front(&wire);
}

void DeviceWE2::reset() { __NVIC_SystemReset(); }
Expand Down
Loading

0 comments on commit 41cf3f1

Please sign in to comment.