Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
SDCC ?= sdcc
CFLAGS = --model-large --std-c99
CFLAGS = --model-large --std-c99 -Isrc
LDFLAGS = --xram-loc 0x8000 --xram-size 2048 --model-large
VPATH = src/
OBJS = main.rel usb.rel usb_desc.rel radio.rel

ifeq ($(CRPA),y)
OBJS += platforms/crpa.rel
else ifeq ($(CRPA_MSPI),y)
OBJS += platforms/crpa_mspi.rel
else
OBJS += platforms/generic.rel
endif

SDCC_VER := $(shell $(SDCC) -v | grep -Po "\d\.\d\.\d" | sed "s/\.//g")

all: sdcc bin/ dongle.bin
all: sdcc bin/ bin/platforms/ dongle.bin

sdcc:
@if test $(SDCC_VER) -lt 310; then echo "Please update SDCC to 3.1.0 or newer."; exit 2; fi
Expand All @@ -21,7 +29,7 @@ dongle.bin: $(OBJS)
$(SDCC) $(CFLAGS) -c $< -o bin/$@

clean:
rm -f bin/*
rm -rf bin/*

install:
./prog/usb-flasher/usb-flash.py bin/dongle.bin
Expand All @@ -34,3 +42,6 @@ logitech_install:

bin/:
mkdir -p bin

bin/platforms/:
mkdir -p bin/platforms/
25 changes: 24 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,33 @@ The following hardware has been tested and is known to work.

## Build the firmware

To build generic firmware without external peripheral/IO support:

```
make
```

To build firmware targeting the Bitcraze Crazyradio PA:

```
make CRPA=y
```

To build firmware targeting a Bitcraze Crazyradio PA modified to be
used as an SPI master (e.g., to use as a programmer):

```
make CRPA_MSPI=y
```

The above `CRPA_MSPI` firmware requires that U2 has been removed,
and that pins 2 and 4 of the U2 footprint are connected. This allows
the CSN pin to be used as an output.

**IMPORTANT:** Using the `CRPA_MSPI` firmware on an unmodified device
may damage U2 or U3 due to contention over the CSN signal.


## Flash over USB

nRF24LU1+ chips come with a factory programmed bootloader occupying the topmost 2KB of flash memory. The CrazyRadio firmware and RFStorm research firmware support USB commands to enter the Nordic bootloader.
Expand Down Expand Up @@ -194,4 +217,4 @@ Transmit a continuous tone at 2405MHz

```
./nrf24-continuous-tone-test.py -c 5
```
```
24 changes: 24 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright (C) 2016 Jon Szymaniak <jon.szymaniak@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MOUSEJACK_COMMON_H_
#define MOUSEJACK_COMMON_H_

// Mark variable intentionally unused to silence associated warnings
#define UNUSED_PARAMETER(x) ((void) (x))

#endif
23 changes: 23 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>

#include "usb.h"
#include "radio.h"
#include "platform.h"

// Program entry point
void main()
{
uint8_t heartbeat = 1;
uint16_t heartbeat_count = 0;

rfcon = 0x06; // enable RF clock
rfctl = 0x10; // enable SPI
ien0 = 0x80; // enable interrupts
TICKDV = 0xFF; // set the tick divider

// Perform platform-specific initializations
platform_init();
platform_led_off(PLATFORM_LED_HEARTBEAT | PLATFORM_LED_DEBUG);

// Initialise and connect the USB controller
init_usb();

Expand All @@ -40,6 +49,20 @@ void main()
REGXH = 0xFF;
REGXL = 0xFF;
REGXC = 0x08;

// 1s, 50% duty cycle heatbeat.
// This will appear slow down when processor is being kept busy in ISRs
if (++heartbeat_count == 500) {
if (heartbeat) {
platform_led_on(PLATFORM_LED_HEARTBEAT);
} else {
platform_led_off(PLATFORM_LED_HEARTBEAT);
}

heartbeat ^= 1;
heartbeat_count = 0;
}

delay_us(1000);
}
}
6 changes: 5 additions & 1 deletion src/nRF24LU1P.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@
// Microsecond delay
inline void delay_us(uint16_t us) { do nop_us(); while(--us); }

// Shift feedback registers
// Special Function Registers (SFR)
__sfr __at (0xE6) rfctl; // ref: nRF24LU1+ Product Spec, Section 6.5.1, Table 20
__sfr __at (0x90) rfcon; // ref: nRF24LU1+ Product Spec, Section 6.5.1, Table 21
__sfr __at (0xA0) usbcon; // ref: nRF24LU1+ Product Spec, Section 7.3, Table 24
__sfr __at (0x80) P0; // ref: nRF24LU1+ Product Spec, Section 13.1, Table 94
__sfr __at (0x94) P0DIR; // ref: nRF24LU1+ Product Spec, Section 13.1, Table 95
__sfr __at (0x95) P0ALT; // ref: nRF24LU1+ Product Spec, Section 13.1, Table 96
__sfr __at (0xC9) P0EXP; // ref: nRF24LU1+ Product Spec, Section 13.1, Table 97
__sfr __at (0xE5) RFDAT; // ref: nRF24LU1+ Product Spec, Section 15.1.2, Table 108
__sfr __at (0xAB) TICKDV; // ref: nRF24LU1+ Product Spec, Section 19.3.2, Table 128
__sfr __at (0xAB) REGXH; // ref: nRF24LU1+ Product Spec, Section 19.3.6, Table 129
__sfr __at (0xAC) REGXL; // ref: nRF24LU1+ Product Spec, Section 19.3.6, Table 129
__sfr __at (0xAD) REGXC; // ref: nRF24LU1+ Product Spec, Section 19.3.6, Table 129
__sfr __at (0xA8) ien0; // ref: nRF24LU1+ Product Spec, Section 22.4.1, Table 139
__sfr __at (0xB8) ien1; // ref: nRF24LU1+ Product Spec, Section 22.4.2, Table 140
__sfr __at (0xB2) SMDAT; // ref: nrf24lu1+ product spec, Section 9.2
__sfr __at (0xB3) SMCTRL; // ref: nrf24lu1+ product spec, Section 9.2

// SFR bits
__sbit __at (0x90) rfce; // ref: nRF24LU1+ Product Spec, Section 6.5.1, Table 21
Expand Down
44 changes: 44 additions & 0 deletions src/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright (C) 2016 Jon Szymaniak <jon.szymaniak@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MOUSEJACK_PLATFORM_H_
#define MOUSEJACK_PLATFORM_H_

#include <stdbool.h>

#define PLATFORM_LED_HEARTBEAT (1 << 0)
#define PLATFORM_LED_DEBUG (1 << 1)

// Initialize platform-specific settings and I/O
void platform_init();

// Enable (true) or disable (false) external LN:s
void platform_enable_lna(bool enable);

// Set the state of LEDs on the platform. A `1` bit is ON, a `0` bit is OFF.
void platform_led(uint8_t led_state);

// Turn on the LEDs associated with a `1` bit the specified mask.
void platform_led_on(uint8_t led_mask);

// Turn off the LEDs associated with a `1` bit the specified mask.
void platform_led_off(uint8_t led_mask);

// Assert SPI Master chip select
void platform_assert_spi_master_cs(bool assert_cs);

#endif
93 changes: 93 additions & 0 deletions src/platforms/crpa.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Bitcraze CrazyRadio PA - Unmodified platform with LED support
*
* Copyright (C) 2016 Jon Szymaniak <jon.szymaniak@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>

#include "nRF24LU1P.h"
#include "platform.h"
#include "common.h"
#include "crpa.h"

void platform_init()
{
/* These pins must always be inputs because they're connected to the output
* of U2 (noninverting buffer).
*/
P0DIR = (CRPA_P0_CSN | CRPA_P0_5);
P0 = 0;
}

