DSM2 bind improvement?

This commit is contained in:
pascallanger 2016-08-22 18:17:14 +02:00
parent b2579538fa
commit 195f918543
8 changed files with 31 additions and 44 deletions

View File

@ -103,7 +103,7 @@ uint8_t A7105_Reset()
uint8_t result;
A7105_WriteReg(0x00, 0x00);
delayMicroseconds(1000);
delayMilliseconds(1);
A7105_SetTxRxMode(TXRX_OFF); //Set both GPIO as output and low
result=A7105_ReadReg(0x10) == 0x9E; //check if is reset.
A7105_Strobe(A7105_STANDBY);

View File

@ -90,7 +90,7 @@ uint16_t ASSAN_callback()
for(uint8_t i=0;i<4;i++)
packet[16+i]=packet[23-i];
packet_count=0;
delay(260);
delayMilliseconds(260);
return 10000; // Wait 270ms in total...
}
}
@ -104,7 +104,7 @@ uint16_t ASSAN_callback()
if(packet_count==20)
{
phase++;
delay(2165);
delayMilliseconds(2165);
}
return 22520;
// Normal operation
@ -134,7 +134,7 @@ uint16_t ASSAN_callback()
static void __attribute__((unused)) ASSAN_initialize_txid()
{
/* //Renaud TXID with Freq=36 and alternate freq 67 or 68 or 69 or 70 or 71 or 73 or 74 or 75 or 78 and may be more...
/* //Renaud TXID with Freq=36 and alternate Freq 67 or 68 or 69 or 70 or 71 or 73 or 74 or 75 or 78 and may be more...
packet[23]=0x22;
packet[22]=0x37;
packet[21]=0xFA;

View File

@ -117,7 +117,7 @@ void CC2500_SetTxRxMode(uint8_t mode)
uint8_t CC2500_Reset()
{
CC2500_Strobe(CC2500_SRES);
delay(1);
delayMilliseconds(1);
CC2500_SetTxRxMode(TXRX_OFF);
return CC2500_ReadReg(CC2500_0E_FREQ1) == 0xC4;//check if reset
}

View File

@ -58,13 +58,15 @@ uint8_t CYRF_ReadRegister(uint8_t address)
uint8_t CYRF_Reset()
{
#ifdef CYRF_RST_HI
CYRF_RST_HI; //Hardware reset
delayMicroseconds(100);
CYRF_RST_LO;
delayMicroseconds(100);
/* CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x01); //Software reset
#endif
CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x01); //Software reset
delayMicroseconds(200);
*/ CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); //Enable XOUT as GPIO
CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); //Enable XOUT as GPIO
CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); //Enable PACTL as GPIO
CYRF_SetTxRxMode(TXRX_OFF);
//Verify the CYRF chip is responding
@ -231,7 +233,7 @@ void CYRF_FindBestChannels(uint8_t *channels, uint8_t len, uint8_t minspace, uin
CYRF_ConfigCRCSeed(0x0000);
CYRF_SetTxRxMode(RX_EN);
//Wait for pre-amp to switch from send to receive
delayMicroseconds(1000);
delayMilliseconds(1);
for(i = 0; i < NUM_FREQ; i++)
{
CYRF_ConfigRFChannel(i);

View File

@ -213,10 +213,8 @@ static void __attribute__((unused)) build_data_packet(uint8_t upper)//
for (i = 0; i < 7; i++)
{
uint8_t idx = ch_map[upper * 7 + i];//1,5,2,3,0,4
uint16_t value;
if (idx == 0xff)
value = 0xffff;
else
uint16_t value = 0xffff;;
if (idx != 0xff)
{
if (binding)
{ // Failsafe position during binding

View File

@ -385,9 +385,9 @@ Model_fixed_id=0;
eeprom_write_block((const void*)0,(void*)40,4);
while(1){
LED_ON;
delay(100);
delayMilliseconds(100);
LED_OFF;
delay(100);
delayMilliseconds(100);
}
}
else{

View File

@ -200,7 +200,7 @@ unsigned long micros()
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
}
void delay(unsigned long ms)
void delayMilliseconds(unsigned long ms)
{
uint16_t start = (uint16_t)micros();
@ -419,7 +419,7 @@ int analogRead(uint8_t pin)
#endif
// without a delay, we seem to read from the wrong channel
//delay(1);
//delayMilliseconds(1);
#if defined(ADCSRA) && defined(ADCL)
// start the conversion

View File

@ -199,7 +199,7 @@ void setup()
memcpy((void *)PPM_data,Servo_data, sizeof(Servo_data));
//Wait for every component to start
delay(100);
delayMilliseconds(100);
// Read status of bind button
#ifdef XMEGA
@ -595,8 +595,9 @@ static void protocol_init()
if(next_callback>32000)
{ // next_callback should not be more than 32767 so we will wait here...
delayMicroseconds(next_callback-2000);
next_callback=2000;
uint16_t temp=next_callback>>10-2;
delayMilliseconds(temp);
next_callback-=temp<<10; // between 2-3ms left at this stage
}
cli(); // disable global int
#ifdef XMEGA
@ -765,7 +766,6 @@ static void Mprotocol_serial_init()
USARTC0.CTRLC = 0x2B ;
USARTC0.DATA ;
#else
#include <util/setbaud.h>
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
@ -844,8 +844,10 @@ void SPI_Write(uint8_t command)
else
SDI_off;
SCK_on;
NOP();
command = command << 1;
SCK_off;
NOP();
}
while(--n) ;
SDI_on;
@ -853,8 +855,7 @@ void SPI_Write(uint8_t command)
uint8_t SPI_Read(void)
{
uint8_t result;
uint8_t i;
uint8_t result=0,i;
for(i=0;i<8;i++)
{
result=result<<1;
@ -863,6 +864,7 @@ uint8_t SPI_Read(void)
SCK_on;
NOP();
SCK_off;
NOP();
}
return result;
}
@ -939,7 +941,7 @@ uint32_t millis()
return TotalMillis ;
}
void delay(unsigned long ms)
void delayMilliseconds(unsigned long ms)
{
uint16_t start = (uint16_t)micros();
uint16_t lms = ms ;
@ -952,29 +954,15 @@ void delay(unsigned long ms)
}
}
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
/* Important notes:
- Max value is 16000µs
- delay is not accurate due to interrupts happening */
void delayMicroseconds(unsigned int us)
{
// calling avrlib's delay_us() function with low values (e.g. 1 or
// 2 microseconds) gives delays longer than desired.
//delay_us(us);
// for the 16 MHz clock on most Arduino boards
// for a one-microsecond delay, simply return. the overhead
// of the function call yields a delay of approximately 1 1/8 us.
if (--us == 0)
return;
// the following loop takes a quarter of a microsecond (4 cycles)
// per iteration, so execute it four times for each microsecond of
// delay requested.
us <<= 2;
// account for the time taken in the preceeding commands.
us -= 2;
// busy wait
us <<= 2; // * 4
us -= 2; // - 2
__asm__ __volatile__ (
"1: sbiw %0,1" "\n\t" // 2 cycles
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
@ -983,8 +971,7 @@ void delayMicroseconds(unsigned int us)
void init()
{
// this needs to be called before setup() or some functions won't
// work there
// this needs to be called before setup() or some functions won't work there
sei();
}