0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 06:11:24 +03:00

fix compile warning

This commit is contained in:
OneOfEleven 2023-11-03 19:51:27 +00:00
parent e2e030aed4
commit fca972a2f2
10 changed files with 105 additions and 28 deletions

View File

@ -36,7 +36,7 @@ ENABLE_REDUCE_LOW_MID_TX_POWER := 1
ENABLE_ALARM := 0
ENABLE_TX1750 := 0
# MDC1200 2.8 kB
ENABLE_MDC1200 := 1
ENABLE_MDC1200 := 0
ENABLE_MDC1200_SHOW_OP_ARG := 1
ENABLE_PWRON_PASSWORD := 0
ENABLE_RESET_AES_KEY := 0

View File

@ -185,7 +185,7 @@ uint16_t BK1080_ReadRegister(BK1080_register_t Register)
I2C_Start();
I2C_Write(0x80);
I2C_Write((Register << 1) | I2C_READ);
I2C_ReadBuffer(Value, sizeof(Value));
I2C_ReadBuffer(Value, sizeof(Value), false);
I2C_Stop();
return (Value[0] << 8) | Value[1];
}

View File

@ -32,7 +32,8 @@ void EEPROM_ReadBuffer(const uint16_t address, void *p_buffer, const unsigned in
I2C_Start();
I2C_Write(0xA1);
I2C_ReadBuffer(p_buffer, size);
// I2C_ReadBuffer(p_buffer, size, false);
I2C_ReadBuffer(p_buffer, size, true); // faster read
I2C_Stop();
}
@ -59,7 +60,9 @@ void EEPROM_WriteBuffer8(const uint16_t address, const void *p_buffer)
// only write the data if it's different to what's already there
uint8_t buffer[8];
EEPROM_ReadBuffer(address, buffer, 8);
if (memcmp(p_buffer, buffer, 8) != 0)
{
I2C_Start();

View File

@ -44,6 +44,47 @@ void I2C_Stop(void)
SYSTICK_DelayUs(1);
}
uint8_t I2C_Read_fast(bool bFinal)
{
uint8_t i, Data;
PORTCON_PORTA_IE |= PORTCON_PORTA_IE_A11_BITS_ENABLE;
PORTCON_PORTA_OD &= ~PORTCON_PORTA_OD_A11_MASK;
GPIOA->DIR &= ~GPIO_DIR_11_MASK;
Data = 0;
for (i = 0; i < 8; i++)
{
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1);
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1);
Data <<= 1;
SYSTICK_Delay250ns(1);
if (GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA))
Data |= 1U;
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1);
}
PORTCON_PORTA_IE &= ~PORTCON_PORTA_IE_A11_MASK;
PORTCON_PORTA_OD |= PORTCON_PORTA_OD_A11_BITS_ENABLE;
GPIOA->DIR |= GPIO_DIR_11_BITS_OUTPUT;
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1);
if (bFinal)
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA);
else
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA);
SYSTICK_Delay250ns(1);
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1);
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1);
return Data;
}
uint8_t I2C_Read(bool bFinal)
{
uint8_t i, Data;
@ -53,16 +94,16 @@ uint8_t I2C_Read(bool bFinal)
GPIOA->DIR &= ~GPIO_DIR_11_MASK;
Data = 0;
for (i = 0; i < 8; i++) {
for (i = 0; i < 8; i++)
{
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_DelayUs(1);
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_DelayUs(1);
Data <<= 1;
SYSTICK_DelayUs(1);
if (GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA)) {
if (GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA))
Data |= 1U;
}
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_DelayUs(1);
}
@ -72,11 +113,10 @@ uint8_t I2C_Read(bool bFinal)
GPIOA->DIR |= GPIO_DIR_11_BITS_OUTPUT;
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_DelayUs(1);
if (bFinal) {
if (bFinal)
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA);
} else {
else
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA);
}
SYSTICK_DelayUs(1);
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_DelayUs(1);
@ -132,25 +172,29 @@ int I2C_Write(uint8_t Data)
return ret;
}
int I2C_ReadBuffer(void *pBuffer, const unsigned int Size)
int I2C_ReadBuffer(void *pBuffer, const unsigned int Size, const bool fast)
{
uint8_t *pData = (uint8_t *)pBuffer;
unsigned int i;
if (Size == 1)
{
*pData = I2C_Read(true);
*pData = fast ? I2C_Read_fast(true) : I2C_Read(true);
return 1;
}
for (i = 0; i < (Size - 1); i++)
if (fast)
{
// SYSTICK_DelayUs(1);
pData[i] = I2C_Read(false);
for (i = 0; i < (Size - 1); i++)
pData[i] = I2C_Read_fast(false);
pData[i++] = I2C_Read_fast(true);
}
else
{
for (i = 0; i < (Size - 1); i++)
pData[i] = I2C_Read(false);
pData[i++] = I2C_Read(true);
}
// SYSTICK_DelayUs(1);
pData[i++] = I2C_Read(true);
return Size;
}

