diff --git a/firmware/Makefile b/firmware/Makefile index 801f00f..a8491f3 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -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 diff --git a/firmware/src/main.c b/firmware/src/main.c index 17c2baf..128d75a 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -1,6 +1,6 @@ /** - * || ____ _ __ - * +------+ / __ )(_) /_______________ _____ ___ + * || ____ _ __ + * +------+ / __ )(_) /_______________ _____ ___ * | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ * +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ * || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ @@ -62,7 +62,7 @@ static char scannLength; static bool contCarrier=false; static bool needAck = true; -void main() +void main() { char status; char leds=0; @@ -70,13 +70,13 @@ void main() 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 @@ -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) @@ -100,7 +100,7 @@ void main() #endif //PPM_JOYSTICK // Initialise and connect the USB usbInit(); - + //Globally activate the interruptions IEN0 |= 0x80; @@ -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) @@ -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(); @@ -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) { @@ -195,7 +195,7 @@ void handleUsbVendorSetup() launchBootloader(); //Will never come back ... - + return; } else if(setup->request == SET_RADIO_CHANNEL) @@ -208,7 +208,7 @@ void handleUsbVendorSetup() else if(setup->request == SET_DATA_RATE) { radioSetDataRate(setup->value); - + usbAckSetup(); return; } @@ -219,14 +219,14 @@ 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; @@ -234,21 +234,21 @@ void handleUsbVendorSetup() 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; } @@ -256,17 +256,17 @@ void handleUsbVendorSetup() { 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; } @@ -278,33 +278,33 @@ 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; ilength, rbuffer, &rlen); - + if (status) IN0BUF[scannLength++] = i; - + ledTimeout = 2; ledSet(LED_GREEN | LED_RED, false); if(status) @@ -312,7 +312,7 @@ void handleUsbVendorSetup() else ledSet(LED_RED, true); } - + //Ack the setup phase usbAckSetup(); return; @@ -323,13 +323,13 @@ 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(); } @@ -337,18 +337,18 @@ void handleUsbVendorSetup() // 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(); } diff --git a/firmware/src/usbDescriptor.c b/firmware/src/usbDescriptor.c index 8a7c24d..2a39893 100644 --- a/firmware/src/usbDescriptor.c +++ b/firmware/src/usbDescriptor.c @@ -1,6 +1,6 @@ /** - * || ____ _ __ - * +------+ / __ )(_) /_______________ _____ ___ + * || ____ _ __ + * +------+ / __ )(_) /_______________ _____ ___ * | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ * +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ * || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ @@ -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) @@ -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