Skip to content

Commit

Permalink
Release of version 0.53
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel committed Nov 17, 2014
1 parent 3dad254 commit b197536
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 58 deletions.
6 changes: 3 additions & 3 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ ifneq ($(PPM_JOYSTICK), 0)
endif
endif

ifdef CFPA
CFLAGS += -DCFPA
ifdef CRPA
CFLAGS += -DCRPA
endif

.PHONY: all cri

all: bin/ cradio.bin
ifdef CFPA
ifdef CRPA
@echo Crazyradio PA build
else
@echo Original Crazyradio build
Expand Down
86 changes: 43 additions & 43 deletions firmware/src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
Expand Down Expand Up @@ -62,21 +62,21 @@ static char scannLength;
static bool contCarrier=false;
static bool needAck = true;

void main()
void main()
{
char status;
char leds=0;
char tlen; //Transmit length
char rlen; //Received packet length
uint8_t ack;
bool with_pa;
#ifndef CFPA

#ifndef CRPA
with_pa = false;
#else
with_pa = true;
#endif

//Init the chip ID
initId();
//Init the led and set the leds until the usb is not ready
Expand All @@ -86,7 +86,7 @@ void main()
ledInit(CRPA_LED_RED, CRPA_LED_GREEN);
}
ledSet(LED_GREEN | LED_RED, true);

// Initialise the radio
if (with_pa) {
// Enable LNA (PA RX)
Expand All @@ -100,7 +100,7 @@ void main()
#endif //PPM_JOYSTICK
// Initialise and connect the USB
usbInit();

//Globally activate the interruptions
IEN0 |= 0x80;

Expand All @@ -112,23 +112,23 @@ void main()

//Wait for the USB to be ready
while (usbGetState() != CONFIGURED);

//Activate OUT1
OUT1BC=0xFF;

while(1)
{
//Send a packet if something is received on the USB
if (!(OUT1CS&EPBSY) && !contCarrier)
{

//Deactivate the USB IN
IN1CS = 0x02;

//Fetch the USB data size. Limit it to 32
tlen = OUT1BC;
if (tlen>32) tlen=32;

//Send the packet
memcpy(tbuffer, OUT1BUF, tlen);
if (needAck)
Expand Down Expand Up @@ -164,16 +164,16 @@ void main()
else
{
radioSendPacketNoAck(tbuffer, tlen);

ledTimeout = 2;
ledSet(LED_GREEN | LED_RED, false);
ledSet(LED_GREEN, true);

//reactivate OUT1
OUT1BC=BCDUMMY;
}
}

//USB vendor setup handling
if(usbIsVendorSetup())
handleUsbVendorSetup();
Expand All @@ -184,7 +184,7 @@ void main()
void handleUsbVendorSetup()
{
__xdata struct controllStruct *setup = usbGetSetupPacket();

//The vendor control messages are valide only when the device is configured
if (usbGetState() >= CONFIGURED)
{
Expand All @@ -195,7 +195,7 @@ void handleUsbVendorSetup()

launchBootloader();
//Will never come back ...

return;
}
else if(setup->request == SET_RADIO_CHANNEL)
Expand All @@ -208,7 +208,7 @@ void handleUsbVendorSetup()
else if(setup->request == SET_DATA_RATE)
{
radioSetDataRate(setup->value);

usbAckSetup();
return;
}
Expand All @@ -219,54 +219,54 @@ void handleUsbVendorSetup()
usbDismissSetup();
return;
}

//Arm and wait for the out transaction
OUT0BC = BCDUMMY;
while (EP0CS & OUTBSY);

//Set address of the pipe given by setup's index
radioSetAddress(OUT0BUF);

//Ack the setup phase
usbAckSetup();
return;
}
else if(setup->request == SET_RADIO_POWER)
{
radioSetPower(setup->value);

usbAckSetup();
return;
}
else if(setup->request == SET_RADIO_ARD)
{
radioSetArd(setup->value);

usbAckSetup();
return;
}
else if(setup->request == SET_RADIO_ARC)
{
radioSetArc(setup->value);

usbAckSetup();
return;
}
else if(setup->request == SET_CONT_CARRIER)
{
radioSetContCarrier((setup->value)?true:false);
contCarrier = (setup->value)?true:false;

ledTimeout = -1;
ledSet(LED_RED, (setup->value)?true:false);

usbAckSetup();
return;
}
else if(setup->request == ACK_ENABLE)
{
needAck = (setup->value)?true:false;

usbAckSetup();
return;
}
Expand All @@ -278,41 +278,41 @@ void handleUsbVendorSetup()
char inc = 1;
unsigned char start, stop;
scannLength = 0;

if(setup->length < 1)
{
usbDismissSetup();
return;
}

//Start and stop channels
start = setup->value;
stop = (setup->index>125)?125:setup->index;

if (radioGetDataRate() == DATA_RATE_2M)
inc = 2; //2M channel are 2MHz wide

//Arm and wait for the out transaction
OUT0BC = BCDUMMY;
while (EP0CS & OUTBSY);

memcpy(tbuffer, OUT0BUF, setup->length);
for (i=start; i<stop+1 && scannLength<MAX_SCANN_LENGTH; i+=inc)
{
radioSetChannel(i);
status = radioSendPacket(tbuffer, setup->length, rbuffer, &rlen);

if (status)
IN0BUF[scannLength++] = i;

ledTimeout = 2;
ledSet(LED_GREEN | LED_RED, false);
if(status)
ledSet(LED_GREEN, true);
else
ledSet(LED_RED, true);
}

//Ack the setup phase
usbAckSetup();
return;
Expand All @@ -323,32 +323,32 @@ void handleUsbVendorSetup()
//(if a scann has been launched before ...)
IN0BC = (setup->length>scannLength)?scannLength:setup->length;
while (EP0CS & INBSY);

//Ack the setup phase
usbAckSetup();
return;
}
}

