Skip to content

Commit

Permalink
completely reworked firmware, added support of inverted signals
Browse files Browse the repository at this point in the history
  • Loading branch information
Portisch committed Oct 31, 2018
1 parent b8e9236 commit 1fa3572
Show file tree
Hide file tree
Showing 11 changed files with 1,082 additions and 1,628 deletions.
969 changes: 460 additions & 509 deletions Keil 8051 v9.53 - Release/RF-Bridge-EFM8BB1.hex

Large diffs are not rendered by default.

72 changes: 20 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,12 @@ But for this the protocol have to be defined in the RF_Protocols.h file.

01 means:</br>
<img src="https://raw.github.com/Portisch/RF-Bridge-EFM8BB1/master/doc/01_Bit_1.png" width="400" ></br>
BIT_HIGH_TIME is 1081µs.</br>
BIT_HIGH_DUTY = 100% / (1081µs + 453µS) * 1081µs =~ 70%. </br>

10 means:</br>
<img src="https://raw.github.com/Portisch/RF-Bridge-EFM8BB1/master/doc/10_Bit_0.png" width="400" ></br>
BIT_LOW_TIME is 453µs.</br>
BIT_LOW_DUTY = 100% / (1081µs + 453µS) * 453µs =~ 30%.</br>

23 means:</br>
<img src="https://raw.github.com/Portisch/RF-Bridge-EFM8BB1/master/doc/23_Sync_Bit.png" width="400" ></br>
SYNC_HIGH is 2990µs.</br>
SYNC_LOW is 7230µs.</br>
SYNC_BIT_COUNT is default 0.</br>

The bitcount can be counted like this:</br>

Expand All @@ -88,21 +81,21 @@ The xx is the firmware version (0x00-0xFF)
0xAA: uart sync init<br/>
0xA6: sniffing active<br/>
0x06: data len<br/>
0x02: protocol identifier<br/>
0x01: protocol index<br/>
0xD0-0x55: data<br/>
0x55: uart sync end

STOP:<br/>
Binary: 10101010 10100110 00000110 00000001 11010000 11111001 00110010 00010001 01010101 01010101<br/>
Hex: AA A6 06 02 D0 F9 32 11 55 55<br/>
Hex: AA A6 06 01 D0 F9 32 11 55 55<br/>
DOWN:<br/>
Binary: 10101010 10100110 00000110 00000001 11010000 11111001 00110010 00010001 00110011 01010101<br/>
Hex: AA A6 06 02 D0 F9 32 11 33 55<br/>
Hex: AA A6 06 01 D0 F9 32 11 33 55<br/>

## RF decode from Seamaid_PAR_56_RGB remote (24 bit of data):
Light ON:<br/>
Binary: 10101010 10100110 00000100 00000011 00110010 11111010 10001111 01010101<br/>
Hex: AA A6 04 03 32 FA 8F 55<br/>
Binary: 10101010 10100110 00000010 00000011 00110010 11111010 10001111 01010101<br/>
Hex: AA A6 04 02 32 FA 8F 55<br/>

## Transmiting by command 0xA5
This is the original implemented RF transmit command<br/>
Expand All @@ -115,7 +108,7 @@ Hex: AA A5 24 E0 01 40 03 84 D0 03 58 55<br/>
0xD0-0x58: 24bit Data<br/>

The high time of the SYNC get calculated by the Tsyn (SYNC low time),<br/>
duty cycle of the high bit is 75% and 25% of the low bit.<br/>
the timing is defined by Tlow and Thigh.<br/>

## Sniffing by command 0xA6
With the command the standard PT226x sniffing gets disabled and the sniffing of the defined protocols in RF_Protocols.h is starting.<br/>
Expand All @@ -128,70 +121,49 @@ Hex: AA A6 04 03 32 FA 80 55<br/>
0xAA: uart sync init<br/>
0xA6: sniffed RF data<br/>
0x04: data len<br/>
0x03: protocol identifier (Seamaid_PAR_56_RGB)<br/>
0x02: protocol index (Seamaid_PAR_56_RGB)<br/>
0x32-0x80: data<br/>
0x55: uart sync end

## Stop sniffing by command 0xA7
Stop the 0xA6 sniffing and restart the PT226x sniffing.
Stop the 0xA6 sniffing and restart the default PT226x sniffing.

