Skip to content

Commit

Permalink
Merge pull request #41 from 916BGAI/main
Browse files Browse the repository at this point in the history
Add axp2101 pmu support and reverse cst7xx touchscreen pos
  • Loading branch information
Z2Z-GuGu authored Aug 20, 2024
2 parents 82012f2 + e26614a commit cbdd1ce
Show file tree
Hide file tree
Showing 27 changed files with 11,030 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
display-coords = <0 0 480 640>;
hynitron,display-coords = <368 552>;
pos-swap = <0>;
posx-reverse = <0>;
posy-reverse = <0>;
posx-reverse = <1>;
posy-reverse = <1>;
status = "okay";
};
};
Expand Down
13 changes: 13 additions & 0 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S99pmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

if [ "$1" = "start" ]
then
. /etc/profile
panel_value=$(grep '^panel=' /boot/uEnv.txt | cut -d '=' -f 2)
if [ "$panel_value" = "MaixCam_Pro" ]
then
echo "init axp2101 pmu"
exec /usr/bin/axp2101
fi
exit 0
fi
2 changes: 2 additions & 0 deletions buildroot/configs/cvitek_SG200X_32bit_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ BR2_PACKAGE_PYTHON_INTELHEX=y
BR2_PACKAGE_VIM=y
BR2_PACKAGE_VIM_RUNTIME=y

BR2_PACKAGE_AXP2101=y

BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="900M"
Expand Down
2 changes: 2 additions & 0 deletions buildroot/configs/cvitek_SG200X_musl_riscv64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ BR2_PACKAGE_PYTHON_ZEROCONF=y
BR2_PACKAGE_VIM=y
BR2_PACKAGE_VIM_RUNTIME=y

BR2_PACKAGE_AXP2101=y

BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="900M"
Expand Down
1 change: 1 addition & 0 deletions buildroot/package/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,7 @@ menu "System tools"
source "package/atop/Config.in"
source "package/attr/Config.in"
source "package/audit/Config.in"
source "package/axp2101/Config.in"
source "package/balena-engine/Config.in"
source "package/bubblewrap/Config.in"
source "package/cgroupfs-mount/Config.in"
Expand Down
5 changes: 5 additions & 0 deletions buildroot/package/axp2101/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config BR2_PACKAGE_AXP2101
bool "axp2101"
help
If you say Y here you get support for the X-Powers AXP2101 power
management ICs (PMICs) controlled with I2C.
20 changes: 20 additions & 0 deletions buildroot/package/axp2101/axp2101.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
################################################################################
#
# axp2101
#
################################################################################

AXP2101_VERSION = 1.0.0
AXP2101_SITE = $(TOPDIR)/package/axp2101/src
AXP2101_SITE_METHOD = local
AXP2101_CFLAGS = -Iinclude -IXPowersLib -IXPowersLib/REG -Wall -Wextra

define AXP2101_BUILD_CMDS
$(MAKE) $(TARGET_CONFIGURE_OPTS) CFLAGS="$(AXP2101_CFLAGS)" -C $(@D)
endef

define AXP2101_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/axp2101 $(TARGET_DIR)/usr/bin/axp2101
endef

$(eval $(generic-package))
28 changes: 28 additions & 0 deletions buildroot/package/axp2101/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
APP_DIR = ./src
SRC_DIR = ./XPowersLib
DIR_BIN = ./bin

OBJ_C = $(wildcard ${SRC_DIR}/*.cpp ${APP_DIR}/*.cpp)
OBJ_O = $(patsubst %.cpp,${DIR_BIN}/%.o,$(notdir ${OBJ_C}))

TARGET = axp2101

DEBUG = -DXPOWERS_NO_ERROR

$(shell mkdir -p $(DIR_BIN))

MSG = -g -O0 -Wall
CFLAGS += $(MSG) $(DEBUG)

${TARGET}:${OBJ_O}
$(CXX) $(CFLAGS) $(OBJ_O) -o $@ $(LIB)

${DIR_BIN}/%.o:$(APP_DIR)/%.cpp
$(CXX) $(CFLAGS) -c $< -o $@ -I $(SRC_DIR)

${DIR_BIN}/%.o:$(SRC_DIR)/%.cpp
$(CXX) $(CFLAGS) -c $< -o $@ $(LIB)

clean :
rm $(DIR_BIN)/*.*
rm $(TARGET)
171 changes: 171 additions & 0 deletions buildroot/package/axp2101/src/XPowersLib/PowerDeliveryHUSB238.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file PowerDeliveryHUSB238.tpp
* @author Lewis He ([email protected])
* @date 2024-07-24
*
*/
#if defined(ARDUINO)
#include <Arduino.h>
#else
#include <math.h>
#endif /*ARDUINO*/
#include "XPowersCommon.tpp"
#include "REG/HUSB238Constants.h"

class PowerDeliveryHUSB238 :
public XPowersCommon<PowerDeliveryHUSB238>
{
friend class XPowersCommon<PowerDeliveryHUSB238>;

public:

enum PD_Status {
NO_RESPONSE,
SUCCESS,
INVALID_CMD,
NOT_SUPPORT,
TRANSACTION_FAIL
};

enum PD_Voltage {
PD_5V = 1,
PD_9V,
PD_12V,
PD_15V,
PD_18V,
PD_20V
};


#if defined(ARDUINO)
PowerDeliveryHUSB238(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = HUSB238_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif

PowerDeliveryHUSB238(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
thisReadRegCallback = readRegCallback;
thisWriteRegCallback = writeRegCallback;
__addr = addr;
}

PowerDeliveryHUSB238()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = SDA;
__scl = SCL;
#endif
__addr = HUSB238_SLAVE_ADDRESS;
}


~PowerDeliveryHUSB238()
{
log_i("~PowerDeliveryHUSB238");
deinit();
}

#if defined(ARDUINO)
bool init(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = HUSB238_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
return begin();
}
#endif

void deinit()
{
end();
}

uint8_t getPdVoltage()
{
int val = readRegister(HUSB238_PD_STATUS0);
if (val == -1)return 0;
val &= 0xF0;
val >>= 4;
return pd_voltage_list[val];
}

float getPdCurrent()
{
int val = readRegister(HUSB238_PD_STATUS0);
if (val == -1)return 0;
val &= 0x0F;
return pd_current_list[val];
}

void setPdVoltage(PD_Voltage vol)
{
writeRegister(HUSB238_SRC_PDO, vol);
writeRegister(HUSB238_GO_COMMAND, 0x01);
}

void resetPdVoltage()
{
writeRegister(HUSB238_GO_COMMAND, 0x10);
}

bool attach()
{
return getRegisterBit(HUSB238_PD_STATUS1, 6);
}

PD_Status status()
{
int val = readRegister(HUSB238_PD_STATUS1);
if (val == -1)return NO_RESPONSE;
val >>= 3;
val &= 0x03;
return static_cast<PD_Status>(val);
}


private:
const uint8_t pd_voltage_list[7] = {0, 5, 9, 12, 15, 18, 20};
const float pd_current_list[16] = {
0.5, 0.7, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5,
2.75, 3, 3.25, 3.5, 4, 4.5, 5
};

bool initImpl()
{
return readRegister(HUSB238_PD_STATUS0) != -1;
}

};



Loading

0 comments on commit cbdd1ce

Please sign in to comment.