//Stall in error if nothing executed!
usbDismissSetup();
}

// De-init all the peripherical,
// and launch the Nordic USB bootloader located @ 0x7800
void launchBootloader()
{
{
void (*bootloader)() = (void (*)())0x7800;

//Deactivate the interruptions
IEN0 = 0x00;

//Deinitialise the USB
usbDeinit();

//Deinitialise the radio
radioDeinit();

//Call the bootloader
bootloader();
}
24 changes: 12 additions & 12 deletions firmware/src/usbDescriptor.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
Expand Down Expand Up @@ -37,7 +37,7 @@ __code const char usbDeviceDescriptor[] = {
64, //bMaxPacketSize0
0x15, 0x19, //idVendor (Nordic)
0x77, 0x77, //idProduct (Randomly chosen for the development)
0x52, 0x99, //bcdDevice (DEV Version v99.52)
0x53, 0x00, //bcdDevice (Release version v0.53)
0x01, //iManufacturer (String 1)
0x02, //iProduct (String 2)
0x1D, //iSerialNumber (the ID is at index 0x1D)
Expand Down Expand Up @@ -138,35 +138,35 @@ __code const char usbHidReportDescriptor[32] = {
//String descriptor for the language
__code char usbStringDescriptor0[4] = {
4, //bLength
STRING_DESCRIPTOR, //bDescriptor type
STRING_DESCRIPTOR, //bDescriptor type
0X09, 0X04 //English (United States)
};

//Manufacturer name "Bitcraze"
__code char usbStringDescriptor1[18] = {
18, //bLength
STRING_DESCRIPTOR, //bDescriptor type
STRING_DESCRIPTOR, //bDescriptor type
//bString ...
'B', 0, 'i', 0, 't', 0, 'c', 0, 'r', 0, 'a', 0, 'z', 0, 'e', 0,
'B', 0, 'i', 0, 't', 0, 'c', 0, 'r', 0, 'a', 0, 'z', 0, 'e', 0,
};

#ifndef CFPA
#ifndef CRPA
//Product name "Crazyradio USB Dongle"
__code char usbStringDescriptor2[44] = {
44, //bLength
STRING_DESCRIPTOR, //bDescriptor type
STRING_DESCRIPTOR, //bDescriptor type
//bString ...
'C',0, 'r',0, 'a',0, 'z',0, 'y',0, 'r',0, 'a',0, 'd',0, 'i',0, 'o',0, ' ',0,
'C',0, 'r',0, 'a',0, 'z',0, 'y',0, 'r',0, 'a',0, 'd',0, 'i',0, 'o',0, ' ',0,
'U',0, 'S',0, 'B',0, ' ',0, 'D',0, 'o',0, 'n',0, 'g',0, 'l',0, 'e',0
};
#else
//Product name "Crazyradio USB Dongle"
__code char usbStringDescriptor2[50] = {
50, //bLength
STRING_DESCRIPTOR, //bDescriptor type
STRING_DESCRIPTOR, //bDescriptor type
//bString ...
'C',0, 'r',0, 'a',0, 'z',0, 'y',0, 'r',0, 'a',0, 'd',0, 'i',0, 'o',0, ' ',0,
'P', 0, 'A', 0, ' ', 0, 'U',0, 'S',0, 'B',0, ' ', 0,
'C',0, 'r',0, 'a',0, 'z',0, 'y',0, 'r',0, 'a',0, 'd',0, 'i',0, 'o',0, ' ',0,
'P', 0, 'A', 0, ' ', 0, 'U',0, 'S',0, 'B',0, ' ', 0,
'D',0, 'o',0, 'n',0, 'g',0, 'l',0, 'e', 0
};
#endif
Expand Down

0 comments on commit b197536

Please sign in to comment.