Skip to content

Commit

Permalink
create a single include file so rcswitch and portisch can share uart …
Browse files Browse the repository at this point in the history
…packet format
  • Loading branch information
mightymos committed Nov 22, 2024
1 parent 7f0e5db commit 999917e
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 108 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ The downside is the effort required to develop firmware and flash by the end use
The firmware radio decoding is inspired by 1) RF-Bridge-EFM8BB1 (Portisch) and 2) rc-switch projects.

# Status
THIS IS A WORK IN PROGRESS and requires multiple flashing steps.
Decoding has only been tested with a single door sensor using standard 24 bit protocol.
THIS IS A WORK IN PROGRESS and requires multiple flashing steps.

For many users it is probably easiest to flash the passthrough mode.
Then perform any actual decoding/encoding on the ESP8265 using Tasmota/ESPHome.
Expand Down
52 changes: 52 additions & 0 deletions inc/portisch_command_format.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef PORTISCH_COMMAND_H
#define PORTISCH_COMMAND_H

// common uart packet format for both rcswitch and portisch (despite the file name)

// this is returned along with an ack in response to a request firmware version command
// which is a good demonstration that serial pins and state machine are working
#define FIRMWARE_VERSION 0x04


// start and end of uart packet
#define RF_CODE_START 0xAA
#define RF_CODE_STOP 0x55

// uart packet format
typedef enum
{
IDLE,
SYNC_INIT,
SYNC_FINISH,
RECEIVE_LENGTH,
RECEIVING,
TRANSMIT,
COMMAND
} uart_state_t;


// commands which should be supported partially by rcswitch and mostly by portisch are given here (learning are not supported as of writing):
// https://github.com/Portisch/RF-Bridge-EFM8BB1/wiki/Commands
typedef enum
{
NONE = 0x00,
RF_CODE_ACK = 0xA0,
RF_CODE_LEARN = 0xA1,
RF_CODE_LEARN_KO = 0xA2,
RF_CODE_LEARN_OK = 0xA3,
RF_CODE_RFIN = 0xA4,
RF_CODE_RFOUT = 0xA5,
RF_CODE_SNIFFING_ON = 0xA6,
RF_CODE_SNIFFING_OFF = 0xA7,
RF_CODE_RFOUT_NEW = 0xA8,
RF_CODE_LEARN_NEW = 0xA9,
RF_CODE_LEARN_KO_NEW = 0xAA,
RF_CODE_LEARN_OK_NEW = 0xAB,
RF_CODE_RFOUT_BUCKET = 0xB0,
RF_CODE_SNIFFING_ON_BUCKET = 0xB1,
RF_DO_BEEP = 0xC0,
RF_ALTERNATIVE_FIRMWARE = 0xFF
} uart_command_t;


#endif
8 changes: 0 additions & 8 deletions inc/portisch_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@

#include <stdbool.h>
#include <stdint.h>

//#include <EFM8BB1.h>

// used in timer functions
//#define SYSCLK 24500000

//
#define FIRMWARE_VERSION 0x03

// macros
#define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0]))
Expand Down
44 changes: 2 additions & 42 deletions inc/portisch_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,12 @@
#define INC_SERIAL_H

#include <stdint.h>

// tasmota protocol
#define RF_CODE_START 0xAA
#define RF_CODE_STOP 0x55

//-----------------------------------------------------------------------------
// Global Enums
//-----------------------------------------------------------------------------
typedef enum
{
IDLE,
SYNC_INIT,
SYNC_FINISH,
RECEIVE_LEN,
RECEIVING,
TRANSMIT,
COMMAND
} uart_state_t;

typedef enum
{
NONE = 0x00,
RF_CODE_ACK = 0xA0,
RF_CODE_LEARN = 0xA1,
RF_CODE_LEARN_KO = 0xA2,
RF_CODE_LEARN_OK = 0xA3,
RF_CODE_RFIN = 0xA4,
RF_CODE_RFOUT = 0xA5,
RF_CODE_SNIFFING_ON = 0xA6,
RF_CODE_SNIFFING_OFF = 0xA7,
RF_CODE_RFOUT_NEW = 0xA8,
RF_CODE_LEARN_NEW = 0xA9,
RF_CODE_LEARN_KO_NEW = 0xAA,
RF_CODE_LEARN_OK_NEW = 0xAB,
RF_CODE_RFOUT_BUCKET = 0xB0,
RF_CODE_SNIFFING_ON_BUCKET = 0xB1,
RF_DO_BEEP = 0xC0,
RF_ALTERNATIVE_FIRMWARE = 0xFF
} uart_command_t;


//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
extern __xdata uart_state_t uart_state;
extern __xdata uart_command_t uart_command;
//extern __xdata uart_state_t uart_state;
//extern __xdata uart_command_t uart_command;

//extern void uart_put_command(uint8_t command);

Expand Down
41 changes: 0 additions & 41 deletions inc/state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,6 @@
#ifndef STATE_MACHINE_H
#define STATE_MACHINE_H

// this is returned along with an ack in response to a request firmware version command
// which is a good demonstration that serial pins and state machine are working
#define FIRMWARE_VERSION 0x03


