I got a sketch for controlling my somfy devices via rc module. However, the sketch is not compatible with ESP8266 ( controlling the GPIO state ... DDRD / PORTD incompatibility).
Can anyone of you help me rewriting this for ESP?
Help is very much appreciated !
#define PORT_TX 5 //5 of PORTD = DigitalPin 5
DDRD |= 1<<PORT_TX; // Pin 5 an output
PORTD &= !(1<<PORT_TX); // Pin 5 LOW
void SendCommand(byte *frame, byte sync) {
if(sync == 2) { // Only with the first frame.
//Wake-up pulse & Silence
PORTD |= 1<<PORT_TX;
delayMicroseconds(9415);
PORTD &= !(1<<PORT_TX);
delayMicroseconds(89565);
}
// Hardware sync: two sync for the first frame, seven for the following ones.
for (int i = 0; i < sync; i++) {
PORTD |= 1<<PORT_TX;
delayMicroseconds(4*SYMBOL);
PORTD &= !(1<<PORT_TX);
delayMicroseconds(4*SYMBOL);
}
// Software sync
PORTD |= 1<<PORT_TX;
delayMicroseconds(4550);
PORTD &= !(1<<PORT_TX);
delayMicroseconds(SYMBOL);
//Data: bits are sent one by one, starting with the MSB.
for(byte i = 0; i < 56; i++) {
if(((frame[i/8] >> (7 - (i%8))) & 1) == 1) {
PORTD &= !(1<<PORT_TX);
delayMicroseconds(SYMBOL);
PORTD ^= 1<<5;
delayMicroseconds(SYMBOL);
}
else {
PORTD |= (1<<PORT_TX);
delayMicroseconds(SYMBOL);
PORTD ^= 1<<5;
delayMicroseconds(SYMBOL);
}
}
PORTD &= !(1<<PORT_TX);
delayMicroseconds(30415); // Inter-frame silence
}