## Transmiting by command 0xA8
There is a new command in the firmware to be able to send RF data.<br/>
Predefined protocols in the RF_Protocols.h file can be used directly by<br/>
using the protocol identifier.<br/>
using the protocol index.<br/>

Hex: AA A8 06 02 D0 F9 32 11 33 55<br/>
Hex: AA A8 06 01 D0 F9 32 11 33 55<br/>

0xAA: uart sync init<br/>
0xA8: transmit RF data<br/>
0x06: data len<br/>
0x02: protocol identifier (ROHRMOTOR24)<br/>
0x02: protocol index (ROHRMOTOR24)<br/>
0xD0-0x33: data<br/>
0x55: uart sync end

#### Universal transmit of a duty cycle based protocol by command 0xA8
When 0x7F get used as protocol identifier the timing can be user defined<br/>
and do not have to be defined in RF_Protocols.h.<br/>
This methode can be used to find correct parameter to define the timing<br/>
in RF_Protocols.h for future.

Hex: AA A8 0D 7F 12 C0 05 DC 02 BC 46 01 2C 1E 08 1E 55<br/>

0xAA: uart sync init<br/>
0xA8: transmit RF data<br/>
0x0D: data len<br/>
0x7F: protocol identifier 0x7F<br/>
0x12-0xC0: SYNC_HIGH<br/>
0x05-0xDC: SYNC_LOW<br/>
0x02-0xBC: BIT_HIGH_TIME<br/>
0x46: BIT_HIGH_DUTY<br/>
0x01-0x2C: BIT_LOW_TIME<br/>
0x1E: BIT_LOW_DUTY<br/>
0x08: BIT_COUNT + SYNC_BIT_COUNT in front of RF data<br/>
0x1E: RF data to send<br/>
0x55: uart sync end<br/>

#### Universal transmit of a time based protocol by command 0xA8
When 0x80 get used as protocol identifier the timing can be user defined<br/>
When 0x80 get used as protocol index the timing can be user defined<br/>
and do not have to be defined in RF_Protocols.h.<br/>
This methode can be used to find correct parameter to define the timing<br/>
This method can be used to find correct parameter to define the timing<br/>
in RF_Protocols.h for future.

<img src="https://raw.github.com/Portisch/RF-Bridge-EFM8BB1/master/doc/pulse_timing.png" width="800" ></br>

Hex: AA A8 0E 80 01 90 1B 58 00 C8 01 02 02 01 0C 1F B0 55<br/>
Hex: AA A8 0F 80 00 0A 00 14 00 C8 01 02 02 01 00 0C 1F B0 55<br/>

