Skip to content

Commit

Permalink
Sync with local development
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Feb 4, 2024
1 parent b743eb0 commit 504ef59
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1706794576;
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1707062705;
2 changes: 1 addition & 1 deletion gd32_emac_artnet_pixel_multi/include/sofware_version_id.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1706794600;
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1707062731;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-959482629664744322" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-959411350189512322" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
2 changes: 1 addition & 1 deletion gd32_emac_ddp_pixel_dmx_multi/include/sofware_version_id.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1706794608;
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1707062740;
2 changes: 1 addition & 1 deletion gd32_emac_ddp_pixel_multi/.settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-959482629664744322" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-959411350189512322" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
2 changes: 1 addition & 1 deletion gd32_emac_ddp_pixel_multi/include/sofware_version_id.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1706794616;
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1707062748;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1706794629;
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1707062762;
2 changes: 1 addition & 1 deletion gd32_emac_e131_pixel_multi/include/sofware_version_id.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1706794637;
constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1707062771;
5 changes: 4 additions & 1 deletion lib-gd32/include/gd32.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ extern "C" {
#elif defined (GD32F407) || defined (GD32F450) || defined (GD32F470)
# define GD32F4XX
# include "gd32f4xx.h"
#elif defined (GD32H759)
# define GD32H7XX
# include "gd32h7xx.h"
#else
# error MCU is not supported
#endif
Expand Down Expand Up @@ -89,7 +92,7 @@ uint16_t bkp_data_read(bkp_data_register_enum register_number);
#endif

#if defined (GD32H7XX)
# define GPIO_OSPEED GPIO_OSPEED_100_220MHZ
# define GPIO_OSPEED GPIO_OSPEED_60MHZ
#else
# define GPIO_OSPEED GPIO_OSPEED_50MHZ
#endif
Expand Down
2 changes: 2 additions & 0 deletions lib-gd32/include/gd32_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
# include "board/gd32f207c_eval.h"
#elif defined (BOARD_GD32F470Z_EVAL)
# include "board/gd32f470z_eval.h"
#elif defined (BOARD_GD32H759I_EVAL)
# include "board/gd32h759i_eval.h"
#elif defined (BOARD_BW_OPIDMX4)
# include "board/bw_opidmx4.h"
#elif defined (BOARD_DMX3)
Expand Down
2 changes: 1 addition & 1 deletion lib-gd32/include/gd32_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ inline void gpio_fsel(const uint32_t gpio_periph, const uint32_t pin, const uint
#elif defined (GD32F4XX) || defined (GD32H7XX)
if (fsel == GPIO_FSEL_OUTPUT) {
gpio_mode_set(gpio_periph, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, pin);
gpio_output_options_set(gpio_periph, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
gpio_output_options_set(gpio_periph, GPIO_OTYPE_PP, GPIO_OSPEED, pin);
} else {
gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, pin);
}
Expand Down
9 changes: 4 additions & 5 deletions lib-gd32/src/gd32_adc.cpp → lib-gd32/src/f/gd32_adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "gd32.h"

void gd32_adc_init(void) {
void gd32_adc_init() {
rcu_periph_clock_enable(RCU_ADC0);
#if !defined (GD32F4XX)
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV12);
Expand Down Expand Up @@ -86,21 +86,20 @@ void gd32_adc_init(void) {
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
}

float gd32_adc_gettemp(void) {
/* value convert */
float gd32_adc_gettemp() {
const float temperature = (1.43f - ADC_IDATA0(ADC0) * 3.3f / 4096) * 1000 / 4.3f + 25;
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
return temperature;
}

float gd32_adc_getvref(void) {
float gd32_adc_getvref() {
const float vref_value = (ADC_IDATA1(ADC0) * 3.3f / 4096);
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
return vref_value;
}

#if defined (GD32F4XX)
float gd32_adc_getvbat(void) {
float gd32_adc_getvbat() {
const float vref_value = (ADC_IDATA2(ADC0) * 3.3f / 4096) * 4;
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
return vref_value;
Expand Down
File renamed without changes.
73 changes: 24 additions & 49 deletions lib-gd32/src/gd32_i2c.cpp → lib-gd32/src/f/gd32_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file gd32_i2c.cpp
*
*/
/* Copyright (C) 2021-2022 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2021-2024 by Arjan van Vught mailto:[email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -32,21 +32,18 @@ static constexpr int32_t TIMEOUT = 0xfff;

static uint8_t s_nAddress;

static int32_t _sendstart(void) {
static int32_t send_start() {
auto nTimeout = TIMEOUT;

/* wait until I2C bus is idle */
while (i2c_flag_get(I2C_PERIPH, I2C_FLAG_I2CBSY)) {
if (--nTimeout <= 0) {
return -GD32_I2C_NOK_TOUT;
}
}

nTimeout = TIMEOUT;

/* send a start condition to I2C bus */
i2c_start_on_bus(I2C_PERIPH);

nTimeout = TIMEOUT;
/* wait until SBSEND bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_SBSEND)) {
if (--nTimeout <= 0) {
Expand All @@ -57,12 +54,10 @@ static int32_t _sendstart(void) {
return GD32_I2C_OK;
}

static int32_t _sendslaveaddr(void) {
auto nTimeout = TIMEOUT;

/* send slave address to I2C bus */
static int32_t send_slaveaddr() {
i2c_master_addressing(I2C_PERIPH, s_nAddress, I2C_TRANSMITTER);

auto nTimeout = TIMEOUT;
/* wait until ADDSEND bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_ADDSEND)) {
if (--nTimeout <= 0) {
Expand All @@ -74,7 +69,6 @@ static int32_t _sendslaveaddr(void) {
i2c_flag_clear(I2C_PERIPH, I2C_FLAG_ADDSEND);

nTimeout = TIMEOUT;

/* wait until the transmit data buffer is empty */
while (SET != i2c_flag_get(I2C_PERIPH, I2C_FLAG_TBE)) {
if (--nTimeout <= 0) {
Expand All @@ -85,10 +79,9 @@ static int32_t _sendslaveaddr(void) {
return GD32_I2C_OK;
}

static int32_t _stop(void) {
static int32_t send_stop() {
auto nTimeout = TIMEOUT;

/* send a stop condition to I2C bus */
i2c_stop_on_bus(I2C_PERIPH);

/* wait until the stop condition is finished */
Expand All @@ -101,17 +94,11 @@ static int32_t _stop(void) {
return GD32_I2C_OK;
}

static int32_t _senddata(uint8_t *pData, uint32_t nCount) {
int32_t nTimeout;

static int32_t send_data(const uint8_t *pData, const uint32_t nCount) {
for (uint32_t i = 0; i < nCount; i++) {
i2c_data_transmit(I2C_PERIPH, *pData);

/* point to the next byte to be written */
pData++;

nTimeout = TIMEOUT;

int32_t nTimeout = TIMEOUT;
/* wait until BTC bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_BTC)) {
if (--nTimeout <= 0) {
Expand All @@ -123,23 +110,23 @@ static int32_t _senddata(uint8_t *pData, uint32_t nCount) {
return GD32_I2C_OK;
}

static int _write(char *pBuffer, int nLength) {
if (_sendstart() != GD32_I2C_OK) {
_stop();
static int32_t write(const char *pBuffer, const int nLength) {
if (send_start() != GD32_I2C_OK) {
send_stop();
return -1;
}

if (_sendslaveaddr() != GD32_I2C_OK) {
_stop();
if (send_slaveaddr() != GD32_I2C_OK) {
send_stop();
return -1;
}

if (_senddata((uint8_t*) pBuffer, (uint32_t) nLength) != GD32_I2C_OK) {
_stop();
if (send_data((uint8_t*) pBuffer, (uint32_t) nLength) != GD32_I2C_OK) {
send_stop();
return -1;
}

_stop();
send_stop();

return 0;
}
Expand All @@ -148,7 +135,7 @@ static int _write(char *pBuffer, int nLength) {
* Public API's
*/

void gd32_i2c_begin(void) {
void gd32_i2c_begin() {
rcu_periph_clock_enable(I2C_RCU_CLK);
rcu_periph_clock_enable(I2C_GPIO_SCL_CLK);
rcu_periph_clock_enable(I2C_GPIO_SDA_CLK);
Expand Down Expand Up @@ -186,18 +173,16 @@ void gd32_i2c_set_address(uint8_t nAddress) {
}

uint8_t gd32_i2c_write(const char *pBuffer, uint32_t nLength) {
const auto ret = _write((char *)pBuffer, (int) nLength);

const auto ret = write((char *)pBuffer, (int) nLength);
return (uint8_t)-ret;
}

uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
auto nTimeout = TIMEOUT;

/* wait until I2C bus is idle */
while (i2c_flag_get(I2C_PERIPH, I2C_FLAG_I2CBSY)) {
if (--nTimeout <= 0) {
_stop();
send_stop();
return GD32_I2C_NOK_TOUT;
}
}
Expand All @@ -210,16 +195,14 @@ uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
i2c_start_on_bus(I2C_PERIPH);

nTimeout = TIMEOUT;

/* wait until SBSEND bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_SBSEND)) {
if (--nTimeout <= 0) {
_stop();
send_stop();
return GD32_I2C_NOK_TOUT;
}
}

/* send slave address to I2C bus */
i2c_master_addressing(I2C_PERIPH, s_nAddress, I2C_RECEIVER);

if (nLength < 3) {
Expand All @@ -228,11 +211,10 @@ uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
}

nTimeout = TIMEOUT;

/* wait until ADDSEND bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_ADDSEND)) {
if (--nTimeout <= 0) {
_stop();
send_stop();
return GD32_I2C_NOK_TOUT;
}
}
Expand All @@ -246,35 +228,31 @@ uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
}

auto nTimeoutLoop = TIMEOUT;

/* while there is data to be read */
while (nLength) {
if (3 == nLength) {
nTimeout = TIMEOUT;
/* wait until BTC bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_BTC)) {
if (--nTimeout <= 0) {
_stop();
send_stop();
return GD32_I2C_NOK_TOUT;
}
}

/* disable acknowledge */
i2c_ack_config(I2C_PERIPH, I2C_ACK_DISABLE);
}

if (2 == nLength) {
nTimeout = TIMEOUT;

/* wait until BTC bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_BTC)) {
if (--nTimeout <= 0) {
_stop();
send_stop();
return GD32_I2C_NOK_TOUT;
}
}

/* send a stop condition to I2C bus */
i2c_stop_on_bus(I2C_PERIPH);
}

Expand All @@ -287,23 +265,20 @@ uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
}

if (--nTimeoutLoop <= 0) {
_stop();
send_stop();
return GD32_I2C_NOK_TOUT;
}
}

nTimeout = TIMEOUT;

/* wait until the stop condition is finished */
while (I2C_CTL0(I2C_PERIPH) & 0x0200) {
if (--nTimeout <= 0) {
return GD32_I2C_NOK_TOUT;
}
}

/* enable acknowledge */
i2c_ack_config(I2C_PERIPH, I2C_ACK_ENABLE);

i2c_ackpos_config(I2C_PERIPH, I2C_ACKPOS_CURRENT);

return GD32_I2C_OK;
Expand Down
Loading

0 comments on commit 504ef59

Please sign in to comment.