change lvgl default PPI to 260, update maixcam2 pinmap io name

This commit is contained in:
Neucrack
2025-08-27 19:45:21 +08:00
parent 8cb2a6d710
commit 883248e24c
9 changed files with 173 additions and 75 deletions

View File

@@ -72,7 +72,7 @@ extern void lv_ui_mutex_unlock();
/*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings.
*(Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI_DEF 180 /*[px/inch]*/
#define LV_DPI_DEF 260 /*[px/inch]*/
/*=================
* OPERATING SYSTEM

View File

@@ -508,6 +508,58 @@ namespace maix::sys
res["total"] = total_memory * 1024;
#if PLATFORM_MAIXCAM
res["hw_total"] = 256 * 1024 * 1024;
file = fopen("/sys/kernel/debug/ion/cvi_carveout_heap_dump/alloc_mem", "r");
if (!file)
{
log::warn("Cannot open /sys/kernel/debug/ion/cvi_carveout_heap_dump/alloc_mem");
}
else
{
unsigned long used_cmm_memory = 0;
while (fgets(line, sizeof(line), file))
{
int i = 0;
while(1)
{
if(line[i] != ' ' && line[i] != '\t')
break;
++i;
}
if (sscanf(line + i, "%ld", &used_cmm_memory) == 1)
{
break;
}
}
fclose(file);
res["cmm_used"] = used_cmm_memory;
}
file = fopen("/sys/kernel/debug/ion/cvi_carveout_heap_dump/total_mem", "r");
if (!file)
{
log::warn("Cannot open /sys/kernel/debug/ion/cvi_carveout_heap_dump/total_mem");
}
else
{
unsigned long total_cmm_memory = 0;
while (fgets(line, sizeof(line), file))
{
int i = 0;
while(1)
{
if(line[i] != ' ' && line[i] != '\t')
break;
++i;
}
if (sscanf(line + i, "%ld", &total_cmm_memory) == 1)
{
break;
}
}
fclose(file);
res["cmm_total"] = total_cmm_memory;
}
#elif PLATFORM_MAIXCAM2
file = fopen("/proc/ax_proc/mem_cmm_info", "r");
if (!file)

View File

@@ -70,20 +70,20 @@ namespace maix::comm
#elif PLATFORM_MAIXCAM2
std::map<std::string, std::map<std::string, std::string>> pins_map = {
{"uart1", {
{"IO0_A30", "UART1_TX"},
{"IO1_A3", "UART1_RX"},
{"A30", "UART1_TX"},
{"B3", "UART1_RX"},
}},
{"uart2", {
{"IO1_A0", "UART2_TX"},
{"IO1_A1", "UART2_RX"},
{"B0", "UART2_TX"},
{"B1", "UART2_RX"},
}},
{"uart3", {
{"IO1_A2", "UART3_TX"},
{"IO1_A3", "UART3_RX"},
{"B2", "UART3_TX"},
{"B3", "UART3_RX"},
}},
{"uart4", {
{"IO0_A21", "UART4_TX"},
{"IO0_A22", "UART4_RX"},
{"A21", "UART4_TX"},
{"A22", "UART4_RX"},
}},
};
#else

View File

@@ -55,13 +55,13 @@ public:
/**
* @brief Construct a new PMU object, will open PMU.
*
* @param driver driver name, only support "axp2101".
* @param driver driver name, support "axp2101" "maixcam2", default empty means use default.
* @param i2c_bus i2c bus number. Automatically selects the on-board pmu when -1 is passed in.
* @param addr PMU i2c addr.
*
* @maixpy maix.ext_dev.pmu.PMU.__init__
*/
PMU(std::string driver = "axp2101", int i2c_bus = -1, int addr = 0x34);
PMU(std::string driver = "", int i2c_bus = -1, int addr = 0x34);
~PMU();
/**

View File

@@ -2,6 +2,8 @@
#include "maix_basic.hpp"
#include "maix_pmu.hpp"
#include "maix_axp2101.hpp"
#include <iostream>
#include <string>
namespace maix::ext_dev::pmu {
@@ -13,11 +15,33 @@ typedef struct {
PMU::PMU(std::string driver, int i2c_bus, int addr)
{
err::check_bool_raise(driver == "axp2101", "Only support axp2101 now");
const char *err_msg = "Only support axp2101 and maixcam2 now";
err::check_bool_raise(driver.empty() || driver == "axp2101", err_msg);
pmu_param_t *param = (pmu_param_t *)malloc(sizeof(pmu_param_t));
err::check_null_raise(param, "Failed to malloc param");
param->driver.axp2101 = new maix::ext_dev::axp2101::AXP2101(i2c_bus, addr);
if(driver.empty())
{
if(sys::device_id() == "maixcam_pro")
driver = "axp2101";
else if(sys::device_id() == "maixcam2")
driver = "maixcam2";
}
if(driver == "axp2101")
{
param->driver.axp2101 = new maix::ext_dev::axp2101::AXP2101(i2c_bus, addr);
}
else if (driver == "maixcam2")
{
// do nothing
// TODO: add maixcam pmu class
}
else
{
free(param);
err::check_bool_raise(false, err_msg);
}
_param = (void *)param;
_driver = driver;
}
@@ -52,6 +76,10 @@ bool PMU::is_bat_connect()
if (_driver == "axp2101") {
ret = param->driver.axp2101->is_bat_connect();
}
else if (_driver == "maixcam2")
{
return true;
}
return ret;
}
@@ -72,6 +100,9 @@ bool PMU::is_charging()
if (_driver == "axp2101") {
ret = param->driver.axp2101->is_charging();
}
else if (_driver == "maixcam2") {
ret = get_bat_percent() != 100;
}
return ret;
}
@@ -82,6 +113,13 @@ int PMU::get_bat_percent()
if (_driver == "axp2101") {
ret = param->driver.axp2101->get_bat_percent();
}
else if (_driver == "maixcam2") {
// read from /sys/class/power_supply/cw2015-battery/capacity
auto f = fs::File("/sys/class/power_supply/cw2015-battery/capacity", "r");
auto line = f.readline();
ret = std::stoi(*line);
delete line;
}
return ret;
}
@@ -92,6 +130,9 @@ ext_dev::pmu::ChargerStatus PMU::get_charger_status()
if (_driver == "axp2101") {
ret = (ext_dev::pmu::ChargerStatus)param->driver.axp2101->get_charger_status();
}
else if (_driver == "maixcam2") {
return ext_dev::pmu::ChargerStatus::CHG_CC_STATE;
}
return ret;
}

View File

@@ -41,7 +41,7 @@ namespace maix::peripheral::spi
* @param[in] bits bits of spi, int type, default is 8.
* @param[in] hw_cs use hardware CS id, -1 means use default(e.g. for MaixCAM2 SPI2 is CS1), 0 means use CS0, 1 means use CS1 ...
* @param[in] soft_cs use soft CS instead of hw_cs, default empty string means not use soft CS control, so you can use hw_cs or control CS pin by your self with GPIO module.
* if set GPIO name, for example GPIOA19(MaixCAM) or GPIO0_A2(MaixCAM2), this class will automatically init GPIO object and control soft CS pin when read/write.
* if set GPIO name, for example GPIOA19(MaixCAM) or GPIOA2(MaixCAM2), this class will automatically init GPIO object and control soft CS pin when read/write.
* Attention, you should set GPIO's pinmap first by yourself first.
* Attention, the driver may still own the hw_cs pin and perform control hw_cs, you can use pinmap to map hw_cs pin to other function to avoid this.
* @param[in] cs_active_low CS pin low voltage means activate slave device, default true. hw_cs only support true, soft_cs support both.

View File

@@ -14,17 +14,18 @@
{
bool maix_gpio_port_parse_pin(const std::string& pin_str, int& group, int& index) {
// GPIO0_A4 --> 0, 4
// IO1_A16 --> 1, 16
std::regex pattern(R"(^(GPIO|IO)(\d{1,2})_A(\d{1,2})$)");
std::smatch match;
// GPIOA4 --> 0, 4
// IOB16 --> 1, 16
std::regex pattern(R"(^((GPIO)?)([A-Z])(\d{1,2})$)");
std::smatch match;
if (std::regex_match(pin_str, match, pattern)) {
group = std::stoi(match[2].str());
index = std::stoi(match[3].str());
return true;
}
return false;
if (std::regex_match(pin_str, match, pattern)) {
char group_char = match[3].str()[0];
group = group_char - 'A'; // 'A' -> 0, 'B' -> 1, ..., 'Z' -> 25
index = std::stoi(match[4].str());
return true;
}
return false;
}
}; // namespace maix::peripheral::gpio

View File

@@ -35,177 +35,177 @@
static const std::map<std::string, PinInfo> pins_info = {
{"IO0_A0",
{"A0", // GPIO0_A0
PinInfo {
std::vector<std::string> {"GPIO0_A0", "I2C6_SDA", "SPI1_MOSI"},
std::vector<std::string> {"GPIOA0", "I2C6_SDA", "SPI1_MOSI"},
PinRegInfo {0x0230000C, 16, 3},
std::vector<int> {6, 3, 2}
}
},
{"IO0_A1",
{"A1", // GPIO0_A1
PinInfo {
std::vector<std::string> {"GPIO0_A1", "I2C6_SCL", "SPI1_MISO"},
std::vector<std::string> {"GPIOA1", "I2C6_SCL", "SPI1_MISO"},
PinRegInfo {0x02300018, 16, 3},
std::vector<int> {6, 3, 2}
}
},
{"IO0_A2",
{"A2", // GPIO0_A2
PinInfo {
std::vector<std::string> {"GPIO0_A2", "SPI1_CS0"},
std::vector<std::string> {"GPIOA2", "SPI1_CS0"},
PinRegInfo {0x02300024, 16, 3},
std::vector<int> {6, 2}
}
},
{"IO0_A4",
{"A4", // GPIO0_A4
PinInfo {
std::vector<std::string> {"GPIO0_A4", "SPI1_SCK", "I2C5_SDA"},
std::vector<std::string> {"GPIOA4", "SPI1_SCK", "I2C5_SDA"},
PinRegInfo {0x0230003C, 16, 3},
std::vector<int> {6, 2, 3}
}
},
{"IO0_A6",
{"A6", // GPIO0_A6
PinInfo {
std::vector<std::string> {"GPIO0_A6"}, // state_led
std::vector<std::string> {"GPIOA6"}, // state_led
PinRegInfo {0x02300054, 16, 3},
std::vector<int> {6}
}
},
{"IO0_A8",
{"A8", // GPIO0_A8
PinInfo {
std::vector<std::string> {"GPIO0_A8", "I2C7_SCL"},
std::vector<std::string> {"GPIOA8", "I2C7_SCL"},
PinRegInfo {0x0230006C, 16, 3},
std::vector<int> {6, 3}
}
},
{"IO0_A9",
{"A9", // GPIO0_A9
PinInfo {
std::vector<std::string> {"GPIO0_A9", "I2C7_SDA"},
std::vector<std::string> {"GPIOA9", "I2C7_SDA"},
PinRegInfo {0x02300078, 16, 3},
std::vector<int> {6, 3}
}
},
{"IO0_A21",
{"A21", // GPIO0_A21
PinInfo {
std::vector<std::string> {"GPIO0_A21", "UART4_TX"},
std::vector<std::string> {"GPIOA21", "UART4_TX"},
PinRegInfo {0x02302090, 16, 3},
std::vector<int> {6, 1}
}
},
{"IO0_A22",
{"A22", // GPIO0_A22
PinInfo {
std::vector<std::string> {"GPIO0_A22", "UART4_RX"},
std::vector<std::string> {"GPIOA22", "UART4_RX"},
PinRegInfo {0x0230209C, 16, 3},
std::vector<int> {6, 1}
}
},
{"IO0_A28",
{"A28", // GPIO0_A28
PinInfo {
std::vector<std::string> {"GPIO0_A28", "UART0_TX"}, // system log output
std::vector<std::string> {"GPIOA28", "UART0_TX"}, // system log output
PinRegInfo {0x0230403C, 16, 3},
std::vector<int> {6, 0}
}
},
{"IO0_A29",
{"A29", // GPIO0_A29
PinInfo {
std::vector<std::string> {"GPIO0_A29", "UART0_RX"}, // system log output
std::vector<std::string> {"GPIOA29", "UART0_RX"}, // system log output
PinRegInfo {0x02304048, 16, 3},
std::vector<int> {6, 0}
}
},
{"IO0_A30",
{"A30", // GPIO0_A30
PinInfo {
std::vector<std::string> {"GPIO0_A30", "PWM6", "UART1_TX", "SPI2_CS3"},
std::vector<std::string> {"GPIOA30", "PWM6", "UART1_TX", "SPI2_CS3"},
PinRegInfo {0x02304054, 16, 3},
std::vector<int> {6, 3, 0, 1}
}
},
{"IO0_A31",
{"A31", // GPIO0_A31
PinInfo {
std::vector<std::string> {"GPIO0_A31", "PWM7", "UART1_RX"},
std::vector<std::string> {"GPIOA31", "PWM7", "UART1_RX"},
PinRegInfo {0x02304060, 16, 3},
std::vector<int> {6, 3, 0}
}
},
{"IO1_A0",
{"B0", // GPIO1_A0
PinInfo {
std::vector<std::string> {"GPIO1_A0", "UART2_TX"},
std::vector<std::string> {"GPIOB0", "UART2_TX"},
PinRegInfo {0x0230406C, 16, 3},
std::vector<int> {6, 0}
}
},
{"IO1_A1",
{"B1", // GPIO1_A1
PinInfo {
std::vector<std::string> {"GPIO1_A1", "UART2_RX"},
std::vector<std::string> {"GPIOB1", "UART2_RX"},
PinRegInfo {0x02304078, 16, 3},
std::vector<int> {6, 0}
}
},
{"IO1_A2",
{"B2", // GPIO1_A2
PinInfo {
std::vector<std::string> {"GPIO1_A2", "PWM4", "UART3_TX", "SPI2_MOSI"},
std::vector<std::string> {"GPIOB2", "PWM4", "UART3_TX", "SPI2_MOSI"},
PinRegInfo {0x02304084, 16, 3},
std::vector<int> {6, 3, 0, 1}
}
},
{"IO1_A3",
{"B3", // GPIO1_A3
PinInfo {
std::vector<std::string> {"GPIO1_A3", "PWM5", "UART3_RX", "SPI2_MISO"},
std::vector<std::string> {"GPIOB3", "PWM5", "UART3_RX", "SPI2_MISO"},
PinRegInfo {0x02304090, 16, 3},
std::vector<int> {6, 3, 3}
}
},
{"IO1_A18",
{"B18", // GPIO1_A18
PinInfo {
std::vector<std::string> {"GPIO1_A18", "SPI2_MOSI"},
std::vector<std::string> {"GPIOB18", "SPI2_MOSI"},
PinRegInfo {0x104F00CC, 16, 3},
std::vector<int> {6, 4}
}
},
{"IO1_A19",
{"B19", // GPIO1_A19
PinInfo {
std::vector<std::string> {"GPIO1_A19", "SPI2_MISO"},
std::vector<std::string> {"GPIOB19", "SPI2_MISO"},
PinRegInfo {0x104F00D8, 16, 3},
std::vector<int> {6, 4}
}
},
{"IO1_A20",
{"B20", // GPIO1_A20
PinInfo {
std::vector<std::string> {"GPIO1_A20", "SPI2_SCK"},
std::vector<std::string> {"GPIOB20", "SPI2_SCK"},
PinRegInfo {0x104F00E4, 16, 3},
std::vector<int> {6, 4}
}
},
{"IO1_A21",
{"B21", // GPIO1_A21
PinInfo {
std::vector<std::string> {"GPIO1_A21", "SPI2_CS1"},
std::vector<std::string> {"GPIOB21", "SPI2_CS1"},
PinRegInfo {0x104F00F0, 16, 3},
std::vector<int> {6, 4}
}
},
{"IO1_A22",
{"B22", // GPIO1_A22
PinInfo {
std::vector<std::string> {"GPIO1_A22", "PWM3"},
std::vector<std::string> {"GPIOB22", "PWM3"},
PinRegInfo {0x104F00FC, 16, 3},
std::vector<int> {6, 2}
}
},
{"IO1_A24",
{"B24", // GPIO1_A24
PinInfo {
std::vector<std::string> {"GPIO1_A24", "PWM5"},
std::vector<std::string> {"GPIOB24", "PWM5"},
PinRegInfo {0x104F003C, 16, 3},
std::vector<int> {6, 2}
}
},
{"IO1_A25",
{"B25", // GPIO1_A25
PinInfo {
std::vector<std::string> {"GPIO1_A25", "PWM6"}, // LED light
std::vector<std::string> {"GPIOB25", "PWM6"}, // LED light
PinRegInfo {0x104F0048, 16, 3},
std::vector<int> {6, 2}
}
},
{"IO3_A2",
{"C2", // GPIO3_A2
PinInfo {
std::vector<std::string> {"GPIO3_A2"}, // boot/user key
std::vector<std::string> {"GPIOC2"}, // boot/user key
PinRegInfo {0x02302024, 16, 3},
std::vector<int> {0}
}

View File

@@ -22,6 +22,7 @@
#include "maix_fs.hpp"
#include <memory>
#include "ax_middleware.hpp"
#include "maix_pinmap.hpp"
using namespace maix::peripheral;
using namespace maix::middleware;
@@ -170,7 +171,10 @@ namespace maix::display
__config_vo_param(&vo_param, width, height, format, rotate);
err::check_bool_raise(__vo->init(&vo_param) == err::ERR_NONE, "VO init failed");
_bl_pwm = nullptr;
int pwm_id = 5;
// int pwm_id = 5; // for MaixCAM2 alpha version board
// pinmap::set_pin_function("B24", "PWM5")
int pwm_id = 3;
pinmap::set_pin_function("B22", "PWM3");
_bl_pwm = new pwm::PWM(pwm_id, 10000, 50);
}