0xAA: uart sync init<br/>
0xA8: transmit RF data<br/>
0x0E: data len<br/>
0x80: protocol identifier 0x80<br/>
0x01-0x90: SYNC_HIGH<br/>
0x1B-0x58: SYNC_LOW<br/>
0x0F: data len<br/>
0x80: protocol index 0x80<br/>
0x00-0x0A: SYNC_HIGH FACTOR<br/>
0x00-0x14: SYNC_LOW FACTOR<br/>
0x00-0xC8: PULSE_TIME<br/>
0x01: BIT_0_HIGH FACTOR<br/>
0x02: BIT_0_LOW FACTOR<br/>
0x02: BIT_1_HIGH FACTOR<br/>
0x01: BIT_1_LOW FACTOR<br/>
0x00: SYNC_BIT_COUNT<br/>
0x0C: BIT_COUNT<br/>
0x1F-0xB0: RF data to send<br/>
0x55: uart sync end<br/>
Expand Down Expand Up @@ -259,8 +231,4 @@ For support/help take a look [here](https://github.com/Portisch/RF-Bridge-EFM8BB
## Beep by command 0xC0
Hex: AA C0 xx xx 55<br/>

Do beep xxxx miliseconds (uint16_t). Like AA C0 03 E8 55 will beep for ~1000ms.

# Next Steps
Add ESPurna support:<br/>
A new protocol have to be implemented to support more RF signals -> have to be defined!
Do beep xxxx miliseconds (uint16_t). Like AA C0 03 E8 55 will beep for ~1000ms.
13 changes: 5 additions & 8 deletions RF_Bridge.hwconf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<property object="CLOCK_0" propertyId="ABPeripheral.included" value="true"/>
<property object="CLOCK_0" propertyId="clock.clockselect.clocksourcedivider" value="SYSCLK / 1"/>
<property object="CLOCK_0" propertyId="clock.clockselect.sysclk" value="24.500 MHz"/>
<property object="CROSSBAR0" propertyId="xbar0.pca0.cex" value="CEX0 and CEX1"/>
<property object="CROSSBAR0" propertyId="xbar0.pca0.cex" value="CEX0"/>
<property object="CROSSBAR0" propertyId="xbar0.uart0.data" value="Enabled"/>
<property object="DefaultMode" propertyId="mode.diagramLocation" value="100, 100"/>
<property object="INTERRUPT_0" propertyId="ABPeripheral.included" value="true"/>
Expand All @@ -17,6 +17,7 @@
<property object="P0.0" propertyId="ports.settings.iomode" value="Digital Push-Pull Output"/>
<property object="P0.0" propertyId="ports.settings.label" value="T_DATA"/>
<property object="P0.0" propertyId="ports.settings.outputmode" value="Push-pull"/>
<property object="P0.0" propertyId="ports.settings.skip" value="Skipped"/>
<property object="P0.1" propertyId="ports.settings.skip" value="Skipped"/>
<property object="P0.2" propertyId="ports.settings.skip" value="Skipped"/>
<property object="P0.3" propertyId="ports.settings.skip" value="Skipped"/>
Expand All @@ -40,14 +41,10 @@
<property object="PBCFG_0" propertyId="pbcfg.settings.enablecrossbar" value="Enabled"/>
<property object="PCACH_0" propertyId="ABPeripheral.included" value="true"/>
<property object="PCACH_0" propertyId="pcach.pcachannel.cex0outputpolarity" value="Inverted"/>
<property object="PCACH_0" propertyId="pcach.pcachannel.matchfunction" value="Enabled"/>
<property object="PCACH_0" propertyId="pcach.pcachannelcapturecomparemode.enablechannelcomparatorfunction" value="Enabled"/>
<property object="PCACH_0" propertyId="pcach.pcachannelcapturecomparemode.enablechannelpulsewidthmodulationmoden" value="Enabled"/>
<property object="PCACH_0" propertyId="pcach.pcacontrol.channelcapturecomparemode" value="Predefined 8~11-bit pulse modulator"/>
<property object="PCACH_0" propertyId="pcach.pcachannelcapturecomparemode.enablechannelcapturenegativefunction" value="Enabled"/>
<property object="PCACH_0" propertyId="pcach.pcachannelcapturecomparemode.enablechannelcapturepositivefunction" value="Enabled"/>
<property object="PCACH_0" propertyId="pcach.pcacontrol.channelcapturecomparemode" value="Capture on transition of CEX"/>
<property object="PCACH_1" propertyId="ABPeripheral.included" value="true"/>
<property object="PCACH_1" propertyId="pcach.pcachannelcapturecomparemode.enablechannelcapturenegativefunction" value="Enabled"/>
<property object="PCACH_1" propertyId="pcach.pcachannelcapturecomparemode.enablechannelcapturepositivefunction" value="Enabled"/>
<property object="PCACH_1" propertyId="pcach.pcacontrol.channelcapturecomparemode" value="Capture on transition of CEX"/>
<property object="PCACH_2" propertyId="ABPeripheral.included" value="true"/>
<property object="PCA_0" propertyId="ABPeripheral.included" value="true"/>
<property object="PCA_0" propertyId="pca.pcacountertimerconfiguration.enablepcacountertimeroverflowinterrupt" value="Enabled"/>
Expand Down
2 changes: 1 addition & 1 deletion inc/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define TDATA_ON 1
#define TDATA_OFF 0

#define Sniffing true
#define Sniffing_On 1

#define SYSCLK 24500000

Expand Down
1 change: 0 additions & 1 deletion inc/InitDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extern void TIMER16_3_enter_DefaultMode_from_RESET(void);
extern void TIMER_SETUP_0_enter_DefaultMode_from_RESET(void);
extern void PCA_0_enter_DefaultMode_from_RESET(void);
extern void PCACH_0_enter_DefaultMode_from_RESET(void);
extern void PCACH_1_enter_DefaultMode_from_RESET(void);
extern void UART_0_enter_DefaultMode_from_RESET(void);
extern void INTERRUPT_0_enter_DefaultMode_from_RESET(void);
// [Config(Per-Module Mode)Transition Prototypes]$
Expand Down
24 changes: 5 additions & 19 deletions inc/RF_Handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,22 @@
#define INC_RF_HANDLING_H_

extern uint8_t Compute_CRC8_Simple_OneByte(uint8_t byteVal);
extern uint8_t RFInSync(uint8_t identifier, uint16_t period_pos, uint16_t period_neg);
extern bool CheckDutyCycle(uint8_t current_duty_cycle, uint8_t desired_duty_cycle);
extern uint8_t RFInSync(uint8_t identifier, uint8_t inverse, uint16_t period_pos, uint16_t period_neg);
extern uint8_t PCA0_GetProtocolIndex(uint8_t identifier);
extern void PCA0_InitTransmit(uint16_t sync_high, uint16_t sync_low, uint16_t BIT_HIGH_TIME, uint8_t BIT_HIGH_DUTY,
uint16_t BIT_LOW_TIME, uint8_t BIT_LOW_DUTY, uint8_t bitcount);
extern void SetPCA0DutyCylce(void);
extern void SetTimer0Overflow(uint8_t T0_Overflow);
extern void PCA0_StartTransmit(void);
extern void PCA0_StopTransmit(void);
extern uint8_t PCA0_DoSniffing(uint8_t active_command);
extern void PCA0_StopSniffing(void);
extern void SendRFBuckets(uint16_t *buckets, uint8_t *rfdata, uint8_t n, uint8_t repeats);
extern void SendTimingProtocol(uint16_t sync_high, uint16_t sync_low,
uint16_t bit_0_high, uint16_t bit_0_low, uint16_t bit_1_high, uint16_t bit_1_low,
uint8_t bitcount);
uint8_t sync_bits, uint8_t bitcount, uint8_t position);
extern void Bucket_Received(uint16_t duration);

