Skip to content

Commit

Permalink
Beginning HAL for AK3918s
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 30, 2024
1 parent 0225d26 commit 1688e9e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/hal/plus/ak_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
#include "../symbols.h"
#include "../types.h"

#define CVI_VI_CHN_NUM 2
#define AK_VENC_CHN_NUM 2
#define AK_VI_CHN_NUM 2
42 changes: 42 additions & 0 deletions src/hal/plus/ak_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include "ak_common.h"
#include "ak_aud.h"
#include "ak_venc.h"
#include "ak_vi.h"

extern char keepRunning;

extern hal_chnstate ak_state[AK_VENC_CHN_NUM];
extern int (*ak_aud_cb)(hal_audframe*);
extern int (*ak_vid_cb)(char, hal_vidstream*);

void ak_hal_deinit(void);
int ak_hal_init(void);

void ak_audio_deinit(void);
int ak_audio_init(int samplerate);
void *ak_audio_thread(void);

int ak_channel_bind(char index);
int ak_channel_grayscale(char enable);
int ak_channel_unbind(char index);

int ak_config_load(char *path);

int ak_pipeline_create(char mirror, char flip);
void ak_pipeline_destroy(void);

int ak_region_create(int *handle, hal_rect rect, short opacity);
void ak_region_destroy(int *handle);
int ak_region_setbitmap(int *handle, hal_bitmap *bitmap);

int ak_video_create(char index, hal_vidconfig *config);
int ak_video_destroy(char index);
int ak_video_destroy_all(void);
void ak_video_request_idr(char index);
int ak_video_snapshot_grab(char index, hal_jpegdata *jpeg);
void *ak_video_thread(void);

void ak_system_deinit(void);
int ak_system_init(void);
27 changes: 14 additions & 13 deletions src/hal/plus/ak_vi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ typedef struct {
typedef struct {
void *handle;

int (*fnGetSensorResolution)(void *device, ak_vi_res *resolution);
int (*fnLoadSensorConfig)(char *path);

int (*fnDisableDevice)(void *device);
void* (*fnEnableDevice)(int device);
int (*fnGetDeviceConfig)(void *device, ak_vi_cnf *config);
int (*fnStartDevice)(void *device);
int (*fnStopDevice)(void *device);

int (*fnSetDeviceConfig)(void *device, ak_vi_cnf *config);
int (*fnSetDeviceFlipMirror)(void *device, int flipOn, int mirrorOn);
int (*fnSetDeviceMode)(void *device, int nightOn);
int (*fnStartDevice)(void *device);
int (*fnStopDevice)(void *device);
} ak_vi_impl;

static int ak_vi_load(ak_vi_impl *vi_lib) {
if (!(vi_lib->handle = dlopen("libplat_vi.so", RTLD_LAZY | RTLD_GLOBAL)))
HAL_ERROR("ak_vi", "Failed to load library!\nError: %s\n", dlerror());

if (!(vi_lib->fnGetSensorResolution = (int(*)(void* device, ak_vi_res *resolution))
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_get_channel_attr")))
return EXIT_FAILURE;

if (!(vi_lib->fnLoadSensorConfig = (int(*)(char *path))
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_match_sensor")))
return EXIT_FAILURE;
Expand All @@ -52,8 +57,12 @@ static int ak_vi_load(ak_vi_impl *vi_lib) {
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_open")))
return EXIT_FAILURE;

if (!(vi_lib->fnGetDeviceConfig = (int(*)(void* device, ak_vi_cnf *config))
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_get_channel_attr")))
if (!(vi_lib->fnStartDevice = (int(*)(void *device))
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_on")))
return EXIT_FAILURE;

if (!(vi_lib->fnStopDevice = (int(*)(void *device))
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_off")))
return EXIT_FAILURE;

if (!(vi_lib->fnSetDeviceConfig = (int(*)(void* device, ak_vi_cnf *config))
Expand All @@ -68,14 +77,6 @@ static int ak_vi_load(ak_vi_impl *vi_lib) {
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_switch_mode")))
return EXIT_FAILURE;

if (!(vi_lib->fnStartDevice = (int(*)(void *device))
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_on")))
return EXIT_FAILURE;

if (!(vi_lib->fnStopDevice = (int(*)(void *device))
hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_off")))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

Expand Down

0 comments on commit 1688e9e

Please sign in to comment.