Skip to content

Commit 2528ab0

Browse files
authored
Merge pull request #5 from arpruss/master
Support blue pill with open drain communication; respond to har
2 parents 8d55600 + cff4979 commit 2528ab0

File tree

6 files changed

+58
-14
lines changed

6 files changed

+58
-14
lines changed

src/CEC/CEC.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CEC_LogicalDevice : public CEC_Electrical
1010
CDT_TV,
1111
CDT_RECORDING_DEVICE,
1212
CDT_PLAYBACK_DEVICE,
13-
CDT_TUNER,
13+
CDT_TUNER,
1414
CDT_AUDIO_SYSTEM,
1515
CDT_OTHER, // Not a real CEC type..
1616
} CEC_DEVICE_TYPE;
@@ -67,7 +67,8 @@ class CEC_LogicalDevice : public CEC_Electrical
6767
typedef enum {
6868
} CEC_TERTIARY_STATE;
6969

70-
protected:
70+
public:
71+
//protected:
7172
static int _validLogicalAddresses[6][5];
7273
int _logicalAddress;
7374
int _physicalAddress;

src/CEC/CEC_Device.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#include "CEC_Device.h"
22
#include <Arduino.h>
33

4+
#if defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F2) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4)
5+
# define STM32
6+
# define CEC_HIGH 1
7+
# define CEC_LOW 0
8+
#else
9+
# define CEC_HIGH LOW
10+
# define CEC_LOW HIGH
11+
#endif
12+
413
CEC_Device::CEC_Device(int physicalAddress, int in_line, int out_line)
514
: CEC_LogicalDevice(physicalAddress)
615
, _isrTriggered(false)
@@ -12,10 +21,15 @@ CEC_Device::CEC_Device(int physicalAddress, int in_line, int out_line)
1221

1322
void CEC_Device::Initialize(CEC_DEVICE_TYPE type)
1423
{
24+
#ifdef STM32
25+
gpio_set_mode(digitalPinToPort(_in_line), PIN_MAP[_in_line].gpio_bit, GPIO_OUTPUT_OD); // set open drain output
26+
_out_line = _in_line;
27+
#else
1528
pinMode(_out_line, OUTPUT);
1629
pinMode( _in_line, INPUT);
30+
#endif
1731

18-
digitalWrite(_out_line, LOW);
32+
digitalWrite(_out_line, CEC_HIGH);
1933
delay(200);
2034

2135
CEC_LogicalDevice::Initialize(type);
@@ -42,12 +56,12 @@ void CEC_Device::OnReceive(int source, int dest, unsigned char* buffer, int coun
4256
bool CEC_Device::LineState()
4357
{
4458
int state = digitalRead(_in_line);
45-
return state == LOW;
59+
return state == CEC_HIGH;
4660
}
4761

4862
void CEC_Device::SetLineState(bool state)
4963
{
50-
digitalWrite(_out_line, state?LOW:HIGH);
64+
digitalWrite(_out_line, state?CEC_HIGH:CEC_LOW);
5165
// give enough time for the line to settle before sampling
5266
// it
5367
delayMicroseconds(50);

src/CEC/Common.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ void DbgPrint(const char* fmt, ...)
2828

2929
#else
3030

31-
#include <avr/io.h>
32-
#include <avr/pgmspace.h>
31+
//#include <avr/io.h>
32+
//#include <avr/pgmspace.h>
3333
#include <stdlib.h>
3434
#include <string.h>
35-
#include <util/delay.h>
35+
#include <stdarg.h>
36+
//#include <util/delay.h>
3637
#include <Arduino.h>
3738

3839
void DbgPrint(const char* fmt, ...)

src/CEC/Common.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef COMMON_H__
22
#define COMMON_H__
33

4+
#if defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F2) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4)
5+
# define STM32
6+
#endif
7+
8+
49
#ifdef WIN32
510
#include <windows.h>
611
#include <stdio.h>
@@ -9,20 +14,37 @@
914
#define ASSERT(x) assert(x)
1015
void DbgPrint(const char* fmt, ...);
1116

12-
#else
17+
extern "C"
18+
{
19+
extern unsigned long micros();
20+
extern void delayMicroseconds(unsigned int);
21+
}
22+
23+
#elif defined(STM32)
24+
25+
#include "dwt.h"
1326

1427
#define ASSERT(x) ((void)0)
1528
void DbgPrint(const char* fmt, ...);
1629
#ifndef NULL
1730
#define NULL 0
1831
#endif
1932

33+
#else
34+
35+
#define ASSERT(x) ((void)0)
36+
void DbgPrint(const char* fmt, ...);
37+
#ifndef NULL
38+
#define NULL 0
2039
#endif
2140

41+
2242
extern "C"
2343
{
2444
extern unsigned long micros();
2545
extern void delayMicroseconds(unsigned int);
2646
}
2747

48+
#endif
49+
2850
#endif // COMMON_H__

src/CEClient.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// create a new instance of CEClient
44
CEClient::CEClient(int physicalAddress, int inputPin, int outputPin) :
5-
CEC_Device(physicalAddress, inputPin, outputPin) {
5+
CEC_Device(physicalAddress, inputPin, outputPin<0 ? inputPin : outputPin) {
66

77
_ready = false;
88
}
@@ -79,9 +79,17 @@ void CEClient::OnReceive(int source, int dest, unsigned char* buffer, int count)
7979

8080
if(_onReceiveCallback)
8181
_onReceiveCallback(source, dest, buffer, count);
82-
8382
else
8483
CEC_Device::OnReceive(source, dest, buffer, count);
84+
85+
if (!MonitorMode && dest == _logicalAddress && count == 1 && buffer[0] == 0x83) {
86+
unsigned char buffer[4];
87+
buffer[0] = 0x84;
88+
buffer[1] = _physicalAddress >> 8;
89+
buffer[2] = _physicalAddress;
90+
buffer[3] = _deviceType;
91+
TransmitFrame(0xF, buffer, 4);
92+
}
8593
}
8694

8795
// OnReady redefinition, to save the current status

src/CEClient.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ typedef void (*OnReceiveCallbackFunction)(int, int, unsigned char*, int);
99
typedef void (*OnTransmitCompleteCallbackFunction)(bool);
1010

1111
public:
12-
13-
CEClient(int physicalAddress, int inputPin, int outputPin);
12+
CEClient(int physicalAddress, int inputPin, int outputPin=-1);
1413
void begin(CEC_DEVICE_TYPE type = CEC_LogicalDevice::CDT_PLAYBACK_DEVICE);
1514
bool isReady();
1615
bool write(int targetAddress, unsigned char* buffer, int count);
@@ -22,7 +21,6 @@ typedef void (*OnTransmitCompleteCallbackFunction)(bool);
2221
void run();
2322

2423
private:
25-
2624
void OnTransmitComplete(bool);
2725
void OnReceive(int source, int dest, unsigned char* buffer, int count);
2826
void OnReady();

0 commit comments

Comments
 (0)