// 112 byte == 896 bits, so a RF signal with maximum of 896 bits is possible
// for bucket transmission, this depends on the number of buckets.
// E.g. 4 buckets have a total overhead of 11, allowing 101 bits (high/low pairs)
#define RF_DATA_BUFFERSIZE 112

#define SWB(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00))

typedef enum
{
RF_IDLE,
Expand All @@ -44,8 +36,8 @@ typedef enum

typedef enum
{
// do sniffing by duty cycle
MODE_DUTY_CYCLE,
// do sniffing by timing
MODE_TIMING,
// do sniffing by bucket
// https://github.com/pimatic/RFControl
MODE_BUCKET
Expand All @@ -54,26 +46,20 @@ typedef enum
#define RF_DATA_RECEIVED_MASK 0x80

extern SI_SEGMENT_VARIABLE(RF_DATA[RF_DATA_BUFFERSIZE], uint8_t, SI_SEG_XDATA);

// RF_DATA_STATUS
// Bit 7: 1 Data received, 0 nothing received
// Bit 6-0: Protocol identifier
extern SI_SEGMENT_VARIABLE(RF_DATA_STATUS, uint8_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(rf_state, rf_state_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(desired_rf_protocol, uint8_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(rf_sniffing_mode, rf_sniffing_mode_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(protocol_index_in_sync, uint8_t, SI_SEG_XDATA);

extern SI_SEGMENT_VARIABLE(last_sniffing_command, uint8_t, SI_SEG_XDATA);

extern SI_SEGMENT_VARIABLE(DUTY_CYCLE_HIGH, uint8_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(DUTY_CYLCE_LOW, uint8_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(T0_HIGH, uint8_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(T0_LOW, uint8_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(SYNC_HIGH, uint16_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(SYNC_LOW, uint16_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(BIT_HIGH, uint16_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(BIT_LOW, uint16_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(BIT_COUNT, uint8_t, SI_SEG_XDATA);

extern SI_SEGMENT_VARIABLE(actual_bit_of_byte, uint8_t, SI_SEG_XDATA);
extern SI_SEGMENT_VARIABLE(actual_bit, uint8_t, SI_SEG_XDATA);
Expand Down
Loading

0 comments on commit 1fa3572

Please sign in to comment.