Skip to content

Commit

Permalink
fix gpio, add i2c
Browse files Browse the repository at this point in the history
  • Loading branch information
NonPIayerCharacter committed Dec 9, 2024
1 parent 8876e23 commit 72e5b95
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ sdk/OpenLN882H/project/OpenBeken/app:
@mkdir -p "sdk/OpenLN882H/project/OpenBeken"
ln -s "$(shell pwd)/" "sdk/OpenLN882H/project/OpenBeken/app"

.PHONY: prebuild_OpenBK7231N prebuild_OpenBK7231T prebuild_OpenBL602 prebuild_OpenLN882H prebuild_OpenW600 prebuild_OpenW800 prebuild_OpenXR809 prebuild_ESPIDF
.PHONY: prebuild_OpenBK7231N prebuild_OpenBK7231T prebuild_OpenBL602 prebuild_OpenLN882H
.PHONY: prebuild_OpenW600 prebuild_OpenW800 prebuild_OpenXR809 prebuild_ESPIDF prebuild_OpenTR6260

prebuild_OpenBK7231N:
@if [ -e platforms/BK7231N/pre_build.sh ]; then \
Expand Down Expand Up @@ -132,6 +133,13 @@ prebuild_ESPIDF:
else echo "prebuild for ESP-IDF not found ... "; \
fi

prebuild_OpenTR6260:
@if [ -e platforms/TR6260/pre_build.sh ]; then \
echo "prebuild found for TR6260"; \
sh platforms/TR6260/pre_build.sh; \
else echo "prebuild for TR6260 not found ... "; \
fi

# Build main binaries
OpenBK7231T: prebuild_OpenBK7231T
$(MAKE) APP_NAME=OpenBK7231T TARGET_PLATFORM=bk7231t SDK_PATH=sdk/OpenBK7231T APPS_BUILD_PATH=../bk7231t_os build-BK7231
Expand Down Expand Up @@ -260,7 +268,7 @@ OpenESP32S3: prebuild_ESPIDF
cp ./platforms/ESP-IDF/build-s3/OpenBeken.bin output/$(APP_VERSION)/OpenESP32S3_$(APP_VERSION).img

.PHONY: OpenTR6260
OpenTR6260:
OpenTR6260: prebuild_OpenTR6260
if [ ! -e sdk/OpenTR6260/toolchain/nds32le-elf-mculib-v3 ]; then cd sdk/OpenTR6260/toolchain && xz -d < nds32le-elf-mculib-v3.txz | tar xvf - > /dev/null; fi
cd sdk/OpenTR6260/scripts && APP_VERSION=$(APP_VERSION) bash build_tr6260s1.sh
mkdir -p output/$(APP_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion sdk/OpenTR6260
101 changes: 100 additions & 1 deletion src/hal/tr6260/hal_pins_tr6260.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../new_pins.h"
#include "drv_gpio.h"
#include "drv_pwm.h"
#include "soc_pin_mux.h"

extern int g_pwmFrequency;

Expand Down Expand Up @@ -66,6 +67,94 @@ int PIN_GetPWMIndexForPinIndex(int pin)
}
}

