Skip to content

Commit

Permalink
A couple of various fixes
Browse files Browse the repository at this point in the history
- Region thread has increased memory size for libschrift stack allocations
- ioctl calls to reset sensor/MIPI devices are expected to not always return OK
  • Loading branch information
wberube committed May 22, 2024
1 parent edee9e3 commit 101eeec
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 83 deletions.
45 changes: 36 additions & 9 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,19 @@ int v4_sensor_config(void) {
if (fd < 0)
V4_ERROR("Opening imaging device has failed!\n");

if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_INTF, unsigned int), &config.device))
int laneMode = 0;
if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_HSMODE, int), &laneMode))
V4_ERROR("Configuring imaging device lane-splitting mode has failed!\n");

if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_MIPI, unsigned int), &config.device))
V4_ERROR("Enabling imaging device clocking has failed!\n");

if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_MIPI, unsigned int), &config.device))
V4_ERROR("Resetting imaging device has failed!\n");


if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_SENS, unsigned int), &config.device))
V4_ERROR("Enabling imaging sensor clocking has failed!\n");

if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_SENS, unsigned int), &config.device))
V4_ERROR("Resetting imaging sensor has failed!\n");

Expand All @@ -324,18 +334,33 @@ int v4_sensor_config(void) {

usleep(10000);

if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_INTF, unsigned int), &config.device))
V4_ERROR("Unresetting imaging device has failed!\n");
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_MIPI, unsigned int), &config.device);

if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_SENS, unsigned int), &config.device))
V4_ERROR("Unresetting imaging sensor has failed!\n");
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_SENS, unsigned int), &config.device);

close(fd);

return EXIT_SUCCESS;
}

int v4_sensor_cb_empty(void) { return EXIT_SUCCESS; }
void v4_sensor_deconfig(void) {
v4_snr_dev config;
config.device = 0;

int fd = open(V4_SNR_ENDPOINT, O_RDWR);
if (fd < 0)
fprintf(stderr, "[v4_hal] Opening imaging device has failed!\n");

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKOFF_SENS, unsigned int), &config.device);

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_SENS, unsigned int), &config.device);

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_MIPI, unsigned int), &config.device);

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_MIPI, unsigned int), &config.device);

close(fd);
}

