A272R版本优化

This commit is contained in:
2025-05-26 10:28:49 +08:00
parent 3b3c63f1f3
commit 413dd88f3b
22 changed files with 30925 additions and 30666 deletions

View File

@ -204,7 +204,7 @@ void send_mul_touchscreen_x_y_2_carplay(
unsigned short x2, unsigned short y2
);
/*
* @brief 发送旋钮信息给苹果;
* @brief 发送旋钮信息给苹果手机,不建议用这个;
*/
void KnobUpdate(char gSelectButtonPressed,
char gHomeButtonPressed,
@ -213,6 +213,15 @@ void KnobUpdate(char gSelectButtonPressed,
double gYPosition,
char gWheelPositionRelative
);
/*
* @brief 发送旋钮信息给苹果手机;
*/
void sendKnobInfo( char gSelectButtonPressed,
char gHomeButtonPressed,
char gBackButtonPressed,
char gXPosition,
char gYPosition,
char gWheelPositionRelative);
/*
* @brief 请求iphone启动一个应用;
@ -266,6 +275,8 @@ void process_record_stream(int handle, void *buffer, int len, int frames, unsign
int carplay_get_iphone_ip_addr(char *ipaddr);
void carplay_wl_set_iphone_mac_addr(char bt_addr[6]);
int carplay_get_connected_iphone_wifi_mac(char mac[18]);
#ifdef __cplusplus
}
#endif

View File

@ -131,6 +131,18 @@ typedef struct __carplay_cfg_info
}carplay_cfg_info;
typedef struct _carlink_flash_io
{
uint32_t (*get_data_arae_size)(void* ctx);
uint32_t (*get_flash_block_erase_size)(void* ctx);
int32_t (*op_flash)(void* flash_handle, void* ctx, int open);
int32_t (*read_data)(void* flash_handle, void *data, uint32_t length, uint32_t offset, void* ctx);
int32_t (*write_data)(void* flash_handle, void *data, uint32_t length, uint32_t offset, void* ctx);
void* ctx;
void* flash_handle;
} carlink_flash_io;
void register_carlink_flash_io_interface(carlink_flash_io *handle);
#if 0
typedef struct __auto_cfg_info
{

View File

@ -20,8 +20,10 @@
#include "carlink_common.h"
#include "board.h"
#if CARLINK_CP
struct carplay_ctx
{
struct ICalinkEventCallbacks carlinkEventCB;
@ -35,6 +37,7 @@ struct carplay_ctx
char mRemoteBTMac[6];
char mIp[32];
char mPhoneWifiMac[18];
void* mVideoHandle;
};
struct carplay_ctx g_cp_handle;
@ -46,6 +49,85 @@ void start_mdnsd();
void start_mdnsd_posix();
void stop_mdnsd_posix();
#if DEVICE_TYPE_SELECT == SPI_NOR_FLASH
#include "sfud.h"
//根据spi nor flash实际使用情况分配
#ifndef CARLINK_CP_OFFSET
#define CARLINK_CP_OFFSET 0X39000
#endif
#ifndef CARLINK_CP_SIZE
#define CARLINK_CP_SIZE 0x2000
#endif
static int g_sf_read_ptr;
static int32_t cp_sf_op_flash(void* flash_handle, void* ctx, int open)
{
g_sf_read_ptr = 0;
return 0;
}
static int32_t cp_sf_read_data(void* flash_handle, void *data, uint32_t length, uint32_t offset, void* ctx)
{
printf("TRACE[%s][%d] start:len=%d\r\n", __func__ ,__LINE__,length);
int32_t ret = 0;
char num[5] = {0};
uint8_t* readData = NULL;
if (g_sf_read_ptr > CARLINK_CP_SIZE)
return 0;
readData = malloc(CARLINK_CP_SIZE);
memset(readData, 0, CARLINK_CP_SIZE);
sfud_flash *sflash = sfud_get_device(0);
if (SFUD_SUCCESS == sfud_read(sflash, CARLINK_CP_OFFSET, CARLINK_CP_SIZE, readData)) {
memcpy(num, readData, 4);
ret = atoi(num);
if(ret > 0) {
if (ret > length)
ret = length;
if (ret > CARLINK_CP_SIZE)
ret = (CARLINK_CP_SIZE - 4);
memcpy(data, readData + 4, ret);
g_sf_read_ptr += CARLINK_CP_SIZE;
} else {
ret = 0;
}
}
free(readData);
printf("TRACE[%s][%d] end: ret=%d\r\n", __func__ ,__LINE__,ret);
return ret;
}
static int32_t cp_sf_write_data(void* flash_handle, void *data, uint32_t length, uint32_t offset, void* ctx)
{
int ret = 0;
char* writeData = NULL;
if ((length + 4) > CARLINK_CP_SIZE)
length = CARLINK_CP_SIZE - 4;
writeData = malloc(length + 4);
printf("TRACE[%s][%d] start: len=%d\r\n", __func__ ,__LINE__, length);
sprintf(writeData, "%04d", length);
memcpy(writeData + 4, data, length);
sfud_flash *sflash = sfud_get_device(0);
sfud_erase(sflash, CARLINK_CP_OFFSET, CARLINK_CP_SIZE);
if (SFUD_SUCCESS == sfud_erase_write(sflash, CARLINK_CP_OFFSET, length + 4, (void*)writeData)) {
ret = length;
}
free(writeData);
printf("TRACE[%s][%d] end:ret=%d\r\n", __func__ ,__LINE__,ret);
return ret;
}
#endif
static void carplay_notify_event(struct carlink_event *ev, enum CARLINK_EVENT_TYPE type, bool disable_filter)
{
ev->link_type = CARLINK_CARPLAY_WIRELESS;
@ -54,8 +136,6 @@ static void carplay_notify_event(struct carlink_event *ev, enum CARLINK_EVENT_TY
carlink_notify_event(ev);
}
static void iap2_link_status(void *ctx, IAP2_LINK_STATUS status){}
static int iap2_write_data(void *ctx, char *buf, int len)
{
@ -85,7 +165,7 @@ static void iap2_msg_identify(void *ctx, int type, int ok)
start_mdnsd_posix();
}
}
static void iap2_msg_wl_carplay_update(void *ctx, int status)//<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD>"Carplay<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
static void iap2_msg_wl_carplay_update(void *ctx, int status)//手机端"Carplay车载"是否开启
{
struct carplay_ctx* pctx = (struct carplay_ctx*)ctx;
@ -147,9 +227,15 @@ static void audio_stop_callback_impl(void *ctx, int handle, int type)
static int video_start_callback_impl(void *ctx)
{
#if !DISABLE_CARLINK_H264_FRAME_BUF
h264_dec_ctx_init();
set_carlink_display_state(1);
//key_value = 1;
#else
struct carplay_ctx* pctx = (struct carplay_ctx*)ctx;
pctx->mVideoHandle = h264_video_player_init();
#endif
return 0;
}
@ -157,17 +243,24 @@ static void video_stop_callback_impl(void *ctx)
{
//key_value = 0;
printf("%s:%d\r\n", __func__, __LINE__);
#if !DISABLE_CARLINK_H264_FRAME_BUF
set_carlink_display_state(0);
#else
struct carplay_ctx* pctx = (struct carplay_ctx*)ctx;
h264_video_player_uninit(pctx->mVideoHandle);
#endif
}
static int video_proc_data_callback_impl(void *ctx, char *buf, int len)
{
#if !DISABLE_CARLINK_H264_FRAME_BUF
video_frame_s* frame = NULL;
//printf("video_proc_data len:%d\r\n", len);
get_retry:
frame = get_h264_frame_buf();
if (NULL == frame) {
//printf("h264 frame is empty\r\n");
printf("h264 frame is empty\r\n");
vTaskDelay(pdMS_TO_TICKS(10));
goto get_retry;
//continue;
@ -177,6 +270,10 @@ get_retry:
frame->len = len;
notify_h264_frame_ready(&frame);
#else
struct carplay_ctx* pctx = (struct carplay_ctx*)ctx;
h264_video_player_proc(pctx->mVideoHandle, buf, len);
#endif
return 0;
}
static void carplay_viewArea_update_notify(void *ctx, int index){}
@ -229,48 +326,45 @@ static void carlink_cp_input_event_proc(const struct carlink_event *ev)
bool pressed = (bool)ev->u.para[1];
//printf("key %d %d\n", key, (int)pressed);
#if 0
if (key == 19) {//right
if (!pressed)
KnobUpdate(0, 0, 0, 0, 0, 0);
if (0) {
} else if (key == 19) {
/*if (!pressed)
sendKnobInfo(0, 0, 0, 0, 0, 0);//up在主界面向上移动光标
else
KnobUpdate(0, 0, 0, 1.0, 0, 0);
sendKnobInfo(0, 0, 0, 0, 1, 0);*/
if (pressed) {//退后台手机停止发送carplay视频流
carplay_send_change_modes(CarplayTransferType_Take, CarplayTransferPriority_UserInitiated,
CarplayConstraint_Never, CarplayConstraint_Never,
0, 0, 0, 0, 0, 0, 0);
}
} else if (key == 20) {
if (!pressed)
KnobUpdate(0, 0, 0, 0, 0, 0);
/*if (!pressed)
sendKnobInfo(0, 0, 0, 0, 0, 0); //down在主界面向下移动光标
else
KnobUpdate(0, 0, 0, -1.0, 0, 0);
}if (key == 18) {//up
if (!pressed)
KnobUpdate(0, 0, 0, 0, 0, 0);
else
KnobUpdate(0, 0, 0, 0, 1.0, 0);
} else if (key == 17) {//down
if (!pressed)
KnobUpdate(0, 0, 0, 0, 0, 0);
else
KnobUpdate(0, 0, 0, 0, -1.0, 0);
} else if (key == 27) {
KnobUpdate(1, 0, 0, 0, 0, 0);
}
#else
if (key == 19) {//right
if (!pressed)
request_UI("maps:");
} else if (key == 20) {
if (!pressed)
request_UI("music:");
} else if (key == 18) {//left
sendKnobInfo(0, 0, 0, 0, -1, 0);*/
if (pressed) {//回前台手机重新发送carplay视频流
carplay_send_change_modes(CarplayTransferType_Untake,
0, 0, 0,
0, 0, 0, 0, 0, 0, 0);
request_UI(NULL);
}
} else if (key == 18) {//previos
if (pressed)
KnobUpdate(0, 0, 0, 0, 0, 1);
sendKnobInfo(0, 0, 0, 0, 0, 1);
//else
// sendKnobInfo(0, 0, 0, 0, 0, 0);
} else if (key == 17) {//right
} else if (key == 17) {//next
if (pressed)
KnobUpdate(0, 0, 0, 0, 0, -1);
sendKnobInfo(0, 0, 0, 0, 0, -1);
//else
// sendKnobInfo(0, 0, 0, 0, 0, 0);
} else if (key == 27) {// enter
if (pressed)
sendKnobInfo(1, 0, 0, 0, 0, 0);
else
sendKnobInfo(0, 0, 0, 0, 0, 0);
}
#endif
}
static void onEventCarplay(void* ctx, const struct carlink_event *ev)
@ -311,7 +405,7 @@ static void onEventCarplay(void* ctx, const struct carlink_event *ev)
case CARLINK_EVENT_BT_DISCONNECT: {
printf("bt disconnect, iap disconnect %d %d\r\n", pctx->mIapReady, pctx->mPhoneCarplayFlag);
if (pctx->mIapReady && !pctx->mPhoneCarplayFlag) {
//<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD>"Carplay<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22>رգ<D8B1>ͬʱƻ<CAB1><C6BB><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD>ر<EFBFBD><D8B1>ˣ<EFBFBD>ִ<EFBFBD><D6B4>һ<EFBFBD><D2BB>carplay stop
//手机端"Carplay车载"关闭,同时苹果手机蓝牙也关闭了,执行一下carplay stop
carplay_stop();
}
pctx->mIapReady = false;
@ -413,7 +507,7 @@ static void taskInitCarlinkCpProc(void* param)
video_cbs.video_start_callback = video_start_callback_impl;
video_cbs.video_stop_callback = video_stop_callback_impl;
video_cbs.video_proc_data_callback = video_proc_data_callback_impl;
video_cbs.ctx = NULL;
video_cbs.ctx = (void*)pctx;
video_register_callbacks((void *)(&video_cbs));
audio_callbacks_t audio_cbs;
@ -504,13 +598,25 @@ static void carplay_init_parameter()
g_link_info->icurrent = 1000;
g_link_info->enable_iap_carplay_sess = 1;
#if DEVICE_TYPE_SELECT != EMMC_FLASH
g_link_info->keychain_path_dir = "/sf";
{
static carlink_flash_io io = {0};
io.op_flash = cp_sf_op_flash;
io.read_data = cp_sf_read_data;
io.write_data = cp_sf_write_data;
//sfud_erase(sfud_get_device(0), CARLINK_CP_OFFSET, CARLINK_CP_SIZE);
register_carlink_flash_io_interface(&io);
}
#else
g_link_info->keychain_path_dir = DEVICE_PARTITION_NAME;
#endif
g_link_info->is_old_carplay_ver = 0;
g_link_info->enable_single_ui = 1;
g_link_info->disable_carplay_audio = 1;//1. audio is stream to bt;
//g_link_info->mfi_ic_addr = 0x22; //cp2.0
//g_link_info->mfi_ic_addr = 0x22; //cp2.0的地址由reset脚决定
g_link_info->mfi_ic_addr = 0x20; //cp3.0
g_link_info->mfi_ic_i2c_bus_num = 0;

View File

@ -343,5 +343,3 @@ int ark_network_init()
return (int)ret;
}

