misc: Format code.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2025-09-28 19:45:07 +02:00
parent 8233e03553
commit f8e110ca91
31 changed files with 243 additions and 208 deletions

View File

@ -45,10 +45,10 @@
#endif #endif
#define OMV_ALIGN_TO(x, alignment) \ #define OMV_ALIGN_TO(x, alignment) \
((((uintptr_t)(x)) + (alignment) - 1) & ~((uintptr_t)((alignment) - 1))) ((((uintptr_t) (x)) + (alignment) - 1) & ~((uintptr_t) ((alignment) - 1)))
#define OMV_ALIGN_DOWN(x, alignment) \ #define OMV_ALIGN_DOWN(x, alignment) \
((uintptr_t)(x) & ~((uintptr_t)(alignment) - 1)) ((uintptr_t) (x) & ~((uintptr_t) (alignment) - 1))
#define check_timeout_ms(start_ms, timeout) \ #define check_timeout_ms(start_ms, timeout) \
((mp_hal_ticks_ms() - start_ms) > timeout) ((mp_hal_ticks_ms() - start_ms) > timeout)
@ -88,5 +88,5 @@
// type: Type of the containing structure // type: Type of the containing structure
// member: Name of the member within the structure // member: Name of the member within the structure
#define OMV_CONTAINER_OF(ptr, type, member) \ #define OMV_CONTAINER_OF(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member))) ((type *) ((char *) (ptr) - offsetof(type, member)))
#endif //__OMV_COMMON_H__ #endif //__OMV_COMMON_H__

View File