void v4_sensor_deinit(void)
{
Expand Down Expand Up @@ -740,7 +765,7 @@ void *v4_video_thread(void)
int v4_system_calculate_block(short width, short height, v4_common_pixfmt pixFmt,
unsigned int alignWidth)
{
if (alignWidth & 0b0001111) {
if (alignWidth & 0b10001111) {
fprintf(stderr, "[v4_sys] Alignment width (%d) "
"is invalid!\n", alignWidth);
return -1;
Expand All @@ -764,6 +789,8 @@ void v4_system_deinit(void)

v4_isp_drv.obj->pfnUnRegisterCallback(_v4_isp_dev, &v4_ae_lib, &v4_awb_lib);

v4_sensor_deconfig();

v4_sys.fnExit();
v4_vb.fnExit();

Expand Down Expand Up @@ -824,7 +851,7 @@ int v4_system_init(unsigned int alignWidth, unsigned int blockCnt,
if (ret = v4_sensor_config())
return ret;

if (!(v4_isp_drv.obj->pfnRegisterCallback(_v4_isp_dev, &v4_ae_lib, &v4_awb_lib)))
if (ret = v4_isp_drv.obj->pfnRegisterCallback(_v4_isp_dev, &v4_ae_lib, &v4_awb_lib))
return ret;

if (ret = v4_isp.fnRegisterAE(_v4_isp_dev, &v4_ae_lib))
Expand Down
22 changes: 14 additions & 8 deletions src/hal/hisi/v4_snr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
#define V4_SNR_IOC_MAGIC 'm'
#define V4_SNR_LVDS_LANE_NUM 4
#define V4_SNR_MIPI_LANE_NUM 4
#define V4_SNR_WDR_VC_NUM 4
#define V4_SNR_WDR_VC_NUM 2

enum {
V4_SNR_CMD_CONF_DEV = 1,
V4_SNR_CMD_CONF_CLKEDGE,
V4_SNR_CMD_CONF_OUTMSB,
V4_SNR_CMD_CONF_CMV,
V4_SNR_CMD_CONF_CMV = 4,
V4_SNR_CMD_RST_SENS,
V4_SNR_CMD_UNRST_SENS,
V4_SNR_CMD_RST_INTF,
V4_SNR_CMD_UNRST_INTF,
V4_SNR_CMD_CONF_CROP
V4_SNR_CMD_RST_MIPI,
V4_SNR_CMD_UNRST_MIPI,
V4_SNR_CMD_RST_SLVS,
V4_SNR_CMD_UNRST_SLVS,
V4_SNR_CMD_CONF_HSMODE,
V4_SNR_CMD_CLKON_MIPI,
V4_SNR_CMD_CLKOFF_MIPI,
V4_SNR_CMD_CLKON_SLVS,
V4_SNR_CMD_CLKOFF_SLVS,
V4_SNR_CMD_CLKON_SENS,
V4_SNR_CMD_CLKOFF_SENS
};

typedef enum {
Expand Down Expand Up @@ -89,7 +95,7 @@ typedef struct
/* Each lane has two virtual channel, each has four params
If syncSavOn is false: SOF, EOF, SOL, EOL
If syncSavOn is true: invalid sav, invalid eav, valid sav, valid eav */
unsigned short syncCode[4 * 2 * 4];
unsigned short syncCode[V4_SNR_LVDS_LANE_NUM * V4_SNR_WDR_VC_NUM * 4];
} v4_snr_lvds;

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion src/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ int start_region_handler() {
pthread_attr_init(&thread_attr);
size_t stacksize;
pthread_attr_getstacksize(&thread_attr, &stacksize);
size_t new_stacksize = 16 * 1024;
size_t new_stacksize = 256 * 1024;
if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) {
printf(tag "Can't set stack size %zu\n", new_stacksize);
}
Expand Down
72 changes: 63 additions & 9 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,66 @@

const double inv255 = 1.0 / 255.0;

static SFT sft;
static SFT_Image canvas;
static SFT_LMetrics lmtx;
static hal_bitmap bitmap;
SFT sft;
SFT_Image canvas;
SFT_LMetrics lmtx;
hal_bitmap bitmap;

static void text_copy_rendered(SFT_Image *dest, const SFT_Image *source, int x0, int y0, int color)
int utf8_to_utf32(const unsigned char *utf8,
unsigned int *utf32, int max)
{
unsigned int c;
int i = 0;
--max;
while (*utf8)
{
if (i >= max)
return 0;
if (!(*utf8 & 0x80U))
{
utf32[i++] = *utf8++;
}
else if ((*utf8 & 0xe0U) == 0xc0U)
{
c = (*utf8++ & 0x1fU) << 6;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
utf32[i++] = c + (*utf8++ & 0x3fU);
}
else if ((*utf8 & 0xf0U) == 0xe0U)
{
c = (*utf8++ & 0x0fU) << 12;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU) << 6;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
utf32[i++] = c + (*utf8++ & 0x3fU);
}
else if ((*utf8 & 0xf8U) == 0xf0U)
{
c = (*utf8++ & 0x07U) << 18;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU) << 12;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU) << 6;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU);
if ((c & 0xFFFFF800U) == 0xD800U)
return 0;
utf32[i++] = c;
}
else
return 0;
}
utf32[i] = 0;
return i;
}

void text_copy_rendered(SFT_Image *dest, const SFT_Image *source, int x0, int y0, int color)
{
unsigned short maskr = (color & 0x7C00) >> 10;
unsigned short maskg = (color & 0x3E0) >> 5;
Expand All @@ -30,7 +84,7 @@ static void text_copy_rendered(SFT_Image *dest, const SFT_Image *source, int x0,
}
}

static int text_load_font(SFT *sft, const char *path, double size, SFT_LMetrics *lmtx)
int text_load_font(SFT *sft, const char *path, double size, SFT_LMetrics *lmtx)
{
SFT_Font *font = sft_loadfile(path);
if (font == NULL)
Expand All @@ -46,7 +100,7 @@ static int text_load_font(SFT *sft, const char *path, double size, SFT_LMetrics
return EXIT_SUCCESS;
}

static int text_load_glyph(const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph, SFT_GMetrics *metrics)
int text_load_glyph(const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph, SFT_GMetrics *metrics)
{
if (sft_lookup(sft, codepoint, glyph) < 0)
TEXT_ERROR("sft_lookup failed");
Expand All @@ -55,7 +109,7 @@ static int text_load_glyph(const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph
return EXIT_SUCCESS;
}

static void text_new_rendered(SFT_Image *image, int width, int height, int color)
void text_new_rendered(SFT_Image *image, int width, int height, int color)
{
size_t size = (size_t)(width * height * 2);
void *pixels = malloc(size);
Expand All @@ -68,7 +122,7 @@ static void text_new_rendered(SFT_Image *image, int width, int height, int color
((unsigned short*)pixels)[i] = color;
}

static inline void text_dim_rendered(double *margin, double *height, double *width, const char* text)
void text_dim_rendered(double *margin, double *height, double *width, const char* text)
{
double lwidth = 0;
*margin = 0;
Expand Down
60 changes: 4 additions & 56 deletions src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,11 @@

#define TEXT_ERROR(x, ...) \
do { \
fprintf(stderr, "%s \033[31m%s\033[0m\n", "[text] (x)", ##__VA_ARGS__); \
fprintf(stderr, "[text] \033[31m"); \
fprintf(stderr, (x), ##__VA_ARGS__); \
fprintf(stderr, "\033[0m"); \
return EXIT_FAILURE; \
} while (0)

hal_bitmap text_create_rendered(const char *font, double size, const char *text);
hal_dim text_measure_rendered(const char *font, double size, const char *text);

static int utf8_to_utf32(const unsigned char *utf8,
unsigned int *utf32, int max)
{
unsigned int c;
int i = 0;
--max;
while (*utf8)
{
if (i >= max)
return 0;
if (!(*utf8 & 0x80U))
{
utf32[i++] = *utf8++;
}
else if ((*utf8 & 0xe0U) == 0xc0U)
{
c = (*utf8++ & 0x1fU) << 6;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
utf32[i++] = c + (*utf8++ & 0x3fU);
}
else if ((*utf8 & 0xf0U) == 0xe0U)
{
c = (*utf8++ & 0x0fU) << 12;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU) << 6;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
utf32[i++] = c + (*utf8++ & 0x3fU);
}
else if ((*utf8 & 0xf8U) == 0xf0U)
{
c = (*utf8++ & 0x07U) << 18;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU) << 12;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU) << 6;
if ((*utf8 & 0xc0U) != 0x80U)
return 0;
c += (*utf8++ & 0x3fU);
if ((c & 0xFFFFF800U) == 0xD800U)
return 0;
utf32[i++] = c;
}
else
return 0;
}
utf32[i] = 0;
return i;
}
hal_dim text_measure_rendered(const char *font, double size, const char *text);

0 comments on commit 101eeec

Please sign in to comment.