View File

@ -582,12 +582,15 @@ eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase,
static BaseType_t carlink_wifi_init()
{
int status;
static int wifi_sdio_status = MMCSD_HOST_UNPLUGED;
if (wifi_sdio_status == MMCSD_HOST_PLUGED)
return 0;
WIFI_Context_init();
WIFI_RegisterEvent(eWiFiEventMax, carlink_wifi_event_handler);
for (;;) {
status = mmcsd_wait_sdio_ready((int32_t)portMAX_DELAY);
if (status == MMCSD_HOST_PLUGED) {
wifi_sdio_status = mmcsd_wait_sdio_ready((int32_t)portMAX_DELAY);
if (wifi_sdio_status == MMCSD_HOST_PLUGED) {
printf("detect sdio device\r\n");
break;
}
@ -613,8 +616,14 @@ static void bt_set_support_carplay_android_auto()//auto + cp
console_send_atcmd(cmd_str, strlen(cmd_str));
}
static void taskInitCarlinkWlanThread(void* param)
{
carlink_start_wlan();
vTaskDelete(NULL);
}
int carlink_bt_wifi_init()
{
int retry_count = 0;
pthread_mutex_lock(&btwifiLocker);
if (g_bt_wifi_init_flag) {
pthread_mutex_unlock(&btwifiLocker);
@ -627,14 +636,24 @@ int carlink_bt_wifi_init()
//bt_set_support_carplay();
bt_set_support_carplay_android_auto();
carlink_bt_open_nolock();
carlink_start_wlan();
g_bt_wifi_init_flag = 1;
lwip_tcpip_init_done_flag = 0;
xTaskCreate(taskInitCarlinkWlanThread, "initThread", 2048 * 4, NULL, 1, NULL);
while(lwip_tcpip_init_done_flag == 0) {
if (retry_count++ > 50)
break;
vTaskDelay(pdMS_TO_TICKS(300));
}
if (lwip_tcpip_init_done_flag) {
g_bt_wifi_init_flag = 1;
printf("bt wlan init ok\r\n");
} else {
g_bt_wifi_init_flag = 0;
printf("bt wlan init failed\r\n");
}
pthread_mutex_unlock(&btwifiLocker);
printf("bt wlan init is ok\r\n");
// app_wifi_update_demo();
wifi_update_init();
printf("app wlan update init ok\r\n");
return 0;
}

View File

@ -103,7 +103,7 @@ void carlink_register_event_callbacks(const struct ICalinkEventCallbacks *pcb)
int carlink_common_init()
{
FF_Disk_t *sfdisk = NULL;
//FF_Disk_t *sfdisk = NULL;
BaseType_t ret = -1;
pthread_mutex_lock(&carlink_com_locker);
@ -120,14 +120,14 @@ int carlink_common_init()
}
pthread_key_system_init();
#if 0
sfdisk = FF_SFDiskInit("/sf");
if (!sfdisk) {
printf("FF_SFDiskInit fail.\r\n");
//return;
}
ret = xTaskCreate(carlink_event_proc, "cl_ev_proc", 2048, NULL, configMAX_PRIORITIES / 5, NULL);
#endif
ret = xTaskCreate(carlink_event_proc, "cl_ev_proc", 2048, NULL, configMAX_PRIORITIES - 1, NULL);
g_comm_init_flag = 1;
exit:

View File

@ -31,6 +31,11 @@ void set_carlink_display_info(int x, int y, int w, int h);//set carlink show are
void set_carlink_display_state(int on); // on: 1.display carlink; 0. display native ui
void set_carlink_active_video_info(int x, int y);//for android auto
void* h264_video_player_init();
void h264_video_player_uninit(void* h264_Handle);
int h264_video_player_proc(void* h264_Handle, const char *h264_buf, int h264_buf_len);
#define WRITE_BE32(ptr, val) \
do { \
uint8_t* __ptr = (uint8_t*)(ptr); \

View File

@ -131,6 +131,19 @@ typedef struct __carplay_cfg_info
}carplay_cfg_info;
typedef struct _carlink_flash_io
{
uint32_t (*get_data_arae_size)(void* ctx);
uint32_t (*get_flash_block_erase_size)(void* ctx);
int32_t (*op_flash)(void* flash_handle, void* ctx, int open);
int32_t (*read_data)(void* flash_handle, void *data, uint32_t length, uint32_t offset, void* ctx);
int32_t (*write_data)(void* flash_handle, void *data, uint32_t length, uint32_t offset, void* ctx);
void* ctx;
void* flash_handle;
} carlink_flash_io;
void register_carlink_flash_io_interface(carlink_flash_io *handle);
#if 0
typedef struct __auto_cfg_info
{
short width;//pixel
@ -142,10 +155,10 @@ typedef struct __auto_cfg_info
bool disable_carplay_audio;
} auto_cfg_info;
#endif
extern carplay_cfg_info *g_link_info;
extern auto_cfg_info *g_auto_link_info;
//extern auto_cfg_info *g_auto_link_info;
#ifdef __cplusplus
}

View File

@ -68,6 +68,10 @@ void check_key(void)
gs_keyDat[i].flag_Reset=1;
gs_keyDat[i].keyCnt=0;
// printf("LV_KEY_OPTION key long key\r\n");
if(Get_sys_wifi_state()){
printf("key carplay -----------------maps.\r\n");
request_UI("maps:");
}else
Key_Distinction(KEY_LONG_ON,LV_KEY_OPTION);
}
if(i==1 && gs_keyDat[0].flag_Pressed==KEY_OFF)
@ -75,6 +79,11 @@ void check_key(void)
gs_keyDat[i].flag_Reset=1;
gs_keyDat[i].keyCnt=0;
// printf("LV_KEY_SELECT key long key\r\n");
if(Get_sys_wifi_state()){
printf("key carplay -----------------enter.\r\n");
// KnobUpdate(1,0,0,0,0,0);
sendKnobInfo(1, 0, 0, 0, 0, 0);
}else
Key_Distinction(KEY_LONG_ON,LV_KEY_SELECT);
}
@ -100,6 +109,11 @@ void check_key(void)
// // android_auto_send_knob_event(19,1);
// // android_auto_send_knob_event(19,0);
// }else
if(Get_sys_wifi_state()){
printf("key carplay -----------------previos.\r\n");
// KnobUpdate(0,0,0,0,0,1);
sendKnobInfo(0, 0, 0, 0, 0, 1);
}else
Key_Distinction(KEY_SHORT_ON,LV_KEY_OPTION);
}
else if(i==1 && gs_keyDat[0].flag_Pressed==KEY_OFF)
@ -118,6 +132,11 @@ void check_key(void)
// // android_auto_send_knob_event(20,1);
// // android_auto_send_knob_event(20,0);
// }else
if(Get_sys_wifi_state()){
printf("key carplay -----------------next.\r\n");
// KnobUpdate(0,0,0,0,0,-1);
sendKnobInfo(0, 0, 0, 0, 0, -1);
}else
Key_Distinction(KEY_SHORT_ON,LV_KEY_SELECT);
}
}