// FIXME: add comment
typedef enum
{
IDLE,
SYNC_INIT,
SYNC_FINISH,
RECEIVE_LENGTH,
RECEIVING,
TRANSMIT,
COMMAND
} UART_STATE_T;


// commands which should be supported (eventually) are given here:
// https://github.com/Portisch/RF-Bridge-EFM8BB1/wiki/Commands
typedef enum
{
NONE = 0x00,
RF_CODE_ACK = 0xA0,
RF_CODE_LEARN = 0xA1,
RF_CODE_LEARN_KO = 0xA2,
RF_CODE_LEARN_OK = 0xA3,
RF_CODE_RFIN = 0xA4,
RF_CODE_RFOUT = 0xA5,
RF_CODE_SNIFFING_ON = 0xA6,
RF_CODE_SNIFFING_OFF = 0xA7,
RF_CODE_RFOUT_NEW = 0xA8,
RF_CODE_LEARN_NEW = 0xA9,
RF_CODE_LEARN_KO_NEW = 0xAA,
RF_CODE_LEARN_OK_NEW = 0xAB,
RF_CODE_RFOUT_BUCKET = 0xB0,
RF_CODE_SNIFFING_ON_BUCKET = 0xB1,
RF_DO_BEEP = 0xC0,
RF_ALTERNATIVE_FIRMWARE = 0xFF
} UART_COMMAND_T;

typedef enum
{
RF_IDLE = 0x00,
Expand Down
7 changes: 4 additions & 3 deletions src/main_portisch.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "delay.h"
#include "hal.h"
#include "portisch.h"
#include "portisch_command_format.h"
#include "portisch_protocols.h"
#include "portisch_serial.h"
#include "timer_interrupts.h"
Expand Down Expand Up @@ -203,10 +204,10 @@ void uart_state_machine(const unsigned int rxdata)
break;
case RF_CODE_RFOUT_NEW:
tr_repeats = RF_TRANSMIT_REPEATS;
uart_state = RECEIVE_LEN;
uart_state = RECEIVE_LENGTH;
break;
case RF_CODE_RFOUT_BUCKET:
uart_state = RECEIVE_LEN;
uart_state = RECEIVE_LENGTH;
break;
case RF_CODE_SNIFFING_ON_BUCKET:
PCA0_DoSniffing();
Expand All @@ -233,7 +234,7 @@ void uart_state_machine(const unsigned int rxdata)
break;

// Receiving UART data length
case RECEIVE_LEN:
case RECEIVE_LENGTH:
position = 0;
packetLength = rxdata & 0xFF;
if (packetLength > 0)
Expand Down
4 changes: 2 additions & 2 deletions src/main_rcswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ int main (void)
unsigned int rxdataWithFlags = UART_NO_DATA;

// allows communication between uart state machine and radio state machine
RF_COMMAND_T rfCommand = NONE;
RF_COMMAND_T rfCommand;


// hardware initialization
Expand All @@ -203,7 +203,7 @@ int main (void)

// DEBUG:
// on some boards, "debug pin" is actually buzzer so we do not want to use it for debugging unless buzzer has been removed
debug_pin01_off();
//debug_pin01_off();

//
startup_blink();
Expand Down
6 changes: 0 additions & 6 deletions src/portisch_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
#include "portisch_serial.h"
#include "uart.h"

//void uart_put_command(uint8_t command)
//{
// uart_putc(RF_CODE_START);
// uart_putc(command);
// uart_putc(RF_CODE_STOP);
//}

void uart_put_RF_Data_Standard(uint8_t command)
{
Expand Down
4 changes: 2 additions & 2 deletions src/rcswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void transmit(const bool invertedSignal, uint16_t delayHigh, uint16_t delayLow)
set_tdata(firstLogicLevel);

// DEBUG:
set_debug_pin01(firstLogicLevel);
//set_debug_pin01(firstLogicLevel);

init_delay_timer_us(1, delayHigh);
wait_delay_timer_finished();
Expand All @@ -300,7 +300,7 @@ void transmit(const bool invertedSignal, uint16_t delayHigh, uint16_t delayLow)
set_tdata(secondLogicLevel);

// DEBUG:
set_debug_pin01(secondLogicLevel);
//set_debug_pin01(secondLogicLevel);


init_delay_timer_us(1, delayLow);
Expand Down
8 changes: 6 additions & 2 deletions src/state_machine.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "delay.h"
#include "hal.h"

// we use the same format as portisch so okay to include
#include "portisch_command_format.h"

#include "rcswitch.h"
#include "state_machine.h"
#include "uart.h"
Expand Down Expand Up @@ -36,8 +40,8 @@ RF_COMMAND_T uart_state_machine(const unsigned int rxdataWithFlags)
{
// FIXME: eventually an appropriate initialization value might be RF_RFIN for decoding by default
// but right now we decode outside of state machine
__xdata static UART_STATE_T state = IDLE;
__xdata static UART_COMMAND_T command = NONE;
__xdata static uart_state_t state = IDLE;
__xdata static uart_command_t command = NONE;

// FIXME: need to know what initialization value is appropriate
__xdata static uint8_t position = 0;
Expand Down

0 comments on commit 999917e

Please sign in to comment.