void platform_enable_lna(bool enable)
{
crpa_enable_lna(enable);
}

void platform_led(uint8_t leds)
{
uint8_t p0_state = P0;

if (leds & PLATFORM_LED_DEBUG) {
p0_state |= CRPA_P0_RED_LED2;
} else {
p0_state &= ~CRPA_P0_RED_LED2;
}

if (leds & PLATFORM_LED_HEARTBEAT) {
p0_state |= CRPA_P0_GRN_LED1;
} else {
p0_state &= ~CRPA_P0_GRN_LED1;
}

P0 = p0_state;
}

void platform_led_on(uint8_t led_mask)
{
uint8_t p0_state = P0;

if (led_mask & PLATFORM_LED_DEBUG) {
p0_state |= CRPA_P0_RED_LED2;
}

if (led_mask & PLATFORM_LED_HEARTBEAT) {
p0_state |= CRPA_P0_GRN_LED1;
}

P0 = p0_state;
}

void platform_led_off(uint8_t led_mask)
{
uint8_t p0_state = P0;

if (led_mask & PLATFORM_LED_DEBUG) {
p0_state &= ~CRPA_P0_RED_LED2;
}

if (led_mask & PLATFORM_LED_HEARTBEAT) {
p0_state &= ~CRPA_P0_GRN_LED1;
}

P0 = p0_state;
}

// No SPI master support available in this build
void platform_assert_spi_master_cs(bool assert_cs)
{
UNUSED_PARAMETER(assert_cs);
}
42 changes: 42 additions & 0 deletions src/platforms/crpa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Bitcraze CrazyRadio PA common definitions
*
* Copyright (C) 2016 Jon Szymaniak <jon.szymaniak@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CRPA_H_
#define CRPA_H_

// P0 mappning
#define CRPA_P0_SCK (1 << 0)
#define CRPA_P0_MOSI (1 << 1)
#define CRPA_P0_MISO (1 << 2)
#define CRPA_P0_CSN (1 << 3)
#define CRPA_P0_RXEN (1 << 4)
#define CRPA_P0_5 (1 << 5)

// LEDs are on SPI pins
#define CRPA_P0_GRN_LED1 CRPA_P0_SCK
#define CRPA_P0_RED_LED2 CRPA_P0_MISO

#define crpa_enable_lna(enable_) do { \
if (enable_) { \
P0 |= CRPA_P0_RXEN; \
} else { \
P0 &= ~CRPA_P0_RXEN; \
} \
} while (0)

#endif
Loading