-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
9,968 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
list(APPEND ADD_INCLUDE | ||
"include" | ||
"lib/libqr" | ||
"lib/system_ctrl" | ||
"lib/system_state" | ||
"lib/system_init" | ||
"lib/oled_ctrl" | ||
"lib/oled_ui" | ||
"lib/hdmi" | ||
) | ||
|
||
list(APPEND ADD_PRIVATE_INCLUDE "") | ||
|
||
append_srcs_dir(ADD_SRCS | ||
"src" | ||
"lib/libqr" | ||
"lib/system_ctrl" | ||
"lib/system_state" | ||
"lib/system_init" | ||
"lib/oled_ctrl" | ||
"lib/oled_ui" | ||
"lib/hdmi" | ||
) # append source file in src dir to var ADD_SRCS | ||
|
||
list(APPEND ADD_REQUIREMENTS basic peripheral) | ||
|
||
register_component() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#ifndef CONFIG_H_ | ||
#define CONFIG_H_ | ||
|
||
#include "maix_basic.hpp" | ||
#include "maix_time.hpp" | ||
#include "maix_gpio.hpp" | ||
#include "maix_pinmap.hpp" | ||
#include "maix_i2c.hpp" | ||
#include "maix_uart.hpp" | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <sys/stat.h> | ||
#include <stdlib.h> | ||
#include <pthread.h> | ||
#include <sys/poll.h> | ||
#include <fstream> | ||
#include <linux/input.h> | ||
|
||
#include "qr.h" | ||
#include "system_ctrl.h" | ||
#include "system_state.h" | ||
#include "system_init.h" | ||
#include "oled_ctrl.h" | ||
#include "oled_ui.h" | ||
#include "hdmi.h" | ||
|
||
#define IP_Change_time 5000 | ||
#define QR_Change_time 5000 | ||
#define STATE_DELAY 1000 | ||
#define OLED_DELAY 1000 | ||
#define KEY_DELAY 100 | ||
#define KEY_LONG_PRESS 1500 | ||
#define KEY_LONGLONG_PRESS 9000 | ||
#define WIFI_CONNECTION_DELAY 5000 | ||
#define OLED_SLEEP_DELAY_MIN 10 | ||
#define OLED_SLEEP_DELAY_DEFAULT 30 | ||
|
||
typedef struct { | ||
int8_t page = 0; | ||
int8_t sub_page = 0; | ||
uint8_t eth_route[16] = {0}; // route ip | ||
uint8_t wifi_route[16] = {0}; // route ip | ||
uint8_t eth_addr[16] = {0}; // ETH ip | ||
uint8_t wifi_addr[16] = {0}; // WiFi ip | ||
uint8_t tail_addr[16] = {0}; // Tailscale ip | ||
uint8_t rndis_addr[16] = {0}; // RNDIS ip | ||
int8_t eth_state = -1; // cat /sys/class/net/eth0/carrier | ||
int8_t wifi_state = -1; // cat /sys/class/net/wlan0/carrier | ||
int8_t tail_state = -1; // ifconfig tailscale0 | grep 'inet addr' | awk '{print $2}' | ||
int8_t hdmi_state = -1; // cat /proc/cvitek/vi_dbg | grep VIFPS | awk '{print $3}' (1s) | ||
int8_t usb_state = -1; // cat /sys/class/udc/4340000.usb/state | ||
int8_t hid_state = -1; // (exist?) /sys/kernel/config/usb_gadget/g0/configs/c.1/hid.GSn(n=012) | ||
int8_t rndis_state = -1; // (exist?) /sys/kernel/config/usb_gadget/g0/configs/c.1/rndis.usb0 | ||
int8_t udisk_state = -1; // (exist?) /sys/kernel/config/usb_gadget/g0/configs/c.1/mass_storage.disk0 | ||
int8_t host_pwr_state = -1; // cat /sys/class/gpio/gpio504/value | ||
int16_t hdmi_width = 0; // cat /kvmapp/kvm/width | ||
int16_t hdmi_height = 0; // cat /kvmapp/kvm/height | ||
int8_t type = 0; // cat /kvmapp/kvm/type | ||
int8_t now_fps = 0; // cat /kvmapp/kvm/now_fps | ||
int16_t qlty = 0; // cat /kvmapp/kvm/qlty | ||
int8_t oled_thread_running = 0; | ||
int8_t key_thread_running = 0; | ||
int8_t sys_thread_running = 0; | ||
int8_t wifi_config_process = -1; // 1:QR;2:Test;3:IP; | ||
char wifi_ap_pass[9] = {0}; | ||
uint8_t oled_sleep_state = 0; // 0:wakeup; 1:sleep; | ||
int8_t reconvery_update = 0; // 0:Undetected; 1:Needs Update; 2:Update finish; -1:not need to update | ||
} kvm_sys_state_t; | ||
|
||
typedef struct { | ||
int8_t page = -1; | ||
int8_t sub_page = -1; | ||
uint8_t eth_route[16] = {0}; // route ip | ||
uint8_t wifi_route[16] = {0}; // route ip | ||
uint8_t eth_addr[16] = {0}; // ETH ip | ||
uint8_t wifi_addr[16] = {0}; // WiFi ip | ||
uint8_t tail_addr[16] = {0}; // Tailscale ip | ||
uint8_t rndis_addr[16] = {0}; // RNDIS ip | ||
int8_t eth_state = -1; // cat /sys/class/net/eth0/carrier | ||
int8_t wifi_state = -1; // cat /sys/class/net/wlan0/carrier | ||
int8_t tail_state = -1; // ifconfig tailscale0 | grep inet\ addr | awk '{print $2}' | ||
int8_t hdmi_state = -1; // cat /proc/cvitek/vi_dbg | grep VIFPS | awk '{print $3}' (1s) | ||
int8_t usb_state = -1; // cat /sys/class/udc/4340000.usb/state | ||
int8_t hid_state = -1; // (exist?) /sys/kernel/config/usb_gadget/g0/configs/c.1/hid.GSn(n=012) | ||
int8_t rndis_state = -1; // (exist?) /sys/kernel/config/usb_gadget/g0/configs/c.1/rndis.usb0 | ||
int8_t udisk_state = -1; // (exist?) /sys/kernel/config/usb_gadget/g0/configs/c.1/mass_storage.disk0 | ||
int8_t host_pwr_state = -1; // cat /sys/class/gpio/gpio504/value | ||
int16_t hdmi_width = -1; // cat /kvmapp/kvm/width | ||
int16_t hdmi_height = -1; // cat /kvmapp/kvm/height | ||
int8_t type = -1; // cat /kvmapp/kvm/type | ||
int8_t now_fps = -1; // cat /kvmapp/kvm/now_fps | ||
int16_t qlty = -1; // cat /kvmapp/kvm/qlty | ||
uint8_t oled_sleep_param = 0; | ||
uint8_t oled_sleep_state = 0; // 0:wakeup; 1:sleep; | ||
uint64_t oled_sleep_start = 0; | ||
} kvm_oled_state_t; | ||
|
||
#endif // CONFIG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
#include "hdmi.h" | ||
|
||
using namespace maix; | ||
using namespace maix::sys; | ||
using namespace maix::peripheral; | ||
i2c::I2C LT6911_i2c(4, i2c::Mode::MASTER); | ||
|
||
void lt6911_enable() | ||
{ | ||
uint8_t buf[2]; | ||
buf[0] = 0xff; | ||
buf[1] = 0x80; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0xee; | ||
buf[1] = 0x01; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
} | ||
|
||
void lt6911_disable() | ||
{ | ||
uint8_t buf[2]; | ||
buf[0] = 0xff; | ||
buf[1] = 0x80; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0xee; | ||
buf[1] = 0x00; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
} | ||
|
||
void lt6911_start() | ||
{ | ||
uint8_t buf[2]; | ||
|
||
buf[0] = 0xff; | ||
buf[1] = 0x80; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0x5A; | ||
buf[1] = 0x80; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
} | ||
|
||
void lt6911_stop() | ||
{ | ||
uint8_t buf[2]; | ||
|
||
buf[0] = 0xff; | ||
buf[1] = 0x80; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0x5A; | ||
buf[1] = 0x88; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
} | ||
|
||
void lt6911_reset() | ||
{ | ||
lt6911_stop(); | ||
time::sleep_ms(1); | ||
lt6911_start(); | ||
} | ||
|
||
void lt6911_get_hdmi_errer() | ||
{ | ||
uint8_t buf[6]; | ||
|
||
buf[0] = 0xff; | ||
buf[1] = 0xC0; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0x20; | ||
buf[1] = 0x01; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
time::sleep_ms(100); | ||
|
||
buf[0] = 0x24; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 1); | ||
|
||
maix::Bytes *dat = LT6911_i2c.readfrom(LT6911_ADDR, 6); | ||
|
||
buf[0] = 0x20; | ||
buf[1] = 0x07; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
for(int i = 0; i < 6; i++){ | ||
buf[i] = (uint8_t)dat->data[i]; | ||
} | ||
delete dat; | ||
|
||
printf("hdmi_errer_code = %x, %x, %x, %x, %x, %x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); | ||
} | ||
|
||
uint8_t lt6911_get_hdmi_res() | ||
{ | ||
uint8_t buf[2]; | ||
uint8_t revbuf[4]; | ||
uint16_t Vactive; | ||
uint16_t Hactive; | ||
|
||
buf[0] = 0xff; | ||
buf[1] = 0xd2; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0x83; | ||
buf[1] = 0x11; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
time::sleep_ms(100); | ||
|
||
// Vactive | ||
buf[0] = 0x96; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 1); | ||
maix::Bytes *dat0 = LT6911_i2c.readfrom(LT6911_ADDR, 2); | ||
|
||
// Hactive | ||
buf[0] = 0x8b; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 1); | ||
maix::Bytes *dat1 = LT6911_i2c.readfrom(LT6911_ADDR, 2); | ||
|
||
revbuf[0] = (uint8_t)dat0->data[0]; | ||
revbuf[1] = (uint8_t)dat0->data[1]; | ||
revbuf[2] = (uint8_t)dat1->data[0]; | ||
revbuf[3] = (uint8_t)dat1->data[1]; | ||
|
||
Vactive = (revbuf[0] << 8)|revbuf[1]; | ||
Hactive = (revbuf[2] << 8)|revbuf[3]; | ||
Hactive *= 2; | ||
|
||
printf("HDMI res modification event\n"); | ||
printf("new res: %d * %d\n", Hactive, Vactive); | ||
|
||
delete dat0; | ||
delete dat1; | ||
|
||
if (Vactive != 0 && Hactive != 0){ | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
void lt6911_get_hdmi_clk() | ||
{ | ||
uint8_t buf[2]; | ||
uint8_t revbuf[3]; | ||
uint32_t clk; | ||
|
||
buf[0] = 0xff; | ||
buf[1] = 0xa0; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0x34; | ||
buf[1] = 0x0b; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
time::sleep_ms(50); | ||
|
||
// clk | ||
buf[0] = 0xff; | ||
buf[1] = 0xb8; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
buf[0] = 0xb1; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 1); | ||
maix::Bytes *dat0 = LT6911_i2c.readfrom(LT6911_ADDR, 3); | ||
|
||
revbuf[0] = (uint8_t)dat0->data[0]; | ||
revbuf[1] = (uint8_t)dat0->data[1]; | ||
revbuf[2] = (uint8_t)dat0->data[2]; | ||
revbuf[0] &= 0x07; | ||
|
||
clk = revbuf[0]; | ||
clk <<= 8; | ||
clk |= revbuf[1]; | ||
clk <<= 8; | ||
clk |= revbuf[2]; | ||
|
||
printf("HDMI CLK = %d\n", clk); | ||
|
||
delete dat0; | ||
} | ||
|
||
uint8_t lt6911_get_csi_res() | ||
{ | ||
uint8_t ret = 0; | ||
uint8_t buf[2]; | ||
uint8_t revbuf[4]; | ||
static uint16_t old_Vactive; | ||
static uint16_t old_Hactive; | ||
uint16_t Vactive; | ||
uint16_t Hactive; | ||
char Cmd[100]={0}; | ||
|
||
buf[0] = 0xff; | ||
buf[1] = 0xc2; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 2); | ||
|
||
// Vactive | ||
buf[0] = 0x06; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 1); | ||
maix::Bytes *dat0 = LT6911_i2c.readfrom(LT6911_ADDR, 2); | ||
|
||
// Hactive | ||
buf[0] = 0x38; | ||
LT6911_i2c.writeto(LT6911_ADDR, buf, 1); | ||
maix::Bytes *dat1 = LT6911_i2c.readfrom(LT6911_ADDR, 2); | ||
|
||
revbuf[0] = (uint8_t)dat0->data[0]; | ||
revbuf[1] = (uint8_t)dat0->data[1]; | ||
revbuf[2] = (uint8_t)dat1->data[0]; | ||
revbuf[3] = (uint8_t)dat1->data[1]; | ||
|
||
Vactive = (revbuf[0] << 8)|revbuf[1]; | ||
Hactive = (revbuf[2] << 8)|revbuf[3]; | ||
|
||
if(old_Hactive != Hactive || old_Vactive != Vactive){ | ||
old_Hactive = Hactive; | ||
old_Vactive = Vactive; | ||
ret = 1; | ||
} | ||
|
||
printf("CSI res: %d * %d\n", Hactive, Vactive); | ||
// setenv("KVM_CSI_HEIGHT", to_string(Hactive).c_str(), 1); | ||
// setenv("KVM_CSI_WIDTH", to_string(Vactive).c_str(), 1); | ||
|
||
sprintf(Cmd, "echo %d > /kvmapp/kvm/width", Hactive); | ||
system(Cmd); | ||
sprintf(Cmd, "echo %d > /kvmapp/kvm/height", Vactive); | ||
system(Cmd); | ||
|
||
delete dat0; | ||
delete dat1; | ||
|
||
return ret; | ||
} |
Oops, something went wrong.