@ -78,6 +78,7 @@ typedef struct _i2c_dev {
static omv_i2c_t csi_i2c; static omv_i2c_t csi_i2c;
static omv_clk_t csi_clk; static omv_clk_t csi_clk;
// *INDENT-OFF*
// Standard resolution table; // Standard resolution table;
static uint16_t csi_resolution[][2] = { static uint16_t csi_resolution[][2] = {
[OMV_CSI_FRAMESIZE_INVALID] = {0, 0}, [OMV_CSI_FRAMESIZE_INVALID] = {0, 0},
@ -125,11 +126,12 @@ static uint16_t csi_resolution[][2] = {
[OMV_CSI_FRAMESIZE_WQXGA] = {2560, 1600}, [OMV_CSI_FRAMESIZE_WQXGA] = {2560, 1600},
[OMV_CSI_FRAMESIZE_WQXGA2] = {2592, 1944}, [OMV_CSI_FRAMESIZE_WQXGA2] = {2592, 1944},
}; };
// *INDENT-ON*
omv_csi_t csi_all[OMV_CSI_MAX_DEVICES] = {0}; omv_csi_t csi_all[OMV_CSI_MAX_DEVICES] = {0};
__weak void omv_csi_init0() { __weak void omv_csi_init0() {
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) { for (size_t i = 0; i < OMV_CSI_MAX_DEVICES; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
omv_i2c_t *i2c = csi->i2c; omv_i2c_t *i2c = csi->i2c;
@ -179,7 +181,7 @@ __weak int omv_csi_init() {
// Initialize the CSIs using the port's ops as defaults, // Initialize the CSIs using the port's ops as defaults,
// which can be overridden by sensor drivers during probe. // which can be overridden by sensor drivers during probe.
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) { for (size_t i = 0; i < OMV_CSI_MAX_DEVICES; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
memset(csi, 0, sizeof(omv_csi_t)); memset(csi, 0, sizeof(omv_csi_t));
@ -197,7 +199,7 @@ __weak int omv_csi_init() {
} }
// Detect and initialize sensor(s). // Detect and initialize sensor(s).
for (uint32_t i=0, n_buses=OMV_ARRAY_SIZE(buses); i<n_buses; i++) { for (uint32_t i = 0, n_buses = OMV_ARRAY_SIZE(buses); i < n_buses; i++) {
// Initialize the camera bus. // Initialize the camera bus.
omv_i2c_init(&csi_i2c, buses[i][0], buses[i][1]); omv_i2c_init(&csi_i2c, buses[i][0], buses[i][1]);
@ -214,7 +216,7 @@ __weak int omv_csi_init() {
} }
// Configure the DCMI interface. // Configure the DCMI interface.
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) { for (size_t i = 0; i < OMV_CSI_MAX_DEVICES; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
if (omv_csi_config(csi, OMV_CSI_CONFIG_INIT) != 0) { if (omv_csi_config(csi, OMV_CSI_CONFIG_INIT) != 0) {
@ -230,7 +232,7 @@ __weak int omv_csi_init() {
omv_csi_t *omv_csi_get(int id) { omv_csi_t *omv_csi_get(int id) {
omv_csi_t *csi = NULL; omv_csi_t *csi = NULL;
for (size_t i=0; !csi && i<OMV_CSI_MAX_DEVICES; i++) { for (size_t i = 0; !csi && i < OMV_CSI_MAX_DEVICES; i++) {
if (id == -1 && !csi_all[i].auxiliary) { if (id == -1 && !csi_all[i].auxiliary) {
csi = &csi_all[i]; csi = &csi_all[i];
} else if (omv_csi_match(&csi_all[i], id)) { } else if (omv_csi_match(&csi_all[i], id)) {
@ -276,7 +278,7 @@ __weak int omv_csi_abort(omv_csi_t *csi, bool fifo_flush, bool in_irq) {
} }
void omv_csi_abort_all(void) { void omv_csi_abort_all(void) {
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) { for (size_t i = 0; i < OMV_CSI_MAX_DEVICES; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
// Abort ongoing transfer // Abort ongoing transfer
@ -313,8 +315,12 @@ __weak int omv_csi_reset(omv_csi_t *csi, bool hard) {
#endif // MICROPY_PY_IMU #endif // MICROPY_PY_IMU
csi->color_palette = rainbow_table; csi->color_palette = rainbow_table;
csi->disable_full_flush = false; csi->disable_full_flush = false;
csi->vsync_cb = (omv_csi_cb_t) { NULL, NULL }; csi->vsync_cb = (omv_csi_cb_t) {
csi->frame_cb = (omv_csi_cb_t) { NULL, NULL }; NULL, NULL
};
csi->frame_cb = (omv_csi_cb_t) {
NULL, NULL
};
// Restore shutdown state on reset. // Restore shutdown state on reset.
if (!csi->power_on) { if (!csi->power_on) {
@ -341,7 +347,7 @@ __weak int omv_csi_reset(omv_csi_t *csi, bool hard) {
// Note hard-reset is shared between all CSIs. // Note hard-reset is shared between all CSIs.
uint32_t reset_time_ms = mp_hal_ticks_ms(); uint32_t reset_time_ms = mp_hal_ticks_ms();
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) { for (size_t i = 0; i < OMV_CSI_MAX_DEVICES; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
if (csi->detected) { if (csi->detected) {
csi->reset_time_ms = reset_time_ms; csi->reset_time_ms = reset_time_ms;
@ -371,7 +377,7 @@ static size_t omv_csi_detect(omv_i2c_t *i2c, i2c_dev_t *dev_list) {
uint8_t addr_list[OMV_CSI_I2C_MAX_DEV]; uint8_t addr_list[OMV_CSI_I2C_MAX_DEV];
int addr_count = omv_i2c_scan(i2c, addr_list, OMV_ARRAY_SIZE(addr_list)); int addr_count = omv_i2c_scan(i2c, addr_list, OMV_ARRAY_SIZE(addr_list));
for (int i=0; i<addr_count; i++) { for (int i = 0; i < addr_count; i++) {
uint32_t chip_id = 0; uint32_t chip_id = 0;
uint8_t slv_addr = addr_list[i]; uint8_t slv_addr = addr_list[i];
@ -462,7 +468,9 @@ static size_t omv_csi_detect(omv_i2c_t *i2c, i2c_dev_t *dev_list) {
} }
if (chip_id && dev_count < OMV_CSI_MAX_DEVICES) { if (chip_id && dev_count < OMV_CSI_MAX_DEVICES) {
dev_list[dev_count++] = (i2c_dev_t) { slv_addr, chip_id }; dev_list[dev_count++] = (i2c_dev_t) {
slv_addr, chip_id
};
} }
} }
@ -492,7 +500,7 @@ int omv_csi_probe(omv_i2c_t *i2c) {
// Scan the bus multiple times using different reset and power polarities, // Scan the bus multiple times using different reset and power polarities,
// until a supported sensor is detected. // until a supported sensor is detected.
for (size_t i=0; dev_count == 0 && i<OMV_ARRAY_SIZE(polarity_configs); i++) { for (size_t i = 0; dev_count == 0 && i < OMV_ARRAY_SIZE(polarity_configs); i++) {
// Power cycle // Power cycle
#if defined(OMV_CSI_POWER_PIN) #if defined(OMV_CSI_POWER_PIN)
power_pol = polarity_configs[i][0]; power_pol = polarity_configs[i][0];
@ -520,7 +528,9 @@ int omv_csi_probe(omv_i2c_t *i2c) {
// Add special devices, such as SPI sensors, soft-CSI etc... // Add special devices, such as SPI sensors, soft-CSI etc...
#if OMV_SOFTCSI_ENABLE #if OMV_SOFTCSI_ENABLE
if (dev_count < OMV_CSI_MAX_DEVICES) { if (dev_count < OMV_CSI_MAX_DEVICES) {
dev_list[dev_count++] = (i2c_dev_t) { 0, SOFTCSI_ID }; dev_list[dev_count++] = (i2c_dev_t) {
0, SOFTCSI_ID
};
} }
#endif #endif
@ -529,7 +539,9 @@ int omv_csi_probe(omv_i2c_t *i2c) {
// Found PixArt PAJ6100 // Found PixArt PAJ6100
power_pol = OMV_CSI_ACTIVE_LOW; power_pol = OMV_CSI_ACTIVE_LOW;
reset_pol = OMV_CSI_ACTIVE_LOW; reset_pol = OMV_CSI_ACTIVE_LOW;
dev_list[dev_count++] = (i2c_dev_t) { 0, PAJ6100_ID }; dev_list[dev_count++] = (i2c_dev_t) {
0, PAJ6100_ID
};
} }
#endif #endif
@ -539,7 +551,7 @@ int omv_csi_probe(omv_i2c_t *i2c) {
} }
// Initialize detected sensors. // Initialize detected sensors.
for (size_t i=0; i<dev_count; i++) { for (size_t i = 0; i < dev_count; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
sensor_init_t init_fun = NULL; sensor_init_t init_fun = NULL;
@ -553,7 +565,7 @@ int omv_csi_probe(omv_i2c_t *i2c) {
csi->reset_time_ms = power_time_ms; csi->reset_time_ms = power_time_ms;
// Find the sensors init function. // Find the sensors init function.
for (size_t i=0; i<OMV_ARRAY_SIZE(sensor_config_table); i++) { for (size_t i = 0; i < OMV_ARRAY_SIZE(sensor_config_table); i++) {
const sensor_config_t *config = &sensor_config_table[i]; const sensor_config_t *config = &sensor_config_table[i];
if (csi->chip_id == config->chip_id) { if (csi->chip_id == config->chip_id) {
init_fun = config->init_fun; init_fun = config->init_fun;
@ -583,7 +595,7 @@ int omv_csi_probe(omv_i2c_t *i2c) {
// Soft-CSI + Lepton). If only one is found, use it as main. If // Soft-CSI + Lepton). If only one is found, use it as main. If
// multiple, pick the first non-Soft-CSI sensor as main. // multiple, pick the first non-Soft-CSI sensor as main.
if (dev_count == aux_count) { if (dev_count == aux_count) {
for (size_t i=0; i<dev_count; i++) { for (size_t i = 0; i < dev_count; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
if (dev_count == 1 || csi->chip_id != SOFTCSI_ID) { if (dev_count == 1 || csi->chip_id != SOFTCSI_ID) {
aux_count--; aux_count--;
@ -606,7 +618,7 @@ int omv_csi_probe(omv_i2c_t *i2c) {
// Clear the FB pointer for all aux sensors, as they use // Clear the FB pointer for all aux sensors, as they use
// dynamically allocated frame buffers. // dynamically allocated frame buffers.
for (size_t i=0; i<dev_count; i++) { for (size_t i = 0; i < dev_count; i++) {
omv_csi_t *csi = &csi_all[i]; omv_csi_t *csi = &csi_all[i];
if (csi->auxiliary) { if (csi->auxiliary) {
csi->fb = NULL; csi->fb = NULL;
@ -1292,7 +1304,7 @@ __weak int omv_csi_set_framebuffers(omv_csi_t *csi, size_t count, bool expand) {
#endif #endif
if (count == -1) { if (count == -1) {
for (size_t i=3; i>0; i--) { for (size_t i = 3; i > 0; i--) {
if (!framebuffer_resize(csi->fb, i, frame_size, expand)) { if (!framebuffer_resize(csi->fb, i, frame_size, expand)) {
return 0; return 0;
} }

View File

@ -242,7 +242,7 @@ void OMV_ATTR_NO_INSTRUMENT __cyg_profile_func_enter(void *func_addr, void *call
return; return;
} }
if (profiler.stack_top > (int32_t)profiler.stack_depth) { if (profiler.stack_top > (int32_t) profiler.stack_depth) {
profiler.stack_depth = profiler.stack_top; profiler.stack_depth = profiler.stack_top;
} }

View File

@ -83,21 +83,21 @@ OMV_ATTR_NO_INSTRUMENT mutex_t *omv_profiler_lock(void);
// Manual instrumentation macros // Manual instrumentation macros
#define OMV_PROFILER_ENTER(func) \ #define OMV_PROFILER_ENTER(func) \
do { \ do { \
void *func_addr = (void*)(func); \ void *func_addr = (void *) (func); \
void *call_addr = __builtin_return_address(0); \ void *call_addr = __builtin_return_address(0); \
__cyg_profile_func_enter(func_addr, call_addr); \ __cyg_profile_func_enter(func_addr, call_addr); \
} while(0) } while (0)
#define OMV_PROFILER_EXIT(func) \ #define OMV_PROFILER_EXIT(func) \
do { \ do { \
void *func_addr = (void*)(func); \ void *func_addr = (void *) (func); \
void *call_addr = __builtin_return_address(0); \ void *call_addr = __builtin_return_address(0); \
__cyg_profile_func_exit(func_addr, call_addr); \ __cyg_profile_func_exit(func_addr, call_addr); \
} while(0) } while (0)
#else #else
// Disabled - empty macros // Disabled - empty macros
#define OMV_PROFILER_ENTER(func) do {} while(0) #define OMV_PROFILER_ENTER(func) do {} while (0)
#define OMV_PROFILER_EXIT(func) do {} while(0) #define OMV_PROFILER_EXIT(func) do {} while (0)
#endif // OMV_PROFILER_ENABLE #endif // OMV_PROFILER_ENABLE
#endif // __OMV_PROFILER_H__ #endif // __OMV_PROFILER_H__

View File

@ -143,7 +143,9 @@ int tinyusb_debug_init(void) {
ctx.opcode = 0; ctx.opcode = 0;
ctx.length = 0; ctx.length = 0;
if (!ctx.ringbuf.buf) { if (!ctx.ringbuf.buf) {
ctx.ringbuf = (ringbuf_t) { ctx.rawbuf, sizeof(ctx.rawbuf), 0, 0 }; ctx.ringbuf = (ringbuf_t) {
ctx.rawbuf, sizeof(ctx.rawbuf), 0, 0
};
} }
return 0; return 0;
} }
@ -165,7 +167,7 @@ void tinyusb_debug_task(mp_sched_node_t *node) {
if (cmdbuf[0] == 0x30) { if (cmdbuf[0] == 0x30) {
ctx.opcode = cmdbuf[1]; ctx.opcode = cmdbuf[1];
ctx.length = *((uint32_t*)(cmdbuf+2)); ctx.length = *((uint32_t *) (cmdbuf + 2));
usbdbg_control(NULL, ctx.opcode, ctx.length); usbdbg_control(NULL, ctx.opcode, ctx.length);
} }

View File

@ -47,8 +47,7 @@ static int16_t readout_y = 0;
static enum { static enum {
MONO_CFA, RCCC_CFA, BAYER_CFA MONO_CFA, RCCC_CFA, BAYER_CFA
} } cfa_type = MONO_CFA;
cfa_type = MONO_CFA;
static bool is_mt9v0x2(omv_csi_t *csi) { static bool is_mt9v0x2(omv_csi_t *csi) {
return (csi->chip_id == MT9V0X2_ID) || (csi->chip_id == MT9V0X2_C_ID); return (csi->chip_id == MT9V0X2_ID) || (csi->chip_id == MT9V0X2_C_ID);

View File

@ -6,7 +6,7 @@
#include "omv_csi.h" #include "omv_csi.h"
#include "omv_boardconfig.h" #include "omv_boardconfig.h"
typedef int (*sensor_init_t)(omv_csi_t *); typedef int (*sensor_init_t) (omv_csi_t *);
typedef struct { typedef struct {
uint32_t chip_id; uint32_t chip_id;
@ -115,7 +115,7 @@ extern int frogeye2020_init(omv_csi_t *csi);
#endif #endif
extern int softcsi_init(omv_csi_t *csi); extern int softcsi_init(omv_csi_t *csi);
// Sensor table // Sensor table *INDENT-OFF*
static const sensor_config_t sensor_config_table[] = { static const sensor_config_t sensor_config_table[] = {
#if OMV_OV2640_ENABLE #if OMV_OV2640_ENABLE
{ OV2640_ID, OMV_OV2640_CLK_FREQ, ov2640_init }, { OV2640_ID, OMV_OV2640_CLK_FREQ, ov2640_init },

View File

@ -27,8 +27,7 @@
typedef struct xylr { typedef struct xylr {
int16_t x, y, l, r, t_l, b_l; int16_t x, y, l, r, t_l, b_l;
} } xylr_t;
xylr_t;
static float sign(float x) { static float sign(float x) {
return x / fabsf(x); return x / fabsf(x);

View File

@ -61,8 +61,7 @@ float fast_expf(float x) {
float fast_cbrtf(float x) { float fast_cbrtf(float x) {
union { union {
int ix; float x; int ix; float x;
} } v;
v;
v.x = x; // x can be viewed as int. v.x = x; // x can be viewed as int.
v.ix = v.ix / 4 + v.ix / 16; // Approximate divide by 3. v.ix = v.ix / 4 + v.ix / 16; // Approximate divide by 3.
v.ix = v.ix + v.ix / 16; v.ix = v.ix + v.ix / 16;
@ -135,12 +134,10 @@ float fast_atan2f(float y, float x) {
float fast_log2(float x) { float fast_log2(float x) {
union { union {
float f; uint32_t i; float f; uint32_t i;
} } vx = { x };
vx = { x };
union { union {
uint32_t i; float f; uint32_t i; float f;
} } mx = { (vx.i & 0x007FFFFF) | 0x3f000000 };
mx = { (vx.i & 0x007FFFFF) | 0x3f000000 };
float y = vx.i; float y = vx.i;
y *= 1.1920928955078125e-7f; y *= 1.1920928955078125e-7f;
@ -155,8 +152,7 @@ float fast_log(float x) {
float fast_powf(float a, float b) { float fast_powf(float a, float b) {
union { union {
float d; int x; float d; int x;
} } u = { a };
u = { a };
u.x = (int) ((b * (u.x - 1064866805)) + 1064866805); u.x = (int) ((b * (u.x - 1064866805)) + 1064866805);
return u.d; return u.d;
} }

View File

@ -78,8 +78,7 @@ static inline int fast_ceilf(float x) {
#else #else
union { union {
uint32_t i; float f; uint32_t i; float f;
} } max = { 0x3f7fffff };
max = { 0x3f7fffff };
x += max.f; x += max.f;
__asm__ volatile ( __asm__ volatile (
"vcvt.S32.f32 %[r], %[x]\n" "vcvt.S32.f32 %[r], %[x]\n"

View File

@ -172,8 +172,7 @@ typedef struct color_thresholds_list_lnk_data {
uint8_t LMin, LMax; // or grayscale uint8_t LMin, LMax; // or grayscale
int8_t AMin, AMax; int8_t AMin, AMax;
int8_t BMin, BMax; int8_t BMin, BMax;
} }color_thresholds_list_lnk_data_t;
color_thresholds_list_lnk_data_t;
#define COLOR_THRESHOLD_BINARY(pixel, threshold, invert) \ #define COLOR_THRESHOLD_BINARY(pixel, threshold, invert) \
({ \ ({ \

View File

@ -41,8 +41,7 @@ static void read_int_reset(ppm_read_settings_t *rs) {
static void read_int(FIL *fp, uint32_t *i, ppm_read_settings_t *rs) { static void read_int(FIL *fp, uint32_t *i, ppm_read_settings_t *rs) {
enum { enum {
EAT_WHITESPACE, EAT_COMMENT, EAT_NUMBER EAT_WHITESPACE, EAT_COMMENT, EAT_NUMBER
} } mode = EAT_WHITESPACE;
mode = EAT_WHITESPACE;
for (*i = 0;;) { for (*i = 0;;) {
if (!rs->read_int_c_valid) { if (!rs->read_int_c_valid) {
if (file_tell(fp) == file_size(fp)) { if (file_tell(fp) == file_size(fp)) {

View File

@ -1357,10 +1357,18 @@ static inline v4x_rows_t vcvt_u8_f32(v128_t v0) {
}; };
#else #else
return (v4x_rows_t) { return (v4x_rows_t) {
.r0 = (v128_t) { .f32 = { (float32_t) v0.u8[0] } }, .r0 = (v128_t) {
.r1 = (v128_t) { .f32 = { (float32_t) v0.u8[1] } }, .f32 = { (float32_t) v0.u8[0] }
.r2 = (v128_t) { .f32 = { (float32_t) v0.u8[2] } }, },
.r3 = (v128_t) { .f32 = { (float32_t) v0.u8[3] } } .r1 = (v128_t) {
.f32 = { (float32_t) v0.u8[1] }
},
.r2 = (v128_t) {
.f32 = { (float32_t) v0.u8[2] }
},
.r3 = (v128_t) {
.f32 = { (float32_t) v0.u8[3] }
}
}; };
#endif #endif
} }
@ -1377,10 +1385,18 @@ static inline v4x_rows_t vcvt_s8_f32(v128_t v0) {
}; };
#else #else
return (v4x_rows_t) { return (v4x_rows_t) {
.r0 = (v128_t) { .f32 = { (float32_t) v0.s8[0] } }, .r0 = (v128_t) {
.r1 = (v128_t) { .f32 = { (float32_t) v0.s8[1] } }, .f32 = { (float32_t) v0.s8[0] }
.r2 = (v128_t) { .f32 = { (float32_t) v0.s8[2] } }, },
.r3 = (v128_t) { .f32 = { (float32_t) v0.s8[3] } } .r1 = (v128_t) {
.f32 = { (float32_t) v0.s8[1] }
},
.r2 = (v128_t) {
.f32 = { (float32_t) v0.s8[2] }
},
.r3 = (v128_t) {
.f32 = { (float32_t) v0.s8[3] }
}
}; };
#endif #endif
} }
@ -1393,8 +1409,12 @@ static inline v2x_rows_t vcvt_u16_f32(v128_t v0) {
}; };
#else #else
return (v2x_rows_t) { return (v2x_rows_t) {
.r0 = (v128_t) { .f32 = { (float32_t) v0.u16[0] } }, .r0 = (v128_t) {
.r1 = (v128_t) { .f32 = { (float32_t) v0.u16[1] } } .f32 = { (float32_t) v0.u16[0] }
},
.r1 = (v128_t) {
.f32 = { (float32_t) v0.u16[1] }
}
}; };
#endif #endif
} }
@ -1407,8 +1427,12 @@ static inline v2x_rows_t vcvt_s16_f32(v128_t v0) {
}; };
#else #else
return (v2x_rows_t) { return (v2x_rows_t) {
.r0 = (v128_t) { .f32 = { (float32_t) v0.s16[0] } }, .r0 = (v128_t) {
.r1 = (v128_t) { .f32 = { (float32_t) v0.s16[1] } } .f32 = { (float32_t) v0.s16[0] }
},
.r1 = (v128_t) {
.f32 = { (float32_t) v0.s16[1] }
}
}; };
#endif #endif
} }

View File

@ -178,13 +178,15 @@ int ml_backend_init_model(py_ml_model_obj_t *model) {
const LL_Buffer_InfoTypeDef *model_outputs = ll_aton_reloc_get_output_buffers_info(&state->nn_inst, -1); const LL_Buffer_InfoTypeDef *model_outputs = ll_aton_reloc_get_output_buffers_info(&state->nn_inst, -1);
// Initialize the model's inputs. // Initialize the model's inputs.
for (model->inputs_size = 0; model_inputs[model->inputs_size].name != NULL; model->inputs_size++); for (model->inputs_size = 0; model_inputs[model->inputs_size].name != NULL; model->inputs_size++) {
;
}
model->input_shape = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL)); model->input_shape = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL));
model->input_scale = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL)); model->input_scale = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL));
model->input_zero_point = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL)); model->input_zero_point = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL));
model->input_dtype = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL)); model->input_dtype = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->inputs_size, NULL));
for (size_t i=0; i<model->inputs_size; i++) { for (size_t i = 0; i < model->inputs_size; i++) {
const LL_Buffer_InfoTypeDef *input = &model_inputs[i]; const LL_Buffer_InfoTypeDef *input = &model_inputs[i];
// Check input data type. // Check input data type.
@ -193,7 +195,7 @@ int ml_backend_init_model(py_ml_model_obj_t *model) {
} }
mp_obj_tuple_t *o = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(input->mem_ndims, NULL)); mp_obj_tuple_t *o = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(input->mem_ndims, NULL));
for (int j=0; j<input->mem_ndims; j++) { for (int j = 0; j < input->mem_ndims; j++) {
o->items[j] = mp_obj_new_int(input->mem_shape[j]); o->items[j] = mp_obj_new_int(input->mem_shape[j]);
} }
@ -205,13 +207,15 @@ int ml_backend_init_model(py_ml_model_obj_t *model) {
} }
// Initialize the model's outputs. // Initialize the model's outputs.
for (model->outputs_size = 0; model_outputs[model->outputs_size].name != NULL; model->outputs_size++); for (model->outputs_size = 0; model_outputs[model->outputs_size].name != NULL; model->outputs_size++) {
;
}
model->output_shape = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL)); model->output_shape = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL));
model->output_scale = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL)); model->output_scale = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL));
model->output_zero_point = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL)); model->output_zero_point = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL));
model->output_dtype = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL)); model->output_dtype = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(model->outputs_size, NULL));
for (size_t i=0; i<model->outputs_size; i++) { for (size_t i = 0; i < model->outputs_size; i++) {
const LL_Buffer_InfoTypeDef *output = &model_outputs[i]; const LL_Buffer_InfoTypeDef *output = &model_outputs[i];
// Check output data type. // Check output data type.
@ -220,7 +224,7 @@ int ml_backend_init_model(py_ml_model_obj_t *model) {
} }
mp_obj_tuple_t *o = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(output->mem_ndims, NULL)); mp_obj_tuple_t *o = (mp_obj_tuple_t *) MP_OBJ_TO_PTR(mp_obj_new_tuple(output->mem_ndims, NULL));
for (int j=0; j<output->mem_ndims; j++) { for (int j = 0; j < output->mem_ndims; j++) {
o->items[j] = mp_obj_new_int(output->mem_shape[j]); o->items[j] = mp_obj_new_int(output->mem_shape[j]);
} }
@ -237,7 +241,7 @@ int ml_backend_run_inference(py_ml_model_obj_t *model) {
ml_backend_state_t *state = (ml_backend_state_t *) model->state; ml_backend_state_t *state = (ml_backend_state_t *) model->state;
// Flush input buffers. // Flush input buffers.
for (size_t i=0; i< model->inputs_size; i++) { for (size_t i = 0; i < model->inputs_size; i++) {
const LL_Buffer_InfoTypeDef *buf = ll_aton_reloc_get_input_buffers_info(&state->nn_inst, i); const LL_Buffer_InfoTypeDef *buf = ll_aton_reloc_get_input_buffers_info(&state->nn_inst, i);
SCB_CleanDCache_by_Addr(LL_Buffer_addr_start(buf), LL_Buffer_len(buf)); SCB_CleanDCache_by_Addr(LL_Buffer_addr_start(buf), LL_Buffer_len(buf));
} }

View File

@ -416,12 +416,12 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
#if MICROPY_EMIT_MACHINE_CODE #if MICROPY_EMIT_MACHINE_CODE
void *nrf_native_code_commit(void *buf, unsigned int len, void *reloc) { void *nrf_native_code_commit(void *buf, unsigned int len, void *reloc) {
(void)len; (void) len;
if (reloc) { if (reloc) {
// Native code in RAM must execute from the IRAM region at 0x00800000, and so relocations // Native code in RAM must execute from the IRAM region at 0x00800000, and so relocations
// to text must also point to this region. The MICROPY_MAKE_POINTER_CALLABLE macro will // to text must also point to this region. The MICROPY_MAKE_POINTER_CALLABLE macro will
// adjust the `buf` address from RAM to IRAM. // adjust the `buf` address from RAM to IRAM.
mp_native_relocate(reloc, buf, (uintptr_t)MICROPY_MAKE_POINTER_CALLABLE(buf) & ~1); mp_native_relocate(reloc, buf, (uintptr_t) MICROPY_MAKE_POINTER_CALLABLE(buf) & ~1);
} }
return buf; return buf;
} }

View File

@ -265,7 +265,7 @@ static int stm_csi_config(omv_csi_t *csi, omv_csi_config_t config) {
#if USE_DCMIPP #if USE_DCMIPP
csi->dcmipp.State = HAL_DCMIPP_STATE_READY; csi->dcmipp.State = HAL_DCMIPP_STATE_READY;
// Reset pipes states to allow reconfiguring them. // Reset pipes states to allow reconfiguring them.
for (size_t i=0; i<DCMIPP_NUM_OF_PIPES; i++) { for (size_t i = 0; i < DCMIPP_NUM_OF_PIPES; i++) {
csi->dcmipp.PipeState[i] = HAL_DCMIPP_PIPE_STATE_RESET; csi->dcmipp.PipeState[i] = HAL_DCMIPP_PIPE_STATE_RESET;
} }
// Configure the pixel processing pipeline. // Configure the pixel processing pipeline.
@ -287,7 +287,9 @@ static int stm_csi_abort(omv_csi_t *csi, bool fifo_flush, bool in_irq) {
if (!csi->mipi_if) { if (!csi->mipi_if) {
DCMI->CR &= ~DCMI_CR_ENABLE; DCMI->CR &= ~DCMI_CR_ENABLE;
while (DCMI->CR & DCMI_CR_ENABLE); while (DCMI->CR & DCMI_CR_ENABLE) {
;
}
#if defined(STM32N6) #if defined(STM32N6)
HAL_DMA_Abort(&csi->dma); HAL_DMA_Abort(&csi->dma);

View File

@ -283,7 +283,7 @@ uint8_t stm_dma_mpu_region_size(uint32_t size) {
static uint32_t stm_dma_width(uint32_t size, bool source) { static uint32_t stm_dma_width(uint32_t size, bool source) {
#if defined(STM32N6) #if defined(STM32N6)
switch(size) { switch (size) {
case 1: return (source) ? DMA_SRC_DATAWIDTH_BYTE : DMA_DEST_DATAWIDTH_BYTE; case 1: return (source) ? DMA_SRC_DATAWIDTH_BYTE : DMA_DEST_DATAWIDTH_BYTE;
case 2: return (source) ? DMA_SRC_DATAWIDTH_HALFWORD : DMA_DEST_DATAWIDTH_HALFWORD; case 2: return (source) ? DMA_SRC_DATAWIDTH_HALFWORD : DMA_DEST_DATAWIDTH_HALFWORD;
case 4: return (source) ? DMA_SRC_DATAWIDTH_WORD : DMA_DEST_DATAWIDTH_WORD; case 4: return (source) ? DMA_SRC_DATAWIDTH_WORD : DMA_DEST_DATAWIDTH_WORD;
@ -291,7 +291,7 @@ static uint32_t stm_dma_width(uint32_t size, bool source) {
default: return -1; default: return -1;
} }
#else #else
switch(size) { switch (size) {
case 1: return (source) ? DMA_PDATAALIGN_BYTE : DMA_MDATAALIGN_BYTE; case 1: return (source) ? DMA_PDATAALIGN_BYTE : DMA_MDATAALIGN_BYTE;
case 2: return (source) ? DMA_PDATAALIGN_HALFWORD : DMA_MDATAALIGN_HALFWORD; case 2: return (source) ? DMA_PDATAALIGN_HALFWORD : DMA_MDATAALIGN_HALFWORD;
case 4: return (source) ? DMA_PDATAALIGN_WORD : DMA_MDATAALIGN_WORD; case 4: return (source) ? DMA_PDATAALIGN_WORD : DMA_MDATAALIGN_WORD;
@ -422,7 +422,7 @@ int stm_dma_ll_init(DMA_HandleTypeDef *dma_descr, DMA_QListTypeDef *dma_queue,
memset(dma_nodes, 0, sizeof(DMA_NodeTypeDef) * nodes_count); memset(dma_nodes, 0, sizeof(DMA_NodeTypeDef) * nodes_count);
DMA_NodeTypeDef *prev_node = NULL; DMA_NodeTypeDef *prev_node = NULL;
for (size_t i=0; i<nodes_count; i++) { for (size_t i = 0; i < nodes_count; i++) {
if (HAL_DMAEx_List_BuildNode(&node_conf, &dma_nodes[i]) != HAL_OK || if (HAL_DMAEx_List_BuildNode(&node_conf, &dma_nodes[i]) != HAL_OK ||
HAL_DMAEx_List_InsertNode(dma_queue, prev_node, &dma_nodes[i]) != HAL_OK) { HAL_DMAEx_List_InsertNode(dma_queue, prev_node, &dma_nodes[i]) != HAL_OK) {
return -1; return -1;

View File

@ -12,11 +12,11 @@ typedef struct _tim_info {
static uint32_t stm_tim_get_source_clock(TIM_TypeDef *inst) { static uint32_t stm_tim_get_source_clock(TIM_TypeDef *inst) {
uint32_t source = 0; uint32_t source = 0;
#if defined (STM32F4) || defined(STM32F7) || defined(STM32H7) #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
uintptr_t base = ((uintptr_t) inst) & 0xFFFF0000u; uintptr_t base = ((uintptr_t) inst) & 0xFFFF0000u;
#endif #endif
#if defined (STM32F4) || defined(STM32F7) #if defined(STM32F4) || defined(STM32F7)
// Timer clock on F4, F7, H7 == APBx * 2. // Timer clock on F4, F7, H7 == APBx * 2.
if (base == APB1PERIPH_BASE) { if (base == APB1PERIPH_BASE) {
source = HAL_RCC_GetPCLK1Freq() * 2; source = HAL_RCC_GetPCLK1Freq() * 2;