View File

@ -29,9 +29,10 @@ void I2C_Start(void);
void I2C_Stop(void);
uint8_t I2C_Read(bool bFinal);
uint8_t I2C_Read_fast(bool bFinal);
int I2C_Write(uint8_t Data);
int I2C_ReadBuffer(void *pBuffer, unsigned int Size);
int I2C_ReadBuffer(void *pBuffer, unsigned int Size, const bool fast);
int I2C_WriteBuffer(const void *pBuffer, unsigned int Size);
#endif

View File

@ -27,19 +27,44 @@ void SYSTICK_Init(void)
gTickMultiplier = 48;
}
void SYSTICK_DelayUs(uint32_t Delay)
void SYSTICK_DelayUs(const uint32_t Delay)
{
const uint32_t ticks = Delay * gTickMultiplier;
uint32_t i = 0;
uint32_t Start = SysTick->LOAD;
uint32_t Previous = SysTick->VAL;
const uint32_t ticks = Delay * gTickMultiplier;
uint32_t i = 0;
uint32_t Start = SysTick->LOAD;
uint32_t Previous = SysTick->VAL;
do {
uint32_t Current;
uint32_t Delta;
while ((Current = SysTick->VAL) == Previous) {}
Delta = (Current < Previous) ? -Current : Start - Current;
i += Delta + Previous;
uint32_t Current;
do Current = SysTick->VAL;
while (Current == Previous);
Delta = (Current < Previous) ? -Current : Start - Current;
i += Delta + Previous;
Previous = Current;
} while (i < ticks);
}
void SYSTICK_Delay250ns(const uint32_t Delay)
{
const uint32_t ticks = (Delay * gTickMultiplier) >> 2;
uint32_t i = 0;
uint32_t Start = SysTick->LOAD;
uint32_t Previous = SysTick->VAL;
do {
uint32_t Delta;
uint32_t Current;
do Current = SysTick->VAL;
while (Current == Previous);
Delta = (Current < Previous) ? -Current : Start - Current;
i += Delta + Previous;
Previous = Current;
} while (i < ticks);
}

View File

@ -20,7 +20,8 @@
#include <stdint.h>
void SYSTICK_Init(void);
void SYSTICK_DelayUs(uint32_t Delay);
void SYSTICK_DelayUs(const uint32_t Delay);
void SYSTICK_Delay250ns(const uint32_t Delay);
#endif

Binary file not shown.

Binary file not shown.

View File

@ -244,6 +244,9 @@ void UI_update_rssi(const int16_t rssi, const int16_t glitch, const int16_t nois
if (g_current_function == FUNCTION_RECEIVE)
UI_DisplayRSSIBar(rssi, glitch, noise, true);
}
#else
(void)glitch;
(void)noise;
#endif
{ // original little RS bars