void HAL_PIN_Set_As_GPIO(DRV_GPIO_PIN_NAME pin)
{
switch(pin)
{
case DRV_GPIO_0:
PIN_FUNC_SET(IO_MUX0_GPIO0, FUNC_GPIO0_GPIO0);
break;
case DRV_GPIO_1:
PIN_FUNC_SET(IO_MUX0_GPIO1, FUNC_GPIO1_GPIO1);
break;
case DRV_GPIO_2:
PIN_FUNC_SET(IO_MUX0_GPIO2, FUNC_GPIO2_GPIO2);
break;
case DRV_GPIO_3:
PIN_FUNC_SET(IO_MUX0_GPIO3, FUNC_GPIO3_GPIO3);
break;
case DRV_GPIO_4:
PIN_FUNC_SET(IO_MUX0_GPIO4, FUNC_GPIO4_GPIO4);
break;
case DRV_GPIO_5:
PIN_FUNC_SET(IO_MUX0_GPIO5, FUNC_GPIO5_GPIO5);
break;
case DRV_GPIO_6:
PIN_FUNC_SET(IO_MUX0_GPIO6, FUNC_GPIO6_GPIO6);
break;
case DRV_GPIO_7:
#ifndef _USR_TR6260S1
PIN_FUNC_SET(IO_MUX0_GPIO7, FUNC_GPIO7_GPIO7);
break;
case DRV_GPIO_8:
PIN_FUNC_SET(IO_MUX0_GPIO8, FUNC_GPIO8_GPIO8);
break;
case DRV_GPIO_9:
PIN_FUNC_SET(IO_MUX0_GPIO9, FUNC_GPIO9_GPIO9);
break;
case DRV_GPIO_10:
PIN_FUNC_SET(IO_MUX0_GPIO10, FUNC_GPIO10_GPIO10);
break;
case DRV_GPIO_11:
PIN_FUNC_SET(IO_MUX0_GPIO11, FUNC_GPIO11_GPIO11);
break;
case DRV_GPIO_12:
PIN_FUNC_SET(IO_MUX0_GPIO12, FUNC_GPIO12_GPIO12);
#endif
break;
case DRV_GPIO_13: /*don't use in gpio mode*/
//PIN_FUNC_SET(IO_MUX0_GPIO13, FUNC_GPIO13_GPIO13);
break;
case DRV_GPIO_14:
PIN_FUNC_SET(IO_MUX0_GPIO14, FUNC_GPIO14_GPIO14);
break;
case DRV_GPIO_15:
PIN_FUNC_SET(IO_MUX0_GPIO15, FUNC_GPIO15_GPIO15);
break;
case DRV_GPIO_16: /*don't use in gpio mode*/
break;
case DRV_GPIO_17: /*don't use in gpio mode*/
break;
#ifndef _USR_TR6260S1
case DRV_GPIO_18:
PIN_FUNC_SET(IO_MUX0_GPIO18, FUNC_GPIO18_GPIO18);
break;
case DRV_GPIO_19:
PIN_FUNC_SET(IO_MUX0_GPIO19, FUNC_GPIO19_GPIO19);
#endif
break;
case DRV_GPIO_20:
PIN_FUNC_SET(IO_MUX0_GPIO20, FUNC_GPIO20_GPIO20);
break;
case DRV_GPIO_21:
PIN_FUNC_SET(IO_MUX0_GPIO21, FUNC_GPIO21_GPIO21);
break;
case DRV_GPIO_22:
PIN_FUNC_SET(IO_MUX0_GPIO22, FUNC_GPIO22_GPIO22);
break;
case DRV_GPIO_23:
#ifndef _USR_TR6260S1
PIN_FUNC_SET(IO_MUX0_GPIO23, FUNC_GPIO23_GPIO23);
break;
case DRV_GPIO_24:
PIN_FUNC_SET(IO_MUX0_GPIO24, FUNC_GPIO24_GPIO24);
#endif
break;
default:
break;
}
}

const char* HAL_PIN_GetPinNameAlias(int index)
{
if(index >= g_numPins)
Expand Down Expand Up @@ -104,6 +193,7 @@ void HAL_PIN_Setup_Input_Pullup(int index)
if(index >= g_numPins)
return;
trPinMapping_t* pin = g_pins + index;
HAL_PIN_Set_As_GPIO(pin->pin);
DRV_GPIO_CONFIG gpioCfg;
gpioCfg.GPIO_Pin = pin->pin;
gpioCfg.GPIO_PullEn = DRV_GPIO_PULL_EN;
Expand All @@ -118,6 +208,7 @@ void HAL_PIN_Setup_Input_Pulldown(int index)
if(index >= g_numPins)
return;
trPinMapping_t* pin = g_pins + index;
HAL_PIN_Set_As_GPIO(pin->pin);
DRV_GPIO_CONFIG gpioCfg;
gpioCfg.GPIO_Pin = pin->pin;
gpioCfg.GPIO_PullEn = DRV_GPIO_PULL_EN;
Expand All @@ -132,6 +223,7 @@ void HAL_PIN_Setup_Input(int index)
if(index >= g_numPins)
return;
trPinMapping_t* pin = g_pins + index;
HAL_PIN_Set_As_GPIO(pin->pin);
DRV_GPIO_CONFIG gpioCfg;
gpioCfg.GPIO_Pin = pin->pin;
gpioCfg.GPIO_PullEn = DRV_GPIO_PULL_DIS;
Expand All @@ -145,7 +237,14 @@ void HAL_PIN_Setup_Output(int index)
if(index >= g_numPins)
return;
trPinMapping_t* pin = g_pins + index;
gpio_set_dir(pin->pin, DRV_GPIO_DIR_OUTPUT);
HAL_PIN_Set_As_GPIO(pin->pin);
DRV_GPIO_CONFIG gpioCfg;
gpioCfg.GPIO_Pin = pin->pin;
gpioCfg.GPIO_PullEn = DRV_GPIO_PULL_EN;
gpioCfg.GPIO_Dir = DRV_GPIO_DIR_OUTPUT;
gpioCfg.GPIO_PullType = DRV_GPIO_PULL_TYPE_UP;
gpio_config(&gpioCfg);
//gpio_set_dir(pin->pin, DRV_GPIO_DIR_OUTPUT);
}

void HAL_PIN_PWM_Stop(int index)
Expand Down
1 change: 1 addition & 0 deletions src/obk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
#define ENABLE_LITTLEFS 1
#define NEW_TCP_SERVER 1
#define ENABLE_EXPAND_CONSTANT 1
#define ENABLE_I2C 1
#define ENABLE_DRIVER_AHT2X 1
#define ENABLE_DRIVER_BMPI2C 1
#define ENABLE_DRIVER_DS1820 1
Expand Down

0 comments on commit 72e5b95

Please sign in to comment.