Skip to content

Commit

Permalink
feat: sensecap a1102, save result (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
iChizer0 authored Nov 28, 2024
1 parent ebd15f4 commit bbfa34a
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 19 deletions.
85 changes: 85 additions & 0 deletions porting/himax/we2/boards/sensecap_a1102/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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_SENSECAP_A1102_H_
#define _BOARD_SENSECAP_A1102_H_

#define PRODUCT_NAME_PREFIX "sensecap_a1102"
#define PRODUCT_NAME_SUFFIX "v1"
#define DEVICE_NAME (PRODUCT_NAME_PREFIX "_" PRODUCT_NAME_SUFFIX)
#define PORT_DEVICE_NAME "SenseCAP A1102"
#define WATCH_DOG_TIMEOUT_TH 3000

#define SSCMA_CFG_ENABLE_ACTION 1
#define SSCMA_CFG_ENABLE_CONTENTS_EXPORT 1
#define SSCMA_STORAGE_CFG_UPDATE_BOOT_COUNT 0

#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_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

#endif
4 changes: 2 additions & 2 deletions porting/himax/we2/el_camera_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ CameraWE2::CameraWE2() : Camera(0b00001111) {
}
}
}
#elif defined(CONFIG_EL_BOARD_GROVE_VISION_AI_V2)
#elif defined(CONFIG_EL_BOARD_GROVE_VISION_AI_V2) || defined(CONFIG_EL_BOARD_SENSECAP_A1102)
CameraWE2::CameraWE2() : Camera(0b00000111) {}
#else
#error "Camera moudle does not find supported board."
Expand Down Expand Up @@ -134,7 +134,7 @@ el_err_code_t CameraWE2::init(SensorOptIdType opt_id) {
default:
ret = EL_EINVAL;
}
#elif defined(CONFIG_EL_BOARD_GROVE_VISION_AI_V2)
#elif defined(CONFIG_EL_BOARD_GROVE_VISION_AI_V2) || defined(CONFIG_EL_BOARD_SENSECAP_A1102)
switch (opt_id & 0x0FFF) {
case 0:
ret = _drv_cam_init(240, 240);
Expand Down
2 changes: 2 additions & 0 deletions porting/himax/we2/el_config_porting.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "boards/grove_vision_ai_v2/board.h"
#elif defined(CONFIG_EL_BOARD_SENSECAP_WATCHER)
#include "boards/sensecap_watcher/board.h"
#elif defined(CONFIG_EL_BOARD_SENSECAP_A1102)
#include "boards/sensecap_a1102/board.h"
#else
#error "Please specify porting board"
#endif
Expand Down
8 changes: 7 additions & 1 deletion porting/himax/we2/el_device_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void DeviceWE2::init() {
wdg_cfg.period = WATCH_DOG_TIMEOUT_TH;
wdg_cfg.ctrl = WATCHDOG_CTRL_CPU;
wdg_cfg.state = WATCHDOG_STATE_DC;
wdg_cfg.type = WATCHDOG_RESET; //wewweWATCHDOG_INT;
wdg_cfg.type = WATCHDOG_RESET;
hx_drv_watchdog_start(WATCHDOG_ID_0, &wdg_cfg, porting::WDG_Reset_ISR_CB);
hx_drv_uart_init(USE_DW_UART_0, HX_UART0_BASE);

Expand Down Expand Up @@ -181,6 +181,12 @@ void DeviceWE2::init() {
wire.type = EL_TRANSPORT_I2C;
this->_transports.emplace_front(&wire);
#endif

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

void DeviceWE2::reset() { __NVIC_SystemReset(); }
Expand Down
2 changes: 1 addition & 1 deletion porting/himax/we2/el_extfs_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ FileStatus ExtfsWE2::open(const char* path, int mode) {
}

Extfs* Extfs::get_ptr() {
#ifdef CONFIG_EL_BOARD_GROVE_VISION_AI_V2
#if defined(CONFIG_EL_BOARD_GROVE_VISION_AI_V2) || defined(CONFIG_EL_BOARD_SENSECAP_A1102)
static ExtfsWE2 extfs{};
return &extfs;
#else
Expand Down
52 changes: 39 additions & 13 deletions sscma/callback/extension/contents_export.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class ContentsExport {
return true;
}

bool cache_result(std::string&& result_str) {
_result = std::move(result_str);
return true;
}

bool commit(std::string name, std::function<void(Status)> callback) {
if (_data == nullptr || _bytes <= 0) [[unlikely]] {
return false;
Expand All @@ -60,22 +65,41 @@ class ContentsExport {
return false;
}

std::string file = _path + name;
auto handler = _extfs->open(file.c_str(), OpenMode::WRITE);
if (!handler.status.success) {
callback(handler.status);
return false;
}
std::string file_prefix = _path + name;
{
std::string file = file_prefix + ".jpeg";
auto handler = _extfs->open(file.c_str(), OpenMode::WRITE);
if (!handler.status.success) {
callback(handler.status);
return false;
}

size_t written = 0;
auto status = handler.file->write(_data, _bytes, &written);
if (!status.success) {
callback(status);
return false;
size_t written = 0;
auto status = handler.file->write(_data, _bytes, &written);
if (!status.success) {
callback(status);
return false;
}
_bytes = 0;

handler.file->close();
}
_bytes = 0;

handler.file->close();
if (_result.size()) {
std::string file = file_prefix + ".json";
auto handler = _extfs->open(file.c_str(), OpenMode::WRITE);
if (!handler.status.success) {
return false;
}

size_t written = 0;
auto status = handler.file->write(reinterpret_cast<const uint8_t*>(_result.c_str()), _result.size(), &written);
if (!status.success) {
return false;
}

handler.file->close();
}

return true;
}
Expand Down Expand Up @@ -171,6 +195,8 @@ class ContentsExport {

size_t _size;
uint8_t* _data;

std::string _result;
};

} // namespace sscma::extension
16 changes: 14 additions & 2 deletions sscma/callback/invoke.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,20 @@ class Invoke final : public std::enable_shared_from_this<Invoke> {
encoded_frame_str = std::move(img_2_jpeg_json_str(&frame, &processed_frame));
#endif
#if SSCMA_CFG_ENABLE_CONTENTS_EXPORT
if (_contents_export && _exporter) [[likely]]
if (_contents_export && _exporter) [[likely]] {
_exporter->cache(processed_frame.data, processed_frame.size);
_exporter->cache_result(concat_strings("\r{\"type\": 1, \"name\": \"",
_cmd,
"\", \"code\": ",
std::to_string(_ret),
", \"data\": {\"count\": ",
std::to_string(_times),
", ",
algorithm_results_2_json_str(algorithm),
", ",
img_res_2_json_str(&frame),
"}}\n"));
}
#endif
}

Expand Down Expand Up @@ -533,7 +545,7 @@ class Invoke final : public std::enable_shared_from_this<Invoke> {
kv.second = [exporter = _exporter, cmd = std::move(cmd)](void* caller) -> int {
bool success = false;
uint32_t time = el_get_time_ms();
std::string file_name = concat_strings(std::to_string(time), ".jpeg");
std::string file_name = std::to_string(time);

if (!exporter) [[unlikely]]
return 0;
Expand Down

0 comments on commit bbfa34a

Please sign in to comment.