diff --git a/Makefile b/Makefile index acd7ab9..d4fb48a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/driver/bk1080.c b/driver/bk1080.c index ed86c44..57ee7fc 100644 --- a/driver/bk1080.c +++ b/driver/bk1080.c @@ -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]; } diff --git a/driver/eeprom.c b/driver/eeprom.c index cd8f993..f986d76 100644 --- a/driver/eeprom.c +++ b/driver/eeprom.c @@ -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(); diff --git a/driver/i2c.c b/driver/i2c.c index db959c3..373f61f 100644 --- a/driver/i2c.c +++ b/driver/i2c.c @@ -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; } diff --git a/driver/i2c.h b/driver/i2c.h index 8c5cf2b..a305eaa 100644 --- a/driver/i2c.h +++ b/driver/i2c.h @@ -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 diff --git a/driver/systick.c b/driver/systick.c index 5971d74..d72eee9 100644 --- a/driver/systick.c +++ b/driver/systick.c @@ -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); +} diff --git a/driver/systick.h b/driver/systick.h index 95ba478..9e2871f 100644 --- a/driver/systick.h +++ b/driver/systick.h @@ -20,7 +20,8 @@ #include 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 diff --git a/firmware.bin b/firmware.bin index c208b79..770933c 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 985f2d8..be13f1d 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/ui/main.c b/ui/main.c index a7de9e0..c35ccd0 100644 --- a/ui/main.c +++ b/ui/main.c @@ -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